|
| 1 | +var whichOs = require('../which_os'); |
| 2 | + |
| 3 | +describe('whichOs', function () { |
| 4 | + it('returns \'android\'', function () { |
| 5 | + var androidUA = [ |
| 6 | + 'Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30', |
| 7 | + 'Mozilla/5.0 (Linux; U; Android 4.0.3; de-ch; HTC Sensation Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30', |
| 8 | + 'Mozilla/5.0 (Linux; U; Android 2.3; en-us) AppleWebKit/999+ (KHTML, like Gecko) Safari/999.9' |
| 9 | + ].forEach(function (userAgent) { |
| 10 | + expect(whichOs(userAgent)).to.equal('android'); |
| 11 | + }) |
| 12 | + }); |
| 13 | + |
| 14 | + it('returns \'blackberry\'', function () { |
| 15 | + var bbUA = [ |
| 16 | + 'Mozilla/5.0 (BB10; <Device Model>) AppleWebKit/<WebKit Version> (KHTML, like Gecko) Version/<BB Version #> Mobile Safari/<WebKit Version>' |
| 17 | + ].forEach(function (userAgent) { |
| 18 | + expect(whichOs(userAgent)).to.equal('blackberry'); |
| 19 | + }) |
| 20 | + }); |
| 21 | + |
| 22 | + it('returns \'iphone\'', function () { |
| 23 | + var iphoneUA = [ |
| 24 | + 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1C25 Safari/419.3', |
| 25 | + 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7', |
| 26 | + 'Mozilla/5.0 (iPod touch; CPU iPhone OS 7_0_3 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11B511 Safari/9537.53' |
| 27 | + ].forEach(function (userAgent) { |
| 28 | + expect(whichOs(userAgent)).to.equal('iphone'); |
| 29 | + }) |
| 30 | + }); |
| 31 | + |
| 32 | + it('returns \'mac\'', function () { |
| 33 | + var macUA = [ |
| 34 | + 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10', |
| 35 | + 'Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53', |
| 36 | + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2' |
| 37 | + ].forEach(function (userAgent) { |
| 38 | + expect(whichOs(userAgent)).to.equal('mac'); |
| 39 | + }) |
| 40 | + }); |
| 41 | + |
| 42 | + it('returns \'windows\'', function () { |
| 43 | + var windowsUA = [ |
| 44 | + 'Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14', |
| 45 | + 'Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0', |
| 46 | + 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36' |
| 47 | + ].forEach(function (userAgent) { |
| 48 | + expect(whichOs(userAgent)).to.equal('windows'); |
| 49 | + }) |
| 50 | + }); |
| 51 | + |
| 52 | + it('returns \'windows mobile\'', function () { |
| 53 | + var WindowsUA = [ |
| 54 | + 'Mozilla/5.0 (Windows Phone 8.1; ARM; Trident/7.0; Touch; rv:11; IEMobile/11.0) like Android 4.1.2; compatible) like iPhone OS 7_0_3 Mac OS X WebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.99 Mobile Safari /537.36', |
| 55 | + 'Mozilla/5.0 (Windows Phone 8.1; ARM; Trident/7.0; Touch; rv:11; IEMobile/11.0; NOKIA; Lumia 928) like Gecko', |
| 56 | + 'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; rv:11; NOKIA; Lumia 920) like Gecko' |
| 57 | + ].forEach(function (userAgent) { |
| 58 | + expect(whichOs(userAgent)).to.equal('windows mobile'); |
| 59 | + }) |
| 60 | + }); |
| 61 | + |
| 62 | + it('returns \'unknown os\'', function () { |
| 63 | + var unknown = [ |
| 64 | + 'Opera/9.80 (NT 6.0) Presto/2.12.388 Version/12.14' |
| 65 | + ].forEach(function (userAgent) { |
| 66 | + expect(whichOs(userAgent)).to.equal('unknown os'); |
| 67 | + }) |
| 68 | + }); |
| 69 | +}); |
0 commit comments