OLD | NEW |
(Empty) | |
| 1 <html> |
| 2 <body> |
| 3 <script src="../../resources/testharness.js"></script> |
| 4 <script src="../../resources/testharnessreport.js"></script> |
| 5 <script> |
| 6 |
| 7 var test = async_test("Test parsing a data URL. US-ASCII into DOMString"); |
| 8 test.step(function() { |
| 9 var xhr = new XMLHttpRequest; |
| 10 xhr.responseType = 'text'; |
| 11 xhr.open('GET', 'data:text/html,Foobar', true); |
| 12 xhr.onreadystatechange = test.step_func(function() { |
| 13 if (xhr.readyState != xhr.DONE) |
| 14 return; |
| 15 |
| 16 assert_equals(xhr.status, 200, 'status'); |
| 17 assert_equals(xhr.statusText, 'OK', 'statusText'); |
| 18 assert_equals(xhr.getAllResponseHeaders(), 'Content-Type: text/html;char
set=US-ASCII\r\n', 'getAllResponseheaders()'); |
| 19 assert_equals(xhr.response, 'Foobar', 'response'); |
| 20 |
| 21 test.done(); |
| 22 }); |
| 23 xhr.send(); |
| 24 }); |
| 25 |
| 26 var testArrayBuffer = async_test("Test parsing a data URL. Binary into ArrayBuff
er"); |
| 27 testArrayBuffer.step(function() { |
| 28 var xhr = new XMLHttpRequest; |
| 29 xhr.responseType = 'arraybuffer'; |
| 30 xhr.open('GET', 'data:text/html;base64,AAEC/w%3D%3D', true); |
| 31 xhr.onreadystatechange = testArrayBuffer.step_func(function() { |
| 32 if (xhr.readyState != xhr.DONE) |
| 33 return; |
| 34 |
| 35 assert_equals(xhr.status, 200, 'status'); |
| 36 assert_equals(xhr.response.byteLength, 4, 'byteLength'); |
| 37 var view = new Uint8Array(xhr.response); |
| 38 assert_equals(view[0], 0x00, 'view[0]') |
| 39 assert_equals(view[1], 0x01, 'view[1]') |
| 40 assert_equals(view[2], 0x02, 'view[2]') |
| 41 assert_equals(view[3], 0xff, 'view[3]') |
| 42 |
| 43 testArrayBuffer.done(); |
| 44 }); |
| 45 xhr.send(); |
| 46 }); |
| 47 |
| 48 var testUtf8 = async_test("Test parsing a data URL. UTF-8 data into DOMString.")
; |
| 49 testUtf8.step(function() { |
| 50 var xhr = new XMLHttpRequest; |
| 51 xhr.responseType = 'text'; |
| 52 xhr.open('GET', 'data:text/html;charset=utf-8;base64,5paH5a2X', true); |
| 53 xhr.onreadystatechange = testUtf8.step_func(function() { |
| 54 if (xhr.readyState != xhr.DONE) |
| 55 return; |
| 56 |
| 57 assert_equals(xhr.status, 200, 'status'); |
| 58 assert_equals(xhr.getAllResponseHeaders(), 'Content-Type: text/html;char
set=utf-8\r\n', 'getAllResponseheaders()'); |
| 59 assert_equals(xhr.response, '\u6587\u5b57', 'response'); |
| 60 |
| 61 testUtf8.done(); |
| 62 }); |
| 63 xhr.send(); |
| 64 }); |
| 65 |
| 66 var testBad = async_test("Test parsing a data URL. Invalid Base64 data."); |
| 67 testBad.step(function() { |
| 68 var xhr = new XMLHttpRequest; |
| 69 xhr.responseType = 'text'; |
| 70 xhr.open('GET', 'data:text/html;base64,***', true); |
| 71 xhr.onreadystatechange = testBad.step_func(function() { |
| 72 if (xhr.readyState != xhr.DONE) |
| 73 return; |
| 74 |
| 75 assert_not_equals(xhr.status, 200, 'status'); |
| 76 |
| 77 testBad.done(); |
| 78 }); |
| 79 xhr.send(); |
| 80 }); |
| 81 |
| 82 </script> |
| 83 </body> |
| 84 </html> |
OLD | NEW |