diff --git a/test/specs/window/spec.js b/test/specs/window/spec.js index dd5e3278..47aff2ed 100644 --- a/test/specs/window/spec.js +++ b/test/specs/window/spec.js @@ -13,39 +13,39 @@ function giveAHoot(){ test('Window Interfaces Available', function(){ - + ok(Window, 'Window available'); ok(History, 'History available'); ok(Navigator, 'Navigator available'); ok(Screen, 'Screen available'); - + }); - + test('window proxy', function(){ equals(window.THISISNOTDEFINED, undefined, 'window.undefined'); equals(window.document, document, 'window.document('+window.document+') is document('+document+')'); equals(document.nodeType, Node.DOCUMENT_NODE, 'document.nodeType is correct'); - + pollute(); equals(abc, 123, 'unscoped variables pollute the global scope'); - + giveAHoot(); try{ def; ok(false, 'scoped variables dont pollute the global scope'); }catch(e){ - //rhino adds double quotes around the bad variable eg "def" instead of just def + //rhino adds double quotes around the bad variable eg "def" instead of just def //rhino also adds a period at the end ok(e.toString().match(/^ReferenceError:\s\"?def\"?\sis\snot\sdefined\.?$/), 'got ReferenceError'); ok(true, 'scoped variables dont pollute the global scope'); } - + var tmp = new Date().getTime()+''; window[tmp] = 'hello!'; same(window[tmp], 'hello!', 'setting property on window'); delete window[tmp]; same(window[tmp], undefined, 'deleting property on window'); - + }); test('window properties', function(){ @@ -56,7 +56,7 @@ test('window properties', function(){ ok(top, 'top'); ok(parent, 'parent'); ok(window.toString(), '[object Window]'); - + //these values are usually the empty string '' //so we just verify the property is available ok('name' in window, 'name'); @@ -65,7 +65,7 @@ test('window properties', function(){ ok('defaultStatus' in window, 'defaultStatus'); ok('length' in window, 'length'); ok('opener' in window, 'opener'); - + ok(frames, 'frames'); ok(open, 'open'); ok(close, 'close'); @@ -74,20 +74,20 @@ test('window properties', function(){ ok(outerWidth, 'outerWidth'); ok(Number(screenX) !== undefined, 'screenX'); ok(Number(screenY) !== undefined, 'screenY'); - + equals( window, __this__, 'window is the global scope "this"'); equals( window, self, 'self is an alias for window'); equals( window, top, 'top is an alias for window when the window is not in a frame'); equals( window, window.parent, 'window parent is itself'); - + }); test('window event target', function(){ - + ok(window.addEventListener, '.addEventListener'); ok(window.removeEventListener, '.removeEventListener'); ok(window.dispatchEvent, '.dispatchEvent'); - + }); test("window.navigator", function(){ @@ -112,9 +112,9 @@ test("window.navigator", function(){ //ok(navigator.geolocation, '.geolocation is defined'); //ok(navigator.registerContentHandler, '.registerContentHandler is defined'); //ok(navigator.registerProtocolHandler, '.registerProtocolHandler is defined'); - + /* - * several properties will throw a security exception if they + * several properties will throw a security exception if they * are accessed, so we only check that they exist */ //ok("vendor" in navigator, '.vendor is defined'); @@ -127,7 +127,7 @@ test('window.getComputedStyle', function(){ expect(1); ok(window.getComputedStyle, 'window.getComputedStyle'); - + }); @@ -137,11 +137,11 @@ test('window.dialog', function(){ ok(alert, 'alert'); ok(confirm, 'confirm'); ok(prompt, 'prompt'); - + }); test('window.history', function(){ - + expect(8); ok(history === window.history, "history is window.history"); ok(history.length, 'history.length'); @@ -149,27 +149,27 @@ test('window.history', function(){ ok(history.forward, 'history.forward'); ok(history.go, 'history.go'); ok(history.item, 'history.item'); - + //these are generally secured properties of the history //object so we only check that the are defined since //trying to access them will throw an exception ok('current' in history, 'history.current'); ok('previous' in history, 'history.previous'); - + }); test('window.event', function(){ - + expect(3); ok(addEventListener, 'addEventListener'); ok(removeEventListener, 'removeEventListener'); ok(dispatchEvent, 'dispatchEvent'); - + }); test('window.location', function(){ - + expect(12); ok(location === window.location, "location is window.location"); ok('href' in location, 'location.href'); @@ -183,11 +183,11 @@ test('window.location', function(){ ok(location.reload, 'location.reload'); ok(location.replace, 'location.replace'); ok(location.assign, 'location.assign'); - + }); test('window.screen', function(){ - + expect(18); ok(screen === window.screen , 'screen is window screen'); ok("top" in screen, 'top'); @@ -200,7 +200,7 @@ test('window.screen', function(){ ok(screen.availHeight, 'availHeight'); ok("availLeft" in screen, 'availLeft'); ok("availTop" in screen, 'availTop'); - + //closely related function available at window ok(moveBy, 'moveBy'); ok(moveTo, 'moveTo'); @@ -209,15 +209,15 @@ test('window.screen', function(){ ok(scroll, 'scroll'); ok(scrollBy, 'scrollBy'); ok(scrollTo, 'scrollTo'); - + }); test('window.addEventListener / window.dispatchEvent multiple listeners', function(){ expect(36); - + var event; - + window.addEventListener('foo', function(event){ equals(event.eventPhase, Event.AT_TARGET, '.eventPhase is AT_TARGET'); equals(event.currentTarget, window, '.currentTarget is window'); @@ -228,16 +228,16 @@ test('window.addEventListener / window.dispatchEvent multiple listeners', functi equals(event.currentTarget, window, '.currentTarget is window'); equals(event.target, window, '.target is window'); }, false); - + event = document.createEvent('HTMLEvents'); event.initEvent('foo', true, true); window.dispatchEvent(event); - + event = document.createEvent('HTMLEvents'); event.initEvent('foo', false, true); window.dispatchEvent(event); - - + + window.addEventListener('bar', function(event){ equals(event.eventPhase, Event.AT_TARGET, '.eventPhase is AT_TARGET'); equals(event.currentTarget, window, '.currentTarget is window'); @@ -248,15 +248,15 @@ test('window.addEventListener / window.dispatchEvent multiple listeners', functi equals(event.currentTarget, window, '.currentTarget is window'); equals(event.target, window, '.target is window'); }, true); - + event = document.createEvent('HTMLEvents'); event.initEvent('bar', true, true); window.dispatchEvent(event); - + event = document.createEvent('HTMLEvents'); event.initEvent('bar', false, true); window.dispatchEvent(event); - + window.addEventListener('goop', function(event){ equals(event.eventPhase, Event.AT_TARGET, '.eventPhase is AT_TARGET'); equals(event.currentTarget, window, '.currentTarget is window'); @@ -267,11 +267,11 @@ test('window.addEventListener / window.dispatchEvent multiple listeners', functi equals(event.currentTarget, window, '.currentTarget is window'); equals(event.target, window, '.target is window'); }, false); - + event = document.createEvent('HTMLEvents'); event.initEvent('goop', true, true); window.dispatchEvent(event); - + event = document.createEvent('HTMLEvents'); event.initEvent('goop', false, true); window.dispatchEvent(event); @@ -279,17 +279,17 @@ test('window.addEventListener / window.dispatchEvent multiple listeners', functi test('HTMLParser.parseDocument / non-polluting script', function(){ - //one of the easiest way to test the HTMLParser is using frames and + //one of the easiest way to test the HTMLParser is using frames and //writing the document directly expect(4); var iframe = document.createElement("iframe"), - doc, - win; - + doc, + win; + document.body.appendChild(iframe); doc = iframe.contentDocument; win = iframe.contentWindow; - + doc.open(); doc.write("hello"); doc.close(); @@ -306,17 +306,17 @@ test('HTMLParser.parseDocument / non-polluting script', function(){ }); test('HTMLParser.parseDocument / polluting script', function(){ - //one of the easiest way to test the HTMLParser is using frames and + //one of the easiest way to test the HTMLParser is using frames and //writing the document directly expect(4); var iframe = document.createElement("iframe"), - doc, - win; - + doc, + win; + document.body.appendChild(iframe); doc = iframe.contentDocument; win = iframe.contentWindow; - + doc.open(); doc.write("hello"); doc.close(); @@ -332,13 +332,11 @@ test('HTMLParser.parseDocument / polluting script', function(){ document.body.removeChild( iframe ); }); - - test('frame proxy', function(){ var frame, - doc; - + doc; + expect(7); frame = document.createElement('iframe'); frame.width = '100%'; @@ -348,28 +346,34 @@ test('frame proxy', function(){ equals(frame.contentWindow.parent, window, '.contentWindow.parent'); equals(frame.contentWindow.top, window, '.contentWindow.top'); - + ok(frame.contentWindow.Array !== window.Array, '.Array'); ok(new window.Array(), 'new Array'); ok(new frame.contentWindow.Array(), 'new Array'); - + doc = frame.contentDocument; equals(doc.title, 'Envjs Proxy Spec', '.contentDocument.title'); equals(doc.toString(), '[object HTMLDocument]', '.contentDocument.toString()'); /** * TODO move this to its own test - document.body.removeChild( frame ); - - equals(frame.contentWindow, null, '.contentWindow'); - equals(frame.contentDocument, null, '.contentDocument'); - */ + document.body.removeChild( frame ); + + equals(frame.contentWindow, null, '.contentWindow'); + equals(frame.contentDocument, null, '.contentDocument'); + */ start(); }, false); - + frame.src = '../frame/proxy.html'; document.body.appendChild(frame); stop(); }); +test('window.[atob|btoa]', function(){ + ok(window.atob, 'window.atob available'); + ok(window.btoa, 'window.btoa available'); + equals(window.btoa('1234'), 'MTIzNA==', 'smoke test for btoa'); + equals(window.atob('MTIzNA=='), '1234', 'smoke test for btoa'); +});