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
@@ -2,7 +2,7 @@ require "test_helper"
2
2
  require "browser/rails"
3
3
  require "sample_app"
4
4
 
5
- class Browser::MiddlewareTest < Minitest::Test
5
+ class MiddlewareTest < Minitest::Test
6
6
  include Rack::Test::Methods
7
7
 
8
8
  def app
@@ -10,40 +10,40 @@ class Browser::MiddlewareTest < Minitest::Test
10
10
  end
11
11
 
12
12
  test "redirects with 302" do
13
- get "/", {}, {"HTTP_USER_AGENT" => "MSIE 6", "HTTP_ACCEPT" => "text/html"}
13
+ get "/", {}, "HTTP_USER_AGENT" => "MSIE 6", "HTTP_ACCEPT" => "text/html"
14
14
  assert_equal 302, last_response.status
15
15
  end
16
16
 
17
17
  test "redirects ie6 to upgrade path" do
18
- get "/", {}, {"HTTP_USER_AGENT" => "MSIE 6", "HTTP_ACCEPT" => "text/html"}
18
+ get "/", {}, "HTTP_USER_AGENT" => "MSIE 6", "HTTP_ACCEPT" => "text/html"
19
19
  follow_redirect!
20
20
 
21
21
  assert_equal "UPGRADE: ie6", last_response.body
22
22
  end
23
23
 
24
24
  test "redirects ie7 to upgrade path" do
25
- get "/", {}, {"HTTP_USER_AGENT" => "MSIE 7", "HTTP_ACCEPT" => "text/html"}
25
+ get "/", {}, "HTTP_USER_AGENT" => "MSIE 7", "HTTP_ACCEPT" => "text/html"
26
26
  follow_redirect!
27
27
 
28
28
  assert_equal "UPGRADE: ie7", last_response.body
29
29
  end
30
30
 
31
31
  test "redirects ie8 and returns 404" do
32
- get "/", {}, {"HTTP_USER_AGENT" => "MSIE 8", "HTTP_ACCEPT" => "text/html"}
32
+ get "/", {}, "HTTP_USER_AGENT" => "MSIE 8", "HTTP_ACCEPT" => "text/html"
33
33
  follow_redirect!
34
34
 
35
35
  assert_equal 404, last_response.status
36
36
  end
37
37
 
38
38
  test "redirects ie8 with wildcard http accept" do
39
- get "/", {}, {"HTTP_USER_AGENT" => "MSIE 8", "HTTP_ACCEPT" => "*/*"}
39
+ get "/", {}, "HTTP_USER_AGENT" => "MSIE 8", "HTTP_ACCEPT" => "*/*"
40
40
  follow_redirect!
41
41
 
42
42
  assert_equal 404, last_response.status
43
43
  end
44
44
 
45
45
  test "ignores non-html requests" do
46
- get "/", {}, {"HTTP_USER_AGENT" => "MSIE 6", "HTTP_ACCEPT" => "image/png"}
46
+ get "/", {}, "HTTP_USER_AGENT" => "MSIE 6", "HTTP_ACCEPT" => "image/png"
47
47
 
48
48
  assert_equal 200, last_response.status
49
49
  end
@@ -10,13 +10,13 @@ class SampleApp < Rails::Application
10
10
  routes.append do
11
11
  default_headers = {"Content-Type" => "text/html"}
12
12
 
