browser 4.2.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -1
  3. data/FUNDING.yml +3 -0
  4. data/README.md +96 -47
  5. data/bots.yml +1 -1
  6. data/lib/browser/base.rb +53 -2
  7. data/lib/browser/browser.rb +22 -2
  8. data/lib/browser/chrome.rb +7 -1
  9. data/lib/browser/device.rb +2 -2
  10. data/lib/browser/device/unknown.rb +1 -1
  11. data/lib/browser/google_search_app.rb +21 -0
  12. data/lib/browser/huawei_browser.rb +21 -0
  13. data/lib/browser/maxthon.rb +21 -0
  14. data/lib/browser/miui_browser.rb +21 -0
  15. data/lib/browser/platform.rb +4 -4
  16. data/lib/browser/platform/ios.rb +1 -1
  17. data/lib/browser/platform/mac.rb +1 -1
  18. data/lib/browser/platform/{other.rb → unknown.rb} +3 -3
  19. data/lib/browser/platform/windows.rb +1 -1
  20. data/lib/browser/safari.rb +9 -1
  21. data/lib/browser/sougou_browser.rb +24 -0
  22. data/lib/browser/{generic.rb → unknown.rb} +3 -3
  23. data/lib/browser/version.rb +1 -1
  24. data/test/browser_test.rb +23 -6
  25. data/test/ua.yml +12 -4
  26. data/test/unit/adobe_air_test.rb +1 -1
  27. data/test/unit/alipay_test.rb +6 -0
  28. data/test/unit/console_test.rb +2 -2
  29. data/test/unit/device_test.rb +2 -2
  30. data/test/unit/duck_duck_go_test.rb +2 -0
  31. data/test/unit/google_search_app_test.rb +54 -0
  32. data/test/unit/huawei_browser_test.rb +25 -0
  33. data/test/unit/maxthon_test.rb +25 -0
  34. data/test/unit/meta_test.rb +9 -0
  35. data/test/unit/miui_browser_test.rb +25 -0
  36. data/test/unit/opera_test.rb +1 -0
  37. data/test/unit/platform_test.rb +6 -6
  38. data/test/unit/qq_test.rb +12 -0
  39. data/test/unit/safari_test.rb +12 -7
  40. data/test/unit/sougou_browser_test.rb +41 -0
  41. metadata +23 -7
@@ -10,6 +10,9 @@ class AlipayTest < Minitest::Test
10
10
  assert browser.alipay?
11
11
  assert_equal "Alipay", browser.name
12
12
  assert_equal "2.3.4", browser.full_version
13
+
14
+ refute browser.chrome?
15
+ refute browser.safari?
13
16
  end
14
17
 
15
18
  test "detects alipay Android" do
@@ -19,6 +22,9 @@ class AlipayTest < Minitest::Test
19
22
  assert browser.alipay?
20
23
  assert_equal "Alipay", browser.name
21
24
  assert_equal "9.0.1.073001", browser.full_version
25
+
26
+ refute browser.chrome?
27
+ refute browser.safari?
22
28
  end
23
29
 
24
30
  test "detects version by range" do
@@ -5,11 +5,11 @@ require "test_helper"
5
5
  class ConsoleTest < Minitest::Test
6
6
  test "detects psp" do
7
7
  browser = Browser.new(Browser["PSP"])
8
- assert_equal "Generic Browser", browser.name
8
+ assert_equal "Unknown Browser", browser.name
9
9
  end
10
10
 
11
11
  test "detects psp vita" do
12
12
  browser = Browser.new(Browser["PSP_VITA"])
13
- assert_equal "Generic Browser", browser.name
13
+ assert_equal "Unknown Browser", browser.name
14
14
  end
15
15
  end
@@ -20,14 +20,14 @@ class DeviceTest < Minitest::Test
20
20
 
21
21
  Browser::Device.matchers.shift
22
22
  device = Browser::Device.new("Custom")
23
- assert_equal :unknown, device.id
23
+ assert_equal :unknown_device, device.id
24
24
  end
