OLD | NEW |
(Empty) | |
| 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;char
set=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 ArrayBuff
er"); |
| 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;char
set=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, 200, 'status'); |
| 79 assert_not_equals(xhr.response, null, 'response'); |
| 80 assert_equals(xhr.response.type, 'text/html', 'response.type'); |
| 81 var reader = new FileReader(); |
| 82 reader.onabort = testUtf8Blob.step_func(function() { assert_unreached('o
nabort'); }); |
| 83 reader.onerror = testUtf8Blob.step_func(function() { assert_unreached('o
nerror'); }); |
| 84 reader.onload = testUtf8Blob.step_func(function() { |
| 85 assert_equals(reader.result, '\u6587\u5b57', 'result'); |
| 86 testUtf8Blob.done(); |
| 87 }); |
| 88 reader.readAsText(xhr.response); |
| 89 }); |
| 90 xhr.send(); |
| 91 }); |
| 92 |
| 93 var testBad = async_test("Test parsing a data URL. Invalid Base64 data."); |
| 94 testBad.step(function() { |
| 95 var xhr = new XMLHttpRequest; |
| 96 xhr.responseType = 'text'; |
| 97 xhr.open('GET', 'data:text/html;base64,***', true); |
| 98 xhr.onreadystatechange = testBad.step_func(function() { |
| 99 if (xhr.readyState != xhr.DONE) |
| 100 return; |
| 101 |
| 102 assert_not_equals(xhr.status, 200, 'status'); |
| 103 |
| 104 testBad.done(); |
| 105 }); |
| 106 xhr.send(); |
| 107 }); |
| 108 |
| 109 </script> |
| 110 </body> |
| 111 </html> |
OLD | NEW |