13
- root to: -> env { [200, default_headers, ["ROOT"]] }
14
- get "upgrade", to: -> env {
13
+ root to: -> (_env) { [200, default_headers, ["ROOT"]] }
14
+ get "upgrade", to: lambda {|env|
15
15
  browser = Rack::Request.new(env).params["browser"]
16
16
  [200, default_headers, ["UPGRADE: #{browser}"]]
17
17
  }, as: "upgrade"
18
18
 
19
- get "/asset", to: -> env {
19
+ get "/asset", to: proc {
20
20
  [200, {"Content-Type" => "image/png"}, []]
21
21
  }
22
22
  end
@@ -3,18 +3,19 @@ require "bundler/setup"
3
3
  require "minitest/autorun"
4
4
  require "minitest/utils"
5
5
  require "browser"
6
+ require "browser/testing"
6
7
  require "yaml"
7
8
 
8
- $ua = YAML.load_file("./test/ua.yml")
9
+ module Minitest
10
+ class Test
11
+ setup do
12
+ Browser::Bot.instance_variable_set("@detect_empty_ua", false)
13
+ end
9
14
 
10
- class Minitest::Test
11
- setup do
12
- Browser::Bots.instance_variable_set("@detect_empty_ua", false)
13
- end
14
-
15
- def assert_deprecated(message, file, line, &block)
16
- message = "#{message} (called from #{file}:#{line})"
17
- out, err = capture_io(&block)
18
- assert_includes err, message
15
+ def assert_deprecated(message, file, line, &block)
16
+ message = "#{message} (called from #{file}:#{line})"
17
+ _out, err = capture_io(&block)
18
+ assert_includes err, message
19
+ end
19
20
  end
20
21
  end
@@ -16,10 +16,6 @@ ANDROID_LOLLIPOP_51: Mozilla/5.0 (Linux; Android 5.1; Nexus 5 Build/LMY47I) Appl
16
16
  ANDROID_NEXUS_PLAYER: Mozilla/5.0 (Linux; Android 5.0; Nexus Player Build/LRX21V) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.0
17
17
  ANDROID_TV: Mozilla/5.0 (Linux; Android 5.0; ADT-1 Build/LRW87K) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/37.0.0.0 Mobile Safari/537.36
18
18
  ANDROID_WITH_SAFARI: 'Mozilla/5.0 (Linux; U; Android 4.3; en-us; SCH-I535 Build/JSS15J) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'
19
- APPLE_BOT: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/600.2.5 (KHTML, like Gecko) Version/8.0.2 Safari/600.2.5 (Applebot/0.1)'
20
- ASK: 'Mozilla/2.0 (compatible; Ask Jeeves/Teoma; +http://sp.ask.com/docs/about/tech_crawling.html)'
21
- BAIDU: 'Baiduspider+(+http://www.baidu.com/search/spider.htm)'
22
- BINGBOT: 'Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)'
23
19
  BLACKBERRY10: 'Mozilla/5.0 (BB10; Touch) AppleWebKit/537.10+ (KHTML, like Gecko) Version/10.0.9.1675 Mobile Safari/537.10+'
24
20
  BLACKBERRY4: 'BlackBerry8100/4.2.1 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/103'
25
21
  BLACKBERRY5: 'BlackBerry9000/5.0.0.93 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/179'
@@ -29,18 +25,12 @@ BLACKBERRY: 'BlackBerry7100i/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 Vendo
29
25
  CHROME: 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.99 Safari/533.4'
30
26
  CHROME_OS: 'Mozilla/5.0 (X11; CrOS x86_64 3701.81.0) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.57 Safari/537.31.'
31
27
  COREMEDIA: 'Apple Mac OS X v10.6.4 CoreMedia v1.0.0.10F569'
32
- DAUMOA: Mozilla/5.0 (compatible; MSIE or Firefox mutant; not on Windows server;) Daumoa 4.0
33
- DOMAINAREANIMATOR: 'Domain Re-Animator Bot (http://domainreanimator.com) - support@domainreanimator.com'
34
- DOT_BOT: 'Mozilla/5.0 (compatible; DotBot/1.1; http://www.opensiteexplorer.org/dotbot, help@moz.com)'
35
- DUCKDUCKGO: 'DuckDuckBot/1.0; (+http://duckduckgo.com/duckduckbot.html)'
36
- FACEBOOK_BOT: 'facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)'
28
+ CUSTOM_APP: "Our App 0.0.1 (Linux; Android 4.0.3; HTC Ruby Build/IML74K; en_CA)"
37
29
  FIREFOX: 'Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv:1.9.0.2) Gecko/20121223 Ubuntu/9.25 (jaunty) Firefox/3.8'
30
+ FIREFOX_IOS: 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) FxiOS/1.2 Mobile/13C75 Safari/601.1.46'
38
31
  FIREFOX_MODERN: 'Mozilla/5.0 (X11; Ubuntu; Linux armv7l; rv:17.0) Gecko/20100101 Firefox/17.0'
32
+ FIREFOX_OS: 'Mozilla/5.0 (Mobile; rv:18.0) Gecko/18.0 Firefox/18.0'
39
33
  FIREFOX_TABLET: 'Mozilla/5.0 (Android; Tablet; rv:14.0) Gecko/14.0 Firefox/14.0'
40
- GOOGLE_BOT: 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
41
- GOOGLE_PAGE_SPEED_INSIGHTS: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.4 (KHTML, like Gecko; Google Page Speed Insights) Chrome/22.0.1229 Safari/537.4'
42
- GOOGLE_STRUCTURED_DATA_TESTING_TOOL: 'Mozilla/5.0 (compatible; X11; Linux x86_64; Google-StructuredDataTestingTool; +http://www.google.com/webmasters/tools/richsnippets)'
43
- GRAPESHOT: 'Mozilla/5.0 (compatible; GrapeshotCrawler/2.0; +http://www.grapeshot.co.uk/crawler.php)'
44
34
  IE10: 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0; EIE10;ENUSMSN)'
