├── .gitignore ├── lib ├── useragent.rb ├── user_agent │ ├── comparable.rb │ ├── browsers │ │ ├── edge.rb │ │ ├── libavformat.rb │ │ ├── wechat_browser.rb │ │ ├── apple_core_media.rb │ │ ├── gecko.rb │ │ ├── vivaldi.rb │ │ ├── internet_explorer.rb │ │ ├── chrome.rb │ │ ├── opera.rb │ │ ├── itunes.rb │ │ ├── playstation.rb │ │ ├── podcast_addict.rb │ │ ├── base.rb │ │ ├── webkit.rb │ │ └── windows_media_player.rb │ ├── browsers.rb │ ├── operating_systems.rb │ └── version.rb └── user_agent.rb ├── Gemfile ├── Rakefile ├── spec ├── browsers │ ├── chrome_lighthouse_user_agent_spec.rb │ ├── libavformat_user_agent_spec.rb │ ├── edge_user_agent_spec.rb │ ├── vivaldi_user_agent_spec.rb │ ├── bot_user_agent_spec.rb │ ├── iron_user_agent_spec.rb │ ├── wechat_browser_user_agent_spec.rb │ ├── playstation_user_agent_spec.rb │ ├── apple_core_media_user_agent_spec.rb │ ├── podcast_addict_user_agent_spec.rb │ ├── other_user_agent_spec.rb │ ├── itunes_user_agent_spec.rb │ ├── opera_user_agent_spec.rb │ ├── chrome_user_agent_spec.rb │ ├── windows_media_player_user_agent_spec.rb │ ├── internet_explorer_user_agent_spec.rb │ ├── gecko_user_agent_spec.rb │ └── webkit_user_agent_spec.rb └── user_agent_spec.rb ├── useragent.gemspec ├── .github └── workflows │ └── test.yml ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | -------------------------------------------------------------------------------- /lib/useragent.rb: -------------------------------------------------------------------------------- 1 | require 'user_agent' 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gemspec 3 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler' 2 | require 'rspec/core/rake_task' 3 | 4 | Bundler::GemHelper.install_tasks 5 | 6 | RSpec::Core::RakeTask.new do |t| 7 | t.ruby_opts = ["-w"] 8 | end 9 | 10 | task :default => :spec 11 | task :release => :spec 12 | -------------------------------------------------------------------------------- /spec/browsers/chrome_lighthouse_user_agent_spec.rb: -------------------------------------------------------------------------------- 1 | require 'user_agent' 2 | 3 | describe "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4590.2 Safari/537.36 Chrome-Lighthouse" do 4 | before do 5 | @useragent = UserAgent.parse("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4590.2 Safari/537.36 Chrome-Lighthouse") 6 | end 7 | 8 | it { expect(@useragent).to be_bot } 9 | end 10 | -------------------------------------------------------------------------------- /useragent.gemspec: -------------------------------------------------------------------------------- 1 | Gem::Specification.new do |s| 2 | s.name = "useragent" 3 | s.version = "0.16.11" 4 | 5 | s.homepage = "https://github.com/gshutler/useragent" 6 | s.summary = "HTTP User Agent parser" 7 | s.description = "HTTP User Agent parser" 8 | 9 | s.files = Dir["LICENSE", "README.md", "lib/**/*.rb"] 10 | 11 | s.add_development_dependency "rake", "~> 13.0" 12 | s.add_development_dependency "rspec", "~> 3.0" 13 | 14 | s.authors = ["Joshua Peek", "Garry Shutler"] 15 | s.email = "garry@robustsoftware.co.uk" 16 | s.license = "MIT" 17 | end 18 | -------------------------------------------------------------------------------- /lib/user_agent/comparable.rb: -------------------------------------------------------------------------------- 1 | class UserAgent 2 | # A custom Comparable module that will always return false 3 | # if the <=> returns false 4 | module Comparable 5 | def <(other) 6 | (c = self <=> other) ? c == -1 : false 7 | end 8 | 9 | def <=(other) 10 | (c = self <=> other) ? c == -1 || c == 0 : false 11 | end 12 | 13 | def ==(other) 14 | (c = self <=> other) ? c == 0 : false 15 | end 16 | 17 | def >(other) 18 | (c = self <=> other) ? c == 1 : false 19 | end 20 | 21 | def >=(other) 22 | (c = self <=> other) ? c == 1 || c == 0 : false 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Tests 3 | on: [ push, pull_request ] 4 | jobs: 5 | test: 6 | name: Test (Ruby ${{ matrix.ruby }}) 7 | runs-on: ubuntu-${{ matrix.ubuntu }} 8 | strategy: 9 | fail-fast: false 10 | matrix: 11 | ruby: [ '3.3', '3.2', '3.1', '3.0', '2.7', '2.6', '2.5', '2.4', '2.3', 'jruby-9.4' ] 12 | ubuntu: [ 'latest' ] 13 | include: 14 | - { ruby: '2.2', ubuntu: '20.04' } 15 | steps: 16 | - uses: actions/checkout@v4 17 | - uses: ruby/setup-ruby@v1 18 | with: 19 | ruby-version: ${{ matrix.ruby }} 20 | bundler-cache: true 21 | - run: bundle exec rake 22 | -------------------------------------------------------------------------------- /lib/user_agent/browsers/edge.rb: -------------------------------------------------------------------------------- 1 | class UserAgent 2 | module Browsers 3 | class Edge < Base 4 | OS_REGEXP = /Windows NT [\d\.]+|Windows Phone (OS )?[\d\.]+/ 5 | 6 | def self.extend?(agent) 7 | agent.last && agent.last.product == "Edge" 8 | end 9 | 10 | def browser 11 | "Edge" 12 | end 13 | 14 | def version 15 | last.version 16 | end 17 | 18 | def platform 19 | "Windows" 20 | end 21 | 22 | def os 23 | OperatingSystems.normalize_os(os_comment) 24 | end 25 | 26 | private 27 | 28 | def os_comment 29 | detect_comment_match(OS_REGEXP).to_s 30 | end 31 | end 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lib/user_agent/browsers/libavformat.rb: -------------------------------------------------------------------------------- 1 | class UserAgent 2 | module Browsers 3 | # The user agent utilized by ffmpeg or other projects utilizing libavformat 4 | class Libavformat < Base 5 | def self.extend?(agent) 6 | agent.detect do |useragent| 7 | useragent.product == "Lavf" || (useragent.product == "NSPlayer" && agent.version == "4.1.0.3856") 8 | end 9 | end 10 | 11 | # @return ["libavformat"] To make it easy to pick it out, all of the UAs that Lavf uses have this browser. 12 | def browser 13 | "libavformat" 14 | end 15 | 16 | # @return [nil, Version] If the product is NSPlayer, we don't have a version 17 | def version 18 | super unless detect_product("NSPlayer") 19 | end 20 | 21 | # @return [nil] Lavf doesn't return us anything here 22 | def os 23 | nil 24 | end 25 | 26 | # @return [nil] Lavf doesn't return us anything here 27 | def platform 28 | nil 29 | end 30 | end 31 | end 32 | end -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Garry Shutler 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /spec/browsers/libavformat_user_agent_spec.rb: -------------------------------------------------------------------------------- 1 | require 'user_agent' 2 | 3 | shared_examples "libavformat" do 4 | it "should return 'libavformat' as its browser" do 5 | expect(@useragent.browser).to eq("libavformat") 6 | end 7 | 8 | it "should return nil as its OS" do 9 | expect(@useragent.os).to be_nil 10 | end 11 | 12 | it "should return nil as its platform" do 13 | expect(@useragent.platform).to be_nil 14 | end 15 | end 16 | 17 | shared_examples "libavformat has version number" do |version| 18 | it "should return '#{version}' as its version" do 19 | expect(@useragent.version).to eq(version) 20 | end 21 | end 22 | 23 | describe "UserAgent: Lavf/56.4.101" do 24 | before do 25 | @useragent = UserAgent.parse("Lavf/56.4.101") 26 | end 27 | 28 | it_behaves_like "libavformat" 29 | it_behaves_like "libavformat has version number", "56.4.101" 30 | end 31 | 32 | describe "UserAgent: NSPlayer/4.1.0.3856" do 33 | before do 34 | @useragent = UserAgent.parse("NSPlayer/4.1.0.3856") 35 | end 36 | 37 | it_behaves_like "libavformat" 38 | it_behaves_like "libavformat has version number", nil 39 | end 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UserAgent 2 | 3 | [![Build Status](https://github.com/gshutler/useragent/actions/workflows/test.yml/badge.svg)](https://github.com/gshutler/useragent/actions/workflows/test.yml) 4 | [![Gem Version](https://badge.fury.io/rb/useragent.svg)](http://badge.fury.io/rb/useragent) 5 | 6 | UserAgent is a Ruby library that parses and compares HTTP User Agents. 7 | 8 | ## Installation 9 | 10 | gem install useragent 11 | 12 | ### Examples 13 | 14 | #### Reporting 15 | 16 | ```ruby 17 | string = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5' 18 | user_agent = UserAgent.parse(string) 19 | user_agent.browser 20 | # => 'Chrome' 21 | user_agent.version 22 | # => '19.0.1084.56' 23 | user_agent.platform 24 | # => 'Macintosh' 25 | ``` 26 | 27 | #### Comparison 28 | 29 | ```ruby 30 | Browser = Struct.new(:browser, :version) 31 | 32 | SupportedBrowsers = [ 33 | Browser.new("Safari", "3.1.1"), 34 | Browser.new("Firefox", "2.0.0.14"), 35 | Browser.new("Internet Explorer", "7.0") 36 | ] 37 | 38 | user_agent = UserAgent.parse(request.user_agent) 39 | SupportedBrowsers.detect { |browser| user_agent >= browser } 40 | ``` 41 | 42 | Copyright (c) 2015-2019 Garry Shutler, released under the MIT license 43 | -------------------------------------------------------------------------------- /lib/user_agent/browsers/wechat_browser.rb: -------------------------------------------------------------------------------- 1 | class UserAgent 2 | module Browsers 3 | class WechatBrowser < Base 4 | def self.extend?(agent) 5 | agent.detect { |useragent| useragent.product =~ /MicroMessenger/i } 6 | end 7 | 8 | def browser 9 | 'Wechat Browser' 10 | end 11 | 12 | def version 13 | micro_messenger = detect_product("MicroMessenger") 14 | Version.new(micro_messenger.version) 15 | end 16 | 17 | def platform 18 | return unless application && application.comment 19 | 20 | if application.comment[0] =~ /iPhone/ 21 | 'iPhone' 22 | elsif application.comment.any? { |c| c =~ /Android/ } 23 | 'Android' 24 | else 25 | application.comment[0] 26 | end 27 | end 28 | 29 | def os 30 | return unless application && application.comment 31 | 32 | if application.comment[0] =~ /Windows NT/ 33 | OperatingSystems.normalize_os(application.comment[0]) 34 | elsif application.comment[2].nil? 35 | OperatingSystems.normalize_os(application.comment[1]) 36 | elsif application.comment[1] =~ /Android/ 37 | OperatingSystems.normalize_os(application.comment[1]) 38 | else 39 | OperatingSystems.normalize_os(application.comment[2]) 40 | end 41 | end 42 | end 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /lib/user_agent/browsers.rb: -------------------------------------------------------------------------------- 1 | require 'user_agent/browsers/base' 2 | require 'user_agent/browsers/chrome' 3 | require 'user_agent/browsers/edge' 4 | require 'user_agent/browsers/gecko' 5 | require 'user_agent/browsers/internet_explorer' 6 | require 'user_agent/browsers/opera' 7 | require 'user_agent/browsers/webkit' 8 | require 'user_agent/browsers/wechat_browser' 9 | require 'user_agent/browsers/windows_media_player' 10 | require 'user_agent/browsers/itunes' 11 | require 'user_agent/browsers/apple_core_media' 12 | require 'user_agent/browsers/libavformat' 13 | require 'user_agent/browsers/playstation' 14 | require 'user_agent/browsers/podcast_addict' 15 | require 'user_agent/browsers/vivaldi' 16 | 17 | class UserAgent 18 | module Browsers 19 | Security = { 20 | "N" => :none, 21 | "U" => :strong, 22 | "I" => :weak 23 | }.freeze 24 | 25 | ALL = [ 26 | Edge, 27 | InternetExplorer, 28 | Opera, 29 | WechatBrowser, 30 | Vivaldi, 31 | Chrome, 32 | ITunes, 33 | PlayStation, 34 | PodcastAddict, 35 | Webkit, 36 | Gecko, 37 | WindowsMediaPlayer, 38 | AppleCoreMedia, 39 | Libavformat, 40 | ].freeze 41 | 42 | def self.all 43 | ALL 44 | end 45 | 46 | def self.extend(array) 47 | all.each do |extension| 48 | return extension.new(array) if extension.extend?(array) 49 | end 50 | array 51 | end 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /lib/user_agent/browsers/apple_core_media.rb: -------------------------------------------------------------------------------- 1 | class UserAgent 2 | module Browsers 3 | # CoreMedia is a framework on iOS and is used by various iOS apps to playback media. 4 | class AppleCoreMedia < Base 5 | def self.extend?(agent) 6 | agent.detect { |useragent| useragent.product == 'AppleCoreMedia' } 7 | end 8 | 9 | def browser 10 | "AppleCoreMedia" 11 | end 12 | 13 | def application 14 | self.reject { |agent| agent.comment.nil? || agent.comment.empty? }.first 15 | end 16 | 17 | def platform 18 | return unless application 19 | 20 | if application.comment[0] =~ /Windows/ 21 | 'Windows' 22 | else 23 | application.comment[0] 24 | end 25 | end 26 | 27 | def security 28 | Security[application.comment[1]] 29 | end 30 | 31 | def os 32 | return unless application 33 | 34 | if application.comment[0] =~ /Windows NT/ 35 | OperatingSystems.normalize_os(application.comment[0]) 36 | elsif application.comment[2].nil? 37 | OperatingSystems.normalize_os(application.comment[1]) 38 | elsif application.comment[1] =~ /Android/ 39 | OperatingSystems.normalize_os(application.comment[1]) 40 | else 41 | OperatingSystems.normalize_os(application.comment[2]) 42 | end 43 | end 44 | 45 | def localization 46 | return unless application 47 | 48 | application.comment[3] 49 | end 50 | end 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /lib/user_agent/browsers/gecko.rb: -------------------------------------------------------------------------------- 1 | class UserAgent 2 | module Browsers 3 | class Gecko < Base 4 | def self.extend?(agent) 5 | agent.application && agent.application.product == "Mozilla" 6 | end 7 | 8 | GeckoBrowsers = %w( 9 | PaleMoon 10 | Firefox 11 | Camino 12 | Iceweasel 13 | Seamonkey 14 | ).freeze 15 | 16 | def browser 17 | GeckoBrowsers.detect { |browser| respond_to?(browser) } || super 18 | end 19 | 20 | def version 21 | v = send(browser).version 22 | v.nil? ? super : v 23 | end 24 | 25 | def platform 26 | if comment = application.comment 27 | if comment[0] == 'compatible' || comment[0] == 'Mobile' 28 | nil 29 | elsif /^Windows / =~ comment[0] 30 | 'Windows' 31 | else 32 | comment[0] 33 | end 34 | end 35 | end 36 | 37 | def security 38 | Security[application.comment[1]] || :strong 39 | end 40 | 41 | def os 42 | if comment = application.comment 43 | i = if comment[1] == 'U' 44 | 2 45 | elsif /^Windows / =~ comment[0] || /^Android/ =~ comment[0] 46 | 0 47 | elsif comment[0] == 'Mobile' 48 | nil 49 | else 50 | 1 51 | end 52 | 53 | return nil if i.nil? 54 | 55 | OperatingSystems.normalize_os(comment[i]) 56 | end 57 | end 58 | 59 | def localization 60 | if comment = application.comment 61 | comment[3] 62 | end 63 | end 64 | end 65 | end 66 | end 67 | -------------------------------------------------------------------------------- /spec/browsers/edge_user_agent_spec.rb: -------------------------------------------------------------------------------- 1 | require 'user_agent' 2 | 3 | shared_examples_for "Edge browser" do 4 | it "should return 'Edge' as its browser" do 5 | expect(@useragent.browser).to eq("Edge") 6 | end 7 | 8 | it "should return 'Windows' as its platform" do 9 | expect(@useragent.platform).to eq("Windows") 10 | end 11 | end 12 | 13 | describe "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240" do 14 | before do 15 | @useragent = UserAgent.parse("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240") 16 | end 17 | 18 | it_should_behave_like "Edge browser" 19 | 20 | it "should return '12.10240' as its version" do 21 | expect(@useragent.version).to eq("12.10240") 22 | end 23 | 24 | it "should return 'Windows 10' as its os" do 25 | expect(@useragent.os).to eq("Windows 10") 26 | end 27 | end 28 | 29 | describe "Mozilla/5.0 SHC; SHC-Unit-04973; SHC-HTS; SHC-KIOSK; SHC-MAC-0000 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586" do 30 | before do 31 | @useragent = UserAgent.parse("Mozilla/5.0 SHC; SHC-Unit-04973; SHC-HTS; SHC-KIOSK; SHC-MAC-0000 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586") 32 | end 33 | 34 | it_should_behave_like "Edge browser" 35 | 36 | it "should return '13.10586' as its version" do 37 | expect(@useragent.version).to eq("13.10586") 38 | end 39 | 40 | it "should return 'Windows 10' as its os" do 41 | expect(@useragent.os).to eq("Windows 10") 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /lib/user_agent/browsers/vivaldi.rb: -------------------------------------------------------------------------------- 1 | class UserAgent 2 | module Browsers 3 | class Vivaldi < Base 4 | def self.extend?(agent) 5 | agent.detect { |useragent| useragent.product == 'Vivaldi' } 6 | end 7 | 8 | def browser 9 | 'Vivaldi' 10 | end 11 | 12 | def build 13 | webkit.version 14 | end 15 | 16 | def version 17 | last.version 18 | end 19 | 20 | def application 21 | self.reject { |agent| agent.comment.nil? || agent.comment.empty? }.first 22 | end 23 | 24 | def platform 25 | return unless application 26 | 27 | if application.comment[0] =~ /Windows/ 28 | 'Windows' 29 | elsif application.comment.any? { |c| c =~ /CrOS/ } 30 | 'ChromeOS' 31 | elsif application.comment.any? { |c| c =~ /Android/ } 32 | 'Android' 33 | else 34 | application.comment[0] 35 | end 36 | end 37 | 38 | def webkit 39 | detect_product("AppleWebKit") 40 | end 41 | 42 | def os 43 | return unless application 44 | 45 | if application.comment[0] =~ /Windows NT/ 46 | OperatingSystems.normalize_os(application.comment[0]) 47 | elsif application.comment[2].nil? 48 | OperatingSystems.normalize_os(application.comment[1]) 49 | elsif application.comment[1] =~ /Android/ 50 | OperatingSystems.normalize_os(application.comment[1]) 51 | else 52 | OperatingSystems.normalize_os(application.comment[2]) 53 | end 54 | end 55 | 56 | def localization 57 | return unless application 58 | 59 | application.comment[3] 60 | end 61 | end 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /spec/browsers/vivaldi_user_agent_spec.rb: -------------------------------------------------------------------------------- 1 | require 'user_agent' 2 | 3 | shared_examples_for "Vivaldi browser" do 4 | it "should return 'Vivaldi' as its browser" do 5 | expect(@useragent.browser).to eq("Vivaldi") 6 | end 7 | end 8 | 9 | describe "UserAgent: 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36 Vivaldi/1.2.490.43'" do 10 | before do 11 | @useragent = UserAgent.parse("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36 Vivaldi/1.2.490.43") 12 | end 13 | 14 | it_should_behave_like "Vivaldi browser" 15 | 16 | it "should return '1.2.490.43' as its version" do 17 | expect(@useragent.version).to eq("1.2.490.43") 18 | end 19 | 20 | it "should return 'Windows' as its platform" do 21 | expect(@useragent.platform).to eq("Windows") 22 | end 23 | 24 | it "should return 'Windows 7' as its os" do 25 | expect(@useragent.os).to eq("Windows 7") 26 | end 27 | end 28 | 29 | describe "UserAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36 Vivaldi/1.2.490.43'" do 30 | before do 31 | @useragent = UserAgent.parse("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36 Vivaldi/1.2.490.43") 32 | end 33 | 34 | it_should_behave_like "Vivaldi browser" 35 | 36 | it "should return '1.2.490.43' as its version" do 37 | expect(@useragent.version).to eq("1.2.490.43") 38 | end 39 | 40 | it "should return 'X11' as its platform" do 41 | expect(@useragent.platform).to eq("X11") 42 | end 43 | 44 | it "should return 'Linux x86_64' as its os" do 45 | expect(@useragent.os).to eq("Linux x86_64") 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /lib/user_agent/operating_systems.rb: -------------------------------------------------------------------------------- 1 | class UserAgent 2 | module OperatingSystems 3 | IOS_VERSION_REGEX = /CPU (?:iPhone |iPod )?OS ([\d_]+) like Mac OS X/ 4 | 5 | Windows = { 6 | "Windows NT 10.0" => "Windows 10", 7 | "Windows NT 6.3" => "Windows 8.1", 8 | "Windows NT 6.2" => "Windows 8", 9 | "Windows NT 6.1" => "Windows 7", 10 | "Windows NT 6.0" => "Windows Vista", 11 | "Windows NT 5.2" => "Windows XP x64 Edition", 12 | "Windows NT 5.1" => "Windows XP", 13 | "Windows NT 5.01" => "Windows 2000, Service Pack 1 (SP1)", 14 | "Windows NT 5.0" => "Windows 2000", 15 | "Windows NT 4.0" => "Windows NT 4.0", 16 | "Windows 98" => "Windows 98", 17 | "Windows 95" => "Windows 95", 18 | "Windows CE" => "Windows CE" 19 | }.freeze 20 | 21 | def self.normalize_os(os) 22 | Windows[os] || normalize_mac_os_x(os) || normalize_ios(os) || normalize_chrome_os(os) || os 23 | end 24 | 25 | private 26 | def self.normalize_chrome_os(os) 27 | if os =~ /CrOS\s([^\s]+)\s(\d+(\.\d+)*)/ 28 | if $2.nil? 29 | "ChromeOS" 30 | else 31 | version = $2 32 | "ChromeOS #{version}" 33 | end 34 | end 35 | end 36 | 37 | def self.normalize_ios(os) 38 | if os =~ IOS_VERSION_REGEX 39 | if $1.nil? 40 | "iOS" 41 | else 42 | version = $1.tr('_', '.') 43 | "iOS #{version}" 44 | end 45 | end 46 | end 47 | 48 | def self.normalize_mac_os_x(os) 49 | if os =~ /(?:Intel|PPC) Mac OS X\s*([0-9_\.]+)?/ 50 | if $1.nil? 51 | "OS X" 52 | else 53 | version = $1.tr('_', '.') 54 | "OS X #{version}" 55 | end 56 | end 57 | end 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /spec/browsers/bot_user_agent_spec.rb: -------------------------------------------------------------------------------- 1 | require 'user_agent' 2 | 3 | describe "UserAgent: 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'" do 4 | before do 5 | @useragent = UserAgent.parse("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)") 6 | end 7 | 8 | it { expect(@useragent).to be_bot } 9 | end 10 | 11 | describe "UserAgent: 'Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)'" do 12 | before do 13 | @useragent = UserAgent.parse("Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)") 14 | end 15 | 16 | it { expect(@useragent).to be_bot } 17 | end 18 | 19 | describe "UserAgent: 'Twitterbot/1.0'" do 20 | before do 21 | @useragent = UserAgent.parse("Twitterbot/1.0") 22 | end 23 | 24 | it { expect(@useragent).to be_bot} 25 | end 26 | 27 | describe "UserAgent: Mozilla/5.0 (iPhone; CPU iPhone OS 8_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B411 Safari/600.1.4 (compatible; YandexMobileBot/3.0; +http://yandex.com/bots)" do 28 | before do 29 | @useragent = UserAgent.parse("Mozilla/5.0 (iPhone; CPU iPhone OS 8_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B411 Safari/600.1.4 (compatible; YandexMobileBot/3.0; +http://yandex.com/bots)") 30 | end 31 | 32 | it { expect(@useragent).to be_bot} 33 | end 34 | 35 | describe "UserAgent: Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" do 36 | before do 37 | @useragent = UserAgent.parse("Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)") 38 | end 39 | 40 | it { expect(@useragent).to be_bot} 41 | end 42 | -------------------------------------------------------------------------------- /spec/browsers/iron_user_agent_spec.rb: -------------------------------------------------------------------------------- 1 | require 'user_agent' 2 | 3 | shared_examples_for "Iron browser" do 4 | it "should return 'Iron' as its browser" do 5 | expect(@useragent.browser).to eq("Iron") 6 | end 7 | 8 | it "should return a Version object for version" do 9 | expect(@useragent.version).to be_a(UserAgent::Version) 10 | end 11 | end 12 | 13 | # http://www.useragentstring.com/Iron22.0.2150.0_id_19368.php 14 | describe "UserAgent: 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1250.0 Iron/22.0.2150.0 Safari/537.4'" do 15 | before do 16 | @useragent = UserAgent.parse("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1250.0 Iron/22.0.2150.0 Safari/537.4") 17 | end 18 | 19 | it_should_behave_like "Iron browser" 20 | 21 | it "should return '22.0.1250.0' as its version" do 22 | expect(@useragent.version).to eq("22.0.1250.0") 23 | end 24 | 25 | it "should return 'Windows' as its platform" do 26 | expect(@useragent.platform).to eq("Windows") 27 | end 28 | 29 | it "should return 'Windows 7' as its os" do 30 | expect(@useragent.os).to eq("Windows 7") 31 | end 32 | end 33 | 34 | # http://www.useragentstring.com/Iron21.0.1200.0_id_19375.php 35 | describe "UserAgent: 'Mozilla/5.0 (X11; U; Linux amd64) Iron/21.0.1200.0 Chrome/21.0.1200.0 Safari/537.1'" do 36 | before do 37 | @useragent = UserAgent.parse("Mozilla/5.0 (X11; U; Linux amd64) Iron/21.0.1200.0 Chrome/21.0.1200.0 Safari/537.1") 38 | end 39 | 40 | it_should_behave_like "Iron browser" 41 | 42 | it "should return '21.0.1200.0' as its version" do 43 | expect(@useragent.version).to eq("21.0.1200.0") 44 | end 45 | 46 | it "should return 'X11' as its platform" do 47 | expect(@useragent.platform).to eq("X11") 48 | end 49 | 50 | it "should return 'Linux amd' as its os" do 51 | expect(@useragent.os).to eq("Linux amd64") 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /lib/user_agent/browsers/internet_explorer.rb: -------------------------------------------------------------------------------- 1 | class UserAgent 2 | module Browsers 3 | class InternetExplorer < Base 4 | TRIDENT_ENGINES = { 5 | "Trident/8.0" => "11.0", 6 | "Trident/7.0" => "11.0", 7 | "Trident/6.0" => "10.0", 8 | "Trident/5.0" => "9.0", 9 | "Trident/4.0" => "8.0", 10 | }.freeze 11 | 12 | def self.extend?(agent) 13 | agent.application && 14 | agent.application.comment && 15 | (agent.application.comment[1] =~ /MSIE/ || 16 | agent.application.comment.join('; ') =~ /Trident.+rv:/) 17 | end 18 | 19 | def browser 20 | "Internet Explorer" 21 | end 22 | 23 | def version 24 | str = application.comment.join('; ')[/(MSIE\s|rv:)([\d\.]+)/, 2] 25 | Version.new(str) 26 | end 27 | 28 | def trident_version 29 | if trident = application.comment.detect { |c| c['Trident/'] } 30 | trident_version = TRIDENT_ENGINES.fetch(trident, trident) 31 | Version.new(trident_version) 32 | end 33 | end 34 | 35 | def real_version 36 | [trident_version, version].sort.last 37 | end 38 | 39 | def compatibility_view? 40 | trident_version && version < real_version 41 | end 42 | 43 | # Before version 4.0, Chrome Frame declared itself (unversioned) in a comment; 44 | # as of 4.0 it can declare itself versioned in a comment 45 | # or as a separate product with a version 46 | def chromeframe 47 | cf = application.comment.include?("chromeframe") || detect_product("chromeframe") 48 | return cf if cf 49 | cf_comment = application.comment.detect { |c| c['chromeframe/'] } 50 | cf_comment ? UserAgent.new(*cf_comment.split('/', 2)) : nil 51 | end 52 | 53 | def platform 54 | "Windows" 55 | end 56 | 57 | def os 58 | OperatingSystems.normalize_os(application.comment.join('; ').match(/Windows NT [\d\.]+|Windows Phone (OS )?[\d\.]+/).to_s) 59 | end 60 | end 61 | end 62 | end 63 | -------------------------------------------------------------------------------- /lib/user_agent/browsers/chrome.rb: -------------------------------------------------------------------------------- 1 | class UserAgent 2 | module Browsers 3 | class Chrome < Base 4 | def self.extend?(agent) 5 | agent.detect { |useragent| 6 | %w(Chrome CriOS).include?(useragent.product) 7 | } 8 | end 9 | 10 | ChromeBrowsers = %w( 11 | Iron 12 | ).freeze 13 | 14 | def browser 15 | ChromeBrowsers.detect { |browser| respond_to?(browser) } || 'Chrome' 16 | end 17 | 18 | def build 19 | webkit.version 20 | end 21 | 22 | # Prior to Safari 3, the user agent did not include a version number 23 | def version 24 | str = if detect_product("CriOs") 25 | crios.version 26 | else 27 | chrome.version 28 | end 29 | 30 | Version.new(str) 31 | end 32 | 33 | def application 34 | self.reject { |agent| agent.comment.nil? || agent.comment.empty? }.first 35 | end 36 | 37 | def platform 38 | return unless application 39 | 40 | if application.comment[0] =~ /Windows/ 41 | 'Windows' 42 | elsif application.comment.any? { |c| c =~ /CrOS/ } 43 | 'ChromeOS' 44 | elsif application.comment.any? { |c| c =~ /Android/ } 45 | 'Android' 46 | else 47 | application.comment[0] 48 | end 49 | end 50 | 51 | def webkit 52 | detect { |useragent| useragent.product == "AppleWebKit" } 53 | end 54 | 55 | def os 56 | return unless application 57 | 58 | if application.comment[0] =~ /Windows NT/ 59 | OperatingSystems.normalize_os(application.comment[0]) 60 | elsif application.comment[2].nil? 61 | OperatingSystems.normalize_os(application.comment[1]) 62 | elsif application.comment[1] =~ /Android/ 63 | OperatingSystems.normalize_os(application.comment[1]) 64 | else 65 | OperatingSystems.normalize_os(application.comment[2]) 66 | end 67 | end 68 | 69 | def localization 70 | return unless application 71 | 72 | application.comment[3] 73 | end 74 | end 75 | end 76 | end 77 | -------------------------------------------------------------------------------- /lib/user_agent/browsers/opera.rb: -------------------------------------------------------------------------------- 1 | class UserAgent 2 | module Browsers 3 | class Opera < Base 4 | def self.extend?(agent) 5 | (agent.first && agent.first.product == 'Opera') || 6 | (agent.application && agent.application.product == 'Opera') || 7 | (agent.last && agent.last.product == 'OPR') 8 | end 9 | 10 | def browser 11 | 'Opera' 12 | end 13 | 14 | def version 15 | if mini? 16 | Version.new(application.comment.detect{|c| c =~ /Opera Mini/}[/Opera Mini\/([\d\.]+)/, 1]) rescue Version.new 17 | elsif product = detect_product('Version') 18 | Version.new(product.version) 19 | elsif product = detect_product('OPR') 20 | Version.new(product.version) 21 | else 22 | super 23 | end 24 | end 25 | 26 | def platform 27 | return unless application.comment 28 | 29 | if application.comment[0] =~ /Windows/ 30 | "Windows" 31 | else 32 | application.comment[0] 33 | end 34 | end 35 | 36 | def security 37 | if application.comment.nil? 38 | :strong 39 | elsif macintosh? 40 | Security[application.comment[2]] 41 | elsif mini? 42 | Security[application.comment[-2]] 43 | else 44 | Security[application.comment[1]] 45 | end 46 | end 47 | 48 | def mobile? 49 | mini? 50 | end 51 | 52 | def os 53 | return unless application.comment 54 | 55 | if application.comment[0] =~ /Windows/ 56 | OperatingSystems.normalize_os(application.comment[0]) 57 | else 58 | application.comment[1] 59 | end 60 | end 61 | 62 | def localization 63 | return unless application.comment 64 | 65 | if macintosh? 66 | application.comment[3] 67 | else 68 | application.comment[2] 69 | end 70 | end 71 | 72 | private 73 | def mini? 74 | /Opera Mini/ === application 75 | end 76 | 77 | def macintosh? 78 | platform == 'Macintosh' 79 | end 80 | end 81 | end 82 | end 83 | -------------------------------------------------------------------------------- /lib/user_agent.rb: -------------------------------------------------------------------------------- 1 | require 'user_agent/comparable' 2 | require 'user_agent/browsers' 3 | require 'user_agent/operating_systems' 4 | require 'user_agent/version' 5 | 6 | class UserAgent 7 | # http://www.texsoft.it/index.php?m=sw.php.useragent 8 | MATCHER = %r{ 9 | ^['"]* # Possible opening quote(s) 10 | ([^/\s]+) # Product 11 | /?([^\s,]*) # Version 12 | (\s\(([^\)]*)\)|,gzip\(gfe\))? # Comment 13 | }x.freeze 14 | 15 | DEFAULT_USER_AGENT = "Mozilla/4.0 (compatible)" 16 | 17 | def self.parse(string) 18 | if string.nil? || string.strip == "" 19 | string = DEFAULT_USER_AGENT 20 | end 21 | 22 | agents = Browsers::Base.new 23 | while m = string.to_s.match(MATCHER) 24 | agents << new(m[1], m[2], m[4]) 25 | string = string[m[0].length..-1].strip 26 | end 27 | Browsers.extend(agents) 28 | end 29 | 30 | attr_reader :product, :version, :comment 31 | 32 | def initialize(product, version = nil, comment = nil) 33 | if product 34 | @product = product 35 | else 36 | raise ArgumentError, "expected a value for product" 37 | end 38 | 39 | if version && !version.empty? 40 | @version = Version.new(version) 41 | else 42 | @version = Version.new 43 | end 44 | 45 | if comment.respond_to?(:split) 46 | @comment = comment.split("; ") 47 | else 48 | @comment = comment 49 | end 50 | end 51 | 52 | include Comparable 53 | 54 | def detect_comment(&block) 55 | comment && comment.detect(&block) 56 | end 57 | 58 | # Any comparison between two user agents with different products will 59 | # always return false. 60 | def <=>(other) 61 | if @product == other.product 62 | @version <=> other.version 63 | else 64 | false 65 | end 66 | end 67 | 68 | def eql?(other) 69 | @product == other.product && 70 | @version == other.version && 71 | @comment == other.comment 72 | end 73 | 74 | def to_s 75 | to_str 76 | end 77 | 78 | def to_str 79 | if @product && !@version.nil? && @comment 80 | "#{@product}/#{@version} (#{@comment.join("; ")})" 81 | elsif @product && !@version.nil? 82 | "#{@product}/#{@version}" 83 | elsif @product && @comment 84 | "#{@product} (#{@comment.join("; ")})" 85 | else 86 | @product 87 | end 88 | end 89 | end 90 | -------------------------------------------------------------------------------- /lib/user_agent/browsers/itunes.rb: -------------------------------------------------------------------------------- 1 | class UserAgent 2 | module Browsers 3 | # The user agent for iTunes 4 | # 5 | # Some user agents: 6 | # iTunes/10.6.1 (Macintosh; Intel Mac OS X 10.7.3) AppleWebKit/534.53.11 7 | # iTunes/12.0.1 (Macintosh; OS X 10.10) AppleWebKit/0600.1.25 8 | # iTunes/11.1.5 (Windows; Microsoft Windows 7 x64 Business Edition Service Pack 1 (Build 7601)) AppleWebKit/537.60.15 9 | # iTunes/12.0.1 (Windows; Microsoft Windows 8 x64 Home Premium Edition (Build 9200)) AppleWebKit/7600.1017.0.24 10 | # iTunes/12.0.1 (Macintosh; OS X 10.10.1) AppleWebKit/0600.1.25 11 | class ITunes < Webkit 12 | def self.extend?(agent) 13 | agent.detect { |useragent| useragent.product == "iTunes" } 14 | end 15 | 16 | # @return ["iTunes"] Always return iTunes as the browser 17 | def browser 18 | "iTunes" 19 | end 20 | 21 | # @return [Version] The version of iTunes in use 22 | def version 23 | self.iTunes.version 24 | end 25 | 26 | # @return [nil] nil - not included in the user agent 27 | def security 28 | nil 29 | end 30 | 31 | # @return [nil, Version] The WebKit version in use if we have it 32 | def build 33 | super if webkit 34 | end 35 | 36 | # Parses the operating system in use. 37 | # 38 | # @return [String] The operating system 39 | def os 40 | full_os = self.full_os 41 | 42 | if application && application.comment[0] =~ /Windows/ 43 | if full_os =~ /Windows 8\.1/ 44 | "Windows 8.1" 45 | elsif full_os =~ /Windows 8/ 46 | "Windows 8" 47 | elsif full_os =~ /Windows 7/ 48 | "Windows 7" 49 | elsif full_os =~ /Windows Vista/ 50 | "Windows Vista" 51 | elsif full_os =~ /Windows XP/ 52 | "Windows XP" 53 | else 54 | "Windows" 55 | end 56 | else 57 | super 58 | end 59 | end 60 | 61 | # Parses the operating system in use. 62 | # 63 | # @return [String] The operating system 64 | def full_os 65 | if application && application.comment && application.comment.length > 1 66 | full_os = application.comment[1] 67 | 68 | full_os = "#{full_os})" if full_os =~ /\(Build [0-9][0-9][0-9][0-9]\z/ # The regex chops the ) off :( 69 | 70 | full_os 71 | end 72 | end 73 | end 74 | end 75 | end 76 | -------------------------------------------------------------------------------- /lib/user_agent/version.rb: -------------------------------------------------------------------------------- 1 | class UserAgent 2 | class Version 3 | include ::Comparable 4 | 5 | def self.new(obj = nil) 6 | case obj 7 | when Version 8 | obj 9 | when String 10 | super 11 | when NilClass 12 | super("") 13 | else 14 | raise ArgumentError, "invalid value for Version: #{obj.inspect}" 15 | end 16 | end 17 | 18 | def initialize(str) 19 | @str = str 20 | 21 | if @str =~ /^\s*$/ 22 | @nil = true 23 | @sequences = [] 24 | @comparable = false 25 | elsif str =~ /^\d+$/ || str =~ /^\d+\./ 26 | @nil = false 27 | @sequences = str.scan(/\d+|[A-Za-z][0-9A-Za-z-]*$/).map { |s| s =~ /^\d+$/ ? s.to_i : s } 28 | @comparable = true 29 | else 30 | @nil = false 31 | @sequences = [str] 32 | @comparable = false 33 | end 34 | end 35 | 36 | def nil? 37 | @nil 38 | end 39 | 40 | def to_a 41 | @sequences.dup 42 | end 43 | 44 | def to_str 45 | @str.dup 46 | end 47 | 48 | def eql?(other) 49 | other.is_a?(self.class) && to_s == other.to_s 50 | end 51 | 52 | def ==(other) 53 | case other 54 | when Version 55 | eql?(other) 56 | when String 57 | eql?(self.class.new(other)) 58 | when NilClass 59 | nil? 60 | else 61 | false 62 | end 63 | end 64 | 65 | def <=>(other) 66 | case other 67 | when Version 68 | if @comparable 69 | ([0]*6).zip(to_a, other.to_a).each do |dump, a, b| 70 | a ||= 0 71 | b ||= 0 72 | 73 | if a.is_a?(String) && b.is_a?(Integer) 74 | return -1 75 | elsif a.is_a?(Integer) && b.is_a?(String) 76 | return 1 77 | elsif a == b 78 | next 79 | else 80 | return a <=> b 81 | end 82 | end 83 | 0 84 | elsif to_s == other.to_s 85 | return 0 86 | else 87 | return -1 88 | end 89 | when String, NilClass 90 | self <=> self.class.new(other) 91 | else 92 | nil 93 | end 94 | end 95 | 96 | def to_s 97 | to_str 98 | end 99 | 100 | def inspect 101 | "#<#{self.class} #{to_s}>" 102 | end 103 | end 104 | end 105 | -------------------------------------------------------------------------------- /spec/browsers/wechat_browser_user_agent_spec.rb: -------------------------------------------------------------------------------- 1 | require 'user_agent' 2 | 3 | describe "UserAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13E238 MicroMessenger/6.3.16 NetType/WIFI Language/zh_CN'" do 4 | before do 5 | @useragent = UserAgent.parse("Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13E238 MicroMessenger/6.3.16 NetType/WIFI Language/zh_CN") 6 | end 7 | 8 | it "should return WechatBrowser" do 9 | expect(@useragent.browser).to eq("Wechat Browser") 10 | end 11 | 12 | it "should return '6.3.16' as its version" do 13 | expect(@useragent.version).to eq("6.3.16") 14 | end 15 | 16 | it "should return 'iPhone' as its platform" do 17 | expect(@useragent.platform).to eq("iPhone") 18 | end 19 | 20 | it "should return 'iOS 9.3.1' as its os" do 21 | expect(@useragent.os).to eq("iOS 9.3.1") 22 | end 23 | end 24 | 25 | describe "UserAgent: 'Mozilla/5.0 (Linux; Android 4.4.4; MI 4LTE Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/37.0.0.0 Mobile MQQBrowser/6.2 TBS/036215 Safari/537.36 MicroMessenger/6.3.16.49_r03ae324.780 NetType/WIFI Language/zh_CN'" do 26 | before do 27 | @useragent = UserAgent.parse("Mozilla/5.0 (Linux; Android 4.4.4; MI 4LTE Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/37.0.0.0 Mobile MQQBrowser/6.2 TBS/036215 Safari/537.36 MicroMessenger/6.3.16.49_r03ae324.780 NetType/WIFI Language/zh_CN") 28 | end 29 | 30 | it "should return WechatBrowser" do 31 | expect(@useragent.browser).to eq("Wechat Browser") 32 | end 33 | 34 | it "should return '6.3.16.49_r03ae324.780' as its version" do 35 | expect(@useragent.version).to eq("6.3.16.49_r03ae324.780") 36 | end 37 | 38 | it "should return 'Android' as its platform" do 39 | expect(@useragent.platform).to eq("Android") 40 | end 41 | 42 | it "should return 'Android 4.4.4' as its os" do 43 | expect(@useragent.os).to eq("Android 4.4.4") 44 | end 45 | end 46 | 47 | describe "Not well-formed UserAgent: LenovoA658t_TD/1.0 Android 4.0.3 Release/10.01.2012 Browser/WAP2.0 appleWebkit/534.30 MicroMessenger/6.2.4.54_r266a9ba.601 NetType/cmnet Language/zh_CN" do 48 | before do 49 | @useragent = UserAgent.parse("LenovoA658t_TD/1.0 Android 4.0.3 Release/10.01.2012 Browser/WAP2.0 appleWebkit/534.30 MicroMessenger/6.2.4.54_r266a9ba.601 NetType/cmnet Language/zh_CN") 50 | end 51 | 52 | it "should return WechatBrowser" do 53 | expect(@useragent.browser).to eq("Wechat Browser") 54 | end 55 | 56 | it "should return '6.2.4.54_r266a9ba.601' as its version" do 57 | expect(@useragent.version).to eq("6.2.4.54_r266a9ba.601") 58 | end 59 | 60 | it "should return nil as its platform" do 61 | expect(@useragent.platform).to be_nil 62 | end 63 | 64 | it "should return nil as its os" do 65 | expect(@useragent.os).to be_nil 66 | end 67 | 68 | end 69 | 70 | -------------------------------------------------------------------------------- /lib/user_agent/browsers/playstation.rb: -------------------------------------------------------------------------------- 1 | class UserAgent 2 | module Browsers 3 | # Mozilla/5.0 (PLAYSTATION 3 4.75) AppleWebKit/531.22.8 (KHTML, like Gecko) 4 | # Mozilla/5.0 (PLAYSTATION 3 4.76) AppleWebKit/531.22.8 (KHTML, like Gecko) 5 | # Mozilla/5.0 (PLAYSTATION 3; 1.00) 6 | # Mozilla/5.0 (PlayStation Vita 3.52) AppleWebKit/537.73 (KHTML, like Gecko) Silk/3.2 7 | # Mozilla/5.0 (PlayStation 4 2.57) AppleWebKit/537.73 (KHTML, like Gecko) 8 | class PlayStation < Base 9 | def self.extend?(agent) 10 | !agent.application.nil? && !agent.application.comment.nil? && agent.application.comment.any? && ( 11 | agent.application.comment.first.include?('PLAYSTATION 3') || 12 | agent.application.comment.first.include?('PlayStation Vita') || 13 | agent.application.comment.first.include?('PlayStation 4') 14 | ) 15 | end 16 | 17 | # Returns the name of the browser in use. 18 | # 19 | # @return [nil, String] the name of the browser 20 | def browser 21 | if application.comment.first.include?('PLAYSTATION 3') 22 | 'PS3 Internet Browser' 23 | elsif last.product == 'Silk' 24 | 'Silk' 25 | elsif application.comment.first.include?('PlayStation 4') 26 | 'PS4 Internet Browser' 27 | else 28 | nil 29 | end 30 | end 31 | 32 | # PS Vita is mobile, others are not. 33 | # 34 | # @return [true, false] is this a mobile browser? 35 | def mobile? 36 | platform == 'PlayStation Vita' 37 | end 38 | 39 | # Returns the operating system in use. 40 | # 41 | # @return [String] the operating system in use 42 | def os 43 | application.comment.join(' ') 44 | end 45 | 46 | # Returns the platform in use. 47 | # 48 | # @return [nil, "PlayStation 3", "PlayStation 4", "PlayStation Vita"] the platform in use 49 | def platform 50 | if os.include?('PLAYSTATION 3') 51 | 'PlayStation 3' 52 | elsif os.include?('PlayStation 4') 53 | 'PlayStation 4' 54 | elsif os.include?('PlayStation Vita') 55 | 'PlayStation Vita' 56 | else 57 | nil 58 | end 59 | end 60 | 61 | # Returns the browser version in use. If Silk, returns the version of Silk. 62 | # Otherwise, returns the PS3/PS4 firmware version. 63 | # 64 | # @return [nil, Version] the version 65 | def version 66 | if browser == 'Silk' 67 | last.version 68 | elsif platform == 'PlayStation 3' 69 | Version.new(os.split('PLAYSTATION 3 ').last) 70 | elsif platform == 'PlayStation 4' 71 | Version.new(os.split('PlayStation 4 ').last) 72 | elsif platform == 'PlayStation Vita' 73 | Version.new(os.split('PlayStation Vita ').last) 74 | else 75 | nil 76 | end 77 | end 78 | end 79 | end 80 | end 81 | -------------------------------------------------------------------------------- /spec/browsers/playstation_user_agent_spec.rb: -------------------------------------------------------------------------------- 1 | require 'user_agent' 2 | 3 | shared_examples 'PlayStation 3' do 4 | it "returns 'PlayStation 3' as its platform" do 5 | expect(@useragent.platform).to eq('PlayStation 3') 6 | end 7 | 8 | it "returns 'PS3 Internet Browser' as its browser" do 9 | expect(@useragent.browser).to eq('PS3 Internet Browser') 10 | end 11 | 12 | it 'returns false for mobile?' do 13 | expect(@useragent.mobile?).to be false 14 | end 15 | end 16 | 17 | describe "UserAgent: Mozilla/5.0 (PLAYSTATION 3 4.75) AppleWebKit/531.22.8 (KHTML, like Gecko)" do 18 | before do 19 | @useragent = UserAgent.parse("Mozilla/5.0 (PLAYSTATION 3 4.75) AppleWebKit/531.22.8 (KHTML, like Gecko)") 20 | end 21 | 22 | it_behaves_like 'PlayStation 3' 23 | 24 | it "returns 'PLAYSTATION 3 4.75' as its operating system" do 25 | expect(@useragent.os).to eq('PLAYSTATION 3 4.75') 26 | end 27 | 28 | it "returns 4.75 as its version" do 29 | expect(@useragent.version.to_a).to eq([4, 75]) 30 | end 31 | end 32 | 33 | describe "UserAgent: Mozilla/5.0 (PLAYSTATION 3; 1.00)" do 34 | before do 35 | @useragent = UserAgent.parse("Mozilla/5.0 (PLAYSTATION 3; 1.00)") 36 | end 37 | 38 | it_behaves_like 'PlayStation 3' 39 | 40 | it "returns 'PLAYSTATION 3 1.00' as its operating system" do 41 | expect(@useragent.os).to eq('PLAYSTATION 3 1.00') 42 | end 43 | 44 | it "returns 1.0 as its version" do 45 | expect(@useragent.version.to_a).to eq([1, 0]) 46 | end 47 | end 48 | 49 | describe "UserAgent: Mozilla/5.0 (PlayStation Vita 3.52) AppleWebKit/537.73 (KHTML, like Gecko) Silk/3.2" do 50 | before do 51 | @useragent = UserAgent.parse("Mozilla/5.0 (PlayStation Vita 3.52) AppleWebKit/537.73 (KHTML, like Gecko) Silk/3.2") 52 | end 53 | 54 | it "returns 'Silk' as its browser" do 55 | expect(@useragent.browser).to eq('Silk') 56 | end 57 | 58 | it "returns 'PlayStation Vita' as its platform" do 59 | expect(@useragent.platform).to eq('PlayStation Vita') 60 | end 61 | 62 | it "returns 'PlayStation Vita 3.52' as its operating system" do 63 | expect(@useragent.os).to eq('PlayStation Vita 3.52') 64 | end 65 | 66 | it "returns 3.2 as its version" do 67 | expect(@useragent.version.to_a).to eq([3, 2]) 68 | end 69 | 70 | it 'returns true for mobile?' do 71 | expect(@useragent.mobile?).to be true 72 | end 73 | end 74 | 75 | describe "UserAgent: Mozilla/5.0 (PlayStation 4 2.57) AppleWebKit/537.73 (KHTML, like Gecko)" do 76 | before do 77 | @useragent = UserAgent.parse("Mozilla/5.0 (PlayStation 4 2.57) AppleWebKit/537.73 (KHTML, like Gecko)") 78 | end 79 | 80 | it "returns 'PS4 Internet Browser' as its browser" do 81 | expect(@useragent.browser).to eq('PS4 Internet Browser') 82 | end 83 | 84 | it "returns 'PlayStation 4' as its platform" do 85 | expect(@useragent.platform).to eq('PlayStation 4') 86 | end 87 | 88 | it "returns 'PlayStation 4 2.57' as its operating system" do 89 | expect(@useragent.os).to eq('PlayStation 4 2.57') 90 | end 91 | 92 | it "returns 2.57 as its version" do 93 | expect(@useragent.version.to_a).to eq([2, 57]) 94 | end 95 | 96 | it 'returns false for mobile?' do 97 | expect(@useragent.mobile?).to be false 98 | end 99 | end -------------------------------------------------------------------------------- /spec/browsers/apple_core_media_user_agent_spec.rb: -------------------------------------------------------------------------------- 1 | require 'user_agent' 2 | 3 | shared_examples "AppleCoreMedia" do 4 | it "should return 'AppleCoreMedia' as its browser" do 5 | expect(@useragent.browser).to eq("AppleCoreMedia") 6 | end 7 | end 8 | 9 | shared_examples "AppleCoreMedia runs on" do |platform, os| 10 | it "should return '#{platform}' as its platform" do 11 | expect(@useragent.platform).to eq(platform) 12 | end 13 | 14 | it "should return '#{os}' as its OS" do 15 | expect(@useragent.os).to eq(os) 16 | end 17 | end 18 | 19 | shared_examples "AppleCoreMedia has version number" do |version| 20 | it "should return '#{version}' as its version" do 21 | expect(@useragent.version).to eq(version) 22 | end 23 | end 24 | 25 | shared_examples "AppleCoreMedia has localization" do |locale| 26 | it "should return '#{locale}' as its localization" do 27 | expect(@useragent.localization).to eq(locale) 28 | end 29 | end 30 | 31 | shared_examples "AppleCoreMedia has strong encryption" do 32 | it "should return ':strong' as its security" do 33 | expect(@useragent.security).to eq(:strong) 34 | end 35 | end 36 | 37 | describe "UserAgent: AppleCoreMedia/1.0.0.12B435 (iPhone; U; CPU OS 8_1_1 like Mac OS X; en_us)" do 38 | before do 39 | @useragent = UserAgent.parse("AppleCoreMedia/1.0.0.12B435 (iPhone; U; CPU OS 8_1_1 like Mac OS X; en_us)") 40 | end 41 | 42 | it_behaves_like "AppleCoreMedia" 43 | it_behaves_like "AppleCoreMedia runs on", "iPhone", "iOS 8.1.1" 44 | it_behaves_like "AppleCoreMedia has version number", "1.0.0.12B435" 45 | it_behaves_like "AppleCoreMedia has localization", "en_us" 46 | it_behaves_like "AppleCoreMedia has strong encryption" 47 | end 48 | 49 | describe "UserAgent: AppleCoreMedia/1.0.0.10B400 (iPod; U; CPU OS 6_1_5 like Mac OS X; en_us)" do 50 | before do 51 | @useragent = UserAgent.parse("AppleCoreMedia/1.0.0.10B400 (iPod; U; CPU OS 6_1_5 like Mac OS X; en_us)") 52 | end 53 | 54 | it_behaves_like "AppleCoreMedia" 55 | it_behaves_like "AppleCoreMedia runs on", "iPod", "iOS 6.1.5" 56 | it_behaves_like "AppleCoreMedia has version number", "1.0.0.10B400" 57 | it_behaves_like "AppleCoreMedia has localization", "en_us" 58 | it_behaves_like "AppleCoreMedia has strong encryption" 59 | end 60 | 61 | describe "UserAgent: AppleCoreMedia/1.0.0.11D257 (iPad; U; CPU OS 7_1_2 like Mac OS X; en_gb)" do 62 | before do 63 | @useragent = UserAgent.parse("AppleCoreMedia/1.0.0.11D257 (iPad; U; CPU OS 7_1_2 like Mac OS X; en_gb)") 64 | end 65 | 66 | it_behaves_like "AppleCoreMedia" 67 | it_behaves_like "AppleCoreMedia runs on", "iPad", "iOS 7.1.2" 68 | it_behaves_like "AppleCoreMedia has version number", "1.0.0.11D257" 69 | it_behaves_like "AppleCoreMedia has localization", "en_gb" 70 | it_behaves_like "AppleCoreMedia has strong encryption" 71 | end 72 | 73 | describe "UserAgent: AppleCoreMedia/1.0.0.11D257 (iPhone; U; CPU OS 7_1_2 like Mac OS X; en_us)" do 74 | before do 75 | @useragent = UserAgent.parse("AppleCoreMedia/1.0.0.11D257 (iPhone; U; CPU OS 7_1_2 like Mac OS X; en_us)") 76 | end 77 | 78 | it_behaves_like "AppleCoreMedia" 79 | it_behaves_like "AppleCoreMedia runs on", "iPhone", "iOS 7.1.2" 80 | it_behaves_like "AppleCoreMedia has version number", "1.0.0.11D257" 81 | it_behaves_like "AppleCoreMedia has localization", "en_us" 82 | it_behaves_like "AppleCoreMedia has strong encryption" 83 | end 84 | -------------------------------------------------------------------------------- /lib/user_agent/browsers/podcast_addict.rb: -------------------------------------------------------------------------------- 1 | class UserAgent 2 | module Browsers 3 | # Podcast Addict - Dalvik/1.6.0 (Linux; U; Android 4.4.2; LG-D631 Build/KOT49I.D63110b) 4 | # Podcast Addict - Dalvik/2.1.0 (Linux; U; Android 5.1; XT1093 Build/LPE23.32-21.3) 5 | # Podcast Addict - Mozilla/5.0 (Linux; U; Android 4.2.2; en-us; ALCATEL ONE TOUCH Fierce Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.2 Mobile Safari/534.30 6 | # Podcast Addict - Mozilla/5.0 (Linux; U; Android 4.2.2; en-ca; ALCATEL ONE TOUCH 6040A Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.2 Mobile Safari/534.30 7 | # Podcast Addict - Dalvik/2.1.0 (Linux; U; Android M Build/MPZ79M) 8 | class PodcastAddict < Base 9 | def self.extend?(agent) 10 | agent.length >= 3 && agent[0].product == 'Podcast' && agent[1].product == 'Addict' && agent[2].product == '-' 11 | end 12 | 13 | def browser 14 | 'Podcast Addict' 15 | end 16 | 17 | # If we can figure out the device, return it. 18 | # 19 | # @return [nil, String] the device model 20 | def device 21 | return nil unless length >= 4 22 | return nil unless self[3].comment.last.include?(' Build/') 23 | 24 | self[3].comment.last.split(' Build/').first 25 | end 26 | 27 | # If we can figure out the device build, return it. 28 | # 29 | # @return [nil, String] the device build 30 | def device_build 31 | return nil unless length >= 4 32 | return nil unless self[3].comment.last.include?(' Build/') 33 | 34 | self[3].comment.last.split(' Build/').last 35 | end 36 | 37 | # Returns the localization, if known. We currently only know this for certain devices. 38 | # 39 | # @return [nil, String] the localization 40 | def localization 41 | return nil unless length >= 4 42 | return nil unless self[3].comment.last.include?('ALCATEL ') 43 | return nil unless self[3].comment.length >= 5 44 | 45 | self[3].comment[3] 46 | end 47 | 48 | # This is a mobile app, always return true. 49 | # 50 | # @return [true] 51 | def mobile? 52 | true 53 | end 54 | 55 | # Gets the operating system (some variant of Android, if we're certain that is the case) 56 | # 57 | # @return [nil, String] the operating system 58 | def os 59 | return nil unless length >= 4 60 | 61 | # comment[0] = 'Linux' 62 | # comment[1] = 'U' 63 | # comment[2] = 'Android x.y.z' except when there are only 3 tokens, then we don't know the version 64 | if (self[3].product == 'Dalvik' || self[3].product == 'Mozilla') && self[3].comment.length > 3 65 | self[3].comment[2] 66 | elsif (self[3].product == 'Dalvik' || self[3].product == 'Mozilla') && self[3].comment.length == 3 67 | 'Android' 68 | else 69 | nil 70 | end 71 | end 72 | 73 | # Gets the platform (Android, if we're certain) 74 | # 75 | # @return [nil, "Android"] the platform 76 | def platform 77 | if os.include?('Android') 78 | 'Android' 79 | else 80 | nil 81 | end 82 | end 83 | 84 | 85 | # Get the security level reported 86 | # 87 | # @return [:weak, :strong, :none] the security level 88 | def security 89 | return nil unless length >= 4 90 | return nil unless self[3].product == 'Dalvik' || self[3].product == 'Mozilla' 91 | 92 | Security[self[3].comment[1]] 93 | end 94 | 95 | # We aren't provided with the version :( 96 | # 97 | # @return [nil] 98 | def version 99 | nil 100 | end 101 | end 102 | end 103 | end -------------------------------------------------------------------------------- /lib/user_agent/browsers/base.rb: -------------------------------------------------------------------------------- 1 | class UserAgent 2 | module Browsers 3 | class Base < Array 4 | include Comparable 5 | 6 | def <=>(other) 7 | if respond_to?(:browser) && other.respond_to?(:browser) && 8 | browser == other.browser 9 | version <=> Version.new(other.version) 10 | else 11 | false 12 | end 13 | end 14 | 15 | def eql?(other) 16 | self == other 17 | end 18 | 19 | def to_s 20 | to_str 21 | end 22 | 23 | def to_str 24 | join(" ") 25 | end 26 | 27 | def application 28 | first 29 | end 30 | 31 | def browser 32 | application && application.product 33 | end 34 | 35 | def version 36 | application && application.version 37 | end 38 | 39 | def platform 40 | nil 41 | end 42 | 43 | def os 44 | nil 45 | end 46 | 47 | def respond_to?(symbol, include_all = false) 48 | detect_product(symbol) ? true : super 49 | end 50 | 51 | def method_missing(method, *args, &block) 52 | detect_product(method) || super 53 | end 54 | 55 | def mobile? 56 | if detect_product('Mobile') || detect_comment('Mobile') 57 | true 58 | elsif os =~ /Android/ 59 | true 60 | elsif application && application.detect_comment { |c| c =~ /^IEMobile/ } 61 | true 62 | else 63 | false 64 | end 65 | end 66 | 67 | def bot? 68 | # If UA has no application type, its probably generated by a 69 | # shitty bot. 70 | if application.nil? 71 | true 72 | # Match common case when bots refer to themselves as bots in 73 | # the application comment. There are no standards for how bots 74 | # should call themselves so its not an exhaustive method. 75 | # 76 | # If you want to expand the scope, override the method and 77 | # provide your own regexp. Any patches to future extend this 78 | # list will be rejected. 79 | elsif detect_comment_match(/bot/i) 80 | true 81 | # Google PageSpeed Insights adds "Chrome-Lighthouse" to the user agent 82 | # https://stackoverflow.com/questions/16403295/what-is-the-name-of-the-google-pagespeed-user-agent 83 | elsif detect_product("Chrome-Lighthouse") 84 | true 85 | elsif product = application.product 86 | product.include?('bot') 87 | else 88 | false 89 | end 90 | end 91 | 92 | def to_h 93 | return unless application 94 | 95 | hash = { 96 | :browser => browser, 97 | :platform => platform, 98 | :os => os, 99 | :mobile => mobile?, 100 | :bot => bot?, 101 | } 102 | 103 | if version 104 | hash[:version] = version.to_a 105 | else 106 | hash[:version] = nil 107 | end 108 | 109 | if comment = application.comment 110 | hash[:comment] = comment.dup 111 | else 112 | hash[:comment] = nil 113 | end 114 | 115 | hash 116 | end 117 | 118 | private 119 | def detect_product(product) 120 | detect { |useragent| useragent.product.to_s.downcase == product.to_s.downcase } 121 | end 122 | 123 | def detect_comment(comment) 124 | detect { |useragent| useragent.detect_comment { |c| c == comment } } 125 | end 126 | 127 | def detect_comment_match(regexp) 128 | comment_match = nil 129 | detect { |useragent| useragent.detect_comment { |c| comment_match = c.match(regexp) } } 130 | comment_match 131 | end 132 | end 133 | end 134 | end 135 | -------------------------------------------------------------------------------- /lib/user_agent/browsers/webkit.rb: -------------------------------------------------------------------------------- 1 | class UserAgent 2 | module Browsers 3 | class Webkit < Base 4 | WEBKIT_PRODUCT_REGEXP = /\AAppleWebKit\z/i 5 | WEBKIT_VERSION_REGEXP = /\A(?AppleWebKit)\/(?[\d\.]+)/i 6 | 7 | def self.extend?(agent) 8 | agent.detect { |useragent| useragent.product =~ WEBKIT_PRODUCT_REGEXP || useragent.detect_comment { |c| c =~ WEBKIT_VERSION_REGEXP } } 9 | end 10 | 11 | def browser 12 | if os =~ /Android/ 13 | 'Android' 14 | elsif platform == 'BlackBerry' 15 | platform 16 | else 17 | 'Safari' 18 | end 19 | end 20 | 21 | def build 22 | webkit.version 23 | end 24 | 25 | BuildVersions = { 26 | "85.7" => "1.0", 27 | "85.8.5" => "1.0.3", 28 | "85.8.2" => "1.0.3", 29 | "124" => "1.2", 30 | "125.2" => "1.2.2", 31 | "125.4" => "1.2.3", 32 | "125.5.5" => "1.2.4", 33 | "125.5.6" => "1.2.4", 34 | "125.5.7" => "1.2.4", 35 | "312.1.1" => "1.3", 36 | "312.1" => "1.3", 37 | "312.5" => "1.3.1", 38 | "312.5.1" => "1.3.1", 39 | "312.5.2" => "1.3.1", 40 | "312.8" => "1.3.2", 41 | "312.8.1" => "1.3.2", 42 | "412" => "2.0", 43 | "412.6" => "2.0", 44 | "412.6.2" => "2.0", 45 | "412.7" => "2.0.1", 46 | "416.11" => "2.0.2", 47 | "416.12" => "2.0.2", 48 | "417.9" => "2.0.3", 49 | "418" => "2.0.3", 50 | "418.8" => "2.0.4", 51 | "418.9" => "2.0.4", 52 | "418.9.1" => "2.0.4", 53 | "419" => "2.0.4", 54 | "425.13" => "2.2", 55 | "534.52.7" => "5.1.2" 56 | }.freeze 57 | 58 | # Prior to Safari 3, the user agent did not include a version number 59 | def version 60 | str = if product = detect_product('Version') 61 | product.version 62 | elsif os =~ /iOS ([\d\.]+)/ && browser == "Safari" 63 | $1.tr('_', '.') 64 | else 65 | BuildVersions[build.to_s] 66 | end 67 | 68 | Version.new(str) 69 | end 70 | 71 | def application 72 | self.reject { |agent| agent.comment.nil? || agent.comment.empty? }.first 73 | end 74 | 75 | def platform 76 | return unless application 77 | 78 | if application.comment[0] =~ /Windows/ 79 | 'Windows' 80 | elsif application.comment[0] == 'BB10' 81 | 'BlackBerry' 82 | elsif application.comment.any? { |c| c =~ /Android/ } 83 | 'Android' 84 | else 85 | application.comment[0] 86 | end 87 | end 88 | 89 | def webkit 90 | if product_match = detect { |useragent| useragent.product =~ WEBKIT_PRODUCT_REGEXP } 91 | product_match 92 | elsif comment_match = detect_comment_match(WEBKIT_VERSION_REGEXP) 93 | UserAgent.new(comment_match[:webkit], comment_match[:version]) 94 | end 95 | end 96 | 97 | def security 98 | Security[application.comment[1]] 99 | end 100 | 101 | def os 102 | return unless application 103 | 104 | if application.comment[0] =~ /Windows NT/ 105 | OperatingSystems.normalize_os(application.comment[0]) 106 | elsif application.comment[2].nil? 107 | OperatingSystems.normalize_os(application.comment[1]) 108 | elsif application.comment[1] =~ /Android/ 109 | OperatingSystems.normalize_os(application.comment[1]) 110 | elsif (os_string = application.comment.detect { |c| c =~ OperatingSystems::IOS_VERSION_REGEX }) 111 | OperatingSystems.normalize_os(os_string) 112 | else 113 | OperatingSystems.normalize_os(application.comment[2]) 114 | end 115 | end 116 | 117 | def localization 118 | return unless application 119 | 120 | application.comment[3] 121 | end 122 | end 123 | end 124 | end 125 | -------------------------------------------------------------------------------- /spec/browsers/podcast_addict_user_agent_spec.rb: -------------------------------------------------------------------------------- 1 | require 'user_agent' 2 | 3 | shared_examples 'Podcast Addict' do 4 | it "returns 'Podcast Addict' as its browser" do 5 | expect(@useragent.browser).to eq('Podcast Addict') 6 | end 7 | 8 | it 'returns nil as its version' do 9 | expect(@useragent.version).to be_nil 10 | end 11 | 12 | it "returns 'Android' as its platform" do 13 | expect(@useragent.platform).to eq('Android') 14 | end 15 | 16 | it "returns ':strong' as its security" do 17 | expect(@useragent.security).to eq(:strong) 18 | end 19 | 20 | it 'is a mobile user agent' do 21 | expect(@useragent.mobile?).to be true 22 | end 23 | end 24 | 25 | describe "UserAgent: Podcast Addict - Dalvik/1.6.0 (Linux; U; Android 4.4.2; LG-D631 Build/KOT49I.D63110b)" do 26 | before do 27 | @useragent = UserAgent.parse("Podcast Addict - Dalvik/1.6.0 (Linux; U; Android 4.4.2; LG-D631 Build/KOT49I.D63110b)") 28 | end 29 | 30 | it_behaves_like 'Podcast Addict' 31 | 32 | it "returns 'Android 4.4.2' as its operating system" do 33 | expect(@useragent.os).to eq('Android 4.4.2') 34 | end 35 | 36 | it "returns 'LG-D631' as its device" do 37 | expect(@useragent.device).to eq('LG-D631') 38 | end 39 | 40 | it "returns 'KOT49I.D63110b' as its device build" do 41 | expect(@useragent.device_build).to eq('KOT49I.D63110b') 42 | end 43 | 44 | it 'returns nil as its localization' do 45 | expect(@useragent.localization).to be_nil 46 | end 47 | end 48 | 49 | describe "UserAgent: Podcast Addict - Dalvik/2.1.0 (Linux; U; Android 5.1; XT1093 Build/LPE23.32-21.3)" do 50 | before do 51 | @useragent = UserAgent.parse("Podcast Addict - Dalvik/2.1.0 (Linux; U; Android 5.1; XT1093 Build/LPE23.32-21.3)") 52 | end 53 | 54 | it_behaves_like 'Podcast Addict' 55 | 56 | it "returns 'Android 5.1' as its operating system" do 57 | expect(@useragent.os).to eq('Android 5.1') 58 | end 59 | 60 | it "returns 'XT1093' as its device" do 61 | expect(@useragent.device).to eq('XT1093') 62 | end 63 | 64 | it "returns 'LPE23.32-21.3' as its device build" do 65 | expect(@useragent.device_build).to eq('LPE23.32-21.3') 66 | end 67 | 68 | it 'returns nil as its localization' do 69 | expect(@useragent.localization).to be_nil 70 | end 71 | end 72 | 73 | describe "UserAgent: Podcast Addict - Dalvik/2.1.0 (Linux; U; Android M Build/MPZ79M)" do 74 | before do 75 | @useragent = UserAgent.parse("Podcast Addict - Dalvik/2.1.0 (Linux; U; Android M Build/MPZ79M)") 76 | end 77 | 78 | it_behaves_like 'Podcast Addict' 79 | 80 | it "returns 'Android' as its operating system" do 81 | expect(@useragent.os).to eq('Android') 82 | end 83 | 84 | it "returns 'Android M' as its device" do 85 | expect(@useragent.device).to eq('Android M') 86 | end 87 | 88 | it "returns 'MPZ79M' as its device build" do 89 | expect(@useragent.device_build).to eq('MPZ79M') 90 | end 91 | 92 | it 'returns nil as its localization' do 93 | expect(@useragent.localization).to be_nil 94 | end 95 | end 96 | 97 | describe "UserAgent: Podcast Addict - Mozilla/5.0 (Linux; U; Android 4.2.2; en-ca; ALCATEL ONE TOUCH 6040A Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.2 Mobile Safari/534.30" do 98 | before do 99 | @useragent = UserAgent.parse("Podcast Addict - Mozilla/5.0 (Linux; U; Android 4.2.2; en-ca; ALCATEL ONE TOUCH 6040A Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.2 Mobile Safari/534.30") 100 | end 101 | 102 | it_behaves_like 'Podcast Addict' 103 | 104 | it "returns 'Android' as its operating system" do 105 | expect(@useragent.os).to eq('Android 4.2.2') 106 | end 107 | 108 | it "returns 'ALCATEL ONE TOUCH 6040A' as its device" do 109 | expect(@useragent.device).to eq('ALCATEL ONE TOUCH 6040A') 110 | end 111 | 112 | it "returns 'JDQ39' as its device build" do 113 | expect(@useragent.device_build).to eq('JDQ39') 114 | end 115 | 116 | it "returns 'en-ca' as its localization" do 117 | expect(@useragent.localization).to eq('en-ca') 118 | end 119 | end -------------------------------------------------------------------------------- /spec/browsers/other_user_agent_spec.rb: -------------------------------------------------------------------------------- 1 | require 'user_agent' 2 | 3 | describe "UserAgent: nil" do 4 | before do 5 | @useragent = UserAgent.parse(nil) 6 | end 7 | 8 | it "should return 'Mozilla' as its browser" do 9 | expect(@useragent.browser).to eq("Mozilla") 10 | end 11 | 12 | it "should return '4.0' as its version" do 13 | expect(@useragent.version).to eq("4.0") 14 | end 15 | 16 | it "should return nil as its platform" do 17 | expect(@useragent.platform).to eq(nil) 18 | end 19 | 20 | it "should return nil as its os" do 21 | expect(@useragent.os).to eq(nil) 22 | end 23 | 24 | it { expect(@useragent).not_to be_mobile } 25 | it { expect(@useragent).not_to be_bot } 26 | end 27 | 28 | describe "UserAgent: ''" do 29 | before do 30 | @useragent = UserAgent.parse('') 31 | end 32 | 33 | it "should return 'Mozilla' as its browser" do 34 | expect(@useragent.browser).to eq("Mozilla") 35 | end 36 | 37 | it "should return '4.0' as its version" do 38 | expect(@useragent.version).to eq("4.0") 39 | end 40 | 41 | it "should return nil as its platform" do 42 | expect(@useragent.platform).to eq(nil) 43 | end 44 | 45 | it "should return nil as its os" do 46 | expect(@useragent.os).to eq(nil) 47 | end 48 | 49 | it { expect(@useragent).not_to be_mobile } 50 | it { expect(@useragent).not_to be_bot } 51 | end 52 | 53 | describe "UserAgent: 'Mozilla/4.0 (compatible)'" do 54 | before do 55 | @useragent = UserAgent.parse("Mozilla/4.0 (compatible)") 56 | end 57 | 58 | it "should return 'Mozilla' as its browser" do 59 | expect(@useragent.browser).to eq("Mozilla") 60 | end 61 | 62 | it "should return '4.0' as its version" do 63 | expect(@useragent.version).to eq("4.0") 64 | end 65 | 66 | it "should return nil as its platform" do 67 | expect(@useragent.platform).to eq(nil) 68 | end 69 | 70 | it "should return nil as its os" do 71 | expect(@useragent.os).to eq(nil) 72 | end 73 | 74 | it { expect(@useragent).not_to be_mobile } 75 | it { expect(@useragent).not_to be_bot } 76 | end 77 | 78 | describe "UserAgent: 'Mozilla/5.0'" do 79 | before do 80 | @useragent = UserAgent.parse("Mozilla/5.0") 81 | end 82 | 83 | it "should return 'Mozilla' as its browser" do 84 | expect(@useragent.browser).to eq("Mozilla") 85 | end 86 | 87 | it "should return '5.0' as its version" do 88 | expect(@useragent.version).to eq("5.0") 89 | end 90 | 91 | it "should return nil as its platform" do 92 | expect(@useragent.platform).to eq(nil) 93 | end 94 | 95 | it "should return nil as its os" do 96 | expect(@useragent.os).to eq(nil) 97 | end 98 | 99 | it { expect(@useragent).not_to be_mobile } 100 | it { expect(@useragent).not_to be_bot } 101 | end 102 | 103 | describe "UserAgent: 'amaya/9.51 libwww/5.4.0'" do 104 | before do 105 | @useragent = UserAgent.parse("amaya/9.51 libwww/5.4.0") 106 | end 107 | 108 | it "should return 'amaya' as its browser" do 109 | expect(@useragent.browser).to eq("amaya") 110 | end 111 | 112 | it "should return '9.51' as its version" do 113 | expect(@useragent.version).to eq("9.51") 114 | end 115 | 116 | it "should return '5.4.0' as its libwww version" do 117 | expect(@useragent.libwww.version).to eq("5.4.0") 118 | end 119 | end 120 | 121 | describe "UserAgent: 'Rails Testing'" do 122 | before do 123 | @useragent = UserAgent.parse("Rails Testing") 124 | end 125 | 126 | it "should return 'Rails' as its browser" do 127 | expect(@useragent.browser).to eq("Rails") 128 | end 129 | 130 | it { expect(@useragent.version).to be_nil } 131 | it { expect(@useragent.platform).to be_nil } 132 | it { expect(@useragent.os).to be_nil } 133 | it { expect(@useragent).not_to be_mobile } 134 | end 135 | 136 | describe "UserAgent: 'Python-urllib/2.7'" do 137 | before do 138 | @useragent = UserAgent.parse("Python-urllib/2.7") 139 | end 140 | 141 | it "should return 'Python-urllib' as its browser" do 142 | expect(@useragent.browser).to eq("Python-urllib") 143 | end 144 | 145 | it "should return '2.7' as its version" do 146 | expect(@useragent.version).to eq("2.7") 147 | end 148 | 149 | it { expect(@useragent.platform).to be_nil } 150 | it { expect(@useragent.os).to be_nil } 151 | it { expect(@useragent).not_to be_mobile } 152 | end 153 | 154 | describe "UserAgent: 'check_http/v1.4.15 (nagios-plugins 1.4.15)'" do 155 | before do 156 | @useragent = UserAgent.parse("check_http/v1.4.15 (nagios-plugins 1.4.15)") 157 | end 158 | 159 | it "should return 'check_http' as its browser" do 160 | expect(@useragent.browser).to eq("check_http") 161 | end 162 | 163 | it "should return 'v1.4.15' as its version" do 164 | expect(@useragent.version).to eq("v1.4.15") 165 | end 166 | 167 | it { expect(@useragent.platform).to be_nil } 168 | it { expect(@useragent.os).to be_nil } 169 | it { expect(@useragent).not_to be_mobile } 170 | end 171 | 172 | describe "UserAgent: '/WebTest.pm'" do 173 | before do 174 | @useragent = UserAgent.parse("/WebTest.pm") 175 | end 176 | 177 | it "should return nil as its browser" do 178 | expect(@useragent.browser).to eq(nil) 179 | end 180 | end 181 | -------------------------------------------------------------------------------- /spec/browsers/itunes_user_agent_spec.rb: -------------------------------------------------------------------------------- 1 | require 'user_agent' 2 | 3 | shared_examples "iTunes" do 4 | it "should return 'iTunes' as its browser" do 5 | expect(@useragent.browser).to eq("iTunes") 6 | end 7 | 8 | it "should return nil as its security" do 9 | expect(@useragent.security).to be_nil 10 | end 11 | end 12 | 13 | shared_examples "iTunes runs on" do |platform, os| 14 | it "should return '#{platform}' as its platform" do 15 | expect(@useragent.platform).to eq(platform) 16 | end 17 | 18 | it "should return '#{os}' as its OS" do 19 | expect(@useragent.os).to eq(os) 20 | end 21 | end 22 | 23 | shared_examples "iTunes has version number" do |version| 24 | it "should return '#{version}' as its version" do 25 | expect(@useragent.version).to eq(version) 26 | end 27 | end 28 | 29 | shared_examples "iTunes has WebKit build number" do |version| 30 | it "should return '#{version}' as its WebKit build number" do 31 | expect(@useragent.build).to eq(version) 32 | end 33 | end 34 | 35 | describe "UserAgent: iTunes/10.6.1 (Macintosh; Intel Mac OS X 10.7.3) AppleWebKit/534.53.11" do 36 | before do 37 | @useragent = UserAgent.parse("iTunes/10.6.1 (Macintosh; Intel Mac OS X 10.7.3) AppleWebKit/534.53.11") 38 | end 39 | 40 | it_behaves_like "iTunes" 41 | it_behaves_like "iTunes runs on", "Macintosh", "OS X 10.7.3" 42 | it_behaves_like "iTunes has version number", "10.6.1" 43 | it_behaves_like "iTunes has WebKit build number", "534.53.11" 44 | end 45 | 46 | describe "UserAgent: iTunes/12.0.1 (Macintosh; OS X 10.10) AppleWebKit/0600.1.25" do 47 | before do 48 | @useragent = UserAgent.parse("iTunes/12.0.1 (Macintosh; OS X 10.10) AppleWebKit/0600.1.25") 49 | end 50 | 51 | it_behaves_like "iTunes" 52 | it_behaves_like "iTunes runs on", "Macintosh", "OS X 10.10" 53 | it_behaves_like "iTunes has version number", "12.0.1" 54 | it_behaves_like "iTunes has WebKit build number", "0600.1.25" 55 | 56 | # this really only needs tested once since we're fixing the parse error for Windows only 57 | it "should return 'OS X 10.10' as its full OS" do 58 | expect(@useragent.full_os).to eq("OS X 10.10") 59 | end 60 | end 61 | 62 | describe "UserAgent: iTunes/11.1.5 (Windows; Microsoft Windows 7 x64 Business Edition Service Pack 1 (Build 7601)) AppleWebKit/537.60.15" do 63 | before do 64 | @useragent = UserAgent.parse("iTunes/11.1.5 (Windows; Microsoft Windows 7 x64 Business Edition Service Pack 1 (Build 7601)) AppleWebKit/537.60.15") 65 | end 66 | 67 | it_behaves_like "iTunes" 68 | it_behaves_like "iTunes runs on", "Windows", "Windows 7" 69 | it_behaves_like "iTunes has version number", "11.1.5" 70 | it_behaves_like "iTunes has WebKit build number", "537.60.15" 71 | 72 | it "should return 'Microsoft Windows 7 x64 Business Edition Service Pack 1 (Build 7601)' as its full OS" do 73 | expect(@useragent.full_os).to eq("Microsoft Windows 7 x64 Business Edition Service Pack 1 (Build 7601)") 74 | end 75 | end 76 | 77 | describe "UserAgent: iTunes/12.0.1 (Windows; Microsoft Windows 8 x64 Home Premium Edition (Build 9200)) AppleWebKit/7600.1017.0.24" do 78 | before do 79 | @useragent = UserAgent.parse("iTunes/12.0.1 (Windows; Microsoft Windows 8 x64 Home Premium Edition (Build 9200)) AppleWebKit/7600.1017.0.24") 80 | end 81 | 82 | it_behaves_like "iTunes" 83 | it_behaves_like "iTunes runs on", "Windows", "Windows 8" 84 | it_behaves_like "iTunes has version number", "12.0.1" 85 | it_behaves_like "iTunes has WebKit build number", "7600.1017.0.24" 86 | 87 | it "should return 'Microsoft Windows 8 x64 Home Premium Edition (Build 9200)' as its full OS" do 88 | expect(@useragent.full_os).to eq("Microsoft Windows 8 x64 Home Premium Edition (Build 9200)") 89 | end 90 | end 91 | 92 | describe "UserAgent: iTunes/12.0.1 (Macintosh; OS X 10.10.1) AppleWebKit/0600.1.25" do 93 | before do 94 | @useragent = UserAgent.parse("iTunes/12.0.1 (Macintosh; OS X 10.10.1) AppleWebKit/0600.1.25") 95 | end 96 | 97 | it_behaves_like "iTunes" 98 | it_behaves_like "iTunes runs on", "Macintosh", "OS X 10.10.1" 99 | it_behaves_like "iTunes has version number", "12.0.1" 100 | it_behaves_like "iTunes has WebKit build number", "0600.1.25" 101 | end 102 | 103 | describe "UserAgent: iTunes/9.1.1" do 104 | before do 105 | @useragent = UserAgent.parse("iTunes/9.1.1") 106 | end 107 | 108 | it_behaves_like "iTunes" 109 | it_behaves_like "iTunes has version number", "9.1.1" 110 | 111 | it "should return nil for WebKit build number" do 112 | expect(@useragent.build).to be_nil 113 | end 114 | 115 | it "should return nil for the OS" do 116 | expect(@useragent.os).to be_nil 117 | end 118 | 119 | it "should return nil for the platform" do 120 | expect(@useragent.platform).to be_nil 121 | end 122 | end 123 | 124 | describe "UserAgent: iTunes/10.7 Downcast/2.8.26.1005" do 125 | before do 126 | @useragent = UserAgent.parse("iTunes/10.7 Downcast/2.8.26.1005") 127 | end 128 | 129 | it_behaves_like "iTunes" 130 | it_behaves_like "iTunes has version number", "10.7" 131 | 132 | it "should return nil for WebKit build number" do 133 | expect(@useragent.build).to be_nil 134 | end 135 | 136 | it "should return nil for the OS" do 137 | expect(@useragent.os).to be_nil 138 | end 139 | 140 | it "should return nil for the platform" do 141 | expect(@useragent.platform).to be_nil 142 | end 143 | end 144 | -------------------------------------------------------------------------------- /lib/user_agent/browsers/windows_media_player.rb: -------------------------------------------------------------------------------- 1 | class UserAgent 2 | module Browsers 3 | # The user agent used by Windows Media Player or applications which utilize the 4 | # Windows Media SDK. 5 | # 6 | # @note Both VLC and libavformat impersonate Windows Media Player when they think they 7 | # are using MMS (Microsoft Media Services/Windows Media Server). 8 | class WindowsMediaPlayer < Base 9 | def self.extend?(agent) 10 | agent.detect do |useragent| 11 | %w(NSPlayer Windows-Media-Player WMFSDK).include?(useragent.product) && 12 | agent.version != "4.1.0.3856" && # 4.1.0.3856 is libavformat 13 | agent.version != "7.10.0.3059" && # used by VLC for mmsh support 14 | agent.version != "7.0.0.1956" # used by VLC for mmstu support 15 | end 16 | end 17 | 18 | # The Windows Media Format SDK version 19 | # 20 | # @return [Version, nil] The WMFSDK version 21 | def wmfsdk_version 22 | (respond_to?("WMFSDK") && self.send("WMFSDK").version) || nil 23 | end 24 | 25 | # Check if the client supports the WMFSDK version passed in. 26 | # 27 | # @param [String] version 28 | # The WMFSDK version to check for. For example, "9.0", "11.0", "12.0" 29 | # @return [true, false] Is this media player compatible with the passed WMFSDK version? 30 | def has_wmfsdk?(version) 31 | if wmfsdk_version && wmfsdk_version.to_s =~ /\A#{version}/ 32 | return true 33 | else 34 | return false 35 | end 36 | end 37 | 38 | # @return ["Windows Media Player"] All of the user agents we parse are Windows Media Player 39 | def browser 40 | "Windows Media Player" 41 | end 42 | 43 | # @return ["Windows"] All of the user agents we parse are on Windows 44 | def platform 45 | "Windows" 46 | end 47 | 48 | # @return [true, false] Is this Windows Media Player 6.4 (NSPlayer 4.1) or Media Player 6.0 (NSPlayer 3.2)? 49 | def classic? 50 | version.to_a[0] <= 4 51 | end 52 | 53 | # Check if our parsed OS is a mobile OS 54 | # 55 | # @return [true, false] Is this a mobile Windows Media Player? 56 | def mobile? 57 | ["Windows Phone 8", "Windows Phone 8.1"].include?(os) 58 | end 59 | 60 | # Parses the Windows Media Player version to figure out the host OS version 61 | # 62 | # User agents I have personally found: 63 | # 64 | # Windows 95 with Windows Media Player 6.4:: 65 | # NSPlayer/4.1.0.3857 66 | # 67 | # Windows 98 SE with Windows Media Player 6.01:: 68 | # NSPlayer/3.2.0.3564 69 | # 70 | # Womdpws 98 SE with Windows Media Player 6.4:: 71 | # NSPlayer/4.1.0.3857 72 | # NSPlayer/4.1.0.3925 73 | # 74 | # Windows 98 SE with Windows Media Player 7.1:: 75 | # NSPlayer/7.1.0.3055 76 | # 77 | # Windows 98 SE with Windows Media Player 9.0:: 78 | # Windows-Media-Player/9.00.00.2980 79 | # NSPlayer/9.0.0.2980 WMFSDK/9.0 80 | # 81 | # Windows 2000 with Windows Media Player 6.4:: 82 | # NSPlayer/4.1.0.3938 83 | # 84 | # Windows 2000 with Windows Media Player 7.1 (downgraded from WMP9):: 85 | # NSPlayer/9.0.0.3268 86 | # NSPlayer/9.0.0.3268 WMFSDK/9.0 87 | # NSPlayer/9.0.0.3270 WMFSDK/9.0 88 | # NSPlayer/9.0.0.2980 89 | # 90 | # Windows 2000 with Windows Media Player 9.0:: 91 | # NSPlayer/9.0.0.3270 WMFSDK/9.0 92 | # Windows-Media-Player/9.00.00.3367 93 | # 94 | # Windows XP with Windows Media Player 6.4:: 95 | # NSPlayer/4.1.0.3936 96 | # 97 | # Windows XP with Windows Media Player 9:: 98 | # NSPlayer/9.0.0.4503 99 | # NSPlayer/9.0.0.4503 WMFSDK/9.0 100 | # Windows-Media-Player/9.00.00.4503 101 | # 102 | # Windows XP with Windows Media Player 10:: 103 | # NSPlayer/10.0.0.3802 104 | # NSPlayer/10.0.0.3802 WMFSDK/10.0 105 | # Windows-Media-Player/10.00.00.3802 106 | # 107 | # Windows XP with Windows Media Player 11:: 108 | # NSPlayer/11.0.5721.5262 109 | # NSPlayer/11.0.5721.5262 WMFSDK/11.0 110 | # Windows-Media-Player/11.0.5721.5262 111 | # 112 | # Windows Vista with Windows Media Player 11:: 113 | # NSPlayer/11.00.6002.18392 WMFSDK/11.00.6002.18392 114 | # NSPlayer/11.0.6002.18005 115 | # NSPlayer/11.0.6002.18049 WMFSDK/11.0 116 | # Windows-Media-Player/11.0.6002.18311 117 | # 118 | # Windows 8.1 with Windows Media Player 12:: 119 | # NSPlayer/12.00.9600.17031 WMFSDK/12.00.9600.17031 120 | # 121 | # Windows 10 with Windows Media Player 12:: 122 | # Windows-Media-Player/12.0.9841.0 123 | # NSPlayer/12.00.9841.0000 WMFSDK/12.00.9841.0000 124 | # 125 | # Windows Phone 8.1 (Podcasts app):: 126 | # NSPlayer/12.00.9651.0000 WMFSDK/12.00.9651.0000 127 | def os 128 | # WMP 6.4 129 | if classic? 130 | case version.to_a[3] 131 | when 3564, 3925 then "Windows 98" 132 | when 3857 then "Windows 9x" 133 | when 3936 then "Windows XP" 134 | when 3938 then "Windows 2000" 135 | else "Windows" 136 | end 137 | 138 | # WMP 7/7.1 139 | elsif version.to_a[0] == 7 140 | case version.to_a[3] 141 | when 3055 then "Windows 98" 142 | else "Windows" 143 | end 144 | 145 | # WMP 8 was also known as "Windows Media Player for Windows XP" 146 | elsif version.to_a[0] == 8 147 | "Windows XP" 148 | 149 | # WMP 9/10 150 | elsif version.to_a[0] == 9 || version.to_a[0] == 10 151 | case version.to_a[3] 152 | when 2980 then "Windows 98/2000" 153 | when 3268, 3367, 3270 then "Windows 2000" 154 | when 3802, 4503 then "Windows XP" 155 | else "Windows" 156 | end 157 | 158 | # WMP 11/12 159 | elsif version.to_a[0] == 11 || version.to_a[0] == 12 160 | case version.to_a[2] 161 | when 9841, 9858, 9860, 162 | 9879 then "Windows 10" 163 | when 9651 then "Windows Phone 8.1" 164 | when 9600 then "Windows 8.1" 165 | when 9200 then "Windows 8" 166 | when 7600, 7601 then "Windows 7" 167 | when 6000, 6001, 6002 then "Windows Vista" 168 | when 5721 then "Windows XP" 169 | else "Windows" 170 | end 171 | else 172 | "Windows" 173 | end 174 | end 175 | end 176 | end 177 | end -------------------------------------------------------------------------------- /spec/browsers/opera_user_agent_spec.rb: -------------------------------------------------------------------------------- 1 | require 'user_agent' 2 | 3 | shared_examples_for "Opera browser" do 4 | it "should return 'Opera' as its browser" do 5 | expect(@useragent.browser).to eq("Opera") 6 | end 7 | 8 | it "should return a Version object for version" do 9 | expect(@useragent.version).to be_a(UserAgent::Version) 10 | end 11 | end 12 | 13 | # http://www.useragentstring.com/Opera12.14_id_19612.php 14 | describe "UserAgent: 'Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14'" do 15 | before do 16 | @useragent = UserAgent.parse("Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14") 17 | end 18 | 19 | it_should_behave_like "Opera browser" 20 | 21 | it "should return '12.14' as its version" do 22 | expect(@useragent.version).to eq("12.14") 23 | end 24 | 25 | it "should return 'Windows' as its platform" do 26 | expect(@useragent.platform).to eq("Windows") 27 | end 28 | 29 | it "should return 'Windows Vista' as its os" do 30 | expect(@useragent.os).to eq("Windows Vista") 31 | end 32 | end 33 | 34 | describe "UserAgent: 'Opera/9.27 (Macintosh; Intel Mac OS X; U; en)'" do 35 | before do 36 | @useragent = UserAgent.parse("Opera/9.27 (Macintosh; Intel Mac OS X; U; en)") 37 | end 38 | 39 | it_should_behave_like "Opera browser" 40 | 41 | it "should return '9.27' as its version" do 42 | expect(@useragent.version).to eq("9.27") 43 | end 44 | 45 | it "should return 'Macintosh' as its platform" do 46 | expect(@useragent.platform).to eq("Macintosh") 47 | end 48 | 49 | it "should return 'Intel Mac OS X' as its os" do 50 | expect(@useragent.os).to eq("Intel Mac OS X") 51 | end 52 | 53 | it "should return 'en' as its localization" do 54 | expect(@useragent.localization).to eq("en") 55 | end 56 | end 57 | 58 | describe "UserAgent: 'Opera/9.27 (Windows NT 5.1; U; en)'" do 59 | before do 60 | @useragent = UserAgent.parse("Opera/9.27 (Windows NT 5.1; U; en)") 61 | end 62 | 63 | it_should_behave_like "Opera browser" 64 | 65 | it "should return '9.27' as its version" do 66 | expect(@useragent.version).to eq("9.27") 67 | end 68 | 69 | it "should return 'Windows' as its platform" do 70 | expect(@useragent.platform).to eq("Windows") 71 | end 72 | 73 | it "should return 'Windows XP' as its os" do 74 | expect(@useragent.os).to eq("Windows XP") 75 | end 76 | 77 | it "should return 'en' as its localization" do 78 | expect(@useragent.localization).to eq("en") 79 | end 80 | end 81 | 82 | describe "UserAgent: 'Opera/9.80'" do 83 | before do 84 | @useragent = UserAgent.parse("Opera/9.80") 85 | end 86 | 87 | it_should_behave_like "Opera browser" 88 | 89 | it "should return '9.80' as its version" do 90 | expect(@useragent.version).to eq("9.80") 91 | end 92 | 93 | it "should return nil as its platform" do 94 | expect(@useragent.platform).to be_nil 95 | end 96 | 97 | it "should return nil as its os" do 98 | expect(@useragent.os).to be_nil 99 | end 100 | 101 | it "should return nil as its localization" do 102 | expect(@useragent.localization).to be_nil 103 | end 104 | end 105 | 106 | describe "UserAgent: 'Opera/9.80 (Macintosh; Intel Mac OS X; U; en) Presto/2.2.15 Version/10.10'" do 107 | before do 108 | @useragent = UserAgent.parse("Opera/9.80 (Macintosh; Intel Mac OS X; U; en) Presto/2.2.15 Version/10.10") 109 | end 110 | 111 | it_should_behave_like "Opera browser" 112 | 113 | it "should return '10.10' as its version" do 114 | expect(@useragent.version).to eq("10.10") 115 | end 116 | 117 | it "should return 'Macintosh' as its platform" do 118 | expect(@useragent.platform).to eq("Macintosh") 119 | end 120 | 121 | it "should return 'Intel Mac OS X' as its os" do 122 | expect(@useragent.os).to eq("Intel Mac OS X") 123 | end 124 | 125 | it "should return 'en' as its localization" do 126 | expect(@useragent.localization).to eq("en") 127 | end 128 | end 129 | 130 | describe "UserAgent: 'Opera/9.80 (Windows NT 6.0; U; en) Presto/2.2.15 Version/10.10'" do 131 | before do 132 | @useragent = UserAgent.parse("Opera/9.80 (Windows NT 6.0; U; en) Presto/2.2.15 Version/10.10") 133 | end 134 | 135 | it_should_behave_like "Opera browser" 136 | 137 | it "should return '10.10' as its version" do 138 | expect(@useragent.version).to eq("10.10") 139 | end 140 | 141 | it "should return 'Windows' as its platform" do 142 | expect(@useragent.platform).to eq("Windows") 143 | end 144 | 145 | it "should return 'Windows Vista' as its os" do 146 | expect(@useragent.os).to eq("Windows Vista") 147 | end 148 | 149 | it "should return 'en' as its localization" do 150 | expect(@useragent.localization).to eq("en") 151 | end 152 | end 153 | 154 | describe "UserAgent: 'Opera/9.80 (J2ME/MIDP; Opera Mini/9 (Compatible; MSIE:9.0; iPhone; BlackBerry9700; AppleWebKit/24.746; U; en) Presto/2.5.25 Version/10.54'" do 155 | before do 156 | @useragent = UserAgent.parse("Opera/9.80 (J2ME/MIDP; Opera Mini/9 (Compatible; MSIE:9.0; iPhone; BlackBerry9700; AppleWebKit/24.746; U; en) Presto/2.5.25 Version/10.54'") 157 | end 158 | 159 | it_should_behave_like "Opera browser" 160 | 161 | it { expect(@useragent).to be_mobile } 162 | end 163 | 164 | describe "UserAgent: 'Opera/9.80 (J2ME/MIDP; Opera Mini/9.80 (J2ME/23.377; U; en) Presto/2.5.25 Version/10.54'" do 165 | before do 166 | @useragent = UserAgent.parse("Opera/9.80 (J2ME/MIDP; Opera Mini/9.80 (J2ME/23.377; U; en) Presto/2.5.25 Version/10.54") 167 | end 168 | 169 | it_should_behave_like "Opera browser" 170 | 171 | it { expect(@useragent).to be_mobile } 172 | end 173 | 174 | # http://www.useragentstring.com/Opera%20Mini9.80_id_17936.php 175 | describe "UserAgent: 'Opera/9.80 (J2ME/MIDP; Opera Mini/9.80 (S60; SymbOS; Opera Mobi/23.348; U; en) Presto/2.5.25 Version/10.54'" do 176 | before do 177 | @useragent = UserAgent.parse("Opera/9.80 (J2ME/MIDP; Opera Mini/9.80 (S60; SymbOS; Opera Mobi/23.348; U; en) Presto/2.5.25 Version/10.54") 178 | end 179 | 180 | it_should_behave_like "Opera browser" 181 | 182 | it "should return '9.80' as its version" do 183 | expect(@useragent.version).to eq("9.80") 184 | end 185 | end 186 | 187 | # http://www.useragentstring.com/Opera%20Mini7.1.32694_id_19147.php 188 | describe "UserAgent: 'Opera/9.80 (iPhone; Opera Mini/7.1.32694/27.1407; U; en) Presto/2.8.119 Version/11.10'" do 189 | before do 190 | @useragent = UserAgent.parse("Opera/9.80 (iPhone; Opera Mini/7.1.32694/27.1407; U; en) Presto/2.8.119 Version/11.10") 191 | end 192 | 193 | it_should_behave_like "Opera browser" 194 | 195 | it "should return '7.1.32694' as its version" do 196 | expect(@useragent.version).to eq("7.1.32694") 197 | end 198 | end 199 | 200 | describe "Opera/9.80 (BREW Opera Mini/6.0.3/27.2354 U es) Presto/2.8.119 240X320 Samsung SCH-U485" do 201 | before do 202 | @useragent = UserAgent.parse("Opera/9.80 (BREW Opera Mini/6.0.3/27.2354 U es) Presto/2.8.119 240X320 Samsung SCH-U485") 203 | end 204 | 205 | it_should_behave_like "Opera browser" 206 | 207 | it "should return '6.0.3' as its version" do 208 | expect(@useragent.version).to eq("6.0.3") 209 | end 210 | end 211 | 212 | describe "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36 OPR/28.0.1750.48" do 213 | before do 214 | @useragent = UserAgent.parse("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36 OPR/28.0.1750.48") 215 | end 216 | 217 | it_should_behave_like "Opera browser" 218 | 219 | it "should return '28.0.1750.48' as it's version" do 220 | expect(@useragent.version).to eq("28.0.1750.48") 221 | end 222 | end 223 | -------------------------------------------------------------------------------- /spec/browsers/chrome_user_agent_spec.rb: -------------------------------------------------------------------------------- 1 | require 'user_agent' 2 | 3 | shared_examples_for "Chrome browser" do 4 | it "should return 'Chrome' as its browser" do 5 | expect(@useragent.browser).to eq("Chrome") 6 | end 7 | end 8 | 9 | # http://www.useragentstring.com/Chrome30.0.1599.17_id_19721.php 10 | describe "UserAgent: 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.17 Safari/537.36'" do 11 | before do 12 | @useragent = UserAgent.parse("Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.17 Safari/537.36") 13 | end 14 | 15 | it_should_behave_like "Chrome browser" 16 | 17 | it "should return '30.0.1599.17' as its version" do 18 | expect(@useragent.version).to eq("30.0.1599.17") 19 | end 20 | 21 | it "should return 'Windows' as its platform" do 22 | expect(@useragent.platform).to eq("Windows") 23 | end 24 | 25 | it "should return 'Windows 8' as its os" do 26 | expect(@useragent.os).to eq("Windows 8") 27 | end 28 | end 29 | 30 | # http://www.useragentstring.com/Chrome29.0.1547.62_id_19709.php 31 | describe "UserAgent: 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36'" do 32 | before do 33 | @useragent = UserAgent.parse("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36") 34 | end 35 | 36 | it_should_behave_like "Chrome browser" 37 | 38 | it "should return '29.0.1547.62' as its version" do 39 | expect(@useragent.version).to eq("29.0.1547.62") 40 | end 41 | 42 | it "should return 'Windows' as its platform" do 43 | expect(@useragent.platform).to eq("Windows") 44 | end 45 | 46 | it "should return 'Windows 7' as its os" do 47 | expect(@useragent.os).to eq("Windows 7") 48 | end 49 | end 50 | 51 | describe "UserAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36'" do 52 | before do 53 | @useragent = UserAgent.parse("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36") 54 | end 55 | 56 | it_should_behave_like "Chrome browser" 57 | 58 | it "should return '29.0.1547.57' as its version" do 59 | expect(@useragent.version).to eq("29.0.1547.57") 60 | end 61 | 62 | it "should return 'X11' as its platform" do 63 | expect(@useragent.platform).to eq("X11") 64 | end 65 | 66 | it "should return 'Linux x86_64' as its os" do 67 | expect(@useragent.os).to eq("Linux x86_64") 68 | end 69 | end 70 | 71 | describe "UserAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) CriOS/28.0.1500.16 Mobile/10B329 Safari/8536.25'" do 72 | before do 73 | @useragent = UserAgent.parse("Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) CriOS/28.0.1500.16 Mobile/10B329 Safari/8536.25") 74 | end 75 | 76 | it_should_behave_like "Chrome browser" 77 | 78 | it "should return '536.26' as its build" do 79 | expect(@useragent.build).to eq("536.26") 80 | end 81 | 82 | it "should return '28.0.1500.16' as its version" do 83 | expect(@useragent.version).to eq("28.0.1500.16") 84 | end 85 | 86 | it "should return '536.26' as its webkit version" do 87 | expect(@useragent.webkit.version).to eq("536.26") 88 | end 89 | 90 | it "should return 'iPhone' as its platform" do 91 | expect(@useragent.platform).to eq("iPhone") 92 | end 93 | 94 | it "should return 'iOS 6.1.3' as its os" do 95 | expect(@useragent.os).to eq("iOS 6.1.3") 96 | end 97 | 98 | it { expect(@useragent).to be_mobile } 99 | end 100 | 101 | describe "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.40 Safari/537.17" do 102 | before do 103 | @useragent = UserAgent.parse("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.40 Safari/537.17") 104 | end 105 | 106 | it "should return 'Macintosh' as its platform" do 107 | expect(@useragent.platform).to eq("Macintosh") 108 | end 109 | 110 | it "should return 'OS X 10.8.2' as its os" do 111 | expect(@useragent.os).to eq("OS X 10.8.2") 112 | end 113 | end 114 | 115 | describe "UserAgent: 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19'" do 116 | before do 117 | @useragent = UserAgent.parse("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19") 118 | end 119 | 120 | it_should_behave_like "Chrome browser" 121 | 122 | it "should return '535.19' as its build" do 123 | expect(@useragent.build).to eq("535.19") 124 | end 125 | 126 | it "should return '18.0.1025.168' as its version" do 127 | expect(@useragent.version).to eq("18.0.1025.168") 128 | end 129 | 130 | it "should return '535.19' as its webkit version" do 131 | expect(@useragent.webkit.version).to eq("535.19") 132 | end 133 | 134 | it "should return 'Windows' as its platform" do 135 | expect(@useragent.platform).to eq("Windows") 136 | end 137 | 138 | it "should return 'Windows 7' as its os" do 139 | expect(@useragent.os).to eq("Windows 7") 140 | end 141 | end 142 | 143 | describe "Mozilla/5.0 (Linux; Android 4.2; Nexus 7 Build/JOP40C) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19" do 144 | before do 145 | @useragent = UserAgent.parse("Mozilla/5.0 (Linux; Android 4.2; Nexus 7 Build/JOP40C) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19") 146 | end 147 | 148 | it "should return 'Chrome' as its browser" do 149 | expect(@useragent.browser).to eq("Chrome") 150 | end 151 | 152 | it "should return 'Android' as its platform" do 153 | expect(@useragent.platform).to eq("Android") 154 | end 155 | 156 | it "should return 'Android 4.2' as its os" do 157 | expect(@useragent.os).to eq("Android 4.2") 158 | end 159 | 160 | it { expect(@useragent).to be_mobile } 161 | end 162 | 163 | 164 | describe "UserAgent: 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.639.0 Safari/534.16'" do 165 | before do 166 | @useragent = UserAgent.parse("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.639.0 Safari/534.16") 167 | end 168 | 169 | it_should_behave_like "Chrome browser" 170 | 171 | it "should return '534.16' as its build" do 172 | expect(@useragent.build).to eq("534.16") 173 | end 174 | 175 | it "should return '10.0.639.0' as its version" do 176 | expect(@useragent.version).to eq("10.0.639.0") 177 | end 178 | 179 | it "should return '534.16' as its webkit version" do 180 | expect(@useragent.webkit.version).to eq("534.16") 181 | end 182 | 183 | it "should return 'Macintosh' as its platform" do 184 | expect(@useragent.platform).to eq("Macintosh") 185 | end 186 | 187 | it "should return 'OS X 10.6.5' as its os" do 188 | expect(@useragent.os).to eq("OS X 10.6.5") 189 | end 190 | 191 | it "should return 'en-US' as its localization" do 192 | expect(@useragent.localization).to eq("en-US") 193 | end 194 | 195 | it "should be greater than Chrome 8.0" do 196 | other = UserAgent.parse("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.231 Safari/534.10") 197 | expect(@useragent).to be > other 198 | end 199 | 200 | it "should not be less than Chrome 8.0" do 201 | other = UserAgent.parse("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.231 Safari/534.10") 202 | expect(@useragent).not_to be < other 203 | end 204 | end 205 | 206 | describe "UserAgent: 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.231 Safari/534.10'" do 207 | before do 208 | @useragent = UserAgent.parse("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.231 Safari/534.10") 209 | end 210 | 211 | it_should_behave_like "Chrome browser" 212 | 213 | it "should return '534.10' as its build" do 214 | expect(@useragent.build).to eq("534.10") 215 | end 216 | 217 | it "should return '8.0.552.231' as its version" do 218 | expect(@useragent.version).to eq("8.0.552.231") 219 | end 220 | 221 | it "should return '534.10' as its webkit version" do 222 | expect(@useragent.webkit.version).to eq("534.10") 223 | end 224 | 225 | it "should return 'Macintosh' as its platform" do 226 | expect(@useragent.platform).to eq("Macintosh") 227 | end 228 | 229 | it "should return 'OS X 10.6.5' as its os" do 230 | expect(@useragent.os).to eq("OS X 10.6.5") 231 | end 232 | 233 | it "should return 'en-US' as its localization" do 234 | expect(@useragent.localization).to eq("en-US") 235 | end 236 | end 237 | 238 | describe "UserAgent: 'Mozilla/5.0 AppleWebKit/534.10 Chrome/8.0.552.215 Safari/534.10'" do 239 | before do 240 | @useragent = UserAgent.parse("Mozilla/5.0 AppleWebKit/534.10 Chrome/8.0.552.215 Safari/534.10") 241 | end 242 | 243 | it_should_behave_like "Chrome browser" 244 | 245 | it "should return '534.10' as its build" do 246 | expect(@useragent.build).to eq("534.10") 247 | end 248 | 249 | it "should return '8.0.552.215' as its version" do 250 | expect(@useragent.version).to eq("8.0.552.215") 251 | end 252 | 253 | it "should return '534.10' as its webkit version" do 254 | expect(@useragent.webkit.version).to eq("534.10") 255 | end 256 | 257 | it "should return nil as its platform" do 258 | expect(@useragent.platform).to be_nil 259 | end 260 | 261 | it "should return nil as its os" do 262 | expect(@useragent.os).to be_nil 263 | end 264 | end 265 | 266 | describe "UserAgent: 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/6.0'" do 267 | before do 268 | @useragent = UserAgent.parse("Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/6.0") 269 | end 270 | 271 | it_should_behave_like "Chrome browser" 272 | 273 | it "should return '533.2' as its build" do 274 | expect(@useragent.build).to eq("533.2") 275 | end 276 | 277 | it "should return '6.0' as its version" do 278 | expect(@useragent.version).to eq("6.0") 279 | end 280 | 281 | it "should return '533.2' as its webkit version" do 282 | expect(@useragent.webkit.version).to eq("533.2") 283 | end 284 | 285 | it "should return 'Windows' as its platform" do 286 | expect(@useragent.platform).to eq("Windows") 287 | end 288 | 289 | it "should return 'Windows 7' as its os" do 290 | expect(@useragent.os).to eq("Windows 7") 291 | end 292 | 293 | it "should return 'en-US' as its localization" do 294 | expect(@useragent.localization).to eq("en-US") 295 | end 296 | end 297 | 298 | describe "UserAgent: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.0.2 Safari/525.13'" do 299 | before do 300 | @useragent = UserAgent.parse("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.0.2 Safari/525.13") 301 | end 302 | 303 | it_should_behave_like "Chrome browser" 304 | 305 | it "should return '525.13' as its build" do 306 | expect(@useragent.build).to eq("525.13") 307 | end 308 | 309 | it "should return '0.0.2' as its version" do 310 | expect(@useragent.version).to eq("0.0.2") 311 | end 312 | 313 | it "should return '525.13' as its webkit version" do 314 | expect(@useragent.webkit.version).to eq("525.13") 315 | end 316 | 317 | it "should return 'Windows' as its platform" do 318 | expect(@useragent.platform).to eq("Windows") 319 | end 320 | 321 | it "should return 'Windows XP' as its os" do 322 | expect(@useragent.os).to eq("Windows XP") 323 | end 324 | 325 | it "should return 'en-US' as its localization" do 326 | expect(@useragent.localization).to eq("en-US") 327 | end 328 | end 329 | 330 | describe "UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36" do 331 | before do 332 | @useragent = UserAgent.parse("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36") 333 | end 334 | 335 | it_should_behave_like "Chrome browser" 336 | 337 | it "should return '537.36' as its build" do 338 | expect(@useragent.build).to eq("537.36") 339 | end 340 | 341 | it "should return '29.0.1547.62' as its version" do 342 | expect(@useragent.version).to eq("29.0.1547.62") 343 | end 344 | 345 | it "should return '537.36' as its webkit version" do 346 | expect(@useragent.webkit.version).to eq("537.36") 347 | end 348 | 349 | it "should return 'X11' as its platform" do 350 | expect(@useragent.platform).to eq("X11") 351 | end 352 | 353 | it "should return 'Linux x86_64' as its os" do 354 | expect(@useragent.os).to eq("Linux x86_64") 355 | end 356 | end 357 | -------------------------------------------------------------------------------- /spec/browsers/windows_media_player_user_agent_spec.rb: -------------------------------------------------------------------------------- 1 | require 'user_agent' 2 | 3 | shared_examples "Windows Media Player" do 4 | it "should return 'Windows Media Player' as its browser" do 5 | expect(@useragent.browser).to eq("Windows Media Player") 6 | end 7 | 8 | it "should return 'Windows' as its platform" do 9 | expect(@useragent.platform).to eq("Windows") 10 | end 11 | 12 | it "should not identify as being classic" do 13 | expect(@useragent.classic?).to eq(false) 14 | end 15 | 16 | it "should be the desktop version" do 17 | expect(@useragent.mobile?).to eq(false) 18 | end 19 | end 20 | 21 | shared_examples "Windows Media Player Mobile" do 22 | it "should return 'Windows Media Player' as its browser" do 23 | expect(@useragent.browser).to eq("Windows Media Player") 24 | end 25 | 26 | it "should return 'Windows' as its platform" do 27 | expect(@useragent.platform).to eq("Windows") 28 | end 29 | 30 | it "should not identify as being classic" do 31 | expect(@useragent.classic?).to eq(false) 32 | end 33 | 34 | it "should be the desktop version" do 35 | expect(@useragent.mobile?).to eq(true) 36 | end 37 | end 38 | 39 | shared_examples "Windows Media Player Classic" do 40 | it "should return 'Windows Media Player' as its browser" do 41 | expect(@useragent.browser).to eq("Windows Media Player") 42 | end 43 | 44 | it "should return 'Windows' as its platform" do 45 | expect(@useragent.platform).to eq("Windows") 46 | end 47 | 48 | it "should identify as being classic" do 49 | expect(@useragent.classic?).to eq(true) 50 | end 51 | end 52 | 53 | shared_examples "Windows Media Player isn't using WMFSDK" do 54 | it "should return nil as its WMFSDK version" do 55 | expect(@useragent.wmfsdk_version).to be_nil 56 | end 57 | 58 | it "should not have WMFSDK9" do 59 | expect(@useragent.has_wmfsdk?("9")).to eq(false) 60 | end 61 | 62 | it "should not have WMFSDK10" do 63 | expect(@useragent.has_wmfsdk?("10")).to eq(false) 64 | end 65 | 66 | it "should not have WMFSDK11" do 67 | expect(@useragent.has_wmfsdk?("11")).to eq(false) 68 | end 69 | 70 | it "should not have WMFSDK12" do 71 | expect(@useragent.has_wmfsdk?("12")).to eq(false) 72 | end 73 | end 74 | 75 | shared_examples "Windows Media Player runs on" do |os| 76 | it "should return '#{os}' as its OS" do 77 | expect(@useragent.os).to eq(os) 78 | end 79 | end 80 | 81 | shared_examples "Windows Media Player has version number" do |version| 82 | it "should return '#{version}' as its version" do 83 | expect(@useragent.version).to eq(version) 84 | end 85 | end 86 | 87 | %w{4.1.0.3856 7.10.0.3059 7.0.0.1956}.each do |not_wmp| 88 | describe "UserAgent: NSPlayer/#{not_wmp}" do 89 | before do 90 | @useragent = UserAgent.parse("NSPlayer/#{not_wmp}") 91 | end 92 | 93 | it "should not return 'Windows Media Player' as its browser" do 94 | expect(@useragent.browser).not_to eq("Windows Media Player") 95 | end 96 | 97 | it "should not return 'Windows' as its platform" do 98 | expect(@useragent.platform).not_to eq("Windows") 99 | end 100 | end 101 | end 102 | 103 | %w{4.1.0.3857}.each do |win9x_wmp6| 104 | describe "UserAgent: NSPlayer/#{win9x_wmp6}" do 105 | before do 106 | @useragent = UserAgent.parse("NSPlayer/#{win9x_wmp6}") 107 | end 108 | 109 | it_behaves_like "Windows Media Player Classic" 110 | it_behaves_like "Windows Media Player isn't using WMFSDK" 111 | it_behaves_like "Windows Media Player runs on", "Windows 9x" 112 | it_behaves_like "Windows Media Player has version number", win9x_wmp6 113 | end 114 | end 115 | 116 | %w{3.2.0.3564 4.1.0.3925}.each do |win98_wmp6| 117 | describe "UserAgent: NSPlayer/#{win98_wmp6}" do 118 | before do 119 | @useragent = UserAgent.parse("NSPlayer/#{win98_wmp6}") 120 | end 121 | 122 | it_behaves_like "Windows Media Player Classic" 123 | it_behaves_like "Windows Media Player isn't using WMFSDK" 124 | it_behaves_like "Windows Media Player runs on", "Windows 98" 125 | it_behaves_like "Windows Media Player has version number", win98_wmp6 126 | end 127 | end 128 | 129 | %w{7.1.0.3055}.each do |win98_wmp71| 130 | describe "UserAgent: NSPlayer/#{win98_wmp71}" do 131 | before do 132 | @useragent = UserAgent.parse("NSPlayer/#{win98_wmp71}") 133 | end 134 | 135 | it_behaves_like "Windows Media Player" 136 | it_behaves_like "Windows Media Player isn't using WMFSDK" 137 | it_behaves_like "Windows Media Player runs on", "Windows 98" 138 | it_behaves_like "Windows Media Player has version number", win98_wmp71 139 | end 140 | end 141 | 142 | describe "UserAgent: Windows-Media-Player/9.00.00.2980" do 143 | before do 144 | @useragent = UserAgent.parse("Windows-Media-Player/9.00.00.2980") 145 | end 146 | 147 | it_behaves_like "Windows Media Player" 148 | it_behaves_like "Windows Media Player isn't using WMFSDK" 149 | it_behaves_like "Windows Media Player runs on", "Windows 98/2000" 150 | it_behaves_like "Windows Media Player has version number", "9.00.00.2980" 151 | end 152 | 153 | describe "UserAgent: NSPlayer/9.0.0.2980 WMFSDK/9.0" do 154 | before do 155 | @useragent = UserAgent.parse("NSPlayer/9.0.0.2980 WMFSDK/9.0") 156 | end 157 | 158 | it_behaves_like "Windows Media Player" 159 | it_behaves_like "Windows Media Player runs on", "Windows 98/2000" 160 | it_behaves_like "Windows Media Player has version number", "9.0.0.2980" 161 | 162 | it "should return '9.0' as its WMFSDK version" do 163 | expect(@useragent.wmfsdk_version).to eq("9.0") 164 | end 165 | 166 | it "should have WMFSDK9" do 167 | expect(@useragent.has_wmfsdk?("9.0")).to eq(true) 168 | end 169 | end 170 | 171 | describe "UserAgent: NSPlayer/4.1.0.3938" do 172 | before do 173 | @useragent = UserAgent.parse("NSPlayer/4.1.0.3938") 174 | end 175 | 176 | it_behaves_like "Windows Media Player Classic" 177 | it_behaves_like "Windows Media Player isn't using WMFSDK" 178 | it_behaves_like "Windows Media Player runs on", "Windows 2000" 179 | it_behaves_like "Windows Media Player has version number", "4.1.0.3938" 180 | end 181 | 182 | describe "UserAgent: NSPlayer/9.0.0.3268" do 183 | before do 184 | @useragent = UserAgent.parse("NSPlayer/9.0.0.3268") 185 | end 186 | 187 | it_behaves_like "Windows Media Player" 188 | it_behaves_like "Windows Media Player isn't using WMFSDK" 189 | it_behaves_like "Windows Media Player runs on", "Windows 2000" 190 | it_behaves_like "Windows Media Player has version number", "9.0.0.3268" 191 | end 192 | 193 | describe "UserAgent: NSPlayer/9.0.0.3268 WMFSDK/9.0" do 194 | before do 195 | @useragent = UserAgent.parse("NSPlayer/9.0.0.3268 WMFSDK/9.0") 196 | end 197 | 198 | it_behaves_like "Windows Media Player" 199 | it_behaves_like "Windows Media Player runs on", "Windows 2000" 200 | it_behaves_like "Windows Media Player has version number", "9.0.0.3268" 201 | 202 | it "should return '9.0' as its WMFSDK version" do 203 | expect(@useragent.wmfsdk_version).to eq("9.0") 204 | end 205 | 206 | it "should have WMFSDK9" do 207 | expect(@useragent.has_wmfsdk?("9.0")).to eq(true) 208 | end 209 | end 210 | 211 | describe "UserAgent: NSPlayer/9.0.0.3270 WMFSDK/9.0" do 212 | before do 213 | @useragent = UserAgent.parse("NSPlayer/9.0.0.3270 WMFSDK/9.0") 214 | end 215 | 216 | it_behaves_like "Windows Media Player" 217 | it_behaves_like "Windows Media Player runs on", "Windows 2000" 218 | it_behaves_like "Windows Media Player has version number", "9.0.0.3270" 219 | 220 | it "should return '9.0' as its WMFSDK version" do 221 | expect(@useragent.wmfsdk_version).to eq("9.0") 222 | end 223 | 224 | it "should have WMFSDK9" do 225 | expect(@useragent.has_wmfsdk?("9.0")).to eq(true) 226 | end 227 | end 228 | 229 | describe "UserAgent: Windows-Media-Player/9.00.00.3367" do 230 | before do 231 | @useragent = UserAgent.parse("Windows-Media-Player/9.00.00.3367") 232 | end 233 | 234 | it_behaves_like "Windows Media Player" 235 | it_behaves_like "Windows Media Player isn't using WMFSDK" 236 | it_behaves_like "Windows Media Player runs on", "Windows 2000" 237 | it_behaves_like "Windows Media Player has version number", "9.00.00.3367" 238 | end 239 | 240 | describe "UserAgent: NSPlayer/4.1.0.3936" do 241 | before do 242 | @useragent = UserAgent.parse("NSPlayer/4.1.0.3936") 243 | end 244 | 245 | it_behaves_like "Windows Media Player Classic" 246 | it_behaves_like "Windows Media Player isn't using WMFSDK" 247 | it_behaves_like "Windows Media Player runs on", "Windows XP" 248 | it_behaves_like "Windows Media Player has version number", "4.1.0.3936" 249 | end 250 | 251 | describe "UserAgent: NSPlayer/9.0.0.4503" do 252 | before do 253 | @useragent = UserAgent.parse("NSPlayer/9.0.0.4503") 254 | end 255 | 256 | it_behaves_like "Windows Media Player" 257 | it_behaves_like "Windows Media Player isn't using WMFSDK" 258 | it_behaves_like "Windows Media Player runs on", "Windows XP" 259 | it_behaves_like "Windows Media Player has version number", "9.0.0.4503" 260 | end 261 | 262 | describe "UserAgent: NSPlayer/9.0.0.4503 WMFSDK/9.0" do 263 | before do 264 | @useragent = UserAgent.parse("NSPlayer/9.0.0.4503 WMFSDK/9.0") 265 | end 266 | 267 | it_behaves_like "Windows Media Player" 268 | it_behaves_like "Windows Media Player runs on", "Windows XP" 269 | it_behaves_like "Windows Media Player has version number", "9.0.0.4503" 270 | 271 | it "should return '9.0' as its WMFSDK version" do 272 | expect(@useragent.wmfsdk_version).to eq("9.0") 273 | end 274 | 275 | it "should have WMFSDK9" do 276 | expect(@useragent.has_wmfsdk?("9.0")).to eq(true) 277 | end 278 | end 279 | 280 | describe "UserAgent: Windows-Media-Player/9.00.00.4503" do 281 | before do 282 | @useragent = UserAgent.parse("Windows-Media-Player/9.00.00.4503") 283 | end 284 | 285 | it_behaves_like "Windows Media Player" 286 | it_behaves_like "Windows Media Player runs on", "Windows XP" 287 | it_behaves_like "Windows Media Player isn't using WMFSDK" 288 | it_behaves_like "Windows Media Player has version number", "9.00.00.4503" 289 | end 290 | 291 | describe "UserAgent: NSPlayer/10.0.0.3802" do 292 | before do 293 | @useragent = UserAgent.parse("NSPlayer/10.0.0.3802") 294 | end 295 | 296 | it_behaves_like "Windows Media Player" 297 | it_behaves_like "Windows Media Player runs on", "Windows XP" 298 | it_behaves_like "Windows Media Player isn't using WMFSDK" 299 | it_behaves_like "Windows Media Player has version number", "10.0.0.3802" 300 | end 301 | 302 | describe "UserAgent: NSPlayer/10.0.0.3802 WMFSDK/10.0" do 303 | before do 304 | @useragent = UserAgent.parse("NSPlayer/10.0.0.3802 WMFSDK/10.0") 305 | end 306 | 307 | it_behaves_like "Windows Media Player" 308 | it_behaves_like "Windows Media Player runs on", "Windows XP" 309 | it_behaves_like "Windows Media Player has version number", "10.0.0.3802" 310 | 311 | it "should return '10.0' as its WMFSDK version" do 312 | expect(@useragent.wmfsdk_version).to eq("10.0") 313 | end 314 | 315 | it "should have WMFSDK10" do 316 | expect(@useragent.has_wmfsdk?("10.0")).to eq(true) 317 | end 318 | end 319 | 320 | describe "UserAgent: Windows-Media-Player/10.00.00.3802" do 321 | before do 322 | @useragent = UserAgent.parse("Windows-Media-Player/10.00.00.3802") 323 | end 324 | 325 | it_behaves_like "Windows Media Player" 326 | it_behaves_like "Windows Media Player runs on", "Windows XP" 327 | it_behaves_like "Windows Media Player isn't using WMFSDK" 328 | it_behaves_like "Windows Media Player has version number", "10.00.00.3802" 329 | end 330 | 331 | describe "UserAgent: NSPlayer/11.0.5721.5262" do 332 | before do 333 | @useragent = UserAgent.parse("NSPlayer/11.0.5721.5262") 334 | end 335 | 336 | it_behaves_like "Windows Media Player" 337 | it_behaves_like "Windows Media Player isn't using WMFSDK" 338 | it_behaves_like "Windows Media Player runs on", "Windows XP" 339 | it_behaves_like "Windows Media Player has version number", "11.0.5721.5262" 340 | end 341 | 342 | describe "UserAgent: NSPlayer/11.0.5721.5262 WMFSDK/11.0" do 343 | before do 344 | @useragent = UserAgent.parse("NSPlayer/11.0.5721.5262 WMFSDK/11.0") 345 | end 346 | 347 | it_behaves_like "Windows Media Player" 348 | it_behaves_like "Windows Media Player runs on", "Windows XP" 349 | it_behaves_like "Windows Media Player has version number", "11.0.5721.5262" 350 | 351 | it "should return '11.0' as its WMFSDK version" do 352 | expect(@useragent.wmfsdk_version).to eq("11.0") 353 | end 354 | 355 | it "should have WMFSDK11" do 356 | expect(@useragent.has_wmfsdk?("11.0")).to eq(true) 357 | end 358 | end 359 | 360 | describe "UserAgent: Windows-Media-Player/11.0.5721.5262" do 361 | before do 362 | @useragent = UserAgent.parse("Windows-Media-Player/11.0.5721.5262") 363 | end 364 | 365 | it_behaves_like "Windows Media Player" 366 | it_behaves_like "Windows Media Player isn't using WMFSDK" 367 | it_behaves_like "Windows Media Player runs on", "Windows XP" 368 | it_behaves_like "Windows Media Player has version number", "11.0.5721.5262" 369 | end 370 | 371 | describe "UserAgent: NSPlayer/11.00.6002.18392 WMFSDK/11.00.6002.18392" do 372 | before do 373 | @useragent = UserAgent.parse("NSPlayer/11.00.6002.18392 WMFSDK/11.00.6002.18392") 374 | end 375 | 376 | it_behaves_like "Windows Media Player" 377 | it_behaves_like "Windows Media Player runs on", "Windows Vista" 378 | it_behaves_like "Windows Media Player has version number", "11.00.6002.18392" 379 | 380 | it "should return '11.00.6002.18392' as its WMFSDK version" do 381 | expect(@useragent.wmfsdk_version).to eq("11.00.6002.18392") 382 | end 383 | 384 | it "should have WMFSDK11" do 385 | expect(@useragent.has_wmfsdk?("11.0")).to eq(true) 386 | end 387 | end 388 | 389 | describe "UserAgent: NSPlayer/11.0.6002.18005" do 390 | before do 391 | @useragent = UserAgent.parse("NSPlayer/11.0.6002.18005") 392 | end 393 | 394 | it_behaves_like "Windows Media Player" 395 | it_behaves_like "Windows Media Player isn't using WMFSDK" 396 | it_behaves_like "Windows Media Player runs on", "Windows Vista" 397 | it_behaves_like "Windows Media Player has version number", "11.0.6002.18005" 398 | end 399 | 400 | describe "UserAgent: NSPlayer/11.0.6002.18049 WMFSDK/11.0" do 401 | before do 402 | @useragent = UserAgent.parse("NSPlayer/11.0.6002.18049 WMFSDK/11.0") 403 | end 404 | 405 | it_behaves_like "Windows Media Player" 406 | it_behaves_like "Windows Media Player runs on", "Windows Vista" 407 | it_behaves_like "Windows Media Player has version number", "11.0.6002.18049" 408 | 409 | it "should return '11.0' as its WMFSDK version" do 410 | expect(@useragent.wmfsdk_version).to eq("11.0") 411 | end 412 | 413 | it "should have WMFSDK11" do 414 | expect(@useragent.has_wmfsdk?("11.0")).to eq(true) 415 | end 416 | end 417 | 418 | describe "UserAgent: Windows-Media-Player/11.0.6002.18311" do 419 | before do 420 | @useragent = UserAgent.parse("Windows-Media-Player/11.0.6002.18311") 421 | end 422 | 423 | it_behaves_like "Windows Media Player" 424 | it_behaves_like "Windows Media Player isn't using WMFSDK" 425 | it_behaves_like "Windows Media Player runs on", "Windows Vista" 426 | it_behaves_like "Windows Media Player has version number", "11.0.6002.18311" 427 | end 428 | 429 | # FIXME: User agents for Windows 7 and Windows 8 430 | 431 | describe "UserAgent: NSPlayer/12.00.9600.17031 WMFSDK/12.00.9600.17031" do 432 | before do 433 | @useragent = UserAgent.parse("NSPlayer/12.00.9600.17031 WMFSDK/12.00.9600.17031") 434 | end 435 | 436 | it_behaves_like "Windows Media Player" 437 | it_behaves_like "Windows Media Player runs on", "Windows 8.1" 438 | it_behaves_like "Windows Media Player has version number", "12.00.9600.17031" 439 | 440 | it "should return '12.00.9600.17031' as its WMFSDK version" do 441 | expect(@useragent.wmfsdk_version).to eq("12.00.9600.17031") 442 | end 443 | 444 | it "should have WMFSDK12" do 445 | expect(@useragent.has_wmfsdk?("12.0")).to eq(true) 446 | end 447 | end 448 | 449 | describe "UserAgent: Windows-Media-Player/12.0.9841.0" do 450 | before do 451 | @useragent = UserAgent.parse("Windows-Media-Player/12.0.9841.0") 452 | end 453 | 454 | it_behaves_like "Windows Media Player" 455 | it_behaves_like "Windows Media Player runs on", "Windows 10" 456 | it_behaves_like "Windows Media Player has version number", "12.0.9841.0" 457 | end 458 | 459 | describe "UserAgent: NSPlayer/12.00.9841.0000 WMFSDK/12.00.9841.0000" do 460 | before do 461 | @useragent = UserAgent.parse("NSPlayer/12.00.9841.0000 WMFSDK/12.00.9841.0000") 462 | end 463 | 464 | it_behaves_like "Windows Media Player" 465 | it_behaves_like "Windows Media Player runs on", "Windows 10" 466 | it_behaves_like "Windows Media Player has version number", "12.00.9841.0000" 467 | 468 | it "should return '12.00.9841.0000' as its WMFSDK version" do 469 | expect(@useragent.wmfsdk_version).to eq("12.00.9841.0000") 470 | end 471 | 472 | it "should have WMFSDK12" do 473 | expect(@useragent.has_wmfsdk?("12.0")).to eq(true) 474 | end 475 | end 476 | 477 | describe "UserAgent: NSPlayer/12.00.9651.0000 WMFSDK/12.00.9651.0000" do 478 | before do 479 | @useragent = UserAgent.parse("NSPlayer/12.00.9651.0000 WMFSDK/12.00.9651.0000") 480 | end 481 | 482 | it_behaves_like "Windows Media Player Mobile" 483 | it_behaves_like "Windows Media Player runs on", "Windows Phone 8.1" 484 | it_behaves_like "Windows Media Player has version number", "12.00.9651.0000" 485 | 486 | it "should return '12.00.9651.0000' as its WMFSDK version" do 487 | expect(@useragent.wmfsdk_version).to eq("12.00.9651.0000") 488 | end 489 | 490 | it "should have WMFSDK12" do 491 | expect(@useragent.has_wmfsdk?("12.0")).to eq(true) 492 | end 493 | end 494 | -------------------------------------------------------------------------------- /spec/browsers/internet_explorer_user_agent_spec.rb: -------------------------------------------------------------------------------- 1 | require 'user_agent' 2 | 3 | shared_examples_for "Internet Explorer browser" do 4 | it "should return 'Internet Explorer' as its browser" do 5 | expect(@useragent.browser).to eq("Internet Explorer") 6 | end 7 | 8 | it "should return 'Windows' as its platform" do 9 | expect(@useragent.platform).to eq("Windows") 10 | end 11 | end 12 | 13 | describe "UserAgent: Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko" do 14 | before do 15 | @useragent = UserAgent.parse("Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko") 16 | end 17 | 18 | it_should_behave_like "Internet Explorer browser" 19 | 20 | it "should return '11.0' as its version" do 21 | expect(@useragent.version).to eq("11.0") 22 | end 23 | 24 | it "should return 'Windows 7' as its os" do 25 | expect(@useragent.os).to eq("Windows 7") 26 | end 27 | 28 | it "should have a higher version number than IE10" do 29 | expect(@useragent.version).to be > 30 | UserAgent.parse("Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)").version 31 | end 32 | end 33 | 34 | describe "UserAgent: Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko" do 35 | before do 36 | @useragent = UserAgent.parse("Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko") 37 | end 38 | 39 | it_should_behave_like "Internet Explorer browser" 40 | 41 | it "should return '11.0' as its version" do 42 | expect(@useragent.version).to eq("11.0") 43 | end 44 | 45 | it "should return 'Windows 8.1' as its os" do 46 | expect(@useragent.os).to eq("Windows 8.1") 47 | end 48 | end 49 | 50 | describe "UserAgent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko" do 51 | before do 52 | @useragent = UserAgent.parse("Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko") 53 | end 54 | 55 | it_should_behave_like "Internet Explorer browser" 56 | 57 | it "should return '11.0' as its version" do 58 | expect(@useragent.version).to eq("11.0") 59 | end 60 | 61 | it "should return 'Windows 7' as its os" do 62 | expect(@useragent.os).to eq("Windows 7") 63 | end 64 | end 65 | 66 | describe "UserAgent: Mozilla/5.0 (IE 11.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C; rv:11.0) like Gecko" do 67 | before do 68 | @useragent = UserAgent.parse("Mozilla/5.0 (IE 11.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C; rv:11.0) like Gecko") 69 | end 70 | 71 | it_should_behave_like "Internet Explorer browser" 72 | 73 | it "should return '11.0' as its version" do 74 | expect(@useragent.version).to eq("11.0") 75 | end 76 | 77 | it "should return 'Windows 8.1' as its os" do 78 | expect(@useragent.os).to eq("Windows 8.1") 79 | end 80 | 81 | it "should have a higher version number than IE10" do 82 | expect(@useragent.version).to be > 83 | UserAgent.parse("Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)").version 84 | end 85 | end 86 | 87 | describe "UserAgent: Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko" do 88 | before do 89 | @useragent = UserAgent.parse("Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko") 90 | end 91 | 92 | it_should_behave_like "Internet Explorer browser" 93 | 94 | it "should return '11.0' as its version" do 95 | expect(@useragent.version).to eq("11.0") 96 | end 97 | 98 | it "should return 'Windows 8.1' as its os" do 99 | expect(@useragent.os).to eq("Windows 8.1") 100 | end 101 | 102 | it "should have a higher version number than IE10" do 103 | expect(@useragent.version).to be > 104 | UserAgent.parse("Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)").version 105 | end 106 | end 107 | 108 | describe "UserAgent: 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko'" do 109 | before do 110 | @useragent = UserAgent.parse("Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko") 111 | end 112 | 113 | it_should_behave_like "Internet Explorer browser" 114 | 115 | it "should return '11.0' as its version", :focus => true do 116 | expect(@useragent.version).to eq("11.0") 117 | end 118 | 119 | it "should return 'Windows 8.1' as its os" do 120 | expect(@useragent.os).to eq("Windows 8.1") 121 | end 122 | 123 | it "should have a higher version number than IE10" do 124 | expect(@useragent.version).to be > 125 | UserAgent.parse('Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)').version 126 | end 127 | end 128 | 129 | describe "UserAgent: Mozilla/5.0 (Windows NT 6.1; Trident/8.0; rv:11.0) like Gecko" do 130 | before do 131 | @useragent = UserAgent.parse("Mozilla/5.0 (Windows NT 6.1; Trident/8.0; rv:11.0) like Gecko") 132 | end 133 | 134 | it_should_behave_like "Internet Explorer browser" 135 | 136 | it "should return '11.0' as its version" do 137 | expect(@useragent.version).to eq("11.0") 138 | end 139 | 140 | it "should return '11.0' as its real version" do 141 | expect(@useragent.real_version).to eq("11.0") 142 | end 143 | 144 | it { expect(@useragent).not_to be_compatibility_view } 145 | end 146 | 147 | describe "UserAgent: 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)'" do 148 | before do 149 | @useragent = UserAgent.parse("Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)") 150 | end 151 | 152 | it_should_behave_like "Internet Explorer browser" 153 | 154 | it "should return '10.0' as its version" do 155 | expect(@useragent.version).to eq("10.0") 156 | end 157 | 158 | it "should return 'Windows 8' as its os" do 159 | expect(@useragent.os).to eq("Windows 8") 160 | end 161 | 162 | it "should have a higher version number than IE9" do 163 | expect(@useragent.version).to be > 164 | UserAgent.parse('Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.2; ARM; Trident/6.0; Touch; .NET4.0E; .NET4.0C; Tablet PC 2.0)').version 165 | end 166 | 167 | it { expect(@useragent).not_to be_mobile } 168 | end 169 | 170 | describe "UserAgent: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; ARM; Trident/6.0; Touch; .NET4.0E; .NET4.0C; Tablet PC 2.0)'" do 171 | before do 172 | @useragent = UserAgent.parse("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; ARM; Trident/6.0; Touch; .NET4.0E; .NET4.0C; Tablet PC 2.0)") 173 | end 174 | 175 | it_should_behave_like "Internet Explorer browser" 176 | 177 | it "should return '7.0' as its version" do 178 | expect(@useragent.version).to eq("7.0") 179 | end 180 | 181 | it "should return 'Windows 8' as its os" do 182 | expect(@useragent.os).to eq("Windows 8") 183 | end 184 | 185 | it { expect(@useragent).to be_compatibility_view } 186 | it { expect(@useragent).not_to be_mobile } 187 | end 188 | 189 | describe "UserAgent: 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; ARM; Trident/6.0; Touch)'" do 190 | before do 191 | @useragent = UserAgent.parse("Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; ARM; Trident/6.0; Touch)") 192 | end 193 | 194 | it_should_behave_like "Internet Explorer browser" 195 | 196 | it "should return '10.0' as its version" do 197 | expect(@useragent.version).to eq("10.0") 198 | end 199 | 200 | it "should return 'Windows 8' as its os" do 201 | expect(@useragent.os).to eq("Windows 8") 202 | end 203 | 204 | it { expect(@useragent).not_to be_compatibility_view } 205 | it { expect(@useragent).not_to be_mobile } 206 | end 207 | 208 | describe "UserAgent: 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)'" do 209 | before do 210 | @useragent = UserAgent.parse("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)") 211 | end 212 | 213 | it_should_behave_like "Internet Explorer browser" 214 | 215 | it "should return '9.0' as its version" do 216 | expect(@useragent.version).to eq("9.0") 217 | end 218 | 219 | it "should return 'Windows 7' as its os" do 220 | expect(@useragent.os).to eq("Windows 7") 221 | end 222 | 223 | it { expect(@useragent).not_to be_mobile } 224 | end 225 | 226 | describe "UserAgent: 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)'" do 227 | before do 228 | @useragent = UserAgent.parse("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)") 229 | end 230 | 231 | it_should_behave_like "Internet Explorer browser" 232 | 233 | it "should return '9.0' as its version" do 234 | expect(@useragent.version).to eq("9.0") 235 | end 236 | 237 | it "should return 'Windows 7' as its os" do 238 | expect(@useragent.os).to eq("Windows 7") 239 | end 240 | 241 | it { expect(@useragent).not_to be_compatibility_view } 242 | it { expect(@useragent).not_to be_mobile } 243 | end 244 | 245 | describe "UserAgent: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)' Compat View" do 246 | before do 247 | @useragent = UserAgent.parse("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)") 248 | end 249 | 250 | it_should_behave_like "Internet Explorer browser" 251 | 252 | it "should return '7.0' as its version" do 253 | expect(@useragent.version).to eq("7.0") 254 | end 255 | 256 | it "should return 'Windows 7' as its os" do 257 | expect(@useragent.os).to eq("Windows 7") 258 | end 259 | 260 | it { expect(@useragent).to be_compatibility_view } 261 | it { expect(@useragent).not_to be_mobile } 262 | end 263 | 264 | describe "UserAgent: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)'" do 265 | before do 266 | @useragent = UserAgent.parse("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)") 267 | end 268 | 269 | it_should_behave_like "Internet Explorer browser" 270 | 271 | it "should return '7.0' as its version" do 272 | expect(@useragent.version).to eq("7.0") 273 | end 274 | 275 | it "should return 'Windows Vista' as its os" do 276 | expect(@useragent.os).to eq("Windows Vista") 277 | end 278 | end 279 | 280 | describe "UserAgent: 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)'" do 281 | before do 282 | @useragent = UserAgent.parse("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)") 283 | end 284 | 285 | it_should_behave_like "Internet Explorer browser" 286 | 287 | it "should return '6.0' as its version" do 288 | expect(@useragent.version).to eq("6.0") 289 | end 290 | 291 | it "should return 'Windows XP' as its os" do 292 | expect(@useragent.os).to eq("Windows XP") 293 | end 294 | 295 | it "should be == 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)'" do 296 | expect(@useragent).to eq(@useragent) 297 | end 298 | 299 | it "should not be == 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.1)'" do 300 | expect(@useragent).not_to eq(UserAgent.parse("Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.1)")) 301 | end 302 | 303 | it "should be > 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.1)'" do 304 | expect(@useragent).to be > UserAgent.parse("Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.1)") 305 | end 306 | 307 | it "should not be < 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.1)'" do 308 | expect(@useragent).not_to be < UserAgent.parse("Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.1)") 309 | end 310 | 311 | it "should be >= 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.1)'" do 312 | expect(@useragent).to be >= UserAgent.parse("Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.1)") 313 | end 314 | 315 | it "should not be >= 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)'" do 316 | expect(@useragent).not_to be >= UserAgent.parse("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)") 317 | end 318 | 319 | it "should be <= 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)'" do 320 | expect(@useragent).to be <= UserAgent.parse("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)") 321 | end 322 | 323 | it "should not be <= 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.1)'" do 324 | expect(@useragent).not_to be <= UserAgent.parse("Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.1)") 325 | end 326 | end 327 | 328 | describe "UserAgent: 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.1)'" do 329 | before do 330 | @useragent = UserAgent.parse("Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.1)") 331 | end 332 | 333 | it_should_behave_like "Internet Explorer browser" 334 | 335 | it "should return '5.5' as its version" do 336 | expect(@useragent.version).to eq("5.5") 337 | end 338 | 339 | it "should return 'Windows XP' as its os" do 340 | expect(@useragent.os).to eq("Windows XP") 341 | end 342 | end 343 | 344 | describe "UserAgent: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; SAMSUNG; SGH-i917)'" do 345 | before do 346 | @useragent = UserAgent.parse("Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; SAMSUNG; SGH-i917)") 347 | end 348 | 349 | it_should_behave_like "Internet Explorer browser" 350 | 351 | it "should return '7.0' as its version" do 352 | expect(@useragent.version).to eq("7.0") 353 | end 354 | 355 | it "should return 'Windows Phone OS 7.0' as its os" do 356 | expect(@useragent.os).to eq("Windows Phone OS 7.0") 357 | end 358 | 359 | it { expect(@useragent).to be_mobile } 360 | end 361 | 362 | describe "UserAgent: 'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 625; Vodafone)'" do 363 | before do 364 | @useragent = UserAgent.parse("Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 625; Vodafone)") 365 | end 366 | 367 | it_should_behave_like "Internet Explorer browser" 368 | 369 | it "should return '10.0' as its version" do 370 | expect(@useragent.version).to eq("10.0") 371 | end 372 | 373 | it "should return 'Windows Phone 8.0' as its os" do 374 | expect(@useragent.os).to eq("Windows Phone 8.0") 375 | end 376 | 377 | it { expect(@useragent).to be_mobile } 378 | end 379 | 380 | describe "Mozilla/5.0 (MSIE 8.0; Windows NT 6.0; Trident/7.0; rv:11.0) like Gecko" do 381 | before do 382 | @useragent = UserAgent.parse("Mozilla/5.0 (MSIE 8.0; Windows NT 6.0; Trident/7.0; rv:11.0) like Gecko") 383 | end 384 | 385 | it "should return '8.0' as its version" do 386 | expect(@useragent.version).to eq("8.0") 387 | end 388 | 389 | it "should return '11.0' as its real version" do 390 | expect(@useragent.real_version).to eq("11.0") 391 | end 392 | 393 | it { expect(@useragent).to be_compatibility_view } 394 | end 395 | 396 | describe "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; BOIE9;ENUS))" do 397 | before do 398 | @useragent = UserAgent.parse("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; BOIE9;ENUS))") 399 | end 400 | 401 | it "should return '9.0' as its version" do 402 | expect(@useragent.version).to eq("9.0") 403 | end 404 | 405 | it "should return '11.0' as its real version" do 406 | expect(@useragent.real_version).to eq("11.0") 407 | end 408 | 409 | it { expect(@useragent).to be_compatibility_view } 410 | end 411 | 412 | describe "Non-Chrome Frame browsers" do 413 | before do 414 | @useragent = UserAgent.parse("Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.1)") 415 | end 416 | 417 | it_should_behave_like "Internet Explorer browser" 418 | 419 | it "shouldn't pose as chromeframe" do 420 | expect(@useragent.chromeframe).to be_nil 421 | end 422 | end 423 | 424 | describe "Chrome Frame installs before version 4.0" do 425 | before do 426 | @useragent = UserAgent.parse("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; chromeframe)") 427 | end 428 | 429 | it_should_behave_like "Internet Explorer browser" 430 | 431 | it "should return true as chromeframe" do 432 | expect(@useragent.chromeframe).to be_truthy 433 | end 434 | 435 | it "shouldn't have a version" do 436 | expect(@useragent.chromeframe).not_to respond_to(:version) 437 | end 438 | end 439 | 440 | describe "Chrome Frame from version 4.0 on" do 441 | context "as separate product" do 442 | before do 443 | @useragent = UserAgent.parse("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) chromeframe/4.0") 444 | end 445 | 446 | it_should_behave_like "Internet Explorer browser" 447 | 448 | it "should return true as chromeframe" do 449 | expect(@useragent.chromeframe).to be_truthy 450 | end 451 | 452 | it "should have a version" do 453 | expect(@useragent.chromeframe.version).to eq("4.0") 454 | end 455 | end 456 | 457 | context "as versioned comment" do 458 | before do 459 | @useragent = UserAgent.parse("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; chromeframe/4.0)") 460 | end 461 | 462 | it_should_behave_like "Internet Explorer browser" 463 | 464 | it "should return true as chromeframe" do 465 | expect(@useragent.chromeframe).to be_truthy 466 | end 467 | 468 | it "should have a version" do 469 | expect(@useragent.chromeframe.version).to eq("4.0") 470 | end 471 | end 472 | end 473 | 474 | describe "UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;)" do 475 | before do 476 | @useragent = UserAgent.parse("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;)") 477 | end 478 | 479 | it_should_behave_like "Internet Explorer browser" 480 | 481 | it "should not be considered to be in compatibility view" do 482 | expect(@useragent).not_to be_compatibility_view 483 | end 484 | end 485 | -------------------------------------------------------------------------------- /spec/browsers/gecko_user_agent_spec.rb: -------------------------------------------------------------------------------- 1 | require 'user_agent' 2 | 3 | shared_examples_for "Firefox browser" do 4 | it "should return 'Firefox' as its browser" do 5 | expect(@useragent.browser).to eq("Firefox") 6 | end 7 | 8 | it "should return :strong as its security" do 9 | expect(@useragent.security).to eq(:strong) 10 | end 11 | end 12 | 13 | describe 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0b8) Gecko/20100101 Firefox/4.0b8' do 14 | before do 15 | @useragent = UserAgent.parse('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0b8) Gecko/20100101 Firefox/4.0b8') 16 | end 17 | 18 | it_should_behave_like "Firefox browser" 19 | 20 | it "should return '4.0b8' as its version" do 21 | expect(@useragent.version).to eq("4.0b8") 22 | end 23 | 24 | it "should return '20100101' as its gecko version" do 25 | expect(@useragent.gecko.version).to eq("20100101") 26 | end 27 | 28 | it "should return 'Macintosh' as its platform" do 29 | expect(@useragent.platform).to eq("Macintosh") 30 | end 31 | 32 | it "should return 'OS X 10.6' as its os" do 33 | expect(@useragent.os).to eq("OS X 10.6") 34 | end 35 | 36 | it "should return nil as its localization" do 37 | expect(@useragent.localization).to be_nil 38 | end 39 | 40 | it { expect(@useragent).not_to be_mobile } 41 | end 42 | 43 | describe 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13' do 44 | before do 45 | @useragent = UserAgent.parse('Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13') 46 | end 47 | 48 | it_should_behave_like "Firefox browser" 49 | 50 | it "should return '3.6.13' as its version" do 51 | expect(@useragent.version).to eq("3.6.13") 52 | end 53 | 54 | it "should return '20101203' as its gecko version" do 55 | expect(@useragent.gecko.version).to eq("20101203") 56 | end 57 | 58 | it "should return 'Macintosh' as its platform" do 59 | expect(@useragent.platform).to eq("Macintosh") 60 | end 61 | 62 | it "should return 'OS X 10.6' as its os" do 63 | expect(@useragent.os).to eq("OS X 10.6") 64 | end 65 | 66 | it "should return 'en-US' as its localization" do 67 | expect(@useragent.localization).to eq("en-US") 68 | end 69 | 70 | it { expect(@useragent).not_to be_mobile } 71 | end 72 | 73 | describe "UserAgent: 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008070206 Firefox/3.0.1'" do 74 | before do 75 | @useragent = UserAgent.parse("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008070206 Firefox/3.0.1") 76 | end 77 | 78 | it_should_behave_like "Firefox browser" 79 | 80 | it "should return '3.0.1' as its version" do 81 | expect(@useragent.version).to eq("3.0.1") 82 | end 83 | 84 | it "should return '2008070206' as its gecko version" do 85 | expect(@useragent.gecko.version).to eq("2008070206") 86 | end 87 | 88 | it "should return 'X11' as its platform" do 89 | expect(@useragent.platform).to eq("X11") 90 | end 91 | 92 | it "should return 'Linux i686' as its os" do 93 | expect(@useragent.os).to eq("Linux i686") 94 | end 95 | 96 | it "should return 'en-US' as its localization" do 97 | expect(@useragent.localization).to eq("en-US") 98 | end 99 | 100 | it { expect(@useragent).not_to be_mobile } 101 | end 102 | 103 | describe "UserAgent: 'Mozilla/5.0 (X11; Linux x86_64; rv:27.0) Gecko/20100101 Firefox/27.0'" do 104 | before do 105 | @useragent = UserAgent.parse("Mozilla/5.0 (X11; Linux x86_64; rv:27.0) Gecko/20100101 Firefox/27.0") 106 | end 107 | 108 | it_should_behave_like "Firefox browser" 109 | 110 | it "should return '27.0' as its version" do 111 | expect(@useragent.version).to eq("27.0") 112 | end 113 | 114 | it "should return '20100101' as its gecko version" do 115 | expect(@useragent.gecko.version).to eq("20100101") 116 | end 117 | 118 | it "should return 'X11' as its platform" do 119 | expect(@useragent.platform).to eq("X11") 120 | end 121 | 122 | it "should return 'Linux x86_64' as its os" do 123 | expect(@useragent.os).to eq("Linux x86_64") 124 | end 125 | 126 | it { expect(@useragent).not_to be_mobile } 127 | end 128 | 129 | describe "UserAgent: 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14'" do 130 | before do 131 | @useragent = UserAgent.parse("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14") 132 | end 133 | 134 | it_should_behave_like "Firefox browser" 135 | 136 | it "should return '2.0.0.14' as its version" do 137 | expect(@useragent.version).to eq("2.0.0.14") 138 | end 139 | 140 | it "should return '20080404' as its gecko version" do 141 | expect(@useragent.gecko.version).to eq("20080404") 142 | end 143 | 144 | it "should return 'Macintosh' as its platform" do 145 | expect(@useragent.platform).to eq("Macintosh") 146 | end 147 | 148 | it "should return 'OS X' as its os" do 149 | expect(@useragent.os).to eq("OS X") 150 | end 151 | 152 | it "should return 'en-US' as its localization" do 153 | expect(@useragent.localization).to eq("en-US") 154 | end 155 | end 156 | 157 | describe "UserAgent: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14'" do 158 | before do 159 | @useragent = UserAgent.parse("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14") 160 | end 161 | 162 | it_should_behave_like "Firefox browser" 163 | 164 | it "should return '2.0.0.14' as its version" do 165 | expect(@useragent.version).to eq("2.0.0.14") 166 | end 167 | 168 | it "should return '20080404' as its gecko version" do 169 | expect(@useragent.gecko.version).to eq("20080404") 170 | end 171 | 172 | it "should return 'Windows' as its platform" do 173 | expect(@useragent.platform).to eq("Windows") 174 | end 175 | 176 | it "should return 'Windows XP' as its os" do 177 | expect(@useragent.os).to eq("Windows XP") 178 | end 179 | 180 | it "should return 'en-US' as its localization" do 181 | expect(@useragent.localization).to eq("en-US") 182 | end 183 | end 184 | 185 | describe "UserAgent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1'" do 186 | before do 187 | @useragent = UserAgent.parse("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1") 188 | end 189 | 190 | it_should_behave_like "Firefox browser" 191 | 192 | it "should return '16.0.1' as its version" do 193 | expect(@useragent.version).to eq("16.0.1") 194 | end 195 | 196 | it "should return '20121011' as its gecko version" do 197 | expect(@useragent.gecko.version).to eq("20121011") 198 | end 199 | 200 | it "should return 'Windows' as its platform" do 201 | expect(@useragent.platform).to eq("Windows") 202 | end 203 | 204 | it "should return 'Windows 7' as its os" do 205 | expect(@useragent.os).to eq("Windows 7") 206 | end 207 | 208 | it "should return nil as its localization" do 209 | expect(@useragent.localization).to be_nil 210 | end 211 | end 212 | 213 | describe "UserAgent: 'Mozilla/5.0 (Windows NT 6.1; Win64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1'" do 214 | before do 215 | @useragent = UserAgent.parse("Mozilla/5.0 (Windows NT 6.1; Win64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1") 216 | end 217 | 218 | it_should_behave_like "Firefox browser" 219 | 220 | it "should return '16.0.1' as its version" do 221 | expect(@useragent.version).to eq("16.0.1") 222 | end 223 | 224 | it "should return '20121011' as its gecko version" do 225 | expect(@useragent.gecko.version).to eq("20121011") 226 | end 227 | 228 | it "should return 'Windows' as its platform" do 229 | expect(@useragent.platform).to eq("Windows") 230 | end 231 | 232 | it "should return 'Windows 7' as its os" do 233 | expect(@useragent.os).to eq("Windows 7") 234 | end 235 | 236 | it "should return nil as its localization" do 237 | expect(@useragent.localization).to be_nil 238 | end 239 | end 240 | 241 | describe 'Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20100101 Firefox/17.0' do 242 | before do 243 | @useragent = UserAgent.parse('Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20100101 Firefox/17.0') 244 | end 245 | 246 | it_should_behave_like "Firefox browser" 247 | 248 | it "should return '17.0' as its version" do 249 | expect(@useragent.version).to eq("17.0") 250 | end 251 | 252 | it "should return '20100101' as its gecko version" do 253 | expect(@useragent.gecko.version).to eq("20100101") 254 | end 255 | 256 | it "should return 'Windows' as its platform" do 257 | expect(@useragent.platform).to eq("Windows") 258 | end 259 | 260 | it "should return 'Windows XP' as its os" do 261 | expect(@useragent.os).to eq("Windows XP") 262 | end 263 | 264 | it "should return nil as its localization" do 265 | expect(@useragent.localization).to be_nil 266 | end 267 | end 268 | 269 | describe 'UserAgent: Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20100101 Firefox/17.0' do 270 | before do 271 | @useragent = UserAgent.parse('Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20100101 Firefox/17.0') 272 | end 273 | 274 | it_should_behave_like "Firefox browser" 275 | 276 | it "should return '17.0' as its version" do 277 | expect(@useragent.version).to eq("17.0") 278 | end 279 | 280 | it "should return '20100101' as its gecko version" do 281 | expect(@useragent.gecko.version).to eq("20100101") 282 | end 283 | 284 | it "should return 'Windows' as its platform" do 285 | expect(@useragent.platform).to eq("Windows") 286 | end 287 | 288 | it "should return 'Windows 7' as its os" do 289 | expect(@useragent.os).to eq("Windows 7") 290 | end 291 | 292 | it "should return nil as its localization" do 293 | expect(@useragent.localization).to be_nil 294 | end 295 | end 296 | 297 | describe "UserAgent: 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.12) Gecko/20070508 Firefox/1.5.0.12'" do 298 | before do 299 | @useragent = UserAgent.parse("Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.12) Gecko/20070508 Firefox/1.5.0.12") 300 | end 301 | 302 | it_should_behave_like "Firefox browser" 303 | 304 | it "should return '1.5.0.12' as its version" do 305 | expect(@useragent.version).to eq("1.5.0.12") 306 | end 307 | 308 | it "should return '20070508' as its gecko version" do 309 | expect(@useragent.gecko.version).to eq("20070508") 310 | end 311 | 312 | it "should return 'Macintosh' as its platform" do 313 | expect(@useragent.platform).to eq("Macintosh") 314 | end 315 | 316 | it "should return 'PPC Mac OS X Mach-O' as its os" do 317 | expect(@useragent.os).to eq("OS X") 318 | end 319 | 320 | it "should return 'en-US' as its localization" do 321 | expect(@useragent.localization).to eq("en-US") 322 | end 323 | end 324 | 325 | describe "UserAgent: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070508 Firefox/1.5.0.12'" do 326 | before do 327 | @useragent = UserAgent.parse("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070508 Firefox/1.5.0.12") 328 | end 329 | 330 | it_should_behave_like "Firefox browser" 331 | 332 | it "should return '1.5.0.12' as its version" do 333 | expect(@useragent.version).to eq("1.5.0.12") 334 | end 335 | 336 | it "should return '20070508' as its gecko version" do 337 | expect(@useragent.gecko.version).to eq("20070508") 338 | end 339 | 340 | it "should return 'Windows' as its platform" do 341 | expect(@useragent.platform).to eq("Windows") 342 | end 343 | 344 | it "should return 'Windows XP' as its os" do 345 | expect(@useragent.os).to eq("Windows XP") 346 | end 347 | 348 | it "should return 'en-US' as its localization" do 349 | expect(@useragent.localization).to eq("en-US") 350 | end 351 | end 352 | 353 | describe "UserAgent: 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.4) Gecko/20060612 Firefox/1.5.0.4 Flock/0.7.0.17.1'" do 354 | before do 355 | @useragent = UserAgent.parse("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.4) Gecko/20060612 Firefox/1.5.0.4 Flock/0.7.0.17.1") 356 | end 357 | 358 | it_should_behave_like "Firefox browser" 359 | 360 | it "should return '1.5.0.4' as its version" do 361 | expect(@useragent.version).to eq("1.5.0.4") 362 | end 363 | 364 | it "should return '20060612' as its gecko version" do 365 | expect(@useragent.gecko.version).to eq("20060612") 366 | end 367 | 368 | it "should return 'X11' as its platform" do 369 | expect(@useragent.platform).to eq("X11") 370 | end 371 | 372 | it "should return 'Linux i686' as its os" do 373 | expect(@useragent.os).to eq("Linux i686") 374 | end 375 | 376 | it "should return 'en-US' as its localization" do 377 | expect(@useragent.localization).to eq("en-US") 378 | end 379 | end 380 | 381 | describe "UserAgent: 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en; rv:1.8.1.14) Gecko/20080409 Camino/1.6 (like Firefox/2.0.0.14)'" do 382 | before do 383 | @useragent = UserAgent.parse("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en; rv:1.8.1.14) Gecko/20080409 Camino/1.6 (like Firefox/2.0.0.14)") 384 | end 385 | 386 | it "should return 'Camino' as its browser" do 387 | expect(@useragent.browser).to eq("Camino") 388 | end 389 | 390 | it "should return '1.6' as its version" do 391 | expect(@useragent.version).to eq("1.6") 392 | end 393 | 394 | it "should return '20080409' as its gecko version" do 395 | expect(@useragent.gecko.version).to eq("20080409") 396 | end 397 | 398 | it "should return 'Macintosh' as its platform" do 399 | expect(@useragent.platform).to eq("Macintosh") 400 | end 401 | 402 | it "should return 'OS X' as its os" do 403 | expect(@useragent.os).to eq("OS X") 404 | end 405 | 406 | it "should return 'en' as its localization" do 407 | expect(@useragent.localization).to eq("en") 408 | end 409 | end 410 | 411 | describe 'UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1) Gecko/20061024 Iceweasel/2.0 (Debian-2.0+dfsg-1)' do 412 | before do 413 | @useragent = UserAgent.parse('Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1) Gecko/20061024 Iceweasel/2.0 (Debian-2.0+dfsg-1)') 414 | end 415 | 416 | it "should return 'Iceweasel' as its browser" do 417 | expect(@useragent.browser).to eq("Iceweasel") 418 | end 419 | 420 | it "should return '2.0' as its version" do 421 | expect(@useragent.version).to eq("2.0") 422 | end 423 | 424 | it "should return '20061024' as its gecko version" do 425 | expect(@useragent.gecko.version).to eq("20061024") 426 | end 427 | 428 | it "should return 'X11' as its platform" do 429 | expect(@useragent.platform).to eq("X11") 430 | end 431 | 432 | it "should return 'Linux i686' as its os" do 433 | expect(@useragent.os).to eq("Linux i686") 434 | end 435 | 436 | it "should return 'en-US' as its localization" do 437 | expect(@useragent.localization).to eq("en-US") 438 | end 439 | end 440 | 441 | describe 'UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.4) Gecko/20091017 SeaMonkey/2.0' do 442 | before do 443 | @useragent = UserAgent.parse('Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.4) Gecko/20091017 SeaMonkey/2.0') 444 | end 445 | 446 | it "should return 'Seamonkey' as its browser" do 447 | expect(@useragent.browser).to eq("Seamonkey") 448 | end 449 | 450 | it "should return '2.0' as its version" do 451 | expect(@useragent.version).to eq("2.0") 452 | end 453 | 454 | it "should return '20091017' as its gecko version" do 455 | expect(@useragent.gecko.version).to eq("20091017") 456 | end 457 | 458 | it "should return 'Macintosh' as its platform" do 459 | expect(@useragent.platform).to eq("Macintosh") 460 | end 461 | 462 | it "should return 'OS X 10.6' as its os" do 463 | expect(@useragent.os).to eq("OS X 10.6") 464 | end 465 | 466 | it "should return 'en-US' as its localization" do 467 | expect(@useragent.localization).to eq("en-US") 468 | end 469 | end 470 | 471 | describe 'Mozilla/5.0 (Android; Mobile; rv:19.0) Gecko/19.0 Firefox/19.0' do 472 | before do 473 | @useragent = UserAgent.parse('Mozilla/5.0 (Android; Mobile; rv:19.0) Gecko/19.0 Firefox/19.0') 474 | end 475 | 476 | it_behaves_like 'Firefox browser' 477 | 478 | it 'returns true for mobile?' do 479 | expect(@useragent.mobile?).to be true 480 | end 481 | 482 | it "returns 'Android' as the platform" do 483 | expect(@useragent.platform).to eq('Android') 484 | end 485 | 486 | it "returns 'Android' as the operating system" do 487 | expect(@useragent.os).to eq('Android') 488 | end 489 | end 490 | 491 | describe 'Mozilla/5.0 (Mobile; rv:41.0) Gecko/41.0 Firefox/41.0' do 492 | before do 493 | @useragent = UserAgent.parse('Mozilla/5.0 (Mobile; rv:41.0) Gecko/41.0 Firefox/41.0') 494 | end 495 | 496 | it_behaves_like 'Firefox browser' 497 | 498 | it 'returns true for mobile?' do 499 | expect(@useragent.mobile?).to be true 500 | end 501 | 502 | it "returns nil as the platform" do 503 | expect(@useragent.platform).to be_nil 504 | end 505 | 506 | it "returns nil as the operating system" do 507 | expect(@useragent.os).to be_nil 508 | end 509 | end 510 | 511 | describe 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:x.x.x) Gecko/20041107 Firefox/x.x' do 512 | before do 513 | @useragent = UserAgent.parse('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:x.x.x) Gecko/20041107 Firefox/x.x') 514 | end 515 | 516 | it_should_behave_like "Firefox browser" 517 | 518 | it "should return 'x.x' as its version" do 519 | expect(@useragent.version).to eq("x.x") 520 | end 521 | 522 | it "should return '20041107' as its gecko version" do 523 | expect(@useragent.gecko.version).to eq("20041107") 524 | end 525 | 526 | it "should return 'Windows' as its platform" do 527 | expect(@useragent.platform).to eq("Windows") 528 | end 529 | 530 | it "should return 'Windows XP' as its os" do 531 | expect(@useragent.os).to eq("Windows XP") 532 | end 533 | end 534 | 535 | shared_examples_for "PaleMoon browser" do 536 | it "should return 'PaleMoon' as its browser" do 537 | expect(@useragent.browser).to eq("PaleMoon") 538 | end 539 | end 540 | 541 | describe 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.7) Gecko/20140802 Firefox/24.7 PaleMoon/24.7.1' do 542 | before do 543 | @useragent = UserAgent.parse('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.7) Gecko/20140802 Firefox/24.7 PaleMoon/24.7.1') 544 | end 545 | 546 | it_should_behave_like "PaleMoon browser" 547 | 548 | it "should return '24.7.1' as its version" do 549 | expect(@useragent.version).to eq("24.7.1") 550 | end 551 | 552 | it "should return '20140802' as its gecko version" do 553 | expect(@useragent.gecko.version).to eq("20140802") 554 | end 555 | 556 | it "should return '24.7' as its firefox version" do 557 | expect(@useragent.firefox.version).to eq("24.7") 558 | end 559 | 560 | it "should return 'Windows' as its platform" do 561 | expect(@useragent.platform).to eq("Windows") 562 | end 563 | 564 | it "should return 'Windows 7' as its os" do 565 | expect(@useragent.os).to eq("Windows 7") 566 | end 567 | end 568 | 569 | describe 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20141001 PaleMoon/25.0.0' do 570 | before do 571 | @useragent = UserAgent.parse('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20141001 PaleMoon/25.0.0') 572 | end 573 | 574 | it_should_behave_like "PaleMoon browser" 575 | 576 | it "should return '25.0.0' as its version" do 577 | expect(@useragent.version).to eq("25.0.0") 578 | end 579 | 580 | it "should return '20141001' as its gecko version" do 581 | expect(@useragent.gecko.version).to eq("20141001") 582 | end 583 | 584 | it "should return '24.7' as its firefox version" do 585 | expect { @useragent.firefox }.to raise_error(NoMethodError) 586 | end 587 | end -------------------------------------------------------------------------------- /spec/user_agent_spec.rb: -------------------------------------------------------------------------------- 1 | require 'user_agent' 2 | require 'ostruct' 3 | 4 | describe UserAgent do 5 | it "should require a product" do 6 | expect { UserAgent.new(nil) }.to raise_error(ArgumentError, "expected a value for product") 7 | end 8 | 9 | it "should split comment to an array if a string is passed in" do 10 | useragent = UserAgent.new("Mozilla", "5.0", "Macintosh; U; Intel Mac OS X 10_5_3; en-us") 11 | expect(useragent.comment).to eq(["Macintosh", "U", "Intel Mac OS X 10_5_3", "en-us"]) 12 | end 13 | 14 | it "should set version to nil if it is blank" do 15 | expect(UserAgent.new("Mozilla", "").version).to be_nil 16 | end 17 | 18 | it "should only output product when coerced to a string" do 19 | expect(UserAgent.new("Mozilla").to_str).to eq("Mozilla") 20 | end 21 | 22 | it "should output product and version when coerced to a string" do 23 | expect(UserAgent.new("Mozilla", "5.0").to_str).to eq("Mozilla/5.0") 24 | end 25 | 26 | it "should output product, version and comment when coerced to a string" do 27 | useragent = UserAgent.new("Mozilla", "5.0", ["Macintosh", "U", "Intel Mac OS X 10_5_3", "en-us"]) 28 | expect(useragent.to_str).to eq("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_3; en-us)") 29 | end 30 | 31 | it "should output product and comment when coerced to a string" do 32 | useragent = UserAgent.new("Mozilla", nil, ["Macintosh"]) 33 | expect(useragent.to_str).to eq("Mozilla (Macintosh)") 34 | end 35 | 36 | it "should be eql if both products are the same" do 37 | expect(UserAgent.new("Mozilla")).to eql(UserAgent.new("Mozilla")) 38 | end 39 | 40 | it "should not be eql if both products are the same" do 41 | expect(UserAgent.new("Mozilla")).not_to eql(UserAgent.new("Opera")) 42 | end 43 | 44 | it "should be eql if both products and versions are the same" do 45 | expect(UserAgent.new("Mozilla", "5.0")).to eql(UserAgent.new("Mozilla", "5.0")) 46 | end 47 | 48 | it "should not be eql if both products and versions are not the same" do 49 | expect(UserAgent.new("Mozilla", "5.0")).not_to eql(UserAgent.new("Mozilla", "4.0")) 50 | end 51 | 52 | it "should be eql if both products, versions and comments are the same" do 53 | expect(UserAgent.new("Mozilla", "5.0", ["Macintosh"])).to eql(UserAgent.new("Mozilla", "5.0", ["Macintosh"])) 54 | end 55 | 56 | it "should not be eql if both products, versions and comments are not the same" do 57 | expect(UserAgent.new("Mozilla", "5.0", ["Macintosh"])).not_to eql(UserAgent.new("Mozilla", "5.0", ["Windows"])) 58 | end 59 | 60 | it "should not be eql if both products, versions and comments are not the same" do 61 | expect(UserAgent.new("Mozilla", "5.0", ["Macintosh"])).not_to eql(UserAgent.new("Mozilla", "4.0", ["Macintosh"])) 62 | end 63 | 64 | it "should not be equal? if both products are the same" do 65 | expect(UserAgent.new("Mozilla")).not_to equal(UserAgent.new("Mozilla")) 66 | end 67 | 68 | it "should be == if products are the same" do 69 | expect(UserAgent.new("Mozilla")).to eq(UserAgent.new("Mozilla")) 70 | end 71 | 72 | it "should be == if products and versions are the same" do 73 | expect(UserAgent.new("Mozilla", "5.0")).to eq(UserAgent.new("Mozilla", "5.0")) 74 | end 75 | 76 | it "should not be == if products and versions are the different" do 77 | expect(UserAgent.new("Mozilla", "5.0")).not_to eq(UserAgent.new("Mozilla", "4.0")) 78 | end 79 | 80 | it "should return false if comparing different products" do 81 | expect(UserAgent.new("Mozilla")).not_to be <= UserAgent.new("Opera") 82 | end 83 | 84 | it "should not be > if products are the same" do 85 | expect(UserAgent.new("Mozilla")).not_to be > UserAgent.new("Mozilla") 86 | end 87 | 88 | it "should not be < if products are the same" do 89 | expect(UserAgent.new("Mozilla")).not_to be < UserAgent.new("Mozilla") 90 | end 91 | 92 | it "should be >= if products are the same" do 93 | expect(UserAgent.new("Mozilla")).to be >= UserAgent.new("Mozilla") 94 | end 95 | 96 | it "should be <= if products are the same" do 97 | expect(UserAgent.new("Mozilla")).to be <= UserAgent.new("Mozilla") 98 | end 99 | 100 | it "should be > if products are the same and version is greater" do 101 | expect(UserAgent.new("Mozilla", "5.0")).to be > UserAgent.new("Mozilla", "4.0") 102 | end 103 | 104 | it "should not be > if products are the same and version is less" do 105 | expect(UserAgent.new("Mozilla", "4.0")).not_to be > UserAgent.new("Mozilla", "5.0") 106 | end 107 | 108 | it "should be < if products are the same and version is less" do 109 | expect(UserAgent.new("Mozilla", "4.0")).to be < UserAgent.new("Mozilla", "5.0") 110 | end 111 | 112 | it "should not be < if products are the same and version is greater" do 113 | expect(UserAgent.new("Mozilla", "5.0")).not_to be < UserAgent.new("Mozilla", "4.0") 114 | end 115 | 116 | it "should be >= if products are the same and version is greater" do 117 | expect(UserAgent.new("Mozilla", "5.0")).to be >= UserAgent.new("Mozilla", "4.0") 118 | end 119 | 120 | it "should not be >= if products are the same and version is less" do 121 | expect(UserAgent.new("Mozilla", "4.0")).not_to be >= UserAgent.new("Mozilla", "5.0") 122 | end 123 | 124 | it "should be <= if products are the same and version is less" do 125 | expect(UserAgent.new("Mozilla", "4.0")).to be <= UserAgent.new("Mozilla", "5.0") 126 | end 127 | 128 | it "should not be <= if products are the same and version is greater" do 129 | expect(UserAgent.new("Mozilla", "5.0")).not_to be <= UserAgent.new("Mozilla", "4.0") 130 | end 131 | 132 | it "should be >= if products are the same and version is the same" do 133 | expect(UserAgent.new("Mozilla", "5.0")).to be >= UserAgent.new("Mozilla", "5.0") 134 | end 135 | 136 | it "should be <= if products are the same and version is the same" do 137 | expect(UserAgent.new("Mozilla", "5.0")).to be <= UserAgent.new("Mozilla", "5.0") 138 | end 139 | end 140 | 141 | describe UserAgent, "::MATCHER" do 142 | it "should not match a blank line" do 143 | expect(UserAgent::MATCHER).not_to match("") 144 | end 145 | 146 | it "should match a single product" do 147 | expect(UserAgent::MATCHER).to match("Mozilla") 148 | end 149 | 150 | it "should match a product and version" do 151 | expect(UserAgent::MATCHER).to match("Mozilla/5.0") 152 | end 153 | 154 | it "should match a product, version, and comment" do 155 | expect(UserAgent::MATCHER).to match("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_3; en-us)") 156 | end 157 | 158 | it "should match a product, and comment" do 159 | expect(UserAgent::MATCHER).to match("Mozilla (Macintosh; U; Intel Mac OS X 10_5_3; en-us)") 160 | end 161 | end 162 | 163 | describe UserAgent, ".parse" do 164 | let(:default_user_agent) { UserAgent.parse(UserAgent::DEFAULT_USER_AGENT) } 165 | 166 | it "should concatenate user agents when coerced to a string" do 167 | string = UserAgent.parse("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_3; en-us) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.1 Safari/525.18") 168 | expect(string.to_str).to eq("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_3; en-us) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.1 Safari/525.18") 169 | end 170 | 171 | it "should parse a single product" do 172 | useragent = UserAgent.new("Mozilla") 173 | expect(UserAgent.parse("Mozilla").application).to eq(useragent) 174 | end 175 | 176 | it "should parse a single product with version" do 177 | useragent = UserAgent.new("Mozilla", "5.0") 178 | expect(UserAgent.parse("Mozilla/5.0").application).to eq(useragent) 179 | end 180 | 181 | it "should parse a single product with an empty comment" do 182 | useragent = UserAgent.new("Mozilla", "5.0") 183 | expect(UserAgent.parse("Mozilla/5.0 ()").application).to eq(useragent) 184 | end 185 | 186 | it "should parse a single product, version, and comment" do 187 | useragent = UserAgent.new("Mozilla", "5.0", ["Macintosh", "U", "Intel Mac OS X 10_5_3", "en-us"]) 188 | expect(UserAgent.parse("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_3; en-us)").application).to eq(useragent) 189 | end 190 | 191 | it "should parse a single product, version, and comment, with space-padded semicolons" do 192 | useragent = UserAgent.new("Mozilla", "5.0", ["Macintosh", "U", "Intel Mac OS X 10_5_3", "en-us"]) 193 | expect(UserAgent.parse("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_3 ; en-us; )").application).to eq(useragent) 194 | end 195 | 196 | it "should parse a user agent string with gzip(gfe) addition correctly" do 197 | agent = UserAgent.parse("Mozilla/5.0 (Windows NT 5.1; rv:35.0) Gecko/20100101 Firefox/35.0,gzip(gfe)") 198 | 199 | expect(agent.version.to_s).to eq("35.0") 200 | end 201 | 202 | it "should parse a single product and comment" do 203 | useragent = UserAgent.new("Mozilla", nil, ["Macintosh"]) 204 | expect(UserAgent.parse("Mozilla (Macintosh)").application).to eq(useragent) 205 | end 206 | 207 | it "should parse nil as the default agent" do 208 | expect(UserAgent.parse(nil)).to eq(default_user_agent) 209 | end 210 | 211 | it "should parse an empty string as the default agent" do 212 | expect(UserAgent.parse("")).to eq(default_user_agent) 213 | end 214 | 215 | it "should parse a blank string as the default agent" do 216 | expect(UserAgent.parse(" ")).to eq(default_user_agent) 217 | end 218 | 219 | it "should parse a double-quoted user-agent" do 220 | useragent = UserAgent.new("Mozilla", "5.0", ["X11", "Linux x86_64", "rv:9.0"]) 221 | expect(UserAgent.parse("\"Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20100101 Firefox/8.0\"").application).to eq(useragent) 222 | end 223 | 224 | it "should parse a user-agent with leading double-quote" do 225 | useragent = UserAgent.new("Mozilla", "5.0", ["X11", "Linux x86_64", "rv:9.0"]) 226 | expect(UserAgent.parse("\"Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20100101 Firefox/8.0").application).to eq(useragent) 227 | end 228 | 229 | it "should parse a single-quoted user-agent" do 230 | useragent = UserAgent.new("Mozilla", "5.0", nil) 231 | expect(UserAgent.parse("'Mozilla/5.0'").application).to eq(useragent) 232 | end 233 | 234 | it "should parse a user-agent with leading single-quote" do 235 | useragent = UserAgent.new("Mozilla", "5.0", nil) 236 | expect(UserAgent.parse("'Mozilla/5.0").application).to eq(useragent) 237 | end 238 | end 239 | 240 | describe UserAgent::Browsers::Base, "#<" do 241 | before do 242 | @ie_7 = UserAgent.parse("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)") 243 | @ie_6 = UserAgent.parse("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)") 244 | @firefox = UserAgent.parse("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14") 245 | end 246 | 247 | it "should not be < if user agent does not have a browser" do 248 | expect(@ie_7).not_to be < "Mozilla" 249 | end 250 | 251 | it "should not be < if user agent does not have the same browser" do 252 | expect(@ie_7).not_to be < @firefox 253 | end 254 | 255 | it "should be < if version is less than its version" do 256 | expect(@ie_6).to be < @ie_7 257 | end 258 | 259 | it "should not be < if version is the same as its version" do 260 | expect(@ie_6).not_to be < @ie_6 261 | end 262 | 263 | it "should not be < if version is greater than its version" do 264 | expect(@ie_7).not_to be < @ie_6 265 | end 266 | end 267 | 268 | describe UserAgent::Browsers::Base, "#<=" do 269 | before do 270 | @ie_7 = UserAgent.parse("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)") 271 | @ie_6 = UserAgent.parse("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)") 272 | @firefox = UserAgent.parse("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14") 273 | end 274 | 275 | it "should not be <= if user agent does not have a browser" do 276 | expect(@ie_7).not_to be <= "Mozilla" 277 | end 278 | 279 | it "should not be <= if user agent does not have the same browser" do 280 | expect(@ie_7).not_to be <= @firefox 281 | end 282 | 283 | it "should be <= if version is less than its version" do 284 | expect(@ie_6).to be <= @ie_7 285 | end 286 | 287 | it "should be <= if version is the same as its version" do 288 | expect(@ie_6).to be <= @ie_6 289 | end 290 | 291 | it "should not be <= if version is greater than its version" do 292 | expect(@ie_7).not_to be <= @ie_6 293 | end 294 | end 295 | 296 | describe UserAgent::Browsers::Base, "#==" do 297 | before do 298 | @ie_7 = UserAgent.parse("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)") 299 | @ie_6 = UserAgent.parse("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)") 300 | @firefox = UserAgent.parse("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14") 301 | end 302 | 303 | it "should not be == if user agent does not have a browser" do 304 | expect(@ie_7).not_to eq("Mozilla") 305 | end 306 | 307 | it "should not be == if user agent does not have the same browser" do 308 | expect(@ie_7).not_to eq(@firefox) 309 | end 310 | 311 | it "should not be == if version is less than its version" do 312 | expect(@ie_6).not_to eq(@ie_7) 313 | end 314 | 315 | it "should be == if version is the same as its version" do 316 | expect(@ie_6).to eq(@ie_6) 317 | end 318 | 319 | it "should not be == if version is greater than its version" do 320 | expect(@ie_7).not_to eq(@ie_6) 321 | end 322 | end 323 | 324 | describe UserAgent::Browsers::Base, "#>" do 325 | before do 326 | @ie_7 = UserAgent.parse("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)") 327 | @ie_6 = UserAgent.parse("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)") 328 | @firefox = UserAgent.parse("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14") 329 | end 330 | 331 | it "should not be > if user agent does not have a browser" do 332 | expect(@ie_7).not_to be > "Mozilla" 333 | end 334 | 335 | it "should not be > if user agent does not have the same browser" do 336 | expect(@ie_7).not_to be > @firefox 337 | end 338 | 339 | it "should not be > if version is less than its version" do 340 | expect(@ie_6).not_to be > @ie_7 341 | end 342 | 343 | it "should not be > if version is the same as its version" do 344 | expect(@ie_6).not_to be > @ie_6 345 | end 346 | 347 | it "should be > if version is greater than its version" do 348 | expect(@ie_7).to be > @ie_6 349 | end 350 | end 351 | 352 | describe UserAgent::Browsers::Base, "#>=" do 353 | before do 354 | @ie_7 = UserAgent.parse("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)") 355 | @ie_6 = UserAgent.parse("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)") 356 | @firefox = UserAgent.parse("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14") 357 | end 358 | 359 | it "should not be >= if user agent does not have a browser" do 360 | expect(@ie_7).not_to be >= "Mozilla" 361 | end 362 | 363 | it "should not be >= if user agent does not have the same browser" do 364 | expect(@ie_7).not_to be >= @firefox 365 | end 366 | 367 | it "should not be >= if version is less than its version" do 368 | expect(@ie_6).not_to be >= @ie_7 369 | end 370 | 371 | it "should be >= if version is the same as its version" do 372 | expect(@ie_6).to be >= @ie_6 373 | end 374 | 375 | it "should be >= if version is greater than its version" do 376 | expect(@ie_7).to be >= @ie_6 377 | end 378 | end 379 | 380 | describe UserAgent::Browsers::Base, "#to_h" do 381 | shared_examples "Browser serializer" do |user_agent_string, expected_hash| 382 | let(:useragent) do 383 | UserAgent.parse(user_agent_string) 384 | end 385 | 386 | let(:actual) do 387 | useragent.to_h 388 | end 389 | 390 | expected_hash.each_pair do |key, value| 391 | it "should serialize :#{key} as '#{value}'" do 392 | expect(actual[key]).to eq(value) 393 | end 394 | end 395 | end 396 | 397 | it_behaves_like "Browser serializer", 398 | "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_3; en-us)", 399 | { 400 | :browser => "Mozilla", 401 | :version => [5, 0], 402 | :platform => "Macintosh", 403 | :os => "OS X 10.5.3", 404 | :mobile => false, 405 | :bot => false, 406 | :comment => ["Macintosh", "U", "Intel Mac OS X 10_5_3", "en-us"], 407 | } 408 | 409 | it_behaves_like "Browser serializer", 410 | "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", 411 | { 412 | :browser => "Mozilla", 413 | :version => [5, 0], 414 | :platform => nil, 415 | :os => "Googlebot/2.1", 416 | :mobile => false, 417 | :bot => true, 418 | :comment => ["compatible", "Googlebot/2.1", "+http://www.google.com/bot.html"], 419 | } 420 | 421 | it_behaves_like "Browser serializer", 422 | "Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) CriOS/28.0.1500.16 Mobile/10B329 Safari/8536.25", 423 | { 424 | :browser => "Chrome", 425 | :version => [28, 0, 1500, 16], 426 | :platform => "iPhone", 427 | :os => "iOS 6.1.3", 428 | :mobile => true, 429 | :bot => false, 430 | :comment => ["iPhone", "CPU iPhone OS 6_1_3 like Mac OS X"], 431 | } 432 | end 433 | 434 | describe UserAgent::Version do 435 | it "should be eql if versions are the same" do 436 | expect(UserAgent::Version.new("5.0")).to eql(UserAgent::Version.new("5.0")) 437 | end 438 | 439 | it "should not be eql if versions are the different" do 440 | expect(UserAgent::Version.new("9.0")).not_to eql(UserAgent::Version.new("5.0")) 441 | end 442 | 443 | it "should be == if versions are the same" do 444 | expect(UserAgent::Version.new("5.0")).to eq(UserAgent::Version.new("5.0")) 445 | end 446 | 447 | it "should be == if versions are the same string" do 448 | expect(UserAgent::Version.new("5.0")).to eq("5.0") 449 | end 450 | 451 | it "should not be == if versions are the different" do 452 | expect(UserAgent::Version.new("9.0")).not_to eq(UserAgent::Version.new("5.0")) 453 | end 454 | 455 | it "should not be == to nil" do 456 | expect(UserAgent::Version.new("9.0")).not_to eq(nil) 457 | end 458 | 459 | it "should not be == to []" do 460 | expect(UserAgent::Version.new("9.0")).not_to eq([]) 461 | end 462 | 463 | it "should be < if version is less" do 464 | expect(UserAgent::Version.new("9.0")).to be < UserAgent::Version.new("10.0") 465 | end 466 | 467 | it "should be < if version is less" do 468 | expect(UserAgent::Version.new("4")).to be < UserAgent::Version.new("4.1") 469 | end 470 | 471 | it "should be < if version is less and a string" do 472 | expect(UserAgent::Version.new("9.0")).to be < "10.0" 473 | end 474 | 475 | it "should not be < if version is greater" do 476 | expect(UserAgent::Version.new("9.0")).not_to be > UserAgent::Version.new("10.0") 477 | end 478 | 479 | it "should be <= if version is less" do 480 | expect(UserAgent::Version.new("9.0")).to be <= UserAgent::Version.new("10.0") 481 | end 482 | 483 | it "should not be <= if version is greater" do 484 | expect(UserAgent::Version.new("9.0")).not_to be >= UserAgent::Version.new("10.0") 485 | end 486 | 487 | it "should be <= if version is same" do 488 | expect(UserAgent::Version.new("9.0")).to be <= UserAgent::Version.new("9.0") 489 | end 490 | 491 | it "should be > if version is greater" do 492 | expect(UserAgent::Version.new("1.0")).to be > UserAgent::Version.new("0.9") 493 | end 494 | 495 | it "should be > if version is greater" do 496 | expect(UserAgent::Version.new("4.1")).to be > UserAgent::Version.new("4") 497 | end 498 | 499 | it "should not be > if version is less" do 500 | expect(UserAgent::Version.new("0.0.1")).not_to be > UserAgent::Version.new("10.0") 501 | end 502 | 503 | it "should be >= if version is greater" do 504 | expect(UserAgent::Version.new("10.0")).to be >= UserAgent::Version.new("4.0") 505 | end 506 | 507 | it "should not be >= if version is less" do 508 | expect(UserAgent::Version.new("0.9")).not_to be >= UserAgent::Version.new("1.0") 509 | end 510 | 511 | it "should not be > if version is invalid" do 512 | expect(UserAgent::Version.new("x.x")).not_to be > UserAgent::Version.new("1.0") 513 | end 514 | 515 | it "should be < if version is invalid" do 516 | expect(UserAgent::Version.new("x.x")).to be < UserAgent::Version.new("1.0") 517 | end 518 | 519 | it "should be > when compared with invalid" do 520 | expect(UserAgent::Version.new("1.0")).to be > UserAgent::Version.new("x.x") 521 | end 522 | 523 | it "should not be < when compared with invalid" do 524 | expect(UserAgent::Version.new("1.0")).not_to be < UserAgent::Version.new("x.x") 525 | end 526 | 527 | it "should not be > if both versions are invalid" do 528 | expect(UserAgent::Version.new("a.a")).not_to be > UserAgent::Version.new("b.b") 529 | end 530 | 531 | it "should be < if both versions are invalid" do 532 | expect(UserAgent::Version.new("a.a")).to be < UserAgent::Version.new("b.b") 533 | end 534 | 535 | it "should not be > if version is nil" do 536 | expect(UserAgent::Version.new(nil)).not_to be > UserAgent::Version.new("1.0") 537 | end 538 | 539 | it "should be < if version is nil" do 540 | expect(UserAgent::Version.new(nil)).to be < UserAgent::Version.new("1.0") 541 | end 542 | 543 | it "should not be > when compared with nil" do 544 | expect(UserAgent::Version.new(nil)).not_to be > UserAgent::Version.new(nil) 545 | end 546 | 547 | it "should not be < when compared with nil" do 548 | expect(UserAgent::Version.new(nil)).not_to be < UserAgent::Version.new(nil) 549 | end 550 | 551 | it "should not be > if both versions are nil" do 552 | expect(UserAgent::Version.new(nil)).not_to be > UserAgent::Version.new(nil) 553 | end 554 | 555 | it "should not be < if both versions are nil" do 556 | expect(UserAgent::Version.new(nil)).not_to be < UserAgent::Version.new(nil) 557 | end 558 | 559 | it "should be > if version is nil" do 560 | expect(UserAgent::Version.new("9.0")).to be > nil 561 | end 562 | 563 | context "comparing with structs" do 564 | it "should not be < if products are the same and version is greater" do 565 | expect(UserAgent.parse("Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)")).not_to be < OpenStruct.new(:browser => "Internet Explorer", :version => "7.0") 566 | end 567 | end 568 | end 569 | -------------------------------------------------------------------------------- /spec/browsers/webkit_user_agent_spec.rb: -------------------------------------------------------------------------------- 1 | require 'user_agent' 2 | 3 | shared_examples_for "Safari browser" do 4 | it "should return 'Safari' as its browser" do 5 | expect(@useragent.browser).to eq("Safari") 6 | end 7 | 8 | it "should return :strong as its security" do 9 | expect(@useragent.security).to eq(:strong) 10 | end 11 | end 12 | 13 | describe "UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16" do 14 | before do 15 | @useragent = UserAgent.parse("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16") 16 | end 17 | 18 | it_should_behave_like "Safari browser" 19 | 20 | it "should return '533.16' as its build" do 21 | expect(@useragent.build).to eq("533.16") 22 | end 23 | 24 | it "should return '5.0' as its version" do 25 | expect(@useragent.version).to eq("5.0") 26 | end 27 | 28 | it "should return '533.16' as its webkit version" do 29 | expect(@useragent.webkit.version).to eq("533.16") 30 | end 31 | 32 | it "should return 'Macintosh' as its platform" do 33 | expect(@useragent.platform).to eq("Macintosh") 34 | end 35 | 36 | it "should return 'OS X 10.6.3' as its os" do 37 | expect(@useragent.os).to eq("OS X 10.6.3") 38 | end 39 | 40 | it "should return 'en-us' as its localization" do 41 | expect(@useragent.localization).to eq("en-us") 42 | end 43 | 44 | it { expect(@useragent).not_to be_mobile } 45 | end 46 | 47 | describe "UserAgent: 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_3; en-us) AppleWebKit/526.9 (KHTML, like Gecko) Version/4.0dp1 Safari/526.8'" do 48 | before do 49 | @useragent = UserAgent.parse("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_3; en-us) AppleWebKit/526.9 (KHTML, like Gecko) Version/4.0dp1 Safari/526.8") 50 | end 51 | 52 | it_should_behave_like "Safari browser" 53 | 54 | it "should return '526.8' as its build" do 55 | expect(@useragent.build).to eq("526.9") 56 | end 57 | 58 | it "should return '4.0dp1' as its version" do 59 | expect(@useragent.version).to eq("4.0dp1") 60 | end 61 | 62 | it "should return '526.9' as its webkit version" do 63 | expect(@useragent.webkit.version).to eq("526.9") 64 | end 65 | 66 | it "should return 'Macintosh' as its platform" do 67 | expect(@useragent.platform).to eq("Macintosh") 68 | end 69 | 70 | it "should return 'OS X 10.5.3' as its os" do 71 | expect(@useragent.os).to eq("OS X 10.5.3") 72 | end 73 | 74 | it "should return 'en-us' as its localization" do 75 | expect(@useragent.localization).to eq("en-us") 76 | end 77 | 78 | it { expect(@useragent).not_to be_mobile } 79 | end 80 | 81 | describe "UserAgent: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en) AppleWebKit/526.9 (KHTML, like Gecko) Version/4.0dp1 Safari/526.8'" do 82 | before do 83 | @useragent = UserAgent.parse("Mozilla/5.0 (Windows; U; Windows NT 5.1; en) AppleWebKit/526.9 (KHTML, like Gecko) Version/4.0dp1 Safari/526.8") 84 | end 85 | 86 | it_should_behave_like "Safari browser" 87 | 88 | it "should return '526.8' as its build" do 89 | expect(@useragent.build).to eq("526.9") 90 | end 91 | 92 | it "should return '4.0dp1' as its version" do 93 | expect(@useragent.version).to eq("4.0dp1") 94 | end 95 | 96 | it "should return '526.9' as its webkit version" do 97 | expect(@useragent.webkit.version).to eq("526.9") 98 | end 99 | 100 | it "should return 'Windows' as its platform" do 101 | expect(@useragent.platform).to eq("Windows") 102 | end 103 | 104 | it "should return 'Windows XP' as its os" do 105 | expect(@useragent.os).to eq("Windows XP") 106 | end 107 | 108 | it "should return 'en' as its localization" do 109 | expect(@useragent.localization).to eq("en") 110 | end 111 | 112 | it { expect(@useragent).not_to be_mobile } 113 | end 114 | 115 | describe "UserAgent: 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_3; en-us) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.1 Safari/525.18'" do 116 | before do 117 | @useragent = UserAgent.parse("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_3; en-us) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.1 Safari/525.18") 118 | end 119 | 120 | it_should_behave_like "Safari browser" 121 | 122 | it "should return '525.18' as its build" do 123 | expect(@useragent.build).to eq("525.18") 124 | end 125 | 126 | it "should return '3.1.1' as its version" do 127 | expect(@useragent.version).to eq("3.1.1") 128 | end 129 | 130 | it "should return '525.18' as its webkit version" do 131 | expect(@useragent.webkit.version).to eq("525.18") 132 | end 133 | 134 | it "should return 'Macintosh' as its platform" do 135 | expect(@useragent.platform).to eq("Macintosh") 136 | end 137 | 138 | it "should return 'OS X 10.5.3' as its os" do 139 | expect(@useragent.os).to eq("OS X 10.5.3") 140 | end 141 | 142 | it "should return 'en-us' as its localization" do 143 | expect(@useragent.localization).to eq("en-us") 144 | end 145 | 146 | it "should be == 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_3; en-us) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.1 Safari/525.18'" do 147 | expect(@useragent).to eq(@useragent) 148 | end 149 | 150 | it "should not be == 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/419 (KHTML, like Gecko) Safari/419.3'" do 151 | expect(@useragent).not_to eq(UserAgent.parse("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/419 (KHTML, like Gecko) Safari/419.3")) 152 | end 153 | 154 | it "should be > 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/419 (KHTML, like Gecko) Safari/419.3'" do 155 | expect(@useragent).to be > UserAgent.parse("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/419 (KHTML, like Gecko) Safari/419.3") 156 | end 157 | 158 | it "should not be > 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_3; en-us) AppleWebKit/526.9 (KHTML, like Gecko) Version/4.0dp1 Safari/526.8'" do 159 | expect(@useragent).not_to be > UserAgent.parse("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_3; en-us) AppleWebKit/526.9 (KHTML, like Gecko) Version/4.0dp1 Safari/526.8") 160 | end 161 | 162 | it "should be < 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_3; en-us) AppleWebKit/526.9 (KHTML, like Gecko) Version/4.0dp1 Safari/526.8'" do 163 | expect(@useragent).to be < UserAgent.parse("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_3; en-us) AppleWebKit/526.9 (KHTML, like Gecko) Version/4.0dp1 Safari/526.8") 164 | end 165 | 166 | it "should not be < 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_3; en-us) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.1 Safari/525.18'" do 167 | expect(@useragent).not_to be < @useragent 168 | end 169 | 170 | it "should be >= 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/419 (KHTML, like Gecko) Safari/419.3'" do 171 | expect(@useragent).to be >= UserAgent.parse("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/419 (KHTML, like Gecko) Safari/419.3") 172 | end 173 | 174 | it "should not be >= 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_3; en-us) AppleWebKit/526.9 (KHTML, like Gecko) Version/4.0dp1 Safari/526.8'" do 175 | expect(@useragent).not_to be >= UserAgent.parse("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_3; en-us) AppleWebKit/526.9 (KHTML, like Gecko) Version/4.0dp1 Safari/526.8") 176 | end 177 | 178 | it "should be <= 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_3; en-us) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.1 Safari/525.18'" do 179 | expect(@useragent).to be <= @useragent 180 | end 181 | 182 | it "should not be <= 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/419 (KHTML, like Gecko) Safari/419.3'" do 183 | expect(@useragent).not_to be <= UserAgent.parse("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/419 (KHTML, like Gecko) Safari/419.3") 184 | end 185 | end 186 | 187 | describe "UserAgent: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.1 Safari/525.18'" do 188 | before do 189 | @useragent = UserAgent.parse("Mozilla/5.0 (Windows; U; Windows NT 5.1; en) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.1 Safari/525.18") 190 | end 191 | 192 | it_should_behave_like "Safari browser" 193 | 194 | it "should return '525.18' as its build" do 195 | expect(@useragent.build).to eq("525.18") 196 | end 197 | 198 | it "should return '3.1.1' as its version" do 199 | expect(@useragent.version).to eq("3.1.1") 200 | end 201 | 202 | it "should return '525.18' as its webkit version" do 203 | expect(@useragent.webkit.version).to eq("525.18") 204 | end 205 | 206 | it "should return 'Windows' as its platform" do 207 | expect(@useragent.platform).to eq("Windows") 208 | end 209 | 210 | it "should return 'Windows XP' as its os" do 211 | expect(@useragent.os).to eq("Windows XP") 212 | end 213 | 214 | it "should return 'en' as its localization" do 215 | expect(@useragent.localization).to eq("en") 216 | end 217 | end 218 | 219 | describe "UserAgent: 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/419 (KHTML, like Gecko) Safari/419.3'" do 220 | before do 221 | @useragent = UserAgent.parse("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/419 (KHTML, like Gecko) Safari/419.3") 222 | end 223 | 224 | it_should_behave_like "Safari browser" 225 | 226 | it "should return '419.3' as its build" do 227 | expect(@useragent.build).to eq("419") 228 | end 229 | 230 | it "should return '2.0.4' as its version" do 231 | expect(@useragent.version).to eq("2.0.4") 232 | end 233 | 234 | it "should return '419' as its webkit version" do 235 | expect(@useragent.webkit.version).to eq("419") 236 | end 237 | 238 | it "should return 'Macintosh' as its platform" do 239 | expect(@useragent.platform).to eq("Macintosh") 240 | end 241 | 242 | it "should return 'OS X' as its os" do 243 | expect(@useragent.os).to eq("OS X") 244 | end 245 | 246 | it "should return 'en' as its localization" do 247 | expect(@useragent.localization).to eq("en") 248 | end 249 | end 250 | 251 | describe "UserAgent: 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/412.6 (KHTML, like Gecko) Safari/412.2'" do 252 | before do 253 | @useragent = UserAgent.parse("Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/412.6 (KHTML, like Gecko) Safari/412.2") 254 | end 255 | 256 | it_should_behave_like "Safari browser" 257 | 258 | it "should return '412.2' as its build" do 259 | expect(@useragent.build).to eq("412.6") 260 | end 261 | 262 | it "should return '2.0' as its version" do 263 | expect(@useragent.version).to eq("2.0") 264 | end 265 | 266 | it "should return '412.6' as its webkit version" do 267 | expect(@useragent.webkit.version).to eq("412.6") 268 | end 269 | 270 | it "should return 'Macintosh' as its platform" do 271 | expect(@useragent.platform).to eq("Macintosh") 272 | end 273 | 274 | it "should return 'OS X' as its os" do 275 | expect(@useragent.os).to eq("OS X") 276 | end 277 | 278 | it "should return 'en' as its localization" do 279 | expect(@useragent.localization).to eq("en-us") 280 | end 281 | end 282 | 283 | describe "UserAgent: 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412.6.2 (KHTML, like Gecko) Safari/412.2.2'" do 284 | before do 285 | @useragent = UserAgent.parse("Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412.6.2 (KHTML, like Gecko) Safari/412.2.2") 286 | end 287 | 288 | it_should_behave_like "Safari browser" 289 | 290 | it "should return '412.2.2' as its build" do 291 | expect(@useragent.build).to eq("412.6.2") 292 | end 293 | 294 | it "should return '2.0' as its version" do 295 | expect(@useragent.version).to eq("2.0") 296 | end 297 | 298 | it "should return '412.6.2' as its webkit version" do 299 | expect(@useragent.webkit.version).to eq("412.6.2") 300 | end 301 | 302 | it "should return 'Macintosh' as its platform" do 303 | expect(@useragent.platform).to eq("Macintosh") 304 | end 305 | 306 | it "should return 'OS X' as its os" do 307 | expect(@useragent.os).to eq("OS X") 308 | end 309 | 310 | it "should return 'en' as its localization" do 311 | expect(@useragent.localization).to eq("en") 312 | end 313 | end 314 | 315 | describe "UserAgent: 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/312.8 (KHTML, like Gecko) Safari/312.6'" do 316 | before do 317 | @useragent = UserAgent.parse("Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/312.8 (KHTML, like Gecko) Safari/312.6") 318 | end 319 | 320 | it_should_behave_like "Safari browser" 321 | 322 | it "should return '312.6' as its build" do 323 | expect(@useragent.build).to eq("312.8") 324 | end 325 | 326 | it "should return '1.3.2' as its version" do 327 | expect(@useragent.version).to eq("1.3.2") 328 | end 329 | 330 | it "should return '312.8' as its webkit version" do 331 | expect(@useragent.webkit.version).to eq("312.8") 332 | end 333 | 334 | it "should return 'Macintosh' as its platform" do 335 | expect(@useragent.platform).to eq("Macintosh") 336 | end 337 | 338 | it "should return 'OS X' as its os" do 339 | expect(@useragent.os).to eq("OS X") 340 | end 341 | 342 | it "should return 'en' as its localization" do 343 | expect(@useragent.localization).to eq("en") 344 | end 345 | end 346 | 347 | describe "UserAgent: 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; fr-ch) AppleWebKit/312.1.1 (KHTML, like Gecko) Safari/312'" do 348 | before do 349 | @useragent = UserAgent.parse("Mozilla/5.0 (Macintosh; U; PPC Mac OS X; fr-ch) AppleWebKit/312.1.1 (KHTML, like Gecko) Safari/312") 350 | end 351 | 352 | it_should_behave_like "Safari browser" 353 | 354 | it "should return '312' as its build" do 355 | expect(@useragent.build).to eq("312.1.1") 356 | end 357 | 358 | it "should return '1.3' as its version" do 359 | expect(@useragent.version).to eq("1.3") 360 | end 361 | 362 | it "should return '312.1.1' as its webkit version" do 363 | expect(@useragent.webkit.version).to eq("312.1.1") 364 | end 365 | 366 | it "should return 'Macintosh' as its platform" do 367 | expect(@useragent.platform).to eq("Macintosh") 368 | end 369 | 370 | it "should return 'OS X' as its os" do 371 | expect(@useragent.os).to eq("OS X") 372 | end 373 | 374 | it "should return 'en' as its localization" do 375 | expect(@useragent.localization).to eq("fr-ch") 376 | end 377 | end 378 | 379 | describe "UserAgent: 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; es-es) AppleWebKit/312.5.2 (KHTML, like Gecko) Safari/312.3.3'" do 380 | before do 381 | @useragent = UserAgent.parse("Mozilla/5.0 (Macintosh; U; PPC Mac OS X; es-es) AppleWebKit/312.5.2 (KHTML, like Gecko) Safari/312.3.3") 382 | end 383 | 384 | it_should_behave_like "Safari browser" 385 | 386 | it "should return '312.3.3' as its build" do 387 | expect(@useragent.build).to eq("312.5.2") 388 | end 389 | 390 | it "should return '1.3.1' as its version" do 391 | expect(@useragent.version).to eq("1.3.1") 392 | end 393 | 394 | it "should return '312.5.2' as its webkit version" do 395 | expect(@useragent.webkit.version).to eq("312.5.2") 396 | end 397 | 398 | it "should return 'Macintosh' as its platform" do 399 | expect(@useragent.platform).to eq("Macintosh") 400 | end 401 | 402 | it "should return 'OS X' as its os" do 403 | expect(@useragent.os).to eq("OS X") 404 | end 405 | 406 | it "should return 'en' as its localization" do 407 | expect(@useragent.localization).to eq("es-es") 408 | end 409 | end 410 | 411 | describe "UserAgent: 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; fr) AppleWebKit/312.5.1 (KHTML, like Gecko) Safari/312.3.1'" do 412 | before do 413 | @useragent = UserAgent.parse("Mozilla/5.0 (Macintosh; U; PPC Mac OS X; fr) AppleWebKit/312.5.1 (KHTML, like Gecko) Safari/312.3.1") 414 | end 415 | 416 | it_should_behave_like "Safari browser" 417 | 418 | it "should return '312.3.1' as its build" do 419 | expect(@useragent.build).to eq("312.5.1") 420 | end 421 | 422 | it "should return '1.3.1' as its version" do 423 | expect(@useragent.version).to eq("1.3.1") 424 | end 425 | 426 | it "should return '312.5.1' as its webkit version" do 427 | expect(@useragent.webkit.version).to eq("312.5.1") 428 | end 429 | 430 | it "should return 'Macintosh' as its platform" do 431 | expect(@useragent.platform).to eq("Macintosh") 432 | end 433 | 434 | it "should return 'OS X' as its os" do 435 | expect(@useragent.os).to eq("OS X") 436 | end 437 | 438 | it "should return 'en' as its localization" do 439 | expect(@useragent.localization).to eq("fr") 440 | end 441 | end 442 | 443 | describe "UserAgent: 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/312.5 (KHTML, like Gecko) Safari/312.3'" do 444 | before do 445 | @useragent = UserAgent.parse("Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/312.5 (KHTML, like Gecko) Safari/312.3") 446 | end 447 | 448 | it_should_behave_like "Safari browser" 449 | 450 | it "should return '312.3' as its build" do 451 | expect(@useragent.build).to eq("312.5") 452 | end 453 | 454 | it "should return '1.3.1' as its version" do 455 | expect(@useragent.version).to eq("1.3.1") 456 | end 457 | 458 | it "should return '312.5' as its webkit version" do 459 | expect(@useragent.webkit.version).to eq("312.5") 460 | end 461 | 462 | it "should return 'Macintosh' as its platform" do 463 | expect(@useragent.platform).to eq("Macintosh") 464 | end 465 | 466 | it "should return 'OS X' as its os" do 467 | expect(@useragent.os).to eq("OS X") 468 | end 469 | 470 | it "should return 'en' as its localization" do 471 | expect(@useragent.localization).to eq("en-us") 472 | end 473 | end 474 | 475 | describe "UserAgent: 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/124 (KHTML, like Gecko) Safari/125'" do 476 | before do 477 | @useragent = UserAgent.parse("Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/124 (KHTML, like Gecko) Safari/125") 478 | end 479 | 480 | it_should_behave_like "Safari browser" 481 | 482 | it "should return '125' as its build" do 483 | expect(@useragent.build).to eq("124") 484 | end 485 | 486 | it "should return '1.2' as its version" do 487 | expect(@useragent.version).to eq("1.2") 488 | end 489 | 490 | it "should return '124' as its webkit version" do 491 | expect(@useragent.webkit.version).to eq("124") 492 | end 493 | 494 | it "should return 'Macintosh' as its platform" do 495 | expect(@useragent.platform).to eq("Macintosh") 496 | end 497 | 498 | it "should return 'OS X' as its os" do 499 | expect(@useragent.os).to eq("OS X") 500 | end 501 | 502 | it "should return 'en' as its localization" do 503 | expect(@useragent.localization).to eq("en-us") 504 | end 505 | end 506 | 507 | describe "UserAgent: 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/125.5.7 (KHTML, like Gecko) Safari/125.12'" do 508 | before do 509 | @useragent = UserAgent.parse("Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/125.5.7 (KHTML, like Gecko) Safari/125.12") 510 | end 511 | 512 | it_should_behave_like "Safari browser" 513 | 514 | it "should return '125.12' as its build" do 515 | expect(@useragent.build).to eq("125.5.7") 516 | end 517 | 518 | it "should return '1.2.4' as its version" do 519 | expect(@useragent.version).to eq("1.2.4") 520 | end 521 | 522 | it "should return '125.5.7' as its webkit version" do 523 | expect(@useragent.webkit.version).to eq("125.5.7") 524 | end 525 | 526 | it "should return 'Macintosh' as its platform" do 527 | expect(@useragent.platform).to eq("Macintosh") 528 | end 529 | 530 | it "should return 'OS X' as its os" do 531 | expect(@useragent.os).to eq("OS X") 532 | end 533 | 534 | it "should return 'en' as its localization" do 535 | expect(@useragent.localization).to eq("en") 536 | end 537 | end 538 | 539 | describe "UserAgent: 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; fr-fr) AppleWebKit/85.7 (KHTML, like Gecko) Safari/85.5'" do 540 | before do 541 | @useragent = UserAgent.parse("Mozilla/5.0 (Macintosh; U; PPC Mac OS X; fr-fr) AppleWebKit/85.7 (KHTML, like Gecko) Safari/85.5") 542 | end 543 | 544 | it_should_behave_like "Safari browser" 545 | 546 | it "should return '85.5' as its build" do 547 | expect(@useragent.build).to eq("85.7") 548 | end 549 | 550 | it "should return '1.0' as its version" do 551 | expect(@useragent.version).to eq("1.0") 552 | end 553 | 554 | it "should return '85.7' as its webkit version" do 555 | expect(@useragent.webkit.version).to eq("85.7") 556 | end 557 | 558 | it "should return 'Macintosh' as its platform" do 559 | expect(@useragent.platform).to eq("Macintosh") 560 | end 561 | 562 | it "should return 'OS X' as its os" do 563 | expect(@useragent.os).to eq("OS X") 564 | end 565 | 566 | it "should return 'en' as its localization" do 567 | expect(@useragent.localization).to eq("fr-fr") 568 | end 569 | end 570 | 571 | describe "UserAgent: 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/4A102 Safari/419'" do 572 | before do 573 | @useragent = UserAgent.parse("Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/4A102 Safari/419") 574 | end 575 | 576 | it_should_behave_like "Safari browser" 577 | 578 | it "should return '419' as its build" do 579 | expect(@useragent.build).to eq("420.1") 580 | end 581 | 582 | it "should return '3.0' as its version" do 583 | expect(@useragent.version).to eq("3.0") 584 | end 585 | 586 | it "should return '420.1' as its webkit version" do 587 | expect(@useragent.webkit.version).to eq("420.1") 588 | end 589 | 590 | it "should return 'iPhone' as its platform" do 591 | expect(@useragent.platform).to eq("iPhone") 592 | end 593 | 594 | it "should return 'CPU like Mac OS X' as its os" do 595 | expect(@useragent.os).to eq("CPU like Mac OS X") 596 | end 597 | 598 | it "should return 'en' as its localization" do 599 | expect(@useragent.localization).to eq("en") 600 | end 601 | 602 | it { expect(@useragent).to be_mobile } 603 | end 604 | 605 | describe "UserAgent: 'Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/4A102 Safari/419'" do 606 | before do 607 | @useragent = UserAgent.parse("Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/4A102 Safari/419") 608 | end 609 | 610 | it_should_behave_like "Safari browser" 611 | 612 | it "should return '419' as its build" do 613 | expect(@useragent.build).to eq("420.1") 614 | end 615 | 616 | it "should return '3.0' as its version" do 617 | expect(@useragent.version).to eq("3.0") 618 | end 619 | 620 | it "should return '420.1' as its webkit version" do 621 | expect(@useragent.webkit.version).to eq("420.1") 622 | end 623 | 624 | it "should return 'iPod' as its platform" do 625 | expect(@useragent.platform).to eq("iPod") 626 | end 627 | 628 | it "should return 'CPU like Mac OS X' as its os" do 629 | expect(@useragent.os).to eq("CPU like Mac OS X") 630 | end 631 | 632 | it "should return 'en' as its localization" do 633 | expect(@useragent.localization).to eq("en") 634 | end 635 | 636 | it { expect(@useragent).to be_mobile } 637 | end 638 | 639 | describe "UserAgent: 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" do 640 | before do 641 | @useragent = UserAgent.parse("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") 642 | end 643 | 644 | it_should_behave_like "Safari browser" 645 | 646 | it "should return '531.21.10' as its build" do 647 | expect(@useragent.build).to eq("531.21.10") 648 | end 649 | 650 | it "should return '4.0.4' as its version" do 651 | expect(@useragent.version).to eq("4.0.4") 652 | end 653 | 654 | it "should return '531.21.10' as its webkit version" do 655 | expect(@useragent.webkit.version).to eq("531.21.10") 656 | end 657 | 658 | it "should return 'iPad' as its platform" do 659 | expect(@useragent.platform).to eq("iPad") 660 | end 661 | 662 | it "should return 'iOS 3.2' as its os" do 663 | expect(@useragent.os).to eq("iOS 3.2") 664 | end 665 | 666 | it "should return 'en-us' as its localization" do 667 | expect(@useragent.localization).to eq("en-us") 668 | end 669 | 670 | it { expect(@useragent).to be_mobile } 671 | end 672 | 673 | describe "UserAgent: 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_3 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7E18 Safari/528.16'" do 674 | before do 675 | @useragent = UserAgent.parse("Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_3 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7E18 Safari/528.16") 676 | end 677 | 678 | it_should_behave_like "Safari browser" 679 | 680 | it "should return '528.18' as its build" do 681 | expect(@useragent.build).to eq("528.18") 682 | end 683 | 684 | it "should return '4.0' as its version" do 685 | expect(@useragent.version).to eq("4.0") 686 | end 687 | 688 | it "should return '528.18' as its webkit version" do 689 | expect(@useragent.webkit.version).to eq("528.18") 690 | end 691 | 692 | it "should return 'iPhone' as its platform" do 693 | expect(@useragent.platform).to eq("iPhone") 694 | end 695 | 696 | it "should return 'iOS 3.1.3' as its os" do 697 | expect(@useragent.os).to eq("iOS 3.1.3") 698 | end 699 | 700 | it "should return 'en-us' as its localization" do 701 | expect(@useragent.localization).to eq("en-us") 702 | end 703 | end 704 | 705 | describe "UserAgent: 'Mozilla/5.0 (iPod; U; CPU iPhone OS 3_1_3 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7E18 Safari/528.16'" do 706 | before do 707 | @useragent = UserAgent.parse("Mozilla/5.0 (iPod; U; CPU iPhone OS 3_1_3 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7E18 Safari/528.16") 708 | end 709 | 710 | it_should_behave_like "Safari browser" 711 | 712 | it "should return '528.18' as its build" do 713 | expect(@useragent.build).to eq("528.18") 714 | end 715 | 716 | it "should return '4.0' as its version" do 717 | expect(@useragent.version).to eq("4.0") 718 | end 719 | 720 | it "should return '528.18' as its webkit version" do 721 | expect(@useragent.webkit.version).to eq("528.18") 722 | end 723 | 724 | it "should return 'iPod' as its platform" do 725 | expect(@useragent.platform).to eq("iPod") 726 | end 727 | 728 | it "should return 'iOS 3.1.3' as its os" do 729 | expect(@useragent.os).to eq("iOS 3.1.3") 730 | end 731 | 732 | it "should return 'en' as its localization" do 733 | expect(@useragent.localization).to eq("en-us") 734 | end 735 | 736 | it { expect(@useragent).to be_mobile } 737 | end 738 | 739 | describe "UserAgent: 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-us) AppleWebKit/533.19.4 (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4'" do 740 | before do 741 | @useragent = UserAgent.parse("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-us) AppleWebKit/533.19.4 (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4") 742 | end 743 | 744 | it_should_behave_like "Safari browser" 745 | 746 | it "should return '533.19.4' as its build" do 747 | expect(@useragent.build).to eq("533.19.4") 748 | end 749 | 750 | it "should return '5.0.3' as its version" do 751 | expect(@useragent.version).to eq("5.0.3") 752 | end 753 | 754 | it "should return '533.19.4' as its webkit version" do 755 | expect(@useragent.webkit.version).to eq("533.19.4") 756 | end 757 | 758 | it "should return 'Macintosh' as its platform" do 759 | expect(@useragent.platform).to eq("Macintosh") 760 | end 761 | 762 | it "should return 'OS X 10.6.5' as its os" do 763 | expect(@useragent.os).to eq("OS X 10.6.5") 764 | end 765 | 766 | it "should return 'en' as its localization" do 767 | expect(@useragent.localization).to eq("en-us") 768 | end 769 | 770 | it { expect(@useragent).not_to be_mobile } 771 | end 772 | 773 | describe "UserAgent: 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7'" do 774 | before do 775 | @useragent = UserAgent.parse("Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7") 776 | end 777 | 778 | it_should_behave_like "Safari browser" 779 | 780 | it "should return '532.9' as its build" do 781 | expect(@useragent.build).to eq("532.9") 782 | end 783 | 784 | it "should return '4.0.5' as its version" do 785 | expect(@useragent.version).to eq("4.0.5") 786 | end 787 | 788 | it "should return '532.9' as its webkit version" do 789 | expect(@useragent.webkit.version).to eq("532.9") 790 | end 791 | 792 | it "should return 'iPhone' as its platform" do 793 | expect(@useragent.platform).to eq("iPhone") 794 | end 795 | 796 | it "should return 'iOS 4.1'" do 797 | expect(@useragent.os).to eq("iOS 4.1") 798 | end 799 | 800 | it "should return 'en' as its localization" do 801 | expect(@useragent.localization).to eq("en-us") 802 | end 803 | 804 | it { expect(@useragent).to be_mobile } 805 | end 806 | 807 | describe "UserAgent: 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Mobile/8A306'" do 808 | before do 809 | @useragent = UserAgent.parse("Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Mobile/8A306") 810 | end 811 | 812 | it_should_behave_like "Safari browser" 813 | 814 | it "should return '532.9' as its build" do 815 | expect(@useragent.build).to eq("532.9") 816 | end 817 | 818 | it "should return '4.0.1' as its version" do 819 | expect(@useragent.version).to eq("4.0.1") 820 | end 821 | 822 | it "should return '532.9' as its webkit version" do 823 | expect(@useragent.webkit.version).to eq("532.9") 824 | end 825 | 826 | it "should return 'iPhone' as its platform" do 827 | expect(@useragent.platform).to eq("iPhone") 828 | end 829 | 830 | it "should return 'iOS 4.0.1'" do 831 | expect(@useragent.os).to eq("iOS 4.0.1") 832 | end 833 | 834 | it "should return 'en' as its localization" do 835 | expect(@useragent.localization).to eq("en-us") 836 | end 837 | 838 | it { expect(@useragent).to be_mobile } 839 | end 840 | 841 | describe "UserAgent: 'Mozilla/5.0 (iPhone Simulator; U; CPU iPhone OS 4_0_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A306 Safari/6531.22.7'" do 842 | before do 843 | @useragent = UserAgent.parse("Mozilla/5.0 (iPhone Simulator; U; CPU iPhone OS 4_0_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A306 Safari/6531.22.7") 844 | end 845 | 846 | it_should_behave_like "Safari browser" 847 | 848 | it "should return '532.9' as its build" do 849 | expect(@useragent.build).to eq("532.9") 850 | end 851 | 852 | it "should return '4.0.5' as its version" do 853 | expect(@useragent.version).to eq("4.0.5") 854 | end 855 | 856 | it "should return '532.9' as its webkit version" do 857 | expect(@useragent.webkit.version).to eq("532.9") 858 | end 859 | 860 | it "should return 'iPhone' as its platform" do 861 | expect(@useragent.platform).to eq("iPhone Simulator") 862 | end 863 | 864 | it "should return 'iOS 4.0.1'" do 865 | expect(@useragent.os).to eq("iOS 4.0.1") 866 | end 867 | 868 | it "should return 'en' as its localization" do 869 | expect(@useragent.localization).to eq("en-us") 870 | end 871 | 872 | it { expect(@useragent).to be_mobile } 873 | end 874 | 875 | describe "UserAgent: 'Mozilla/5.0 (Linux; U; Android 1.5; de-; HTC Magic Build/PLAT-RC33) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1'" do 876 | before do 877 | @useragent = UserAgent.parse("Mozilla/5.0 (Linux; U; Android 1.5; de-; HTC Magic Build/PLAT-RC33) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1") 878 | end 879 | 880 | it "should return 'Android' as its browser" do 881 | expect(@useragent.browser).to eq("Android") 882 | end 883 | 884 | it "should return '528.5+' as its build" do 885 | expect(@useragent.build).to eq("528.5+") 886 | end 887 | 888 | it "should return '3.1.2' as its version" do 889 | expect(@useragent.version).to eq("3.1.2") 890 | end 891 | 892 | it "should return '528.5+' as its webkit version" do 893 | expect(@useragent.webkit.version).to eq("528.5+") 894 | end 895 | 896 | it "should return 'Android' as its platform" do 897 | expect(@useragent.platform).to eq("Android") 898 | end 899 | 900 | it "should return 'Android 1.5' as its os" do 901 | expect(@useragent.os).to eq("Android 1.5") 902 | end 903 | 904 | it { expect(@useragent).to be_mobile } 905 | end 906 | 907 | describe "UserAgent: 'Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, Like Gecko) Version/6.0.0.141 Mobile Safari/534.1+'" do 908 | before do 909 | @useragent = UserAgent.parse("Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, Like Gecko) Version/6.0.0.141 Mobile Safari/534.1+") 910 | end 911 | 912 | it "should return 'BlackBerry' as its browser" do 913 | expect(@useragent.browser).to eq("BlackBerry") 914 | end 915 | 916 | it "should return '534.1+' as its build" do 917 | expect(@useragent.build).to eq("534.1+") 918 | end 919 | 920 | it "should return '6.0.0.141' as its version" do 921 | expect(@useragent.version).to eq("6.0.0.141") 922 | end 923 | 924 | it "should return '534.1+' as its webkit version" do 925 | expect(@useragent.webkit.version).to eq("534.1+") 926 | end 927 | 928 | it "should return 'BlackBerry' as its platform" do 929 | expect(@useragent.platform).to eq("BlackBerry") 930 | end 931 | 932 | it "should return 'BlackBerry 9800' as its os" do 933 | expect(@useragent.os).to eq("BlackBerry 9800") 934 | end 935 | 936 | it { expect(@useragent).to be_mobile } 937 | end 938 | 939 | describe "UserAgent: 'Mozilla/5.0 (BB10; Touch) AppleWebKit/537.3+ (KHTML, like Gecko) Version/10.0.9.388 Mobile Safari/537.3+'" do 940 | before do 941 | @useragent = UserAgent.parse("Mozilla/5.0 (BB10; Touch) AppleWebKit/537.3+ (KHTML, like Gecko) Version/10.0.9.388 Mobile Safari/537.3+") 942 | end 943 | 944 | it "should return 'BlackBerry' as its browser" do 945 | expect(@useragent.browser).to eq("BlackBerry") 946 | end 947 | 948 | it "should return '537.3+' as its build" do 949 | expect(@useragent.build).to eq("537.3+") 950 | end 951 | 952 | it "should return '10.0.9.388' as its version" do 953 | expect(@useragent.version).to eq("10.0.9.388") 954 | end 955 | 956 | it "should return '537.3+' as its webkit version" do 957 | expect(@useragent.webkit.version).to eq("537.3+") 958 | end 959 | 960 | it "should return 'BlackBerry' as its platform" do 961 | expect(@useragent.platform).to eq("BlackBerry") 962 | end 963 | 964 | it "should return 'Touch' as its os" do 965 | expect(@useragent.os).to eq("Touch") 966 | end 967 | 968 | it { expect(@useragent).to be_mobile } 969 | end 970 | 971 | describe "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/534.51.22 (KHTML, like Gecko) Version/5.1.1 Safari/534.51.22" do 972 | before do 973 | @useragent = UserAgent.parse("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/534.51.22 (KHTML, like Gecko) Version/5.1.1 Safari/534.51.22") 974 | end 975 | 976 | it "should return 'Safari' as its browser" do 977 | expect(@useragent.browser).to eq("Safari") 978 | end 979 | 980 | it "should return nil as its security" do 981 | expect(@useragent.security).to be_nil 982 | end 983 | 984 | it "should return '534.51.22' as its build" do 985 | expect(@useragent.build).to eq("534.51.22") 986 | end 987 | 988 | it "should return '5.1.1' as its version" do 989 | expect(@useragent.version).to eq("5.1.1") 990 | end 991 | 992 | it "should return '534.51.22' as its webkit version" do 993 | expect(@useragent.webkit.version).to eq("534.51.22") 994 | end 995 | 996 | it "should return 'Macintosh' as its platform" do 997 | expect(@useragent.platform).to eq("Macintosh") 998 | end 999 | 1000 | it "should return 'OS X 10.7.2' as its os" do 1001 | expect(@useragent.os).to eq("OS X 10.7.2") 1002 | end 1003 | 1004 | it "should return nil as its localization" do 1005 | expect(@useragent.localization).to be_nil 1006 | end 1007 | 1008 | it { expect(@useragent).not_to be_mobile } 1009 | end 1010 | 1011 | describe "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/534.52.7 (KHTML, like Gecko)" do 1012 | before do 1013 | @useragent = UserAgent.parse("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/534.52.7 (KHTML, like Gecko)") 1014 | end 1015 | 1016 | it "should return 'Safari' as its browser" do 1017 | expect(@useragent.browser).to eq("Safari") 1018 | end 1019 | 1020 | it "should return '5.1.2' as its version" do 1021 | expect(@useragent.version).to eq("5.1.2") 1022 | end 1023 | end 1024 | 1025 | describe "UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Salamander/44.0 Safari/537.36" do 1026 | before do 1027 | @useragent = UserAgent.parse("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Salamander/44.0 Safari/537.36") 1028 | end 1029 | 1030 | it "should return '537.36' as its build" do 1031 | expect(@useragent.build).to eq("537.36") 1032 | end 1033 | 1034 | it "should return null as its version" do 1035 | expect(@useragent.version).to eq("") 1036 | end 1037 | 1038 | it "should return '537.36' as its webkit version" do 1039 | expect(@useragent.webkit.version).to eq("537.36") 1040 | end 1041 | 1042 | it "should return 'Macintosh' as its platform" do 1043 | expect(@useragent.platform).to eq("Macintosh") 1044 | end 1045 | 1046 | it "should return 'OS X 10.9.5' as its os" do 1047 | expect(@useragent.os).to eq("OS X 10.9.5") 1048 | end 1049 | 1050 | it { expect(@useragent).not_to be_mobile } 1051 | end 1052 | 1053 | describe "UserAgent: Mozilla/5.0 (X11; CrOS armv7l 4537.56.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.38 Safari/537.36" do 1054 | before do 1055 | @useragent = UserAgent.parse("Mozilla/5.0 (X11; CrOS armv7l 4537.56.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.38 Safari/537.36") 1056 | end 1057 | 1058 | it "should return '537.36' as its build" do 1059 | expect(@useragent.build).to eq("537.36") 1060 | end 1061 | 1062 | it "should return '30.0.1599.38' as its version" do 1063 | expect(@useragent.version).to eq("30.0.1599.38") 1064 | end 1065 | 1066 | it "should return '537.36' as its webkit version" do 1067 | expect(@useragent.webkit.version).to eq("537.36") 1068 | end 1069 | 1070 | it "should return 'ChromeOS' as its platform" do 1071 | expect(@useragent.platform).to eq("ChromeOS") 1072 | end 1073 | 1074 | it "should return 'ChromeOS 4537.56.0' as its os" do 1075 | expect(@useragent.os).to eq("ChromeOS 4537.56.0") 1076 | end 1077 | 1078 | it { expect(@useragent).not_to be_mobile } 1079 | end 1080 | 1081 | describe "UserAgent: Mozilla/5.0 (X11; CrOS x86_64 4920.71.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.95 Safari/537.36" do 1082 | before do 1083 | @useragent = UserAgent.parse("Mozilla/5.0 (X11; CrOS x86_64 4920.71.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.95 Safari/537.36") 1084 | end 1085 | 1086 | it "should return '537.36' as its build" do 1087 | expect(@useragent.build).to eq("537.36") 1088 | end 1089 | 1090 | it "should return '32.0.1700.95' as its version" do 1091 | expect(@useragent.version).to eq("32.0.1700.95") 1092 | end 1093 | 1094 | it "should return '537.36' as its webkit version" do 1095 | expect(@useragent.webkit.version).to eq("537.36") 1096 | end 1097 | 1098 | it "should return 'ChromeOS' as its platform" do 1099 | expect(@useragent.platform).to eq("ChromeOS") 1100 | end 1101 | 1102 | it "should return 'ChromeOS 4920.71.0' as its os" do 1103 | expect(@useragent.os).to eq("ChromeOS 4920.71.0") 1104 | end 1105 | 1106 | it { expect(@useragent).not_to be_mobile } 1107 | end 1108 | 1109 | describe "UserAgent: Mozilla/5.0 (X11; U; CrOS i686 9.10.0; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.253.0 Safari/532.5" do 1110 | before do 1111 | @useragent = UserAgent.parse("Mozilla/5.0 (X11; U; CrOS i686 9.10.0; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.253.0 Safari/532.5") 1112 | end 1113 | 1114 | it "should return '532.5' as its build" do 1115 | expect(@useragent.build).to eq("532.5") 1116 | end 1117 | 1118 | it "should return '4.0.253.0' as its version" do 1119 | expect(@useragent.version).to eq("4.0.253.0") 1120 | end 1121 | 1122 | it "should return '532.5' as its webkit version" do 1123 | expect(@useragent.webkit.version).to eq("532.5") 1124 | end 1125 | 1126 | it "should return 'ChromeOS' as its platform" do 1127 | expect(@useragent.platform).to eq("ChromeOS") 1128 | end 1129 | 1130 | it "should return 'ChromeOS 9.10.0' as its os" do 1131 | expect(@useragent.os).to eq("ChromeOS 9.10.0") 1132 | end 1133 | 1134 | it { expect(@useragent).not_to be_mobile } 1135 | end 1136 | 1137 | describe "UserAgent: Mozilla/5.0 (iPhone; U; fr; CPU iPhone OS 4_2_1 like Mac OS X; fr) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148a Safari/6533.18.5" do 1138 | before do 1139 | @useragent = UserAgent.parse("Mozilla/5.0 (iPhone; U; fr; CPU iPhone OS 4_2_1 like Mac OS X; fr) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148a Safari/6533.18.5") 1140 | end 1141 | 1142 | it "should return '533.17.9' as its build" do 1143 | expect(@useragent.build).to eq("533.17.9") 1144 | end 1145 | 1146 | it "should return '5.0.2' as its version" do 1147 | expect(@useragent.version).to eq("5.0.2") 1148 | end 1149 | 1150 | it "should return '533.17.9' as its webkit version" do 1151 | expect(@useragent.webkit.version).to eq("533.17.9") 1152 | end 1153 | 1154 | it "should return 'iPhone' as its platform" do 1155 | expect(@useragent.platform).to eq("iPhone") 1156 | end 1157 | 1158 | it "should return 'iOS 4.2.1' as its os" do 1159 | expect(@useragent.os).to eq("iOS 4.2.1") 1160 | end 1161 | 1162 | it { expect(@useragent).to be_mobile } 1163 | end 1164 | 1165 | describe "UserAgent: Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30" do 1166 | before do 1167 | @useragent = UserAgent.parse("Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30") 1168 | end 1169 | 1170 | it "should return 'Android' as its browser" do 1171 | expect(@useragent.browser).to eq("Android") 1172 | end 1173 | 1174 | it "should return :strong as its security" do 1175 | expect(@useragent.security).to eq(:strong) 1176 | end 1177 | 1178 | it "should return '534.30' as its build" do 1179 | expect(@useragent.build).to eq("534.30") 1180 | end 1181 | 1182 | it "should return '4.0' as its version" do 1183 | expect(@useragent.version).to eq("4.0") 1184 | end 1185 | 1186 | it "should return '534.30' as its webkit version" do 1187 | expect(@useragent.webkit.version).to eq("534.30") 1188 | end 1189 | 1190 | it "should return 'Android' as its platform" do 1191 | expect(@useragent.platform).to eq("Android") 1192 | end 1193 | 1194 | it "should return 'Android 4.0.3' as its os" do 1195 | expect(@useragent.os).to eq("Android 4.0.3") 1196 | end 1197 | 1198 | it "should return 'ko-kr' as its localization" do 1199 | expect(@useragent.localization).to eq("ko-kr") 1200 | end 1201 | 1202 | it { expect(@useragent).to be_mobile } 1203 | end 1204 | 1205 | describe "UserAgent: HUAWEI_MT7-TL00_TD/5.0 Android/4.4.2 (Linux; U; Android 4.4.2; zh-cn) Release/01.18.2014 Browser/WAP2.0 (AppleWebKit/537.36) Mobile Safari/537.36" do 1206 | before do 1207 | @useragent = UserAgent.parse("HUAWEI_MT7-TL00_TD/5.0 Android/4.4.2 (Linux; U; Android 4.4.2; zh-cn) Release/01.18.2014 Browser/WAP2.0 (AppleWebKit/537.36) Mobile Safari/537.36") 1208 | end 1209 | 1210 | it "should return 'Android' as its browser" do 1211 | expect(@useragent.browser).to eq("Android") 1212 | end 1213 | 1214 | it "should return :strong as its security" do 1215 | expect(@useragent.security).to eq(:strong) 1216 | end 1217 | 1218 | it "should return '537.36' as its build" do 1219 | expect(@useragent.build).to eq("537.36") 1220 | end 1221 | 1222 | it "should return nil as its version" do 1223 | expect(@useragent.version).to be_nil 1224 | end 1225 | 1226 | it "should return '537.36' as its webkit version" do 1227 | expect(@useragent.webkit.version).to eq("537.36") 1228 | end 1229 | 1230 | it "should return 'Android' as its platform" do 1231 | expect(@useragent.platform).to eq("Android") 1232 | end 1233 | 1234 | it "should return 'Android 4.4.2' as its os" do 1235 | expect(@useragent.os).to eq("Android 4.4.2") 1236 | end 1237 | 1238 | it "should return 'zh-cn' as its localization" do 1239 | expect(@useragent.localization).to eq("zh-cn") 1240 | end 1241 | 1242 | it { expect(@useragent).to be_mobile } 1243 | end 1244 | --------------------------------------------------------------------------------