browser 1.1.0 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.bundle/config +2 -0
  3. data/.hound.yml +26 -6
  4. data/.rubocop.yml +26 -6
  5. data/CHANGELOG.md +10 -0
  6. data/README.md +177 -41
  7. data/Rakefile +1 -1
  8. data/bin/rake +16 -0
  9. data/bot_exceptions.yml +1 -0
  10. data/bots.yml +188 -192
  11. data/browser.gemspec +14 -28
  12. data/languages.yml +54 -54
  13. data/lib/browser.rb +82 -202
  14. data/lib/browser/accept_language.rb +47 -0
  15. data/lib/browser/action_controller.rb +1 -1
  16. data/lib/browser/base.rb +159 -0
  17. data/lib/browser/blackberry.rb +21 -0
  18. data/lib/browser/bot.rb +63 -0
  19. data/lib/browser/chrome.rb +23 -0
  20. data/lib/browser/detect_version.rb +19 -0
  21. data/lib/browser/device.rb +175 -0
  22. data/lib/browser/device/base.rb +11 -0
  23. data/lib/browser/device/blackberry_playbook.rb +17 -0
  24. data/lib/browser/device/ipad.rb +17 -0
  25. data/lib/browser/device/iphone.rb +17 -0
  26. data/lib/browser/device/ipod_touch.rb +17 -0
  27. data/lib/browser/device/kindle.rb +17 -0
  28. data/lib/browser/device/kindle_fire.rb +17 -0
  29. data/lib/browser/device/playstation3.rb +17 -0
  30. data/lib/browser/device/playstation4.rb +17 -0
  31. data/lib/browser/device/psp.rb +17 -0
  32. data/lib/browser/device/psvita.rb +17 -0
  33. data/lib/browser/device/surface.rb +23 -0
  34. data/lib/browser/device/tv.rb +17 -0
  35. data/lib/browser/device/unknown.rb +17 -0
  36. data/lib/browser/device/wii.rb +17 -0
  37. data/lib/browser/device/wiiu.rb +17 -0
  38. data/lib/browser/device/xbox_360.rb +17 -0
  39. data/lib/browser/device/xbox_one.rb +17 -0
  40. data/lib/browser/edge.rb +19 -0
  41. data/lib/browser/firefox.rb +19 -0
  42. data/lib/browser/generic.rb +32 -0
  43. data/lib/browser/internet_explorer.rb +61 -0
  44. data/lib/browser/meta/base.rb +1 -1
  45. data/lib/browser/meta/device.rb +9 -0
  46. data/lib/browser/meta/generic_browser.rb +1 -1
  47. data/lib/browser/meta/id.rb +1 -1
  48. data/lib/browser/meta/ie.rb +1 -1
  49. data/lib/browser/meta/ios.rb +2 -2
  50. data/lib/browser/meta/mobile.rb +2 -2
  51. data/lib/browser/meta/modern.rb +1 -1
  52. data/lib/browser/meta/platform.rb +2 -2
  53. data/lib/browser/meta/proxy.rb +1 -1
  54. data/lib/browser/meta/safari.rb +1 -1
  55. data/lib/browser/meta/tablet.rb +9 -0
  56. data/lib/browser/meta/webkit.rb +1 -1
  57. data/lib/browser/middleware.rb +1 -1
  58. data/lib/browser/middleware/context.rb +2 -2
  59. data/lib/browser/middleware/context/additions.rb +1 -1
  60. data/lib/browser/middleware/context/url_methods.rb +3 -3
  61. data/lib/browser/nokia.rb +19 -0
  62. data/lib/browser/opera.rb +19 -0
  63. data/lib/browser/phantom_js.rb +19 -0
  64. data/lib/browser/platform.rb +152 -0
  65. data/lib/browser/platform/adobe_air.rb +21 -0
  66. data/lib/browser/platform/android.rb +21 -0
  67. data/lib/browser/platform/base.rb +15 -0
  68. data/lib/browser/platform/blackberry.rb +21 -0
  69. data/lib/browser/platform/chrome_os.rb +21 -0
  70. data/lib/browser/platform/firefox_os.rb +21 -0
  71. data/lib/browser/platform/ios.rb +28 -0
  72. data/lib/browser/platform/linux.rb +21 -0
  73. data/lib/browser/platform/mac.rb +21 -0
  74. data/lib/browser/platform/other.rb +21 -0
  75. data/lib/browser/platform/windows.rb +21 -0
  76. data/lib/browser/platform/windows_mobile.rb +21 -0
  77. data/lib/browser/platform/windows_phone.rb +21 -0
  78. data/lib/browser/rails.rb +3 -2
  79. data/lib/browser/safari.rb +22 -0
  80. data/lib/browser/testing.rb +23 -0
  81. data/lib/browser/uc_browser.rb +19 -0
  82. data/lib/browser/version.rb +2 -7
  83. data/search_engines.yml +5 -5
  84. data/test/browser_test.rb +71 -172
  85. data/test/middleware_test.rb +7 -7
  86. data/test/sample_app.rb +3 -3
  87. data/test/test_helper.rb +11 -10
  88. data/test/ua.yml +15 -26
  89. data/test/ua_bots.yml +27 -0
  90. data/test/ua_search_engines.yml +6 -0
  91. data/test/unit/accept_language_test.rb +92 -0
  92. data/test/unit/adobe_air_test.rb +5 -10
  93. data/test/unit/android_test.rb +44 -49
  94. data/test/unit/blackberry_test.rb +55 -77
  95. data/test/unit/bots_test.rb +52 -84
  96. data/test/unit/chrome_test.rb +48 -42
  97. data/test/unit/console_test.rb +4 -62
  98. data/test/unit/device_test.rb +193 -0
  99. data/test/unit/firefox_test.rb +32 -27
  100. data/test/unit/ie_test.rb +223 -238
  101. data/test/unit/ios_app_test.rb +3 -3
  102. data/test/unit/ios_test.rb +87 -94
  103. data/test/unit/kindle_test.rb +10 -24
  104. data/test/unit/nokia_test.rb +3 -7
  105. data/test/unit/opera_test.rb +20 -30
  106. data/test/unit/platform_test.rb +161 -0
  107. data/test/unit/proxy_test.rb +3 -3
  108. data/test/unit/safari_test.rb +66 -0
  109. data/test/unit/uc_browser_test.rb +3 -7
  110. data/test/unit/windows_phone_test.rb +19 -40
  111. data/test/unit/windows_test.rb +32 -34
  112. metadata +73 -28
  113. data/lib/browser/methods/blackberry.rb +0 -51
  114. data/lib/browser/methods/bots.rb +0 -35
  115. data/lib/browser/methods/consoles.rb +0 -43
  116. data/lib/browser/methods/devices.rb +0 -41
  117. data/lib/browser/methods/ie.rb +0 -99
  118. data/lib/browser/methods/language.rb +0 -16
  119. data/lib/browser/methods/mobile.rb +0 -35
  120. data/lib/browser/methods/platform.rb +0 -152
  121. data/lib/browser/methods/proxy.rb +0 -8
  122. data/lib/browser/methods/tv.rb +0 -8
