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(){
79 it('should think it is executed in a browser', function(){
80 var isPhantomJS = !!navigator.userAgent.match(/phantomjs/i);
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 var isPhantomJS = !!navigator.userAgent.match(/phantomjs/i);
88 expect(isPhantomJS || Browser.ie || Browser.safari || Browser.chrome || Browser.firefox || Browser.opera).toEqual(true);
92 it('should not assign a Browser[Browser.name] property for IE v11 or higher', function(){
93 if (Browser.name == 'ie' && Browser.version >= 11){
94 expect(Browser.ie || Browser.safari || Browser.chrome || Browser.firefox || Browser.opera).toBeUndefined();
99 it('should assume the IE version is emulated by the documentMode (X-UA-Compatible)', function(){
100 if (Browser.name == 'ie' && document.documentMode) expect(Browser.version).toEqual(document.documentMode);
105 describe('Browser.parseUA', function(){
107 var parse = Browser.parseUA;
110 desc: 'Internet Explorer 6',
111 string: 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; Win64; x64; SV1; .NET CLR 2.0.50727)',
118 desc: 'Internet Explorer 7',
119 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)',
126 desc: 'Internet Explorer 8',
127 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)',
134 desc: 'Internet Explorer 9',
135 string: 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)',
142 desc: 'Internet Explorer 10',
143 string: 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)',
150 desc: 'Internet Explorer 11',
151 string: 'Mozilla/5.0 (IE 11.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C; rv:11.0) like Gecko',
158 desc: 'Internet Explorer 11 v2',
159 string: 'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv 11.0) like Gecko',
166 desc: 'Internet Explorer 10 in IE7 compatibility',
167 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)',
175 string: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:24.0) Gecko/20100101 Firefox/24.0',
183 string: 'Opera/9.80 (Windows NT 5.1; U; cs) Presto/2.2.15 Version/10.00',
191 string: 'Opera/9.80 (Windows NT 6.1; WOW64; U; pt) Presto/2.10.229 Version/11.62',
199 string: 'Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14',
207 string: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.71 (KHTML, like Gecko) Version/6.1 Safari/537.71',
215 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',
222 desc: 'Chrome 33 on iOS',
223 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',
231 var testUA = function(ua){
233 var browser = parse(ua.string, '');
234 Object.forEach(ua.expect, runExpects, browser);
238 var runExpects = function(val, key){
239 expect(this[key]).toEqual(val);
242 Object.forEach(userAgents, function(obj){
243 it('should parse ' + obj.desc + ' user agent string', testUA(obj));