blob: f20a3eaa41af55669e69cdccea0147cfe5a91dca [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>
Hallvord R. M. Steen2a95be62014-02-28 04:14:288 <link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-send()-method" data-tested-assertations="/following::ol/li[4]" />
9 <link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#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 */
19 { contentType: 'text/html;charset=UTF-8' }
Hallvord R. M. Steen2a95be62014-02-28 04:14:2820 ]
21
Hallvord R. M. Steen04f212c2014-04-23 12:35:5522
James Grahama2522832014-04-07 16:19:1423 function request(input, isHTML, title) {
Philip Jägenstedtc053f402014-01-22 17:02:1824 test(function() {
25 var client = new XMLHttpRequest()
Hallvord R. M. Steen78fe5c72013-10-05 21:43:4726 client.open("POST", "resources/content.py?response_charset_label=UTF-8", false)
Philip Jägenstedtc053f402014-01-22 17:02:1827 client.send(input)
Hallvord R. M. Steen856f2da2013-09-23 20:45:4928 var exp = expectations[number]
Hallvord R. M. Steenc59ba922014-02-07 07:19:5429 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:4930 // The indexOf() assertation will overlook some stuff, i.e. XML prologues that shouldn't be there (looking at you, Presto).
31 // However, arguably these things have little to do with the XHR functionality we're testing.
Hallvord R. M. Steenb307a4f2014-02-28 04:24:5732 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.
33 assert_true(client.responseText.indexOf(exp.responseText) != -1);
34 }
Philip Jägenstedtc053f402014-01-22 17:02:1835 assert_equals(client.responseXML, null)
James Grahama2522832014-04-07 16:19:1436 }, title)
Philip Jägenstedtc053f402014-01-22 17:02:1837 }
Hallvord R. M. Steen04f212c2014-04-23 12:35:5538 function init(fr, number, title) { request(fr.contentDocument, number) }
Philip Jägenstedtc053f402014-01-22 17:02:1839 </script>
Hallvord R. M. Steen856f2da2013-09-23 20:45:4940 <!--
41 This test also tests how documents in various encodings are serialized.
42 The below IFRAMEs contain:
43 * one XML document parsed from a windows-1252 source - content is <ÿ/>
Hallvord R. M. Steen2a95be62014-02-28 04:14:2844 * one HTML-document parsed from an invalid UTF-8 source, will contain a basic HTML DOM
Hallvord R. M. Steen856f2da2013-09-23 20:45:4945 with a U+FFFD replacement character for the invalid char
46 * one HTML document parsed from a valid Shift-JIS source
47 -->
Hallvord R. M. Steen04f212c2014-04-23 12:35:5548 <iframe src='resources/win-1252-xml.py' onload="init(this, 0, 'XML document, windows-1252')"></iframe>
49 <iframe src='resources/invalid-utf8-html.py' onload="init(this, 1, 'HTML document, invalid UTF-8')"></iframe>
50 <iframe src='resources/shift-jis-html.py' onload="init(this, 2, 'HTML document, shift-jis')"></iframe>
51 <iframe src='folder.txt' onload="init(this, 3, 'plain text file')"></iframe>
52 <iframe src='resources/image.gif' onload="init(this, 4, 'image file')"></iframe>
53
Philip Jägenstedtc053f402014-01-22 17:02:1854 </body>
55</html>