@@ -27,7 +27,7 @@ class ContentScopeScriptsJsInjectorPluginTest {
27
27
var coroutineRule = CoroutineTestRule ()
28
28
29
29
private val mockCoreContentScopeScripts: CoreContentScopeScripts = mock()
30
- private val adsJsContentScopeScripts : AdsJsContentScopeScripts = mock()
30
+ private val mockAdsJsContentScopeScripts : AdsJsContentScopeScripts = mock()
31
31
private val mockWebView: WebView = mock()
32
32
private val mockContentScopeExperiments: ContentScopeExperiments = mock()
33
33
private val mockWebViewCompatWrapper: WebViewCompatWrapper = mock()
@@ -41,7 +41,7 @@ class ContentScopeScriptsJsInjectorPluginTest {
41
41
whenever(mockContentScopeExperiments.getActiveExperiments()).thenReturn(listOf (mockToggle))
42
42
contentScopeScriptsJsInjectorPlugin = ContentScopeScriptsJsInjectorPlugin (
43
43
mockCoreContentScopeScripts,
44
- adsJsContentScopeScripts ,
44
+ mockAdsJsContentScopeScripts ,
45
45
mockContentScopeExperiments,
46
46
coroutineRule.testDispatcherProvider,
47
47
mockWebViewCompatWrapper,
@@ -51,6 +51,7 @@ class ContentScopeScriptsJsInjectorPluginTest {
51
51
@Test
52
52
fun whenEnabledAndInjectContentScopeScriptsThenPopulateMessagingParameters () = runTest {
53
53
whenever(mockCoreContentScopeScripts.isEnabled()).thenReturn(true )
54
+ whenever(mockAdsJsContentScopeScripts.isEnabled()).thenReturn(true )
54
55
whenever(mockCoreContentScopeScripts.getScript(null , listOf ())).thenReturn(" " )
55
56
contentScopeScriptsJsInjectorPlugin.onPageStarted(mockWebView, null , null )
56
57
@@ -69,6 +70,7 @@ class ContentScopeScriptsJsInjectorPluginTest {
69
70
@Test
70
71
fun whenEnabledAndInjectContentScopeScriptsThenUseParams () = runTest {
71
72
whenever(mockCoreContentScopeScripts.isEnabled()).thenReturn(true )
73
+ whenever(mockAdsJsContentScopeScripts.isEnabled()).thenReturn(true )
72
74
whenever(mockCoreContentScopeScripts.getScript(true , listOf ())).thenReturn(" " )
73
75
contentScopeScriptsJsInjectorPlugin.onPageStarted(mockWebView, null , true )
74
76
@@ -98,6 +100,7 @@ class ContentScopeScriptsJsInjectorPluginTest {
98
100
fun whenEnabledAndPageStartedWithInitJsAndActiveExperimentsChangedAfterwardsThenReturnActiveExperimentsFromInit () = runTest {
99
101
val mockToggle2 = mock<Toggle >()
100
102
whenever(mockCoreContentScopeScripts.isEnabled()).thenReturn(true )
103
+ whenever(mockAdsJsContentScopeScripts.isEnabled()).thenReturn(true )
101
104
102
105
contentScopeScriptsJsInjectorPlugin.onInit(mockWebView)
103
106
@@ -112,6 +115,7 @@ class ContentScopeScriptsJsInjectorPluginTest {
112
115
fun whenInitJsActiveExperimentsUpdated () = runTest {
113
116
val mockToggle2 = mock<Toggle >()
114
117
whenever(mockCoreContentScopeScripts.isEnabled()).thenReturn(true )
118
+ whenever(mockAdsJsContentScopeScripts.isEnabled()).thenReturn(true )
115
119
contentScopeScriptsJsInjectorPlugin.onInit(mockWebView)
116
120
117
121
val result = contentScopeScriptsJsInjectorPlugin.onPageStarted(mockWebView, null , null )
@@ -130,6 +134,7 @@ class ContentScopeScriptsJsInjectorPluginTest {
130
134
fun whenPageFinishedActiveExperimentsUpdated () = runTest {
131
135
val mockToggle2 = mock<Toggle >()
132
136
whenever(mockCoreContentScopeScripts.isEnabled()).thenReturn(true )
137
+ whenever(mockAdsJsContentScopeScripts.isEnabled()).thenReturn(true )
133
138
contentScopeScriptsJsInjectorPlugin.onInit(mockWebView)
134
139
135
140
val result = contentScopeScriptsJsInjectorPlugin.onPageStarted(mockWebView, null , null )
@@ -147,35 +152,59 @@ class ContentScopeScriptsJsInjectorPluginTest {
147
152
@Test
148
153
fun whenDocumentStartScriptSupportedAndInitCalledWithScriptChangedThenScriptInjected () = runTest {
149
154
whenever(mockWebViewCompatWrapper.isDocumentStartScriptSupported()).thenReturn(true )
150
- whenever(mockCoreContentScopeScripts .isEnabled()).thenReturn(true )
151
- whenever(adsJsContentScopeScripts .getScript(any())).thenReturn(" mockScript" )
155
+ whenever(mockAdsJsContentScopeScripts .isEnabled()).thenReturn(true )
156
+ whenever(mockAdsJsContentScopeScripts .getScript(any())).thenReturn(" mockScript" )
152
157
153
158
contentScopeScriptsJsInjectorPlugin.onInit(mockWebView)
154
159
155
- verify(adsJsContentScopeScripts ).getScript(listOf (mockToggle))
160
+ verify(mockAdsJsContentScopeScripts ).getScript(listOf (mockToggle))
156
161
verify(mockWebViewCompatWrapper).addDocumentStartJavaScript(any(), eq(" mockScript" ), any())
157
162
}
158
163
159
164
@Test
160
165
fun whenDocumentStartScriptNotSupportedAndInitCalledThenNoScriptInjected () = runTest {
161
166
whenever(mockWebViewCompatWrapper.isDocumentStartScriptSupported()).thenReturn(false )
167
+ whenever(mockAdsJsContentScopeScripts.isEnabled()).thenReturn(true )
168
+ whenever(mockAdsJsContentScopeScripts.getScript(any())).thenReturn(" mockScript" )
169
+
170
+ contentScopeScriptsJsInjectorPlugin.onInit(mockWebView)
171
+
172
+ verifyNoInteractions(mockAdsJsContentScopeScripts)
173
+ verify(mockWebViewCompatWrapper, never()).addDocumentStartJavaScript(any(), any(), any())
174
+ }
175
+
176
+ @Test
177
+ fun whenAdsjsIsNotEnabledAndInitCalledThenNoScriptInjected () = runTest {
178
+ whenever(mockWebViewCompatWrapper.isDocumentStartScriptSupported()).thenReturn(true )
162
179
whenever(mockCoreContentScopeScripts.isEnabled()).thenReturn(true )
163
- whenever(adsJsContentScopeScripts.getScript(any())).thenReturn(" mockScript" )
180
+ whenever(mockAdsJsContentScopeScripts.isEnabled()).thenReturn(false )
181
+ whenever(mockAdsJsContentScopeScripts.getScript(any())).thenReturn(" mockScript" )
164
182
165
183
contentScopeScriptsJsInjectorPlugin.onInit(mockWebView)
166
184
167
- verifyNoInteractions(adsJsContentScopeScripts)
185
+ verify(mockWebViewCompatWrapper, never()).addDocumentStartJavaScript(any(), any(), any())
186
+ }
187
+
188
+ @Test
189
+ fun whenAdsjsIsNotEnabledAndPageFinishedCalledThenNoScriptInjected () = runTest {
190
+ whenever(mockWebViewCompatWrapper.isDocumentStartScriptSupported()).thenReturn(true )
191
+ whenever(mockCoreContentScopeScripts.isEnabled()).thenReturn(true )
192
+ whenever(mockAdsJsContentScopeScripts.isEnabled()).thenReturn(false )
193
+ whenever(mockAdsJsContentScopeScripts.getScript(any())).thenReturn(" mockScript" )
194
+
195
+ contentScopeScriptsJsInjectorPlugin.onPageFinished(mockWebView, null )
196
+
168
197
verify(mockWebViewCompatWrapper, never()).addDocumentStartJavaScript(any(), any(), any())
169
198
}
170
199
171
200
@Test
172
201
fun whenDocumentStartScriptNotSupportedAndPageFinishedCalledThenNoScriptInjected () = runTest {
173
202
whenever(mockWebViewCompatWrapper.isDocumentStartScriptSupported()).thenReturn(false )
174
- whenever(mockCoreContentScopeScripts .isEnabled()).thenReturn(true )
203
+ whenever(mockAdsJsContentScopeScripts .isEnabled()).thenReturn(true )
175
204
176
205
contentScopeScriptsJsInjectorPlugin.onPageFinished(mockWebView, null )
177
206
178
- verifyNoInteractions(adsJsContentScopeScripts )
207
+ verifyNoInteractions(mockAdsJsContentScopeScripts )
179
208
verify(mockWebViewCompatWrapper, never()).addDocumentStartJavaScript(any(), any(), any())
180
209
}
181
210
}
0 commit comments