@@ -19,7 +19,9 @@ package com.duckduckgo.app.browser.useragent
19
19
import com.duckduckgo.app.global.device.DeviceInfo
20
20
import com.nhaarman.mockitokotlin2.mock
21
21
import com.nhaarman.mockitokotlin2.whenever
22
+ import org.junit.Assert.assertTrue
22
23
import org.junit.Before
24
+ import org.junit.Test
23
25
24
26
class UserAgentProviderTest {
25
27
@@ -32,103 +34,103 @@ class UserAgentProviderTest {
32
34
whenever(deviceInfo.majorAppVersion).thenReturn(" 5" )
33
35
}
34
36
35
- // @Test
36
- // fun whenUaRetrievedWithNoParamsThenDeviceStrippedAndApplicationComponentAddedBeforeSafari() {
37
- // testee = UserAgentProvider(Agent.DEFAULT, deviceInfo)
38
- // val actual = testee.userAgent()
39
- // assertTrue("$actual does not match expected regex", ValidationRegex.converted.matches(actual))
40
- // }
41
- //
42
- // @Test
43
- // fun whenMobileUaRetrievedThenDeviceStrippedAndApplicationComponentAddedBeforeSafari() {
44
- // testee = UserAgentProvider(Agent.DEFAULT, deviceInfo)
45
- // val actual = testee.userAgent(isDesktop = false)
46
- // assertTrue("$actual does not match expected regex", ValidationRegex.converted.matches(actual))
47
- // }
48
- //
49
- // @Test
50
- // fun whenDesktopUaRetrievedThenDeviceStrippedAndApplicationComponentAddedBeforeSafari() {
51
- // testee = UserAgentProvider(Agent.DEFAULT, deviceInfo)
52
- // val actual = testee.userAgent(isDesktop = true)
53
- // assertTrue("$actual does not match expected regex", ValidationRegex.desktop.matches(actual))
54
- // }
55
- //
56
- // @Test
57
- // fun whenMissingAppleWebKitComponentThenUaContainsMozillaAndApplicationAndSafariComponents() {
58
- // testee = UserAgentProvider(Agent.NO_WEBKIT, deviceInfo)
59
- // val actual = testee.userAgent(isDesktop = false)
60
- // assertTrue("$actual does not match expected regex", ValidationRegex.missingWebKit.matches(actual))
61
- // }
62
- //
63
- // @Test
64
- // fun whenMissingSafariComponentThenUaContainsMozillaAndVersionAndApplicationComponents() {
65
- // testee = UserAgentProvider(Agent.NO_SAFARI, deviceInfo)
66
- // val actual = testee.userAgent(isDesktop = false)
67
- // assertTrue("$actual does not match expected result", ValidationRegex.missingSafari.matches(actual))
68
- // }
69
- //
70
- // @Test
71
- // fun whenMissingVersionComponentThenUaContainsMozillaAndApplicationAndSafariComponents() {
72
- // testee = UserAgentProvider(Agent.NO_VERSION, deviceInfo)
73
- // val actual = testee.userAgent(isDesktop = false)
74
- // assertTrue("$actual does not match expected result", ValidationRegex.noVersion.matches(actual))
75
- // }
76
- //
77
- // @Test
78
- // fun whenDomainDoesNotSupportApplicationThenUaOmitsApplicationComponent() {
79
- // testee = UserAgentProvider(Agent.DEFAULT, deviceInfo)
80
- // val actual = testee.userAgent(NO_APPLICATION_DOMAIN)
81
- // assertTrue("$actual does not match expected regex", ValidationRegex.noApplication.matches(actual))
82
- // }
83
- //
84
- // @Test
85
- // fun whenSubdomsinDoesNotSupportApplicationThenUaOmitsApplicationComponent() {
86
- // testee = UserAgentProvider(Agent.DEFAULT, deviceInfo)
87
- // val actual = testee.userAgent(NO_APPLICATION_SUBDOMAIN)
88
- // assertTrue("$actual does not match expected regex", ValidationRegex.noApplication.matches(actual))
89
- // }
90
- //
91
- // @Test
92
- // fun whenDomainSupportsApplicationThenUaAddsApplicationComponentBeforeSafari() {
93
- // testee = UserAgentProvider(Agent.DEFAULT, deviceInfo)
94
- // val actual = testee.userAgent(DOMAIN)
95
- // assertTrue("$actual does not match expected regex", ValidationRegex.converted.matches(actual))
96
- // }
97
- //
98
- // @Test
99
- // fun whenDomainDoesNotSupportVersionThenUaOmitsVersionComponent() {
100
- // testee = UserAgentProvider(Agent.DEFAULT, deviceInfo)
101
- // val actual = testee.userAgent(NO_VERSION_DOMAIN)
102
- // assertTrue("$actual does not match expected regex", ValidationRegex.noVersion.matches(actual))
103
- // }
104
- //
105
- // @Test
106
- // fun whenSubdomainDoesNotSupportVersionThenUaOmitsVersionComponent() {
107
- // testee = UserAgentProvider(Agent.DEFAULT, deviceInfo)
108
- // val actual = testee.userAgent(NO_VERSION_SUBDOMAIN)
109
- // assertTrue("$actual does not match expected regex", ValidationRegex.noVersion.matches(actual))
110
- // }
111
- //
112
- // @Test
113
- // fun whenDomainSupportsVersionThenUaIncludesVersionComponentInUsualLocation() {
114
- // testee = UserAgentProvider(Agent.DEFAULT, deviceInfo)
115
- // val actual = testee.userAgent(DOMAIN)
116
- // assertTrue("$actual does not match expected regex", ValidationRegex.converted.matches(actual))
117
- // }
118
- //
119
- // @Test
120
- // fun whenUserAgentIsForASiteThatShouldUseDesktopAgentThenReturnDesktopUserAgent() {
121
- // testee = UserAgentProvider(Agent.DEFAULT, deviceInfo)
122
- // val actual = testee.userAgent(DESKTOP_ONLY_SITE)
123
- // assertTrue("$actual does not match expected regex", ValidationRegex.desktop.matches(actual))
124
- // }
125
- //
126
- // @Test
127
- // fun whenUserAgentIsForASiteThatShouldUseDesktopAgentButContainsAnExclusionThenDoNotReturnConvertedUserAgent() {
128
- // testee = UserAgentProvider(Agent.DEFAULT, deviceInfo)
129
- // val actual = testee.userAgent(DESKTOP_ONLY_SITE_EXCEPTION)
130
- // assertTrue("$actual does not match expected regex", ValidationRegex.converted.matches(actual))
131
- // }
37
+ @Test
38
+ fun whenUaRetrievedWithNoParamsThenDeviceStrippedAndApplicationComponentAddedBeforeSafari () {
39
+ testee = UserAgentProvider (Agent .DEFAULT , deviceInfo)
40
+ val actual = testee.userAgent()
41
+ assertTrue(" $actual does not match expected regex" , ValidationRegex .converted.matches(actual))
42
+ }
43
+
44
+ @Test
45
+ fun whenMobileUaRetrievedThenDeviceStrippedAndApplicationComponentAddedBeforeSafari () {
46
+ testee = UserAgentProvider (Agent .DEFAULT , deviceInfo)
47
+ val actual = testee.userAgent(isDesktop = false )
48
+ assertTrue(" $actual does not match expected regex" , ValidationRegex .converted.matches(actual))
49
+ }
50
+
51
+ @Test
52
+ fun whenDesktopUaRetrievedThenDeviceStrippedAndApplicationComponentAddedBeforeSafari () {
53
+ testee = UserAgentProvider (Agent .DEFAULT , deviceInfo)
54
+ val actual = testee.userAgent(isDesktop = true )
55
+ assertTrue(" $actual does not match expected regex" , ValidationRegex .desktop.matches(actual))
56
+ }
57
+
58
+ @Test
59
+ fun whenMissingAppleWebKitComponentThenUaContainsMozillaAndApplicationAndSafariComponents () {
60
+ testee = UserAgentProvider (Agent .NO_WEBKIT , deviceInfo)
61
+ val actual = testee.userAgent(isDesktop = false )
62
+ assertTrue(" $actual does not match expected regex" , ValidationRegex .missingWebKit.matches(actual))
63
+ }
64
+
65
+ @Test
66
+ fun whenMissingSafariComponentThenUaContainsMozillaAndVersionAndApplicationComponents () {
67
+ testee = UserAgentProvider (Agent .NO_SAFARI , deviceInfo)
68
+ val actual = testee.userAgent(isDesktop = false )
69
+ assertTrue(" $actual does not match expected result" , ValidationRegex .missingSafari.matches(actual))
70
+ }
71
+
72
+ @Test
73
+ fun whenMissingVersionComponentThenUaContainsMozillaAndApplicationAndSafariComponents () {
74
+ testee = UserAgentProvider (Agent .NO_VERSION , deviceInfo)
75
+ val actual = testee.userAgent(isDesktop = false )
76
+ assertTrue(" $actual does not match expected result" , ValidationRegex .noVersion.matches(actual))
77
+ }
78
+
79
+ @Test
80
+ fun whenDomainDoesNotSupportApplicationThenUaOmitsApplicationComponent () {
81
+ testee = UserAgentProvider (Agent .DEFAULT , deviceInfo)
82
+ val actual = testee.userAgent(NO_APPLICATION_DOMAIN )
83
+ assertTrue(" $actual does not match expected regex" , ValidationRegex .noApplication.matches(actual))
84
+ }
85
+
86
+ @Test
87
+ fun whenSubdomsinDoesNotSupportApplicationThenUaOmitsApplicationComponent () {
88
+ testee = UserAgentProvider (Agent .DEFAULT , deviceInfo)
89
+ val actual = testee.userAgent(NO_APPLICATION_SUBDOMAIN )
90
+ assertTrue(" $actual does not match expected regex" , ValidationRegex .noApplication.matches(actual))
91
+ }
92
+
93
+ @Test
94
+ fun whenDomainSupportsApplicationThenUaAddsApplicationComponentBeforeSafari () {
95
+ testee = UserAgentProvider (Agent .DEFAULT , deviceInfo)
96
+ val actual = testee.userAgent(DOMAIN )
97
+ assertTrue(" $actual does not match expected regex" , ValidationRegex .converted.matches(actual))
98
+ }
99
+
100
+ @Test
101
+ fun whenDomainDoesNotSupportVersionThenUaOmitsVersionComponent () {
102
+ testee = UserAgentProvider (Agent .DEFAULT , deviceInfo)
103
+ val actual = testee.userAgent(NO_VERSION_DOMAIN )
104
+ assertTrue(" $actual does not match expected regex" , ValidationRegex .noVersion.matches(actual))
105
+ }
106
+
107
+ @Test
108
+ fun whenSubdomainDoesNotSupportVersionThenUaOmitsVersionComponent () {
109
+ testee = UserAgentProvider (Agent .DEFAULT , deviceInfo)
110
+ val actual = testee.userAgent(NO_VERSION_SUBDOMAIN )
111
+ assertTrue(" $actual does not match expected regex" , ValidationRegex .noVersion.matches(actual))
112
+ }
113
+
114
+ @Test
115
+ fun whenDomainSupportsVersionThenUaIncludesVersionComponentInUsualLocation () {
116
+ testee = UserAgentProvider (Agent .DEFAULT , deviceInfo)
117
+ val actual = testee.userAgent(DOMAIN )
118
+ assertTrue(" $actual does not match expected regex" , ValidationRegex .converted.matches(actual))
119
+ }
120
+
121
+ @Test
122
+ fun whenUserAgentIsForASiteThatShouldUseDesktopAgentThenReturnDesktopUserAgent () {
123
+ testee = UserAgentProvider (Agent .DEFAULT , deviceInfo)
124
+ val actual = testee.userAgent(DESKTOP_ONLY_SITE )
125
+ assertTrue(" $actual does not match expected regex" , ValidationRegex .desktop.matches(actual))
126
+ }
127
+
128
+ @Test
129
+ fun whenUserAgentIsForASiteThatShouldUseDesktopAgentButContainsAnExclusionThenDoNotReturnConvertedUserAgent () {
130
+ testee = UserAgentProvider (Agent .DEFAULT , deviceInfo)
131
+ val actual = testee.userAgent(DESKTOP_ONLY_SITE_EXCEPTION )
132
+ assertTrue(" $actual does not match expected regex" , ValidationRegex .converted.matches(actual))
133
+ }
132
134
133
135
companion object {
134
136
const val DOMAIN = " http://example.com"
0 commit comments