@@ -0,0 +1,193 @@
1
+ require "test_helper"
2
+
3
+ class DeviceTest < Minitest::Test
4
+ test "detect generic device" do
5
+ device = Browser::Device.new("")
6
+
7
+ assert device.unknown?
8
+ assert_equal :unknown, device.id
9
+ end
10
+
11
+ test "detect ipad" do
12
+ device = Browser::Device.new(Browser["IOS9"])
13
+ assert device.ipad?
14
+ assert_equal :ipad, device.id
15
+ assert_equal "iPad", device.name
16
+ end
17
+
18
+ test "detect ipod" do
19
+ device = Browser::Device.new(Browser["IPOD"])
20
+ assert device.ipod_touch?
21
+ assert device.ipod?
22
+ assert_equal :ipod_touch, device.id
23
+ assert_equal "iPod Touch", device.name
24
+ end
25
+
26
+ test "detect iphone" do
27
+ device = Browser::Device.new(Browser["IOS8"])
28
+ assert device.iphone?
29
+ assert_equal :iphone, device.id
30
+ assert_equal "iPhone", device.name
31
+ end
32
+
33
+ test "detect ps3" do
34
+ device = Browser::Device.new(Browser["PLAYSTATION3"])
35
+ assert device.ps3?
36
+ assert device.playstation3?
37
+ assert device.playstation?
38
+ assert_equal :ps3, device.id
39
+ assert_equal "PlayStation 3", device.name
40
+ end
41
+
42
+ test "detect ps4" do
43
+ device = Browser::Device.new(Browser["PLAYSTATION4"])
44
+ assert device.ps4?
45
+ assert device.playstation4?
46
+ assert device.playstation?
47
+ assert_equal :ps4, device.id
48
+ assert_equal "PlayStation 4", device.name
49
+ end
50
+
51
+ test "detects xbox 360" do
52
+ device = Browser::Device.new(Browser["XBOX360"])
53
+
54
+ assert device.console?
55
+ assert device.xbox?
56
+ refute device.xbox_one?
57
+ assert_equal :xbox_360, device.id
58
+ assert_equal "Xbox 360", device.name
59
+ end
60
+
61
+ test "detects xbox one" do
62
+ device = Browser::Device.new(Browser["XBOXONE"])
63
+
64
+ assert device.console?
65
+ assert device.xbox?
66
+ assert device.xbox_one?
67
+ assert_equal :xbox_one, device.id
68
+ assert_equal "Xbox One", device.name
69
+ end
70
+
71
+ test "detect psp" do
72
+ device = Browser::Device.new(Browser["PSP"])
73
+ assert device.psp?
74
+ assert_equal :psp, device.id
75
+ assert_equal "PlayStation Portable", device.name
76
+ end
77
+
78
+ test "detect psvita" do
79
+ device = Browser::Device.new(Browser["PSP_VITA"])
80
+ assert device.playstation_vita?
81
+ assert device.vita?
82
+ assert_equal :psvita, device.id
83
+ assert_equal "PlayStation Vita", device.name
84
+ end
85
+
86
+ test "detect kindle" do
87
+ device = Browser::Device.new(Browser["KINDLE"])
88
+ assert device.kindle?
89
+ assert_equal :kindle, device.id
90
+ assert_equal "Kindle", device.name
91
+ refute device.silk?
92
+ end
93
+
94
+ %w[
95
+ KINDLE_FIRE
96
+ KINDLE_FIRE_HD
97
+ KINDLE_FIRE_HD_MOBILE
98
+ ].each do |key|
99
+ test "detect #{key} as kindle fire" do
100
+ device = Browser::Device.new(Browser[key])
101
+
102
+ assert device.kindle?
103
+ assert device.kindle_fire?
104
+ assert_equal :kindle_fire, device.id
105
+ assert_equal "Kindle Fire", device.name
106
+ end
107
+ end
108
+
109
+ test "detect wii" do
110
+ device = Browser::Device.new(Browser["NINTENDO_WII"])
111
+ assert device.nintendo_wii?
112
+ assert device.console?
113
+ assert device.nintendo?
114
+ assert device.wii?
115
+ assert_equal :wii, device.id
116
+ assert_equal "Nintendo Wii", device.name
117
+ end
118
+
119
+ test "detect wiiu" do
120
+ device = Browser::Device.new(Browser["NINTENDO_WIIU"])
121
+ assert device.nintendo_wiiu?
122
+ assert device.wiiu?
123
+ assert device.console?
124
+ assert device.nintendo?
125
+ assert_equal :wiiu, device.id
126
+ assert_equal "Nintendo WiiU", device.name
127
+ end
128
+
129
+ test "detect blackberry playbook" do
130
+ device = Browser::Device.new(Browser["PLAYBOOK"])
131
+ assert device.playbook?
132
+ assert device.blackberry_playbook?
133
+ assert_equal :playbook, device.id
134
+ assert_equal "BlackBerry Playbook", device.name
135
+ end
136
+
137
+ test "detect surface" do
138
+ device = Browser::Device.new(Browser["SURFACE"])
139
+ assert device.surface?
140
+ assert_equal :surface, device.id
141
+ assert_equal "Microsoft Surface", device.name
142
+ end
143
+
144
+ test "detect tv" do
145
+ device = Browser::Device.new(Browser["SMART_TV"])
146
+ assert device.tv?
147
+ assert_equal :tv, device.id
148
+ assert_equal "TV", device.name
149
+ end
150
+
151
+ %w[
152
+ ANDROID
153
+ SYMBIAN
154
+ MIDP
155
+ IPHONE
156
+ IPOD
157
+ WINDOWS_MOBILE
158
+ WINDOWS_PHONE
159
+ WINDOWS_PHONE8
160
+ WINDOWS_PHONE_81
161
+ OPERA_MINI
162
+ LUMIA800
163
+ MS_EDGE_MOBILE
164
+ UC_BROWSER
165
+ NOKIA
166
+ OPERA_MOBI
167
+ KINDLE_FIRE_HD_MOBILE
168
+ ].each do |key|
169
+ test "detect #{key} as mobile" do
170
+ device = Browser::Device.new(Browser[key])
171
+ assert device.mobile?
172
+ refute device.tablet?
173
+ end
174
+ end
175
+
176
+ %w[
177
+ PLAYBOOK
178
+ IPAD
179
+ NEXUS_TABLET
180
+ SURFACE
181
+ XOOM
182
+ NOOK
183
+ SAMSUNG
184
+ FIREFOX_TABLET
185
+ NEXUS7
186
+ ].each do |key|
187
+ test "detect #{key} as tablet" do
188
+ device = Browser::Device.new(Browser[key])
189
+ assert device.tablet?
190
+ refute device.mobile?
191
+ end
192
+ end
193
+ end
@@ -1,41 +1,46 @@
1
1
  require "test_helper"