45
35
  IE10_COMPAT: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; EIE10;ENUSMSN)'
46
36
  IE10_X64_WINX64: 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; Trident/6.0)'
@@ -52,6 +42,7 @@ IE7: 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)'
52
42
  IE8: 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.2; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)'
53
43
  IE8_COMPAT: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0; SLCC1; Media Center PC 5.0; .NET CLR 3.5.21022)'
54
44
  IE9: 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)'
45
+ IE9_CHROME_FRAME: 'Mozilla/5.0 (Windows NT 6.1; WOW64; chromeframe/26.0.1410.43) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31'
55
46
  IE9_COMPAT: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/5.0)'
56
47
  IE_WITHOUT_TRIDENT: Mozilla/4.0 (compatible; MSIE8.0; Windows NT 6.0) .NET CLR 2.0.50727)
57
48
  IOS4: 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7'
@@ -68,16 +59,13 @@ KINDLE: 'Mozilla/5.0 (Linux; U; en-US) AppleWebKit/528.5+ (KHTML, like Gecko, Sa
68
59
  KINDLE_FIRE: 'Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Kindle Fire Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'
69
60
  KINDLE_FIRE_HD: 'Mozilla/5.0 (Linux; U; en-us; KFTT Build/IML74K) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.4 Safari/535.19 Silk-Accelerated=true'
70
61
  KINDLE_FIRE_HD_MOBILE: 'Mozilla/5.0 (Linux; U; Android 4.0.3; en-us; KFTT Build/IML74K) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.4 Mobile Safari/535.19 Silk-Accelerated=true'
71
- LINKDEXBOT: 'Mozilla/5.0 (compatible; linkdexbot/2.0; +http://www.linkdex.com/bots/)'
72
- LOAD_TIME_BOT: 'Mozilla/5.0 (compatible; LoadTimeBot/0.9; +http://www.loadtime.net/bot.html)'
73
62
  LUMIA800: 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; XBLWP7; ZuneWP7'
74
- MAIL_RU: 'Mozilla/5.0 (compatible; Linux x86_64; Mail.RU_Bot/2.0; +http://go.mail.ru/help/robots)'
75
- MEGAINDEX_RU: 'Mozilla/5.0 (compatible; MegaIndex.ru/2.0; +https://www.megaindex.ru/?tab=linkAnalyze)'
63
+ MIDP: MIDP-2.0
76
64
  MOBILE_CHROME: 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en) AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/19.0.1084.60 Mobile/9B206 Safari/7534.48.3'
77
65
  MS_EDGE: 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0'
78
66
  MS_EDGE_COMPAT: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; WOW64; Trident/8.0; .NET4.0C; .NET4.0E; Tablet PC 2.0; Microsoft Outlook 15.0.4433; ms-office; MSOffice 15)'
79
67
  MS_EDGE_MOBILE: 'Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; DEVICE INFO) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Mobile Safari/537.36 Edge/12.0'
80
- MSN_BOT: 'msnbot-media/1.1 (+http://search.msn.com/msnbot.htm)'
68
+ NEXUS7: 'Mozilla/5.0 (Linux; Android 4.3; Nexus 7 Build/JWR66Y) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.72 Safari/537.36'
81
69
  NEXUS_TABLET: 'Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19'
82
70
  NINTENDO_WII: 'Opera/9.00 (Nintendo Wii; U; ; 1309-9; en)'
