Permalink
Browse files

Detecting QuickTime.

  • Loading branch information...
1 parent 318fbd8 commit ec471bd656555814f5313256dbd5e9b46dc9760a @fnando committed Oct 27, 2010
Showing with 19 additions and 2 deletions.
  1. +9 −2 lib/browser.rb
  2. +10 −0 test/browser_test.rb
View
@@ -23,7 +23,8 @@ class Browser
:opera => "Opera",
:other => "Other",
:safari => "Safari",
- :psp => "PlayStation Portable"
+ :psp => "PlayStation Portable",
+ :quicktime => "QuickTime"
}
LANGUAGES = {
@@ -177,6 +178,7 @@ def id
when blackberry? then :blackberry
when safari? then :safari
when psp? then :psp
+ when quicktime? then :quicktime
else
:other
end
@@ -194,7 +196,7 @@ def version
# Return the full version.
def full_version
- _, v = *ua.match(/(?:Version|MSIE|Opera|Firefox|Chrome|BlackBerry[^\/]+)[\/ ]([\d.]+)/)
+ _, v = *ua.match(/(?:Version|MSIE|Opera|Firefox|Chrome|QuickTime|BlackBerry[^\/]+)[\/ ]([\d.]+)/)
v || "0.0"
end
@@ -213,6 +215,11 @@ def mobile?
!!(ua =~ /(Mobile|Symbian|MIDP|Windows CE)/) || blackberry? || psp?
end
+ # Detect if browser is QuickTime
+ def quicktime?
+ !!(ua =~ /QuickTime/i)
+ end
+
# Detect if browser is BlackBerry
def blackberry?
!!(ua =~ /BlackBerry/)
View
@@ -25,6 +25,7 @@ class BrowserTest < Test::Unit::TestCase
ANDROID = "Android SDK 1.5r3: Mozilla/5.0 (Linux; U; Android 1.5; de-; sdk Build/CUPCAKE) AppleWebkit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1"
BLACKBERRY = "BlackBerry7100i/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/103"
PSP = "Mozilla/4.0 (PSP (PlayStation Portable); 2.00)"
+ QUICKTIME = "QuickTime/7.6.8 (qtver=7.6.8;os=Windows NT 5.1Service Pack 3)"
def setup
@browser = Browser.new
@@ -211,6 +212,15 @@ def test_detect_blackberry
assert_equal "4", @browser.version
end
+ def test_detect_quicktime
+ @browser.ua = QUICKTIME
+
+ assert_equal "QuickTime", @browser.name
+ assert @browser.quicktime?
+ assert_equal "7.6.8", @browser.full_version
+ assert_equal "7", @browser.version
+ end
+
def test_detect_psp
@browser.ua = PSP

0 comments on commit ec471bd

Please sign in to comment.