25
25
 
26
26
  test "detect generic device" do
27
27
  device = Browser::Device.new("")
28
28
 
29
29
  assert device.unknown?
30
- assert_equal :unknown, device.id
30
+ assert_equal :unknown_device, device.id
31
31
  end
32
32
 
33
33
  test "detect ipad" do
@@ -9,6 +9,7 @@ class DuckDuckGoTest < Minitest::Test
9
9
  refute browser.safari?
10
10
  refute browser.chrome?
11
11
  assert browser.webkit?
12
+ refute browser.bot?
12
13
  assert_equal "DuckDuckGo", browser.name
13
14
  assert_equal :duckduckgo, browser.id
14
15
  end
@@ -18,6 +19,7 @@ class DuckDuckGoTest < Minitest::Test
18
19
  assert browser.duck_duck_go?
19
20
  refute browser.safari?
20
21
  refute browser.chrome?
22
+ refute browser.bot?
21
23
  assert_equal "DuckDuckGo", browser.name
22
24
  assert_equal :duckduckgo, browser.id
23
25
  end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class GoogleSearchAppTest < Minitest::Test
6
+ test "detects Google Search App (Android)" do
7
+ browser = Browser.new(Browser["GOOGLE_SEARCH_APP_ANDROID"])
8
+
9
+ assert browser.webkit?
10
+ assert browser.google_search_app?
11
+ assert browser.platform.android?
12
+ assert_equal :google_search_app, browser.id
13
+ assert_equal "11", browser.version
14
+ assert_equal "11.6.8.21", browser.full_version
15
+ assert_equal "Google Search App", browser.name
16
+ refute browser.chrome?
17
+ refute browser.safari?
18
+ end
19
+
20
+ test "detects Google Search App (iPad)" do
21
+ browser = Browser.new(Browser["GOOGLE_SEARCH_APP_IPAD"])
22
+
23
+ assert browser.webkit?
24
+ assert browser.google_search_app?
25
+ assert browser.device.ipad?
26
+ assert browser.platform.ios?
27
+ assert_equal :google_search_app, browser.id
28
+ assert_equal "102", browser.version
29
+ assert_equal "102.0.304944559", browser.full_version
30
+ assert_equal "Google Search App", browser.name
31
+ refute browser.chrome?
32
+ refute browser.safari?
33
+ end
34
+
35
+ test "detects Google Search App (iPhone)" do
36
+ browser = Browser.new(Browser["GOOGLE_SEARCH_APP_IPHONE"])
37
+
38
+ assert browser.webkit?
39
+ assert browser.google_search_app?
40
+ assert browser.device.iphone?
41
+ assert browser.platform.ios?
42
+ assert_equal :google_search_app, browser.id
43
+ assert_equal "105", browser.version
44
+ assert_equal "105.0.307913796", browser.full_version
45
+ assert_equal "Google Search App", browser.name
46
+ refute browser.chrome?
47
+ refute browser.safari?
48
+ end
49
+
50
+ test "detects version by range (iPad)" do
51
+ browser = Browser.new(Browser["GOOGLE_SEARCH_APP_IPAD"])
52
+ assert browser.google_search_app?(%w[>=102 <103])
53
+ end
54
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class HuaweiBrowserTest < Minitest::Test
6
+ test "detects Huawei Browser" do
7
+ browser = Browser.new(Browser["HUAWEI_BROWSER"])
8
+ assert browser.huawei_browser?
9
+ refute browser.safari?
10
+ refute browser.chrome?
11
+ assert_equal "Huawei Browser", browser.name
12
+ assert_equal :huawei_browser, browser.id
13
+ end
14
+
15
+ test "detects correct version" do
16
+ browser = Browser.new(Browser["HUAWEI_BROWSER"])
17
+ assert_equal "10.1.2.300", browser.full_version
18
+ assert_equal "10", browser.version
19
+ end
20
+
21
+ test "detects version by range" do
22
+ browser = Browser.new(Browser["HUAWEI_BROWSER"])
23
+ assert browser.huawei_browser?(%w[>=10 <11])
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class MaxthonTest < Minitest::Test
6
+ test "detects Maxthon" do
7
+ browser = Browser.new(Browser["MAXTHON"])
8
+ assert browser.maxthon?
9
+ refute browser.safari?
10
+ refute browser.chrome?
11
+ assert_equal "Maxthon", browser.name
12
+ assert_equal :maxthon, browser.id
13
+ end
14
+
15
+ test "detects correct version" do
16
+ browser = Browser.new(Browser["MAXTHON"])
17
+ assert_equal "5.3.8.2000", browser.full_version
18
+ assert_equal "5", browser.version
19
+ end
20
+
21
+ test "detects version by range" do
22
+ browser = Browser.new(Browser["MAXTHON"])
23
+ assert browser.maxthon?(%w[>=5 <6])
24
+ end
25
+ end
@@ -45,4 +45,13 @@ class MetaTest < Minitest::Test
45
45
  assert meta.include?("blackberry")
