browser 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,48 +1,48 @@
1
- require "spec_helper"
1
+ require "test_helper"
2
2
  require "browser/rails"
3
3
  require "sample_app"
4
4
 
5
- describe Browser::Middleware do
5
+ class Browser::MiddlewareTest < Minitest::Test
6
6
  include Rack::Test::Methods
7
7
 
8
8
  def app
9
9
  Rails.application
10
10
  end
11
11
 
12
- it "redirects with 302" do
12
+ test "redirects with 302" do
13
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
- it "redirects ie6 to upgrade path" do
17
+ test "redirects ie6 to upgrade path" do
18
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
- it "redirects ie7 to upgrade path" do
24
+ test "redirects ie7 to upgrade path" do
25
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
- it "redirects ie8 and returns 404" do
31
+ test "redirects ie8 and returns 404" do
32
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
- it "redirects ie8 with wildcard http accept" do
38
+ test "redirects ie8 with wildcard http accept" do
39
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
- it "ignores non-html requests" do
45
+ test "ignores non-html requests" do
46
46
  get "/", {}, {"HTTP_USER_AGENT" => "MSIE 6", "HTTP_ACCEPT" => "image/png"}
47
47
 
48
48
  assert_equal 200, last_response.status
@@ -22,9 +22,9 @@ class SampleApp < Rails::Application
22
22
  end
23
23
 
24
24
  config.middleware.use Browser::Middleware do
25
- redirect_to upgrade_path(browser: "ie6") if browser.ie6?
26
- redirect_to upgrade_path(browser: "ie7") if browser.ie7?
27
- redirect_to "/invalid" if browser.ie8?
25
+ redirect_to upgrade_path(browser: "ie6") if browser.ie?(6)
26
+ redirect_to upgrade_path(browser: "ie7") if browser.ie?(7)
27
+ redirect_to "/invalid" if browser.ie?(8)
28
28
  end
29
29
  end
30
30
 
@@ -0,0 +1,20 @@
1
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
2
+ require "bundler/setup"
3
+ require "minitest/autorun"
4
+ require "minitest/utils"
5
+ require "browser"
6
+ require "yaml"
7
+
8
+ $ua = YAML.load_file("./test/ua.yml")
9
+
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
19
+ end
20
+ end
@@ -1,5 +1,20 @@
1
1
  ADOBE_AIR: 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; de) AppleWebKit/533.19.4 (KHTML, like Gecko) AdobeAIR/13.0'
2
2
  ANDROID: 'Android SDK 1.5r3: Mozilla/5.0 (Linux; U; Android 1.5; de-; sdk Build/CUPCAKE) AppleWebkit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1'