2
2
 
3
3
  class FirefoxTest < Minitest::Test
4
- setup do
5
- @browser = Browser.new
4
+ test "detects firefox" do
5
+ browser = Browser.new(Browser["FIREFOX"])
6
+
7
+ assert_equal "Firefox", browser.name
8
+ assert browser.firefox?
9
+ refute browser.modern?
10
+ assert_equal "3.8", browser.full_version
11
+ assert_equal "3", browser.version
6
12
  end
7
13
 
8
- test "detects firefox" do
9
- @browser.ua = $ua["FIREFOX"]
14
+ test "detects firefox for iOS" do
15
+ browser = Browser.new(Browser["FIREFOX_IOS"])
10
16
 
11
- assert_equal "Firefox", @browser.name
12
- assert @browser.firefox?
13
- refute @browser.modern?
14
- assert_equal "3.8", @browser.full_version
15
- assert_equal "3", @browser.version
17
+ assert_equal "Firefox", browser.name
18
+ assert browser.firefox?
19
+ assert browser.platform.ios?
20
+ assert_equal "1.2", browser.full_version
21
+ assert_equal "1", browser.version
16
22
  end
17
23
 
18
24
  test "detects modern firefox" do
19
- @browser.ua = $ua["FIREFOX_MODERN"]
20
-
21
- assert_equal :firefox, @browser.id
22
- assert_equal "Firefox", @browser.name
23
- assert @browser.firefox?
24
- assert @browser.modern?
25
- assert_equal "17.0", @browser.full_version
26
- assert_equal "17", @browser.version
25
+ browser = Browser.new(Browser["FIREFOX_MODERN"])
26
+
27
+ assert_equal :firefox, browser.id
28
+ assert_equal "Firefox", browser.name
29
+ assert browser.firefox?
30
+ assert browser.modern?
31
+ assert_equal "17.0", browser.full_version
32
+ assert_equal "17", browser.version
27
33
  end