46
46
  assert meta.include?("mobile")
47
47
  end
48
+
49
+ test "returns string representation for unknown platform/device/browser" do
50
+ browser = Browser.new("Unknown")
51
+ meta = browser.to_s
52
+
53
+ assert meta.include?("unknown_platform")
54
+ assert meta.include?("unknown_device")
55
+ assert meta.include?("unknown_browser")
56
+ end
48
57
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class MiuiBrowserTest < Minitest::Test
6
+ test "detects Miui Browser" do
7
+ browser = Browser.new(Browser["MIUI_BROWSER"])
8
+ assert browser.miui_browser?
9
+ refute browser.safari?
10
+ refute browser.chrome?
11
+ assert_equal "Miui Browser", browser.name
12
+ assert_equal :miui_browser, browser.id
13
+ end
14
+
15
+ test "detects correct version" do
16
+ browser = Browser.new(Browser["MIUI_BROWSER"])
17
+ assert_equal "12.3.3", browser.full_version
18
+ assert_equal "12", browser.version
19
+ end
20
+
21
+ test "detects version by range" do
22
+ browser = Browser.new(Browser["MIUI_BROWSER"])
23
+ assert browser.miui_browser?(%w[>=12 <13])
24
+ end
25
+ end
@@ -20,6 +20,7 @@ class OperaTest < Minitest::Test
20
20
  assert browser.opera?
21
21
  assert browser.webkit?
22
22
  refute browser.chrome?
23
+ refute browser.safari?
23
24
  assert_equal "15.0.1147.44", browser.full_version
24
25
  assert_equal "15", browser.version
25
26
  end
@@ -20,7 +20,7 @@ class PlatformTest < Minitest::Test
20
20
 
21
21
  Browser::Platform.matchers.shift
22
22
  platform = Browser::Platform.new("Custom")
23
- assert_equal :other, platform.id
23
+ assert_equal :unknown_platform, platform.id
24
24
  end
25
25
 
26
26
  test "implements to_s" do
@@ -35,13 +35,13 @@ class PlatformTest < Minitest::Test
35
35
  refute platform == :android
36
36
  end
37
37
 
38
- test "detect other" do
39
- platform = Browser::Platform.new("Other")
38
+ test "detect unknown platforms" do
39
+ platform = Browser::Platform.new("Unknown")
40
40
 
41
- assert_equal "Other", platform.name
42
- assert_equal :other, platform.id
41
+ assert_equal "Unknown", platform.name
42
+ assert_equal :unknown_platform, platform.id
43
43
  assert_equal "0", platform.version
44
- assert platform.other?
44
+ assert platform.unknown?
45
45
  end
46
46
 
47
47
  test "detect ios (iPhone)" do
@@ -9,6 +9,9 @@ class QQTest < Minitest::Test
9
9
  assert_equal "6.3.3.432", browser.full_version
10
10
  assert_equal "QQ Browser", browser.name
11
11
  assert_equal :qq, browser.id
