tizen beta release
[framework/web/webkit-efl.git] / LayoutTests / fast / xmlhttprequest / xmlhttprequest-responsetype-text.html
1 <html>
2 <head>
3 <script src="../js/resources/js-test-pre.js"></script>
4 <style type="text/css">
5 .box {
6   display: box;
7   border: 1px solid black;
8   margin-bottom: 0.5em;
9 }
10 .boxheader {
11   font-weight: bold;
12   color: maroon;
13 }
14 pre {
15   margin-left: 2em;
16 }
17 </style>
18 </head>
19 <body>
20
21 <div id="description"></div>
22
23 <div class="box"><span class="boxheader">responseText</span>
24 <pre id="id1">@@No result@@</pre>
25 </div>
26 <br>
27
28 <div id="console"></div>
29
30 <script>
31 description("Tests XMLHttpRequest 'text' loading with the .responseType and .response attributes.");
32
33 var xhr = 0;
34
35 function load() {
36     testPassed('DONE LOADING');
37     testPassed('received response object of type : ' + typeof xhr.response + ".");
38
39     // Make sure exception is thrown if responseType is set too late in the loading process.
40     // .responseType was previously set to "text".  Let's try setting it to "arraybuffer".
41     try {
42         xhr.responseType = "arraybuffer";
43     } catch(e) {
44         testPassed("exception correctly thrown when xhr.responseType is set to valid value too late in the loading process : " + e + ".");
45     }
46
47     // Get .responseText
48     document.getElementById("id1").firstChild.nodeValue = xhr.responseText;
49
50     // .response is really just an alias to .responseText when .responseType is set to "text".
51     // Make sure they're the same.
52     if (xhr.response == xhr.responseText)
53         testPassed("xhr.response == xhr.responseText.");
54     else
55         testFailed("xhr.response == xhr.responseText.");
56
57     xhr = null;
58     finishJSTest();
59 }
60
61 function runTest() {
62     if (window.layoutTestController) {
63         layoutTestController.dumpAsText();
64         layoutTestController.waitUntilDone();
65     }
66
67     xhr = new XMLHttpRequest();
68     xhr.onload = load;
69     xhr.open("GET", "resources/xmlhttprequest-get-data.xml", true);
70         
71     try {
72         if ("responseType" in xhr)
73             testPassed("responseType property exists.");
74         else
75             testFailed("responseType property does not exist.");
76         
77
78         if ("response" in xhr)
79             testPassed("response property exists.");
80         else
81             testFailed("response property does not exist.");
82
83         // Make sure we can set responseType to "text" before send() is called.
84         try {
85             xhr.responseType = "text";
86             if (xhr.responseType == "text")
87                 testPassed("xhr.responseType has been correctly set to 'text'.");
88         } catch(e) {
89             testFailed("unable to set xhr.responseType to 'text' " + e + ".");
90         }
91     } catch(e) {
92         testFailed("Caught exception " + e + ".");
93     }
94
95     xhr.send(null);
96     window.jsTestIsAsync = true;
97 }
98
99 runTest();
100
101 </script>
102
103 <script src="../js/resources/js-test-post.js"></script>
104
105 </body>
106 </html>