Update web-platform-tests to revision dc5cbf088edcdb266541d4e5a76149a2c6e716a0

This commit is contained in:
Ms2ger 2016-09-09 09:40:35 +02:00
parent 1d40075f03
commit 079092dfea
2381 changed files with 90360 additions and 17722 deletions

View file

@ -80,14 +80,13 @@
assert_equals(fd.get('key'), "null");
}, 'testFormDataAppendToFormNull2');
test(function() {
var f1 = create_formdata(['key', new Blob(), 'blank.txt']).get('key');
var f2 = new File([new Blob()], 'blank.txt');
var fileAttrs = ['name', 'size', 'type'];
fileAttrs.forEach(function(attr) {
assert_equals(f1[attr], f2[attr], attr + " should be equal");
});
var before = new Date(new Date().getTime() - 2000); // two seconds ago, in case there's clock drift
var fd = create_formdata(['key', new Blob(), 'blank.txt']).get('key');
assert_equals(fd.name, "blank.txt");
assert_equals(fd.type, "");
assert_equals(fd.size, 0);
assert_greater_than_equal(fd.lastModified, before);
assert_less_than_equal(fd.lastModified, new Date());
}, 'testFormDataAppendEmptyBlob');
function create_formdata() {

View file

@ -0,0 +1,40 @@
test(function() {
var client = new XMLHttpRequest()
assert_false(client.withCredentials, "withCredentials defaults to false")
client.withCredentials = true
assert_true(client.withCredentials, "is true after setting")
}, "default value is false, set value is true")
test(function() {
var client = new XMLHttpRequest()
client.open("GET", "resources/delay.py?ms=1000", true)
client.withCredentials = true
assert_true(client.withCredentials, "set in OPEN state")
}, "can also be set in OPEN state")
test(function() {
var client = new XMLHttpRequest()
client.open("GET", "resources/delay.py?ms=1000", false)
client.withCredentials = true
assert_true(client.withCredentials, "set in OPEN state")
}, "setting on synchronous XHR")
async_test(function() {
var client = new XMLHttpRequest()
client.open("GET", "resources/delay.py?ms=1000")
client.send()
assert_throws("InvalidStateError", function() { client.withCredentials = true })
client.onreadystatechange = this.step_func(function() {
assert_throws("InvalidStateError", function() { client.withCredentials = true })
if (client.readyState === 4) {
this.done()
}
})
}, "setting withCredentials when not in UNSENT, OPENED state (asynchronous)")
test(function() {
var client = new XMLHttpRequest()
client.open("GET", "resources/delay.py?ms=1000", false)
client.send();
assert_throws("InvalidStateError", function() { client.withCredentials = true })
}, "setting withCredentials when in DONE state (synchronous)")

View file

@ -1,13 +0,0 @@
<!doctype html>
<meta charset=utf-8>
<title>XMLHttpRequest#withCredentials</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src=XMLHttpRequest-withCredentials.js></script>
<link rel="help" href="https://xhr.spec.whatwg.org/#the-withcredentials-attribute"
data-tested-assertations="following::ol/li[1] following::ol/li[2]
following::ol/li[3] following::ol/li[4]">
<div id="log"></div>
<script>
test_withCredentials(false)
</script>

View file

@ -1,42 +0,0 @@
function test_withCredentials(worker) {
test(function() {
var client = new XMLHttpRequest()
assert_false(client.withCredentials, "withCredentials defaults to false")
client.withCredentials = true
assert_true(client.withCredentials, "is true after setting")
}, "default value is false, set value is true")
test(function() {
var client = new XMLHttpRequest()
client.open("GET", "resources/delay.py?ms=1000", true)
client.withCredentials = true
assert_true(client.withCredentials, "set in OPEN state")
}, "can also be set in OPEN state")
test(function() {
var client = new XMLHttpRequest()
client.open("GET", "resources/delay.py?ms=1000", false)
client.withCredentials = true
assert_true(client.withCredentials, "set in OPEN state")
}, "setting on synchronous XHR")
async_test(function() {
var client = new XMLHttpRequest()
client.open("GET", "resources/delay.py?ms=1000")
client.send()
assert_throws("InvalidStateError", function() { client.withCredentials = true })
client.onreadystatechange = this.step_func(function() {
assert_throws("InvalidStateError", function() { client.withCredentials = true })
if (client.readyState === 4) {
this.done()
}
})
}, "setting withCredentials when not in UNSENT, OPENED state (asynchronous)")
test(function() {
var client = new XMLHttpRequest()
client.open("GET", "resources/delay.py?ms=1000", false)
client.send();
assert_throws("InvalidStateError", function() { client.withCredentials = true })
}, "setting withCredentials when in DONE state (synchronous)")
}

View file

@ -1,4 +0,0 @@
importScripts("/resources/testharness.js")
importScripts("XMLHttpRequest-withCredentials.js")
test_withCredentials(true);
done()

View file

@ -4,6 +4,7 @@
<title>XMLHttpRequest: abort() while sending data</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/xmlhttprequest-event-order.js"></script>
<link rel="help" href="https://xhr.spec.whatwg.org/#the-abort()-method" data-tested-assertations="following-sibling::ol/li[4]/ol/li[7] following-sibling::ol/li[4]/ol/li[7]/ol/li[2] following-sibling::ol/li[4]/ol/li[7]/ol/li[3] following-sibling::ol/li[4]/ol/li[7]/ol/li[4]" />
<link rel="help" href="https://xhr.spec.whatwg.org/#make-upload-progress-notifications" data-tested-assertations="following::ul[1]/li[1] following::ul[1]/li[2]/ol[1]/li[2] following::ul[1]/li[2]/ol[1]/li[3] following::ul[1]/li[2]/ol[1]/li[4]" />
</head>
@ -11,29 +12,16 @@
<div id="log"></div>
<script>
var test = async_test(document.title, {timeout:1100})
var result = []
var expected = ['progress on XHR Upload', 'abort on XHR Upload', 'loadend on XHR Upload', 'progress on XHR', 'abort on XHR', 'loadend on XHR']
function logEvt (e) {
var str = e.type+' on '
str += e.target instanceof XMLHttpRequest ? 'XHR' : 'XHR Upload'
result.push(str)
}
test.step(function() {
var client = new XMLHttpRequest()
prepare_xhr_for_event_order_test(client);
client.open("POST", "resources/delay.py?ms=1000")
client.addEventListener('progress', logEvt)
client.addEventListener('abort', logEvt)
client.addEventListener('loadend', function (e) {
logEvt(e)
client.addEventListener("loadend", function(e) {
test.step(function() {
assert_equals(client.readyState, 4)
assert_array_equals(result, expected)
assert_xhr_event_order_matches([1, "loadstart(0,0,false)", "upload.loadstart(0,9999,true)", 4, "upload.progress(0,0,false)", "upload.abort(0,0,false)", "upload.loadend(0,0,false)", "progress(0,0,false)", "abort(0,0,false)", "loadend(0,0,false)"]);
test.done()
})
})
client.upload.addEventListener('loadend', logEvt)
client.upload.addEventListener('progress', logEvt)
client.upload.addEventListener('abort', logEvt)
});
client.send((new Array(10000)).join('a'))
client.abort()
})

View file

@ -4,6 +4,7 @@
<link rel="help" href="https://xhr.spec.whatwg.org/#the-abort()-method" data-tested-assertations="following-sibling::ol/li[4]/ol/li[3] following-sibling::ol/li[4]/ol/li[5] following-sibling::ol/li[4]/ol/li[6] following-sibling::ol/li[4]/ol/li[7]/ol/li[3] following-sibling::ol/li[4]/ol/li[7]/ol/li[4] following-sibling::ol/li[5]" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/xmlhttprequest-event-order.js"></script>
<title>XMLHttpRequest: The abort() method: abort and loadend events</title>
</head>
@ -16,18 +17,9 @@
test.step(function()
{
var xhr = new XMLHttpRequest();
var expect = [1, 4, "upload.abort", "upload.loadend", "abort", "loadend"];
var actual = [];
prepare_xhr_for_event_order_test(xhr);
xhr.onreadystatechange = function()
{
test.step(function()
{
actual.push(xhr.readyState);
});
};
xhr.onloadstart = function()
{
xhr.addEventListener("loadstart", function() {
test.step(function()
{
var readyState = xhr.readyState;
@ -35,23 +27,18 @@
{
xhr.abort();
VerifyResult();
}else{
} else {
assert_unreached('Loadstart event should not fire in readyState '+readyState);
}
});
};
xhr.onloadend = function(e){ actual.push(e.type); };
xhr.onabort = function(e){ actual.push(e.type); };
xhr.upload.onloadend = function(e){ actual.push("upload." + e.type); };
xhr.upload.onabort = function(e){ actual.push("upload." + e.type); };
});
function VerifyResult()
{
test.step(function()
{
assert_array_equals(actual, expect);
assert_xhr_event_order_matches([1, "loadstart(0,0,false)", 4, "upload.progress(0,0,false)", "upload.abort(0,0,false)", "upload.loadend(0,0,false)", "progress(0,0,false)", "abort(0,0,false)", "loadend(0,0,false)"]);
assert_equals(xhr.readyState, 0, 'state should be UNSENT');
test.done();
});

View file

@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<meta name="assert" content="Check the order of events fired when the request has failed.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/xmlhttprequest-event-order.js"></script>
<title>XMLHttpRequest: event - error (order of events)</title>
</head>
<body>
<div id="log"></div>
<script type="text/javascript">
var test = async_test();
test.step(function()
{
var xhr = new XMLHttpRequest();
prepare_xhr_for_event_order_test(xhr);
xhr.addEventListener("loadend", function() {
test.step(function() {
// no progress events due to CORS failure
assert_xhr_event_order_matches([1, "loadstart(0,0,false)", "upload.loadstart(0,12,true)", 2, 4, "upload.error(0,0,false)", "upload.loadend(0,0,false)", "error(0,0,false)", "loadend(0,0,false)"]);
test.done();
});
});
xhr.open("POST", "http://nonexistent-origin.{{host}}:{{ports[http][0]}}", true);
xhr.send("Test Message");
});
</script>
</body>
</html>

View file

@ -18,7 +18,7 @@ async_test(function (t) {
t.done();
});
client.open("GET", "http://example.nonexist");
client.open("GET", "http://nonexistent-origin.{{host}}:{{ports[http][0]}}");
client.send("null");
}, document.title);

View file

@ -0,0 +1,25 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>XMLHttpRequest Test: event - error</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<meta name="assert" content="Check if event onerror is fired When the request has failed.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
async_test(function (t) {
var client = new XMLHttpRequest();
client.onerror = t.step_func(function(e) {
assert_true(e instanceof ProgressEvent);
assert_equals(e.type, "error");
t.done();
});
client.open("GET", "http://nonexistent-origin.{{host}}:{{ports[http][0]}}");
client.send("null");
}, document.title);
</script>

View file

@ -23,7 +23,7 @@
if (client.readyState === 4)
assert_unreached("onprogress not called.");
});
client.open("GET", "resources/trickle.py");
client.open("GET", "resources/trickle.py?count=4&delay=150");
client.send(null);
});
</script>

