|
16 | 16 | */
|
17 | 17 |
|
18 | 18 | import { expect } from 'chai';
|
19 |
| -import { _getBrowserName, BrowserName } from './browser'; |
| 19 | +import { _getBrowserName, BrowserName, _isIOS } from './browser'; |
20 | 20 |
|
21 |
| -describe('core/util/_getBrowserName', () => { |
22 |
| - it('should recognize Opera', () => { |
23 |
| - const userAgent = |
24 |
| - 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36 OPR/36.0.2130.74'; |
25 |
| - expect(_getBrowserName(userAgent)).to.eq(BrowserName.OPERA); |
26 |
| - }); |
| 21 | +describe('core/util/browser', () => { |
| 22 | + context('_getBrowserName', () => { |
| 23 | + it('should recognize Opera', () => { |
| 24 | + const userAgent = |
| 25 | + 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36 OPR/36.0.2130.74'; |
| 26 | + expect(_getBrowserName(userAgent)).to.eq(BrowserName.OPERA); |
| 27 | + }); |
27 | 28 |
|
28 |
| - it('should recognize IE', () => { |
29 |
| - const userAgent = |
30 |
| - 'Mozilla/5.0 (compatible; MSIE 9.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)'; |
31 |
| - expect(_getBrowserName(userAgent)).to.eq(BrowserName.IE); |
32 |
| - }); |
| 29 | + it('should recognize IE', () => { |
| 30 | + const userAgent = |
| 31 | + 'Mozilla/5.0 (compatible; MSIE 9.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)'; |
| 32 | + expect(_getBrowserName(userAgent)).to.eq(BrowserName.IE); |
| 33 | + }); |
33 | 34 |
|
34 |
| - it('should recognize Edge', () => { |
35 |
| - const userAgent = |
36 |
| - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240'; |
37 |
| - expect(_getBrowserName(userAgent)).to.eq(BrowserName.EDGE); |
38 |
| - }); |
| 35 | + it('should recognize Edge', () => { |
| 36 | + const userAgent = |
| 37 | + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240'; |
| 38 | + expect(_getBrowserName(userAgent)).to.eq(BrowserName.EDGE); |
| 39 | + }); |
39 | 40 |
|
40 |
| - it('should recognize Firefox', () => { |
41 |
| - const userAgent = |
42 |
| - 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0'; |
43 |
| - expect(_getBrowserName(userAgent)).to.eq(BrowserName.FIREFOX); |
44 |
| - }); |
| 41 | + it('should recognize Firefox', () => { |
| 42 | + const userAgent = |
| 43 | + 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0'; |
| 44 | + expect(_getBrowserName(userAgent)).to.eq(BrowserName.FIREFOX); |
| 45 | + }); |
45 | 46 |
|
46 |
| - it('should recognize Silk', () => { |
47 |
| - const userAgent = |
48 |
| - 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Silk/44.1.54 like Chrome/44.0.2403.63 Safari/537.36'; |
49 |
| - expect(_getBrowserName(userAgent)).to.eq(BrowserName.SILK); |
50 |
| - }); |
| 47 | + it('should recognize Silk', () => { |
| 48 | + const userAgent = |
| 49 | + 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Silk/44.1.54 like Chrome/44.0.2403.63 Safari/537.36'; |
| 50 | + expect(_getBrowserName(userAgent)).to.eq(BrowserName.SILK); |
| 51 | + }); |
51 | 52 |
|
52 |
| - it('should recognize Safari', () => { |
53 |
| - const userAgent = |
54 |
| - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11-4) AppleWebKit/601.5.17 (KHTML, like Gecko) Version/9.1 Safari/601.5.17'; |
55 |
| - expect(_getBrowserName(userAgent)).to.eq(BrowserName.SAFARI); |
56 |
| - }); |
| 53 | + it('should recognize Safari', () => { |
| 54 | + const userAgent = |
| 55 | + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11-4) AppleWebKit/601.5.17 (KHTML, like Gecko) Version/9.1 Safari/601.5.17'; |
| 56 | + expect(_getBrowserName(userAgent)).to.eq(BrowserName.SAFARI); |
| 57 | + }); |
57 | 58 |
|
58 |
| - it('should recognize Chrome', () => { |
59 |
| - const userAgent = |
60 |
| - 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36'; |
61 |
| - expect(_getBrowserName(userAgent)).to.eq(BrowserName.CHROME); |
62 |
| - }); |
| 59 | + it('should recognize Chrome', () => { |
| 60 | + const userAgent = |
| 61 | + 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36'; |
| 62 | + expect(_getBrowserName(userAgent)).to.eq(BrowserName.CHROME); |
| 63 | + }); |
63 | 64 |
|
64 |
| - it('should recognize Android', () => { |
65 |
| - const userAgent = |
66 |
| - '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'; |
67 |
| - expect(_getBrowserName(userAgent)).to.eq(BrowserName.ANDROID); |
68 |
| - }); |
| 65 | + it('should recognize Android', () => { |
| 66 | + const userAgent = |
| 67 | + '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'; |
| 68 | + expect(_getBrowserName(userAgent)).to.eq(BrowserName.ANDROID); |
| 69 | + }); |
69 | 70 |
|
70 |
| - it('should recognize Blackberry', () => { |
71 |
| - const userAgent = |
72 |
| - 'Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.1.0.346 Mobile Safari/534.11+'; |
73 |
| - expect(_getBrowserName(userAgent)).to.eq(BrowserName.BLACKBERRY); |
74 |
| - }); |
| 71 | + it('should recognize Blackberry', () => { |
| 72 | + const userAgent = |
| 73 | + 'Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.1.0.346 Mobile Safari/534.11+'; |
| 74 | + expect(_getBrowserName(userAgent)).to.eq(BrowserName.BLACKBERRY); |
| 75 | + }); |
75 | 76 |
|
76 |
| - it('should recognize IE Mobile', () => { |
77 |
| - const userAgent = |
78 |
| - 'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0;Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920)'; |
79 |
| - expect(_getBrowserName(userAgent)).to.eq(BrowserName.IEMOBILE); |
80 |
| - }); |
| 77 | + it('should recognize IE Mobile', () => { |
| 78 | + const userAgent = |
| 79 | + 'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0;Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920)'; |
| 80 | + expect(_getBrowserName(userAgent)).to.eq(BrowserName.IEMOBILE); |
| 81 | + }); |
81 | 82 |
|
82 |
| - it('should recognize WebOS', () => { |
83 |
| - const userAgent = |
84 |
| - 'Mozilla/5.0 (webOS/1.3; U; en-US) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/1.0 Safari/525.27.1 Desktop/1.0'; |
85 |
| - expect(_getBrowserName(userAgent)).to.eq(BrowserName.WEBOS); |
86 |
| - }); |
| 83 | + it('should recognize WebOS', () => { |
| 84 | + const userAgent = |
| 85 | + 'Mozilla/5.0 (webOS/1.3; U; en-US) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/1.0 Safari/525.27.1 Desktop/1.0'; |
| 86 | + expect(_getBrowserName(userAgent)).to.eq(BrowserName.WEBOS); |
| 87 | + }); |
87 | 88 |
|
88 |
| - it('should recognize an unlisted browser', () => { |
89 |
| - const userAgent = |
90 |
| - 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Awesome/2.0.012'; |
91 |
| - expect(_getBrowserName(userAgent)).to.eq('Awesome'); |
| 89 | + it('should recognize an unlisted browser', () => { |
| 90 | + const userAgent = |
| 91 | + 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Awesome/2.0.012'; |
| 92 | + expect(_getBrowserName(userAgent)).to.eq('Awesome'); |
| 93 | + }); |
| 94 | + |
| 95 | + it('should default to Other', () => { |
| 96 | + const userAgent = |
| 97 | + 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12D508 [FBAN/FBIOS;FBAV/27.0.0.10.12;FBBV/8291884;FBDV/iPhone7,1;FBMD/iPhone;FBSN/iPhone OS;FBSV/8.2;FBSS/3; FBCR/vodafoneIE;FBID/phone;FBLC/en_US;FBOP/5]'; |
| 98 | + expect(_getBrowserName(userAgent)).to.eq(BrowserName.OTHER); |
| 99 | + }); |
92 | 100 | });
|
93 | 101 |
|
94 |
| - it('should default to Other', () => { |
95 |
| - const userAgent = |
96 |
| - 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12D508 [FBAN/FBIOS;FBAV/27.0.0.10.12;FBBV/8291884;FBDV/iPhone7,1;FBMD/iPhone;FBSN/iPhone OS;FBSV/8.2;FBSS/3; FBCR/vodafoneIE;FBID/phone;FBLC/en_US;FBOP/5]'; |
97 |
| - expect(_getBrowserName(userAgent)).to.eq(BrowserName.OTHER); |
| 102 | + context('_isIOS', () => { |
| 103 | + it('should recognize iPhone', () => { |
| 104 | + const userAgent = |
| 105 | + 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/1234' |
| 106 | + expect(_isIOS(userAgent)).to.be.true; |
| 107 | + }); |
| 108 | + |
| 109 | + it('should recognize iPad without iPad string', () => { |
| 110 | + const userAgent = |
| 111 | + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/1234' |
| 112 | + expect(_isIOS(userAgent)).to.be.true; |
| 113 | + }); |
| 114 | + |
| 115 | + it('should respond false for other mobile', () => { |
| 116 | + const userAgent = |
| 117 | + '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 Chrome/534.30'; |
| 118 | + expect(_isIOS(userAgent)).to.be.false; |
| 119 | + }); |
98 | 120 | });
|
99 | 121 | });
|
0 commit comments