Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / xmlhttprequest / xmlhttprequest-data-url.html
1 <html>
2 <body>
3 <script src="../../resources/testharness.js"></script>
4 <script src="../../resources/testharnessreport.js"></script>
5 <script>
6 // This test must be run over HTTP. Otherwise, content_shell runs it with file:
7 // scheme and then the access to data: resources are handled as same origin
8 // access.
9
10 var test = async_test("Test parsing a data URL. US-ASCII into DOMString");
11 test.step(function() {
12     var xhr = new XMLHttpRequest;
13     xhr.responseType = 'text';
14     xhr.open('GET', 'data:text/html,Foobar', true);
15     xhr.onreadystatechange = test.step_func(function() {
16         if (xhr.readyState != xhr.DONE)
17             return;
18
19         assert_equals(xhr.status, 200, 'status');
20         assert_equals(xhr.statusText, 'OK', 'statusText');
21         assert_equals(xhr.getAllResponseHeaders(), 'Content-Type: text/html;charset=US-ASCII\r\n', 'getAllResponseheaders()');
22         assert_equals(xhr.response, 'Foobar', 'response');
23
24         test.done();
25     });
26     xhr.send();
27 });
28
29 var testArrayBuffer = async_test("Test parsing a data URL. Binary into ArrayBuffer");
30 testArrayBuffer.step(function() {
31     var xhr = new XMLHttpRequest;
32     xhr.responseType = 'arraybuffer';
33     xhr.open('GET', 'data:text/html;base64,AAEC/w%3D%3D', true);
34     xhr.onreadystatechange = testArrayBuffer.step_func(function() {
35         if (xhr.readyState != xhr.DONE)
36             return;
37
38         assert_equals(xhr.status, 200, 'status');
39         assert_equals(xhr.response.byteLength, 4, 'byteLength');
40         var view = new Uint8Array(xhr.response);
41         assert_equals(view[0], 0x00, 'view[0]')
42         assert_equals(view[1], 0x01, 'view[1]')
43         assert_equals(view[2], 0x02, 'view[2]')
44         assert_equals(view[3], 0xff, 'view[3]')
45
46         testArrayBuffer.done();
47     });
48     xhr.send();
49 });
50
51 var testUtf8 = async_test("Test parsing a data URL. UTF-8 data into DOMString.");
52 testUtf8.step(function() {
53     var xhr = new XMLHttpRequest;
54     xhr.responseType = 'text';
55     xhr.open('GET', 'data:text/html;charset=utf-8;base64,5paH5a2X', true);
56     xhr.onreadystatechange = testUtf8.step_func(function() {
57         if (xhr.readyState != xhr.DONE)
58             return;
59
60         assert_equals(xhr.status, 200, 'status');
61         assert_equals(xhr.getAllResponseHeaders(), 'Content-Type: text/html;charset=utf-8\r\n', 'getAllResponseheaders()');
62         assert_equals(xhr.response, '\u6587\u5b57', 'response');
63
64         testUtf8.done();
65     });
66     xhr.send();
67 });
68
69 var testUtf8Blob = async_test("Test parsing a data URL. UTF-8 data into Blob.");
70 testUtf8Blob.step(function() {
71     var xhr = new XMLHttpRequest;
72     xhr.responseType = 'blob';
73     xhr.open('GET', 'data:text/html;charset=utf-8;base64,5paH5a2X', true);
74     xhr.onreadystatechange = testUtf8Blob.step_func(function() {
75         if (xhr.readyState != xhr.DONE)
76             return;
77
78         assert_equals(xhr.status, 0, 'status');
79         assert_equals(xhr.response, null, 'response');
80         testUtf8Blob.done();
81     });
82     xhr.send();
83 });
84
85 var testBad = async_test("Test parsing a data URL. Invalid Base64 data.");
86 testBad.step(function() {
87     var xhr = new XMLHttpRequest;
88     xhr.responseType = 'text';
89     xhr.open('GET', 'data:text/html;base64,***', true);
90     xhr.onreadystatechange = testBad.step_func(function() {
91         if (xhr.readyState != xhr.DONE)
92             return;
93
94         assert_not_equals(xhr.status, 200, 'status');
95
96         testBad.done();
97     });
98     xhr.send();
99 });
100
101 </script>
102 </body>
103 </html>