28
34
 
29
35
  test "detects firefox android tablet" do
30
- @browser.ua = $ua["FIREFOX_TABLET"]
31
-
32
- assert_equal :firefox, @browser.id
33
- assert_equal "Firefox", @browser.name
34
- assert @browser.firefox?
35
- assert @browser.modern?
36
- assert @browser.tablet?
37
- assert @browser.android?
38
- assert_equal "14.0", @browser.full_version
39
- assert_equal "14", @browser.version
36
+ browser = Browser.new(Browser["FIREFOX_TABLET"])
37
+
38
+ assert_equal :firefox, browser.id
39
+ assert_equal "Firefox", browser.name
40
+ assert browser.firefox?
41
+ assert browser.modern?
42
+ assert browser.platform.android?
43
+ assert_equal "14.0", browser.full_version
44
+ assert_equal "14", browser.version
40
45
  end
41
46
  end
@@ -1,340 +1,325 @@
1
1
  require "test_helper"
2
2
 
3
3
  class IeTest < Minitest::Test
4
- setup do
5
- @browser = Browser.new
6
- end
7
-
8
4
  test "detects ie6" do
9
- @browser.ua = $ua["IE6"]
5
+ browser = Browser.new(Browser["IE6"])
10
6
 
11
- assert_equal "Internet Explorer", @browser.name
12
- assert @browser.ie?
13
- assert @browser.ie?(6)
14
- refute @browser.modern?
15
- assert_equal "6.0", @browser.full_version
16
- assert_equal "6", @browser.version
7
+ assert_equal "Internet Explorer", browser.name
8
+ assert browser.ie?
9
+ assert browser.ie?(6)
10
+ refute browser.modern?
11
+ assert_equal "6.0", browser.full_version
12
+ assert_equal "6", browser.version
17
13
  end
18
14
 
19
15
  test "detects ie7" do
20
- @browser.ua = $ua["IE7"]
16
+ browser = Browser.new(Browser["IE7"])
21
17
 
22
- assert_equal "Internet Explorer", @browser.name
23
- assert @browser.ie?
24
- assert @browser.ie?(7)
25
- refute @browser.modern?
26
- assert_equal "7.0", @browser.full_version
27
- assert_equal "7", @browser.version
18
+ assert_equal "Internet Explorer", browser.name
19
+ assert browser.ie?
20
+ assert browser.ie?(7)
21
+ refute browser.modern?
22
+ assert_equal "7.0", browser.full_version
23
+ assert_equal "7", browser.version
28
24
  end
29
25
 
30
26
  test "detects ie8" do
31
- @browser.ua = $ua["IE8"]
27
+ browser = Browser.new(Browser["IE8"])
32
28
 
33
- assert_equal "Internet Explorer", @browser.name
34
- assert @browser.ie?
35
- assert @browser.ie?(8)
36
- refute @browser.modern?
37
- refute @browser.compatibility_view?
38
- assert_equal "8.0", @browser.full_version
39
- assert_equal "8", @browser.version
29
+ assert_equal "Internet Explorer", browser.name
30
+ assert browser.ie?
31
+ assert browser.ie?(8)
32
+ refute browser.modern?
33
+ refute browser.compatibility_view?
34
+ assert_equal "8.0", browser.full_version
35
+ assert_equal "8", browser.version
40
36
  end
41
37
 
42
38
  test "detects ie8 in compatibility view" do
43
- @browser.ua = $ua["IE8_COMPAT"]
39
+ browser = Browser.new(Browser["IE8_COMPAT"])
44
40
 
45
- assert_equal "Internet Explorer", @browser.name
46
- assert @browser.ie?
47
- assert @browser.ie?(8)
48
- refute @browser.modern?
49
- assert @browser.compatibility_view?
50
- assert_equal "8.0", @browser.full_version
51
- assert_equal "8", @browser.version
52
- assert_equal "7.0", @browser.msie_full_version
53
- assert_equal "7", @browser.msie_version
41
+ assert_equal "Internet Explorer", browser.name
42
+ assert browser.ie?
43
+ assert browser.ie?(8)
44
+ refute browser.modern?
45
+ assert browser.compatibility_view?
46
+ assert_equal "8.0", browser.full_version
47
+ assert_equal "8", browser.version
48
+ assert_equal "7.0", browser.msie_full_version
49
+ assert_equal "7", browser.msie_version
54
50
  end
55
51
 
56
52
  test "detects ie9" do
57
- @browser.ua = $ua["IE9"]
53
+ browser = Browser.new(Browser["IE9"])
58
54
 
