Pier Angelo Vendrame pushed to branch tor-browser-128.3.0esr-14.0-1 at The Tor Project / Applications / Tor Browser

Commits:

4 changed files:

Changes:

  • mobile/android/android-components/components/feature/search/src/main/java/mozilla/components/feature/search/telemetry/SerpTelemetryRepository.kt
    ... ... @@ -8,7 +8,7 @@ import mozilla.appservices.remotesettings.RemoteSettingsResponse
    8 8
     import mozilla.components.support.base.log.logger.Logger
    
    9 9
     import mozilla.components.support.ktx.android.org.json.asSequence
    
    10 10
     import mozilla.components.support.ktx.android.org.json.toList
    
    11
    -import mozilla.components.support.remotesettings.RemoteSettingsClient
    
    11
    +//import mozilla.components.support.remotesettings.RemoteSettingsClient
    
    12 12
     import mozilla.components.support.remotesettings.RemoteSettingsResult
    
    13 13
     import org.jetbrains.annotations.VisibleForTesting
    
    14 14
     import org.json.JSONArray
    
    ... ... @@ -23,22 +23,22 @@ internal const val REMOTE_ENDPOINT_BUCKET_NAME = "main"
    23 23
      * Parse SERP Telemetry json from remote config.
    
    24 24
      */
    
    25 25
     class SerpTelemetryRepository(
    
    26
    -    rootStorageDirectory: File,
    
    26
    +//    rootStorageDirectory: File,
    
    27 27
         private val readJson: () -> JSONObject,
    
    28
    -    collectionName: String,
    
    29
    -    serverUrl: String = REMOTE_PROD_ENDPOINT_URL,
    
    30
    -    bucketName: String = REMOTE_ENDPOINT_BUCKET_NAME,
    
    28
    +//    collectionName: String,
    
    29
    +//    serverUrl: String = REMOTE_PROD_ENDPOINT_URL,
    
    30
    +//    bucketName: String = REMOTE_ENDPOINT_BUCKET_NAME,
    
    31 31
     ) {
    
    32 32
         val logger = Logger("SerpTelemetryRepository")
    
    33 33
         private var providerList: List<SearchProviderModel> = emptyList()
    
    34 34
     
    
    35
    -    @VisibleForTesting
    
    36
    -    internal var remoteSettingsClient = RemoteSettingsClient(
    
    37
    -        serverUrl = serverUrl,
    
    38
    -        bucketName = bucketName,
    
    39
    -        collectionName = collectionName,
    
    40
    -        storageRootDirectory = rootStorageDirectory,
    
    41
    -    )
    
    35
    +//    @VisibleForTesting
    
    36
    +//    internal var remoteSettingsClient = RemoteSettingsClient(
    
    37
    +//        serverUrl = serverUrl,
    
    38
    +//        bucketName = bucketName,
    
    39
    +//        collectionName = collectionName,
    
    40
    +//        storageRootDirectory = rootStorageDirectory,
    
    41
    +//    )
    
    42 42
     
    
    43 43
         /**
    
    44 44
          * Provides list of search providers from cache or dump and fetches from remotes server .
    
    ... ... @@ -65,7 +65,7 @@ class SerpTelemetryRepository(
    65 65
             val remoteResponse = fetchRemoteResponse()
    
    66 66
             if (remoteResponse.lastModified > cacheLastModified) {
    
    67 67
                 providerList = parseRemoteResponse(remoteResponse)
    
    68
    -            writeToCache(remoteResponse)
    
    68
    +            //writeToCache(remoteResponse)
    
    69 69
             }
    
    70 70
         }
    
    71 71
     
    
    ... ... @@ -73,8 +73,9 @@ class SerpTelemetryRepository(
    73 73
          * Writes data to local cache.
    
    74 74
          */
    
    75 75
         @VisibleForTesting
    
    76
    -    internal suspend fun writeToCache(records: RemoteSettingsResponse): RemoteSettingsResult {
    
    77
    -        return remoteSettingsClient.write(records)
    
    76
    +    internal suspend fun writeToCache(/*records: RemoteSettingsResponse*/): RemoteSettingsResult {
    
    77
    +        return RemoteSettingsResult.NetworkFailure(Exception("Bug-43113: no remote fetching"))
    
    78
    +//        return remoteSettingsClient.write(records)
    
    78 79
         }
    
    79 80
     
    
    80 81
         /**
    
    ... ... @@ -104,12 +105,12 @@ class SerpTelemetryRepository(
    104 105
          */
    
    105 106
         @VisibleForTesting
    
    106 107
         internal suspend fun fetchRemoteResponse(): RemoteSettingsResponse {
    
    107
    -        val result = remoteSettingsClient.fetch()
    
    108
    -        return if (result is RemoteSettingsResult.Success) {
    
    109
    -            result.response
    
    110
    -        } else {
    
    111
    -            RemoteSettingsResponse(emptyList(), 0u)
    
    112
    -        }
    
    108
    +//        val result = remoteSettingsClient.fetch()
    
    109
    +//        return if (result is RemoteSettingsResult.Success) {
    
    110
    +//            result.response
    
    111
    +//        } else {
    
    112
    +        return RemoteSettingsResponse(emptyList(), 0u)
    
    113
    +//        }
    
    113 114
         }
    
    114 115
     
    
    115 116
         /**
    
    ... ... @@ -117,16 +118,16 @@ class SerpTelemetryRepository(
    117 118
          */
    
    118 119
         @VisibleForTesting
    
    119 120
         internal suspend fun loadProvidersFromCache(): Pair<ULong, List<SearchProviderModel>> {
    
    120
    -        val result = remoteSettingsClient.read()
    
    121
    -        return if (result is RemoteSettingsResult.Success) {
    
    122
    -            val response = result.response.records.mapNotNull {
    
    123
    -                it.fields.toSearchProviderModel()
    
    124
    -            }
    
    125
    -            val lastModified = result.response.lastModified
    
    126
    -            Pair(lastModified, response)
    
    127
    -        } else {
    
    128
    -            Pair(0u, emptyList())
    
    129
    -        }
    
    121
    +//        val result = remoteSettingsClient.read()
    
    122
    +//        return if (result is RemoteSettingsResult.Success) {
    
    123
    +//            val response = result.response.records.mapNotNull {
    
    124
    +//                it.fields.toSearchProviderModel()
    
    125
    +//            }
    
    126
    +//            val lastModified = result.response.lastModified
    
    127
    +//            Pair(lastModified, response)
    
    128
    +//        } else {
    
    129
    +        return Pair(0u, emptyList())
    
    130
    +//        }
    
    130 131
         }
    
    131 132
     }
    
    132 133
     
    

  • mobile/android/android-components/components/feature/search/src/test/java/mozilla/components/feature/search/telemetry/BaseSearchTelemetryTest.kt
    ... ... @@ -27,161 +27,161 @@ import java.io.File
    27 27
     @RunWith(AndroidJUnit4::class)
    
    28 28
     class BaseSearchTelemetryTest {
    
    29 29
     
    
    30
    -    private lateinit var baseTelemetry: BaseSearchTelemetry
    
    31
    -    private lateinit var handler: BaseSearchTelemetry.SearchTelemetryMessageHandler
    
    32
    -
    
    33
    -    @Mock
    
    34
    -    private lateinit var mockRepo: SerpTelemetryRepository
    
    35
    -
    
    36
    -    private val mockReadJson: () -> JSONObject = mock()
    
    37
    -    private val mockRootStorageDirectory: File = mock()
    
    38
    -
    
    39
    -    private fun createMockProviderList(): List<SearchProviderModel> = listOf(
    
    40
    -        SearchProviderModel(
    
    41
    -            schema = 1698656464939,
    
    42
    -            taggedCodes = listOf("monline_7_dg"),
    
    43
    -            telemetryId = "baidu",
    
    44
    -            organicCodes = emptyList(),
    
    45
    -            codeParamName = "tn",
    
    46
    -            queryParamNames = listOf("wd"),
    
    47
    -            searchPageRegexp = "^https://(?:m|www)\\\\.baidu\\\\.com/(?:s|baidu)",
    
    48
    -            followOnParamNames = listOf("oq"),
    
    49
    -            extraAdServersRegexps = listOf("^https?://www\\\\.baidu\\\\.com/baidu\\\\.php?"),
    
    50
    -            expectedOrganicCodes = emptyList(),
    
    51
    -        ),
    
    52
    -    )
    
    53
    -
    
    54
    -    private val rawJson = """
    
    55
    -        {
    
    56
    -  "data": [
    
    57
    -    {
    
    58
    -      "schema": 1698656464939,
    
    59
    -      "taggedCodes": [
    
    60
    -        "monline_7_dg"
    
    61
    -      ],
    
    62
    -      "telemetryId": "baidu",
    
    63
    -      "organicCodes": [],
    
    64
    -      "codeParamName": "tn",
    
    65
    -      "queryParamNames": [
    
    66
    -        "wd"
    
    67
    -      ],
    
    68
    -      "searchPageRegexp": "^https://(?:m|www)\\.baidu\\.com/(?:s|baidu)",
    
    69
    -      "followOnParamNames": [
    
    70
    -        "oq"
    
    71
    -      ],
    
    72
    -      "extraAdServersRegexps": [
    
    73
    -        "^https?://www\\.baidu\\.com/baidu\\.php?"
    
    74
    -      ],
    
    75
    -      "id": "19c434a3-d173-4871-9743-290ac92a3f6a",
    
    76
    -      "last_modified": 1698666532326
    
    77
    -    }],
    
    78
    -  "timestamp": 16
    
    79
    -}
    
    80
    -    """.trimIndent()
    
    81
    -
    
    82
    -    @Before
    
    83
    -    fun setup() {
    
    84
    -        baseTelemetry = spy(
    
    85
    -            object : BaseSearchTelemetry() {
    
    86
    -                override suspend fun install(
    
    87
    -                    engine: Engine,
    
    88
    -                    store: BrowserStore,
    
    89
    -                    providerList: List<SearchProviderModel>,
    
    90
    -                ) {
    
    91
    -                    // mock, do nothing
    
    92
    -                }
    
    93
    -
    
    94
    -                override fun processMessage(message: JSONObject) {
    
    95
    -                    // mock, do nothing
    
    96
    -                }
    
    97
    -            },
    
    98
    -        )
    
    99
    -        handler = baseTelemetry.SearchTelemetryMessageHandler()
    
    100
    -        mockRepo = spy(SerpTelemetryRepository(mockRootStorageDirectory, mockReadJson, "test"))
    
    101
    -    }
    
    102
    -
    
    103
    -    @Test
    
    104
    -    fun `GIVEN an engine WHEN installWebExtension is called THEN the provided extension is installed in engine`() {
    
    105
    -        val engine: Engine = mock()
    
    106
    -        val store: BrowserStore = mock()
    
    107
    -        val id = "id"
    
    108
    -        val resourceUrl = "resourceUrl"
    
    109
    -        val messageId = "messageId"
    
    110
    -        val extensionInfo = ExtensionInfo(id, resourceUrl, messageId)
    
    111
    -
    
    112
    -        baseTelemetry.installWebExtension(engine, store, extensionInfo)
    
    113
    -
    
    114
    -        verify(engine).installBuiltInWebExtension(
    
    115
    -            id = eq(id),
    
    116
    -            url = eq(resourceUrl),
    
    117
    -            onSuccess = any(),
    
    118
    -            onError = any(),
    
    119
    -        )
    
    120
    -    }
    
    121
    -
    
    122
    -    @Test
    
    123
    -    fun `GIVEN a search provider does not exist for the url WHEN getProviderForUrl is called THEN return null`() {
    
    124
    -        val url = "https://www.mozilla.com/search?q=firefox"
    
    125
    -        baseTelemetry.providerList = createMockProviderList()
    
    126
    -
    
    127
    -        assertEquals(null, baseTelemetry.getProviderForUrl(url))
    
    128
    -    }
    
    129
    -
    
    130
    -    @Test(expected = IllegalStateException::class)
    
    131
    -    fun `GIVEN an extension message WHEN that cannot be processed THEN throw IllegalStateException`() {
    
    132
    -        val message = "message"
    
    133
    -
    
    134
    -        handler.onMessage(message, mock())
    
    135
    -    }
    
    136
    -
    
    137
    -    @Test
    
    138
    -    fun `GIVEN an extension message WHEN received THEN pass it to processMessage`() {
    
    139
    -        val message = JSONObject()
    
    140
    -
    
    141
    -        handler.onMessage(message, mock())
    
    142
    -
    
    143
    -        verify(baseTelemetry).processMessage(message)
    
    144
    -    }
    
    145
    -
    
    146
    -    @Test
    
    147
    -    fun `GIVEN empty cacheResponse WHEN initializeProviderList is called THEN  update providerList`(): Unit =
    
    148
    -        runBlocking {
    
    149
    -            val localResponse = JSONObject(rawJson)
    
    150
    -            val cacheResponse: Pair<ULong, List<SearchProviderModel>> = Pair(0u, emptyList())
    
    151
    -
    
    152
    -            `when`(mockRepo.loadProvidersFromCache()).thenReturn(cacheResponse)
    
    153
    -            doAnswer {
    
    154
    -                localResponse
    
    155
    -            }.`when`(mockReadJson)()
    
    156
    -
    
    157
    -            `when`(mockRepo.parseLocalPreinstalledData(localResponse)).thenReturn(createMockProviderList())
    
    158
    -            doReturn(Unit).`when`(mockRepo).fetchRemoteResponse(any())
    
    159
    -
    
    160
    -            baseTelemetry.setProviderList(mockRepo.updateProviderList())
    
    161
    -
    
    162
    -            assertEquals(baseTelemetry.providerList.toString(), createMockProviderList().toString())
    
    163
    -        }
    
    164
    -
    
    165
    -    @Test
    
    166
    -    fun `GIVEN non-empty cacheResponse WHEN initializeProviderList is called THEN update providerList`(): Unit =
    
    167
    -        runBlocking {
    
    168
    -            val localResponse = JSONObject(rawJson)
    
    169
    -            val cacheResponse: Pair<ULong, List<SearchProviderModel>> = Pair(123u, createMockProviderList())
    
    170
    -
    
    171
    -            `when`(mockRepo.loadProvidersFromCache()).thenReturn(cacheResponse)
    
    172
    -            doAnswer {
    
    173
    -                localResponse
    
    174
    -            }.`when`(mockReadJson)()
    
    175
    -            doReturn(Unit).`when`(mockRepo).fetchRemoteResponse(any())
    
    176
    -
    
    177
    -            baseTelemetry.setProviderList(mockRepo.updateProviderList())
    
    178
    -
    
    179
    -            assertEquals(baseTelemetry.providerList.toString(), createMockProviderList().toString())
    
    180
    -        }
    
    181
    -
    
    182
    -    fun getProviderForUrl(url: String): SearchProviderModel? {
    
    183
    -        return createMockProviderList().find { provider ->
    
    184
    -            provider.searchPageRegexp.pattern.toRegex().containsMatchIn(url)
    
    185
    -        }
    
    186
    -    }
    
    30
    +//    private lateinit var baseTelemetry: BaseSearchTelemetry
    
    31
    +//    private lateinit var handler: BaseSearchTelemetry.SearchTelemetryMessageHandler
    
    32
    +//
    
    33
    +//    @Mock
    
    34
    +//    private lateinit var mockRepo: SerpTelemetryRepository
    
    35
    +//
    
    36
    +//    private val mockReadJson: () -> JSONObject = mock()
    
    37
    +//    private val mockRootStorageDirectory: File = mock()
    
    38
    +//
    
    39
    +//    private fun createMockProviderList(): List<SearchProviderModel> = listOf(
    
    40
    +//        SearchProviderModel(
    
    41
    +//            schema = 1698656464939,
    
    42
    +//            taggedCodes = listOf("monline_7_dg"),
    
    43
    +//            telemetryId = "baidu",
    
    44
    +//            organicCodes = emptyList(),
    
    45
    +//            codeParamName = "tn",
    
    46
    +//            queryParamNames = listOf("wd"),
    
    47
    +//            searchPageRegexp = "^https://(?:m|www)\\\\.baidu\\\\.com/(?:s|baidu)",
    
    48
    +//            followOnParamNames = listOf("oq"),
    
    49
    +//            extraAdServersRegexps = listOf("^https?://www\\\\.baidu\\\\.com/baidu\\\\.php?"),
    
    50
    +//            expectedOrganicCodes = emptyList(),
    
    51
    +//        ),
    
    52
    +//    )
    
    53
    +//
    
    54
    +//    private val rawJson = """
    
    55
    +//        {
    
    56
    +//  "data": [
    
    57
    +//    {
    
    58
    +//      "schema": 1698656464939,
    
    59
    +//      "taggedCodes": [
    
    60
    +//        "monline_7_dg"
    
    61
    +//      ],
    
    62
    +//      "telemetryId": "baidu",
    
    63
    +//      "organicCodes": [],
    
    64
    +//      "codeParamName": "tn",
    
    65
    +//      "queryParamNames": [
    
    66
    +//        "wd"
    
    67
    +//      ],
    
    68
    +//      "searchPageRegexp": "^https://(?:m|www)\\.baidu\\.com/(?:s|baidu)",
    
    69
    +//      "followOnParamNames": [
    
    70
    +//        "oq"
    
    71
    +//      ],
    
    72
    +//      "extraAdServersRegexps": [
    
    73
    +//        "^https?://www\\.baidu\\.com/baidu\\.php?"
    
    74
    +//      ],
    
    75
    +//      "id": "19c434a3-d173-4871-9743-290ac92a3f6a",
    
    76
    +//      "last_modified": 1698666532326
    
    77
    +//    }],
    
    78
    +//  "timestamp": 16
    
    79
    +//}
    
    80
    +//    """.trimIndent()
    
    81
    +//
    
    82
    +//    @Before
    
    83
    +//    fun setup() {
    
    84
    +//        baseTelemetry = spy(
    
    85
    +//            object : BaseSearchTelemetry() {
    
    86
    +//                override suspend fun install(
    
    87
    +//                    engine: Engine,
    
    88
    +//                    store: BrowserStore,
    
    89
    +//                    providerList: List<SearchProviderModel>,
    
    90
    +//                ) {
    
    91
    +//                    // mock, do nothing
    
    92
    +//                }
    
    93
    +//
    
    94
    +//                override fun processMessage(message: JSONObject) {
    
    95
    +//                    // mock, do nothing
    
    96
    +//                }
    
    97
    +//            },
    
    98
    +//        )
    
    99
    +//        handler = baseTelemetry.SearchTelemetryMessageHandler()
    
    100
    +//        mockRepo = spy(SerpTelemetryRepository(mockRootStorageDirectory, mockReadJson, "test"))
    
    101
    +//    }
    
    102
    +//
    
    103
    +//    @Test
    
    104
    +//    fun `GIVEN an engine WHEN installWebExtension is called THEN the provided extension is installed in engine`() {
    
    105
    +//        val engine: Engine = mock()
    
    106
    +//        val store: BrowserStore = mock()
    
    107
    +//        val id = "id"
    
    108
    +//        val resourceUrl = "resourceUrl"
    
    109
    +//        val messageId = "messageId"
    
    110
    +//        val extensionInfo = ExtensionInfo(id, resourceUrl, messageId)
    
    111
    +//
    
    112
    +//        baseTelemetry.installWebExtension(engine, store, extensionInfo)
    
    113
    +//
    
    114
    +//        verify(engine).installBuiltInWebExtension(
    
    115
    +//            id = eq(id),
    
    116
    +//            url = eq(resourceUrl),
    
    117
    +//            onSuccess = any(),
    
    118
    +//            onError = any(),
    
    119
    +//        )
    
    120
    +//    }
    
    121
    +//
    
    122
    +//    @Test
    
    123
    +//    fun `GIVEN a search provider does not exist for the url WHEN getProviderForUrl is called THEN return null`() {
    
    124
    +//        val url = "https://www.mozilla.com/search?q=firefox"
    
    125
    +//        baseTelemetry.providerList = createMockProviderList()
    
    126
    +//
    
    127
    +//        assertEquals(null, baseTelemetry.getProviderForUrl(url))
    
    128
    +//    }
    
    129
    +//
    
    130
    +//    @Test(expected = IllegalStateException::class)
    
    131
    +//    fun `GIVEN an extension message WHEN that cannot be processed THEN throw IllegalStateException`() {
    
    132
    +//        val message = "message"
    
    133
    +//
    
    134
    +//        handler.onMessage(message, mock())
    
    135
    +//    }
    
    136
    +//
    
    137
    +//    @Test
    
    138
    +//    fun `GIVEN an extension message WHEN received THEN pass it to processMessage`() {
    
    139
    +//        val message = JSONObject()
    
    140
    +//
    
    141
    +//        handler.onMessage(message, mock())
    
    142
    +//
    
    143
    +//        verify(baseTelemetry).processMessage(message)
    
    144
    +//    }
    
    145
    +//
    
    146
    +//    @Test
    
    147
    +//    fun `GIVEN empty cacheResponse WHEN initializeProviderList is called THEN  update providerList`(): Unit =
    
    148
    +//        runBlocking {
    
    149
    +//            val localResponse = JSONObject(rawJson)
    
    150
    +//            val cacheResponse: Pair<ULong, List<SearchProviderModel>> = Pair(0u, emptyList())
    
    151
    +//
    
    152
    +//            `when`(mockRepo.loadProvidersFromCache()).thenReturn(cacheResponse)
    
    153
    +//            doAnswer {
    
    154
    +//                localResponse
    
    155
    +//            }.`when`(mockReadJson)()
    
    156
    +//
    
    157
    +//            `when`(mockRepo.parseLocalPreinstalledData(localResponse)).thenReturn(createMockProviderList())
    
    158
    +//            doReturn(Unit).`when`(mockRepo).fetchRemoteResponse(any())
    
    159
    +//
    
    160
    +//            baseTelemetry.setProviderList(mockRepo.updateProviderList())
    
    161
    +//
    
    162
    +//            assertEquals(baseTelemetry.providerList.toString(), createMockProviderList().toString())
    
    163
    +//        }
    
    164
    +//
    
    165
    +//    @Test
    
    166
    +//    fun `GIVEN non-empty cacheResponse WHEN initializeProviderList is called THEN update providerList`(): Unit =
    
    167
    +//        runBlocking {
    
    168
    +//            val localResponse = JSONObject(rawJson)
    
    169
    +//            val cacheResponse: Pair<ULong, List<SearchProviderModel>> = Pair(123u, createMockProviderList())
    
    170
    +//
    
    171
    +//            `when`(mockRepo.loadProvidersFromCache()).thenReturn(cacheResponse)
    
    172
    +//            doAnswer {
    
    173
    +//                localResponse
    
    174
    +//            }.`when`(mockReadJson)()
    
    175
    +//            doReturn(Unit).`when`(mockRepo).fetchRemoteResponse(any())
    
    176
    +//
    
    177
    +//            baseTelemetry.setProviderList(mockRepo.updateProviderList())
    
    178
    +//
    
    179
    +//            assertEquals(baseTelemetry.providerList.toString(), createMockProviderList().toString())
    
    180
    +//        }
    
    181
    +//
    
    182
    +//    fun getProviderForUrl(url: String): SearchProviderModel? {
    
    183
    +//        return createMockProviderList().find { provider ->
    
    184
    +//            provider.searchPageRegexp.pattern.toRegex().containsMatchIn(url)
    
    185
    +//        }
    
    186
    +//    }
    
    187 187
     }

  • mobile/android/android-components/components/feature/search/src/test/java/mozilla/components/feature/search/telemetry/SerpTelemetryRepositoryTest.kt
    ... ... @@ -23,70 +23,70 @@ import org.robolectric.RobolectricTestRunner
    23 23
     
    
    24 24
     @RunWith(RobolectricTestRunner::class)
    
    25 25
     class SerpTelemetryRepositoryTest {
    
    26
    -    @Mock
    
    27
    -    private lateinit var mockRemoteSettingsClient: RemoteSettingsClient
    
    28
    -
    
    29
    -    private lateinit var serpTelemetryRepository: SerpTelemetryRepository
    
    30
    -
    
    31
    -    @Before
    
    32
    -    fun setup() {
    
    33
    -        MockitoAnnotations.openMocks(this)
    
    34
    -        serpTelemetryRepository = SerpTelemetryRepository(
    
    35
    -            rootStorageDirectory = mock(),
    
    36
    -            readJson = mock(),
    
    37
    -            collectionName = "",
    
    38
    -            serverUrl = "https://test.server",
    
    39
    -            bucketName = "",
    
    40
    -        )
    
    41
    -
    
    42
    -        serpTelemetryRepository.remoteSettingsClient = mockRemoteSettingsClient
    
    43
    -    }
    
    44
    -
    
    45
    -    @Test
    
    46
    -    fun `GIVEN non-empty response WHEN writeToCache is called THEN the result is a success`() = runBlocking {
    
    47
    -        val records = listOf(
    
    48
    -            RemoteSettingsRecord("1", 123u, false, null, JSONObject()),
    
    49
    -            RemoteSettingsRecord("2", 456u, true, null, JSONObject()),
    
    50
    -        )
    
    51
    -        val response = RemoteSettingsResponse(records, 125614567U)
    
    52
    -
    
    53
    -        `when`(mockRemoteSettingsClient.write(response))
    
    54
    -            .thenReturn(RemoteSettingsResult.Success(response))
    
    55
    -
    
    56
    -        val result = serpTelemetryRepository.writeToCache(response)
    
    57
    -
    
    58
    -        assertTrue(result is RemoteSettingsResult.Success)
    
    59
    -        assertEquals(response, (result as RemoteSettingsResult.Success).response)
    
    60
    -    }
    
    61
    -
    
    62
    -    @Test
    
    63
    -    fun `GIVEN non-empty response WHEN fetchRemoteResponse is called THEN the result is equal to the response`() = runBlocking {
    
    64
    -        val records = listOf(
    
    65
    -            RemoteSettingsRecord("1", 123u, false, null, JSONObject()),
    
    66
    -            RemoteSettingsRecord("2", 456u, true, null, JSONObject()),
    
    67
    -        )
    
    68
    -        val response = RemoteSettingsResponse(records, 125614567U)
    
    69
    -        `when`(mockRemoteSettingsClient.fetch())
    
    70
    -            .thenReturn(RemoteSettingsResult.Success(response))
    
    71
    -
    
    72
    -        val result = serpTelemetryRepository.fetchRemoteResponse()
    
    73
    -
    
    74
    -        assertEquals(response, result)
    
    75
    -    }
    
    76
    -
    
    77
    -    @Test
    
    78
    -    fun `GIVEN non-empty response WHEN loadProvidersFromCache is called THEN the result is equal to the response`() = runBlocking {
    
    79
    -        val records = listOf(
    
    80
    -            RemoteSettingsRecord("1", 123u, false, null, JSONObject()),
    
    81
    -            RemoteSettingsRecord("2", 456u, true, null, JSONObject()),
    
    82
    -        )
    
    83
    -        val response = RemoteSettingsResponse(records, 125614567U)
    
    84
    -        `when`(mockRemoteSettingsClient.read())
    
    85
    -            .thenReturn(RemoteSettingsResult.Success(response))
    
    86
    -
    
    87
    -        val result = serpTelemetryRepository.loadProvidersFromCache()
    
    88
    -
    
    89
    -        assertEquals(response.lastModified, result.first)
    
    90
    -        assertEquals(response.records.mapNotNull { it.fields.toSearchProviderModel() }, result.second)
    
    91
    -    }
    
    26
    +//    @Mock
    
    27
    +//    private lateinit var mockRemoteSettingsClient: RemoteSettingsClient
    
    28
    +//
    
    29
    +//    private lateinit var serpTelemetryRepository: SerpTelemetryRepository
    
    30
    +//
    
    31
    +//    @Before
    
    32
    +//    fun setup() {
    
    33
    +//        MockitoAnnotations.openMocks(this)
    
    34
    +//        serpTelemetryRepository = SerpTelemetryRepository(
    
    35
    +//            rootStorageDirectory = mock(),
    
    36
    +//            readJson = mock(),
    
    37
    +//            collectionName = "",
    
    38
    +//            serverUrl = "https://test.server",
    
    39
    +//            bucketName = "",
    
    40
    +//        )
    
    41
    +//
    
    42
    +//        serpTelemetryRepository.remoteSettingsClient = mockRemoteSettingsClient
    
    43
    +//    }
    
    44
    +//
    
    45
    +//    @Test
    
    46
    +//    fun `GIVEN non-empty response WHEN writeToCache is called THEN the result is a success`() = runBlocking {
    
    47
    +//        val records = listOf(
    
    48
    +//            RemoteSettingsRecord("1", 123u, false, null, JSONObject()),
    
    49
    +//            RemoteSettingsRecord("2", 456u, true, null, JSONObject()),
    
    50
    +//        )
    
    51
    +//        val response = RemoteSettingsResponse(records, 125614567U)
    
    52
    +//
    
    53
    +//        `when`(mockRemoteSettingsClient.write(response))
    
    54
    +//            .thenReturn(RemoteSettingsResult.Success(response))
    
    55
    +//
    
    56
    +//        val result = serpTelemetryRepository.writeToCache(response)
    
    57
    +//
    
    58
    +//        assertTrue(result is RemoteSettingsResult.Success)
    
    59
    +//        assertEquals(response, (result as RemoteSettingsResult.Success).response)
    
    60
    +//    }
    
    61
    +//
    
    62
    +//    @Test
    
    63
    +//    fun `GIVEN non-empty response WHEN fetchRemoteResponse is called THEN the result is equal to the response`() = runBlocking {
    
    64
    +//        val records = listOf(
    
    65
    +//            RemoteSettingsRecord("1", 123u, false, null, JSONObject()),
    
    66
    +//            RemoteSettingsRecord("2", 456u, true, null, JSONObject()),
    
    67
    +//        )
    
    68
    +//        val response = RemoteSettingsResponse(records, 125614567U)
    
    69
    +//        `when`(mockRemoteSettingsClient.fetch())
    
    70
    +//            .thenReturn(RemoteSettingsResult.Success(response))
    
    71
    +//
    
    72
    +//        val result = serpTelemetryRepository.fetchRemoteResponse()
    
    73
    +//
    
    74
    +//        assertEquals(response, result)
    
    75
    +//    }
    
    76
    +//
    
    77
    +//    @Test
    
    78
    +//    fun `GIVEN non-empty response WHEN loadProvidersFromCache is called THEN the result is equal to the response`() = runBlocking {
    
    79
    +//        val records = listOf(
    
    80
    +//            RemoteSettingsRecord("1", 123u, false, null, JSONObject()),
    
    81
    +//            RemoteSettingsRecord("2", 456u, true, null, JSONObject()),
    
    82
    +//        )
    
    83
    +//        val response = RemoteSettingsResponse(records, 125614567U)
    
    84
    +//        `when`(mockRemoteSettingsClient.read())
    
    85
    +//            .thenReturn(RemoteSettingsResult.Success(response))
    
    86
    +//
    
    87
    +//        val result = serpTelemetryRepository.loadProvidersFromCache()
    
    88
    +//
    
    89
    +//        assertEquals(response.lastModified, result.first)
    
    90
    +//        assertEquals(response.records.mapNotNull { it.fields.toSearchProviderModel() }, result.second)
    
    91
    +//    }
    
    92 92
     }

  • mobile/android/android-components/components/support/remotesettings/src/main/java/mozilla/components/support/remotesettings/RemoteSettingsClient.kt
    ... ... @@ -64,18 +64,20 @@ class RemoteSettingsClient(
    64 64
          */
    
    65 65
         @Suppress("TooGenericExceptionCaught")
    
    66 66
         suspend fun fetch(): RemoteSettingsResult = withContext(Dispatchers.IO) {
    
    67
    -        try {
    
    68
    -            val serverRecords = RemoteSettings(config).use {
    
    69
    -                it.getRecords()
    
    70
    -            }
    
    71
    -            RemoteSettingsResult.Success(serverRecords)
    
    72
    -        } catch (e: RemoteSettingsException) {
    
    73
    -            Logger.error(e.message.toString())
    
    74
    -            RemoteSettingsResult.NetworkFailure(e)
    
    75
    -        } catch (e: NullPointerException) {
    
    76
    -            Logger.error(e.message.toString())
    
    77
    -            RemoteSettingsResult.NetworkFailure(e)
    
    78
    -        }
    
    67
    +//        try {
    
    68
    +//            val serverRecords = RemoteSettings(config).use {
    
    69
    +//                it.getRecords()
    
    70
    +//            }
    
    71
    +//            RemoteSettingsResult.Success(serverRecords)
    
    72
    +//        } catch (e: RemoteSettingsException) {
    
    73
    +//            Logger.error(e.message.toString())
    
    74
    +//            RemoteSettingsResult.NetworkFailure(e)
    
    75
    +//        } catch (e: NullPointerException) {
    
    76
    +//            Logger.error(e.message.toString())
    
    77
    +//            RemoteSettingsResult.NetworkFailure(e)
    
    78
    +//        }
    
    79
    +        RemoteSettingsResult.NetworkFailure(Exception("tb-43113: no remote fetching"))
    
    80
    +
    
    79 81
         }
    
    80 82
     
    
    81 83
         /**
    
    ... ... @@ -123,7 +125,8 @@ class RemoteSettingsClient(
    123 125
     suspend fun RemoteSettingsClient.readOrFetch(): RemoteSettingsResult {
    
    124 126
         val readResult = read()
    
    125 127
         return if (readResult is RemoteSettingsResult.DiskFailure) {
    
    126
    -        fetch()
    
    128
    +        //fetch()
    
    129
    +        RemoteSettingsResult.NetworkFailure(Exception("tb-43113: no remote fetching"))
    
    127 130
         } else {
    
    128 131
             readResult
    
    129 132
         }