3
+ ANDROID_CUPCAKE: Mozilla/5.0 (Linux; U; Android 1.5; en-gb; T-Mobile G1 Build/CRC1) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1
4
+ ANDROID_DONUT: Mozilla/5.0 (Linux; U; Android 1.6; ar-us; SonyEricssonX10i Build/R2BA026) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1
5
+ ANDROID_ECLAIR_21: Mozilla/5.0 (Linux; U; Android 2.1; en-us; Nexus One Build/ERD62) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17
6
+ ANDROID_FROYO: Mozilla/5.0 (Linux; U; Android 2.2; en-sa; HTC_DesireHD_A9191 Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
7
+ ANDROID_GINGERBREAD: Mozilla/5.0 (Linux; U; Android 2.3.3; en-us; Sensation_4G Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/5.0 Safari/533.16
8
+ ANDROID_HONEYCOMB_30: 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
9
+ ANDROID_ICECREAM: Mozilla/5.0 (Linux; U; Android 4.0.1; en-us; sdk Build/ICS_MR0) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
10
+ ANDROID_JELLYBEAN_41: Mozilla/5.0 (Linux; U; Android 4.1.1; en-us; Nexus S Build/JRO03E) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
11
+ ANDROID_JELLYBEAN_42: Mozilla/5.0 (Linux; U; Android 4.2; en-us; Nexus 10 Build/JVP15I) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30
12
+ ANDROID_JELLYBEAN_43: Mozilla/5.0 (Linux; Android 4.3; Nexus 7 Build/JWR66D) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.111 Safari/537.36
13
+ ANDROID_KITKAT: Mozilla/5.0 (Linux; Android 4.4; Nexus 7 Build/KOT24) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.105 Safari/537.36
14
+ ANDROID_LOLLIPOP_50: Mozilla/5.0 (Linux; Android 5.0; Nexus 5 Build/LPX13D) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.102 Mobile Safari/537.36
15
+ ANDROID_LOLLIPOP_51: Mozilla/5.0 (Linux; Android 5.1; Nexus 5 Build/LMY47I) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/40.0.0.0 Mobile Safari/537.36; DailymotionEmbedSDK 1.0
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
+ 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
3
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'
4
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)'
5
20
  ASK: 'Mozilla/2.0 (compatible; Ask Jeeves/Teoma; +http://sp.ask.com/docs/about/tech_crawling.html)'
@@ -14,6 +29,8 @@ BLACKBERRY: 'BlackBerry7100i/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 Vendo
14
29
  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'
15
30
  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.'
16
31
  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'
17
34
  DOT_BOT: 'Mozilla/5.0 (compatible; DotBot/1.1; http://www.opensiteexplorer.org/dotbot, help@moz.com)'
18
35
  DUCKDUCKGO: 'DuckDuckBot/1.0; (+http://duckduckgo.com/duckduckbot.html)'
19
36
  FACEBOOK_BOT: 'facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)'
@@ -23,28 +40,27 @@ FIREFOX_TABLET: 'Mozilla/5.0 (Android; Tablet; rv:14.0) Gecko/14.0 Firefox/14.0'
23
40
  GOOGLE_BOT: 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
24
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'
25
42
  GOOGLE_STRUCTURED_DATA_TESTING_TOOL: 'Mozilla/5.0 (compatible; X11; Linux x86_64; Google-StructuredDataTestingTool; +http://www.google.com/webmasters/tools/richsnippets)'
26
- DAUMOA: Mozilla/5.0 (compatible; MSIE or Firefox mutant; not on Windows server;) Daumoa 4.0
27
- IE_WITHOUT_TRIDENT: Mozilla/4.0 (compatible; MSIE8.0; Windows NT 6.0) .NET CLR 2.0.50727)
43
+ GRAPESHOT: 'Mozilla/5.0 (compatible; GrapeshotCrawler/2.0; +http://www.grapeshot.co.uk/crawler.php)'
28
44
  IE10: 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0; EIE10;ENUSMSN)'
29
45
  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)'
30
46
  IE10_X64_WINX64: 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; Trident/6.0)'
31
47
  IE11: 'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko'
32
- IE11_TOUCH_SCREEN: 'Mozilla/5.0 (Windows NT 6.3; Win64; x64; Trident/7.0; Touch; rv:11.0) like Gecko'
33
48
  IE11_COMPAT: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.3; WOW64; Trident/7.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729)'
49
+ IE11_TOUCH_SCREEN: 'Mozilla/5.0 (Windows NT 6.3; Win64; x64; Trident/7.0; Touch; rv:11.0) like Gecko'
34
50
  IE6: 'Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)'
35
51
  IE7: 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)'
36
52
  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)'
37
53
  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)'
38
54
  IE9: 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)'
39
55
  IE9_COMPAT: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/5.0)'
40
- 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'
41
- 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)'
42
- 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'
56
+ IE_WITHOUT_TRIDENT: Mozilla/4.0 (compatible; MSIE8.0; Windows NT 6.0) .NET CLR 2.0.50727)
43
57
  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'
44
58
  IOS5: 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3'
45
59
  IOS6: 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25'
46
60
  IOS7: 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53'
47
61
  IOS8: 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A365 Safari/600.1.4'