View file

@ -0,0 +1,37 @@
<!DOCTYPE html>
<html>
<head>
<meta name="assert" content="Check the order of events fired when the request has failed.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/xmlhttprequest-event-order.js"></script>
<title>XMLHttpRequest: event - timeout (order of events)</title>
</head>
<body>
<div id="log"></div>
<script type="text/javascript">
var test = async_test();
test.step(function()
{
var xhr = new XMLHttpRequest();
prepare_xhr_for_event_order_test(xhr);
xhr.addEventListener("loadend", function() {
test.step(function() {
assert_xhr_event_order_matches([1, "loadstart(0,0,false)", "upload.loadstart(0,12,true)", 4, "upload.progress(0,0,false)", "upload.timeout(0,0,false)", "upload.loadend(0,0,false)", "progress(0,0,false)", "timeout(0,0,false)", "loadend(0,0,false)"]);
test.done();
});
});
xhr.timeout = 5;
xhr.open("POST", "resources/delay.py?ms=20000");
xhr.send("Test Message");
setTimeout(test.step_func(function () {
assert_unreached("ontimeout not called.");
}), 10);
});
</script>
</body>
</html>

View file

@ -10,6 +10,7 @@
<link rel="help" href="https://xhr.spec.whatwg.org/#dom-xmlhttprequest-upload" data-tested-assertations=".." />
<div id="log"></div>
<script src="/common/get-host-info.sub.js"></script>
<script>
var test = async_test();
test.step(function() {
@ -20,7 +21,7 @@
client.onload = test.step_func(function() {
assert_unreached("onprogress not called.");
});
client.open("POST", "http://{{domains[www2]}}:{{ports[http][0]}}/XMLHttpRequest/resources/corsenabled.py");
client.open("POST", get_host_info().HTTP_REMOTE_ORIGIN + "/XMLHttpRequest/resources/corsenabled.py");
client.send("This is a test string.");
});
</script>