83
71
  NINTENDO_WIIU: 'Mozilla/5.0 (Nintendo WiiU) AppleWebKit/534.52 (KHTML, like Gecko) NX/2.1.0.8.23 NintendoBrowser/1.1.0.7579.EU'
@@ -93,20 +81,23 @@ PLAYSTATION3: 'Mozilla/5.0 (PLAYSTATION 3; 3.55)'
93
81
  PLAYSTATION4: 'Mozilla/5.0 (PlayStation 4 1.020) AppleWebKit/536.26 (KHTML, like Gecko)'
94
82
  PSP: 'Mozilla/4.0 (PSP (PlayStation Portable); 2.00)'
95
83
  PSP_VITA: 'Mozilla/5.0 (Playstation Vita 1.61) AppleWebKit/531.22.8 (KHTML, like Gecko) Silk/3.2'
96
- QUERYSEEKER: 'QuerySeekerSpider ( http://queryseeker.com/bot.html )'
97
84
  QUICKTIME: 'QuickTime/7.6.8 (qtver=7.6.8;os=Windows NT 5.1Service Pack 3)'
85
+ SAFARI3: 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en) AppleWebKit/522.15.5 (KHTML, like Gecko) Version/3.0.3 Safari/522.15.5'
86
+ SAFARI4: 'Mozilla/5.0 (Windows; U; Windows NT 6.0; fr-ch) AppleWebKit/531.9 (KHTML, like Gecko) Version/4.0.3 Safari/531.9'
87
+ SAFARI5: 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; fr-ch) AppleWebKit/533.19.4 (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4'
88
+ SAFARI6: 'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25'
89
+ SAFARI7: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9) AppleWebKit/537.71 (KHTML, like Gecko) Version/7.0 Safari/537.71'
90
+ SAFARI8: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_90) AppleWebKit/600.1.25 (KHTML, like Gecko) Version/8.0 Safari/600.1.25'
91
+ SAFARI9: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/601.3.9 (KHTML, like Gecko) Version/9.0.2 Safari/601.3.9'
98
92
  SAFARI: 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-us) AppleWebKit/533.17.8 (KHTML, like Gecko) Version/5.0.1 Safari/533.17.8'
99
93
  SAFARI_IPAD_WEBAPP_MODE: 'Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405'
100
94
  SAFARI_IPHONE_WEBAPP_MODE: 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.20 (KHTML, like Gecko) Mobile/7B298g'
101
95
  SAMSUNG: 'Mozilla/5.0 (Linux; U; Android 4.0.4; en-us; SAMSUNG-SGH-I497 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30'
102
96
  SAMSUNG_CHROME: 'Mozilla/5.0 (Linux; Android 4.4.2; en-gb; SAMSUNG GT-I9195/I9195XXUCNEA Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/1.5 Chrome/28.0.1500.94 Mobile Safari/537.36'
103
- SCRAPY: 'Scrapy/0.18.4 (+http://scrapy.org)'
104
- SEOKICKS: 'Mozilla/5.0 (compatible; SEOkicks-Robot; +http://www.seokicks.de/robot.html)'
105
- SISTRIX: 'Mozilla/5.0 (compatible; SISTRIX Crawler; http://crawler.sistrix.net/)'
106
97
  SMART_TV: 'Mozilla/5.0 (SmartHub; SMART-TV; U; Linux/SmartTV) AppleWebKit/531.2+ (KHTML, like Gecko) WebBrowser/1.0 SmartTV Safari/531.2+'
107
98
  SURFACE: 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; ARM; Trident/6.0; Touch)'
99
+ SYMBIAN: 'Nokia5250/10.0.011 (SymbianOS/9.4; U; Series60/5.0 Mozilla/5.0; Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/525 (KHTML, like Gecko) Safari/525 3gpp-gba'
108
100
  TABLOID: 'Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13'
109
- TINEYE: 'TinEye-bot/0.51 (see http://www.tineye.com/crawler.html)'
110
101
  UC_BROWSER: 'Mozilla/5.0 (Linux; U; Android 4.4.2; en-US; GT-I9500 Build/KOT49H) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 UCBrowser/9.9.4.484 U3/0.8.0 Mobile Safari/533.1'
111
102
  WINDOWS7: 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0) chromeframe/10.0.648.205'
112
103
  WINDOWS81: 'Mozilla/5.0 (IE 11.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C; rv:11.0) like Gecko'
