Skip to content

Commit 1ff382e

Browse files
authored
FF updating script on protections changed (#6906)
Task/Issue URL: https://app.asana.com/1/137249556945/project/72649045549333/task/1211578851788392?focus=true ### Description * FF updating script on protections changed as part of native crashes investigation after adding `addDocumentStartJavaScript` ### Steps to test this PR _Pre-requisites_ - [x] Apply this [patch](https://duckduckgo-my.sharepoint.com/:u:/p/cbarreiro/EfoKD1EMQPxFhWiH_LHI2wgB0RxCvVUtJBiCx7ofwCsTeQ?e=Lhx8IW) - [x] Do a clean install of the app - [x] Open Feature flags inventory - [x] Set `updateScriptOnPageFinished` to false to reduce the amount of logs - [x] Filter logcat by `"Cris"` _FF enabled_ - [x] Open Feature flags inventory - [x] Set `updateScriptOnProtectionsChanged` to true - [x] Load a page - [x] Change protection status from context menu - [x] Check there's a log for `addDocumentJavaScript` every time you toggle protections - [x] Open privacy dashboard and toggle privacy protections from there - [x] Navigate back to the WebView - [x] Check there's a log for `addDocumentJavaScript` every time you toggle protections _FF enabled_ - [x] Open Feature flags inventory - [x] Set `updateScriptOnProtectionsChanged` to false - [x] Load a page - [x] Change protection status from context menu - [x] Check there's no log for `addDocumentJavaScript` every time you toggle protections - [x] Open privacy dashboard and toggle privacy protections from there - [x] Navigate back to the WebView - [x] Check there's no log for `addDocumentJavaScript` every time you toggle protections ### UI changes n/a
1 parent b853bf6 commit 1ff382e

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

app/src/androidTest/java/com/duckduckgo/app/browser/BrowserTabViewModelTest.kt

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7005,9 +7005,10 @@ class BrowserTabViewModelTest {
70057005
}
70067006

70077007
@Test
7008-
fun whenPrivacyProtectionsUpdatedAndAndUpdateScriptOnPageFinishedEnabledThenAddDocumentStartJavaScript() =
7008+
fun whenPrivacyProtectionsUpdatedAndUpdateScriptOnPageFinishedEnabledAndUpdateScriptOnProtectionsChangedEnabledThenAddDocumentStartJavaScript() =
70097009
runTest {
70107010
fakeAndroidConfigBrowserFeature.updateScriptOnPageFinished().setRawStoredState(State(true))
7011+
fakeAndroidConfigBrowserFeature.updateScriptOnProtectionsChanged().setRawStoredState(State(true))
70117012

70127013
testee.privacyProtectionsUpdated(mockWebView)
70137014

@@ -7016,16 +7017,41 @@ class BrowserTabViewModelTest {
70167017
}
70177018

70187019
@Test
7019-
fun whenPrivacyProtectionsUpdatedAndAndUpdateScriptOnPageFinishedDisabledThenAddDocumentStartJavaScriptOnlyOnCSS() =
7020+
fun whenPrivacyProtectionsUpdatedAndUpdateScriptOnPageFinishedTrueAndUpdateScriptOnProtectionsChangedFalseThenNotAddDocumentStartJavaScript() =
7021+
runTest {
7022+
fakeAndroidConfigBrowserFeature.updateScriptOnPageFinished().setRawStoredState(State(true))
7023+
fakeAndroidConfigBrowserFeature.updateScriptOnProtectionsChanged().setRawStoredState(State(false))
7024+
7025+
testee.privacyProtectionsUpdated(mockWebView)
7026+
7027+
assertEquals(0, fakeAddDocumentStartJavaScriptPlugins.cssPlugin.countInitted)
7028+
assertEquals(0, fakeAddDocumentStartJavaScriptPlugins.otherPlugin.countInitted)
7029+
}
7030+
7031+
@Test
7032+
fun whenPrivacyProtectionsUpdatedAndUpdateScriptOnPageFinishedDisabledThenAddDocumentStartJavaScriptOnlyOnCSS() =
70207033
runTest {
70217034
fakeAndroidConfigBrowserFeature.updateScriptOnPageFinished().setRawStoredState(State(false))
7035+
fakeAndroidConfigBrowserFeature.updateScriptOnProtectionsChanged().setRawStoredState(State(true))
70227036

70237037
testee.privacyProtectionsUpdated(mockWebView)
70247038

70257039
assertEquals(1, fakeAddDocumentStartJavaScriptPlugins.cssPlugin.countInitted)
70267040
assertEquals(0, fakeAddDocumentStartJavaScriptPlugins.otherPlugin.countInitted)
70277041
}
70287042

7043+
@Test
7044+
fun whenPrivacyProtectionsUpdatedAndUpdateScriptOnPageFinishedFalseAndUpdateScriptOnProtectionsChangedFalseThenNotAddDocumentStartJavaScript() =
7045+
runTest {
7046+
fakeAndroidConfigBrowserFeature.updateScriptOnPageFinished().setRawStoredState(State(false))
7047+
fakeAndroidConfigBrowserFeature.updateScriptOnProtectionsChanged().setRawStoredState(State(false))
7048+
7049+
testee.privacyProtectionsUpdated(mockWebView)
7050+
7051+
assertEquals(0, fakeAddDocumentStartJavaScriptPlugins.cssPlugin.countInitted)
7052+
assertEquals(0, fakeAddDocumentStartJavaScriptPlugins.otherPlugin.countInitted)
7053+
}
7054+
70297055
@Test
70307056
fun whenCtaShownThenFireInContextDialogShownPixel() =
70317057
runTest {

app/src/main/java/com/duckduckgo/app/browser/BrowserTabViewModel.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4257,6 +4257,10 @@ class BrowserTabViewModel @Inject constructor(
42574257
}
42584258

42594259
suspend fun privacyProtectionsUpdated(webView: WebView) {
4260+
if (withContext(dispatchers.io()) { !androidBrowserConfig.updateScriptOnProtectionsChanged().isEnabled() }) {
4261+
return
4262+
}
4263+
42604264
if (withContext(dispatchers.io()) { !androidBrowserConfig.updateScriptOnPageFinished().isEnabled() }) {
42614265
addDocumentStartJavascriptPlugins
42624266
.getPlugins()

app/src/main/java/com/duckduckgo/app/pixels/remoteconfig/AndroidBrowserConfigFeature.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,7 @@ interface AndroidBrowserConfigFeature {
191191

192192
@Toggle.DefaultValue(TRUE)
193193
fun updateScriptOnPageFinished(): Toggle
194+
195+
@Toggle.DefaultValue(TRUE)
196+
fun updateScriptOnProtectionsChanged(): Toggle
194197
}

0 commit comments

Comments
 (0)