12
+
13
+ refute browser.chrome?
14
+ refute browser.safari?
12
15
  end
13
16
 
14
17
  test "detects QQ browser for Android" do
@@ -17,6 +20,9 @@ class QQTest < Minitest::Test
17
20
  assert_equal "6.2", browser.full_version
18
21
  assert_equal "QQ Browser", browser.name
19
22
  assert_equal :qq, browser.id
23
+
24
+ refute browser.chrome?
25
+ refute browser.safari?
20
26
  end
21
27
 
22
28
  test "detects QQ browser for Mac" do
@@ -25,6 +31,9 @@ class QQTest < Minitest::Test
25
31
  assert_equal "4.2.4753.400", browser.full_version
26
32
  assert_equal "QQ Browser", browser.name
27
33
  assert_equal :qq, browser.id
34
+
35
+ refute browser.chrome?
36
+ refute browser.safari?
28
37
  end
29
38
 
30
39
  test "detects QQ browser lite for Mac" do
@@ -33,5 +42,8 @@ class QQTest < Minitest::Test
33
42
  assert_equal "1.0.4", browser.full_version
34
43
  assert_equal "QQ Browser", browser.name
35
44
  assert_equal :qq, browser.id
45
+
46
+ refute browser.chrome?
47
+ refute browser.safari?
36
48
  end
37
49
  end
@@ -7,7 +7,7 @@ class SafariTest < Minitest::Test
7
7
  browser = Browser.new(Browser["SAFARI3"])
8
8
 
9
9
  assert browser.safari?
10
- assert browser.safari?(3)
10
+ assert browser.safari?("~>3.0")
11
11
  assert_equal "3", browser.version
12
12
  assert_equal "3.0.3", browser.full_version
13
13
  end
@@ -16,7 +16,7 @@ class SafariTest < Minitest::Test
16
16
  browser = Browser.new(Browser["SAFARI4"])
17
17
 
18
18
  assert browser.safari?
19
- assert browser.safari?(4)
19
+ assert browser.safari?("~>4.0")
20
20
  assert_equal "4", browser.version
21
21
  assert_equal "4.0.3", browser.full_version
22
22
  end
@@ -25,7 +25,7 @@ class SafariTest < Minitest::Test
25
25
  browser = Browser.new(Browser["SAFARI5"])
26
26
 
27
27
  assert browser.safari?
28
- assert browser.safari?(5)
28
+ assert browser.safari?("~>5.0")
29
29
  assert_equal "5", browser.version
30
30
  assert_equal "5.0.3", browser.full_version
31
31
  end
@@ -34,7 +34,7 @@ class SafariTest < Minitest::Test
34
34
  browser = Browser.new(Browser["SAFARI6"])
35
35
 
36
36
  assert browser.safari?
37
- assert browser.safari?(6)
37
+ assert browser.safari?("~>6.0")
38
38
  assert_equal "6", browser.version
39
39
  assert_equal "6.0", browser.full_version
40
40
  end
@@ -43,7 +43,7 @@ class SafariTest < Minitest::Test
43
43
  browser = Browser.new(Browser["SAFARI7"])
44
44
 
45
45
  assert browser.safari?
46
- assert browser.safari?(7)
46
+ assert browser.safari?("~>7.0")
47
47
  assert_equal "7", browser.version
48
48
  assert_equal "7.0", browser.full_version
49
49
  end
@@ -52,7 +52,7 @@ class SafariTest < Minitest::Test
52
52
  browser = Browser.new(Browser["SAFARI8"])
53
53
 
54
54
  assert browser.safari?
55
- assert browser.safari?(8)
55
+ assert browser.safari?("~>8.0")
56
56
  assert_equal "8", browser.version
57
57
  assert_equal "8.0", browser.full_version
58
58
  end
@@ -61,7 +61,7 @@ class SafariTest < Minitest::Test
61
61
  browser = Browser.new(Browser["SAFARI9"])
62
62
 
63
63
  assert browser.safari?
64
- assert browser.safari?(9)
64
+ assert browser.safari?("~>9.0")
65
65
  assert_equal "9", browser.version