View file

@ -0,0 +1,42 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Whitespace and null in header values</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=support.js?pipe=sub></script>
<h1>Whitespace and null in response header values</h1>
<div id=log></div>
<script>
function matchHeaderValue(val) {
test(function () {
var client = new XMLHttpRequest();
var trimmed = val.trim();
client.open("GET", "resources/parse-headers.py?my-custom-header="+encodeURIComponent(val), false);
client.send();
var r = client.getResponseHeader("My-Custom-Header");
assert_equals(r, trimmed);
}, "Header value: " + val.replace(/\t/g, "[tab]").replace(/ /g, "_").replace("\0", "\\0"));
}
matchHeaderValue("hello world\0");
matchHeaderValue("\0hello world");
matchHeaderValue("hello\0world");
matchHeaderValue(" hello world");
matchHeaderValue("hello world ");
matchHeaderValue(" hello world ");
matchHeaderValue("\thello world");
matchHeaderValue("hello world\t");
matchHeaderValue("\thello world\t");
matchHeaderValue("hello world");
matchHeaderValue("hello\tworld");
matchHeaderValue("\0");
matchHeaderValue(" ");
matchHeaderValue("\t");
matchHeaderValue("");
</script>

View file

@ -15,9 +15,10 @@
var client = new self[0].XMLHttpRequest()
client.onreadystatechange = function() {
test.step(function() {
if(client.readyState == 4)
if(client.readyState == 4) {
assert_equals(client.responseText, "bottom\n")
test.done()
}
})
}
client.open("GET", "folder.txt")

