1616
1717package com.duckduckgo.app.trackerdetection
1818
19- import com.duckduckgo.app.trackerdetection.model.DisconnectTracker
20- import com.duckduckgo.app.trackerdetection.model.NetworkTrackers
21- import com.duckduckgo.app.trackerdetection.model.ResourceType
19+ import com.duckduckgo.app.trackerdetection.model.*
2220import com.nhaarman.mockito_kotlin.any
2321import com.nhaarman.mockito_kotlin.mock
2422import com.nhaarman.mockito_kotlin.whenever
25- import org.junit.Assert.assertFalse
26- import org.junit.Assert.assertTrue
23+ import org.junit.Assert.assertEquals
24+ import org.junit.Assert.assertNull
2725import org.junit.Test
2826import org.mockito.ArgumentMatchers.anyString
29- import java.util.*
3027
3128
3229class TrackerDetectorInstrumentationTest {
3330
34- private val networkTrackers = NetworkTrackers ()
31+ private val networkTrackers = TrackerNetworks ()
3532 private val trackerDetector = TrackerDetector (networkTrackers)
3633
3734 companion object {
@@ -40,71 +37,89 @@ class TrackerDetectorInstrumentationTest {
4037 }
4138
4239 @Test
43- fun whenThereAreNoClientsThenShouldBlockIsFalse () {
44- assertFalse (trackerDetector.shouldBlock (" http://thirdparty.com/update.js" , " http://example.com/index.com" , resourceType))
40+ fun whenThereAreNoClientsThenEvaluateReturnsNull () {
41+ assertNull (trackerDetector.evaluate (" http://thirdparty.com/update.js" , " http://example.com/index.com" , resourceType))
4542 }
4643
4744 @Test
48- fun whenAllClientsFailToMatchThenShouldBlockIsFalse () {
45+ fun whenAllClientsFailToMatchThenEvaluateReturnsNull () {
4946 trackerDetector.addClient(neverMatchingClient())
5047 trackerDetector.addClient(neverMatchingClient())
51- assertFalse (trackerDetector.shouldBlock (" http://thirdparty.com/update.js" , " http://example.com/index.com" , resourceType))
48+ assertNull (trackerDetector.evaluate (" http://thirdparty.com/update.js" , " http://example.com/index.com" , resourceType))
5249 }
5350
5451 @Test
55- fun whenAllClientsMatchThenShouldBlockIsTrue () {
52+ fun whenAllClientsMatchThenEvaluateReturnsTrackingEvent () {
5653 trackerDetector.addClient(alwaysMatchingClient())
5754 trackerDetector.addClient(alwaysMatchingClient())
58- assertTrue(trackerDetector.shouldBlock(" http://thirdparty.com/update.js" , " http://example.com/index.com" , resourceType))
55+ val expected = TrackingEvent (" http://example.com/index.com" , " http://thirdparty.com/update.js" , null , true )
56+ val actual = trackerDetector.evaluate(" http://thirdparty.com/update.js" , " http://example.com/index.com" , resourceType)
57+ assertEquals(expected, actual)
5958 }
6059
6160 @Test
62- fun whenSomeClientsMatchThenShouldBlockIsTrue () {
61+ fun whenSomeClientsMatchThenEvaluateReturnsTrackingEvent () {
6362 trackerDetector.addClient(neverMatchingClient())
6463 trackerDetector.addClient(alwaysMatchingClient())
65- assertTrue(trackerDetector.shouldBlock(" http://thirdparty.com/update.js" , " http://example.com/index.com" , resourceType))
64+ val expected = TrackingEvent (" http://example.com/index.com" , " http://thirdparty.com/update.js" , null , true )
65+ val actual = trackerDetector.evaluate(" http://thirdparty.com/update.js" , " http://example.com/index.com" , resourceType)
66+ assertEquals(expected, actual)
6667 }
6768
6869 @Test
69- fun whenUrlHasSameDomainAsDocumentThenShouldBlockIsFalse () {
70+ fun whenTrackerIsPartOfNetworkThenEvaluateReturnsTrackingEventWithNetwork () {
71+ val networks = arrayListOf (
72+ DisconnectTracker (" thirdparty.com" , " " , network, " http://network.com" )
73+ )
74+ networkTrackers.updateData(networks)
75+ trackerDetector.addClient(alwaysMatchingClient())
76+
77+ val network = TrackerNetwork (network, " http://network.com" )
78+ val expected = TrackingEvent (" http://example.com/index.com" , " http://thirdparty.com/update.js" , network, true )
79+ val actual = trackerDetector.evaluate(" http://thirdparty.com/update.js" , " http://example.com/index.com" , resourceType)
80+ assertEquals(expected, actual)
81+ }
82+
83+ @Test
84+ fun whenUrlHasSameDomainAsDocumentThenEvaluateReturnsNull () {
7085 trackerDetector.addClient(alwaysMatchingClient())
71- assertFalse (trackerDetector.shouldBlock (" http://example.com/update.js" , " http://example.com/index.com" , resourceType))
86+ assertNull (trackerDetector.evaluate (" http://example.com/update.js" , " http://example.com/index.com" , resourceType))
7287 }
7388
7489 @Test
75- fun whenUrlIsSubdomainOfDocumentThenShouldBlockIsFalse () {
90+ fun whenUrlIsSubdomainOfDocumentThenEvaluateReturnsNull () {
7691 trackerDetector.addClient(alwaysMatchingClient())
77- assertFalse (trackerDetector.shouldBlock (" http://mobile.example.com/update.js" , " http://example.com/index.com" , resourceType))
92+ assertNull (trackerDetector.evaluate (" http://mobile.example.com/update.js" , " http://example.com/index.com" , resourceType))
7893 }
7994
8095 @Test
81- fun whenUrlIsParentOfDocumentThenShouldBlockIsFalse () {
96+ fun whenUrlIsParentOfDocumentThenEvaluateReturnsNull () {
8297 trackerDetector.addClient(alwaysMatchingClient())
83- assertFalse (trackerDetector.shouldBlock (" http://example.com/update.js" , " http://mobile.example.com/index.com" , resourceType))
98+ assertNull (trackerDetector.evaluate (" http://example.com/update.js" , " http://mobile.example.com/index.com" , resourceType))
8499 }
85100
86101 @Test
87- fun whenUrlIsNetworkOfDocumentThenShouldBlockIsFalse () {
88- val networks = Arrays .asList (DisconnectTracker (" example.com" , " " , network, " http://thirdparty.com/" ))
102+ fun whenUrlIsNetworkOfDocumentThenEvaluateReturnsNull () {
103+ val networks = arrayListOf (DisconnectTracker (" example.com" , " " , network, " http://thirdparty.com/" ))
89104 networkTrackers.updateData(networks)
90- assertFalse (trackerDetector.shouldBlock (" http://thirdparty.com/update.js" , " http://example.com/index.com" , resourceType))
105+ assertNull (trackerDetector.evaluate (" http://thirdparty.com/update.js" , " http://example.com/index.com" , resourceType))
91106 }
92107
93108 @Test
94- fun whenDocumentIsNetworkOfUrlThenShouldBlockIsFalse () {
95- val networks = Arrays .asList (DisconnectTracker (" thirdparty.com" , " " , network, " http://example.com" ))
109+ fun whenDocumentIsNetworkOfUrlThenEvaluateReturnsNull () {
110+ val networks = arrayListOf (DisconnectTracker (" thirdparty.com" , " " , network, " http://example.com" ))
96111 networkTrackers.updateData(networks)
97- assertFalse (trackerDetector.shouldBlock (" http://thirdparty.com/update.js" , " http://example.com/index.com" , resourceType))
112+ assertNull (trackerDetector.evaluate (" http://thirdparty.com/update.js" , " http://example.com/index.com" , resourceType))
98113 }
99114
100115 @Test
101- fun whenUrlSharesSameNetworkAsDocumentThenShouldBlockIsFalse () {
102- val networks = Arrays .asList (
116+ fun whenUrlSharesSameNetworkAsDocumentThenEvaluateReturnsNull () {
117+ val networks = arrayListOf (
103118 DisconnectTracker (" thirdparty.com" , " " , network, " http://network.com" ),
104119 DisconnectTracker (" example.com" , " " , network, " http://network.com" )
105120 )
106121 networkTrackers.updateData(networks)
107- assertFalse (trackerDetector.shouldBlock (" http://thirdparty.com/update.js" , " http://example.com/index.com" , resourceType))
122+ assertNull (trackerDetector.evaluate (" http://thirdparty.com/update.js" , " http://example.com/index.com" , resourceType))
108123 }
109124
110125 private fun alwaysMatchingClient (): Client {
0 commit comments