66
66
  assert_equal "9.0.2", browser.full_version
67
67
  end
@@ -88,4 +88,9 @@ class SafariTest < Minitest::Test
88
88
  browser = Browser.new(Browser["SAFARI9"])
89
89
  assert browser.webkit?(%w[>=601 <602])
90
90
  end
91
+
92
+ test "detects safari version by range" do
93
+ browser = Browser.new(Browser["SAFARI9"])
94
+ assert browser.safari?(%w[>=9.0 <10])
95
+ end
91
96
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class SougouBrowserTest < Minitest::Test
6
+ test "detects Sougou Browser on desktop device" do
7
+ browser = Browser.new(Browser["SOUGOU_BROWSER"])
8
+ assert browser.sougou_browser?
9
+ refute browser.safari?
10
+ refute browser.chrome?
11
+ assert_equal "Sougou Browser", browser.name
12
+ assert_equal :sougou_browser, browser.id
13
+ end
14
+
15
+ test "detects correct version on desktop device" do
16
+ browser = Browser.new(Browser["SOUGOU_BROWSER"])
17
+ assert_equal "0.0", browser.full_version
18
+ assert_equal "0", browser.version
19
+ end
20
+
21
+ test "detects Sougou Browser on mobile device" do
22
+ browser = Browser.new(Browser["SOUGOU_BROWSER_MOBILE"])
23
+ assert browser.sougou_browser?
24
+ assert browser.device.mobile?
25
+ refute browser.safari?
26
+ refute browser.chrome?
27
+ assert_equal "Sougou Browser", browser.name
28
+ assert_equal :sougou_browser, browser.id
29
+ end
30
+
31
+ test "detects correct version on mobile device" do
32
+ browser = Browser.new(Browser["SOUGOU_BROWSER_MOBILE"])
33
+ assert_equal "5.28.12", browser.full_version
34
+ assert_equal "5", browser.version
35
+ end
36
+
37
+ test "detects version by range on mobile device" do
38
+ browser = Browser.new(Browser["SOUGOU_BROWSER_MOBILE"])
39
+ assert browser.sougou_browser?(%w[>=5 <6])
40
+ end
41
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browser
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-31 00:00:00.000000000 Z
11
+ date: 2020-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -177,6 +177,7 @@ files:
177
177
  - ".rubocop.yml"
178
178
  - ".travis.yml"
179
179
  - CHANGELOG.md
180
+ - FUNDING.yml
180
181
  - Gemfile
181
182
  - README.md
182
183
  - Rakefile
@@ -227,9 +228,11 @@ files:
227
228
  - lib/browser/electron.rb
228
229
  - lib/browser/facebook.rb
229
230
  - lib/browser/firefox.rb
230
- - lib/browser/generic.rb
231
+ - lib/browser/google_search_app.rb
232
+ - lib/browser/huawei_browser.rb
231
233
  - lib/browser/instagram.rb
232
234
  - lib/browser/internet_explorer.rb
235
+ - lib/browser/maxthon.rb
233
236
  - lib/browser/meta.rb
234
237
  - lib/browser/meta/base.rb
235
238
  - lib/browser/meta/device.rb
@@ -248,6 +251,7 @@ files:
248
251
  - lib/browser/middleware/context.rb
249
252
  - lib/browser/middleware/context/additions.rb
250
253
  - lib/browser/middleware/context/url_methods.rb
254
+ - lib/browser/miui_browser.rb
251
255
  - lib/browser/nokia.rb
252
256
  - lib/browser/opera.rb
253
257
  - lib/browser/otter.rb
@@ -262,7 +266,7 @@ files:
262
266
  - lib/browser/platform/ios.rb
263
267
  - lib/browser/platform/linux.rb
264
268
  - lib/browser/platform/mac.rb
265
- - lib/browser/platform/other.rb
269
+ - lib/browser/platform/unknown.rb
266
270
  - lib/browser/platform/windows.rb
267
271
  - lib/browser/platform/windows_mobile.rb
