Skip to content

Commit

Permalink
Add test for Safari on Windows detection
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Dec 11, 2014
1 parent 8dacf97 commit a4b55e7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/),
iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/),
webos = ua.match(/(webOS|hpwOS)[\s\/]([\d.]+)/),
win = platform.match(/Win\d{2}|Windows/),
win = /Win\d{2}|Windows/.test(platform),
wp = ua.match(/Windows Phone ([\d.]+)/),
touchpad = webos && ua.match(/TouchPad/),
kindle = ua.match(/Kindle\/([\d.]+)/),
Expand Down Expand Up @@ -52,7 +52,10 @@
if (chrome) browser.chrome = true, browser.version = chrome[1]
if (firefox) browser.firefox = true, browser.version = firefox[1]
if (ie) browser.ie = true, browser.version = ie[1]
if (safari && (osx || os.ios || win)) {browser.safari = true; if (osx) browser.version = safari[1]}
if (safari && (osx || os.ios || win)) {
browser.safari = true
if (!os.ios) browser.version = safari[1]
}
if (webview) browser.webview = true

os.tablet = !!(ipad || playbook || (android && !ua.match(/Mobile/)) ||
Expand Down
13 changes: 13 additions & 0 deletions test/detect.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ <h1>Zepto Detect unit tests</h1>
Safari_OSX_7_0_1: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.73.11 (KHTML, like Gecko) Version/7.0.1 Safari/537.73.11",
Safari_OSX_7_0: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9) AppleWebKit/537.71 (KHTML, like Gecko) Version/7.0 Safari/537.71",
Safari_OSX_6_0: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25",
Safari_Windows_NT: "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27",

WebOS_1_4_0_Pre: "Mozilla/5.0 (webOS/1.4.0; U; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Version/1.0 Safari/532.2 Pre/1.1",
WebOS_1_4_0_Pixi: "Mozilla/5.0 (webOS/1.4.0; U; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Version/1.0 Safari/532.2 Pixi/1.1",
Expand Down Expand Up @@ -125,6 +126,18 @@ <h1>Zepto Detect unit tests</h1>
});
},

testSafariWindows: function(t){
detect(UA.Safari_Windows_NT, "Windows", function(os, browser){
t.assertUndefined(os.osx)
t.assertUndefined(os.ios)
t.assertUndefined(os.wp)
t.assertTrue(browser.webkit)
t.assertTrue(browser.safari)
t.assertFalse(!!browser.chrome)
t.assertEqual("5.0.4", browser.version)
});
},

testWebOS: function(t){
detect(UA.WebOS_1_4_0_Pre, function(os, browser){
t.assertTrue(os.webos)
Expand Down

0 comments on commit a4b55e7

Please sign in to comment.