https://github.com/web-platform-tests/wpt
Raw File
Tip revision: e58b9b6c5ed4a0846aea6de7366a492d627f0c12 authored by Robin Berjon on 10 April 2014, 17:37:03 UTC
the HTTP interface expects a date, not a string containing a date
Tip revision: e58b9b6
data-uri.htm
<!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/li[1] following::ul/li[2] following::ul/li[4]" />
    <link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-send()-method" data-tested-assertations="following::ul/li[10]/dl/dt[2]" />
<div id="log"></div>

<script>
  function do_test(method, uri, charset, namePostfix) {
    if (typeof charset === 'undefined' || charset === null) charset = 'text/plain';
    var test = async_test("XHR method " + method + " with charset " + charset+(namePostfix||''));
    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==", undefined, " (base64)");
  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>
back to top