[483] | 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, ioPublish: true"></script> |
---|
| 10 | <script type="text/javascript"> |
---|
| 11 | require(["dojo", "doh", "dojo/topic", "dojo/io/iframe"], function(dojo, doh, topic){ |
---|
| 12 | doh.register([ |
---|
| 13 | function ioIframeGetText(t){ |
---|
| 14 | var d = new doh.Deferred(); |
---|
| 15 | var td = dojo.io.iframe.send({ |
---|
| 16 | url: "../request/iframeDummyMethod.php?type=text", |
---|
| 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 ioIframeGetFormJson(t){ |
---|
| 33 | var d = new doh.Deferred(); |
---|
| 34 | var td = dojo.io.iframe.send({ |
---|
| 35 | url: "../request/iframeDummyMethod.php", |
---|
| 36 | form: "contentArrayTest", |
---|
| 37 | content: { |
---|
| 38 | type: "json", |
---|
| 39 | color: "blue", |
---|
| 40 | size: 42 |
---|
| 41 | }, |
---|
| 42 | timeoutSeconds: 5, |
---|
| 43 | preventCache: true, |
---|
| 44 | handleAs: "json", |
---|
| 45 | handle: function(res, ioArgs){ |
---|
| 46 | if(!(res instanceof Error) && |
---|
| 47 | t.is("blue", res.query.color)){ |
---|
| 48 | d.callback(true); |
---|
| 49 | }else{ |
---|
| 50 | d.errback(false); |
---|
| 51 | } |
---|
| 52 | } |
---|
| 53 | }); |
---|
| 54 | return d; |
---|
| 55 | }, |
---|
| 56 | |
---|
| 57 | function ioIframeGetJson(t){ |
---|
| 58 | var d = new doh.Deferred(); |
---|
| 59 | var td = dojo.io.iframe.send({ |
---|
| 60 | url: "../request/iframeDummyMethod.php?type=json", |
---|
| 61 | content: { |
---|
| 62 | color: "blue", |
---|
| 63 | size: 42 |
---|
| 64 | }, |
---|
| 65 | timeoutSeconds: 5, |
---|
| 66 | preventCache: true, |
---|
| 67 | handleAs: "json", |
---|
| 68 | handle: function(res, ioArgs){ |
---|
| 69 | if(!(res instanceof Error) && |
---|
| 70 | t.is("blue", res.query.color)){ |
---|
| 71 | d.callback(true); |
---|
| 72 | }else{ |
---|
| 73 | d.errback(false); |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | }); |
---|
| 77 | return d; |
---|
| 78 | }, |
---|
| 79 | |
---|
| 80 | function ioIframeNotPostJson(t){ |
---|
| 81 | var d = new doh.Deferred(); |
---|
| 82 | var td = dojo.io.iframe.send({ |
---|
| 83 | method: "post", |
---|
| 84 | url: "../request/iframeDummyMethod.php?type=json", |
---|
| 85 | content: { |
---|
| 86 | color: "blue", |
---|
| 87 | size: 42 |
---|
| 88 | }, |
---|
| 89 | timeoutSeconds: 5, |
---|
| 90 | preventCache: true, |
---|
| 91 | handleAs: "json", |
---|
| 92 | handle: function(res, ioArgs){ |
---|
| 93 | if(!(res instanceof Error) && |
---|
| 94 | t.is("blue", res.query.color)){ |
---|
| 95 | d.callback(true); |
---|
| 96 | }else{ |
---|
| 97 | d.errback(false); |
---|
| 98 | } |
---|
| 99 | } |
---|
| 100 | }); |
---|
| 101 | return d; |
---|
| 102 | }, |
---|
| 103 | |
---|
| 104 | function ioIframePostFormJson(t){ |
---|
| 105 | var d = new doh.Deferred(); |
---|
| 106 | var form = dojo.byId("contentArrayTest"); |
---|
| 107 | form.getAttributeNode("method").value = "post"; |
---|
| 108 | var td = dojo.io.iframe.send({ |
---|
| 109 | method: "post", |
---|
| 110 | url: "../request/iframeDummyMethod.php?type=json", |
---|
| 111 | form: "contentArrayTest", |
---|
| 112 | content: { |
---|
| 113 | color: "blue", |
---|
| 114 | size: 42 |
---|
| 115 | }, |
---|
| 116 | timeoutSeconds: 5, |
---|
| 117 | preventCache: true, |
---|
| 118 | handleAs: "json", |
---|
| 119 | handle: function(res, ioArgs){ |
---|
| 120 | if(!(res instanceof Error) && |
---|
| 121 | t.is("blue", res.post.color)){ |
---|
| 122 | d.callback(true); |
---|
| 123 | }else{ |
---|
| 124 | d.errback(false); |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | }); |
---|
| 128 | return d; |
---|
| 129 | }, |
---|
| 130 | |
---|
| 131 | function ioIframeGetJavascript(t){ |
---|
| 132 | var d = new doh.Deferred(); |
---|
| 133 | var form = dojo.byId("contentArrayTest"); |
---|
| 134 | form.getAttributeNode("method").value = "get"; |
---|
| 135 | var td = dojo.io.iframe.send({ |
---|
| 136 | url: "iframeResponse.js.html", |
---|
| 137 | method: "GET", |
---|
| 138 | timeoutSeconds: 5, |
---|
| 139 | preventCache: true, |
---|
| 140 | handleAs: "javascript", |
---|
| 141 | handle: function(res, ioArgs){ |
---|
| 142 | console.log("RES: ", res); |
---|
| 143 | if(!(res instanceof Error) && |
---|
| 144 | t.is(42, window.iframeTestingFunction())){ |
---|
| 145 | d.callback(true); |
---|
| 146 | }else{ |
---|
| 147 | d.errback(false); |
---|
| 148 | } |
---|
| 149 | } |
---|
| 150 | }); |
---|
| 151 | return d; |
---|
| 152 | }, |
---|
| 153 | |
---|
| 154 | function ioIframeGetHtml(t){ |
---|
| 155 | var d = new doh.Deferred(); |
---|
| 156 | var td = dojo.io.iframe.send({ |
---|
| 157 | url: "iframeResponse.html", |
---|
| 158 | method: "GET", |
---|
| 159 | timeoutSeconds: 5, |
---|
| 160 | preventCache: true, |
---|
| 161 | handleAs: "html", |
---|
| 162 | handle: function(res, ioArgs){ |
---|
| 163 | if(!(res instanceof Error) && |
---|
| 164 | t.is("SUCCESSFUL HTML response", res.getElementsByTagName("h1")[0].innerHTML)){ |
---|
| 165 | d.callback(true); |
---|
| 166 | }else{ |
---|
| 167 | d.errback(false); |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | }); |
---|
| 171 | return d; |
---|
| 172 | }, |
---|
| 173 | |
---|
| 174 | function ioIframeGetXml(t){ |
---|
| 175 | var d = new doh.Deferred(); |
---|
| 176 | var td = dojo.io.iframe.send({ |
---|
| 177 | url: "iframeResponse.xml", |
---|
| 178 | method: "GET", |
---|
| 179 | timeoutSeconds: 5, |
---|
| 180 | preventCache: true, |
---|
| 181 | handleAs: "xml", |
---|
| 182 | handle: function(res, ioArgs){ |
---|
| 183 | if(!(res instanceof Error) |
---|
| 184 | && t.is(4, res.documentElement.getElementsByTagName("child").length) |
---|
| 185 | ){ |
---|
| 186 | d.callback(true); |
---|
| 187 | } else { |
---|
| 188 | d.errback(false); |
---|
| 189 | } |
---|
| 190 | } |
---|
| 191 | }); |
---|
| 192 | return d; |
---|
| 193 | }, |
---|
| 194 | function ioIframeContentArray(t){ |
---|
| 195 | //Tests if an array passed in content causes as an error on cleanup. |
---|
| 196 | var d = new doh.Deferred(); |
---|
| 197 | var td = dojo.io.iframe.send({ |
---|
| 198 | url: "iframeResponse.text.html", |
---|
| 199 | form: "contentArrayTest", |
---|
| 200 | content: {"tag": ["value1","value2"]}, |
---|
| 201 | handle: d.getTestErrback(function(res, ioArgs){ |
---|
| 202 | t.f(res instanceof Error); |
---|
| 203 | }) |
---|
| 204 | }); |
---|
| 205 | var stop = topic.subscribe("/dojo/io/stop", function(){ |
---|
| 206 | stop.remove(); |
---|
| 207 | d.callback(true); |
---|
| 208 | }); |
---|
| 209 | return d; |
---|
| 210 | }, |
---|
| 211 | function ioPublish(t){ |
---|
| 212 | var d = new doh.Deferred(); |
---|
| 213 | |
---|
| 214 | var topicCount = 0; |
---|
| 215 | topic.subscribe("/dojo/io/start", function(){ |
---|
| 216 | topicCount++; |
---|
| 217 | }); |
---|
| 218 | topic.subscribe("/dojo/io/send", function(){ |
---|
| 219 | topicCount++; |
---|
| 220 | }); |
---|
| 221 | topic.subscribe("/dojo/io/load", function(){ |
---|
| 222 | topicCount++; |
---|
| 223 | }); |
---|
| 224 | topic.subscribe("/dojo/io/error", function(){ |
---|
| 225 | topicCount--; |
---|
| 226 | }); |
---|
| 227 | topic.subscribe("/dojo/io/done", function(){ |
---|
| 228 | topicCount++; |
---|
| 229 | }); |
---|
| 230 | topic.subscribe("/dojo/io/stop", d.getTestCallback(function(){ |
---|
| 231 | topicCount++; |
---|
| 232 | t.is(5, topicCount); |
---|
| 233 | })); |
---|
| 234 | |
---|
| 235 | dojo.io.iframe.send({ |
---|
| 236 | url: "iframeResponse.text.html", |
---|
| 237 | method: "GET", |
---|
| 238 | timeoutSeconds: 5, |
---|
| 239 | preventCache: true |
---|
| 240 | }); |
---|
| 241 | return d; |
---|
| 242 | } |
---|
| 243 | ]); |
---|
| 244 | doh.runOnLoad(); |
---|
| 245 | /* |
---|
| 246 | // for watching in the debugger... |
---|
| 247 | dojo.addOnLoad(function(){ |
---|
| 248 | var td = dojo.io.iframe.get({ |
---|
| 249 | url: "iframeResponse.text.html", |
---|
| 250 | timeoutSeconds: 5, |
---|
| 251 | preventCache: true, |
---|
| 252 | handle: function(res, ioArgs){ |
---|
| 253 | if(!(res instanceof Error) && |
---|
| 254 | "iframe succeeded" == res){ |
---|
| 255 | console.debug("OK"); |
---|
| 256 | }else{ |
---|
| 257 | console.debug("Error", res); |
---|
| 258 | } |
---|
| 259 | } |
---|
| 260 | }); |
---|
| 261 | }); |
---|
| 262 | */ |
---|
| 263 | }); |
---|
| 264 | |
---|
| 265 | </script> |
---|
| 266 | </head> |
---|
| 267 | <body> |
---|
| 268 | <form id="contentArrayTest" method="get" enctype="multipart/form-data"> |
---|
| 269 | </form> |
---|
| 270 | </body> |
---|
| 271 | </html> |
---|