@@ -118,10 +109,8 @@ WINDOWS_PHONE_81: 'Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Tri
118
109
  WINDOWS_VISTA: 'Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.0.3705; .NET CLR 1.1.4322)'
119
110
  WINDOWS_WOW64: "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko"
120
111
  WINDOWS_XP: 'Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; FDM; .NET CLR 1.1.4322)'
112
+ WINDOWS_XP_64: 'Mozilla/4.0 (Compatible; MSIE 8.0; Windows NT 5.2; Trident/6.0)'
121
113
  XBOX360: 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; Xbox), or Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; Xbox)'
122
114
  XBOXONE: 'Mozilla/5.0 (Compatible; MSIE 10.0; Windows NT 6.2; Trident /6.0; Xbox; Xbox One)'
123
115
  XOOM: 'Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13'
124
- YAHOO_SLURP: 'Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)'
125
116
  YANDEX_BROWSER: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 YaBrowser/15.4.2272.3909 (beta) Yowser/2.0 Safari/537.36'
126
- YANDEX_DIRECT: 'Mozilla/5.0 (compatible; YandexDirect/3.0; +http://yandex.com/bots)'
127
- YANDEX_METRIKA: 'Mozilla/5.0 (compatible; YandexMetrika/3.0; +http://yandex.com/bots)'
@@ -0,0 +1,27 @@
1
+ APPLE_BOT: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/600.2.5 (KHTML, like Gecko) Version/8.0.2 Safari/600.2.5 (Applebot/0.1)'
2
+ ASK: 'Mozilla/2.0 (compatible; Ask Jeeves/Teoma; +http://sp.ask.com/docs/about/tech_crawling.html)'
3
+ BAIDU: 'Baiduspider+(+http://www.baidu.com/search/spider.htm)'
4
+ BINGBOT: 'Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)'
5
+ DAUMOA: Mozilla/5.0 (compatible; MSIE or Firefox mutant; not on Windows server;) Daumoa 4.0
6
+ DOMAINAREANIMATOR: 'Domain Re-Animator Bot (http://domainreanimator.com) - support@domainreanimator.com'
7
+ DOT_BOT: 'Mozilla/5.0 (compatible; DotBot/1.1; http://www.opensiteexplorer.org/dotbot, help@moz.com)'
8
+ DUCKDUCKGO: 'DuckDuckBot/1.0; (+http://duckduckgo.com/duckduckbot.html)'
9
+ FACEBOOK_BOT: 'facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)'
10
+ GOOGLE_BOT: 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
11
+ GOOGLE_PAGE_SPEED_INSIGHTS: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.4 (KHTML, like Gecko; Google Page Speed Insights) Chrome/22.0.1229 Safari/537.4'
12
+ GOOGLE_STRUCTURED_DATA_TESTING_TOOL: 'Mozilla/5.0 (compatible; X11; Linux x86_64; Google-StructuredDataTestingTool; +http://www.google.com/webmasters/tools/richsnippets)'
13
+ GRAPESHOT: 'Mozilla/5.0 (compatible; GrapeshotCrawler/2.0; +http://www.grapeshot.co.uk/crawler.php)'
14
+ LINKDEXBOT: 'Mozilla/5.0 (compatible; linkdexbot/2.0; +http://www.linkdex.com/bots/)'
15
+ LOAD_TIME_BOT: 'Mozilla/5.0 (compatible; LoadTimeBot/0.9; +http://www.loadtime.net/bot.html)'
16
+ MAIL_RU: 'Mozilla/5.0 (compatible; Linux x86_64; Mail.RU_Bot/2.0; +http://go.mail.ru/help/robots)'
17
+ MEGAINDEX_RU: 'Mozilla/5.0 (compatible; MegaIndex.ru/2.0; +https://www.megaindex.ru/?tab=linkAnalyze)'
18
+ MRCHROME: 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.107 Amigo/45.0.2454.107 MRCHROME SOC Safari/537.36'
19
+ MSN_BOT: 'msnbot-media/1.1 (+http://search.msn.com/msnbot.htm)'
20
+ QUERYSEEKER: 'QuerySeekerSpider ( http://queryseeker.com/bot.html )'
21
+ SCRAPY: 'Scrapy/0.18.4 (+http://scrapy.org)'
22
+ SEOKICKS: 'Mozilla/5.0 (compatible; SEOkicks-Robot; +http://www.seokicks.de/robot.html)'
23
+ SISTRIX: 'Mozilla/5.0 (compatible; SISTRIX Crawler; http://crawler.sistrix.net/)'
24
+ TINEYE: 'TinEye-bot/0.51 (see http://www.tineye.com/crawler.html)'
25
+ YAHOO_SLURP: 'Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)'
26
+ YANDEX_DIRECT: 'Mozilla/5.0 (compatible; YandexDirect/3.0; +http://yandex.com/bots)'
27
+ YANDEX_METRIKA: 'Mozilla/5.0 (compatible; YandexMetrika/3.0; +http://yandex.com/bots)'
@@ -0,0 +1,6 @@
1
+ ASK: 'Mozilla/2.0 (compatible; Ask Jeeves/Teoma; +http://sp.ask.com/docs/about/tech_crawling.html)'
2
+ BAIDU: 'Baiduspider+(+http://www.baidu.com/search/spider.htm)'
3
+ BINGBOT: 'Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)'
4
+ DUCKDUCKGO: 'DuckDuckBot/1.0; (+http://duckduckgo.com/duckduckbot.html)'
5
+ GOOGLE_BOT: 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
6
+ YAHOO_SLURP: 'Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)'
@@ -0,0 +1,92 @@
1
+ require "test_helper"
2
+
3
+ class AcceptLanguageTest < Minitest::Test
4
+ def assert_language(item, expect = {})
5
+ assert_equal expect[:code], item.code, "failed code comparison"
6
+ assert_equal expect[:region], item.region, "failed region comparison"
7
+ assert_equal expect[:quality], item.quality, "failed quality comparison"
8
+ end
9
+
10
+ test "returns full language" do
11
+ language = Browser::AcceptLanguage.new("en-GB")
12
+ assert_equal "en-GB", language.full
13
+ end
14
+
15
+ test "returns language name" do
16
+ language = Browser::AcceptLanguage.new("en-GB")
17
+ assert_equal "English/United Kingdom", language.name
18
+
19
+ language = Browser::AcceptLanguage.new("en")
20
+ assert_equal "English", language.name
21
+ end
22
+
23
+ test "returns nil for unknown languages" do
24
+ language = Browser::AcceptLanguage.new("unknown")
25
+ assert_nil language.name
26
+ end
27
+
28
+ test "parses language with quality" do
29
+ language = Browser::AcceptLanguage.new("en-GB;q=0.8")
30
+ assert_language language, code: "en", region: "GB", quality: 0.8
31
+ end
32
+
33
+ test "parses language without quality" do
34
+ language = Browser::AcceptLanguage.new("en-GB")
35
+ assert_language language, code: "en", region: "GB", quality: 1.0
36
+ end
37
+
38
+ test "parses language without region" do
39
+ language = Browser::AcceptLanguage.new("en")
40
+ assert_language language, code: "en", region: nil, quality: 1.0
41
+ end
42
+
43
+ test "ignores multi-part region" do
44
+ language = Browser::AcceptLanguage.new("az-AZ-Cyrl")
45
+ assert_language language, code: "az", region: "AZ", quality: 1.0
46
+ end
47
+
48
+ test "parses multi-language set" do
49
+ result = Browser::AcceptLanguage.parse("fr-CA,fr;q=0.8")
50
+
51
+ assert_equal 2, result.count
52
+ assert_language result[0], code: "fr", region: "CA", quality: 1.0
53
+ assert_language result[1], code: "fr", region: nil, quality: 0.8
54
+ end
55
+
56
+ test "parses wildcard" do
57
+ result = Browser::AcceptLanguage.parse("fr-CA,*;q=0.8")
58
+
59
+ assert_language result[0], code: "fr", region: "CA", quality: 1.0
60
+ assert_language result[1], code: "*", region: nil, quality: 0.8
61
+ end
62
+
63
+ test "parses complex set" do
64
+ result = Browser::AcceptLanguage.parse("fr-CA,fr;q=0.8,en-US;q=0.6,en;q=0.4,*;q=0.1")
65
+
66
+ assert_language result[0], code: "fr", region: "CA", quality: 1.0
67
+ assert_language result[1], code: "fr", region: nil, quality: 0.8
68
+ assert_language result[2], code: "en", region: "US", quality: 0.6
69
+ assert_language result[3], code: "en", region: nil, quality: 0.4
70
+ assert_language result[4], code: "*", region: nil, quality: 0.1
71
+ end
72
+
73
+ test "handles random white spaces" do
74
+ result = Browser::AcceptLanguage.parse("fr-CA, fr;q=0.8, en-US;q=0.6,en;q=0.4, *;q=0.1")
75
+
76
+ assert_language result[0], code: "fr", region: "CA", quality: 1.0
77
+ assert_language result[1], code: "fr", region: nil, quality: 0.8
78
+ assert_language result[2], code: "en", region: "US", quality: 0.6
79
+ assert_language result[3], code: "en", region: nil, quality: 0.4
80
+ assert_language result[4], code: "*", region: nil, quality: 0.1
81
+ end
82
+
83
+ test "sorts based on quality" do
84
+ result = Browser::AcceptLanguage.parse("fr-CA,fr;q=0.2,en-US;q=0.6,en;q=0.4,*;q=0.5")
85
+
86
+ assert_language result[0], code: "fr", region: "CA", quality: 1.0
87
+ assert_language result[1], code: "en", region: "US", quality: 0.6
88
+ assert_language result[2], code: "*", region: nil, quality: 0.5
89
+ assert_language result[3], code: "en", region: nil, quality: 0.4
90
+ assert_language result[4], code: "fr", region: nil, quality: 0.2
91
+ end
92
+ end
@@ -1,17 +1,12 @@
1
1
  require "test_helper"
