@@ -25,18 +25,27 @@ import com.duckduckgo.contentscopescripts.api.GlobalContentScopeJsMessageHandler
25
25
import com.duckduckgo.contentscopescripts.api.GlobalJsMessageHandler
26
26
import com.duckduckgo.contentscopescripts.api.WebCompatContentScopeJsMessageHandlersPlugin
27
27
import com.duckduckgo.contentscopescripts.impl.AdsJsContentScopeScripts
28
+ import com.duckduckgo.contentscopescripts.impl.ContentScopeScriptsFeature
28
29
import com.duckduckgo.js.messaging.api.JsMessage
30
+ import com.duckduckgo.js.messaging.api.SubscriptionEventData
29
31
import com.duckduckgo.js.messaging.api.WebCompatMessageHandler
30
32
import com.duckduckgo.js.messaging.api.WebViewCompatMessageCallback
31
33
import junit.framework.TestCase.assertEquals
32
34
import junit.framework.TestCase.assertNull
33
35
import kotlinx.coroutines.test.runTest
34
36
import org.json.JSONObject
37
+ import org.junit.Assert.assertFalse
38
+ import org.junit.Assert.assertTrue
39
+ import org.junit.Assert.assertFalse
40
+ import org.junit.Assert.assertTrue
35
41
import org.junit.Before
36
42
import org.junit.Rule
37
43
import org.junit.Test
38
44
import org.junit.runner.RunWith
45
+ import org.mockito.kotlin.any
39
46
import org.mockito.kotlin.mock
47
+ import org.mockito.kotlin.never
48
+ import org.mockito.kotlin.verify
40
49
import org.mockito.kotlin.whenever
41
50
42
51
@RunWith(AndroidJUnit4 ::class )
@@ -247,6 +256,65 @@ class WebCompatMessagingPluginTest {
247
256
assertEquals(" contentScopeAdsjs" , capturedObjectName)
248
257
}
249
258
259
+ // @Test
260
+ // fun `when posting message and adsjs is disabled then do not post message`() = runTest {
261
+ // whenever(adsJsContentScopeScripts.isEnabled()).thenReturn(false)
262
+ // val eventData = SubscriptionEventData("feature", "subscription", JSONObject())
263
+ // givenInterfaceIsRegistered()
264
+ // processInitialPing()
265
+ //
266
+ // val result = testee.postMessage(eventData)
267
+ //
268
+ // verify(mockWebView, never()).safePostMessage(any(), any())
269
+ // assertFalse(result)
270
+ // }
271
+ //
272
+ // @Test
273
+ // fun `when posting message and adsjs is enabled but webView not registered then do not post message`() = runTest {
274
+ // whenever(adsJsContentScopeScripts.isEnabled()).thenReturn(true)
275
+ // val eventData = SubscriptionEventData("feature", "subscription", JSONObject())
276
+ // processInitialPing()
277
+ //
278
+ // val result = testee.postMessage(eventData)
279
+ //
280
+ // verify(mockWebView, never()).safePostMessage(any(), any())
281
+ // assertFalse(result)
282
+ // }
283
+ //
284
+ // @Test
285
+ // fun `when posting message and adsjs is enabled but initialPing not processes then do not post message`() = runTest {
286
+ // whenever(adsJsContentScopeScripts.isEnabled()).thenReturn(true)
287
+ // val eventData = SubscriptionEventData("feature", "subscription", JSONObject())
288
+ //
289
+ // val result = testee.postMessage(eventData)
290
+ //
291
+ // verify(mockWebView, never()).safePostMessage(any(), any())
292
+ // assertFalse(result)
293
+ // }
294
+ //
295
+ // @Test
296
+ // fun `when posting message after getting initialPing and adsjs is enabled then post message`() = runTest {
297
+ // whenever(adsJsContentScopeScripts.isEnabled()).thenReturn(true)
298
+ // val eventData = SubscriptionEventData("feature", "subscription", JSONObject())
299
+ // givenInterfaceIsRegistered()
300
+ // processInitialPing()
301
+ // verify(mockWebView, never()).postWebMessage(any(), any())
302
+ //
303
+ // val result = testee.postMessage(eventData)
304
+ //
305
+ // verify(mockWebView).safePostMessage(any(), any())
306
+ // assertTrue(result)
307
+ // }
308
+
309
+ private fun processInitialPing () = runTest {
310
+ val message = """
311
+ {"context":"contentScopeScripts","featureName":"messaging","id":"debugId","method":"initialPing","params":{}}
312
+ """ .trimIndent()
313
+ testee.process(message, callback, mockReplyProxy)
314
+ }
315
+
316
+
317
+
250
318
private val callback = object : WebViewCompatMessageCallback () {
251
319
var counter = 0
252
320
override fun process (
0 commit comments