View file

@ -4,4 +4,4 @@ def main(request, response):
srcmoddt = datetime.datetime.fromtimestamp(os.path.getmtime(srcpath))
response.headers.set("Last-Modified", srcmoddt.strftime("%a, %d %b %Y %H:%M:%S GMT"))
response.headers.set("Content-Type", "application/xml")
return open(srcpath).read()
return open(srcpath, "r").read()

View file

@ -0,0 +1,10 @@
import json
def main(request, response):
content = ""
if "my-custom-header" in request.GET:
val = request.GET.first("my-custom-header")
response.headers.set("My-Custom-Header", val)
return content

View file

@ -1,12 +1,15 @@
import time
def main(request, response):
chunk = "TEST_TRICKLE\n"
delay = float(request.GET.first("ms", 500)) / 1E3
count = int(request.GET.first("count", 50))
if "specifylength" in request.GET:
response.headers.set("Content-Length", count * len(chunk))
time.sleep(delay)
response.headers.set("Content-type", "text/plain")
response.write_status_headers()
time.sleep(delay);
for i in xrange(count):
response.writer.write_content("TEST_TRICKLE\n")
response.writer.write_content(chunk)
time.sleep(delay)

View file

@ -0,0 +1,33 @@
(function(global) {
var recorded_xhr_events = [];
function record_xhr_event(e) {
var prefix = e.target instanceof XMLHttpRequestUpload ? "upload." : "";
recorded_xhr_events.push((prefix || "") + e.type + "(" + e.loaded + "," + e.total + "," + e.lengthComputable + ")");
}
global.prepare_xhr_for_event_order_test = function(xhr) {
xhr.addEventListener("readystatechange", function(e) {
recorded_xhr_events.push(xhr.readyState);
});
var events = ["loadstart", "progress", "abort", "timeout", "error", "load", "loadend"];
for(var i=0; i<events.length; ++i) {
xhr.addEventListener(events[i], record_xhr_event);
}
if ("upload" in xhr) {
for(var i=0; i<events.length; ++i) {
xhr.upload.addEventListener(events[i], record_xhr_event);
}
}
}
global.assert_xhr_event_order_matches = function(expected) {
try {
assert_array_equals(recorded_xhr_events, expected);
} catch(e) {
e.message += "\nRecorded events were:" + recorded_xhr_events.join(", ");
e.message += "\nExpected events were:" + expected.join(", ");
throw e;
}
}
}(this));

View file

@ -15,18 +15,18 @@
<script>
var test = async_test();
test.step(function() {
function doTest(test, expectedLengthComputable, expectedTotal, url) {
var client = new XMLHttpRequest();
var lastSize = 0;
client.onprogress = test.step_func(function() {
client.onprogress = test.step_func(function(e) {
assert_equals(e.total, expectedTotal);
assert_equals(e.lengthComputable, expectedLengthComputable);
var currentSize = client.responseText.length;
if (lastSize > 0 && currentSize > lastSize) {
// growth from a positive size to bigger!
test.done();
}
@ -39,7 +39,13 @@ test.step(function() {
}
});
client.open("GET", "resources/trickle.py?count=1000");
client.open("GET", url);
client.send(null);
});
return client;
}
async_test(function () { doTest(this, false, 0, "resources/trickle.py?count=6&delay=150"); },
document.title + ', unknown content-length');
async_test(function () { doTest(this, true, 78, "resources/trickle.py?count=6&delay=150&specifylength=1"); },
document.title + ', known content-length');
</script>

View file

@ -19,7 +19,7 @@
assert_equals(client.responseXML.documentElement.localName, "html", 'localName is html')
assert_equals(client.responseXML.documentElement.childNodes.length, 5, 'childNodes is 5')
assert_equals(client.responseXML.getElementById("n1").localName, client.responseXML.documentElement.childNodes[1].localName)
assert_equals(client.responseXML.getElementById("n2"), null, 'getElementById("n2")')
assert_equals(client.responseXML.getElementById("n2"), client.responseXML.documentElement.childrenNodes[3], 'getElementById("n2")')
assert_equals(client.responseXML.getElementsByTagName("p")[1].namespaceURI, "namespacesarejuststrings", 'namespaceURI')
})
test(function() {

View file

@ -45,7 +45,7 @@
test(function() {
var lastModified = Math.floor(new Date(client.responseXML.lastModified).getTime() / 1000);
var now = Math.floor(new Date().getTime() / 1000);
var now = Math.floor(new Date().getTime(new Date().getTime() + 2000) / 1000); // two seconds from now, in case there's clock drift
assert_greater_than_equal(lastModified, timePreXHR);
assert_less_than_equal(lastModified, now);
}, 'lastModified set to time of response if no HTTP header provided')

View file

@ -21,7 +21,13 @@
assert_false(pe.lengthComputable, "lengthComputable is false.");
assert_equals(pe.total, 0, "total is zero.");
});
xhr.onloadend = this.step_func_done();
xhr.onloadend = this.step_func(function(pe) {
assert_equals(pe.type, "loadend");
assert_equals(pe.loaded, 0, "loaded is zero.");
assert_false(pe.lengthComputable, "lengthComputable is false.");
assert_equals(pe.total, 0, "total is zero.");
this.done();
});
xhr.open("GET", "http://{{host}}:{{ports[http][1]}}/XMLHttpRequest/resources/img.jpg", true);
xhr.send(null);
})