59
- assert_equal "Internet Explorer", @browser.name
60
- assert @browser.ie?
61
- assert @browser.ie?(9)
62
- assert @browser.modern?
63
- refute @browser.compatibility_view?
64
- assert_equal "9.0", @browser.full_version
65
- assert_equal "9", @browser.version
55
+ assert_equal "Internet Explorer", browser.name
56
+ assert browser.ie?
57
+ assert browser.ie?(9)
58
+ assert browser.modern?
59
+ refute browser.compatibility_view?
60
+ assert_equal "9.0", browser.full_version
61
+ assert_equal "9", browser.version
66
62
  end
67
63
 
68
64
  test "detects ie9 in compatibility view" do
69
- @browser.ua = $ua["IE9_COMPAT"]
65
+ browser = Browser.new(Browser["IE9_COMPAT"])
70
66
 
71
- assert_equal "Internet Explorer", @browser.name
72
- assert @browser.ie?
73
- assert @browser.ie?(9)
74
- refute @browser.modern?
75
- assert @browser.compatibility_view?
76
- assert_equal "9.0", @browser.full_version
77
- assert_equal "9", @browser.version
78
- assert_equal "7.0", @browser.msie_full_version
79
- assert_equal "7", @browser.msie_version
67
+ assert_equal "Internet Explorer", browser.name
68
+ assert browser.ie?
69
+ assert browser.ie?(9)
70
+ refute browser.modern?
71
+ assert browser.compatibility_view?
72
+ assert_equal "9.0", browser.full_version
73
+ assert_equal "9", browser.version
74
+ assert_equal "7.0", browser.msie_full_version
75
+ assert_equal "7", browser.msie_version
80
76
  end
81
77
 
82
78
  test "detects ie10" do
83
- @browser.ua = $ua["IE10"]
79
+ browser = Browser.new(Browser["IE10"])
84
80
 
85
- assert_equal "Internet Explorer", @browser.name
86
- assert @browser.ie?
87
- assert @browser.ie?(10)
88
- assert @browser.modern?
89
- refute @browser.compatibility_view?
90
- assert_equal "10.0", @browser.full_version
91
- assert_equal "10", @browser.version
81
+ assert_equal "Internet Explorer", browser.name
82
+ assert browser.ie?
83
+ assert browser.ie?(10)
84
+ assert browser.modern?
85
+ refute browser.compatibility_view?
86
+ assert_equal "10.0", browser.full_version
87
+ assert_equal "10", browser.version
92
88
  end
93
89
 
94
90
  test "detects ie10 in compatibility view" do
95
- @browser.ua = $ua["IE10_COMPAT"]
91
+ browser = Browser.new(Browser["IE10_COMPAT"])
96
92
 
97
- assert_equal "Internet Explorer", @browser.name
98
- assert @browser.ie?
99
- assert @browser.ie?(10)
100
- refute @browser.modern?
101
- assert @browser.compatibility_view?
102
- assert_equal "10.0", @browser.full_version
103
- assert_equal "10", @browser.version
104
- assert_equal "7.0", @browser.msie_full_version
105
- assert_equal "7", @browser.msie_version
93
+ assert_equal "Internet Explorer", browser.name
94
+ assert browser.ie?
95
+ assert browser.ie?(10)
96
+ refute browser.modern?
97
+ assert browser.compatibility_view?
98
+ assert_equal "10.0", browser.full_version
99
+ assert_equal "10", browser.version
100
+ assert_equal "7.0", browser.msie_full_version
101
+ assert_equal "7", browser.msie_version
106
102
  end
107
103
 
108
104
  test "detects ie11" do
109
- @browser.ua = $ua["IE11"]
105
+ browser = Browser.new(Browser["IE11"])
110
106
 
111
- assert_equal "Internet Explorer", @browser.name
112
- assert @browser.ie?
113
- assert @browser.ie?(11)
114
- assert @browser.modern?
115
- refute @browser.compatibility_view?
116
- assert_equal "11.0", @browser.full_version
117
- assert_equal "11", @browser.version
107
+ assert_equal "Internet Explorer", browser.name
108
+ assert browser.ie?
109
+ assert browser.ie?(11)
110
+ assert browser.modern?
111
+ refute browser.compatibility_view?
112
+ assert_equal "11.0", browser.full_version
113
+ assert_equal "11", browser.version
118
114
  end
119
115
 
120
116
  test "detects ie11 in compatibility view" do
121
- @browser.ua = $ua["IE11_COMPAT"]
117
+ browser = Browser.new(Browser["IE11_COMPAT"])
122
118
 
123
- assert_equal "Internet Explorer", @browser.name
124
- assert @browser.ie?
125
- assert @browser.ie?(11)
126
- refute @browser.modern?
127
- assert @browser.compatibility_view?
128
- assert_equal "11.0", @browser.full_version
129
- assert_equal "11", @browser.version
130
- assert_equal "7.0", @browser.msie_full_version
131
- assert_equal "7", @browser.msie_version
119
+ assert_equal "Internet Explorer", browser.name
120
+ assert browser.ie?
121
+ assert browser.ie?(11)
122
+ refute browser.modern?
123
+ assert browser.compatibility_view?
124
+ assert_equal "11.0", browser.full_version
125
+ assert_equal "11", browser.version
126
+ assert_equal "7.0", browser.msie_full_version
127
+ assert_equal "7", browser.msie_version
132
128
  end
133
129
 
