| Index: LayoutTests/http/tests/xmlhttprequest/xmlhttprequest-data-url.html
|
| diff --git a/LayoutTests/http/tests/xmlhttprequest/xmlhttprequest-data-url.html b/LayoutTests/http/tests/xmlhttprequest/xmlhttprequest-data-url.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0b8903d38f6f449186fdfb9a9bcdc64f57ff864b
|
| --- /dev/null
|
| +++ b/LayoutTests/http/tests/xmlhttprequest/xmlhttprequest-data-url.html
|
| @@ -0,0 +1,111 @@
|
| +<html>
|
| +<body>
|
| +<script src="../../resources/testharness.js"></script>
|
| +<script src="../../resources/testharnessreport.js"></script>
|
| +<script>
|
| +// This test must be run over HTTP. Otherwise, content_shell runs it with file:
|
| +// scheme and then the access to data: resources are handled as same origin
|
| +// access.
|
| +
|
| +var test = async_test("Test parsing a data URL. US-ASCII into DOMString");
|
| +test.step(function() {
|
| + var xhr = new XMLHttpRequest;
|
| + xhr.responseType = 'text';
|
| + xhr.open('GET', 'data:text/html,Foobar', true);
|
| + xhr.onreadystatechange = test.step_func(function() {
|
| + if (xhr.readyState != xhr.DONE)
|
| + return;
|
| +
|
| + assert_equals(xhr.status, 200, 'status');
|
| + assert_equals(xhr.statusText, 'OK', 'statusText');
|
| + assert_equals(xhr.getAllResponseHeaders(), 'Content-Type: text/html;charset=US-ASCII\r\n', 'getAllResponseheaders()');
|
| + assert_equals(xhr.response, 'Foobar', 'response');
|
| +
|
| + test.done();
|
| + });
|
| + xhr.send();
|
| +});
|
| +
|
| +var testArrayBuffer = async_test("Test parsing a data URL. Binary into ArrayBuffer");
|
| +testArrayBuffer.step(function() {
|
| + var xhr = new XMLHttpRequest;
|
| + xhr.responseType = 'arraybuffer';
|
| + xhr.open('GET', 'data:text/html;base64,AAEC/w%3D%3D', true);
|
| + xhr.onreadystatechange = testArrayBuffer.step_func(function() {
|
| + if (xhr.readyState != xhr.DONE)
|
| + return;
|
| +
|
| + assert_equals(xhr.status, 200, 'status');
|
| + assert_equals(xhr.response.byteLength, 4, 'byteLength');
|
| + var view = new Uint8Array(xhr.response);
|
| + assert_equals(view[0], 0x00, 'view[0]')
|
| + assert_equals(view[1], 0x01, 'view[1]')
|
| + assert_equals(view[2], 0x02, 'view[2]')
|
| + assert_equals(view[3], 0xff, 'view[3]')
|
| +
|
| + testArrayBuffer.done();
|
| + });
|
| + xhr.send();
|
| +});
|
| +
|
| +var testUtf8 = async_test("Test parsing a data URL. UTF-8 data into DOMString.");
|
| +testUtf8.step(function() {
|
| + var xhr = new XMLHttpRequest;
|
| + xhr.responseType = 'text';
|
| + xhr.open('GET', 'data:text/html;charset=utf-8;base64,5paH5a2X', true);
|
| + xhr.onreadystatechange = testUtf8.step_func(function() {
|
| + if (xhr.readyState != xhr.DONE)
|
| + return;
|
| +
|
| + assert_equals(xhr.status, 200, 'status');
|
| + assert_equals(xhr.getAllResponseHeaders(), 'Content-Type: text/html;charset=utf-8\r\n', 'getAllResponseheaders()');
|
| + assert_equals(xhr.response, '\u6587\u5b57', 'response');
|
| +
|
| + testUtf8.done();
|
| + });
|
| + xhr.send();
|
| +});
|
| +
|
| +var testUtf8Blob = async_test("Test parsing a data URL. UTF-8 data into Blob.");
|
| +testUtf8Blob.step(function() {
|
| + var xhr = new XMLHttpRequest;
|
| + xhr.responseType = 'blob';
|
| + xhr.open('GET', 'data:text/html;charset=utf-8;base64,5paH5a2X', true);
|
| + xhr.onreadystatechange = testUtf8Blob.step_func(function() {
|
| + if (xhr.readyState != xhr.DONE)
|
| + return;
|
| +
|
| + assert_equals(xhr.status, 200, 'status');
|
| + assert_not_equals(xhr.response, null, 'response');
|
| + assert_equals(xhr.response.type, 'text/html', 'response.type');
|
| + var reader = new FileReader();
|
| + reader.onabort = testUtf8Blob.step_func(function() { assert_unreached('onabort'); });
|
| + reader.onerror = testUtf8Blob.step_func(function() { assert_unreached('onerror'); });
|
| + reader.onload = testUtf8Blob.step_func(function() {
|
| + assert_equals(reader.result, '\u6587\u5b57', 'result');
|
| + testUtf8Blob.done();
|
| + });
|
| + reader.readAsText(xhr.response);
|
| + });
|
| + xhr.send();
|
| +});
|
| +
|
| +var testBad = async_test("Test parsing a data URL. Invalid Base64 data.");
|
| +testBad.step(function() {
|
| + var xhr = new XMLHttpRequest;
|
| + xhr.responseType = 'text';
|
| + xhr.open('GET', 'data:text/html;base64,***', true);
|
| + xhr.onreadystatechange = testBad.step_func(function() {
|
| + if (xhr.readyState != xhr.DONE)
|
| + return;
|
| +
|
| + assert_not_equals(xhr.status, 200, 'status');
|
| +
|
| + testBad.done();
|
| + });
|
| + xhr.send();
|
| +});
|
| +
|
| +</script>
|
| +</body>
|
| +</html>
|
|
|