1
0
mirror of https://github.com/lancedikson/bowser synced 2024-10-27 20:34:22 +00:00

Make testable and add tests.

This commit is contained in:
Hannes Diercks 2013-12-13 13:17:10 +01:00
parent 88589615f4
commit 89cffac4a5
6 changed files with 554 additions and 69 deletions

View File

@ -1,2 +1,16 @@
boosh: boosh:
node make/build.js node make/build.js
REPORTER = dot
test:
@NODE_ENV=test ./node_modules/.bin/mocha \
--reporter $(REPORTER) \
test-w:
@NODE_ENV=test ./node_modules/.bin/mocha \
--reporter $(REPORTER) \
--growl \
--watch
.PHONY: test test-w

View File

@ -61,3 +61,19 @@ else if (bowser.c) {
else { else {
// unsupported (bowser.x) // unsupported (bowser.x)
} }
```
Building
--------
Simply `$ npm install` and `$ make` inside the bowser folder.
Testing
-------
We started a list `src/useragents.js` with example user agents and their expected bowser object.
Whenever you add support for new browsers or notice a bug / mismatch, please update the list and
check if all tests are still passing.
To run the test call `$ make test` and hope for green light ;)

View File

@ -12,5 +12,6 @@
} }
, "devDependencies": { , "devDependencies": {
"smoosh": "*" "smoosh": "*"
, "mocha": "*"
} }
} }

View File

@ -4,69 +4,64 @@
else this[name] = definition() else this[name] = definition()
}('bowser', function () { }('bowser', function () {
/** /**
* navigator.userAgent => * See useragents.js for examples of navigator.userAgent
* Chrome: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.57 Safari/534.24"
* Opera: "Opera/9.80 (Macintosh; Intel Mac OS X 10.6.7; U; en) Presto/2.7.62 Version/11.01"
* Safari: "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-us) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1"
* IE: "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; 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)"
* IE>=11: "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; .NET4.0E; .NET4.0C; Media Center PC 6.0; rv:11.0) like Gecko"
* Firefox: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0) Gecko/20100101 Firefox/4.0"
* iPhone: "Mozilla/5.0 (iPhone Simulator; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5"
* iPad: "Mozilla/5.0 (iPad; U; CPU OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5",
* Android: "Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; T-Mobile G2 Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"
* Touchpad: "Mozilla/5.0 (hp-tabled;Linux;hpwOS/3.0.5; U; en-US)) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/234.83 Safari/534.6 TouchPad/1.0"
* PhantomJS: "Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.5.0 Safari/534.34"
*/ */
var ua = navigator.userAgent var t = true,
, t = true v /* temporary placeholder for versions. */
, ie = /(msie|trident)/i.test(ua)
, chrome = /chrome|crios/i.test(ua)
, phantom = /phantom/i.test(ua)
, safari = /safari/i.test(ua) && !chrome && !phantom
, iphone = /iphone/i.test(ua)
, ipad = /ipad/i.test(ua)
, touchpad = /touchpad/i.test(ua)
, android = /android/i.test(ua)
, opera = /opera/i.test(ua) || /opr/i.test(ua)
, firefox = /firefox/i.test(ua)
, gecko = /gecko\//i.test(ua)
, seamonkey = /seamonkey\//i.test(ua)
, webkitVersion = /version\/(\d+(\.\d+)?)/i
, firefoxVersion = /firefox\/(\d+(\.\d+)?)/i
, o
function detect() { function detect(ua) {
if (ie) return { var ie = /(msie|trident)/i.test(ua)
, chrome = /chrome|crios/i.test(ua)
, phantom = /phantom/i.test(ua)
, safari = /safari/i.test(ua) && !chrome && !phantom
, iphone = /iphone/i.test(ua)
, ipad = /ipad/i.test(ua)
, touchpad = /touchpad/i.test(ua)
, android = /android/i.test(ua)
, opera = /opera/i.test(ua) || /opr/i.test(ua)
, firefox = /firefox/i.test(ua)
, gecko = /gecko\//i.test(ua)
, seamonkey = /seamonkey\//i.test(ua)
, webkitVersion = /version\/(\d+(\.\d+)?)/i
, firefoxVersion = /firefox[ \/](\d+(\.\d+)?)/i
, o = {}
if (opera) {
if ((v = ua.match(webkitVersion)) && v.length > 1) v = v[1]
else if ((v = ua.match(/opr\/(\d+(\.\d+)?)/i)) && v.length > 1) v = v[1]
else if ((v = ua.match(/opera[ \/](\d+(\.\d+)?)/i)) && v.length > 1) v = v[1]
else v = 0
o = {
name: 'Opera'
, opera: t
, version: v
}
} else if (ie) o = {
name: 'Internet Explorer' name: 'Internet Explorer'
, msie: t , msie: t
, version: ua.match(/(msie |rv:)(\d+(\.\d+)?)/i)[2] , version: ua.match(/(msie |rv:)(\d+(\.\d+)?)/i)[2]
} }
if (opera) return { else if (chrome) o = {
name: 'Opera'
, opera: t
, version: ua.match(webkitVersion) ? ua.match(webkitVersion)[1] : ua.match(/opr\/(\d+(\.\d+)?)/i)[1]
}
if (chrome) return {
name: 'Chrome' name: 'Chrome'
, webkit: t , webkit: t
, chrome: t , chrome: t
, version: ua.match(/(?:chrome|crios)\/(\d+(\.\d+)?)/i)[1] , version: ua.match(/(?:chrome|crios)\/(\d+(\.\d+)?)/i)[1]
} }
if (phantom) return { else if (phantom) o = {
name: 'PhantomJS' name: 'PhantomJS'
, webkit: t , webkit: t
, phantom: t , phantom: t
, version: ua.match(/phantomjs\/(\d+(\.\d+)+)/i)[1] , version: ua.match(/phantomjs\/(\d+(\.\d+)?)/i)[1]
} }
if (touchpad) return { else if (touchpad) o = {
name: 'TouchPad' name: 'TouchPad'
, webkit: t , webkit: t
, touchpad: t , touchpad: t
, version : ua.match(/touchpad\/(\d+(\.\d+)?)/i)[1] , version : ua.match(/touchpad\/(\d+(\.\d+)?)/i)[1]
} }
if (iphone || ipad) { else if (iphone || ipad) {
o = { o = {
name : iphone ? 'iPhone' : 'iPad' name : iphone ? 'iPhone' : 'iPad'
, webkit: t , webkit: t
@ -79,61 +74,68 @@
if (webkitVersion.test(ua)) { if (webkitVersion.test(ua)) {
o.version = ua.match(webkitVersion)[1] o.version = ua.match(webkitVersion)[1]
} }
return o
} }
if (android) return { else if (android) o = {
name: 'Android' name: 'Android'
, webkit: t , webkit: t
, android: t , android: t
, mobile: t , mobile: t
, version: (ua.match(webkitVersion) || ua.match(firefoxVersion))[1] , version: (ua.match(webkitVersion) || ua.match(firefoxVersion))[1]
} }
if (safari) return { else if (safari) o = {
name: 'Safari' name: 'Safari'
, webkit: t , webkit: t
, safari: t , safari: t
, version: ua.match(webkitVersion)[1] , version: ((v = ua.match(webkitVersion)) ? v[1] : 0)
} }
if (gecko) { else if (gecko) {
o = { o = {
name: 'Gecko' name: 'Gecko'
, gecko: t , gecko: t
, mozilla: t , mozilla: t
, version: ua.match(firefoxVersion)[1] , version: ((v = ua.match(firefoxVersion)) && v? v[1] : 0)
} }
if (firefox) { if (firefox) {
o.name = 'Firefox'; o.name = 'Firefox';
o.firefox = t; o.firefox = t;
} }
return o
} }
if (seamonkey) return { else if (seamonkey) o = {
name: 'SeaMonkey' name: 'SeaMonkey'
, seamonkey: t , seamonkey: t
, version: ua.match(/seamonkey\/(\d+(\.\d+)?)/i)[1] , version: ua.match(/seamonkey\/(\d+(\.\d+)?)/i)[1]
} }
return {}
// Graded Browser Support
// http://developer.yahoo.com/yui/articles/gbs
if ((o.msie && o.version >= 8) ||
(o.chrome && o.version >= 10) ||
(o.firefox && o.version >= 4.0) ||
(o.safari && o.version >= 5) ||
(o.opera && o.version >= 10.0)) {
o.a = t;
}
else if ((o.msie && o.version < 8) ||
(o.chrome && o.version < 10) ||
(o.firefox && o.version < 4.0) ||
(o.safari && o.version < 5) ||
(o.opera && o.version < 10.0)) {
o.c = t
} else o.x = t
return o
} }
var bowser = detect() var bowser = detect(typeof navigator !== 'undefined' ? navigator.userAgent : '')
// Graded Browser Support
// http://developer.yahoo.com/yui/articles/gbs
if ((bowser.msie && bowser.version >= 8) ||
(bowser.chrome && bowser.version >= 10) ||
(bowser.firefox && bowser.version >= 4.0) ||
(bowser.safari && bowser.version >= 5) ||
(bowser.opera && bowser.version >= 10.0)) {
bowser.a = t;
}
else if ((bowser.msie && bowser.version < 8) || /*
(bowser.chrome && bowser.version < 10) || * Set our detect method to the main bowser object so we can
(bowser.firefox && bowser.version < 4.0) || * reuse it to test other user agents.
(bowser.safari && bowser.version < 5) || * This is needed to implement future tests.
(bowser.opera && bowser.version < 10.0)) { */
bowser.c = t bowser._detect = detect;
} else bowser.x = t
return bowser return bowser
}); });

388
src/useragents.js Normal file
View File

@ -0,0 +1,388 @@
/**
* Example User Agents and their expected bowser objects.
* Most of them where found at http://www.useragentstring.com/
*
* @see test/test.js
* @author hannes.diercks@jimdo.com
*/
module.exports.useragents = {
Chrome: {
'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.17 Safari/537.36': {
chrome: true
, version: '30.0'
, webkit: true
, a: true
}
, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36': {
chrome: true
, version: '29.0'
, webkit: true
, a: true
}
, 'Mozilla/5.0 (X11; CrOS i686 4319.74.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36': {
chrome: true
, version: '29.0'
, webkit: true
, a: true
}
, 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36': {
chrome: true
, version: '29.0'
, webkit: true
, a: true
}
, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1468.0 Safari/537.36': {
chrome: true
, version: '28.0'
, webkit: true
, a: true
}
, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.57 Safari/534.24': {
chrome: true
, version: '11.0'
, webkit: true
, a: true
}
, 'Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.462.0 Safari/534.3': {
chrome: true
, version: '6.0'
, webkit: true
, c: true
}
}
, Opera: {
'Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14': {
opera: true
, version: '12.14'
, a: true
}
, 'Mozilla/5.0 (Windows NT 6.0; rv:2.0) Gecko/20100101 Firefox/4.0 Opera 12.14': {
opera: true
, version: '12.14'
, a: true
}
, 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0) Opera 12.14': {
opera: true
, version: '12.14'
, a: true
}
, 'Opera/12.80 (Windows NT 5.1; U; en) Presto/2.10.289 Version/12.02': {
opera: true
, version: '12.02'
, a: true
}
, 'Opera/9.80 (X11; Linux i686; U; es-ES) Presto/2.8.131 Version/11.11': {
opera: true
, version: '11.11'
, a: true
}
, 'Opera/9.80 (Macintosh; Intel Mac OS X 10.6.7; U; en) Presto/2.7.62 Version/11.01': {
opera: true
, version: '11.01'
, a: true
}
, 'Opera/9.80 (Windows NT 5.2; U; zh-cn) Presto/2.6.30 Version/10.63': {
opera: true
, version: '10.63'
, a: true
}
, 'Opera/9.80 (X11; Linux i686; U; it) Presto/2.5.24 Version/10.54': {
opera: true
, version: '10.54'
, a: true
}
, 'Opera/9.70 (Linux ppc64 ; U; en) Presto/2.2.1': {
opera: true
, version: '9.70'
, c: true
}
, 'Opera/9.63 (X11; Linux i686)': {
opera: true
, version: '9.63'
, c: true
}
, 'Mozilla/5.0 (X11; Linux i686; U; en) Opera 8.52': {
opera: true
, version: '8.52'
, c: true
}
}
, Safari: {
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.13+ (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2': {
safari: true
, version: '5.1'
, webkit: true
, a: true
}
, 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-us) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1': {
safari: true
, version: '5.0'
, webkit: true
, a: true
}
, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; ru-RU) AppleWebKit/533.18.1 (KHTML, like Gecko) Version/5.0.2 Safari/533.18.5': {
safari: true
, version: '5.0'
, webkit: true
, a: true
}
, 'Mozilla/5.0 (X11; U; Linux x86_64; en-us) AppleWebKit/531.2+ (KHTML, like Gecko) Version/5.0 Safari/531.2+': {
safari: true
, version: '5.0'
, webkit: true
, a: true
}
, 'Mozilla/5.0 (Windows; U; Windows NT 5.0; en-en) AppleWebKit/533.16 (KHTML, like Gecko) Version/4.1 Safari/533.16': {
safari: true
, version: '4.1'
, webkit: true
, c: true
}
, 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_6_1; en_GB, en_US) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Safari/531.21.10': {
safari: true
, version: '4.0'
, webkit: true
, c: true
}
, 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; de-de) AppleWebKit/525.28.3 (KHTML, like Gecko) Version/3.2.3 Safari/525.28.3': {
safari: true
, version: '3.2'
, webkit: true
, c: true
}
}
, 'Internet Explorer': {
'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; .NET4.0E; .NET4.0C; Media Center PC 6.0; rv:11.0) like Gecko': {
msie: true
, version: '11.0'
, a: true
}
, 'Mozilla/5.0 (compatible; MSIE 10.6; Windows NT 6.1; Trident/5.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727) 3gpp-gba UNTRUSTED/1.0': {
msie: true
, version: '10.6'
, a: true
}
, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/4.0; InfoPath.2; SV1; .NET CLR 2.0.50727; WOW64)': {
msie: true
, version: '10.0'
, a: true
}
, 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 2.0.50727; Media Center PC 6.0)': {
msie: true
, version: '9.0'
, a: true
}
, 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; 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)': {
msie: true
, version: '8.0'
, a: true
}
, 'Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727)': {
msie: true
, version: '7.0'
, c: true
}
, 'Mozilla/4.0 (compatible; MSIE 6.1; Windows XP; .NET CLR 1.1.4322; .NET CLR 2.0.50727)': {
msie: true
, version: '6.1'
, c: true
}
, 'Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0) (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)': {
msie: true
, version: '6.0'
, c: true
}
, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT)': {
msie: true
, version: '5.01'
, c: true
}
}
, Firefox: {
'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0': {
mozilla: true
, gecko: true
, firefox: true
, version: '25.0'
, a: true
}
, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0': {
mozilla: true
, gecko: true
, firefox: true
, version: '24.0'
, a: true
}
, 'Mozilla/5.0 (X11; Linux i686; rv:21.0) Gecko/20100101 Firefox/21.0': {
mozilla: true
, gecko: true
, firefox: true
, version: '21.0'
, a: true
}
, 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:15.0) Gecko/20120910144328 Firefox/15.0.2': {
mozilla: true
, gecko: true
, firefox: true
, version: '15.0'
, a: true
}
, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; WOW64; en-US; rv:2.0.4) Gecko/20120718 AskTbAVR-IDW/3.12.5.17700 Firefox/14.0.1': {
mozilla: true
, gecko: true
, firefox: true
, version: '14.0'
, a: true
}
, 'Mozilla/5.0 (Windows NT 5.1; rv:6.0) Gecko/20100101 Firefox/6.0 FirePHP/0.6': {
mozilla: true
, gecko: true
, firefox: true
, version: '6.0'
, a: true
}
, 'Mozilla/5.0 (X11; Linux x86_64; rv:2.2a1pre) Gecko/20100101 Firefox/4.2a1pre': {
mozilla: true
, gecko: true
, firefox: true
, version: '4.2'
, a: true
}
, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0) Gecko/20100101 Firefox/4.0': {
mozilla: true
, gecko: true
, firefox: true
, version: '4.0'
, a: true
}
, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2b1) Gecko/20091014 Firefox/3.6b1 GTB5': {
mozilla: true
, gecko: true
, firefox: true
, version: '3.6'
, c: true
}
, 'Mozilla/5.0 (Windows; U; Windows NT 6.0; de; rv:1.9.0.15) Gecko/2009101601 Firefox 2.1 (.NET CLR 3.5.30729)': {
mozilla: true
, gecko: true
, firefox: true
, version: '2.1'
, c: true
}
, 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.7) Gecko/20061014 Firefox/1.5.0.7': {
mozilla: true
, gecko: true
, firefox: true
, version: '1.5'
, c: true
}
}
, iPhone: {
'Mozilla/5.0 (iPhone Simulator; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5': {
ios: true
, version: '5.0'
, iphone: true
, ipad: false
, mobile: true
, webkit: true
, x: true
}
, 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3': {
ios: true
, version: '3.0'
, iphone: true
, ipad: false
, mobile: true
, webkit: true
, x: true
}
, '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/8B5097d Safari/6531.22.7': {
ios: true
, version: '4.0'
, iphone: true
, ipad: false
, mobile: true
, webkit: true
, x: true
}
, 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_5_2; en-gb) AppleWebKit/526+ (KHTML, like Gecko) Version/3.1 iPhone': {
ios: true
, version: '3.1'
, iphone: true
, ipad: false
, mobile: true
, webkit: true
, x: true
}
}
, iPad: {
'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25': {
ios: true
, version: '6.0'
, iphone: false
, ipad: true
, mobile: true
, webkit: true
, x: true
}
, 'Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko ) Version/5.1 Mobile/9B176 Safari/7534.48.3': {
ios: true
, version: '5.1'
, iphone: false
, ipad: true
, mobile: true
, webkit: true
, x: true
}
, 'Mozilla/5.0 (iPad; U; CPU OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5': {
ios: true
, version: '5.0'
, iphone: false
, ipad: true
, mobile: true
, webkit: true
, x: true
}
, 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; es-es) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B360 Safari/531.21.10': {
ios: true
, version: '4.0'
, iphone: false
, ipad: true
, mobile: true
, webkit: true
, x: true
}
}
, Android: {
'Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; T-Mobile G2 Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1': {
android: true
, webkit: true
, version: 4.0
, mobile: true
, x: true
}
, 'Mozilla/5.0 (Linux; U; Android 1.6; ar-us; SonyEricssonX10i Build/R2BA026) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1': {
android: true
, webkit: true
, version: 3.1
, mobile: true
, x: true
}
}
, TouchPad: {
'Mozilla/5.0 (hp-tabled;Linux;hpwOS/3.0.5; U; en-US)) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/234.83 Safari/534.6 TouchPad/1.0': {
touchpad: true
, version: '1.0'
, webkit: true
, x: true
}
}
, PhantomJS: {
'Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.5.0 Safari/534.34': {
phantom: true
, webkit: true
, version: '1.5'
, x: true
}
}
};

64
test/test.js Normal file
View File

@ -0,0 +1,64 @@
/**
* Loop through all entries in our user agents object and test everything.
*
* @see src/useragents.js
* @author hannes.diercks@jimdo.com
*/
var g
, ua
, p
, assert = require('assert')
, browser = require('../src/bowser').browser
, allUserAgents = require('../src/useragents').useragents
/**
* Get the length of an object.
* http://stackoverflow.com/questions/5223/length-of-javascript-object-ie-associative-array
*
* @param {Object} obj
* @return {Number}
*/
function objLength(obj) {
var size = 0
, key
for (key in obj) {
if (obj.hasOwnProperty(key)) size++
}
return size
}
/* Groups */
for (g in allUserAgents) { (function(group, userAgents) {
describe(group, function() {
/* User Agents */
for (ua in userAgents) { (function(userAgent, expections) {
describe('#' + userAgent, function() {
expections.name = group
/* Get the result from bowser. */
var result = browser._detect(userAgent)
, expectionLength = objLength(expections)
/* At first, check if the result has the correct length. */
it('Should have ' + expectionLength + ' properties', function() {
assert.equal(objLength(result), expectionLength)
})
/* Properties */
for (p in expections) { (function(property, value, resultValue) {
/* Now ensure correctness of every property. */
it('\'s Property "' + property + '" should be ' + value, function() {
assert.equal(resultValue, value)
})
})(p, expections[p], result[p])}
})
})(ua, userAgents[ua])}
})
})(g, allUserAgents[g])}