blob: 5f1cb68dce819d0884a64bc9a106c9b5e21ac58b [file] [log] [blame]
Philip Jägenstedtc053f402014-01-22 17:02:181<!doctype html>
2<html>
3 <head>
4 <title>XMLHttpRequest: send() - Document</title>
Hallvord R. M. Steen856f2da2013-09-23 20:45:495 <meta charset="utf-8">
Philip Jägenstedtc053f402014-01-22 17:02:186 <script src="/resources/testharness.js"></script>
7 <script src="/resources/testharnessreport.js"></script>
Ms2ger91fef142014-11-01 09:24:378 <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" />
Philip Jägenstedtc053f402014-01-22 17:02:1810 </head>
11 <body>
12 <div id="log"></div>
13 <script>
Hallvord R. M. Steen856f2da2013-09-23 20:45:4914 var expectations = [
Hallvord R. M. Steenc59ba922014-02-07 07:19:5415 { contentType: 'application/xml;charset=UTF-8', responseText : '<\u00FF\/>' },
16 { contentType: 'text/html;charset=UTF-8', responseText : '<body>\uFFFD<\/body>' }, /*invalid character code in document turns into FFFD*/
17 { contentType: 'text/html;charset=UTF-8', responseText : '<body>\u30C6\u30b9\u30c8<\/body>' } /* correctly serialized Shift-JIS */,
18 { contentType: 'text/html;charset=UTF-8', responseText: 'top' }, /* There's some markup included, but it's not really relevant for this test suite, so we do an indexOf() test */
Michael Layzell2f3f5412015-10-21 12:31:5819 { contentType: 'text/html;charset=UTF-8' },
20 { contentType: 'text/html;charset=UTF-8', responseText: '<img>foo' },
21 { contentType: 'text/html;charset=UTF-8', responseText: '<!DOCTYPE html><html><head></head><body><div></div></body></html>' }
Hallvord R. M. Steen2a95be62014-02-28 04:14:2822 ]
23
Hallvord R. M. Steen04f212c2014-04-23 12:35:5524
Michael Layzell2f3f5412015-10-21 12:31:5825 function request(input, number, title) {
Philip Jägenstedtc053f402014-01-22 17:02:1826 test(function() {
27 var client = new XMLHttpRequest()
Hallvord R. M. Steen78fe5c72013-10-05 21:43:4728 client.open("POST", "resources/content.py?response_charset_label=UTF-8", false)
Philip Jägenstedtc053f402014-01-22 17:02:1829 client.send(input)
Hallvord R. M. Steen856f2da2013-09-23 20:45:4930 var exp = expectations[number]
Hallvord R. M. Steenc59ba922014-02-07 07:19:5431 assert_equals(client.getResponseHeader('X-Request-Content-Type'), exp.contentType, 'document should be serialized and sent as '+exp.contentType+' (TEST#'+number+')')
Hallvord R. M. Steen856f2da2013-09-23 20:45:4932 // The indexOf() assertation will overlook some stuff, i.e. XML prologues that shouldn't be there (looking at you, Presto).
33 // However, arguably these things have little to do with the XHR functionality we're testing.
Hallvord R. M. Steenb307a4f2014-02-28 04:24:5734 if(exp.responseText){ // This test does not want to assert anything about what markup a standalone IMG should be wrapped in. Hence the GIF test lacks a responseText expectation.
Michael Layzell2f3f5412015-10-21 12:31:5835 assert_true(client.responseText.indexOf(exp.responseText) != -1,
36 JSON.stringify(exp.responseText) + " not in " +
37 JSON.stringify(client.responseText));
Hallvord R. M. Steenb307a4f2014-02-28 04:24:5738 }
Philip Jägenstedtc053f402014-01-22 17:02:1839 assert_equals(client.responseXML, null)
James Grahama2522832014-04-07 16:19:1440 }, title)
Philip Jägenstedtc053f402014-01-22 17:02:1841 }
Michael Layzell2f3f5412015-10-21 12:31:5842 function init(fr, number, title) { request(fr.contentDocument, number, title) }
Philip Jägenstedtc053f402014-01-22 17:02:1843 </script>
Hallvord R. M. Steen856f2da2013-09-23 20:45:4944 <!--
45 This test also tests how documents in various encodings are serialized.
46 The below IFRAMEs contain:
47 * one XML document parsed from a windows-1252 source - content is <ÿ/>
Hallvord R. M. Steen2a95be62014-02-28 04:14:2848 * one HTML-document parsed from an invalid UTF-8 source, will contain a basic HTML DOM
Hallvord R. M. Steen856f2da2013-09-23 20:45:4949 with a U+FFFD replacement character for the invalid char
50 * one HTML document parsed from a valid Shift-JIS source
51 -->
Hallvord R. M. Steen04f212c2014-04-23 12:35:5552 <iframe src='resources/win-1252-xml.py' onload="init(this, 0, 'XML document, windows-1252')"></iframe>
53 <iframe src='resources/invalid-utf8-html.py' onload="init(this, 1, 'HTML document, invalid UTF-8')"></iframe>
54 <iframe src='resources/shift-jis-html.py' onload="init(this, 2, 'HTML document, shift-jis')"></iframe>
55 <iframe src='folder.txt' onload="init(this, 3, 'plain text file')"></iframe>
56 <iframe src='resources/image.gif' onload="init(this, 4, 'image file')"></iframe>
Michael Layzell2f3f5412015-10-21 12:31:5857 <iframe src='resources/img-utf8-html.py' onload="init(this, 5, 'img tag')"></iframe>
58 <iframe src='resources/empty-div-utf8-html.py' onload="init(this, 6, 'empty div')"></iframe>
Hallvord R. M. Steen04f212c2014-04-23 12:35:5559
Philip Jägenstedtc053f402014-01-22 17:02:1860 </body>
61</html>