window.html
3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<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>