268
272
  - lib/browser/platform/windows_phone.rb
@@ -271,9 +275,11 @@ files:
271
275
  - lib/browser/safari.rb
272
276
  - lib/browser/samsung_browser.rb
273
277
  - lib/browser/snapchat.rb
278
+ - lib/browser/sougou_browser.rb
274
279
  - lib/browser/sputnik.rb
275
280
  - lib/browser/testing.rb
276
281
  - lib/browser/uc_browser.rb
282
+ - lib/browser/unknown.rb
277
283
  - lib/browser/version.rb
278
284
  - lib/browser/weibo.rb
279
285
  - lib/browser/yandex.rb
@@ -303,13 +309,17 @@ files:
303
309
  - test/unit/facebook_test.rb
304
310
  - test/unit/firefox_test.rb
305
311
  - test/unit/generic_test.rb
312
+ - test/unit/google_search_app_test.rb
313
+ - test/unit/huawei_browser_test.rb
306
314
  - test/unit/instagram_test.rb
307
315
  - test/unit/internet_explorer_test.rb
308
316
  - test/unit/ios_app_test.rb
309
317
  - test/unit/ios_test.rb
310
318
  - test/unit/kindle_test.rb
319
+ - test/unit/maxthon_test.rb
311
320
  - test/unit/meta_test.rb
312
321
  - test/unit/micro_messenger_test.rb
322
+ - test/unit/miui_browser_test.rb
313
323
  - test/unit/nokia_test.rb
314
324
  - test/unit/opera_test.rb
315
325
  - test/unit/otter_test.rb
@@ -319,6 +329,7 @@ files:
319
329
  - test/unit/safari_test.rb
320
330
  - test/unit/samsung_browser_test.rb
321
331
  - test/unit/snapchat_test.rb
332
+ - test/unit/sougou_browser_test.rb
322
333
  - test/unit/sputnik_test.rb
323
334
  - test/unit/uc_browser_test.rb
324
335
  - test/unit/weibo_test.rb
@@ -330,7 +341,7 @@ licenses:
330
341
  - MIT
331
342
  metadata:
332
343
  changelog_uri: https://github.com/fnando/browser/blob/master/CHANGELOG.md
333
- post_install_message:
344
+ post_install_message:
334
345
  rdoc_options: []
335
346
  require_paths:
336
347
  - lib
@@ -346,7 +357,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
346
357
  version: '0'
347
358
  requirements: []
348
359
  rubygems_version: 3.1.2
349
- signing_key:
360
+ signing_key:
350
361
  specification_version: 4
351
362
  summary: Do some browser detection with Ruby.
352
363
  test_files:
@@ -375,13 +386,17 @@ test_files:
375
386
  - test/unit/facebook_test.rb
376
387
  - test/unit/firefox_test.rb
377
388
  - test/unit/generic_test.rb
389
+ - test/unit/google_search_app_test.rb
390
+ - test/unit/huawei_browser_test.rb
378
391
  - test/unit/instagram_test.rb
379
392
  - test/unit/internet_explorer_test.rb
380
393
  - test/unit/ios_app_test.rb
381
394
  - test/unit/ios_test.rb
382
395
  - test/unit/kindle_test.rb
396
+ - test/unit/maxthon_test.rb
383
397
  - test/unit/meta_test.rb
384
398
  - test/unit/micro_messenger_test.rb
399
+ - test/unit/miui_browser_test.rb
385
400
  - test/unit/nokia_test.rb
386
401
  - test/unit/opera_test.rb
387
402
  - test/unit/otter_test.rb
@@ -391,6 +406,7 @@ test_files:
391
406
  - test/unit/safari_test.rb
392
407
  - test/unit/samsung_browser_test.rb
393
408
  - test/unit/snapchat_test.rb
409
+ - test/unit/sougou_browser_test.rb
394
410
  - test/unit/sputnik_test.rb
395
411
  - test/unit/uc_browser_test.rb
396
412
  - test/unit/weibo_test.rb