134
130
  test "detects Lumia 800" do
135
- @browser.ua = $ua["LUMIA800"]
131
+ browser = Browser.new(Browser["LUMIA800"])
136
132
 
137
- assert_equal "Internet Explorer", @browser.name
138
- assert @browser.ie?
139
- assert @browser.ie?(9)
140
- assert_equal "9.0", @browser.full_version
141
- assert_equal "9", @browser.version
142
- refute @browser.tablet?
143
- assert @browser.mobile?
133
+ assert_equal "Internet Explorer", browser.name
134
+ assert browser.ie?
135
+ assert browser.ie?(9)
136
+ assert_equal "9.0", browser.full_version
137
+ assert_equal "9", browser.version
144
138
  end
145
139
 
146
140
  test "detects ie11 touch desktop pc" do
147
- @browser.ua = $ua["IE11_TOUCH_SCREEN"]
141
+ browser = Browser.new(Browser["IE11_TOUCH_SCREEN"])
148
142
 
149
- assert_equal "Internet Explorer", @browser.name
150
- assert @browser.ie?
151
- assert @browser.ie?(11)
152
- assert @browser.modern?
153
- refute @browser.compatibility_view?
154
- refute @browser.windows_rt?
155
- assert @browser.windows_touchscreen_desktop?
156
- assert @browser.windows8?
157
- assert_equal "11.0", @browser.full_version
158
- assert_equal "11", @browser.version
143
+ assert_equal "Internet Explorer", browser.name
144
+ assert browser.ie?
145
+ assert browser.ie?(11)
146
+ assert browser.modern?
147
+ refute browser.compatibility_view?
148
+ refute browser.platform.windows_rt?
149
+ assert browser.platform.windows_touchscreen_desktop?
150
+ assert browser.platform.windows8?
151
+ assert_equal "11.0", browser.full_version
152
+ assert_equal "11", browser.version
159
153
  end
160
154
 
161
155
  test "detects Microsoft Edge" do
162
- @browser.ua = $ua["MS_EDGE"]
156
+ browser = Browser.new(Browser["MS_EDGE"])
163
157
 
164
- assert_equal :edge, @browser.id
165
- assert_equal "Microsoft Edge", @browser.name
166
- assert_equal "12.0", @browser.full_version
167
- assert_equal "12", @browser.version
168
- assert @browser.windows10?
169
- assert @browser.edge?
170
- assert @browser.modern?
171
- refute @browser.webkit?
172
- refute @browser.chrome?
173
- refute @browser.safari?
174
- refute @browser.mobile?
158
+ assert_equal :edge, browser.id
159
+ assert_equal "Microsoft Edge", browser.name
160
+ assert_equal "12.0", browser.full_version
161
+ assert_equal "12", browser.version
162
+ assert browser.platform.windows10?
163
+ assert browser.edge?
164
+ assert browser.modern?
165
+ refute browser.webkit?
166
+ refute browser.chrome?
167
+ refute browser.safari?
168
+ refute browser.device.mobile?
175
169
  end
176
170
 
177
171
  test "detects Microsoft Edge in compatibility view" do
178
- @browser.ua = $ua["MS_EDGE_COMPAT"]
179
-
180
- assert_equal :edge, @browser.id
181
- assert_equal "Microsoft Edge", @browser.name
182
- assert_equal "12.0", @browser.full_version
183
- assert_equal "12", @browser.version
184
- assert_equal "7.0", @browser.msie_full_version
185
- assert_equal "7", @browser.msie_version
186
- assert @browser.edge?
187
- assert @browser.compatibility_view?
188
- refute @browser.modern?
189
- refute @browser.webkit?
190
- refute @browser.chrome?
191
- refute @browser.safari?
192
- refute @browser.mobile?
172
+ browser = Browser.new(Browser["MS_EDGE_COMPAT"])
173
+
174
+ assert_equal :edge, browser.id
175
+ assert_equal "Microsoft Edge", browser.name
176
+ assert_equal "12.0", browser.full_version
177
+ assert_equal "12", browser.version
178
+ assert_equal "7.0", browser.msie_full_version
179
+ assert_equal "7", browser.msie_version
180
+ assert browser.edge?
181
+ assert browser.compatibility_view?
182
+ refute browser.modern?
183
+ refute browser.webkit?
184
+ refute browser.chrome?
185
+ refute browser.safari?
186
+ refute browser.device.mobile?
193
187
  end
194
188
 
195
189
  test "detects Microsoft Edge Mobile" do
196
- @browser.ua = $ua["MS_EDGE_MOBILE"]
197
-
198
- assert_equal :edge, @browser.id
199
- assert_equal "Microsoft Edge", @browser.name
200
- assert_equal "12.0", @browser.full_version
201
- assert_equal "12", @browser.version
202
- refute @browser.windows10?
203
- assert @browser.windows_phone?
204
- assert @browser.edge?
205
- assert @browser.modern?
206
- assert @browser.mobile?
207
- refute @browser.webkit?
208
- refute @browser.chrome?
209
- refute @browser.safari?
190
+ browser = Browser.new(Browser["MS_EDGE_MOBILE"])
191
+
192
+ assert_equal :edge, browser.id
193
+ assert_equal "Microsoft Edge", browser.name
194
+ assert_equal "12.0", browser.full_version
195
+ assert_equal "12", browser.version
196
+ refute browser.platform.windows10?
197
+ assert browser.platform.windows_phone?
198
+ assert browser.edge?
199
+ assert browser.modern?
200
+ refute browser.webkit?
201
+ refute browser.chrome?
202
+ refute browser.safari?
210
203
  end
