diff --git a/README.md b/README.md index 82f79d1..708bb7e 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,10 @@ else { Building -------- -Simply `$ npm install` and `$ make` inside the bowser folder. +If you'd like to contribute a change to bowser, modify the files in src/, then run the following (you'll need node + npm installed): + + $ npm install + $ make Testing @@ -76,4 +79,4 @@ We started a list `src/useragents.js` with example user agents and their expecte 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 ;) +To run the test call `$ make test` diff --git a/bowser.js b/bowser.js index 52a0e02..4760640 100644 --- a/bowser.js +++ b/bowser.js @@ -5,8 +5,8 @@ */ !function (name, definition) { - if (typeof define == 'function') define(definition) - else if (typeof module != 'undefined' && module.exports) module.exports['browser'] = definition() + if (typeof module != 'undefined' && module.exports) module.exports['browser'] = definition() + else if (typeof define == 'function') define(definition) else this[name] = definition() }('bowser', function () { /** @@ -19,9 +19,11 @@ * 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", + * iPod: "Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_3 like Mac OS X; ja-jp) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 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" + * Amazon Silk: "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.0.22.153_10033210) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true" */ var ua = navigator.userAgent @@ -29,10 +31,12 @@ , 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) + , ipod = /ipod/i.test(ua) , touchpad = /touchpad/i.test(ua) + , silk = /silk/i.test(ua) + , safari = /safari/i.test(ua) && !chrome && !phantom && !silk , android = /android/i.test(ua) , opera = /opera/i.test(ua) || /opr/i.test(ua) , firefox = /firefox/i.test(ua) @@ -40,6 +44,7 @@ , seamonkey = /seamonkey\//i.test(ua) , webkitVersion = /version\/(\d+(\.\d+)?)/i , firefoxVersion = /firefox\/(\d+(\.\d+)?)/i + , mobile = /mobile/i.test(ua) , o function detect() { @@ -59,6 +64,10 @@ , webkit: t , chrome: t , version: ua.match(/(?:chrome|crios)\/(\d+(\.\d+)?)/i)[1] + , ipad: ipad + , iphone: iphone + , ios: !!ua.match(/crios/i) + , mobile: mobile } if (phantom) return { name: 'PhantomJS' @@ -72,14 +81,23 @@ , touchpad: t , version : ua.match(/touchpad\/(\d+(\.\d+)?)/i)[1] } - if (iphone || ipad) { + + if (silk) return { + name: 'Amazon Silk' + , webkit: t + , android: t + , mobile: t + , version : ua.match(/silk\/(\d+(\.\d+)?)/i)[1] + } + if (iphone || ipad || ipod) { o = { - name : iphone ? 'iPhone' : 'iPad' + name : iphone ? 'iPhone' : ipad ? 'iPad' : 'iPod' , webkit: t - , mobile: t + , mobile: iphone , ios: t , iphone: iphone , ipad: ipad + , ipod: ipod } // WTF: version is not part of user agent in web apps if (webkitVersion.test(ua)) { @@ -125,17 +143,17 @@ // 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) || + if ((bowser.msie && bowser.version >= 9) || + (bowser.chrome && bowser.version >= 20) || + (bowser.firefox && bowser.version >= 10.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) || - (bowser.firefox && bowser.version < 4.0) || + else if ((bowser.msie && bowser.version < 9) || + (bowser.chrome && bowser.version < 20) || + (bowser.firefox && bowser.version < 10.0) || (bowser.safari && bowser.version < 5) || (bowser.opera && bowser.version < 10.0)) { bowser.c = t diff --git a/bowser.min.js b/bowser.min.js index 39277ba..1dc92af 100644 --- a/bowser.min.js +++ b/bowser.min.js @@ -3,4 +3,4 @@ * https://github.com/ded/bowser * MIT License | (c) Dustin Diaz 2013 */ -!function(e,t){typeof define=="function"?define(t):typeof module!="undefined"&&module.exports?module.exports.browser=t():this[e]=t()}("bowser",function(){function g(){return n?{name:"Internet Explorer",msie:t,version:e.match(/(msie |rv:)(\d+(\.\d+)?)/i)[2]}:l?{name:"Opera",opera:t,version:e.match(d)?e.match(d)[1]:e.match(/opr\/(\d+(\.\d+)?)/i)[1]}:r?{name:"Chrome",webkit:t,chrome:t,version:e.match(/(?:chrome|crios)\/(\d+(\.\d+)?)/i)[1]}:i?{name:"PhantomJS",webkit:t,phantom:t,version:e.match(/phantomjs\/(\d+(\.\d+)+)/i)[1]}:a?{name:"TouchPad",webkit:t,touchpad:t,version:e.match(/touchpad\/(\d+(\.\d+)?)/i)[1]}:o||u?(m={name:o?"iPhone":"iPad",webkit:t,mobile:t,ios:t,iphone:o,ipad:u},d.test(e)&&(m.version=e.match(d)[1]),m):f?{name:"Android",webkit:t,android:t,mobile:t,version:(e.match(d)||e.match(v))[1]}:s?{name:"Safari",webkit:t,safari:t,version:e.match(d)[1]}:h?(m={name:"Gecko",gecko:t,mozilla:t,version:e.match(v)[1]},c&&(m.name="Firefox",m.firefox=t),m):p?{name:"SeaMonkey",seamonkey:t,version:e.match(/seamonkey\/(\d+(\.\d+)?)/i)[1]}:{}}var e=navigator.userAgent,t=!0,n=/(msie|trident)/i.test(e),r=/chrome|crios/i.test(e),i=/phantom/i.test(e),s=/safari/i.test(e)&&!r&&!i,o=/iphone/i.test(e),u=/ipad/i.test(e),a=/touchpad/i.test(e),f=/android/i.test(e),l=/opera/i.test(e)||/opr/i.test(e),c=/firefox/i.test(e),h=/gecko\//i.test(e),p=/seamonkey\//i.test(e),d=/version\/(\d+(\.\d+)?)/i,v=/firefox\/(\d+(\.\d+)?)/i,m,y=g();return y.msie&&y.version>=8||y.chrome&&y.version>=10||y.firefox&&y.version>=4||y.safari&&y.version>=5||y.opera&&y.version>=10?y.a=t:y.msie&&y.version<8||y.chrome&&y.version<10||y.firefox&&y.version<4||y.safari&&y.version<5||y.opera&&y.version<10?y.c=t:y.x=t,y}) \ No newline at end of file +!function(e,t){typeof module!="undefined"&&module.exports?module.exports.browser=t():typeof define=="function"?define(t):this[e]=t()}("bowser",function(){function w(){return n?{name:"Internet Explorer",msie:t,version:e.match(/(msie |rv:)(\d+(\.\d+)?)/i)[2]}:h?{name:"Opera",opera:t,version:e.match(m)?e.match(m)[1]:e.match(/opr\/(\d+(\.\d+)?)/i)[1]}:r?{name:"Chrome",webkit:t,chrome:t,version:e.match(/(?:chrome|crios)\/(\d+(\.\d+)?)/i)[1],ipad:o,iphone:s,ios:!!e.match(/crios/i),mobile:y}:i?{name:"PhantomJS",webkit:t,phantom:t,version:e.match(/phantomjs\/(\d+(\.\d+)+)/i)[1]}:a?{name:"TouchPad",webkit:t,touchpad:t,version:e.match(/touchpad\/(\d+(\.\d+)?)/i)[1]}:f?{name:"Amazon Silk",webkit:t,android:t,mobile:t,version:e.match(/silk\/(\d+(\.\d+)?)/i)[1]}:s||o||u?(b={name:s?"iPhone":o?"iPad":"iPod",webkit:t,mobile:s,ios:t,iphone:s,ipad:o,ipod:u},m.test(e)&&(b.version=e.match(m)[1]),b):c?{name:"Android",webkit:t,android:t,mobile:t,version:(e.match(m)||e.match(g))[1]}:l?{name:"Safari",webkit:t,safari:t,version:e.match(m)[1]}:d?(b={name:"Gecko",gecko:t,mozilla:t,version:e.match(g)[1]},p&&(b.name="Firefox",b.firefox=t),b):v?{name:"SeaMonkey",seamonkey:t,version:e.match(/seamonkey\/(\d+(\.\d+)?)/i)[1]}:{}}var e=navigator.userAgent,t=!0,n=/(msie|trident)/i.test(e),r=/chrome|crios/i.test(e),i=/phantom/i.test(e),s=/iphone/i.test(e),o=/ipad/i.test(e),u=/ipod/i.test(e),a=/touchpad/i.test(e),f=/silk/i.test(e),l=/safari/i.test(e)&&!r&&!i&&!f,c=/android/i.test(e),h=/opera/i.test(e)||/opr/i.test(e),p=/firefox/i.test(e),d=/gecko\//i.test(e),v=/seamonkey\//i.test(e),m=/version\/(\d+(\.\d+)?)/i,g=/firefox\/(\d+(\.\d+)?)/i,y=/mobile/i.test(e),b,E=w();return E.msie&&E.version>=9||E.chrome&&E.version>=20||E.firefox&&E.version>=10||E.safari&&E.version>=5||E.opera&&E.version>=10?E.a=t:E.msie&&E.version<9||E.chrome&&E.version<20||E.firefox&&E.version<10||E.safari&&E.version<5||E.opera&&E.version<10?E.c=t:E.x=t,E}) \ No newline at end of file diff --git a/package.json b/package.json index 6f78cb2..7cb4fd7 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,22 @@ { - "name": "bowser" - , "description": "a browser detector" - , "keywords": ["ender", "browser", "sniff", "detection"] - , "version": "0.3.4" - , "homepage": "https://github.com/ded/bowser" - , "author": "Dustin Diaz (http://dustindiaz.com)" - , "main": "./bowser.js" - , "repository": { - "type": "git" - , "url": "https://github.com/ded/bowser.git" - } - , "devDependencies": { - "smoosh": "*" + "name": "bowser", + "description": "a browser detector", + "keywords": [ + "ender", + "browser", + "sniff", + "detection" + ], + "version": "0.3.9", + "homepage": "https://github.com/ded/bowser", + "author": "Dustin Diaz (http://dustindiaz.com)", + "main": "./bowser.js", + "repository": { + "type": "git", + "url": "https://github.com/ded/bowser.git" + }, + "devDependencies": { + "smoosh": "*" , "mocha": "*" } } diff --git a/src/bowser.js b/src/bowser.js index 5ab09c2..aaf2ec4 100644 --- a/src/bowser.js +++ b/src/bowser.js @@ -1,9 +1,9 @@ !function (name, definition) { - if (typeof define == 'function') define(definition) - else if (typeof module != 'undefined' && module.exports) module.exports['browser'] = definition() + if (typeof module != 'undefined' && module.exports) module.exports['browser'] = definition() + else if (typeof define == 'function') define(definition) else this[name] = definition() }('bowser', function () { - /** + /** * See useragents.js for examples of navigator.userAgent */ @@ -15,17 +15,21 @@ 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) + , ipod = /ipod/i.test(ua) , touchpad = /touchpad/i.test(ua) + , silk = /silk/i.test(ua) + , safari = /safari/i.test(ua) && !chrome && !phantom && !silk , 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 , firefoxVersion = /firefox[ \/](\d+(\.\d+)?)/i + , mobile = /mobile/i.test(ua) , o = {} if (opera) { @@ -48,6 +52,10 @@ , webkit: t , chrome: t , version: ua.match(/(?:chrome|crios)\/(\d+(\.\d+)?)/i)[1] + , ipad: ipad + , iphone: iphone + , ios: !!ua.match(/crios/i) + , mobile: mobile } else if (phantom) o = { name: 'PhantomJS' @@ -61,14 +69,22 @@ , touchpad: t , version : ua.match(/touchpad\/(\d+(\.\d+)?)/i)[1] } - else if (iphone || ipad) { - o = { - name : iphone ? 'iPhone' : 'iPad' + else if (silk) o = { + name: 'Amazon Silk' , webkit: t + , android: t , mobile: t + , version : ua.match(/silk\/(\d+(\.\d+)?)/i)[1] + } + else if (iphone || ipad || ipod) { + o = { + name : iphone ? 'iPhone' : ipad ? 'iPad' : 'iPod' + , webkit: t + , mobile: iphone , ios: t , iphone: iphone , ipad: ipad + , ipod: ipod } // WTF: version is not part of user agent in web apps if (webkitVersion.test(ua)) { @@ -108,17 +124,17 @@ // 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) || + if ((o.msie && o.version >= 9) || + (o.chrome && o.version >= 20) || + (o.firefox && o.version >= 10.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) || + else if ((o.msie && o.version < 9) || + (o.chrome && o.version < 20) || + (o.firefox && o.version < 10.0) || (o.safari && o.version < 5) || (o.opera && o.version < 10.0)) { o.c = t diff --git a/src/useragents.js b/src/useragents.js index ba66622..08080ea 100644 --- a/src/useragents.js +++ b/src/useragents.js @@ -7,48 +7,86 @@ */ 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 + 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.17 Safari/537.36': { + chrome: true + , ipad: false + , iphone: false + , ios: false + , mobile: false + , 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 + , ipad: false + , iphone: false + , ios: false + , mobile: false + , 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 + , ipad: false + , iphone: false + , ios: false + , mobile: false + , 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 + , ipad: false + , iphone: false + , ios: false + , mobile: false + , 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 + , ipad: false + , iphone: false + , ios: false + , mobile: false + , 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 + , ipad: false + , iphone: false + , ios: false + , mobile: false + , version: '11.0' + , webkit: true + , c: 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 + , ipad: false + , iphone: false + , ios: false + , mobile: false + , version: '6.0' + , webkit: true + , c: true + } + } + , 'Amazon Silk': { + 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.0.22.153_10033210) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true': { + name: 'Amazon Silk' + , webkit: true + , android: true + , mobile: true + , version : '1.0' + , x: true + } } , Opera: { 'Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14': { @@ -175,7 +213,7 @@ module.exports.useragents = { , '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 + , c: 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 @@ -239,21 +277,21 @@ module.exports.useragents = { , gecko: true , firefox: true , version: '6.0' - , a: true + , c: 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 + , c: 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 + , c: true } , 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2b1) Gecko/20091014 Firefox/3.6b1 GTB5': { mozilla: true @@ -283,6 +321,7 @@ module.exports.useragents = { , version: '5.0' , iphone: true , ipad: false + , ipod: false , mobile: true , webkit: true , x: true @@ -292,6 +331,7 @@ module.exports.useragents = { , version: '3.0' , iphone: true , ipad: false + , ipod: false , mobile: true , webkit: true , x: true @@ -301,6 +341,7 @@ module.exports.useragents = { , version: '4.0' , iphone: true , ipad: false + , ipod: false , mobile: true , webkit: true , x: true @@ -310,6 +351,7 @@ module.exports.useragents = { , version: '3.1' , iphone: true , ipad: false + , ipod: false , mobile: true , webkit: true , x: true @@ -318,37 +360,45 @@ module.exports.useragents = { , 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 + , name: 'iPad' , version: '6.0' , iphone: false , ipad: true - , mobile: true + , ipod: false + , mobile: false , 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 + , name: 'iPad' , version: '5.1' , iphone: false , ipad: true - , mobile: true + , ipod: false + , mobile: false , 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 + , name: 'iPad' , version: '5.0' , iphone: false , ipad: true - , mobile: true + , ipod: false + , mobile: false , 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 + , name: 'iPad' , version: '4.0' , iphone: false , ipad: true - , mobile: true + , ipod: false + , mobile: false , webkit: true , x: true } diff --git a/test/test.js b/test/test.js index d2702af..ef881ef 100644 --- a/test/test.js +++ b/test/test.js @@ -28,23 +28,34 @@ function objLength(obj) { return size } +function objKeys(obj) { + var keys = [] + , key + for (key in obj) { + if (obj.hasOwnProperty(key)) { + keys.push(key) + } + } + keys.sort(); + return keys.join(', ') +} + /* Groups */ for (g in allUserAgents) { (function(group, userAgents) { describe(group, function() { /* User Agents */ for (ua in userAgents) { (function(userAgent, expections) { - describe('#' + userAgent, function() { + describe('user agent "' + 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) + it('should have ' + objLength(expections) + ' properties', function() { + assert.equal(objKeys(result), objKeys(expections)) }) /* Properties */