2
2
 
3
3
  class AdobeAirTest < Minitest::Test
4
- setup do
5
- @browser = Browser.new
6
- end
7
-
8
4
  test "detects adobe air" do
9
- @browser.ua = $ua["ADOBE_AIR"]
5
+ browser = Browser.new(Browser["ADOBE_AIR"])
10
6
 
11
- assert @browser.adobe_air?
12
- assert @browser.webkit?
13
- assert_equal @browser.version, "13"
14
- assert_equal @browser.full_version, "13.0"
15
- assert_equal @browser.name, "Other"
7
+ assert browser.webkit?
8
+ assert_equal "0", browser.version
9
+ assert_equal "0.0", browser.full_version
10
+ assert_equal "Generic Browser", browser.name
16
11
  end
17
12
  end
@@ -1,97 +1,92 @@
1
1
  require "test_helper"
2
2
 
3
3
  class AndroidTest < Minitest::Test
4
- setup do
5
- @browser = Browser.new
6
- end
7
-
8
4
  test "detect android cupcake (1.5)" do
9
- @browser.ua = $ua['ANDROID_CUPCAKE']
10
- assert @browser.android?
11
- assert @browser.android?(1.5)
5
+ browser = Browser.new(Browser["ANDROID_CUPCAKE"])
6
+ assert browser.platform.android?
7
+ assert browser.platform.android?(1.5)
12
8
  end