View file

@ -10,13 +10,17 @@
<body>
<div id="log"></div>
<script>
test(function() {
function request(method) {
var client = new XMLHttpRequest()
client.open("POST", "resources/content.py", false)
client.open(method, "resources/content.py", false)
client.upload.onloadstart = function(){assert_unreached('this event should not fire for empty strings')}
client.send("")
assert_equals(client.getResponseHeader("x-request-content-length"), "0")
})
var expectedLength = method == "HEAD" ? "NO" : "0";
assert_equals(client.getResponseHeader("x-request-content-length"), expectedLength)
}
test(function() { request("POST"); }, document.title + " (POST)");
test(function() { request("PUT"); }, document.title + " (PUT)");
test(function() { request("HEAD"); }, document.title + " (HEAD)");
</script>
</body>
</html>

View file

@ -23,13 +23,7 @@
client.upload.addEventListener('loadstart', logEvt)
client.addEventListener('loadend', function(){
test.step(function(){
if (method === "HEAD") {
// Fetch 4.4.3 --- Set Content-Length to 0 if method is HEAD and
// request's body is null.
assert_equals(client.getResponseHeader("x-request-content-length"), "0")
} else {
assert_equals(client.getResponseHeader("x-request-content-length"), "NO")
}
assert_equals(client.getResponseHeader("x-request-content-length"), "NO")
assert_equals(client.getResponseHeader("x-request-method"), method)
assert_equals(client.responseText, "")
assert_array_equals(events, [])

View file

@ -23,13 +23,7 @@
client.upload.addEventListener('loadend', logEvt)
client.upload.addEventListener('loadstart', logEvt)
if (method === "HEAD") {
// Fetch 4.4.3 --- Set Content-Length to 0 if method is HEAD and
// request's body is null.
assert_equals(client.getResponseHeader("x-request-content-length"), "0")
} else {
assert_equals(client.getResponseHeader("x-request-content-length"), "NO")
}
assert_equals(client.getResponseHeader("x-request-content-length"), "NO")
assert_equals(client.getResponseHeader("x-request-method"), method)
assert_equals(client.responseText, "")
assert_array_equals(events, [])

View file

@ -9,24 +9,32 @@
<body>
<div id="log"></div>
<script>
test(function() {
function noContentTypeTest(method) {
var client = new XMLHttpRequest()
client.open("POST", "resources/content.py", false)
client.open(method, "resources/content.py", false)
client.upload.onloadstart = function(){assert_unreached('this event should not fire for null')}
client.send(null)
assert_equals(client.getResponseHeader("x-request-content-length"), "0")
var expectedLength = method == "HEAD" ? "NO" : "0";
assert_equals(client.getResponseHeader("x-request-content-length"), expectedLength)
assert_equals(client.getResponseHeader("x-request-content-type"), "NO")
}, "No content type")
}
test(function() { noContentTypeTest("POST"); }, "No content type (POST)");
test(function() { noContentTypeTest("PUT"); }, "No content type (PUT)");
test(function() { noContentTypeTest("HEAD"); }, "No content type (HEAD)");
test(function() {
function explicitContentTypeTest(method) {
var client = new XMLHttpRequest()
client.open("POST", "resources/content.py", false)
client.open(method, "resources/content.py", false)
var content_type = 'application/x-foo'
client.setRequestHeader('Content-Type', content_type)
client.send(null)
assert_equals(client.getResponseHeader("x-request-content-length"), "0")
var expectedLength = method == "HEAD" ? "NO" : "0";
assert_equals(client.getResponseHeader("x-request-content-length"), expectedLength)
assert_equals(client.getResponseHeader("x-request-content-type"), content_type)
}, "Explicit content type")
}
test(function() { explicitContentTypeTest("POST"); }, "Explicit content type (POST)");
test(function() { explicitContentTypeTest("PUT"); }, "Explicit content type (PUT)");
test(function() { explicitContentTypeTest("HEAD"); }, "Explicit content type (HEAD)");
</script>
</body>
</html>

View file

@ -11,6 +11,7 @@
<link rel="help" href="https://xhr.spec.whatwg.org/#the-response-attribute" data-tested-assertations="following-sibling::ol/li[1]" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/xmlhttprequest-event-order.js"></script>
<title>XMLHttpRequest: The send() method: event order when there is no response entity body</title>
</head>
@ -23,35 +24,18 @@
test.step(function()
{
var xhr = new XMLHttpRequest();
var expect = ["loadstart", 4, "load", "loadend"];
var actual = [];
prepare_xhr_for_event_order_test(xhr);
xhr.onreadystatechange = test.step_func(function()
{
test.step(function()
{
if (xhr.readyState == 3)
{
assert_equals(xhr.response, "");
}
else if (xhr.readyState == 4)
{
actual.push(xhr.readyState);
}
});
});
xhr.addEventListener("readystatechange", test.step_func(function() {
if (xhr.readyState == 3) {
assert_equals(xhr.response, "");
}
}));
xhr.onloadstart = test.step_func(function(e){ actual.push(e.type); });
xhr.onload = test.step_func(function(e){ actual.push(e.type); });
xhr.onloadend = test.step_func(function(e){
actual.push(e.type);
assert_array_equals(actual, expect);
xhr.addEventListener("loadend", test.step_func(function(e) {
assert_xhr_event_order_matches([1, "loadstart(0,0,false)", 2, "progress(0,0,false)", 4,"load(0,0,false)", "loadend(0,0,false)"]);
test.done();
});
xhr.upload.onloadstart = test.step_func(function(e){ assert_unreached('upload.'+e.type); });
xhr.upload.onload = test.step_func(function(e){ assert_unreached('upload.'+e.type); });
xhr.upload.onloadend = test.step_func(function(e){ assert_unreached('upload.'+e.type); });
}));
xhr.open("POST", "./resources/content.py", true);
xhr.send();

View file

@ -4,13 +4,18 @@
<title>XMLHttpRequest: send() - non same-origin</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<base href="http://{{domains[www2]}}:{{ports[http][0]}}">
<base>
<link rel="help" href="https://xhr.spec.whatwg.org/#cross-origin-request-steps" data-tested-assertations="/following::DL[2]/DT[1] /following::DL[2]/DD[1]" />
<link rel="help" href="https://xhr.spec.whatwg.org/#cross-origin-request-event-rules" data-tested-assertations="/following::DL[1]/DT[2] /following::DL[1]/DD[2]" />
</head>
<body>
<div id="log"></div>
<script src="/common/get-host-info.sub.js"></script>
<script>
// Setting base URL before running the tests
var host_info = get_host_info();
document.getElementsByTagName("base")[0].setAttribute("href", host_info.HTTP_REMOTE_ORIGIN);
function url(url) {
test(function() {
var client = new XMLHttpRequest()
@ -20,7 +25,7 @@
}
url("mailto:test@example.org")
url("tel:+31600000000")
url("http://{{domains[www2]}}:{{ports[http][0]}}/")
url(host_info.HTTP_REMOTE_ORIGIN)
url("javascript:alert('FAIL')")
url("folder.txt")
</script>

View file

@ -3,6 +3,7 @@
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/xmlhttprequest-event-order.js"></script>
<title>XMLHttpRequest: The send() method: event order when synchronous flag is set</title>
<link rel="help" href="https://xhr.spec.whatwg.org/#handler-xhr-onloadstart" data-tested-assertations="../.." />
<link rel="help" href="https://xhr.spec.whatwg.org/#handler-xhr-onloadend" data-tested-assertations="../.." />
@ -21,30 +22,13 @@
<script type="text/javascript">
test(function () {
var xhr = new XMLHttpRequest();
var expect = [4, "load", "loadend"];
var actual = [];
xhr.onreadystatechange = function()
{
if (xhr.readyState == 4)
{
actual.push(xhr.readyState);
}
};
xhr.onloadstart = function(e){ actual.push(e.type); };
xhr.onload = function(e){ actual.push(e.type); };
xhr.onloadend = function(e){ actual.push(e.type); };
xhr.upload.onload = function(e){ actual.push("upload." + e.type); };
xhr.upload.onloadstart = function(e){ actual.push("upload." + e.type); };
xhr.upload.onloadend = function(e){ actual.push("upload." + e.type);};
prepare_xhr_for_event_order_test(xhr);
xhr.open("POST", "./resources/content.py", false);
xhr.send("Test Message");
assert_equals(xhr.response, "Test Message");
assert_array_equals(actual, expect);
assert_xhr_event_order_matches([1, 4, "load(12,12,true)", "loadend(12,12,true)"]);
});
</script>
</body>

View file

@ -9,19 +9,229 @@
<body>
<div id="log"></div>
<script>
function request(value) {
function request(inputGenerator, headersToSend, expectedType, title) {
test(function() {
try {
var toSend = inputGenerator();
} catch(e) {
assert_unreached("Skipping test as could not create a " + inputGenerator.name.replace("_", "") + "; ");
}
var client = new XMLHttpRequest()
client.open("POST", "resources/inspect-headers.py?filter_name=Content-Type", false)
client.setRequestHeader('Content-Type', value)
client.send("")
assert_equals(client.responseText, 'content-type: '+ String(value ? value.trim() : value).toLowerCase()+'\n' )
}, document.title + " (" + value + ")")
for(header in headersToSend) {
if (headersToSend.hasOwnProperty(header)) {
client.setRequestHeader(header, headersToSend[header]);
}
}
client.send(toSend)
var responseType = client.responseText.replace("\n", "").replace("; ", ";").toLowerCase(); // don't care about case or space after semicolon for charset
if (expectedType === undefined || expectedType === null) {
assert_equals(responseType, "");
} else if (expectedType instanceof RegExp) {
if (!expectedType.ignoreCase) expectedType = new RegExp(expectedType, "i"); // always ignore case; the regex itself will have to remember to handle the optional space after the semicolon for charset
assert_regexp_match(responseType, expectedType);
} else {
expectedType = "content-type: " + String(expectedType ? expectedType.trim().replace("; ", ";") : expectedType).toLowerCase()
assert_equals(responseType, expectedType);
}
}, title)
}
request("")
request(" ")
request(null)
request(undefined)
request(
function _String() { return ""; },
{"Content-Type": ""},
"",
'setRequestHeader("") sends a blank string'
)
request(
function _String() { return ""; },
{"Content-Type": " "},
" ",
'setRequestHeader(" ") sends the string " "'
)
request(
function _String() { return ""; },
{"Content-Type": null},
"null",
'setRequestHeader(null) sends the string "null"'
)
request(
function _String() { return ""; },
{"Content-Type": undefined},
"undefined",
'setRequestHeader(undefined) sends the string "undefined"'
)
request(
function _String() { return "test"; },
{},
"text/plain;charset=UTF-8",
'String request has correct default Content-Type of "text/plain;charset=UTF-8"'
)
request(
function _String() { return "test()"; },
{"Content-Type": "text/javascript;charset=ASCII"},
"text/javascript;charset=UTF-8",
"String request keeps setRequestHeader() Content-Type, with charset adjusted to UTF-8"
)
request(
function _XMLDocument() { return new DOMParser().parseFromString("<xml/>", "application/xml"); },
{"Content-Type": ""},
"",
'XML Document request respects setRequestHeader("")'
)
request(
function _XMLDocument() { return new DOMParser().parseFromString("<xml/>", "application/xml"); },
{},
"application/xml;charset=UTF-8",
'XML Document request has correct default Content-Type of "application/xml;charset=UTF-8"'
)
request(
function _XMLDocument() { return new DOMParser().parseFromString("<xml/>", "application/xml"); },
{"Content-Type": "application/xhtml+xml;charset=ASCII"},
"application/xhtml+xml;charset=UTF-8",
"XML Document request keeps setRequestHeader() Content-Type, with charset adjusted to UTF-8"
)
request(
function _HTMLDocument() { return new DOMParser().parseFromString("<html></html>", "text/html"); },
{"Content-Type": ""},
"",
'HTML Document request respects setRequestHeader("")'
)
request(
function _HTMLDocument() { return new DOMParser().parseFromString("<html></html>", "text/html"); },
{},
"text/html;charset=UTF-8",
'HTML Document request has correct default Content-Type of "text/html;charset=UTF-8"'
)
request(
function _HTMLDocument() { return new DOMParser().parseFromString("<html></html>", "text/html"); },
{"Content-Type": "text/html+junk;charset=ASCII"},
"text/html+junk;charset=UTF-8",
"HTML Document request keeps setRequestHeader() Content-Type, with charset adjusted to UTF-8"
)
request(
function _Blob() { return new Blob(["test"]); },
{"Content-Type": ""},
"",
'Blob request respects setRequestHeader("") to be specified'
)
request(
function _Blob() { return new Blob(["test"]); },
{},
undefined,
"Blob request with unset type sends no Content-Type without setRequestHeader() call"
)
request(
function _Blob() { return new Blob(["test"]); },
{"Content-Type": "application/xml;charset=ASCII"},
"application/xml;charset=ASCII",
"Blob request with unset type keeps setRequestHeader() Content-Type and charset"
)
request(
function _Blob() { return new Blob(["<xml/>"], {type : "application/xml;charset=ASCII"}); },
{},
"application/xml;charset=ASCII",
"Blob request with set type uses that it for Content-Type unless setRequestHeader()"
)
request(
function _Blob() { return new Blob(["<xml/>"], {type : "application/xml;charset=UTF8"}); },
{"Content-Type": "application/xml+junk;charset=ASCII"},
"application/xml+junk;charset=ASCII",
"Blob request with set type keeps setRequestHeader() Content-Type and charset"
)
request(
function _ArrayBuffer() { return new ArrayBuffer(10); },
{"Content-Type": ""},
"",
'ArrayBuffer request respects setRequestHeader("")'
)
request(
function _ArrayBuffer() { return new ArrayBuffer(10); },
{},
undefined,
"ArrayBuffer request sends no Content-Type without setRequestHeader() call"
)
request(
function _ArrayBuffer() { return new ArrayBuffer(10); },
{"Content-Type": "application/xml;charset=ASCII"},
"application/xml;charset=ASCII",
"ArrayBuffer request keeps setRequestHeader() Content-Type and charset"
)
request(
function _Uint8Array() { return new Uint8Array(new ArrayBuffer(10)); },
{"Content-Type": ""},
"",
'ArrayBufferView request respects setRequestHeader("")'
)
request(
function _Uint8Array() { return new Uint8Array(new ArrayBuffer(10)); },
{},
undefined,
"ArrayBufferView request sends no Content-Type without setRequestHeader() call"
)
request(
function _Uint8Array() { return new Uint8Array(new ArrayBuffer(10)); },
{"Content-Type": "application/xml;charset=ASCII"},
"application/xml;charset=ASCII",
"ArrayBufferView request keeps setRequestHeader() Content-Type and charset"
)
request(
function _FormData() { return new FormData(); },
{"Content-Type": ""},
"",
'FormData request respects setRequestHeader("")'
)
request(
function _FormData() { return new FormData(); },
{},
/multipart\/form-data;boundary=(.*)/,
'FormData request has correct default Content-Type of "multipart\/form-data;boundary=_"'
)
request(
function _FormData() { return new FormData(); },
{"Content-Type": "application/xml;charset=ASCII"},
"application/xml;charset=ASCII",
"FormData request keeps setRequestHeader() Content-Type and charset"
)
request(
function _URLSearchParams() { return new URLSearchParams("q=testQ&topic=testTopic") },
{"Content-Type": ""},
"",
'URLSearchParams respects setRequestHeader("")'
)
request(
function _URLSearchParams() { return new URLSearchParams("q=testQ&topic=testTopic") },
{},
"application/x-www-form-urlencoded;charset=UTF-8",
'URLSearchParams request has correct default Content-Type of "application/x-www-form-urlencoded;charset=UTF-8"'
)
request(
function _URLSearchParams() { return new URLSearchParams("q=testQ&topic=testTopic") },
{"Content-Type": "application/xml;charset=ASCII"},
"application/xml;charset=UTF-8",
"URLSearchParams request keeps setRequestHeader() Content-Type, with charset adjusted to UTF-8"
// the default Content-Type for URLSearchParams has a charset specified (utf-8) in
// https://fetch.spec.whatwg.org/#bodyinit, so the user's must be changed to match it
// as per https://xhr.spec.whatwg.org/#the-send%28%29-method step 4.
)
request(
function _ReadableStream() { return new ReadableStream() },
{"Content-Type": ""},
"",
'ReadableStream request respects setRequestHeader("")'
)
request(
function _ReadableStream() { return new ReadableStream() },
{},
undefined,
"ReadableStream request with under type sends no Content-Type without setRequestHeader() call"
)
request(
function _ReadableStream() { return new ReadableStream() },
{"Content-Type": "application/xml;charset=ASCII"},
"application/xml;charset=ASCII",
"ReadableStream request keeps setRequestHeader() Content-Type and charset"
)
</script>
</body>
</html>