62
+ IOS9: 'Mozilla/5.0 (iPad; CPU OS 9_0 like Mac OS X) AppleWebKit/601.1.17 (KHTML, like Gecko) Version/8.0 Mobile/13A175 Safari/600.1.4'
63
+ IOS_WEBVIEW: Mozilla/5.0 (iPhone; CPU iPhone OS 8_4 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12H141
48
64
  IPAD: 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10'
49
65
  IPHONE: 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/1A542a Safari/419.3'
50
66
  IPOD: 'Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3A100a Safari/419.3'
@@ -58,10 +74,14 @@ LUMIA800: 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; XBLWP
58
74
  MAIL_RU: 'Mozilla/5.0 (compatible; Linux x86_64; Mail.RU_Bot/2.0; +http://go.mail.ru/help/robots)'
59
75
  MEGAINDEX_RU: 'Mozilla/5.0 (compatible; MegaIndex.ru/2.0; +https://www.megaindex.ru/?tab=linkAnalyze)'
60
76
  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
+ 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
+ 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
+ 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'
61
80
  MSN_BOT: 'msnbot-media/1.1 (+http://search.msn.com/msnbot.htm)'
62
81
  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'
63
82
  NINTENDO_WII: 'Opera/9.00 (Nintendo Wii; U; ; 1309-9; en)'
64
83
  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'
84
+ NOKIA: 'Mozilla/5.0 (Series40; NokiaX3-02/le6.32; Profile/MIDP-2.1 Configuration/CLDC-1.1) Gecko/20100401 S40OviBrowser/2.0.2.62.10'
65
85
  NOOK: 'Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; NOOK BNTV250A Build/GINGERBREAD 1.4.3) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Safari/533.1'
66
86
  OPERA: 'Opera/9.80 (Macintosh; Intel Mac OS X 10.7.4; U; en) Presto/2.10.229 Version/11.64'
67
87
  OPERA_MINI: 'Opera/9.80 (Android; Opera Mini/7.029952/28.2359;u; fr) Presto/2.8.119 Version/11.10'
@@ -73,30 +93,35 @@ PLAYSTATION3: 'Mozilla/5.0 (PLAYSTATION 3; 3.55)'
73
93
  PLAYSTATION4: 'Mozilla/5.0 (PlayStation 4 1.020) AppleWebKit/536.26 (KHTML, like Gecko)'
74
94
  PSP: 'Mozilla/4.0 (PSP (PlayStation Portable); 2.00)'
75
95
  PSP_VITA: 'Mozilla/5.0 (Playstation Vita 1.61) AppleWebKit/531.22.8 (KHTML, like Gecko) Silk/3.2'
76
- QUICKTIME: 'QuickTime/7.6.8 (qtver=7.6.8;os=Windows NT 5.1Service Pack 3)'
77
96
  QUERYSEEKER: 'QuerySeekerSpider ( http://queryseeker.com/bot.html )'
97
+ QUICKTIME: 'QuickTime/7.6.8 (qtver=7.6.8;os=Windows NT 5.1Service Pack 3)'
78
98
  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'
79
99
  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'
80
100
  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'
81
101
  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'
82
102
  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'
83
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/)'
84
106
  SMART_TV: 'Mozilla/5.0 (SmartHub; SMART-TV; U; Linux/SmartTV) AppleWebKit/531.2+ (KHTML, like Gecko) WebBrowser/1.0 SmartTV Safari/531.2+'
85
107
  SURFACE: 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; ARM; Trident/6.0; Touch)'
86
108
  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'
87
- WINDOWS_XP: 'Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; FDM; .NET CLR 1.1.4322)'
88
- 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)'
109
+ TINEYE: 'TinEye-bot/0.51 (see http://www.tineye.com/crawler.html)'
110
+ 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'
89
111
  WINDOWS7: 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0) chromeframe/10.0.648.205'
90
112
  WINDOWS81: 'Mozilla/5.0 (IE 11.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C; rv:11.0) like Gecko'
91
113
  WINDOWS8: 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)'
92
- WINDOWS_WOW64: "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko"
93
114
  WINDOWS_MOBILE: 'Mozilla/4.0 (compatible; MSIE 6.0; Windows CE; IEMobile 6.12)'
94
115
  WINDOWS_PHONE8: 'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920)'
95
116
  WINDOWS_PHONE: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; DELL; Venue Pro)'
96
117
  WINDOWS_PHONE_81: 'Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 929) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537'
118
+ 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
+ WINDOWS_WOW64: "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko"
120
+ WINDOWS_XP: 'Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; FDM; .NET CLR 1.1.4322)'
97
121
  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)'
98
122
  XBOXONE: 'Mozilla/5.0 (Compatible; MSIE 10.0; Windows NT 6.2; Trident /6.0; Xbox; Xbox One)'
99
123
  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'
100
124
  YAHOO_SLURP: 'Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)'
