iframe.html
5.44 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Testing dojo/request/iframe</title>
<style type="text/css">
@import "../../resources/dojo.css";
</style>
<script>
var dojoConfig = {
async: true
};
</script>
<script type="text/javascript" src="../../dojo.js"></script>
<script type="text/javascript">
require(["doh", "dojo/request/iframe", "dojo/_base/lang", "dojo/dom", "dojo/domReady!"], function(doh, iframe, lang, dom){
doh.register("dojo/request/iframe", [
function ioIframeGetText(t){
var d = new doh.Deferred();
var td = iframe.get("iframeDummyMethod.php?type=text", {
preventCache: true
});
td.then(d.getTestErrback(function(data){
t.is("iframe succeeded", data);
return td.response.then(d.getTestCallback(function(response){
t.is("iframe succeeded", response.data);
}));
}));
return d;
},
function ioIframePostJson(t){
var d = new doh.Deferred();
var td = iframe.post("iframeDummyMethod.php?type=json", {
preventCache: true,
form: "contentArrayTest",
data: {
color: "blue"
},
handleAs: "json"
});
td.then(d.getTestCallback(function(data){
t.is("json", data.query.type);
t.is("blue", data.post.color);
t.is("42", data.post.size);
}));
return d;
},
function ioIframePostWithoutForm(t){
var d = new doh.Deferred();
var td = iframe.post("iframeDummyMethod.php?type=json", {
preventCache: true,
data: {
color: "blue"
},
handleAs: "json"
});
td.then(d.getTestCallback(function(data){
t.is("json", data.query.type);
t.is("blue", data.post.color);
}));
return d;
},
function ioIframeGetJson(t){
var d = new doh.Deferred();
var td = iframe.get("iframeDummyMethod.php?type=json", {
preventCache: true,
data: {
color: "blue"
},
handleAs: "json"
});
td.then(d.getTestCallback(function(data){
t.is("json", data.query.type);
t.is("blue", data.query.color);
}));
return d;
},
function ioIframeGetWithForm(t){
var d = new doh.Deferred();
var td = iframe.get("iframeDummyMethod.php?type=json", {
preventCache: true,
form: "contentArrayTest",
data: {
color: "blue"
},
handleAs: "json"
});
td.then(d.getTestCallback(function(data){
t.is("json", data.query.type);
t.is("blue", data.query.color);
t.is("42", data.query.size);
}));
return d;
},
function ioIframeGetJavascript(t){
var d = new doh.Deferred();
var td = iframe.get("iframeDummyMethod.php?type=javascript", {
preventCache: true,
handleAs: "javascript"
});
td.then(d.getTestCallback(function(){
t.is(42, window.iframeTestingFunction());
}));
return d;
},
function ioIframeGetHtml(t){
var d = new doh.Deferred();
var td = iframe.get("iframeDummyMethod.php?type=html", {
preventCache: true,
handleAs: "html"
});
td.then(d.getTestCallback(function(data){
t.is("SUCCESSFUL HTML response",
data.getElementsByTagName("h1")[0].innerHTML);
}));
return d;
},
function ioIframeGetXml(t){
var d = new doh.Deferred();
var td = iframe.get("iframeDummyMethod.php?type=xml", {
preventCache: true,
handleAs: "xml"
});
td.then(d.getTestCallback(function(data){
t.is(4, data.documentElement.getElementsByTagName("child").length);
}), lang.hitch(d, "errback"));
return d;
},
function ioIframeDataArray(t){
//Tests if an array passed in content causes as an error on cleanup.
var d = new doh.Deferred();
var td = iframe.post("iframeDummyMethod.php?type=json", {
form: "contentArrayTest",
data: {"tag": ["value1","value2"]},
handleAs: "json"
});
td.then(d.getTestCallback(function(data){
t.is("json", data.query.type);
t.is("value2", data.post.tag);
t.is("42", data.post.size);
/* Test to make sure the form still exists and it hasn't moved */
var form = dom.byId("contentArrayTest");
t.t(form);
t.isNot("absolute", dom.byId("contentArrayTest").style.position);
}));
return d;
},
{
name: "iframeQueue",
timeout: 10000,
runTest: function(t){
var d = new doh.Deferred();
iframe.get("iframeDummyMethod.php",{
query: {
type: "text",
delay: 2,
text: "one"
}
}).then(d.getTestErrback(function(data){
t.is("one", data);
}));
iframe.get("iframeDummyMethod.php",{
query: {
type: "text",
text: "two"
}
}).then(d.getTestErrback(function(data){
t.is("two", data);
}));
iframe.get("iframeDummyMethod.php",{
query: {
type: "text",
text: "three"
}
}).then(d.getTestCallback(function(data){
t.is("three", data);
}));
t.is(3, iframe._dfdQueue.length);
return d;
}
}
]);
doh.run();
});
</script>
</head>
<body>
<form id="contentArrayTest" method="get" enctype="multipart/form-data">
<input type="hidden" name="size" value="42"/>
</form>
</body>
</html>