@@ -41,7 +41,6 @@ import androidx.lifecycle.LiveData
4141import androidx.lifecycle.MutableLiveData
4242import androidx.lifecycle.Observer
4343import androidx.room.Room
44- import androidx.test.annotation.UiThreadTest
4544import androidx.test.filters.SdkSuppress
4645import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
4746import com.duckduckgo.adclick.api.AdClickManager
@@ -617,10 +616,6 @@ class BrowserTabViewModelTest {
617616
618617 private val mockWebView: WebView = mock()
619618
620- private val fakeAddDocumentStartJavaScriptPlugins = FakeAddDocumentStartJavaScriptPluginPoint ()
621- private val fakeMessagingPlugins = FakeWebMessagingPluginPoint ()
622- private val fakePostMessageWrapperPlugins = FakePostMessageWrapperPluginPoint ()
623-
624619 private val mockDeviceAppLookup: DeviceAppLookup = mock()
625620
626621 @Before
@@ -850,9 +845,6 @@ class BrowserTabViewModelTest {
850845 externalIntentProcessingState = mockExternalIntentProcessingState,
851846 vpnMenuStateProvider = mockVpnMenuStateProvider,
852847 webViewCompatWrapper = mockWebViewCompatWrapper,
853- addDocumentStartJavascriptPlugins = fakeAddDocumentStartJavaScriptPlugins,
854- webMessagingPlugins = fakeMessagingPlugins,
855- postMessageWrapperPlugins = fakePostMessageWrapperPlugins,
856848 addressBarTrackersAnimationFeatureToggle = mockAddressBarTrackersAnimationFeatureToggle,
857849 autoconsentPixelManager = mockAutoconsentPixelManager,
858850 )
@@ -7091,102 +7083,6 @@ class BrowserTabViewModelTest {
70917083 verify(mockOnboardingDesignExperimentManager).onWebPageFinishedLoading(url)
70927084 }
70937085
7094- @Test
7095- fun whenPageFinishedAndUpdateScriptOnPageFinishedEnabledThenAddDocumentStartJavaScript () =
7096- runTest {
7097- val url = " https://example.com"
7098- val webViewNavState = WebViewNavigationState (mockStack, 100 )
7099- fakeAndroidConfigBrowserFeature.updateScriptOnPageFinished().setRawStoredState(State (true ))
7100-
7101- testee.pageFinished(mockWebView, webViewNavState, url)
7102-
7103- assertEquals(1 , fakeAddDocumentStartJavaScriptPlugins.cssPlugin.countInitted)
7104- assertEquals(1 , fakeAddDocumentStartJavaScriptPlugins.otherPlugin.countInitted)
7105- }
7106-
7107- @Test
7108- fun whenPageFinishedAndUpdateScriptOnPageFinishedDisabledThenDoNotCallAddDocumentStartJavaScript () =
7109- runTest {
7110- val url = " https://example.com"
7111- val webViewNavState = WebViewNavigationState (mockStack, 100 )
7112- fakeAndroidConfigBrowserFeature.updateScriptOnPageFinished().setRawStoredState(State (false ))
7113-
7114- testee.pageFinished(mockWebView, webViewNavState, url)
7115-
7116- assertEquals(0 , fakeAddDocumentStartJavaScriptPlugins.cssPlugin.countInitted)
7117- assertEquals(0 , fakeAddDocumentStartJavaScriptPlugins.otherPlugin.countInitted)
7118- }
7119-
7120- @Test
7121- fun whenPrivacyProtectionsUpdatedAndUpdateScriptOnPageFinishedEnabledAndUpdateScriptOnProtectionsChangedEnabledThenAddDocumentStartJavaScript () =
7122- runTest {
7123- fakeAndroidConfigBrowserFeature.updateScriptOnPageFinished().setRawStoredState(State (true ))
7124- fakeAndroidConfigBrowserFeature.updateScriptOnProtectionsChanged().setRawStoredState(State (true ))
7125-
7126- testee.privacyProtectionsUpdated(mockWebView)
7127-
7128- assertEquals(1 , fakeAddDocumentStartJavaScriptPlugins.cssPlugin.countInitted)
7129- assertEquals(1 , fakeAddDocumentStartJavaScriptPlugins.otherPlugin.countInitted)
7130- }
7131-
7132- @Test
7133- fun whenPrivacyProtectionsUpdatedAndUpdateScriptOnProtectionsChangedEnabledAndStopLoadingBeforeUpdatingScriptEnabledThenStopLoading () =
7134- runTest {
7135- fakeAndroidConfigBrowserFeature.updateScriptOnProtectionsChanged().setRawStoredState(State (true ))
7136- fakeAndroidConfigBrowserFeature.stopLoadingBeforeUpdatingScript().setRawStoredState(State (true ))
7137-
7138- testee.privacyProtectionsUpdated(mockWebView)
7139-
7140- verify(mockWebView).stopLoading()
7141- }
7142-
7143- @Test
7144- fun whenPrivacyProtectionsUpdatedAndUpdateScriptOnProtectionsChangedEnabledAndStopLoadingBeforeUpdatingScriptDisabledThenDoNotStopLoading () =
7145- runTest {
7146- fakeAndroidConfigBrowserFeature.updateScriptOnProtectionsChanged().setRawStoredState(State (true ))
7147- fakeAndroidConfigBrowserFeature.stopLoadingBeforeUpdatingScript().setRawStoredState(State (false ))
7148-
7149- testee.privacyProtectionsUpdated(mockWebView)
7150-
7151- verify(mockWebView, never()).stopLoading()
7152- }
7153-
7154- @Test
7155- fun whenPrivacyProtectionsUpdatedAndUpdateScriptOnPageFinishedTrueAndUpdateScriptOnProtectionsChangedFalseThenNotAddDocumentStartJavaScript () =
7156- runTest {
7157- fakeAndroidConfigBrowserFeature.updateScriptOnPageFinished().setRawStoredState(State (true ))
7158- fakeAndroidConfigBrowserFeature.updateScriptOnProtectionsChanged().setRawStoredState(State (false ))
7159-
7160- testee.privacyProtectionsUpdated(mockWebView)
7161-
7162- assertEquals(0 , fakeAddDocumentStartJavaScriptPlugins.cssPlugin.countInitted)
7163- assertEquals(0 , fakeAddDocumentStartJavaScriptPlugins.otherPlugin.countInitted)
7164- }
7165-
7166- @Test
7167- fun whenPrivacyProtectionsUpdatedAndUpdateScriptOnPageFinishedDisabledThenAddDocumentStartJavaScriptOnlyOnCSS () =
7168- runTest {
7169- fakeAndroidConfigBrowserFeature.updateScriptOnPageFinished().setRawStoredState(State (false ))
7170- fakeAndroidConfigBrowserFeature.updateScriptOnProtectionsChanged().setRawStoredState(State (true ))
7171-
7172- testee.privacyProtectionsUpdated(mockWebView)
7173-
7174- assertEquals(1 , fakeAddDocumentStartJavaScriptPlugins.cssPlugin.countInitted)
7175- assertEquals(0 , fakeAddDocumentStartJavaScriptPlugins.otherPlugin.countInitted)
7176- }
7177-
7178- @Test
7179- fun whenPrivacyProtectionsUpdatedAndUpdateScriptOnPageFinishedFalseAndUpdateScriptOnProtectionsChangedFalseThenNotAddDocumentStartJavaScript () =
7180- runTest {
7181- fakeAndroidConfigBrowserFeature.updateScriptOnPageFinished().setRawStoredState(State (false ))
7182- fakeAndroidConfigBrowserFeature.updateScriptOnProtectionsChanged().setRawStoredState(State (false ))
7183-
7184- testee.privacyProtectionsUpdated(mockWebView)
7185-
7186- assertEquals(0 , fakeAddDocumentStartJavaScriptPlugins.cssPlugin.countInitted)
7187- assertEquals(0 , fakeAddDocumentStartJavaScriptPlugins.otherPlugin.countInitted)
7188- }
7189-
71907086 @Test
71917087 fun whenCtaShownThenFireInContextDialogShownPixel () =
71927088 runTest {
@@ -7689,46 +7585,6 @@ class BrowserTabViewModelTest {
76897585 assertNull(" SERP logo should be cleared when navigating to non-DuckDuckGo URL" , omnibarViewState().serpLogo)
76907586 }
76917587
7692- @UiThreadTest
7693- @Test
7694- fun whenConfigureWebViewThenCallAddDocumentStartJavaScript () =
7695- runTest {
7696- val mockCallback = mock<WebViewCompatMessageCallback >()
7697- val webView = DuckDuckGoWebView (context)
7698- assertEquals(0 , fakeAddDocumentStartJavaScriptPlugins.cssPlugin.countInitted)
7699-
7700- testee.configureWebView(webView, mockCallback)
7701-
7702- assertEquals(1 , fakeAddDocumentStartJavaScriptPlugins.cssPlugin.countInitted)
7703- }
7704-
7705- @UiThreadTest
7706- @Test
7707- fun whenConfigureWebViewThenCallAddMessageListener () =
7708- runTest {
7709- val mockCallback = mock<WebViewCompatMessageCallback >()
7710- val webView = DuckDuckGoWebView (context)
7711- assertFalse(fakeMessagingPlugins.plugin.registered)
7712-
7713- testee.configureWebView(webView, mockCallback)
7714-
7715- assertTrue(fakeMessagingPlugins.plugin.registered)
7716- }
7717-
7718- @UiThreadTest
7719- @Test
7720- fun whenPostMessageThenCallPostContentScopeMessage () =
7721- runTest {
7722- val data = SubscriptionEventData (" feature" , " method" , JSONObject ())
7723- val webView = DuckDuckGoWebView (context)
7724-
7725- assertFalse(fakePostMessageWrapperPlugins.plugin.postMessageCalled)
7726-
7727- testee.postContentScopeMessage(data, webView)
7728-
7729- assertTrue(fakePostMessageWrapperPlugins.plugin.postMessageCalled)
7730- }
7731-
77327588 private fun aCredential (): LoginCredentials = LoginCredentials (domain = null , username = null , password = null )
77337589
77347590 private fun assertShowHistoryCommandSent (expectedStackSize : Int ) {
0 commit comments