10 describe('$exec', function(){
12 it('should evaluate on global scope', function(){
13 $exec.call($exec, 'var execSpec = 42');
14 expect(window.execSpec).toEqual(42);
17 it('should return the evaluated script', function(){
18 expect($exec('$empty();')).toEqual('$empty();');
24 describe('Browser.exec', function(){
26 it('should evaluate on global scope', function(){
27 Browser.exec.call(Browser.exec, 'var execSpec = 42');
28 expect(window.execSpec).toEqual(42);
31 it('should return the evaluated script', function(){
32 expect(Browser.exec('function test(){}')).toEqual('function test(){}');
37 // String.stripScripts
39 describe('String.stripScripts', function(){
41 it('should strip all script tags from a string', function(){
42 expect('<div><script type="text/javascript" src="file.js"></script></div>'.stripScripts()).toEqual('<div></div>');
45 it('should execute the stripped tags from the string', function(){
46 expect('<div><script type="text/javascript"> var stripScriptsSpec = 42; </script></div>'.stripScripts(true)).toEqual('<div></div>');
47 expect(window.stripScriptsSpec).toEqual(42);
48 expect('<div><script>\n// <!--\nvar stripScriptsSpec = 24;\n//-->\n</script></div>'.stripScripts(true)).toEqual('<div></div>');
49 expect(window.stripScriptsSpec).toEqual(24);
50 expect('<div><script>\n/*<![CDATA[*/\nvar stripScriptsSpec = 4242;\n/*]]>*/</script></div>'.stripScripts(true)).toEqual('<div></div>');
51 expect(window.stripScriptsSpec).toEqual(4242);
57 describe('Document', function(){
59 it('should hold the parent window', function(){
60 expect(document.window).toEqual(window);
63 it('should hold the head element', function(){
64 expect(document.head.tagName.toLowerCase()).toEqual('head');
69 describe('Window', function(){
71 it('should set the Element prototype', function(){
72 expect(window.Element.prototype).toBeDefined();
77 describe('Browser', function(){
78 var isPhantomJS = !!navigator.userAgent.match(/phantomjs/i);
80 it('should think it is executed in a browser', function(){
81 if (!isPhantomJS) expect(['ie', 'safari', 'chrome', 'firefox', 'opera']).toContain(Browser.name);
85 it('should assign a Browser[Browser.name] property for all browsers, except IE v11 or higher', function(){
86 if (Browser.name != 'ie' || Browser.version < 11){
87 expect(isPhantomJS || Browser.ie || Browser.safari || Browser.chrome || Browser.firefox || Browser.opera).toEqual(true);
91 it('should not assign a Browser[Browser.name] property for IE v11 or higher', function(){
92 if (Browser.name == 'ie' && Browser.version >= 11){
93 expect(Browser.ie || Browser.safari || Browser.chrome || Browser.firefox || Browser.opera).toBeUndefined();
98 it('should assume the IE version is emulated by the documentMode (X-UA-Compatible)', function(){
99 if (Browser.name == 'ie' && document.documentMode) expect(Browser.version).toEqual(document.documentMode);
101 it('should find a browser version', function(){
102 expect(Browser.version || isPhantomJS).toBeTruthy();
103 expect(typeof Browser.version).toEqual('number');
108 describe('Browser.parseUA', function(){
110 var parse = Browser.parseUA;
113 desc: 'Internet Explorer 6',
114 string: 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; Win64; x64; SV1; .NET CLR 2.0.50727)',
121 desc: 'Internet Explorer 7',
122 string: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)',
129 desc: 'Internet Explorer 8',
130 string: 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)',
137 desc: 'Internet Explorer 9',
138 string: 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)',
145 desc: 'Internet Explorer 10',
146 string: 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)',
153 desc: 'Internet Explorer 11',
154 string: 'Mozilla/5.0 (IE 11.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C; rv:11.0) like Gecko',
161 desc: 'Internet Explorer 11 v2',
162 string: 'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv 11.0) like Gecko',
169 desc: 'Internet Explorer 10 in IE7 compatibility',
170 string: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)',
178 string: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:24.0) Gecko/20100101 Firefox/24.0',
186 string: 'Opera/9.80 (Windows NT 5.1; U; cs) Presto/2.2.15 Version/10.00',
194 string: 'Opera/9.80 (Windows NT 6.1; WOW64; U; pt) Presto/2.10.229 Version/11.62',
202 string: 'Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14',
210 string: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.71 (KHTML, like Gecko) Version/6.1 Safari/537.71',
218 string: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36',
225 desc: 'Chrome 33 on iOS',
226 string: 'Mozilla/5.0 (iPad; CPU OS 7_0_4 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) CriOS/33.0.1750.21 Mobile/11B554a Safari/9537.53',
234 string: 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0',
243 var testUA = function(ua){
245 var browser = parse(ua.string, '');
246 Object.forEach(ua.expect, runExpects, browser);
250 var runExpects = function(val, key){
251 expect(this[key]).toEqual(val);
254 Object.forEach(userAgents, function(obj){
255 it('should parse ' + obj.desc + ' user agent string', testUA(obj));