File tree Expand file tree Collapse file tree 3 files changed +44
-0
lines changed
androidTest/java/com/duckduckgo/app/browser
main/java/com/duckduckgo/app Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -7016,6 +7016,32 @@ class BrowserTabViewModelTest {
7016
7016
assertEquals(1 , fakeAddDocumentStartJavaScriptPlugins.otherPlugin.countInitted)
7017
7017
}
7018
7018
7019
+ @Test
7020
+ fun whenPrivacyProtectionsUpdatedAndPauseWebViewBeforeUpdatingScriptEnabledThenWebViewPausedBeforeAddingScript () =
7021
+ runTest {
7022
+ fakeAndroidConfigBrowserFeature.updateScriptOnPageFinished().setRawStoredState(State (true ))
7023
+ fakeAndroidConfigBrowserFeature.pauseWebViewBeforeUpdatingScript().setRawStoredState(State (true ))
7024
+
7025
+ testee.privacyProtectionsUpdated(mockWebView)
7026
+
7027
+ verify(mockWebView).stopLoading()
7028
+ verify(mockWebView).pauseTimers()
7029
+ verify(mockWebView).resumeTimers()
7030
+ }
7031
+
7032
+ @Test
7033
+ fun whenPrivacyProtectionsUpdatedAndPauseWebViewBeforeUpdatingScriptDisabledThenDoNotWebViewPausedBeforeAddingScript () =
7034
+ runTest {
7035
+ fakeAndroidConfigBrowserFeature.updateScriptOnPageFinished().setRawStoredState(State (true ))
7036
+ fakeAndroidConfigBrowserFeature.pauseWebViewBeforeUpdatingScript().setRawStoredState(State (false ))
7037
+
7038
+ testee.privacyProtectionsUpdated(mockWebView)
7039
+
7040
+ verify(mockWebView, never()).stopLoading()
7041
+ verify(mockWebView, never()).pauseTimers()
7042
+ verify(mockWebView, never()).resumeTimers()
7043
+ }
7044
+
7019
7045
@Test
7020
7046
fun whenPrivacyProtectionsUpdatedAndUpdateScriptOnPageFinishedTrueAndUpdateScriptOnProtectionsChangedFalseThenNotAddDocumentStartJavaScript () =
7021
7047
runTest {
Original file line number Diff line number Diff line change @@ -4261,6 +4261,17 @@ class BrowserTabViewModel @Inject constructor(
4261
4261
return
4262
4262
}
4263
4263
4264
+ val pauseWebViewBeforeUpdatingScript = withContext(dispatchers.io()) {
4265
+ androidBrowserConfig.pauseWebViewBeforeUpdatingScript().isEnabled()
4266
+ }
4267
+
4268
+ if (pauseWebViewBeforeUpdatingScript) {
4269
+ withContext(dispatchers.main()) {
4270
+ webView.stopLoading()
4271
+ webView.pauseTimers()
4272
+ }
4273
+ }
4274
+
4264
4275
if (withContext(dispatchers.io()) { ! androidBrowserConfig.updateScriptOnPageFinished().isEnabled() }) {
4265
4276
addDocumentStartJavascriptPlugins
4266
4277
.getPlugins()
@@ -4272,6 +4283,10 @@ class BrowserTabViewModel @Inject constructor(
4272
4283
} else {
4273
4284
addDocumentStartJavaScript(webView)
4274
4285
}
4286
+
4287
+ if (pauseWebViewBeforeUpdatingScript) {
4288
+ webView.resumeTimers()
4289
+ }
4275
4290
}
4276
4291
4277
4292
fun onUserDismissedAutoCompleteInAppMessage () {
Original file line number Diff line number Diff line change @@ -194,4 +194,7 @@ interface AndroidBrowserConfigFeature {
194
194
195
195
@Toggle.DefaultValue (TRUE )
196
196
fun updateScriptOnProtectionsChanged (): Toggle
197
+
198
+ @Toggle.DefaultValue (TRUE )
199
+ fun pauseWebViewBeforeUpdatingScript (): Toggle
197
200
}
You can’t perform that action at this time.
0 commit comments