3 <script src=
"../../resources/testharness.js"></script>
4 <script src=
"../../resources/testharnessreport.js"></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
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
)
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');
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
)
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]')
46 testArrayBuffer
.done();
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
)
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');
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
)
78 assert_equals(xhr
.status
, 0, 'status');
79 assert_equals(xhr
.response
, null, 'response');
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
)
94 assert_not_equals(xhr
.status
, 200, 'status');