Codebase list ruby-browser / 4262ae1
Imported Upstream version 1.0.1 Balasankar C 8 years ago
15 changed file(s) with 483 addition(s) and 44 deletion(s). Raw diff Collapse all Expand all
0 ClassLength:
1 Enabled: false
2
3 CyclomaticComplexity:
4 Enabled: false
5
6 Documentation:
7 Enabled: false
8
9 Encoding:
10 Enabled: false
11
12 FileName:
13 Enabled: false
14
15 IfUnlessModifier:
16 Enabled: false
17
18 MethodLength:
19 Enabled: false
20
21 ModuleFunction:
22 Enabled: false
23
24 OneLineConditional:
25 Enabled: false
26
27 ParameterLists:
28 Enabled: false
29
30 Proc:
31 Enabled: false
32
33 SingleLineBlockParams:
34 Enabled: false
35
36 VariableInterpolation:
37 Enabled: false
38
39 TrailingComma:
40 Enabled: false
41
42 WhileUntilModifier:
43 Enabled: false
44
45 PredicateName:
46 NamePrefixBlacklist:
47 - is_
48
49 StringLiterals:
50 EnforcedStyle: double_quotes
51 SupportedStyles:
52 - single_quotes
53 - double_quotes
54
55 DotPosition:
56 EnforcedStyle: leading
57
58 SpaceBeforeBlockBraces:
59 EnforcedStyle: space
60
61 SpaceInsideBlockBraces:
62 EnforcedStyle: no_space
63
64 DoubleNegation:
65 Enabled: false
66
67 SpaceInsideBlockBraces:
68 SpaceBeforeBlockParameters: false
69
70 LineLength:
71 Max: 130
72
73 RegexpLiteral:
74 MaxSlashes: 0
75
76 SpaceInsideHashLiteralBraces:
77 Enabled: false
78
79 PercentLiteralDelimiters:
80 PreferredDelimiters:
81 '%': '[]'
82 '%i': '[]'
83 '%q': '[]'
84 '%Q': '[]'
85 '%r': '[]'
86 '%s': '[]'
87 '%w': '[]'
88 '%W': '[]'
89 '%x': '[]'
00 language: ruby
1 sudo: false
2 cache: bundler
13 rvm:
2 - 1.9.3
3 - 2.0.0
4 - 2.1.4
4 - '2.2'
5 - '2.1'
6 - '2.0'
57 gemfile:
68 - Gemfile
79 - gemfiles/rails3.gemfile
810 script: "bundle exec rake spec"
11 notifications:
12 email: false
11
22 [![Travis-CI](https://travis-ci.org/fnando/browser.png)](https://travis-ci.org/fnando/browser)
33 [![CodeClimate](https://codeclimate.com/github/fnando/browser.png)](https://codeclimate.com/github/fnando/browser)
4 [![Gem Version](https://badge.fury.io/rb/browser.svg)](http://badge.fury.io/rb/browser)
45
56 Do some browser detection with Ruby. Includes ActionController integration.
67
3031 browser.firefox?
3132 browser.ie?
3233 browser.ie6? # this goes up to 11
34 browser.edge? # Newest MS browser
3335 browser.modern? # Webkit, Firefox 17+, IE 9+ and Opera 12+
3436 browser.platform # return :mac, :windows, :linux or :other
3537 browser.mac?
6062 * Firefox Tablet 14+
6163 * Opera 12+
6264
63 You can define your your rules. A rule must be a proc/lambda or any object that implements the method === and accepts the browser object. To redefine all rules, clear the existing rules before adding your own.
65 You can define your own rules. A rule must be a proc/lambda or any object that implements the method === and accepts the browser object. To redefine all rules, clear the existing rules before adding your own.
6466
6567 ```ruby
6668 # Only Chrome Canary is considered modern.
8385 <p class="disclaimer">You're running an older IE version. Please update it!</p>
8486 <% end %>
8587 ```
88
89 ### Internet Explorer
90
91 Internet Explorer has a compatibility view mode that allows newer versions (IE8+) to run as an older version. Browser will always return the navigator version, ignoring the compatibility view version, when defined. If you need to get the engine's version, you have to use `Browser#msie_version` and `Browser#msie_full_version`.
92
93 So, let's say an user activates compatibility view in a IE11 browser. This is what you'll get:
94
95 ```ruby
96 browser.version
97 #=> 11
98
99 browser.full_version
100 #=> 11.0
101
102 browser.msie_version
103 #=> 7
104
105 browser.msie_full_version
106 #=> 7.0
107
108 browser.compatibility_view?
109 #=> true
110
111 browser.modern?
112 #=> false
113 ```
114
115 This behavior changed in `v1.0.0`; previously there wasn't a way of getting the real browser version.
86116
87117 ### Bots
88118
120150 end
121151 ```
122152
153 If you need acccess to the `Rack::Request` object (e.g. to exclude a path), you can do so with `request`.
154 ```ruby
155 Rails.configuration.middleware.use Browser::Middleware do
156 redirect_to upgrade_path unless browser.modern? || request.env['PATH_INFO'] == '/exclude_me'
157 end
158 ```
159
123160 ## Maintainer
124161
125162 * Nando Vieira - http://nandovieira.com.br
66 Apache-HttpClient: "Java http library"
77 ApacheBench: "ApacheBench (ab)"
88 AppEngine-Google: "Google App Engine"
9 Applebot: "Apple Bot"
910 Ask Jeeves: "Ask Jeeves"
1011 AsyncHttpClient: "Java http and WebSocket client library"
1112 awe.sm: "Awe.sm URL expander"
1314 Baiduspider: "Chinese search engine"
1415 bingbot: "Microsoft bing bot"
1516 bitlybot: "bit.ly bot"
17 BLEXBot: "webmeup-crawler.com"
1618 bot@linkfluence.net: "Linkfluence bot"
1719 BuiBui-CheckBot: "email: buibui[at]dadapro[dot]com"
1820 Butterfly: "Topsy Labs"
3436 EvriNid: "Evri bot"
3537 Exabot: "Exalead's bot"
3638 ExaleadCloudView: "ExaleadCloudView"
37 facebookexternalhit: "facebook bot"
39 facebookexternalhit: "Facebook Bot"
40 Facebot: "Facebook Bot"
3841 FeedBurner: "RSS bot"
3942 Feedfetcher-Google: "Google Feedfetcher"
4043 FlipboardProxy: "FlipboardProxy"
4346 Gigabot: "Gigabot spider"
4447 Go http package: "Go http library"
4548 Google Web Preview: "Google Instant Previews crawler"
49 Google Page Speed Insights: "Google Page Speed Insights"
4650 Googlebot: "Google spider"
4751 Hatena::Bookmark: "Hatena::Bookmark"
4852 heritrix: "heritrix"
8488 magpie-crawler: "magpie-crawler"
8589 Mail.RU_Bot: "Mail.ru Bot"
8690 Mediapartners-Google: "Google Adsense bot"
91 MegaIndex.ru: "Mozilla/5.0 (compatible; MegaIndex.ru/2.0; +https://www.megaindex.ru/?tab=linkAnalyze)"
8792 MetaURI: "MetaURI"
8893 MetaURI: "URI meta information extractor bot"
8994 MFE_expand: "Mcafee spider"
111116 python-requests: "Python http library"
112117 python-requests: "python-requests"
113118 Python-urllib: "Python http library"
119 QuerySeeker: "QuerySeekerSpider ( http://queryseeker.com/bot.html )"
114120 QuickLook: "QuickLook"
115121 Readability: "Readability"
116122 RebelMouse: "RebelMouse"
128134 ShowyouBot: "Showyou iOS app spider"
129135 Siege: "Joe Dog Siege"
130136 SiteUptime: "Site monitoring services"
137 Slack: "Slackbot-LinkExpanding"
131138 Slurp: "Yahoo spider"
132139 Sogou: "Chinese search engine"
133140 spider: "generic web spider"
152159 Webscout: "Webscout"
153160 Wget: "wget unix CLI http client"
154161 WordPress: "WordPress spider"
162 Wormly: "WormlyBot"
155163 Xenu Link Sleuth: "Xenu Link Sleuth"
156164 XoviBot: "XoviBot"
157165 YandexBot: "Yandex spider"
161169 zelist.ro: "feed parser"
162170 ZIBB: "ZIBB spider"
163171 ZyBorg: "Zyborg? Hmmm...."
172 StructuredDataTestingTool: 'Google-StructuredDataTestingTool'
1010 s.homepage = "http://github.com/fnando/browser"
1111 s.summary = "Do some browser detection with Ruby."
1212 s.description = s.summary
13 s.license = 'MIT'
1314
1415 s.files = `git ls-files`.split("\n")
1516 s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
1617 s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
1718 s.require_paths = ["lib"]
1819
20 s.post_install_message = [
21 "",
22 "#################### WARNING ##############################" ,
23 "# #" ,
24 "# Internet Explorer detection has changed on v1.0.0+. #" ,
25 "# If this is important for you, please read #" ,
26 "# https://github.com/fnando/browser#internet-explorer #" ,
27 "# #" ,
28 "###########################################################" ,
29 "\n"
30 ].join("\n")
31
1932 s.add_development_dependency "bundler", ">= 0"
2033 s.add_development_dependency "rake"
2134 s.add_development_dependency "rails"
2235 s.add_development_dependency "rack-test"
2336 s.add_development_dependency "minitest"
37 s.add_development_dependency "minitest-utils"
2438 end
1818 def bot_name
1919 return unless bot?
2020 return "Generic Bot" if bot_with_empty_ua?
21 BOTS.find {|key, description| ua.include?(key) }.first
21 BOTS.find {|key, _| ua.include?(key) }.first
2222 end
2323
2424 def search_engine?
11 module IE
22 TRIDENT_VERSION_REGEX = %r[Trident/([0-9.]+)]
33 MODERN_IE = %r[Trident/.*?; rv:(.*?)]
4 MSIE = %r{MSIE ([\d.]+)|Trident/.*?; rv:([\d.]+)}
5 EDGE = %r{(Edge/[\d.]+|Trident/8)}
6
7 # https://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx#TriToken
8 TRIDENT_MAPPING = {
9 "4.0" => "8",
10 "5.0" => "9",
11 "6.0" => "10",
12 "7.0" => "11",
13 "8.0" => "12"
14 }
15
16 def ie_version
17 TRIDENT_MAPPING[trident_version] || msie_version
18 end
19
20 def ie_full_version
21 "#{ie_version}.0"
22 end
23
24 def msie_full_version
25 (ua.match(MSIE) && ($1 || $2)) || "0.0"
26 end
27
28 def msie_version
29 msie_full_version.to_s.split(".").first || "0"
30 end
31
32 # Return the trident version.
33 def trident_version
34 ua.match(TRIDENT_VERSION_REGEX) && $1
35 end
436
537 # Detect if browser is Internet Explorer.
638 def ie?
3769 ie? && version == "11"
3870 end
3971
72 # Detect if browser is Microsoft Edge.
73 def edge?
74 !!(ua =~ EDGE)
75 end
76
4077 # Detect if IE is running in compatibility mode.
4178 def compatibility_view?
42 match = ua.match(TRIDENT_VERSION_REGEX)
43 ie? && match && version.to_i < (match[1].to_i + 4)
79 ie? && trident_version && msie_version.to_i < (trident_version.to_i + 4)
4480 end
4581
4682 private
2525 def detect_mobile?
2626 !!(
2727 psp? ||
28 /zunewp7/i.match(ua) ||
2829 /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.match(ua) ||
2930 /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.match(ua[0..3])
3031 )
6969 !!(ua =~ /Windows/)
7070 end
7171
72 ## More info here => http://msdn.microsoft.com/fr-FR/library/ms537503.aspx#PltToken
73 def windows_xp?
74 windows? && !!(ua =~ /Windows NT 5.1/)
75 end
76
77 def windows_vista?
78 windows? && !!(ua =~ /Windows NT 6.0/)
79 end
80
81 def windows7?
82 windows? && !!(ua =~ /Windows NT 6.1/)
83 end
84
7285 def windows8?
7386 windows? && !!(ua =~ /Windows NT 6.[2-3]/)
7487 end
7588
89 def windows8_1?
90 windows? && !!(ua =~ /Windows NT 6\.3/)
91 end
92
93 def windows10?
94 windows? && !!(ua =~ /Windows NT 10/)
95 end
96
7697 def windows_rt?
7798 windows8? && !!(ua =~ /ARM/)
78 end
79
80 # Detect if current platform is Linux flavor.
81 def linux?
82 !!(ua =~ /Linux/)
8399 end
84100
85101 # Detect if current platform is Windows Mobile.
95111 # Detect if current platform is Windows in 64-bit architecture.
96112 def windows_x64?
97113 windows? && !!(ua =~ /(Win64|x64)/) && !!(ua =~ /x64/)
114 end
115
116 def windows_wow64?
117 windows? && !!(ua =~ /WOW64/i)
118 end
119
120 def windows_x64_inclusive?
121 windows_x64? || windows_wow64?
122 end
123
124 # Detect if current platform is Linux flavor.
125 def linux?
126 !!(ua =~ /Linux/)
98127 end
99128
100129 # Detect if current platform is ChromeOS
00 class Browser
11 module Version
2 MAJOR = 0
3 MINOR = 8
4 PATCH = 0
2 MAJOR = 1
3 MINOR = 0
4 PATCH = 1
55 STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
66 end
77 end
4141 alias_method :ua=, :user_agent=
4242
4343 NAMES = {
44 ie: "Internet Explorer", # Must come before android
45 chrome: "Chrome", # Must come before android
44 edge: "Microsoft Edge", # Must come before everything
45 ie: "Internet Explorer", # Must come before android
46 chrome: "Chrome", # Must come before android
47 firefox: "Firefox", # Must come before android
4648 android: "Android",
4749 blackberry: "BlackBerry",
4850 core_media: "Apple CoreMedia",
49 firefox: "Firefox",
5051 ipad: "iPad",
5152 iphone: "iPhone",
5253 ipod: "iPod Touch",
6465 }
6566
6667 VERSIONS = {
68 edge: %r[Edge/([\d.]+)],
6769 chrome: %r[(?:Chrome|CriOS)/([\d.]+)],
6870 default: %r[(?:Version|MSIE|Firefox|QuickTime|BlackBerry[^/]+|CoreMedia v|PhantomJS|AdobeAIR)[/ ]?([a-z0-9.]+)]i,
6971 opera: %r[(?:Opera/.*? Version/([\d.]+)|Chrome/.*?OPR/([\d.]+))],
8789 self.modern_rules.tap do |rules|
8890 rules << -> b { b.webkit? }
8991 rules << -> b { b.firefox? && b.version.to_i >= 17 }
90 rules << -> b { b.ie? && b.version.to_i >= 9 }
92 rules << -> b { b.ie? && b.version.to_i >= 9 && !b.compatibility_view? }
93 rules << -> b { b.edge? && !b.compatibility_view? }
9194 rules << -> b { b.opera? && b.version.to_i >= 12 }
9295 rules << -> b { b.firefox? && b.tablet? && b.android? && b.version.to_i >= 14 }
9396 end
120123
121124 # Return major version.
122125 def version
123 full_version.to_s.split(".").first
126 if ie?
127 ie_version
128 else
129 full_version.to_s.split(".").first
130 end
124131 end
125132
126133 # Return the full version.
127134 def full_version
128 _, *v = *ua.match(VERSIONS.fetch(id, VERSIONS[:default]))
129 v.compact.first || "0.0"
135 if ie?
136 ie_full_version
137 else
138 _, *v = *ua.match(VERSIONS.fetch(id, VERSIONS[:default]))
139 v.compact.first || "0.0"
140 end
130141 end
131142
132143 # Return true if browser is modern (Webkit, Firefox 17+, IE9+, Opera 12+).
136147
137148 # Detect if browser is WebKit-based.
138149 def webkit?
139 !!(ua =~ /AppleWebKit/i)
150 ua =~ /AppleWebKit/i && !edge?
140151 end
141152
142153 # Detect if browser is QuickTime
170181
171182 # Detect if browser is Chrome.
172183 def chrome?
173 !!(ua =~ /Chrome|CriOS/) && !opera?
184 ua =~ /Chrome|CriOS/ && !opera? && !edge?
174185 end
175186
176187 # Detect if browser is Opera.
00 --- !ruby/object:Gem::Specification
11 name: browser
22 version: !ruby/object:Gem::Version
3 version: 0.8.0
3 version: 1.0.1
44 platform: ruby
55 authors:
66 - Nando Vieira
77 autorequire:
88 bindir: bin
99 cert_chain: []
10 date: 2014-11-20 00:00:00.000000000 Z
10 date: 2015-08-25 00:00:00.000000000 Z
1111 dependencies:
1212 - !ruby/object:Gem::Dependency
1313 name: bundler
7979 - - ">="
8080 - !ruby/object:Gem::Version
8181 version: '0'
82 - !ruby/object:Gem::Dependency
83 name: minitest-utils
84 requirement: !ruby/object:Gem::Requirement
85 requirements:
86 - - ">="
87 - !ruby/object:Gem::Version
88 version: '0'
89 type: :development
90 prerelease: false
91 version_requirements: !ruby/object:Gem::Requirement
92 requirements:
93 - - ">="
94 - !ruby/object:Gem::Version
95 version: '0'
8296 description: Do some browser detection with Ruby.
8397 email:
8498 - fnando.vieira@gmail.com
88102 files:
89103 - ".gitignore"
90104 - ".hound.yml"
105 - ".rubocop.yml"
91106 - ".travis.yml"
92107 - CONTRIBUTING.md
93108 - Gemfile
131146 - test/spec_helper.rb
132147 - test/ua.yml
133148 homepage: http://github.com/fnando/browser
134 licenses: []
149 licenses:
150 - MIT
135151 metadata: {}
136 post_install_message:
152 post_install_message: |2+
153
154 #################### WARNING ##############################
155 # #
156 # Internet Explorer detection has changed on v1.0.0+. #
157 # If this is important for you, please read #
158 # https://github.com/fnando/browser#internet-explorer #
159 # #
160 ###########################################################
161
137162 rdoc_options: []
138163 require_paths:
139164 - lib
149174 version: '0'
150175 requirements: []
151176 rubyforge_project:
152 rubygems_version: 2.2.2
177 rubygems_version: 2.4.5
153178 signing_key:
154179 specification_version: 4
155180 summary: Do some browser detection with Ruby.
180180
181181 assert_equal "Internet Explorer", @browser.name
182182 assert @browser.ie?
183 assert @browser.ie7?
184 refute @browser.ie8?
183 assert @browser.ie8?
185184 refute @browser.modern?
186185 assert @browser.compatibility_view?
187 assert_equal "7.0", @browser.full_version
188 assert_equal "7", @browser.version
186 assert_equal "8.0", @browser.full_version
187 assert_equal "8", @browser.version
188 assert_equal "7.0", @browser.msie_full_version
189 assert_equal "7", @browser.msie_version
189190 end
190191
191192 it "detects ie9" do
205206
206207 assert_equal "Internet Explorer", @browser.name
207208 assert @browser.ie?
208 assert @browser.ie7?
209 refute @browser.ie9?
209 assert @browser.ie9?
210210 refute @browser.modern?
211211 assert @browser.compatibility_view?
212 assert_equal "7.0", @browser.full_version
213 assert_equal "7", @browser.version
212 assert_equal "9.0", @browser.full_version
213 assert_equal "9", @browser.version
214 assert_equal "7.0", @browser.msie_full_version
215 assert_equal "7", @browser.msie_version
214216 end
215217
216218 it "detects ie10" do
230232
231233 assert_equal "Internet Explorer", @browser.name
232234 assert @browser.ie?
233 assert @browser.ie7?
234 refute @browser.ie10?
235 assert @browser.ie10?
235236 refute @browser.modern?
236237 assert @browser.compatibility_view?
237 assert_equal "7.0", @browser.full_version
238 assert_equal "7", @browser.version
238 assert_equal "10.0", @browser.full_version
239 assert_equal "10", @browser.version
240 assert_equal "7.0", @browser.msie_full_version
241 assert_equal "7", @browser.msie_version
239242 end
240243
241244 it "detects ie11" do
250253 assert_equal "11", @browser.version
251254 end
252255
256 it "detects ie11 in compatibility view" do
257 @browser.ua = $ua["IE11_COMPAT"]
258
259 assert_equal "Internet Explorer", @browser.name
260 assert @browser.ie?
261 assert @browser.ie11?
262 refute @browser.modern?
263 assert @browser.compatibility_view?
264 assert_equal "11.0", @browser.full_version
265 assert_equal "11", @browser.version
266 assert_equal "7.0", @browser.msie_full_version
267 assert_equal "7", @browser.msie_version
268 end
269
270 it "detects Lumia 800" do
271 @browser.ua = $ua["LUMIA800"]
272
273 assert_equal "Internet Explorer", @browser.name
274 assert @browser.ie?
275 assert @browser.ie9?
276 assert_equal "9.0", @browser.full_version
277 assert_equal "9", @browser.version
278 refute @browser.tablet?
279 assert @browser.mobile?
280 end
281
253282 it "detects opera" do
254283 @browser.ua = $ua["OPERA"]
255284
286315 it "detects modern firefox" do
287316 @browser.ua = $ua["FIREFOX_MODERN"]
288317
318 assert_equal :firefox, @browser.id
289319 assert_equal "Firefox", @browser.name
290320 assert @browser.firefox?
291321 assert @browser.modern?
296326 it "detects firefox android tablet" do
297327 @browser.ua = $ua["FIREFOX_TABLET"]
298328
299 assert_equal "Android", @browser.name
329 assert_equal :firefox, @browser.id
330 assert_equal "Firefox", @browser.name
300331 assert @browser.firefox?
301332 assert @browser.modern?
302333 assert @browser.tablet?
623654 assert @browser.windows?
624655 end
625656
657 it "detects windows_xp" do
658 @browser.ua = $ua["WINDOWS_XP"]
659
660 assert @browser.windows?
661 assert @browser.windows_xp?
662 end
663
664 it "detects windows_vista" do
665 @browser.ua = $ua["WINDOWS_VISTA"]
666
667 assert @browser.windows?
668 assert @browser.windows_vista?
669 end
670
671 it "detects windows7" do
672 @browser.ua = $ua["WINDOWS7"]
673
674 assert @browser.windows?
675 assert @browser.windows7?
676 end
677
626678 it "detects windows8" do
627679 @browser.ua = $ua["WINDOWS8"]
628680
629681 assert @browser.windows?
630682 assert @browser.windows8?
683 refute @browser.windows8_1?
631684 end
632685
633686 it "detects windows8.1" do
635688
636689 assert @browser.windows?
637690 assert @browser.windows8?
691 assert @browser.windows8_1?
638692 end
639693
640694 it "detects linux platform" do
746800 it "detects windows x64" do
747801 @browser.ua = $ua["IE10_X64_WINX64"]
748802 assert @browser.windows_x64?
803 refute @browser.windows_wow64?
804 assert @browser.windows_x64_inclusive?
805 end
806
807 it "detects windows wow64" do
808 @browser.ua = $ua["WINDOWS_WOW64"]
809 refute @browser.windows_x64?
810 assert @browser.windows_wow64?
811 assert @browser.windows_x64_inclusive?
749812 end
750813
751814 it "detects ie11 touch desktop pc" do
763826 assert_equal "11", @browser.version
764827 end
765828
829 it "detects Microsoft Edge" do
830 @browser.ua = $ua["MS_EDGE"]
831
832 assert_equal :edge, @browser.id
833 assert_equal "Microsoft Edge", @browser.name
834 assert_equal "12.0", @browser.full_version
835 assert_equal "12", @browser.version
836 assert @browser.windows10?
837 assert @browser.edge?
838 assert @browser.modern?
839 refute @browser.webkit?
840 refute @browser.chrome?
841 refute @browser.safari?
842 refute @browser.mobile?
843 end
844
845 it "detects Microsoft Edge in compatibility view" do
846 @browser.ua = $ua["MS_EDGE_COMPAT"]
847
848 assert_equal :edge, @browser.id
849 assert_equal "Microsoft Edge", @browser.name
850 assert_equal "12.0", @browser.full_version
851 assert_equal "12", @browser.version
852 assert_equal "7.0", @browser.msie_full_version
853 assert_equal "7", @browser.msie_version
854 assert @browser.edge?
855 assert @browser.compatibility_view?
856 refute @browser.modern?
857 refute @browser.webkit?
858 refute @browser.chrome?
859 refute @browser.safari?
860 refute @browser.mobile?
861 end
862
863 it "detects Microsoft Edge Mobile" do
864 @browser.ua = $ua["MS_EDGE_MOBILE"]
865
866 assert_equal :edge, @browser.id
867 assert_equal "Microsoft Edge", @browser.name
868 assert_equal "12.0", @browser.full_version
869 assert_equal "12", @browser.version
870 refute @browser.windows10?
871 assert @browser.windows_phone?
872 assert @browser.edge?
873 assert @browser.modern?
874 assert @browser.mobile?
875 refute @browser.webkit?
876 refute @browser.chrome?
877 refute @browser.safari?
878 end
879
880 it "detects IE without Trident" do
881 @browser.ua = $ua["IE_WITHOUT_TRIDENT"]
882
883 assert_equal :ie, @browser.id
884 assert_equal "Internet Explorer", @browser.name
885 assert_equal "0.0", @browser.msie_full_version
886 assert_equal "0", @browser.msie_version
887 assert_equal "0.0", @browser.full_version
888 assert_equal "0", @browser.version
889 refute @browser.windows10?
890 refute @browser.windows_phone?
891 refute @browser.edge?
892 refute @browser.modern?
893 refute @browser.mobile?
894 refute @browser.webkit?
895 refute @browser.chrome?
896 refute @browser.safari?
897 end
898
899 it "detects Daumoa" do
900 @browser.ua = $ua["DAUMOA"]
901
902 assert_equal :ie, @browser.id
903 assert_equal "Internet Explorer", @browser.name
904 assert_equal "0.0", @browser.msie_full_version
905 assert_equal "0", @browser.msie_version
906 assert_equal "0.0", @browser.full_version
907 assert_equal "0", @browser.version
908 assert @browser.ie?
909 refute @browser.windows10?
910 refute @browser.windows_phone?
911 refute @browser.edge?
912 refute @browser.modern?
913 refute @browser.mobile?
914 refute @browser.webkit?
915 refute @browser.chrome?
916 refute @browser.safari?
917 end
918
766919 it "detects kindle monochrome" do
767920 @browser.ua = $ua["KINDLE"]
768921
8691022
8701023 it "detects bots" do
8711024 %w[
1025 APPLE_BOT
8721026 DOT_BOT
8731027 FACEBOOK_BOT
8741028 GOOGLE_BOT
8751029 LINKDEXBOT
8761030 LOAD_TIME_BOT
8771031 MAIL_RU
1032 MEGAINDEX_RU
8781033 MSN_BOT
1034 QUERYSEEKER
8791035 SCRAPY
8801036 YANDEX_DIRECT
8811037 YANDEX_METRIKA
8861042
8871043 @browser.ua = $ua["CHROME"]
8881044 refute @browser.bot?
1045 end
1046
1047 it "detects Google Page Speed as a bot" do
1048 @browser.ua = $ua["GOOGLE_PAGE_SPEED_INSIGHTS"]
1049 assert @browser.bot?
8891050 end
8901051
8911052 it "doesn't consider empty UA as bot" do
9511112 end
9521113 end
9531114
1115 it "detects Google Structured Data Testing Tool as a bot" do
1116 @browser.ua = $ua["GOOGLE_STRUCTURED_DATA_TESTING_TOOL"]
1117
1118 assert @browser.bot?, "Google Structured Data Testing Tool should be a bot"
1119 end
1120
9541121 it "knows a supported browser" do
9551122 @browser.ua = "Chrome"
9561123 assert @browser.known?
00 ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
11 require "bundler/setup"
22 require "minitest/autorun"
3 require "minitest/unit"
3 require "minitest/utils"
44 require "browser"
55 require "yaml"
66
00 ADOBE_AIR: 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; de) AppleWebKit/533.19.4 (KHTML, like Gecko) AdobeAIR/13.0'
11 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'
22 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'
3 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)'
34 ASK: 'Mozilla/2.0 (compatible; Ask Jeeves/Teoma; +http://sp.ask.com/docs/about/tech_crawling.html)'
45 BAIDU: 'Baiduspider+(+http://www.baidu.com/search/spider.htm)'
56 BINGBOT: 'Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)'
1920 FIREFOX_MODERN: 'Mozilla/5.0 (X11; Ubuntu; Linux armv7l; rv:17.0) Gecko/20100101 Firefox/17.0'
2021 FIREFOX_TABLET: 'Mozilla/5.0 (Android; Tablet; rv:14.0) Gecko/14.0 Firefox/14.0'
2122 GOOGLE_BOT: 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
23 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'
24 GOOGLE_STRUCTURED_DATA_TESTING_TOOL: 'Mozilla/5.0 (compatible; X11; Linux x86_64; Google-StructuredDataTestingTool; +http://www.google.com/webmasters/tools/richsnippets)'
25 DAUMOA: Mozilla/5.0 (compatible; MSIE or Firefox mutant; not on Windows server;) Daumoa 4.0
26 IE_WITHOUT_TRIDENT: Mozilla/4.0 (compatible; MSIE8.0; Windows NT 6.0) .NET CLR 2.0.50727)
2227 IE10: 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0; EIE10;ENUSMSN)'
2328 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)'
2429 IE10_X64_WINX64: 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; Trident/6.0)'
2530 IE11: 'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko'
2631 IE11_TOUCH_SCREEN: 'Mozilla/5.0 (Windows NT 6.3; Win64; x64; Trident/7.0; Touch; rv:11.0) like Gecko'
32 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)'
2733 IE6: 'Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)'
2834 IE7: 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)'
2935 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)'
3036 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)'
3137 IE9: 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)'
3238 IE9_COMPAT: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/5.0)'
39 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'
40 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)'
41 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'
3342 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'
3443 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'
3544 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'
4453 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'
4554 LINKDEXBOT: 'Mozilla/5.0 (compatible; linkdexbot/2.0; +http://www.linkdex.com/bots/)'
4655 LOAD_TIME_BOT: 'Mozilla/5.0 (compatible; LoadTimeBot/0.9; +http://www.loadtime.net/bot.html)'
56 LUMIA800: 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; XBLWP7; ZuneWP7'
4757 MAIL_RU: 'Mozilla/5.0 (compatible; Linux x86_64; Mail.RU_Bot/2.0; +http://go.mail.ru/help/robots)'
58 MEGAINDEX_RU: 'Mozilla/5.0 (compatible; MegaIndex.ru/2.0; +https://www.megaindex.ru/?tab=linkAnalyze)'
4859 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'
4960 MSN_BOT: 'msnbot-media/1.1 (+http://search.msn.com/msnbot.htm)'
5061 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'
6273 PSP: 'Mozilla/4.0 (PSP (PlayStation Portable); 2.00)'
6374 PSP_VITA: 'Mozilla/5.0 (Playstation Vita 1.61) AppleWebKit/531.22.8 (KHTML, like Gecko) Silk/3.2'
6475 QUICKTIME: 'QuickTime/7.6.8 (qtver=7.6.8;os=Windows NT 5.1Service Pack 3)'
76 QUERYSEEKER: 'QuerySeekerSpider ( http://queryseeker.com/bot.html )'
6577 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'
6678 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'
6779 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'
7183 SMART_TV: 'Mozilla/5.0 (SmartHub; SMART-TV; U; Linux/SmartTV) AppleWebKit/531.2+ (KHTML, like Gecko) WebBrowser/1.0 SmartTV Safari/531.2+'
7284 SURFACE: 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; ARM; Trident/6.0; Touch)'
7385 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'
86 WINDOWS_XP: 'Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; FDM; .NET CLR 1.1.4322)'
87 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)'
88 WINDOWS7: 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0) chromeframe/10.0.648.205'
7489 WINDOWS81: 'Mozilla/5.0 (IE 11.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C; rv:11.0) like Gecko'
7590 WINDOWS8: 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)'
91 WINDOWS_WOW64: "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko"
7692 WINDOWS_MOBILE: 'Mozilla/4.0 (compatible; MSIE 6.0; Windows CE; IEMobile 6.12)'
7793 WINDOWS_PHONE8: 'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920)'
7894 WINDOWS_PHONE: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; DELL; Venue Pro)'