211
204
 
212
205
  test "detects IE without Trident" do
213
- @browser.ua = $ua["IE_WITHOUT_TRIDENT"]
214
-
215
- assert_equal :ie, @browser.id
216
- assert_equal "Internet Explorer", @browser.name
217
- assert_equal "0.0", @browser.msie_full_version
218
- assert_equal "0", @browser.msie_version
219
- assert_equal "0.0", @browser.full_version
220
- assert_equal "0", @browser.version
221
- refute @browser.windows10?
222
- refute @browser.windows_phone?
223
- refute @browser.edge?
224
- refute @browser.modern?
225
- refute @browser.mobile?
226
- refute @browser.webkit?
227
- refute @browser.chrome?
228
- refute @browser.safari?
206
+ browser = Browser.new(Browser["IE_WITHOUT_TRIDENT"])
207
+
208
+ assert_equal :ie, browser.id
209
+ assert_equal "Internet Explorer", browser.name
210
+ assert_equal "0.0", browser.msie_full_version
211
+ assert_equal "0", browser.msie_version
212
+ assert_equal "0.0", browser.full_version
213
+ assert_equal "0", browser.version
214
+ refute browser.platform.windows10?
215
+ refute browser.platform.windows_phone?
216
+ refute browser.edge?
217
+ refute browser.modern?
218
+ refute browser.device.mobile?
219
+ refute browser.webkit?
220
+ refute browser.chrome?
221
+ refute browser.safari?
229
222
  end
230
223
 
231
224
  test "detects windows phone" do
232
- @browser.ua = $ua["WINDOWS_PHONE"]
225
+ browser = Browser.new(Browser["WINDOWS_PHONE"])
233
226
 
234
- assert @browser.ie?
235
- assert_equal "7", @browser.version
236
- assert @browser.mobile?
237
- assert @browser.windows_phone?
238
- refute @browser.windows_mobile?
239
- refute @browser.tablet?
227
+ assert browser.ie?
228
+ assert_equal "7", browser.version
229
+ assert browser.platform.windows_phone?
230
+ refute browser.platform.windows_mobile?
240
231
  end
241
232
 
242
233
  test "detects windows phone 8" do
243
- @browser.ua = $ua["WINDOWS_PHONE8"]
234
+ browser = Browser.new(Browser["WINDOWS_PHONE8"])
244
235
 
245
- assert @browser.ie?
246
- assert_equal "10", @browser.version
247
- assert @browser.mobile?
248
- assert @browser.windows_phone?
249
- refute @browser.windows_mobile?
250
- refute @browser.tablet?
236
+ assert browser.ie?
237
+ assert_equal "10", browser.version
238
+ assert browser.platform.windows_phone?
239
+ refute browser.platform.windows_mobile?
251
240
  end
252
241
 
253
242
  test "detects windows phone 8.1" do
254
- @browser.ua = $ua["WINDOWS_PHONE_81"]
243
+ browser = Browser.new(Browser["WINDOWS_PHONE_81"])
255
244
 
256
- assert @browser.ie?
257
- assert_equal "Internet Explorer", @browser.name
258
- assert_equal :ie, @browser.id
259
- assert_equal "11", @browser.version
260
- assert_equal "11.0", @browser.full_version
261
- assert @browser.mobile?
262
- assert @browser.windows_phone?
263
- refute @browser.windows_mobile?
264
- refute @browser.tablet?
245
+ assert browser.ie?
246
+ assert_equal "Internet Explorer", browser.name
247
+ assert_equal :ie, browser.id
248
+ assert_equal "11", browser.version
249
+ assert_equal "11.0", browser.full_version
250
+ assert browser.platform.windows_phone?
251
+ refute browser.platform.windows_mobile?
265
252
  end
266
253
 
267
254
  test "detects windows mobile (windows phone 8)" do
268
- @browser.ua = $ua["WINDOWS_PHONE8"]
255
+ browser = Browser.new(Browser["WINDOWS_PHONE8"])
269
256
 
270
- assert @browser.ie?
271
- assert_equal "10", @browser.version
272
- assert @browser.mobile?
273
- assert @browser.windows_phone?
274
- refute @browser.windows_mobile?
275
- refute @browser.tablet?
257
+ assert browser.ie?
258
+ assert_equal "10", browser.version
259
+ assert browser.platform.windows_phone?
260
+ refute browser.platform.windows_mobile?
276
261
  end
277
262
 
278
263
  test "detects windows x64" do
279
- @browser.ua = $ua["IE10_X64_WINX64"]
280
- assert @browser.windows_x64?
281
- refute @browser.windows_wow64?
282
- assert @browser.windows_x64_inclusive?
264
+ browser = Browser.new(Browser["IE10_X64_WINX64"])
265
+ assert browser.platform.windows_x64?
266
+ refute browser.platform.windows_wow64?
267
+ assert browser.platform.windows_x64_inclusive?
283
268
  end
