blob: 6dc1f95bf1ac09d89c65d7420fe2667e46ca9665 [file] [log] [blame]
<!doctype html>
<meta charset=utf-8>
<title>XMLHttpRequest: data uri</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#data:-urls-and-http" data-tested-assertations="/following::ul[1] /following::ul[2]" />
<div id="log"></div>
<script>
function do_test(method, uri, charset) {
if (typeof charset === 'undefined' || charset === null) charset = 'text/plain';
var test = async_test("XHR method " + method + " with charset " + charset);
test.step(function() {
var client = new XMLHttpRequest();
client.onreadystatechange = test.step_func(function () {
if (client.readyState !== 4) return;
if (method.toUpperCase() !== 'GET') {
assert_equals(client.status, 501);
assert_equals(client.responseText, null);
return;
}
assert_equals(client.responseText, "Hello, World!");
assert_equals(client.status, 200);
assert_equals(client.getResponseHeader('Content-Type'), charset);
test.done();
});
client.open(method, uri);
client.send(null);
});
}
do_test('GET', "data:text/plain,Hello, World!");
do_test('GET', "data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==");
do_test('GET', "data:text/html,Hello, World!", 'text/html');
do_test('GET', "data:image/png,Hello, World!", 'image/png');
do_test('POST', "data:text/plain,Hello, World!");
do_test('PUT', "data:text/plain,Hello, World!");
do_test('DELETE', "data:text/plain,Hello, World!");
do_test('HEAD', "data:text/plain,Hello, World!");
do_test('UNICORN', "data:text/plain,Hello, World!");
</script>