Commit 7ff93d98 authored by Takeshi Yoshino's avatar Takeshi Yoshino Committed by Commit Bot

Pass the test function to async_test() directly in a XHR layout test

Bug: 
Change-Id: Ib3b20abc3e21e02bca2aa597342ad9907c1b23aa
Reviewed-on: https://chromium-review.googlesource.com/571252Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Commit-Queue: Takeshi Yoshino <tyoshino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#486722}
parent b9fc0761
<html>
<body>
<script src="../../resources/testharness.js"></script> <script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script> <script src="../../resources/testharnessreport.js"></script>
<script> <script>
...@@ -7,97 +5,90 @@ ...@@ -7,97 +5,90 @@
// scheme and then the access to data: resources are handled as same origin // scheme and then the access to data: resources are handled as same origin
// access. // access.
var test = async_test("Test parsing a data URL. US-ASCII into DOMString"); async_test(t => {
test.step(function() { var xhr = new XMLHttpRequest;
var xhr = new XMLHttpRequest; xhr.responseType = 'text';
xhr.responseType = 'text'; xhr.open('GET', 'data:text/html,Foobar', true);
xhr.open('GET', 'data:text/html,Foobar', true); xhr.onreadystatechange = t.step_func(function() {
xhr.onreadystatechange = test.step_func(function() { if (xhr.readyState != xhr.DONE)
if (xhr.readyState != xhr.DONE) return;
return;
assert_equals(xhr.status, 200, 'status'); assert_equals(xhr.status, 200, 'status');
assert_equals(xhr.statusText, 'OK', 'statusText'); assert_equals(xhr.statusText, 'OK', 'statusText');
assert_equals(xhr.getAllResponseHeaders(), 'content-type: text/html\r\n', 'getAllResponseheaders()'); assert_equals(xhr.getAllResponseHeaders(), 'content-type: text/html\r\n', 'getAllResponseheaders()');
assert_equals(xhr.response, 'Foobar', 'response'); assert_equals(xhr.response, 'Foobar', 'response');
test.done(); t.done();
}); });
xhr.send(); xhr.send();
}); }, "Test parsing a data URL. US-ASCII into DOMString");
var testArrayBuffer = async_test("Test parsing a data URL. Binary into ArrayBuffer"); async_test(t => {
testArrayBuffer.step(function() { var xhr = new XMLHttpRequest;
var xhr = new XMLHttpRequest; xhr.responseType = 'arraybuffer';
xhr.responseType = 'arraybuffer'; xhr.open('GET', 'data:text/html;base64,AAEC/w%3D%3D', true);
xhr.open('GET', 'data:text/html;base64,AAEC/w%3D%3D', true); xhr.onreadystatechange = t.step_func(function() {
xhr.onreadystatechange = testArrayBuffer.step_func(function() { if (xhr.readyState != xhr.DONE)
if (xhr.readyState != xhr.DONE) return;
return;
assert_equals(xhr.status, 200, 'status'); assert_equals(xhr.status, 200, 'status');
assert_equals(xhr.response.byteLength, 4, 'byteLength'); assert_equals(xhr.response.byteLength, 4, 'byteLength');
var view = new Uint8Array(xhr.response); var view = new Uint8Array(xhr.response);
assert_equals(view[0], 0x00, 'view[0]') assert_equals(view[0], 0x00, 'view[0]')
assert_equals(view[1], 0x01, 'view[1]') assert_equals(view[1], 0x01, 'view[1]')
assert_equals(view[2], 0x02, 'view[2]') assert_equals(view[2], 0x02, 'view[2]')
assert_equals(view[3], 0xff, 'view[3]') assert_equals(view[3], 0xff, 'view[3]')
testArrayBuffer.done(); t.done();
}); });
xhr.send(); xhr.send();
}); }, "Test parsing a data URL. Binary into ArrayBuffer");
var testUtf8 = async_test("Test parsing a data URL. UTF-8 data into DOMString."); async_test(t => {
testUtf8.step(function() { var xhr = new XMLHttpRequest;
var xhr = new XMLHttpRequest; xhr.responseType = 'text';
xhr.responseType = 'text'; xhr.open('GET', 'data:text/html;charset=utf-8;base64,5paH5a2X', true);
xhr.open('GET', 'data:text/html;charset=utf-8;base64,5paH5a2X', true); xhr.onreadystatechange = t.step_func(function() {
xhr.onreadystatechange = testUtf8.step_func(function() { if (xhr.readyState != xhr.DONE)
if (xhr.readyState != xhr.DONE) return;
return;
assert_equals(xhr.status, 200, 'status'); assert_equals(xhr.status, 200, 'status');
assert_equals(xhr.getAllResponseHeaders(), 'content-type: text/html;charset=utf-8\r\n', 'getAllResponseheaders()'); assert_equals(xhr.getAllResponseHeaders(), 'content-type: text/html;charset=utf-8\r\n', 'getAllResponseheaders()');
assert_equals(xhr.response, '\u6587\u5b57', 'response'); assert_equals(xhr.response, '\u6587\u5b57', 'response');
testUtf8.done(); t.done();
}); });
xhr.send(); xhr.send();
}); }, "Test parsing a data URL. UTF-8 data into DOMString.");
var testUtf8Blob = async_test("Test parsing a data URL. UTF-8 data into Blob."); async_test(t => {
testUtf8Blob.step(function() { var xhr = new XMLHttpRequest;
var xhr = new XMLHttpRequest; xhr.responseType = 'blob';
xhr.responseType = 'blob'; xhr.open('GET', 'data:text/html;charset=utf-8;base64,5paH5a2X', true);
xhr.open('GET', 'data:text/html;charset=utf-8;base64,5paH5a2X', true); xhr.onreadystatechange = t.step_func(function() {
xhr.onreadystatechange = testUtf8Blob.step_func(function() { if (xhr.readyState != xhr.DONE)
if (xhr.readyState != xhr.DONE) return;
return;
assert_equals(xhr.status, 0, 'status'); assert_equals(xhr.status, 0, 'status');
assert_equals(xhr.response, null, 'response'); assert_equals(xhr.response, null, 'response');
testUtf8Blob.done(); t.done();
}); });
xhr.send(); xhr.send();
}); }, "Test parsing a data URL. UTF-8 data into Blob.");
var testBad = async_test("Test parsing a data URL. Invalid Base64 data."); async_test(t => {
testBad.step(function() { var xhr = new XMLHttpRequest;
var xhr = new XMLHttpRequest; xhr.responseType = 'text';
xhr.responseType = 'text'; xhr.open('GET', 'data:text/html;base64,***', true);
xhr.open('GET', 'data:text/html;base64,***', true); xhr.onreadystatechange = t.step_func(function() {
xhr.onreadystatechange = testBad.step_func(function() { if (xhr.readyState != xhr.DONE)
if (xhr.readyState != xhr.DONE) return;
return;
assert_not_equals(xhr.status, 200, 'status'); assert_not_equals(xhr.status, 200, 'status');
testBad.done(); t.done();
}); });
xhr.send(); xhr.send();
}); }, "Test parsing a data URL. Invalid Base64 data.");
</script> </script>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment