1 | <html> |
---|
2 | <head> |
---|
3 | <title>withDoc test</title> |
---|
4 | <style type="text/css"> |
---|
5 | iframe { |
---|
6 | width: 100%; |
---|
7 | height: 120px; |
---|
8 | } |
---|
9 | </style> |
---|
10 | <body> |
---|
11 | <script type="text/javascript" src="../../dojo.js" data-dojo-config="async:1"></script> |
---|
12 | <script type="text/javascript"> |
---|
13 | var frameLoaded; // callback for iframes, defined later |
---|
14 | require(["dojo/_base/kernel", "doh", "dojo/dom-construct", "dojo/sniff", "dojo/_base/window"], |
---|
15 | function(dojo, doh, domConstruct, has, win){ |
---|
16 | var |
---|
17 | fStandards, fQuirks, // iframes used for tests |
---|
18 | tests, numFrames = 2, framesLoaded = 0; |
---|
19 | |
---|
20 | frameLoaded = function(){ |
---|
21 | // Called by each child frame. |
---|
22 | // Tests start running when all iframes are loaded. |
---|
23 | if(++framesLoaded == numFrames){ |
---|
24 | doh.run(); |
---|
25 | } |
---|
26 | }; |
---|
27 | |
---|
28 | tests = [ |
---|
29 | function withDoc(t){ |
---|
30 | var d = fQuirks.contentWindow.document, finished, |
---|
31 | thisObj = {test: "myThis"}; |
---|
32 | |
---|
33 | win.withDoc(d, function(a1, a2){ |
---|
34 | t.is(1, a1, "first passed argument should be 1"); |
---|
35 | t.is(2, a2, "second passed argument should be 2"); |
---|
36 | t.is(this.test, "myThis", "context should be re-hitched"); |
---|
37 | t.is(d, win.doc, "win.doc should be reassigned"); |
---|
38 | finished = true; |
---|
39 | }, thisObj, [1, 2]); |
---|
40 | |
---|
41 | t.t(finished, "Did withDoc test function complete?"); |
---|
42 | t.is(document, win.doc, "win.doc should be restored"); |
---|
43 | }, |
---|
44 | function withGlobal(t){ |
---|
45 | var w = fQuirks.contentWindow, finished, |
---|
46 | thisObj = {test: "myThis"}; |
---|
47 | |
---|
48 | win.withGlobal(w, function(a1, a2){ |
---|
49 | t.is(1, a1, "first passed argument should be 1"); |
---|
50 | t.is(2, a2, "second passed argument should be 2"); |
---|
51 | t.is(this.test, "myThis", "context should be re-hitched"); |
---|
52 | t.is(42, win.global.answer, "win.global should be reassigned"); |
---|
53 | t.is(w.document, win.doc, "win.doc should be reassigned"); |
---|
54 | finished = true; |
---|
55 | }, thisObj, [1, 2]); |
---|
56 | |
---|
57 | t.t(finished, "Did withGlobal test function complete?"); |
---|
58 | t.is(window, win.global, "win.global should be restored"); |
---|
59 | t.is(document, win.doc, "win.doc should be restored"); |
---|
60 | }, |
---|
61 | function hasQuirks(t){ |
---|
62 | var origQuirks = has("quirks"); |
---|
63 | win.withGlobal(fQuirks.contentWindow, function(){ |
---|
64 | t.t(dojo.isQuirks,"dojo.isQuirks should be true in withDoc w/ quirks document"); // remove in 2.0 |
---|
65 | t.t(has("quirks"), "has('quirks') should be true in withDoc w/ quirks document"); |
---|
66 | }); |
---|
67 | t.is(origQuirks, dojo.isQuirks, "dojo.isQuirks should be reset to initial value"); // remove in 2.0 |
---|
68 | t.is(origQuirks, has("quirks"), "has('quirks') should be reset to initial value"); |
---|
69 | win.withGlobal(fStandards.contentWindow, function(){ |
---|
70 | t.f(dojo.isQuirks, "dojo.isQuirks should be false in withDoc w/ standards document"); // remove in 2.0 |
---|
71 | t.f(has("quirks"), "has('quirks') should be false in withDoc w/ standards document"); |
---|
72 | }); |
---|
73 | t.is(origQuirks, dojo.isQuirks, // remove in 2.0 |
---|
74 | "dojo.isQuirks should be reset to initial value (again)"); |
---|
75 | t.is(origQuirks, has("quirks"), |
---|
76 | "has('quirks') should be reset to initial value (again)"); |
---|
77 | } |
---|
78 | ]; |
---|
79 | |
---|
80 | if(has("ie") > 7){ // add hasIE test for X-UA-Compatible-triggered switch |
---|
81 | tests.push(function hasIE(t){ |
---|
82 | var origIE = has("ie"); |
---|
83 | win.withGlobal(fStandards.contentWindow, function(){ |
---|
84 | // these are disabled because it doesn't seem that we can really emulate IE7 with frames like this. |
---|
85 | //t.is(7, dojo.isIE,"dojo.isIE should be 7 in withDoc w/ standards document w/ EmulateIE7"); // remove in 2.0 |
---|
86 | //t.is(7, has("ie"), "has('ie') should be 7 in withDoc w/ standards document w/ EmulateIE7"); |
---|
87 | }); |
---|
88 | t.is(origIE, dojo.isIE, "dojo.isIE should be reset to initial value"); // remove in 2.0 |
---|
89 | t.is(origIE, has("ie"), "has('ie') should be reset to initial value"); |
---|
90 | }); |
---|
91 | } |
---|
92 | |
---|
93 | doh.register("_base/window", tests); |
---|
94 | |
---|
95 | // Add iframe to page w/ document in standards mode |
---|
96 | fStandards = domConstruct.create("iframe", { |
---|
97 | src: "window_iframe_standards.html" |
---|
98 | }, document.body); |
---|
99 | // Add iframe to page w/ document in quirks mode |
---|
100 | fQuirks = domConstruct.create("iframe", { |
---|
101 | src: "window_iframe_quirks.html" |
---|
102 | }, document.body); |
---|
103 | }); |
---|
104 | </script> |
---|
105 | </body> |
---|
106 | </html> |
---|