13
9
 
14
10
  test "detect android donut (1.6)" do
15
- @browser.ua = $ua['ANDROID_DONUT']
16
- assert @browser.android?
17
- assert @browser.android?(1.6)
11
+ browser = Browser.new(Browser["ANDROID_DONUT"])
12
+ assert browser.platform.android?
13
+ assert browser.platform.android?(1.6)
18
14
  end
19
15
 
20
16
  test "detect android eclair (2.1)" do
21
- @browser.ua = $ua['ANDROID_ECLAIR_21']
22
- assert @browser.android?
23
- assert @browser.android?(2.1)
17
+ browser = Browser.new(Browser["ANDROID_ECLAIR_21"])
18
+ assert browser.platform.android?
19
+ assert browser.platform.android?(2.1)
24
20
  end
25
21
 
26
22
  test "detect android froyo (2.2)" do
27
- @browser.ua = $ua['ANDROID_FROYO']
28
- assert @browser.android?
29
- assert @browser.android?(2.2)
23
+ browser = Browser.new(Browser["ANDROID_FROYO"])
24
+ assert browser.platform.android?
25
+ assert browser.platform.android?(2.2)
30
26
  end
31
27
 
32
28
  test "detect android gingerbread (2.3)" do
33
- @browser.ua = $ua['ANDROID_GINGERBREAD']
34
- assert @browser.android?
35
- assert @browser.android?(2.3)
29
+ browser = Browser.new(Browser["ANDROID_GINGERBREAD"])
30
+ assert browser.platform.android?
31
+ assert browser.platform.android?("~> 2.3.0")
36
32
  end
