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 @@ -7015,6 +7015,32 @@ class BrowserTabViewModelTest {
7015
7015
assertEquals(1 , fakeAddDocumentStartJavaScriptPlugins.otherPlugin.countInitted)
7016
7016
}
7017
7017
7018
+ @Test
7019
+ fun whenPrivacyProtectionsUpdatedAndPauseWebViewBeforeUpdatingScriptEnabledThenWebViewPausedBeforeAddingScript () =
7020
+ runTest {
7021
+ fakeAndroidConfigBrowserFeature.updateScriptOnPageFinished().setRawStoredState(State (true ))
7022
+ fakeAndroidConfigBrowserFeature.pauseWebViewBeforeUpdatingScript().setRawStoredState(State (true ))
7023
+
7024
+ testee.privacyProtectionsUpdated(mockWebView)
7025
+
7026
+ verify(mockWebView).stopLoading()
7027
+ verify(mockWebView).pauseTimers()
7028
+ verify(mockWebView).resumeTimers()
7029
+ }
7030
+
7031
+ @Test
7032
+ fun whenPrivacyProtectionsUpdatedAndPauseWebViewBeforeUpdatingScriptDisabledThenDoNotWebViewPausedBeforeAddingScript () =
7033
+ runTest {
7034
+ fakeAndroidConfigBrowserFeature.updateScriptOnPageFinished().setRawStoredState(State (true ))
7035
+ fakeAndroidConfigBrowserFeature.pauseWebViewBeforeUpdatingScript().setRawStoredState(State (false ))
7036
+
7037
+ testee.privacyProtectionsUpdated(mockWebView)
7038
+
7039
+ verify(mockWebView, never()).stopLoading()
7040
+ verify(mockWebView, never()).pauseTimers()
7041
+ verify(mockWebView, never()).resumeTimers()
7042
+ }
7043
+
7018
7044
@Test
7019
7045
fun whenPrivacyProtectionsUpdatedAndAndUpdateScriptOnPageFinishedDisabledThenAddDocumentStartJavaScriptOnlyOnCSS () =
7020
7046
runTest {
Original file line number Diff line number Diff line change @@ -4257,6 +4257,17 @@ class BrowserTabViewModel @Inject constructor(
4257
4257
}
4258
4258
4259
4259
suspend fun privacyProtectionsUpdated (webView : WebView ) {
4260
+ val pauseWebViewBeforeUpdatingScript = withContext(dispatchers.io()) {
4261
+ androidBrowserConfig.pauseWebViewBeforeUpdatingScript().isEnabled()
4262
+ }
4263
+
4264
+ if (pauseWebViewBeforeUpdatingScript) {
4265
+ withContext(dispatchers.main()) {
4266
+ webView.stopLoading()
4267
+ webView.pauseTimers()
4268
+ }
4269
+ }
4270
+
4260
4271
if (withContext(dispatchers.io()) { ! androidBrowserConfig.updateScriptOnPageFinished().isEnabled() }) {
4261
4272
addDocumentStartJavascriptPlugins
4262
4273
.getPlugins()
@@ -4268,6 +4279,10 @@ class BrowserTabViewModel @Inject constructor(
4268
4279
} else {
4269
4280
addDocumentStartJavaScript(webView)
4270
4281
}
4282
+
4283
+ if (pauseWebViewBeforeUpdatingScript) {
4284
+ webView.resumeTimers()
4285
+ }
4271
4286
}
4272
4287
4273
4288
fun onUserDismissedAutoCompleteInAppMessage () {
Original file line number Diff line number Diff line change @@ -191,4 +191,7 @@ interface AndroidBrowserConfigFeature {
191
191
192
192
@Toggle.DefaultValue (TRUE )
193
193
fun updateScriptOnPageFinished (): Toggle
194
+
195
+ @Toggle.DefaultValue (TRUE )
196
+ fun pauseWebViewBeforeUpdatingScript (): Toggle
194
197
}
You can’t perform that action at this time.
0 commit comments