mirror of
https://github.com/servo/servo.git
synced 2025-06-23 08:34:42 +01:00
61 lines
3.7 KiB
HTML
61 lines
3.7 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<title>XMLHttpRequest: send() - Document</title>
|
|
<meta charset="utf-8">
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<link rel="help" href="https://xhr.spec.whatwg.org/#the-send()-method" data-tested-assertations="/following::ol/li[4]" />
|
|
<link rel="help" href="https://xhr.spec.whatwg.org/#dom-XMLHttpRequest-send-document" data-tested-assertations="/following::dd" />
|
|
</head>
|
|
<body>
|
|
<div id="log"></div>
|
|
<script>
|
|
var expectations = [
|
|
{ contentType: 'application/xml;charset=UTF-8', responseText : '<\u00FF\/>' },
|
|
{ contentType: 'text/html;charset=UTF-8', responseText : '<body>\uFFFD<\/body>' }, /*invalid character code in document turns into FFFD*/
|
|
{ contentType: 'text/html;charset=UTF-8', responseText : '<body>\u30C6\u30b9\u30c8<\/body>' } /* correctly serialized Shift-JIS */,
|
|
{ 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 */
|
|
{ contentType: 'text/html;charset=UTF-8' },
|
|
{ contentType: 'text/html;charset=UTF-8', responseText: '<img>foo' },
|
|
{ contentType: 'text/html;charset=UTF-8', responseText: '<!DOCTYPE html><html><head></head><body><div></div></body></html>' }
|
|
]
|
|
|
|
|
|
function request(input, number, title) {
|
|
test(function() {
|
|
var client = new XMLHttpRequest()
|
|
client.open("POST", "resources/content.py?response_charset_label=UTF-8", false)
|
|
client.send(input)
|
|
var exp = expectations[number]
|
|
assert_equals(client.getResponseHeader('X-Request-Content-Type'), exp.contentType, 'document should be serialized and sent as '+exp.contentType+' (TEST#'+number+')')
|
|
// The indexOf() assertation will overlook some stuff, i.e. XML prologues that shouldn't be there (looking at you, Presto).
|
|
// However, arguably these things have little to do with the XHR functionality we're testing.
|
|
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.
|
|
assert_true(client.responseText.indexOf(exp.responseText) != -1,
|
|
JSON.stringify(exp.responseText) + " not in " +
|
|
JSON.stringify(client.responseText));
|
|
}
|
|
assert_equals(client.responseXML, null)
|
|
}, title)
|
|
}
|
|
function init(fr, number, title) { request(fr.contentDocument, number, title) }
|
|
</script>
|
|
<!--
|
|
This test also tests how documents in various encodings are serialized.
|
|
The below IFRAMEs contain:
|
|
* one XML document parsed from a windows-1252 source - content is <ÿ/>
|
|
* one HTML-document parsed from an invalid UTF-8 source, will contain a basic HTML DOM
|
|
with a U+FFFD replacement character for the invalid char
|
|
* one HTML document parsed from a valid Shift-JIS source
|
|
-->
|
|
<iframe src='resources/win-1252-xml.py' onload="init(this, 0, 'XML document, windows-1252')"></iframe>
|
|
<iframe src='resources/invalid-utf8-html.py' onload="init(this, 1, 'HTML document, invalid UTF-8')"></iframe>
|
|
<iframe src='resources/shift-jis-html.py' onload="init(this, 2, 'HTML document, shift-jis')"></iframe>
|
|
<iframe src='folder.txt' onload="init(this, 3, 'plain text file')"></iframe>
|
|
<iframe src='resources/image.gif' onload="init(this, 4, 'image file')"></iframe>
|
|
<iframe src='resources/img-utf8-html.py' onload="init(this, 5, 'img tag')"></iframe>
|
|
<iframe src='resources/empty-div-utf8-html.py' onload="init(this, 6, 'empty div')"></iframe>
|
|
|
|
</body>
|
|
</html>
|