37
33
 
38
34
  test "detect android honeycomb (3.0)" do
39
- @browser.ua = $ua['ANDROID_HONEYCOMB_30']
40
- assert @browser.android?
41
- assert @browser.android?(3.0)
35
+ browser = Browser.new(Browser["ANDROID_HONEYCOMB_30"])
36
+ assert browser.platform.android?
37
+ assert browser.platform.android?("~> 3.0")
42
38
  end
43
39
 
44
40
  test "detect android ice cream sandwich (4.0)" do
45
- @browser.ua = $ua['ANDROID_ICECREAM']
46
- assert @browser.android?
47
- assert @browser.android?(4.0)
41
+ browser = Browser.new(Browser["ANDROID_ICECREAM"])
42
+ assert browser.platform.android?
43
+ assert browser.platform.android?("~> 4.0")
48
44
  end
49
45
 
50
46
  test "detect android jellybean (4.1)" do
51
- @browser.ua = $ua['ANDROID_JELLYBEAN_41']
52
- assert @browser.android?
53
- assert @browser.android?(4.1)
47
+ browser = Browser.new(Browser["ANDROID_JELLYBEAN_41"])
48
+ assert browser.platform.android?
49
+ assert browser.platform.android?("~> 4.1")
54
50
  end
55
51
 
56
52
  test "detect android jellybean (4.2)" do
57
- @browser.ua = $ua['ANDROID_JELLYBEAN_42']
58
- assert @browser.android?
59
- assert @browser.android?(4.2)
53
+ browser = Browser.new(Browser["ANDROID_JELLYBEAN_42"])
54
+ assert browser.platform.android?
55
+ assert browser.platform.android?(4.2)
60
56
  end
61
57
 
62
58
  test "detect android jellybean (4.3)" do
63
- @browser.ua = $ua['ANDROID_JELLYBEAN_43']
64
- assert @browser.android?
65
- assert @browser.android?(4.3)
59
+ browser = Browser.new(Browser["ANDROID_JELLYBEAN_43"])
60
+ assert browser.platform.android?
61
+ assert browser.platform.android?(4.3)
66
62
  end
67
63
 
68
64
  test "detect android kitkat (4.4)" do
69
- @browser.ua = $ua['ANDROID_KITKAT']
70
- assert @browser.android?
71
- assert @browser.android?(4.4)
65
+ browser = Browser.new(Browser["ANDROID_KITKAT"])
66
+ assert browser.platform.android?
67
+ assert browser.platform.android?(4.4)
72
68
  end
73
69
 
74
70
  test "detect android lollipop (5.0)" do
75
- @browser.ua = $ua['ANDROID_LOLLIPOP_50']
76
- assert @browser.android?
77
- assert @browser.android?(5.0)
71
+ browser = Browser.new(Browser["ANDROID_LOLLIPOP_50"])
72
+ assert browser.platform.android?
73
+ assert browser.platform.android?(5.0)
78
74
  end
79
75
 
80
76
  test "detect android lollipop (5.1)" do
81
- @browser.ua = $ua['ANDROID_LOLLIPOP_51']
82
- assert @browser.android?
83
- assert @browser.android?(5.1)
77
+ browser = Browser.new(Browser["ANDROID_LOLLIPOP_51"])
78
+ assert browser.platform.android?
79
+ assert browser.platform.android?(5.1)
84
80
  end
85
81
 
86
82
  test "detect android tv" do
87
- @browser.ua = $ua['ANDROID_TV']
88
- assert @browser.android?
89
- assert @browser.tv?
83
+ browser = Browser.new(Browser["ANDROID_TV"])
84
+ assert browser.platform.android?
85
+ assert browser.device.tv?
90
86
  end
91
87
 
92
88
  test "detect nexus player" do
93
- @browser.ua = $ua['ANDROID_NEXUS_PLAYER']
94
- assert @browser.android?
95
- assert @browser.tv?
89
+ browser = Browser.new(Browser["ANDROID_NEXUS_PLAYER"])
90
+ assert browser.platform.android?
96
91
  end
97
92
  end