UNPKG

can

Version:

MIT-licensed, client-side, JavaScript framework that makes building rich web applications easy.

107 lines (97 loc) 4 kB
<html> <head> <title>withDoc test</title> <style type="text/css"> iframe { width: 100%; height: 120px; } </style> <body> <script type="text/javascript" src="../../dojo.js" data-dojo-config="async:1"></script> <script type="text/javascript"> var frameLoaded; // callback for iframes, defined later require(["dojo/_base/kernel", "doh", "dojo/dom-construct", "dojo/sniff", "dojo/_base/window"], function(dojo, doh, domConstruct, has, win){ var fStandards, fQuirks, // iframes used for tests tests, numFrames = 2, framesLoaded = 0; frameLoaded = function(){ // Called by each child frame. // Tests start running when all iframes are loaded. if(++framesLoaded == numFrames){ doh.run(); } }; tests = [ function withDoc(t){ var d = fQuirks.contentWindow.document, finished, thisObj = {test: "myThis"}; win.withDoc(d, function(a1, a2){ t.is(1, a1, "first passed argument should be 1"); t.is(2, a2, "second passed argument should be 2"); t.is(this.test, "myThis", "context should be re-hitched"); t.is(d, win.doc, "win.doc should be reassigned"); finished = true; }, thisObj, [1, 2]); t.t(finished, "Did withDoc test function complete?"); t.is(document, win.doc, "win.doc should be restored"); }, function withGlobal(t){ var w = fQuirks.contentWindow, finished, thisObj = {test: "myThis"}; win.withGlobal(w, function(a1, a2){ t.is(1, a1, "first passed argument should be 1"); t.is(2, a2, "second passed argument should be 2"); t.is(this.test, "myThis", "context should be re-hitched"); t.is(42, win.global.answer, "win.global should be reassigned"); t.is(w.document, win.doc, "win.doc should be reassigned"); finished = true; }, thisObj, [1, 2]); t.t(finished, "Did withGlobal test function complete?"); t.is(window, win.global, "win.global should be restored"); t.is(document, win.doc, "win.doc should be restored"); }, function hasQuirks(t){ var origQuirks = has("quirks"); win.withGlobal(fQuirks.contentWindow, function(){ t.t(dojo.isQuirks,"dojo.isQuirks should be true in withDoc w/ quirks document"); // remove in 2.0 t.t(has("quirks"), "has('quirks') should be true in withDoc w/ quirks document"); }); t.is(origQuirks, dojo.isQuirks, "dojo.isQuirks should be reset to initial value"); // remove in 2.0 t.is(origQuirks, has("quirks"), "has('quirks') should be reset to initial value"); win.withGlobal(fStandards.contentWindow, function(){ t.f(dojo.isQuirks, "dojo.isQuirks should be false in withDoc w/ standards document"); // remove in 2.0 t.f(has("quirks"), "has('quirks') should be false in withDoc w/ standards document"); }); t.is(origQuirks, dojo.isQuirks, // remove in 2.0 "dojo.isQuirks should be reset to initial value (again)"); t.is(origQuirks, has("quirks"), "has('quirks') should be reset to initial value (again)"); } ]; if(has("ie") > 7){ // add hasIE test for X-UA-Compatible-triggered switch tests.push(function hasIE(t){ var origIE = has("ie"); win.withGlobal(fStandards.contentWindow, function(){ // these are disabled because it doesn't seem that we can really emulate IE7 with frames like this. //t.is(7, dojo.isIE,"dojo.isIE should be 7 in withDoc w/ standards document w/ EmulateIE7"); // remove in 2.0 //t.is(7, has("ie"), "has('ie') should be 7 in withDoc w/ standards document w/ EmulateIE7"); }); t.is(origIE, dojo.isIE, "dojo.isIE should be reset to initial value"); // remove in 2.0 t.is(origIE, has("ie"), "has('ie') should be reset to initial value"); }); } doh.register("_base/window", tests); // Add iframe to page w/ document in standards mode fStandards = domConstruct.create("iframe", { src: "window_iframe_standards.html" }, document.body); // Add iframe to page w/ document in quirks mode fQuirks = domConstruct.create("iframe", { src: "window_iframe_quirks.html" }, document.body); }); </script> </body> </html>