284
269
 
285
270
  test "detects windows wow64" do
286
- @browser.ua = $ua["WINDOWS_WOW64"]
287
- refute @browser.windows_x64?
288
- assert @browser.windows_wow64?
289
- assert @browser.windows_x64_inclusive?
271
+ browser = Browser.new(Browser["WINDOWS_WOW64"])
272
+ refute browser.platform.windows_x64?
273
+ assert browser.platform.windows_wow64?
274
+ assert browser.platform.windows_x64_inclusive?
290
275
  end
291
276
 
292
277
  test "detects windows platform" do
293
- @browser.ua = "Windows"
294
- assert_equal :windows, @browser.platform
295
- assert @browser.windows?
278
+ browser = Browser.new("Windows")
279
+ assert_equal :windows, browser.platform.id
280
+ assert browser.platform.windows?
296
281
  end
297
282
 
298
283
  test "detects windows_xp" do
299
- @browser.ua = $ua["WINDOWS_XP"]
284
+ browser = Browser.new(Browser["WINDOWS_XP"])
300
285
 
301
- assert @browser.windows?
302
- assert @browser.windows_xp?
286
+ assert browser.platform.windows?
287
+ assert browser.platform.windows_xp?
303
288
  end
304
289
 
305
290
  test "detects windows_vista" do
306
- @browser.ua = $ua["WINDOWS_VISTA"]
291
+ browser = Browser.new(Browser["WINDOWS_VISTA"])
307
292
 
308
- assert @browser.windows?
309
- assert @browser.windows_vista?
293
+ assert browser.platform.windows?
294
+ assert browser.platform.windows_vista?
310
295
  end
311
296
 
312
297
  test "detects windows7" do
313
- @browser.ua = $ua["WINDOWS7"]
298
+ browser = Browser.new(Browser["WINDOWS7"])
314
299
 
315
- assert @browser.windows?
316
- assert @browser.windows7?
300
+ assert browser.platform.windows?
301
+ assert browser.platform.windows7?
317
302
  end
318
303
 
319
304
  test "detects windows8" do
320
- @browser.ua = $ua["WINDOWS8"]
305
+ browser = Browser.new(Browser["WINDOWS8"])
321
306
 
322
- assert @browser.windows?
323
- assert @browser.windows8?
324
- refute @browser.windows8_1?
307
+ assert browser.platform.windows?
308
+ assert browser.platform.windows8?
309
+ refute browser.platform.windows8_1?
325
310
  end
326
311
 
327
312
  test "detects windows8.1" do
328
- @browser.ua = $ua["WINDOWS81"]
313
+ browser = Browser.new(Browser["WINDOWS81"])
329
314
 
330
- assert @browser.windows?
331
- assert @browser.windows8?
332
- assert @browser.windows8_1?
315
+ assert browser.platform.windows?
316
+ assert browser.platform.windows8?
317
+ assert browser.platform.windows8_1?
333
318
  end
334
319
 
335
320
  test "returns string representation for ie6" do
336
- @browser.ua = $ua["IE6"]
337
- meta = @browser.meta
321
+ browser = Browser.new(Browser["IE6"])
322
+ meta = browser.meta
338
323
 
339
324
  assert meta.include?("ie")
340
325
  assert meta.include?("ie6")
@@ -345,8 +330,8 @@ class IeTest < Minitest::Test
345
330
  end
346
331
 
347
332
  test "returns string representation for ie7" do
348
- @browser.ua = $ua["IE7"]
349
- meta = @browser.meta
333
+ browser = Browser.new(Browser["IE7"])
334
+ meta = browser.meta
350
335
 
351
336
  assert meta.include?("ie")
352
337
  assert meta.include?("ie7")
@@ -357,8 +342,8 @@ class IeTest < Minitest::Test
357
342
  end
358
343
 
359
344
  test "returns string representation for ie8" do
360
- @browser.ua = $ua["IE8"]
361
- meta = @browser.meta
345
+ browser = Browser.new(Browser["IE8"])
346
+ meta = browser.meta
362
347
 
363
348
  assert meta.include?("ie")
364
349
  assert meta.include?("ie8")
@@ -366,14 +351,14 @@ class IeTest < Minitest::Test
366
351
  assert meta.include?("windows")
367
352
  end
368
353
 
369
- test "warn about deprecated numbered version" do
370
- message = "Browser#ie6? is deprecated; use Browser#ie?(version) instead"
371
- assert_deprecated(message, __FILE__, __LINE__) { @browser.ie6? }
354
+ test "don't detect as two different versions" do
355
+ browser = Browser.new(Browser["IE8"])
356
+ assert browser.ie?(8)
357
+ refute browser.ie?(7)
372
358
  end
373
359
 
374
- test "don't detect as two different versions" do
375
- @browser.ua = $ua["IE8"]
376
- assert @browser.ie?(8)
377
- refute @browser.ie?(7)
360
+ test "more complex versioning check" do
361
+ browser = Browser.new(Browser["IE8"])
362
+ assert browser.ie?(["> 7", "< 9"])
378
363
  end
379
364
  end