125
+ 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'
101
126
  YANDEX_DIRECT: 'Mozilla/5.0 (compatible; YandexDirect/3.0; +http://yandex.com/bots)'
102
127
  YANDEX_METRIKA: 'Mozilla/5.0 (compatible; YandexMetrika/3.0; +http://yandex.com/bots)'
@@ -0,0 +1,17 @@
1
+ require "test_helper"
2
+
3
+ class AdobeAirTest < Minitest::Test
4
+ setup do
5
+ @browser = Browser.new
6
+ end
7
+
8
+ test "detects adobe air" do
9
+ @browser.ua = $ua["ADOBE_AIR"]
10
+
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"
16
+ end
17
+ end
@@ -0,0 +1,97 @@
1
+ require "test_helper"
2
+
3
+ class AndroidTest < Minitest::Test
4
+ setup do
5
+ @browser = Browser.new
6
+ end
7
+
8
+ test "detect android cupcake (1.5)" do
9
+ @browser.ua = $ua['ANDROID_CUPCAKE']
10
+ assert @browser.android?
11
+ assert @browser.android?(1.5)
12
+ end
13
+
14
+ test "detect android donut (1.6)" do
15
+ @browser.ua = $ua['ANDROID_DONUT']
16
+ assert @browser.android?
17
+ assert @browser.android?(1.6)
18
+ end
19
+
20
+ test "detect android eclair (2.1)" do
21
+ @browser.ua = $ua['ANDROID_ECLAIR_21']
22
+ assert @browser.android?
23
+ assert @browser.android?(2.1)
24
+ end
25
+
26
+ test "detect android froyo (2.2)" do
27
+ @browser.ua = $ua['ANDROID_FROYO']
28
+ assert @browser.android?
29
+ assert @browser.android?(2.2)
30
+ end
31
+
32
+ test "detect android gingerbread (2.3)" do
33
+ @browser.ua = $ua['ANDROID_GINGERBREAD']
34
+ assert @browser.android?
35
+ assert @browser.android?(2.3)
36
+ end
37
+
38
+ test "detect android honeycomb (3.0)" do
39
+ @browser.ua = $ua['ANDROID_HONEYCOMB_30']
40
+ assert @browser.android?
41
+ assert @browser.android?(3.0)
42
+ end
43
+
44
+ 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)
48
+ end
49
+
50
+ test "detect android jellybean (4.1)" do
51
+ @browser.ua = $ua['ANDROID_JELLYBEAN_41']
52
+ assert @browser.android?
53
+ assert @browser.android?(4.1)
54
+ end
55
+
56
+ test "detect android jellybean (4.2)" do
57
+ @browser.ua = $ua['ANDROID_JELLYBEAN_42']
58
+ assert @browser.android?
59
+ assert @browser.android?(4.2)
60
+ end
61
+
62
+ test "detect android jellybean (4.3)" do
63
+ @browser.ua = $ua['ANDROID_JELLYBEAN_43']
64
+ assert @browser.android?
65
+ assert @browser.android?(4.3)
66
+ end
67
+
68
+ test "detect android kitkat (4.4)" do
69
+ @browser.ua = $ua['ANDROID_KITKAT']
70
+ assert @browser.android?
71
+ assert @browser.android?(4.4)
72
+ end
73
+
74
+ test "detect android lollipop (5.0)" do
75
+ @browser.ua = $ua['ANDROID_LOLLIPOP_50']
76
+ assert @browser.android?
77
+ assert @browser.android?(5.0)
78
+ end
79
+
80
+ test "detect android lollipop (5.1)" do
81
+ @browser.ua = $ua['ANDROID_LOLLIPOP_51']
82
+ assert @browser.android?
83
+ assert @browser.android?(5.1)
84
+ end
85
+
86
+ test "detect android tv" do
87
+ @browser.ua = $ua['ANDROID_TV']
88
+ assert @browser.android?
89
+ assert @browser.tv?
90
+ end
91
+
92
+ test "detect nexus player" do
93
+ @browser.ua = $ua['ANDROID_NEXUS_PLAYER']
94
+ assert @browser.android?
95
+ assert @browser.tv?
96
+ end
97
+ end
@@ -0,0 +1,106 @@
1
+ require "test_helper"
2
+
3
+ class BlackberryTest < Minitest::Test
4
+ setup do
5
+ @browser = Browser.new
6
+ end
7
+
8
+ test "detects blackberry" do
9
+ @browser.ua = $ua["BLACKBERRY"]
10
+
11
+ assert_equal "BlackBerry", @browser.name
12
+ assert @browser.blackberry?
13
+ refute @browser.tablet?
14
+ assert @browser.mobile?
15
+ refute @browser.modern?
16
+ assert_equal "4.1.0", @browser.full_version
17
+ assert_equal "4", @browser.version
18
+ end
19
+
20
+ test "detects blackberry4" do
21
+ @browser.ua = $ua["BLACKBERRY4"]
22
+
23
+ assert_equal "BlackBerry", @browser.name
24
+ assert_equal "4", @browser.blackberry_version
25
+ assert @browser.blackberry?(4)
26
+ refute @browser.tablet?
27
+ assert @browser.mobile?
28
+ refute @browser.modern?
29
+ assert_equal "4.2.1", @browser.full_version
30
+ assert_equal "4", @browser.version
31
+ end
32
+
33
+ test "detects blackberry5" do
34
+ @browser.ua = $ua["BLACKBERRY5"]
35
+
36
+ assert_equal "BlackBerry", @browser.name
37
+ assert @browser.blackberry?(5)
38
+ assert_equal "5", @browser.blackberry_version
39
+ refute @browser.tablet?
40
+ assert @browser.mobile?
41
+ refute @browser.modern?
42
+ assert_equal "5.0.0.93", @browser.full_version
43
+ assert_equal "5", @browser.version
44
+ end
45
+
46
+ test "detects blackberry6" do
47
+ @browser.ua = $ua["BLACKBERRY6"]
48
+
49
+ assert_equal "Safari", @browser.name
50
+ assert @browser.blackberry?(6)
51
+ assert_equal "6", @browser.blackberry_version
52
+ refute @browser.tablet?
53
+ assert @browser.mobile?
54
+ assert @browser.modern?
55
+ assert_equal "534.11", @browser.full_version
56
+ assert_equal "534", @browser.version
57
+ end
58
+
59
+ test "detects blackberry7" do
60
+ @browser.ua = $ua["BLACKBERRY7"]
61
+
62
+ assert_equal "Safari", @browser.name
63
+ assert @browser.blackberry?(7)
64
+ assert_equal "7", @browser.blackberry_version
65
+ refute @browser.tablet?
66
+ assert @browser.mobile?
67
+ assert @browser.modern?
68
+ assert_equal "534.11", @browser.full_version
69
+ assert_equal "534", @browser.version
70
+ end
71
+
72
+ test "detects blackberry10" do
73
+ @browser.ua = $ua["BLACKBERRY10"]
74
+
75
+ assert_equal "Safari", @browser.name
76
+ assert_equal "10", @browser.blackberry_version
77
+ assert @browser.blackberry?(10)
78
+ refute @browser.tablet?
79
+ assert @browser.mobile?
80
+ assert @browser.modern?
81
+ assert_equal "10.0.9.1675", @browser.full_version
82
+ assert_equal "10", @browser.version
83
+ end
84
+
85
+ test "detects blackberry playbook tablet" do
86
+ @browser.ua = $ua["PLAYBOOK"]
87
+
88
+ refute @browser.android?
89
+ assert @browser.tablet?
90
+ refute @browser.mobile?
91
+
92
+ assert_equal "7.2.1.0", @browser.full_version
93
+ assert_equal "7", @browser.version
94
+ end
95
+
96
+ test "warn about deprecated numbered version" do
97
+ message = "Browser#blackberry10? is deprecated; use Browser#blackberry?(version) instead"
98
+ assert_deprecated(message, __FILE__, __LINE__) { @browser.blackberry10? }
99
+ end
100
+
101
+ test "don't detect as two different versions" do
102
+ @browser.ua = $ua["BLACKBERRY10"]
103
+ assert @browser.blackberry?(10)
104
+ refute @browser.blackberry?(7)
105
+ end
106
+ end
@@ -0,0 +1,121 @@
1
+ require "test_helper"
2
+
3
+ class BotsTest < Minitest::Test
4
+ setup do
5
+ @browser = Browser.new
6
+ end
7
+
8
+ test "detects bots" do
9
+ %w[
10
+ APPLE_BOT
11
+ DOMAINAREANIMATOR
12
+ DOT_BOT
13
+ FACEBOOK_BOT
14
+ GOOGLE_BOT
15
+ GRAPESHOT
16
+ LINKDEXBOT
17
+ LOAD_TIME_BOT
18
+ MAIL_RU
19
+ MEGAINDEX_RU
20
+ MSN_BOT
21
+ QUERYSEEKER
22
+ SCRAPY
23
+ SEOKICKS
24
+ TINEYE
25
+ SISTRIX
26
+ YANDEX_DIRECT
27
+ YANDEX_METRIKA
28
+ ].each do |key|
29
+ @browser.ua = $ua[key]
30
+ assert @browser.bot?, "#{$ua[key]} should be a bot"
31
+ end
32
+
33
+ @browser.ua = $ua["CHROME"]
34
+ refute @browser.bot?
35
+ end
36
+
37
+ test "detects Google Page Speed as a bot" do
38
+ @browser.ua = $ua["GOOGLE_PAGE_SPEED_INSIGHTS"]
39
+ assert @browser.bot?
40
+ end
41
+
42
+ test "doesn't consider empty UA as bot" do
43
+ @browser.ua = ""
44
+ refute @browser.bot?
45
+ end
46
+
47
+ test "allows setting empty string as bots" do
48
+ Browser::Bots.detect_empty_ua!
49
+ @browser.ua = ""
50
+
51
+ assert @browser.bot?
52
+ end
53
+
54
+ test "doesn't detect mozilla as a bot when considering empty UA" do
55
+ Browser::Bots.detect_empty_ua!
56
+ @browser.ua = "Mozilla"
57
+
58
+ refute @browser.bot?
59
+ end
60
+
61
+ test "returns bot name" do
62
+ @browser.ua = $ua["GOOGLE_BOT"]
63
+ assert_equal @browser.bot_name, "Googlebot"
64
+
65
+ @browser.ua = $ua["FACEBOOK_BOT"]
66
+ assert_equal @browser.bot_name, "facebookexternalhit"
67
+ end
68
+
69
+ test "returns bot name (empty string ua detection enabled)" do
70
+ Browser::Bots.detect_empty_ua!
71
+ @browser.ua = ""
72
+
73
+ assert_equal @browser.bot_name, "Generic Bot"
74
+ end
75
+
76
+ test "returns nil for non-bots" do
77
+ @browser.ua = $ua["CHROME"]
78
+ assert_equal @browser.bot_name, nil
79
+ end
80
+
81
+ test "detects as search engines" do
82
+ %w[
83
+ ASK
84
+ BAIDU
85
+ BINGBOT
86
+ DUCKDUCKGO
87
+ GOOGLE_BOT
88
+ YAHOO_SLURP
89
+ ].each do |key|
90
+ @browser.ua = $ua[key]
91
+ assert @browser.search_engine?, "#{$ua[key]} should be a search engine"
92
+ end
93
+ end
94
+
95
+ test "detects Google Structured Data Testing Tool as a bot" do
96
+ @browser.ua = $ua["GOOGLE_STRUCTURED_DATA_TESTING_TOOL"]
97
+
98
+ assert @browser.bot?, "Google Structured Data Testing Tool should be a bot"
99
+ end
100
+
101
+ test "detects Daumoa" do
102
+ @browser.ua = $ua["DAUMOA"]
103
+
104
+ assert_equal :ie, @browser.id
105
+ assert_equal "Internet Explorer", @browser.name
106
+ assert_equal "0.0", @browser.msie_full_version
107
+ assert_equal "0", @browser.msie_version
108
+ assert_equal "0.0", @browser.full_version
109
+ assert_equal "0", @browser.version
110
+ assert @browser.ie?
111
+ assert @browser.bot?
112
+ refute @browser.windows10?
113
+ refute @browser.windows_phone?
114
+ refute @browser.edge?
115
+ refute @browser.modern?
116
+ refute @browser.mobile?
117
+ refute @browser.webkit?
118
+ refute @browser.chrome?
119
+ refute @browser.safari?
120
+ end
121
+ end