1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
---|
2 | "http://www.w3.org/TR/html4/strict.dtd"> |
---|
3 | <html> |
---|
4 | <head> |
---|
5 | <title>Testing dojo.io.iframe</title> |
---|
6 | <style type="text/css"> |
---|
7 | @import "../../resources/dojo.css"; |
---|
8 | </style> |
---|
9 | <script type="text/javascript" src="../../dojo.js" data-dojo-config="isDebug:true"></script> |
---|
10 | <script type="text/javascript"> |
---|
11 | require(["dojo", "doh", "dojo/io/iframe"], function(dojo, doh){ |
---|
12 | doh.register([ |
---|
13 | function ioIframeGetText(t){ |
---|
14 | var d = new doh.Deferred(); |
---|
15 | var td = dojo.io.iframe.send({ |
---|
16 | url: "iframeResponse.text.html", |
---|
17 | method: "GET", |
---|
18 | timeoutSeconds: 5, |
---|
19 | preventCache: true, |
---|
20 | handle: function(res, ioArgs){ |
---|
21 | if(!(res instanceof Error) && |
---|
22 | t.is("iframe succeeded", res)){ |
---|
23 | d.callback(true); |
---|
24 | }else{ |
---|
25 | d.errback(false); |
---|
26 | } |
---|
27 | } |
---|
28 | }); |
---|
29 | return d; |
---|
30 | }, |
---|
31 | |
---|
32 | function ioIframeGetJson(t){ |
---|
33 | var d = new doh.Deferred(); |
---|
34 | var td = dojo.io.iframe.send({ |
---|
35 | url: "iframeResponse.json.html", |
---|
36 | method: "GET", |
---|
37 | timeoutSeconds: 5, |
---|
38 | preventCache: true, |
---|
39 | handleAs: "json", |
---|
40 | handle: function(res, ioArgs){ |
---|
41 | if(!(res instanceof Error) && |
---|
42 | t.is("blue", res.color)){ |
---|
43 | d.callback(true); |
---|
44 | }else{ |
---|
45 | d.errback(false); |
---|
46 | } |
---|
47 | } |
---|
48 | }); |
---|
49 | return d; |
---|
50 | }, |
---|
51 | |
---|
52 | function ioIframeGetJavascript(t){ |
---|
53 | var d = new doh.Deferred(); |
---|
54 | var td = dojo.io.iframe.send({ |
---|
55 | url: "iframeResponse.js.html", |
---|
56 | method: "GET", |
---|
57 | timeoutSeconds: 5, |
---|
58 | preventCache: true, |
---|
59 | handleAs: "javascript", |
---|
60 | handle: function(res, ioArgs){ |
---|
61 | console.log("RES: ", res); |
---|
62 | if(!(res instanceof Error) && |
---|
63 | t.is(42, window.iframeTestingFunction())){ |
---|
64 | d.callback(true); |
---|
65 | }else{ |
---|
66 | d.errback(false); |
---|
67 | } |
---|
68 | } |
---|
69 | }); |
---|
70 | return d; |
---|
71 | }, |
---|
72 | |
---|
73 | function ioIframeGetHtml(t){ |
---|
74 | var d = new doh.Deferred(); |
---|
75 | var td = dojo.io.iframe.send({ |
---|
76 | url: "iframeResponse.html", |
---|
77 | method: "GET", |
---|
78 | timeoutSeconds: 5, |
---|
79 | preventCache: true, |
---|
80 | handleAs: "html", |
---|
81 | handle: function(res, ioArgs){ |
---|
82 | if(!(res instanceof Error) && |
---|
83 | t.is("SUCCESSFUL HTML response", res.getElementsByTagName("h1")[0].innerHTML)){ |
---|
84 | d.callback(true); |
---|
85 | }else{ |
---|
86 | d.errback(false); |
---|
87 | } |
---|
88 | } |
---|
89 | }); |
---|
90 | return d; |
---|
91 | }, |
---|
92 | |
---|
93 | function ioIframeGetXml(t){ |
---|
94 | var d = new doh.Deferred(); |
---|
95 | var td = dojo.io.iframe.send({ |
---|
96 | url: "iframeResponse.xml", |
---|
97 | method: "GET", |
---|
98 | timeoutSeconds: 5, |
---|
99 | preventCache: true, |
---|
100 | handleAs: "xml", |
---|
101 | handle: function(res, ioArgs){ |
---|
102 | if(!(res instanceof Error) |
---|
103 | && t.is(4, res.documentElement.getElementsByTagName("child").length) |
---|
104 | ){ |
---|
105 | d.callback(true); |
---|
106 | } else { |
---|
107 | d.errback(false); |
---|
108 | } |
---|
109 | } |
---|
110 | }); |
---|
111 | return d; |
---|
112 | }, |
---|
113 | function ioIframeContentArray(t){ |
---|
114 | //Tests if an array passed in content causes as an error on cleanup. |
---|
115 | var d = new doh.Deferred(); |
---|
116 | var td = dojo.io.iframe.send({ |
---|
117 | url: "iframeResponse.text.html", |
---|
118 | form: "contentArrayTest", |
---|
119 | content: {"tag": ["value1","value2"]}, |
---|
120 | handle: function(res, ioArgs){ |
---|
121 | if(!(res instanceof Error)){ |
---|
122 | d.callback(true); |
---|
123 | } else { |
---|
124 | d.errback(false); |
---|
125 | } |
---|
126 | } |
---|
127 | }); |
---|
128 | return d; |
---|
129 | } |
---|
130 | ]); |
---|
131 | doh.runOnLoad(); |
---|
132 | /* |
---|
133 | // for watching in the debugger... |
---|
134 | dojo.addOnLoad(function(){ |
---|
135 | var td = dojo.io.iframe.get({ |
---|
136 | url: "iframeResponse.text.html", |
---|
137 | timeoutSeconds: 5, |
---|
138 | preventCache: true, |
---|
139 | handle: function(res, ioArgs){ |
---|
140 | if(!(res instanceof Error) && |
---|
141 | "iframe succeeded" == res){ |
---|
142 | console.debug("OK"); |
---|
143 | }else{ |
---|
144 | console.debug("Error", res); |
---|
145 | } |
---|
146 | } |
---|
147 | }); |
---|
148 | }); |
---|
149 | */ |
---|
150 | }); |
---|
151 | |
---|
152 | </script> |
---|
153 | </head> |
---|
154 | <body> |
---|
155 | <form id="contentArrayTest" method="get" enctype="multipart/form-data"> |
---|
156 | </form> |
---|
157 | </body> |
---|
158 | </html> |
---|