tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

send-entity-body-document.htm (3526B)


      1 <!doctype html>
      2 <html>
      3  <head>
      4    <title>XMLHttpRequest: send() - Document</title>
      5    <meta charset="utf-8">
      6    <script src="/resources/testharness.js"></script>
      7    <script src="/resources/testharnessreport.js"></script>
      8    <link rel="help" href="https://xhr.spec.whatwg.org/#the-send()-method" data-tested-assertations="/following::ol/li[4]" />
      9    <link rel="help" href="https://xhr.spec.whatwg.org/#dom-XMLHttpRequest-send-document" data-tested-assertations="/following::dd" />
     10  </head>
     11  <body>
     12    <div id="log"></div>
     13    <script>
     14    var tests = [
     15      {
     16        title: 'XML document, windows-1252',
     17        url: 'resources/win-1252-xml.py',
     18        contentType: 'application/xml;charset=UTF-8',
     19        responseText: '<\u00FF\/>'
     20      },
     21      // Invalid character code in document turns into U+FFFD.
     22      {
     23        title: 'HTML document, invalid UTF-8',
     24        url: 'resources/invalid-utf8-html.py',
     25        contentType: 'text/html;charset=UTF-8',
     26        responseText: '<body>\uFFFD<\/body>'
     27      },
     28      // Correctly serialized Shift-JIS.
     29      {
     30        title: 'HTML document, shift-jis',
     31        url: 'resources/shift-jis-html.py',
     32        contentType: 'text/html;charset=UTF-8',
     33        responseText: '<body>\u30C6\u30b9\u30c8<\/body>'
     34      },
     35      // There's some markup included, but it's not really relevant for this
     36      // test suite, so we do an indexOf() test.
     37      {
     38        title: 'plain text file',
     39        url: 'folder.txt',
     40        contentType: 'text/html;charset=UTF-8',
     41        responseText: 'top'
     42      },
     43      // This test does not want to assert anything about what markup a
     44      // standalone image should be wrapped in. Hence this test lacks a
     45      // responseText expectation.
     46      {
     47        title: 'image file',
     48        url: 'resources/image.gif',
     49        contentType: 'text/html;charset=UTF-8'
     50      },
     51      {
     52        title: 'img tag',
     53        url: 'resources/img-utf8-html.py',
     54        contentType: 'text/html;charset=UTF-8',
     55        responseText: '<img>foo'
     56      },
     57      {
     58        title: 'empty div',
     59        url: 'resources/empty-div-utf8-html.py',
     60        contentType: 'text/html;charset=UTF-8',
     61        responseText: '<!DOCTYPE html><html><head></head><body><div></div></body></html>'
     62      }
     63    ];
     64 
     65    tests.forEach(function(t) {
     66      async_test(function() {
     67        var iframe = document.createElement("iframe");
     68        iframe.onload = this.step_func_done(function() {
     69          var client = new XMLHttpRequest()
     70          client.open("POST", "resources/content.py?response_charset_label=UTF-8", false)
     71          client.send(iframe.contentDocument)
     72          assert_equals(client.getResponseHeader('X-Request-Content-Type'),
     73                        t.contentType,
     74                        'document should be serialized and sent as ' + t.contentType)
     75          // The indexOf() assertion will overlook some stuff, e.g. XML
     76          // prologues that shouldn't be there (looking at you, Presto).
     77          // However, arguably these things have little to do with the XHR
     78          // functionality we're testing.
     79          if (t.responseText) {
     80            assert_true(client.responseText.indexOf(t.responseText) != -1,
     81                        JSON.stringify(t.responseText) + " not in " +
     82                        JSON.stringify(client.responseText));
     83          }
     84          assert_equals(client.responseXML, null)
     85        });
     86        iframe.src = t.url;
     87        document.body.appendChild(iframe);
     88      }, t.title);
     89    });
     90    </script>
     91  </body>
     92 </html>