Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added PSP.

  • Loading branch information...
commit 91bd8a2657e67354cc9dfe2da74b2c7eba1a1095 1 parent 9d2706d
@fnando authored
Showing with 19 additions and 3 deletions.
  1. +1 −1  Rakefile
  2. +9 −2 lib/browser.rb
  3. +9 −0 test/browser_test.rb
View
2  Rakefile
@@ -1,7 +1,7 @@
require "rcov/rcovtask"
require "rake/testtask"
require "rake/rdoctask"
-require "lib/browser/version"
+require "./lib/browser/version"
Rcov::RcovTask.new do |t|
t.test_files = FileList["test/**/*_test.rb"]
View
11 lib/browser.rb
@@ -22,7 +22,8 @@ class Browser
:ipod => "iPod Touch",
:opera => "Opera",
:other => "Other",
- :safari => "Safari"
+ :safari => "Safari",
+ :psp => "PlayStation Portable"
}
LANGUAGES = {
@@ -175,6 +176,7 @@ def id
when android? then :android
when blackberry? then :blackberry
when safari? then :safari
+ when psp? then :psp
else
:other
end
@@ -208,7 +210,7 @@ def webkit?
# Detect if browser is mobile.
def mobile?
- !!(ua =~ /(Mobile|Symbian|MIDP|Windows CE)/) || blackberry?
+ !!(ua =~ /(Mobile|Symbian|MIDP|Windows CE)/) || blackberry? || psp?
end
# Detect if browser is BlackBerry
@@ -276,6 +278,11 @@ def ie9?
ie? && version == "9"
end
+ # Detect if browser is running from PSP.
+ def psp?
+ !!(ua =~ /PSP/)
+ end
+
# Detect if browser is Opera.
def opera?
!!(ua =~ /Opera/)
View
9 test/browser_test.rb
@@ -24,6 +24,7 @@ class BrowserTest < Test::Unit::TestCase
CHROME = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.99 Safari/533.4"
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)"
def setup
@browser = Browser.new
@@ -210,6 +211,14 @@ def test_detect_blackberry
assert_equal "4", @browser.version
end
+ def test_detect_psp
+ @browser.ua = PSP
+
+ assert_equal "PlayStation Portable", @browser.name
+ assert @browser.psp?
+ assert @browser.mobile?
+ end
+
def test_detect_other_mobiles
@browser.ua = "Symbian OS"
assert @browser.mobile?
Please sign in to comment.
Something went wrong with that request. Please try again.