mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Update web-platform-tests to revision 0d318188757a9c996e20b82db201fd04de5aa255
This commit is contained in:
parent
b2a5225831
commit
1a81b18b9f
12321 changed files with 544385 additions and 6 deletions
|
@ -0,0 +1,28 @@
|
|||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
<title>FormData.append</title>
|
||||
<link rel=help href=https://xhr.spec.whatwg.org/#dom-formdata-append>
|
||||
<script src=/resources/testharness.js></script>
|
||||
<script src=/resources/testharnessreport.js></script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
function test_formdata(creator, verifier, description) {
|
||||
async_test(description).step(function() {
|
||||
var fd = creator();
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onload = this.step_func(function() {
|
||||
verifier(xhr.responseText);
|
||||
this.done();
|
||||
});
|
||||
xhr.open("POST", "resources/upload.py");
|
||||
xhr.send(fd);
|
||||
})
|
||||
}
|
||||
test_formdata(function() {
|
||||
var fd = new FormData();
|
||||
fd.append("name", new String("value"));
|
||||
return fd;
|
||||
}, function(data) {
|
||||
assert_equals(data, "name=value,\n");
|
||||
}, "Passing a String object to FormData.append should work.");
|
||||
</script>
|
|
@ -0,0 +1,14 @@
|
|||
<!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>
|
||||
setup({ explicit_done: true })
|
||||
test_withCredentials(false)
|
||||
</script>
|
|
@ -0,0 +1,43 @@
|
|||
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)
|
||||
if (worker) {
|
||||
client.withCredentials = true
|
||||
assert_true(client.withCredentials, "set in OPEN state")
|
||||
} else {
|
||||
assert_throws("InvalidAccessError", function() {
|
||||
client.withCredentials = true
|
||||
})
|
||||
assert_false(client.withCredentials, "set in OPEN state")
|
||||
}
|
||||
}, "setting on synchronous XHR")
|
||||
|
||||
async_test("setting withCredentials when not in UNSENT, OPENED state").step(function() {
|
||||
this.add_cleanup(done)
|
||||
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()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
importScripts("/resources/testharness.js")
|
||||
importScripts("XMLHttpRequest-withCredentials.js")
|
||||
test_withCredentials(true);
|
|
@ -0,0 +1,42 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: abort() after successful receive should not fire "abort" event</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-abort()-method" data-tested-assertations="following::ol[1]/li[4] following::ol[1]/li[5]"/>
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test();
|
||||
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest();
|
||||
|
||||
client.onreadystatechange = test.step_func(function() {
|
||||
if (client.readyState == 4) {
|
||||
// abort should not cause the "abort" event to fire
|
||||
|
||||
client.abort();
|
||||
|
||||
assert_equals(client.readyState, 0);
|
||||
|
||||
setTimeout(function(){ // use a timeout to catch any implementation that might queue an abort event for later - just in case
|
||||
test.step(function(){test.done();});
|
||||
}, 200);
|
||||
}
|
||||
});
|
||||
|
||||
client.onabort = test.step_func(function () {
|
||||
// this should not fire!
|
||||
|
||||
assert_unreached("abort() should not cause the abort event to fire");
|
||||
});
|
||||
|
||||
client.open("GET", "resources/well-formed.xml", true);
|
||||
client.send(null);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,55 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: abort() after send()</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-abort()-method" data-tested-assertations="following-sibling::ol/li[1] following-sibling::ol/li[3] following-sibling::ol/li[4] following-sibling::ol/li[4]/ol/li[1] following-sibling::ol/li[4]/ol/li[3] following-sibling::ol/li[4]/ol/li[4] following-sibling::ol/li[4]/ol/li[5] following-sibling::ol/li[4]/ol/li[6] following-sibling::ol/li[5]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-responsetext-attribute" data-tested-assertations="following::ol/li[3]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-responsexml-attribute" data-tested-assertations="following::ol/li[3]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#dom-xmlhttprequest-getallresponseheaders" data-tested-assertations="following::ol/li[2]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#dom-xmlhttprequest-getresponseheader" data-tested-assertations="following::ol/li[2]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-status-attribute" data-tested-assertations="following::ol/li[2]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-statustext-attribute" data-tested-assertations="following::ol/li[2]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#infrastructure-for-the-send()-method" data-tested-assertations="following::dt[1] following::dd[1]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test()
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest(),
|
||||
control_flag = false,
|
||||
result = [],
|
||||
expected = [1, 4, 'progress', 'abort', 'loadend'] // open() -> 1, abort() -> 4
|
||||
client.onreadystatechange = function() {
|
||||
test.step(function() {
|
||||
result.push(client.readyState)
|
||||
if(client.readyState == 4) {
|
||||
control_flag = true
|
||||
assert_equals(client.responseXML, null)
|
||||
assert_equals(client.responseText, "")
|
||||
assert_equals(client.status, 0)
|
||||
assert_equals(client.statusText, "")
|
||||
assert_equals(client.getAllResponseHeaders(), "")
|
||||
assert_equals(client.getResponseHeader('Content-Type'), null)
|
||||
}
|
||||
})
|
||||
}
|
||||
client.open("GET", "resources/well-formed.xml", true)
|
||||
client.send(null)
|
||||
client.addEventListener('progress', logEvt)
|
||||
client.addEventListener('abort', logEvt)
|
||||
client.addEventListener('loadend', logEvt)
|
||||
client.abort()
|
||||
assert_true(control_flag)
|
||||
assert_equals(client.readyState, 0)
|
||||
assert_array_equals(result, expected)
|
||||
test.done()
|
||||
function logEvt (e) {
|
||||
result.push(e.type)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,32 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: abort event should fire when stop() method is used</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#infrastructure-for-the-send()-method" data-tested-assertations="following::dt[3] following::dt[3]/following::dd[1]/p"/>
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test();
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest();
|
||||
var abortFired = false;
|
||||
client.onabort = test.step_func(function (e) {
|
||||
assert_equals(e.type, 'abort');
|
||||
abortFired = true;
|
||||
});
|
||||
client.open("GET", "resources/delay.py?ms=3000", true);
|
||||
client.send(null);
|
||||
setTimeout(function(){
|
||||
test.step(function(){
|
||||
assert_equals(abortFired, true);
|
||||
test.done();
|
||||
});
|
||||
}, 200);
|
||||
window.stop();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,58 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: abort() after a timeout should not fire "abort" event</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-abort()-method" data-tested-assertations="following::ol[1]/li[4] following::ol[1]/li[5]"/>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-timeout-attribute" data-tested-assertations="following::ol[1]/li[2]"/>
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test();
|
||||
|
||||
test.step(function() {
|
||||
// timeout is 100ms
|
||||
// the download would otherwise take 1000ms
|
||||
// we check after 300ms to make sure abort does not fire an "abort" event
|
||||
|
||||
var timeoutFired = false;
|
||||
|
||||
var client = new XMLHttpRequest();
|
||||
|
||||
assert_true('timeout' in client, 'xhr.timeout is not supported in this user agent');
|
||||
|
||||
client.timeout = 100;
|
||||
|
||||
setTimeout(test.step_func(function() {
|
||||
assert_true(timeoutFired);
|
||||
|
||||
// abort should not cause the "abort" event to fire
|
||||
client.abort();
|
||||
|
||||
setTimeout(function(){ // use a timeout to catch any implementation that might queue an abort event for later - just in case
|
||||
test.step(function(){test.done();});
|
||||
}, 200);
|
||||
|
||||
assert_equals(client.readyState, 0);
|
||||
|
||||
test.done();
|
||||
}), 300);
|
||||
|
||||
client.ontimeout = function () {
|
||||
timeoutFired = true;
|
||||
};
|
||||
|
||||
client.onabort = test.step_func(function () {
|
||||
// this should not fire!
|
||||
|
||||
assert_unreached("abort() should not cause the abort event to fire");
|
||||
});
|
||||
|
||||
client.open("GET", "/common/blank.html?pipe=trickle(d1)", true);
|
||||
client.send(null);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,32 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: abort() during DONE</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-abort()-method" data-tested-assertations="following-sibling::ol/li[4] following-sibling::ol/li[5]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test()
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest(),
|
||||
result = [],
|
||||
expected = [1, 4] // open() -> 1, send() -> 4
|
||||
client.onreadystatechange = function() {
|
||||
test.step(function() {
|
||||
result.push(client.readyState)
|
||||
})
|
||||
}
|
||||
client.open("GET", "resources/well-formed.xml", false)
|
||||
client.send(null)
|
||||
assert_equals(client.readyState, 4)
|
||||
client.abort()
|
||||
assert_equals(client.readyState, 0)
|
||||
assert_array_equals(result, expected)
|
||||
test.done()
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,29 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: abort() during OPEN</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-abort()-method" data-tested-assertations="following-sibling::ol/li[4] following-sibling::ol/li[5]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-send()-method" data-tested-assertations="following-sibling::ol/li[1]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test()
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
client.open("GET", "...")
|
||||
client.onreadystatechange = function() {
|
||||
test.step(function() {
|
||||
assert_unreached()
|
||||
})
|
||||
}
|
||||
client.abort()
|
||||
assert_equals(client.readyState, 0)
|
||||
assert_throws("InvalidStateError", function() { client.send("test") }, "calling send() after abort()")
|
||||
})
|
||||
test.done()
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,26 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: abort() during UNSENT</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-abort()-method" data-tested-assertations="following-sibling::ol/li[4] following-sibling::ol/li[5]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test()
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
client.onreadystatechange = function() {
|
||||
test.step(function() {
|
||||
assert_unreached()
|
||||
})
|
||||
}
|
||||
client.abort()
|
||||
assert_equals(client.readyState, 0)
|
||||
})
|
||||
test.done()
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,42 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: abort() while sending data</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.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>
|
||||
<body>
|
||||
<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()
|
||||
client.open("POST", "resources/delay.py?ms=1000")
|
||||
client.addEventListener('progress', logEvt)
|
||||
client.addEventListener('abort', logEvt)
|
||||
client.addEventListener('loadend', function (e) {
|
||||
logEvt(e)
|
||||
test.step(function() {
|
||||
assert_equals(client.readyState, 4)
|
||||
assert_array_equals(result, expected)
|
||||
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()
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,45 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-abort()-method" data-tested-assertations="following-sibling::ol/li[4]/ol/li[5]" />
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<title>XMLHttpRequest: The abort() method: do not fire abort event in OPENED state when send() flag is unset. send() throws after abort().</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var test = async_test()
|
||||
|
||||
test.step(function()
|
||||
{
|
||||
var xhr = new XMLHttpRequest()
|
||||
|
||||
xhr.onreadystatechange = function()
|
||||
{
|
||||
test.step(function()
|
||||
{
|
||||
if (xhr.readyState == 1)
|
||||
{
|
||||
xhr.abort();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
xhr.onabort = function(e)
|
||||
{
|
||||
test.step(function()
|
||||
{
|
||||
assert_unreached('when abort() is called, state is OPENED with the send() flag being unset, must not fire abort event per spec')
|
||||
});
|
||||
};
|
||||
|
||||
xhr.open("GET", "./resources/content.py", true); // This should cause a readystatechange event that calls abort()
|
||||
assert_throws("InvalidStateError", function(){ xhr.send() })
|
||||
test.done()
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,25 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: abort() should not reset event listeners</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-abort()-method" data-tested-assertations="following-sibling::ol/li[6] following-sibling::ol/li[7]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test()
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest(),
|
||||
test = function() {}
|
||||
client.onreadystatechange = test
|
||||
client.open("GET", "resources/well-formed.xml")
|
||||
client.send(null)
|
||||
client.abort()
|
||||
assert_equals(client.onreadystatechange, test)
|
||||
})
|
||||
test.done()
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,44 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-abort()-method" data-tested-assertations="following-sibling::ol/li[4]/ol/li[6]"/>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<title>XMLHttpRequest: The abort() method: Fire a progress event named loadend</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var test = async_test(function(test)
|
||||
{
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.onloadstart = function()
|
||||
{
|
||||
test.step(function()
|
||||
{
|
||||
if (xhr.readyState == 1)
|
||||
{
|
||||
xhr.abort();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
xhr.onloadend = function(e)
|
||||
{
|
||||
test.step(function()
|
||||
{
|
||||
assert_true(e instanceof ProgressEvent);
|
||||
assert_equals(e.type, "loadend");
|
||||
test.done();
|
||||
});
|
||||
};
|
||||
|
||||
xhr.open("GET", "resources/content.py", true);
|
||||
xhr.send();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,65 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<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>
|
||||
<title>XMLHttpRequest: The abort() method: abort and loadend events</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var test = async_test();
|
||||
|
||||
test.step(function()
|
||||
{
|
||||
var xhr = new XMLHttpRequest();
|
||||
var expect = [1, 4, "upload.abort", "upload.loadend", "abort", "loadend"];
|
||||
var actual = [];
|
||||
|
||||
xhr.onreadystatechange = function()
|
||||
{
|
||||
test.step(function()
|
||||
{
|
||||
actual.push(xhr.readyState);
|
||||
});
|
||||
};
|
||||
xhr.onloadstart = function()
|
||||
{
|
||||
test.step(function()
|
||||
{
|
||||
var readyState = xhr.readyState;
|
||||
if (readyState == 1)
|
||||
{
|
||||
xhr.abort();
|
||||
VerifyResult();
|
||||
}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_equals(xhr.readyState, 0, 'state should be UNSENT');
|
||||
test.done();
|
||||
});
|
||||
};
|
||||
|
||||
xhr.open("POST", "./resources/content.py", true);
|
||||
xhr.send("Test Message");
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,47 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-abort()-method" data-tested-assertations="following-sibling::ol/li[4]/ol/li[7]/ol/li[3]" />
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<title>XMLHttpRequest: The abort() method: Fire a progress event named abort on the XMLHttpRequestUpload object</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var test = async_test();
|
||||
|
||||
test.step(function()
|
||||
{
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.onloadstart = function()
|
||||
{
|
||||
test.step(function()
|
||||
{
|
||||
if (xhr.readyState == 1)
|
||||
{
|
||||
xhr.abort();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
xhr.upload.onabort = function(e)
|
||||
{
|
||||
test.step(function()
|
||||
{
|
||||
assert_true(e instanceof ProgressEvent);
|
||||
assert_equals(e.type, "abort");
|
||||
assert_equals(e.target, xhr.upload);
|
||||
test.done();
|
||||
});
|
||||
};
|
||||
|
||||
xhr.open("POST", "./resources/content.py", true);
|
||||
xhr.send("Test Message");
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,47 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-abort()-method" data-tested-assertations="following-sibling::ol/li[4]/ol/li[7]/ol/li[4]" />
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<title>XMLHttpRequest: The abort() method: Fire a progress event named loadend on the XMLHttpRequestUpload object</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var test = async_test();
|
||||
|
||||
test.step(function()
|
||||
{
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.onloadstart = function()
|
||||
{
|
||||
test.step(function ()
|
||||
{
|
||||
if (xhr.readyState == 1)
|
||||
{
|
||||
xhr.abort();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
xhr.upload.onloadend = function(e)
|
||||
{
|
||||
test.step(function()
|
||||
{
|
||||
assert_true(e instanceof ProgressEvent);
|
||||
assert_equals(e.type, "loadend");
|
||||
assert_equals(e.target, xhr.upload);
|
||||
test.done();
|
||||
});
|
||||
};
|
||||
|
||||
xhr.open("POST", "./resources/content.py", true);
|
||||
xhr.send("Test Message");
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,40 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: anonymous mode unsupported</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
/*
|
||||
Older versions of the XMLHttpRequest spec had an 'anonymous' mode
|
||||
The point of this mode was to handle same-origin requests like other-origin requests,
|
||||
i.e. require preflight, drop authentication data (cookies and HTTP auth)
|
||||
Also the Origin: and Referer: headers would not be sent
|
||||
|
||||
This mode was dropped due to lack of implementations and interest,
|
||||
and this test is here just to assert failure if any implementation
|
||||
supports this based on an older spec version.
|
||||
*/
|
||||
document.cookie = 'test=anonymous-mode-unsupported'
|
||||
test = async_test();
|
||||
test.add_cleanup(function(){
|
||||
// make sure we clean up the cookie again to avoid confusing other tests..
|
||||
document.cookie = 'test=;expires=Fri, 28 Feb 2014 07:25:59 GMT';
|
||||
})
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest({anonymous:true})
|
||||
client.open("GET", "resources/inspect-headers.py?filter_name=cookie")
|
||||
client.onreadystatechange = test.step_func(function(){
|
||||
if(client.readyState === 4){
|
||||
assert_equals(client.responseText, 'cookie: test=anonymous-mode-unsupported\n', 'The deprecated anonymous:true should be ignored, cookie sent anyway')
|
||||
test.done();
|
||||
}
|
||||
});
|
||||
client.send(null)
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
53
tests/wpt/web-platform-tests/XMLHttpRequest/data-uri.htm
Normal file
53
tests/wpt/web-platform-tests/XMLHttpRequest/data-uri.htm
Normal file
|
@ -0,0 +1,53 @@
|
|||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
<title>XMLHttpRequest: data uri</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#data:-urls-and-http" data-tested-assertations="following::ul/li[1] following::ul/li[2] following::ul/li[4]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-send()-method" data-tested-assertations="following::ul/li[10]/dl/dt[2]" />
|
||||
<div id="log"></div>
|
||||
|
||||
<script>
|
||||
function do_test(method, uri, charset, testNamePostfix) {
|
||||
if (typeof charset === 'undefined' || charset === null) charset = 'text/plain';
|
||||
var test = async_test("XHR method " + method + " with charset " + charset+(testNamePostfix||''));
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest();
|
||||
client.onreadystatechange = test.step_func(function () {
|
||||
if (client.readyState !== 4) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Note: fetching a data URL with a non-GET method returns a network
|
||||
// error per <http://fetch.spec.whatwg.org/#basic-fetch>.
|
||||
if (method.toUpperCase() !== 'GET') {
|
||||
assert_equals(client.status, 0);
|
||||
assert_equals(client.responseText, '');
|
||||
assert_equals(client.statusText, 'OK');
|
||||
test.done();
|
||||
return;
|
||||
}
|
||||
|
||||
assert_equals(client.responseText, "Hello, World!");
|
||||
assert_equals(client.status, 200);
|
||||
assert_equals(client.getResponseHeader('Content-Type'), charset);
|
||||
var allHeaders = client.getAllResponseHeaders();
|
||||
assert_regexp_match(allHeaders, /content\-type\:/i, 'getAllResponseHeaders() includes Content-Type');
|
||||
assert_false(/content\-length\:/i.test(allHeaders), 'getAllResponseHeaders() must not include Content-Length');
|
||||
test.done();
|
||||
});
|
||||
client.open(method, uri);
|
||||
client.send(null);
|
||||
});
|
||||
}
|
||||
do_test('GET', "data:text/plain,Hello, World!");
|
||||
do_test('GET', "data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==", undefined, " (base64)");
|
||||
do_test('GET', "data:text/html,Hello, World!", 'text/html');
|
||||
do_test('GET', "data:text/html;charset=UTF-8,Hello, World!", 'text/html;charset=UTF-8');
|
||||
do_test('GET', "data:image/png,Hello, World!", 'image/png');
|
||||
do_test('POST', "data:text/plain,Hello, World!");
|
||||
do_test('PUT', "data:text/plain,Hello, World!");
|
||||
do_test('DELETE', "data:text/plain,Hello, World!");
|
||||
do_test('HEAD', "data:text/plain,Hello, World!");
|
||||
do_test('UNICORN', "data:text/plain,Hello, World!");
|
||||
</script>
|
29
tests/wpt/web-platform-tests/XMLHttpRequest/event-abort.htm
Normal file
29
tests/wpt/web-platform-tests/XMLHttpRequest/event-abort.htm
Normal file
|
@ -0,0 +1,29 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: abort event</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#handler-xhr-onabort" data-tested-assertations="../.." />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#event-xhr-abort" data-tested-assertations="../.." />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#dom-xmlhttprequest-abort" data-tested-assertations="following::ol//ol//ol/li[3]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test();
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest();
|
||||
client.onabort = test.step_func(function() {
|
||||
test.done();
|
||||
});
|
||||
client.open("GET", "resources/well-formed.xml");
|
||||
client.send(null);
|
||||
client.abort();
|
||||
setTimeout(test.step_func(function () {
|
||||
assert_unreached("onabort not called after 4 ms");
|
||||
}), 4);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
32
tests/wpt/web-platform-tests/XMLHttpRequest/event-load.htm
Normal file
32
tests/wpt/web-platform-tests/XMLHttpRequest/event-load.htm
Normal file
|
@ -0,0 +1,32 @@
|
|||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
<title>XMLHttpRequest: The send() method: Fire an event named load (synchronous flag is unset)</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#handler-xhr-onload" data-tested-assertations="../.." />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#event-xhr-load" data-tested-assertations="../.." />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#infrastructure-for-the-send()-method" data-tested-assertations="following::a[contains(@href,'#switch-done')]/.." />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#switch-done" data-tested-assertations="following::ol/li[6]" />
|
||||
<div id="log"></div>
|
||||
|
||||
<script>
|
||||
var test = async_test();
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest();
|
||||
client.onload = test.step_func(function(e) {
|
||||
assert_true(e instanceof ProgressEvent);
|
||||
assert_equals(e.type, "load");
|
||||
assert_equals(client.readyState, 4);
|
||||
test.done();
|
||||
});
|
||||
client.onreadystatechange = test.step_func(function() {
|
||||
if (client.readyState !== 4) return;
|
||||
|
||||
setTimeout(test.step_func(function() {
|
||||
assert_unreached("Didn't get load event within 4ms of readystatechange==4");
|
||||
}), 4);
|
||||
});
|
||||
client.open("GET", "resources/well-formed.xml");
|
||||
client.send(null);
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,35 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: loadend event</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#handler-xhr-onloadend" data-tested-assertations="/../.." />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#event-xhr-loadend" data-tested-assertations="/../.." />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#infrastructure-for-the-send()-method" data-tested-assertations="/following-sibling::ol/li[10]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#infrastructure-for-the-send()-method" data-tested-assertations="following::a[contains(@href,'#switch-done')]/.." />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#switch-done" data-tested-assertations="following::ol[1]/li[7]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test();
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest();
|
||||
client.onloadend = test.step_func(function(e) {
|
||||
assert_true(e instanceof ProgressEvent);
|
||||
assert_equals(e.type, "loadend");
|
||||
test.done();
|
||||
});
|
||||
client.onreadystatechange = function() {
|
||||
if (client.readyState !== 4) return;
|
||||
setTimeout(test.step_func(function() {
|
||||
assert_unreached("onloadend not called after 100 ms");
|
||||
}), 100);
|
||||
};
|
||||
client.open("GET", "resources/well-formed.xml");
|
||||
client.send(null);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,31 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: loadstart event</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#handler-xhr-onloadstart" data-tested-assertations="../.." />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#event-xhr-loadstart" data-tested-assertations="../.." />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-send()-method" data-tested-assertations="following-sibling::ol/li[9]/ol/li[2]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test();
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest();
|
||||
client.onloadstart = test.step_func(function(e) {
|
||||
assert_true(e instanceof ProgressEvent);
|
||||
assert_equals(e.type, "loadstart");
|
||||
assert_equals(client.readyState, 1);
|
||||
test.done();
|
||||
});
|
||||
setTimeout(test.step_func(function () {
|
||||
assert_unreached("onloadstart not called after 500 ms");
|
||||
}), 500);
|
||||
client.open("GET", "resources/well-formed.xml");
|
||||
client.send(null);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,29 @@
|
|||
<!doctype html>
|
||||
<html lang=en>
|
||||
<meta charset=utf-8>
|
||||
<title>XMLHttpRequest: The send() method: Fire a progress event named progress (synchronous flag is unset)</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#handler-xhr-onprogress" data-tested-assertations="../.." />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#event-xhr-progress" data-tested-assertations="../.." />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-send()-method" data-tested-assertations="following::*//a[contains(@href,'#make-progress-notifications')]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#make-progress-notifications" data-tested-assertations=".." />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#switch-done" data-tested-assertations="following::li[5]" />
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test();
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest();
|
||||
client.onprogress = test.step_func(function(e) {
|
||||
assert_true(e instanceof ProgressEvent);
|
||||
assert_equals(e.type, "progress");
|
||||
test.done();
|
||||
});
|
||||
client.onreadystatechange = test.step_func(function() {
|
||||
if (client.readyState === 4)
|
||||
assert_unreached("onprogress not called.");
|
||||
});
|
||||
client.open("GET", "resources/trickle.py");
|
||||
client.send(null);
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,38 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>XMLHttpRequest: the LOADING state change should only happen once</title>
|
||||
<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[1]/li[10]/dt[1]">
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#infrastructure-for-the-send()-method" data-tested-assertations="following::dt[7] following::a[contains(@href,'#switch-loading')]/..">
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#switch-loading" data-tested-assertations="following::ol[1]/li[1] following::ol[1]/li[2]">
|
||||
</head>
|
||||
|
||||
<div id="log"></div>
|
||||
|
||||
<script>
|
||||
|
||||
var test = async_test();
|
||||
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest();
|
||||
var countedLoading = 0;
|
||||
|
||||
client.onreadystatechange = test.step_func(function() {
|
||||
if (client.readyState === 3) {
|
||||
countedLoading += 1;
|
||||
}
|
||||
|
||||
if (client.readyState === 4) {
|
||||
assert_equals(countedLoading, 1, "LOADING state change may only be emitted once");
|
||||
|
||||
test.done();
|
||||
}
|
||||
});
|
||||
|
||||
client.open("GET", "resources/trickle.py?count=10"); // default timeout in trickle.py is 1/2 sec, so this request will take 5 seconds to complete
|
||||
client.send(null);
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,34 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: timeout event</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#handler-xhr-ontimeout" data-tested-assertations="../.." />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#event-xhr-timeout" data-tested-assertations="../.." />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-timeout-attribute" data-tested-assertations="following-sibling::ol/li[2]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#timeout-error" data-tested-assertations=".." />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#infrastructure-for-the-send()-method" data-tested-assertations="following-sibling::dl//code[contains(@title,'dom-XMLHttpRequest-timeout')]/.. following-sibling::dl//code[contains(@title,'dom-XMLHttpRequest-timeout')]/../following-sibling::dd" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test();
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest();
|
||||
client.ontimeout = function() {
|
||||
test.step(function() {
|
||||
assert_equals(client.readyState, 4);
|
||||
test.done();
|
||||
});
|
||||
};
|
||||
client.timeout = 5;
|
||||
client.open("GET", "resources/delay.py?ms=20000");
|
||||
client.send(null);
|
||||
setTimeout(test.step_func(function () {
|
||||
assert_unreached("ontimeout not called.");
|
||||
}), 10);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,26 @@
|
|||
<!doctype html>
|
||||
<html lang=en>
|
||||
<meta charset=utf-8>
|
||||
<title>XMLHttpRequest: upload progress event for cross-origin requests</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#handler-xhr-onprogress" data-tested-assertations="../.." />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-send()-method" data-tested-assertations="following::*//a[contains(@href,'#make-upload-progress-notifications')] following::ol[1]/li[8]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#make-upload-progress-notifications" data-tested-assertations=".. ../following::ul/li[1]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#dom-xmlhttprequest-upload" data-tested-assertations=".." />
|
||||
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test();
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest();
|
||||
client.upload.onprogress = test.step_func(function() {
|
||||
test.done();
|
||||
});
|
||||
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.send("This is a test string.");
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,26 @@
|
|||
<!doctype html>
|
||||
<html lang=en>
|
||||
<meta charset=utf-8>
|
||||
<title>XMLHttpRequest: upload progress event</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#handler-xhr-onprogress" data-tested-assertations="../.." />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-send()-method" data-tested-assertations="following::*//a[contains(@href,'#make-upload-progress-notifications')] following::ol[1]/li[8]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#make-upload-progress-notifications" data-tested-assertations=".. ../following::ul/li[1]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#dom-xmlhttprequest-upload" data-tested-assertations=".." />
|
||||
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test();
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest();
|
||||
client.upload.onprogress = test.step_func(function() {
|
||||
test.done();
|
||||
});
|
||||
client.onreadystatechange = test.step_func(function() {
|
||||
if (client.readyState === 4) assert_unreached("onprogress not called.");
|
||||
});
|
||||
client.open("POST", "resources/upload.py");
|
||||
client.send("This is a test string.");
|
||||
});
|
||||
</script>
|
1
tests/wpt/web-platform-tests/XMLHttpRequest/folder.txt
Normal file
1
tests/wpt/web-platform-tests/XMLHttpRequest/folder.txt
Normal file
|
@ -0,0 +1 @@
|
|||
top
|
|
@ -0,0 +1,46 @@
|
|||
<!doctype html>
|
||||
<html lang=en>
|
||||
<meta charset=utf-8>
|
||||
<title>XMLHttpRequest: upload formdata with blob</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#interface-formdata" data-tested-assertations="following::P[1]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#dom-formdata" data-tested-assertations="following::P[2]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#dom-formdata-append" data-tested-assertations=".. following::P[1]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#dom-formdata-append" data-tested-assertations="following::P[2] following::UL[1]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#dom-XMLHttpRequest-send-FormData" data-tested-assertations="following::DD[1]" />
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
function do_test (name, fd, expected) {
|
||||
var test = async_test(name);
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest();
|
||||
client.onreadystatechange = test.step_func(function () {
|
||||
if (client.readyState !== 4) return;
|
||||
assert_equals(client.responseText, expected);
|
||||
test.done();
|
||||
});
|
||||
client.open("POST", "resources/upload.py");
|
||||
client.send(fd);
|
||||
});
|
||||
}
|
||||
|
||||
function create_formdata () {
|
||||
var fd = new FormData();
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
fd.append.apply(fd, arguments[i]);
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
do_test("formdata with blob", create_formdata(['key', new Blob(['value'], {type: 'text/x-value'})]), '\nkey=blob:text/x-value:5,');
|
||||
do_test("formdata with named blob", create_formdata(['key', new Blob(['value'], {type: 'text/x-value'}), 'blob.txt']), '\nkey=blob.txt:text/x-value:5,');
|
||||
// If 3rd argument is given and 2nd is not a Blob, formdata.append() should throw
|
||||
var test = async_test('formdata.append() should throw if value is string and file name is given'); // needs to be async just because the others above are
|
||||
test.step(function(){
|
||||
assert_throws(new TypeError(), function(){
|
||||
create_formdata('a', 'b', 'c');
|
||||
});
|
||||
});
|
||||
test.done();
|
||||
</script>
|
43
tests/wpt/web-platform-tests/XMLHttpRequest/formdata.htm
Normal file
43
tests/wpt/web-platform-tests/XMLHttpRequest/formdata.htm
Normal file
|
@ -0,0 +1,43 @@
|
|||
<!doctype html>
|
||||
<html lang=en>
|
||||
<meta charset=utf-8>
|
||||
<title>XMLHttpRequest: upload formdata</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#interface-formdata" data-tested-assertations="following::P[1]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#dom-formdata" data-tested-assertations=".. following::P[1]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#dom-formdata-append" data-tested-assertations=".. following::UL[1]/LI[1] following::UL[1]/LI[2] following::UL[1]/LI[3]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#dom-XMLHttpRequest-send-FormData" data-tested-assertations="following::DD[1]" />
|
||||
<div id="log"></div>
|
||||
<form id="form">
|
||||
<input type="hidden" name="key" value="value">
|
||||
</form>
|
||||
<script>
|
||||
function do_test (name, fd, expected) {
|
||||
var test = async_test(name);
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest();
|
||||
client.onreadystatechange = test.step_func(function () {
|
||||
if (client.readyState !== 4) return;
|
||||
assert_equals(client.responseText, expected);
|
||||
test.done();
|
||||
});
|
||||
client.open("POST", "resources/upload.py");
|
||||
client.send(fd);
|
||||
});
|
||||
}
|
||||
|
||||
function create_formdata () {
|
||||
var fd = new FormData();
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
fd.append.apply(fd, arguments[i]);
|
||||
};
|
||||
return fd;
|
||||
}
|
||||
|
||||
do_test("empty formdata", new FormData(), '\n');
|
||||
do_test("formdata with string", create_formdata(['key', 'value']), 'key=value,\n');
|
||||
do_test("formdata with named string", create_formdata(['key', new Blob(['value'], {type: 'text/plain'}), 'kv.txt']), '\nkey=kv.txt:text/plain:5,');
|
||||
do_test("formdata from form", new FormData(document.getElementById('form')), 'key=value,\n');
|
||||
|
||||
</script>
|
|
@ -0,0 +1,38 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: getAllResponseHeaders() excludes cookies</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#dom-xmlhttprequest-getallresponseheaders" data-tested-assertations="/following::OL[1]/LI[1] /following::OL[1]/LI[3]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test()
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
assert_equals(client.getAllResponseHeaders(), "")
|
||||
client.onreadystatechange = function() {
|
||||
test.step(function() {
|
||||
var headers = client.getAllResponseHeaders().toLowerCase()
|
||||
if(client.readyState == 1) {
|
||||
assert_equals(headers, "")
|
||||
}
|
||||
if(client.readyState > 1) {
|
||||
assert_true(headers.indexOf("\r\n") != -1, "carriage return")
|
||||
assert_true(headers.indexOf("content-type") != -1, "content-type")
|
||||
assert_true(headers.indexOf("x-custom-header") != -1, "x-custom-header")
|
||||
assert_false(headers.indexOf("set-cookie") != -1, "set-cookie")
|
||||
assert_false(headers.indexOf("set-cookie2") != -1, "set-cookie2")
|
||||
}
|
||||
if(client.readyState == 4)
|
||||
test.done()
|
||||
})
|
||||
}
|
||||
client.open("GET", "resources/headers.py")
|
||||
client.send(null)
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,34 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: getAllResponseHeaders() excludes status</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#dom-xmlhttprequest-getallresponseheaders" data-tested-assertations="/following::OL[1]/LI[1] /following::OL[1]/LI[3]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test()
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
client.onreadystatechange = function() {
|
||||
test.step(function() {
|
||||
var headers = client.getAllResponseHeaders().toLowerCase()
|
||||
if(client.readyState == 1) {
|
||||
assert_equals(headers, "")
|
||||
}
|
||||
if(client.readyState > 1) {
|
||||
assert_false(headers.indexOf("200 ok") != -1)
|
||||
assert_false(headers.indexOf("http/1.") != -1)
|
||||
}
|
||||
if(client.readyState == 4)
|
||||
test.done()
|
||||
})
|
||||
}
|
||||
client.open("GET", "resources/headers.py")
|
||||
client.send(null)
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,34 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: getResponseHeader() case-insensitive matching</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#dom-xmlhttprequest-getresponseheader" data-tested-assertations="following::OL[1]/LI[4] following::OL[1]/LI[5] following::OL[1]/LI[6]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test()
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
client.onreadystatechange = function() {
|
||||
test.step(function() {
|
||||
if(client.readyState == 4) {
|
||||
assert_equals(client.getResponseHeader("x-custom-header"), "test")
|
||||
assert_equals(client.getResponseHeader("X-Custom-Header"), "test")
|
||||
assert_equals(client.getResponseHeader("X-CUSTOM-HEADER"), "test")
|
||||
assert_equals(client.getResponseHeader("X-custom-HEADER"), "test")
|
||||
assert_equals(client.getResponseHeader("X-CUSTOM-header-COMMA"), "1, 2")
|
||||
assert_equals(client.getResponseHeader("X-CUSTOM-no-such-header-in-response"), null)
|
||||
assert_true(client.getResponseHeader("CONTENT-TYPE").indexOf("text/plain") != -1)
|
||||
test.done()
|
||||
}
|
||||
})
|
||||
}
|
||||
client.open("GET", "resources/headers.py")
|
||||
client.send(null)
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,32 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: getResponseHeader() and HTTP trailer</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#dom-xmlhttprequest-getresponseheader" data-tested-assertations="/following::OL[1]/LI[4] /following::OL[1]/LI[5] /following::OL[1]/LI[6]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test()
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
client.onreadystatechange = function() {
|
||||
test.step(function() {
|
||||
if(client.readyState == 4) {
|
||||
assert_equals(client.getResponseHeader('Trailer'), 'X-Test-Me')
|
||||
assert_equals(client.getResponseHeader('X-Test-Me'), null)
|
||||
assert_equals(client.getAllResponseHeaders().indexOf('Trailer header value'), -1)
|
||||
assert_regexp_match(client.getAllResponseHeaders(), /Trailer:\sX-Test-Me/)
|
||||
assert_equals(client.responseText, "First chunk\r\nSecond chunk\r\nYet another (third) chunk\r\nYet another (fourth) chunk\r\n")
|
||||
test.done()
|
||||
}
|
||||
})
|
||||
}
|
||||
client.open("GET", "resources/chunked.py")
|
||||
client.send(null)
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,36 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: getResponseHeader() custom/non-existent headers and cookies</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#dom-xmlhttprequest-getresponseheader" data-tested-assertations="following::OL[1]/LI[3] following::OL[1]/LI[5] following::OL[1]/LI[6]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test()
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
client.onreadystatechange = function() {
|
||||
test.step(function() {
|
||||
if(client.readyState == 1) {
|
||||
assert_equals(client.getResponseHeader("x-custom-header"), null)
|
||||
}
|
||||
if(client.readyState > 1) {
|
||||
assert_equals(client.getResponseHeader("x-custom-header"), "test")
|
||||
assert_equals(client.getResponseHeader("x-custom-header-empty"), "")
|
||||
assert_equals(client.getResponseHeader("set-cookie"), null)
|
||||
assert_equals(client.getResponseHeader("set-cookie2"), null)
|
||||
assert_equals(client.getResponseHeader("x-non-existent-header"), null)
|
||||
}
|
||||
if(client.readyState == 4)
|
||||
test.done()
|
||||
})
|
||||
}
|
||||
client.open("GET", "resources/headers.py")
|
||||
client.send(null)
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,36 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: getResponseHeader() in error state (failing cross-origin test)</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#dom-xmlhttprequest-getresponseheader" data-tested-assertations="following::OL[1]/LI[2]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test()
|
||||
test.step(function() {
|
||||
|
||||
var client = new XMLHttpRequest()
|
||||
client.onreadystatechange = function() {
|
||||
test.step(function() {
|
||||
if(client.readyState == 1) {
|
||||
assert_equals(client.getResponseHeader("x-custom-header"), null)
|
||||
}
|
||||
if(client.readyState > 1) {
|
||||
assert_equals(client.getResponseHeader("x-custom-header"), null)
|
||||
}
|
||||
if(client.readyState == 4){
|
||||
assert_equals(client.getResponseHeader("x-custom-header"), null)
|
||||
test.done()
|
||||
}
|
||||
})
|
||||
}
|
||||
var url = location.protocol + "//" + 'www1.' + location.host + (location.pathname.replace(/getresponseheader-error-state\.htm/, 'resources/nocors/folder.txt'))
|
||||
client.open("GET", url)
|
||||
client.send(null)
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,29 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: getResponseHeader() server and date</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#dom-xmlhttprequest-getresponseheader" data-tested-assertations="/following::OL[1]/LI[4] /following::OL[1]/LI[5] /following::OL[1]/LI[6]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test()
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
client.onreadystatechange = function() {
|
||||
test.step(function() {
|
||||
if(client.readyState == 4) {
|
||||
assert_true(client.getResponseHeader("Server") != null)
|
||||
assert_true(client.getResponseHeader("Date") != null)
|
||||
test.done()
|
||||
}
|
||||
})
|
||||
}
|
||||
client.open("GET", "resources/headers.py")
|
||||
client.send(null)
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,34 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: getResponseHeader() funny characters</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#dom-xmlhttprequest-getresponseheader" data-tested-assertations="/following::OL[1]/LI[5] /following::OL[1]/LI[6]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test()
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
client.onreadystatechange = function() {
|
||||
test.step(function() {
|
||||
if(client.readyState == 4) {
|
||||
assert_equals(client.getResponseHeader("x-custom-header "), null)
|
||||
assert_equals(client.getResponseHeader(" x-custom-header"), null)
|
||||
assert_equals(client.getResponseHeader("x-custom-header-bytes"), "\xE2\x80\xA6")
|
||||
assert_equals(client.getResponseHeader("x¾"), null)
|
||||
assert_equals(client.getResponseHeader("x-custom-header\n"), null)
|
||||
assert_equals(client.getResponseHeader("\nx-custom-header"), null)
|
||||
assert_equals(client.getResponseHeader("x-custom-header:"), null)
|
||||
test.done()
|
||||
}
|
||||
})
|
||||
}
|
||||
client.open("GET", "resources/headers.py")
|
||||
client.send(null)
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,32 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: getResponseHeader() in unsent, opened states</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#dom-xmlhttprequest-getresponseheader" data-tested-assertations="/following::OL[1]/LI[1]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test()
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
assert_equals(client.getResponseHeader("x-custom-header"), null)
|
||||
client.onreadystatechange = function() {
|
||||
test.step(function() {
|
||||
if(client.readyState < 2) {
|
||||
assert_equals(client.getResponseHeader("x-custom-header"), null)
|
||||
assert_equals(client.getResponseHeader("CONTENT-TYPE"), null)
|
||||
test.done()
|
||||
}
|
||||
})
|
||||
}
|
||||
client.open("GET", "resources/headers.py")
|
||||
assert_equals(client.getResponseHeader("x-custom-header"), null)
|
||||
assert_equals(client.getResponseHeader("Date"), null)
|
||||
client.send(null)
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
171
tests/wpt/web-platform-tests/XMLHttpRequest/interfaces.html
Normal file
171
tests/wpt/web-platform-tests/XMLHttpRequest/interfaces.html
Normal file
|
@ -0,0 +1,171 @@
|
|||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
<title>XMLHttpRequest IDL tests</title>
|
||||
<script src=/resources/testharness.js></script>
|
||||
<script src=/resources/testharnessreport.js></script>
|
||||
<script src=/resources/WebIDLParser.js></script>
|
||||
<script src=/resources/idlharness.js></script>
|
||||
|
||||
<h1>XMLHttpRequest IDL tests</h1>
|
||||
<div id=log></div>
|
||||
|
||||
<script type=text/plain class=untested>
|
||||
[Constructor(DOMString type, optional EventInit eventInitDict)/*,
|
||||
Exposed=(Window,Worker)*/]
|
||||
interface Event {
|
||||
readonly attribute DOMString type;
|
||||
readonly attribute EventTarget? target;
|
||||
readonly attribute EventTarget? currentTarget;
|
||||
|
||||
const unsigned short NONE = 0;
|
||||
const unsigned short CAPTURING_PHASE = 1;
|
||||
const unsigned short AT_TARGET = 2;
|
||||
const unsigned short BUBBLING_PHASE = 3;
|
||||
readonly attribute unsigned short eventPhase;
|
||||
|
||||
void stopPropagation();
|
||||
void stopImmediatePropagation();
|
||||
|
||||
readonly attribute boolean bubbles;
|
||||
readonly attribute boolean cancelable;
|
||||
void preventDefault();
|
||||
readonly attribute boolean defaultPrevented;
|
||||
|
||||
[Unforgeable] readonly attribute boolean isTrusted;
|
||||
readonly attribute DOMTimeStamp timeStamp;
|
||||
|
||||
void initEvent(DOMString type, boolean bubbles, boolean cancelable);
|
||||
};
|
||||
|
||||
dictionary EventInit {
|
||||
boolean bubbles = false;
|
||||
boolean cancelable = false;
|
||||
};
|
||||
|
||||
/*[Exposed=(Window,Worker)]*/
|
||||
interface EventTarget {
|
||||
void addEventListener(DOMString type, EventListener? callback, optional boolean capture = false);
|
||||
void removeEventListener(DOMString type, EventListener? callback, optional boolean capture = false);
|
||||
boolean dispatchEvent(Event event);
|
||||
};
|
||||
</script>
|
||||
<script type=text/plain class=untested>
|
||||
[TreatNonCallableAsNull]
|
||||
callback EventHandlerNonNull = any (Event event);
|
||||
typedef EventHandlerNonNull? EventHandler;
|
||||
</script>
|
||||
<script type=text/plain>
|
||||
/*[Exposed=(Window,Worker)]*/
|
||||
interface XMLHttpRequestEventTarget : EventTarget {
|
||||
// event handlers
|
||||
attribute EventHandler onloadstart;
|
||||
attribute EventHandler onprogress;
|
||||
attribute EventHandler onabort;
|
||||
attribute EventHandler onerror;
|
||||
attribute EventHandler onload;
|
||||
attribute EventHandler ontimeout;
|
||||
attribute EventHandler onloadend;
|
||||
};
|
||||
|
||||
/*[Exposed=(Window,Worker)]*/
|
||||
interface XMLHttpRequestUpload : XMLHttpRequestEventTarget {
|
||||
};
|
||||
|
||||
enum XMLHttpRequestResponseType {
|
||||
"",
|
||||
"arraybuffer",
|
||||
"blob",
|
||||
"document",
|
||||
"json",
|
||||
"text"
|
||||
};
|
||||
|
||||
[Constructor/*,
|
||||
Exposed=(Window,Worker)*/]
|
||||
interface XMLHttpRequest : XMLHttpRequestEventTarget {
|
||||
// event handler
|
||||
attribute EventHandler onreadystatechange;
|
||||
|
||||
// states
|
||||
const unsigned short UNSENT = 0;
|
||||
const unsigned short OPENED = 1;
|
||||
const unsigned short HEADERS_RECEIVED = 2;
|
||||
const unsigned short LOADING = 3;
|
||||
const unsigned short DONE = 4;
|
||||
readonly attribute unsigned short readyState;
|
||||
|
||||
// request
|
||||
void open(ByteString method, USVString url);
|
||||
void open(ByteString method, USVString url, boolean async, optional USVString? username = null, optional USVString? password = null);
|
||||
void setRequestHeader(ByteString name, ByteString value);
|
||||
attribute unsigned long timeout;
|
||||
attribute boolean withCredentials;
|
||||
readonly attribute XMLHttpRequestUpload upload;
|
||||
void send(optional (Document or BodyInit)? body = null);
|
||||
void abort();
|
||||
|
||||
// response
|
||||
readonly attribute USVString responseURL;
|
||||
readonly attribute unsigned short status;
|
||||
readonly attribute ByteString statusText;
|
||||
ByteString? getResponseHeader(ByteString name);
|
||||
ByteString getAllResponseHeaders();
|
||||
void overrideMimeType(DOMString mime);
|
||||
attribute XMLHttpRequestResponseType responseType;
|
||||
readonly attribute any response;
|
||||
readonly attribute USVString responseText;
|
||||
[Exposed=Window] readonly attribute Document? responseXML;
|
||||
};
|
||||
|
||||
typedef (File or USVString) FormDataEntryValue;
|
||||
|
||||
[Constructor(optional HTMLFormElement form)/*,
|
||||
Exposed=(Window,Worker)*/]
|
||||
interface FormData {
|
||||
void append(USVString name, Blob value, optional USVString filename);
|
||||
void append(USVString name, USVString value);
|
||||
void delete(USVString name);
|
||||
FormDataEntryValue? get(USVString name);
|
||||
sequence<FormDataEntryValue> getAll(USVString name);
|
||||
boolean has(USVString name);
|
||||
void set(USVString name, Blob value, optional USVString filename);
|
||||
void set(USVString name, USVString value);
|
||||
/*iterable<USVString, FormDataEntryValue>;*/
|
||||
};
|
||||
|
||||
[Constructor(DOMString type, optional ProgressEventInit eventInitDict)/*,
|
||||
Exposed=(Window,Worker)*/]
|
||||
interface ProgressEvent : Event {
|
||||
readonly attribute boolean lengthComputable;
|
||||
readonly attribute unsigned long long loaded;
|
||||
readonly attribute unsigned long long total;
|
||||
};
|
||||
|
||||
dictionary ProgressEventInit : EventInit {
|
||||
boolean lengthComputable = false;
|
||||
unsigned long long loaded = 0;
|
||||
unsigned long long total = 0;
|
||||
};
|
||||
</script>
|
||||
<script>
|
||||
"use strict";
|
||||
var form;
|
||||
var idlArray;
|
||||
setup(function() {
|
||||
form = document.createElement("form");
|
||||
idlArray = new IdlArray();
|
||||
[].forEach.call(document.querySelectorAll("script[type=text\\/plain]"), function(node) {
|
||||
if (node.className == "untested") {
|
||||
idlArray.add_untested_idls(node.textContent);
|
||||
} else {
|
||||
idlArray.add_idls(node.textContent);
|
||||
}
|
||||
});
|
||||
idlArray.add_objects({
|
||||
XMLHttpRequest: ['new XMLHttpRequest()'],
|
||||
XMLHttpRequestUpload: ['(new XMLHttpRequest()).upload'],
|
||||
FormData: ['new FormData()', 'new FormData(form)']
|
||||
});
|
||||
});
|
||||
idlArray.test();
|
||||
</script>
|
|
@ -0,0 +1,35 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() after abort()</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::ol/li[15] following::ol/li[15]/ol/li[1] following::ol/li[15]/ol/li[2]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test()
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest(),
|
||||
result = [],
|
||||
expected = [1, 4, 1] // open() -> 1,
|
||||
// abort() -> 4, open() -> 1
|
||||
client.onreadystatechange = function() {
|
||||
test.step(function() {
|
||||
result.push(client.readyState)
|
||||
})
|
||||
}
|
||||
client.open("GET", "resources/well-formed.xml")
|
||||
assert_equals(client.readyState, 1)
|
||||
client.send(null)
|
||||
client.abort()
|
||||
assert_equals(client.readyState, 0)
|
||||
client.open("GET", "resources/well-formed.xml")
|
||||
assert_equals(client.readyState, 1)
|
||||
assert_array_equals(result, expected)
|
||||
})
|
||||
test.done()
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,33 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() after setRequestHeader()</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::ol/li[14]/ul/li[4]" />
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test()
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
client.onreadystatechange = function() {
|
||||
test.step(function() {
|
||||
if(client.readyState === 4){
|
||||
assert_equals(client.responseText, '')
|
||||
test.done()
|
||||
}
|
||||
})
|
||||
}
|
||||
client.open("GET", "resources/inspect-headers.py?filter_name=X-foo")
|
||||
assert_equals(client.readyState, 1)
|
||||
client.setRequestHeader('X-foo', 'bar')
|
||||
client.open("GET", "resources/inspect-headers.py?filter_name=X-foo")
|
||||
assert_equals(client.readyState, 1)
|
||||
client.send()
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
32
tests/wpt/web-platform-tests/XMLHttpRequest/open-during-abort.htm
Executable file
32
tests/wpt/web-platform-tests/XMLHttpRequest/open-during-abort.htm
Executable file
|
@ -0,0 +1,32 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() during abort()</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
test(function() {
|
||||
var client = new XMLHttpRequest(),
|
||||
abort_flag = false,
|
||||
result = [],
|
||||
expected = [1, 4, 1] // open() => 1, abort() => 4, open() => 1
|
||||
|
||||
client.onreadystatechange = this.step_func(function() {
|
||||
result.push(client.readyState)
|
||||
if (abort_flag) {
|
||||
abort_flag = false
|
||||
client.open("GET", "...")
|
||||
}
|
||||
})
|
||||
client.open("GET", "resources/well-formed.xml")
|
||||
client.send(null)
|
||||
abort_flag = true
|
||||
client.abort()
|
||||
assert_array_equals(result, expected)
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,28 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() - bogus methods</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::ol[1]/li[4]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
function method(method) {
|
||||
test(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
assert_throws("SyntaxError", function() { client.open(method, "...") })
|
||||
}, document.title + " (" + method + ")")
|
||||
}
|
||||
method("")
|
||||
method(">")
|
||||
method(" GET")
|
||||
method("G T")
|
||||
method("@GET")
|
||||
method("G:ET")
|
||||
method("GET?")
|
||||
method("GET\n")
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,29 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() - case-insensitive methods test</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::ol/li[5]" />
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
function method(method) {
|
||||
test(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
client.open(method, "resources/content.py", false)
|
||||
client.send(null)
|
||||
assert_equals(client.getResponseHeader("x-request-method"), method.toUpperCase())
|
||||
}, document.title + " (" + method.toUpperCase() + ")")
|
||||
}
|
||||
method("deLETE")
|
||||
method("get")
|
||||
method("heAd")
|
||||
method("OpTIOns")
|
||||
method("post")
|
||||
method("Put")
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,31 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() - case-sensitive methods test</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::ol/li[5]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
function method(method) {
|
||||
test(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
client.open(method, "resources/content.py", false)
|
||||
client.send(null)
|
||||
assert_equals(client.getResponseHeader("x-request-method"), method)
|
||||
}, document.title + " (" + method + ")")
|
||||
}
|
||||
method("XUNICORN")
|
||||
method("xUNIcorn")
|
||||
method("chiCKEN")
|
||||
method("PATCH")
|
||||
method("patCH")
|
||||
method("copy")
|
||||
method("COpy")
|
||||
method("inDEX")
|
||||
method("movE")
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,29 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() - "insecure" methods</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::ol/li[5] following::ol/li[6]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
function method(method) {
|
||||
test(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
assert_throws("SecurityError", function() { client.open(method, "...") })
|
||||
}, document.title + " (" + method + ")")
|
||||
}
|
||||
method("track")
|
||||
method("TRACK")
|
||||
method("trAck")
|
||||
method("TRACE")
|
||||
method("trace")
|
||||
method("traCE")
|
||||
method("connect")
|
||||
method("CONNECT")
|
||||
method("connECT")
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,29 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() sync request not allowed if responseType is set</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::ol[1]/li[4]" />
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
// Note: the case of calling synchronous open() first, and then setting
|
||||
// responseType, is tested in responsetype.html.
|
||||
function request(type) {
|
||||
test(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
client.responseType = type
|
||||
assert_throws("InvalidAccessError", function() { client.open('GET', "...", false) })
|
||||
}, document.title + " (" + type + ")")
|
||||
}
|
||||
request("arraybuffer")
|
||||
request("blob")
|
||||
request("json")
|
||||
request("text")
|
||||
request("document")
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,33 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() - open() - send()</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::ol/li[14]/ul/li[1] following::ol/li[14]/ul/li[2] following::ol/li[15]/ol/li[1] following::ol/li[15]/ol/li[2]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test()
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest(),
|
||||
result = [],
|
||||
expected = [1,2,3,4]
|
||||
client.onreadystatechange = function() {
|
||||
test.step(function() {
|
||||
result.push(client.readyState)
|
||||
if(4 == client.readyState) {
|
||||
assert_array_equals(result, expected)
|
||||
assert_equals(client.responseText, 'top\n')
|
||||
test.done()
|
||||
}
|
||||
})
|
||||
}
|
||||
client.open("GET", "resources/folder.txt")
|
||||
client.open("GET", "folder.txt")
|
||||
client.send(null)
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,31 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() - open() (sync) - send()</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::ol/li[14]/ul/li[1] following::ol/li[14]/ul/li[2] following::ol/li[14]/ul/li[3] following::ol/li[15]/ol/li[1] following::ol/li[15]/ol/li[2]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test()
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest(),
|
||||
result = [],
|
||||
expected = [1,4]
|
||||
client.onreadystatechange = function() {
|
||||
test.step(function() {
|
||||
result.push(client.readyState)
|
||||
})
|
||||
}
|
||||
client.open("GET", "folder.txt")
|
||||
client.open("GET", "folder.txt", false)
|
||||
client.send(null)
|
||||
assert_equals(client.responseText, 'top\n')
|
||||
assert_array_equals(result, expected)
|
||||
test.done()
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
20
tests/wpt/web-platform-tests/XMLHttpRequest/open-referer.htm
Normal file
20
tests/wpt/web-platform-tests/XMLHttpRequest/open-referer.htm
Normal file
|
@ -0,0 +1,20 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() - value of Referer header</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="/following::ol[1]/li[2]/ol[1]/li[4]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
test(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
client.open("POST", "resources/inspect-headers.py?filter_name=referer", false)
|
||||
client.send(null)
|
||||
assert_equals(client.responseText, "referer: "+location.href+'\n')
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,33 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() - send() - open()</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::ol/li[14]/ul/li[1] following::ol/li[14]/ul/li[2] following::ol/li[15]/ol/li[1] following::ol/li[15]/ol/li[2]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test()
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest(),
|
||||
result = [],
|
||||
expected = [1, 'a', 'b', 'c']
|
||||
client.onreadystatechange = function() {
|
||||
test.step(function() {
|
||||
result.push(client.readyState)
|
||||
})
|
||||
}
|
||||
client.open("GET", "folder.txt")
|
||||
result.push('a')
|
||||
client.send()
|
||||
result.push('b')
|
||||
client.open("GET", "folder.txt")
|
||||
result.push('c')
|
||||
assert_array_equals(result, expected)
|
||||
test.done()
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,41 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() (sync) - send() - open()</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::ol[1]/li[14]/ul/li[1] following::ol[1]/li[14]/ul/li[2] following::ol[1]/li[14]/ul/li[3] following::ol[1]/li[15]/ol/li[1] following::ol[1]/li[15]/ol/li[2]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-responsexml-attribute" data-tested-assertations="following::ol[1]/li[2]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-responsetext-attribute" data-tested-assertations="following::ol[1]/li[2]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-status-attribute" data-tested-assertations="following::ol[1]/li[1]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-statustext-attribute" data-tested-assertations="following::ol[1]/li[1]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-getallresponseheaders()-method" data-tested-assertations="following::ol[1]/li[1]" />
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test()
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest(),
|
||||
result = [],
|
||||
expected = [1]
|
||||
client.onreadystatechange = function() {
|
||||
test.step(function() {
|
||||
result.push(client.readyState)
|
||||
})
|
||||
}
|
||||
client.open("GET", "folder.txt")
|
||||
client.send(null)
|
||||
client.open("GET", "folder.txt", false)
|
||||
assert_array_equals(result, expected)
|
||||
assert_equals(client.responseXML, null)
|
||||
assert_equals(client.responseText, "")
|
||||
assert_equals(client.status, 0)
|
||||
assert_equals(client.statusText, "")
|
||||
assert_equals(client.getAllResponseHeaders(), "")
|
||||
test.done()
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,23 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() resolving URLs (about:blank iframe)</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::ol/li[2]/ol/li[2] following::ol/li[7] following::ol/li[14]/ul/li[2]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-responsetext-attribute" data-tested-assertations="following::ol/li[4]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#concept-xmlhttprequest-document" data-tested-assertations=".." />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<iframe src="about:blank"></iframe>
|
||||
<script>
|
||||
test(function() {
|
||||
var client = new self[0].XMLHttpRequest()
|
||||
client.open("GET", "folder.txt", false)
|
||||
client.send("")
|
||||
assert_equals(client.responseText, "top\n")
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,24 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() resolving URLs - insert <base> after open()</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::ol/li[2]/ol/li[2] following::ol/li[7] following::ol/li[14]/ul/li[2]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-responsetext-attribute" data-tested-assertations="following::ol/li[4]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
test(function() {
|
||||
var client = new XMLHttpRequest(),
|
||||
base = document.createElement("base")
|
||||
base.href = location.href.replace(/\/[^/]*$/, '') + "/resources/"
|
||||
client.open("GET", "folder.txt", false)
|
||||
document.getElementsByTagName("head")[0].appendChild(base)
|
||||
client.send(null)
|
||||
assert_equals(client.responseText, "top\n")
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,24 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() resolving URLs - insert <base></title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::ol/li[2]/ol/li[2] following::ol/li[7] following::ol/li[14]/ul/li[2]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-responsetext-attribute" data-tested-assertations="following::ol/li[4]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
test(function() {
|
||||
var client = new XMLHttpRequest(),
|
||||
base = document.createElement("base")
|
||||
base.href = location.href.replace(/\/[^/]*$/, '') + "/resources/"
|
||||
document.getElementsByTagName("head")[0].appendChild(base)
|
||||
client.open("GET", "folder.txt", false)
|
||||
client.send(null)
|
||||
assert_equals(client.responseText, "bottom\n")
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,22 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() resolving URLs - <base></title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<base href="./resources/">
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::ol/li[2]/ol/li[2] following::ol/li[7] following::ol/li[14]/ul/li[2]" />
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-responsetext-attribute" data-tested-assertations="following::ol/li[4]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
test(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
client.open("GET", "folder.txt", false)
|
||||
client.send(null)
|
||||
assert_equals(client.responseText, "bottom\n")
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,22 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() - bogus URLs</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::ol/li[7] following::ol/li[8]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
function url(url) {
|
||||
test(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
assert_throws("SyntaxError", function() { client.open("GET", url) })
|
||||
}, document.title + " (" + url + ")")
|
||||
}
|
||||
url("http:")
|
||||
url("http://a a/")
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,21 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=windows-1252>
|
||||
<title>XMLHttpRequest: open() - URL encoding</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::ol/li[7] following::ol/li[14]/ul/li[2]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
test(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
client.open("GET", "resources/content.py?ß", false)
|
||||
client.send(null)
|
||||
assert_equals(client.getResponseHeader("x-request-query"), "%C3%9F")
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,38 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() resolving URLs - fragment identifier</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::ol[1]/li[7]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
test(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
client.open("GET", "folder.txt#foobar", false)
|
||||
client.send(null)
|
||||
assert_equals(client.responseText, "top\n")
|
||||
})
|
||||
test(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
client.open("GET", "resources/requri.py#foobar", false)
|
||||
client.send(null)
|
||||
assert_regexp_match(client.responseText, /XMLHttpRequest\/resources\/requri\.py$/)
|
||||
}, 'make sure fragment is removed from URL before request')
|
||||
test(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
client.open("GET", "resources/requri.py?help=#foobar", false)
|
||||
client.send(null)
|
||||
assert_regexp_match(client.responseText, /XMLHttpRequest\/resources\/requri\.py\?help=$/)
|
||||
}, 'make sure fragment is removed from URL before request (with query string)')
|
||||
test(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
client.open("GET", "resources/requri.py?" +encodeURIComponent("#foobar"), false)
|
||||
client.send(null)
|
||||
assert_regexp_match(client.responseText, /XMLHttpRequest\/resources\/requri\.py\?%23foobar$/)
|
||||
}, 'make sure escaped # is not removed')
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,19 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() - resolving URLs (javascript: <iframe>; 2)</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::ol[1]/li[2]/ol[1]/li[2] following::ol[1]/li[7] following::ol[1]/li[14]/ul/li[2]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test()
|
||||
test.step(function() {
|
||||
var iframe = document.body.appendChild(document.createElement("iframe"))
|
||||
iframe.src = "javascript:parent.test.step(function() { var x = new XMLHttpRequest(); x.open('GET', 'folder.txt', false); x.send(null); parent.assert_equals(x.responseText, 'top\\n'); parent.test.done() })"
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,28 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() - resolving URLs (javascript: <iframe>; 1)</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::ol[1]/li[2]/ol[1]/li[2] following::ol[1]/li[7] following::ol[1]/li[14]/ul/li[2]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test()
|
||||
function request() {
|
||||
test.step(function() {
|
||||
var x = new XMLHttpRequest()
|
||||
x.open("GET", "folder.txt", false)
|
||||
x.send(null)
|
||||
assert_equals(x.responseText, "top\n")
|
||||
test.done()
|
||||
})
|
||||
}
|
||||
test.step(function() {
|
||||
var iframe = document.body.appendChild(document.createElement("iframe"))
|
||||
iframe.src = "javascript:parent.request()"
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,24 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() resolving URLs (multi-Window; 2; evil)</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::ol[1]/li[2]/ol[1]/li[1]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
function init(){ // called from page inside IFRAME
|
||||
test(function() {
|
||||
var client = new self[0].XMLHttpRequest()
|
||||
document.body.removeChild(document.getElementsByTagName("iframe")[0])
|
||||
assert_throws("InvalidStateError", function() {
|
||||
client.open("GET", "folder.txt")
|
||||
}, "open() when associated document's IFRAME is removed")
|
||||
})
|
||||
}
|
||||
</script>
|
||||
<iframe src="resources/init.htm"></iframe>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,24 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() resolving URLs (multi-Window; 3; evil)</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
function init() {
|
||||
test(function() {
|
||||
var client = new self[0].XMLHttpRequest()
|
||||
client.open("GET", "folder.txt")
|
||||
document.body.removeChild(document.getElementsByTagName("iframe")[0])
|
||||
assert_throws("InvalidStateError", function() {
|
||||
client.send(null)
|
||||
}, "send() when associated document's IFRAME is removed")
|
||||
})
|
||||
}
|
||||
</script>
|
||||
<iframe src="resources/init.htm"></iframe>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,50 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() resolving URLs (multi-Window; 4; evil)</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
/*
|
||||
It's unclear what the pass condition should be for this test.
|
||||
Implementations:
|
||||
Firefox, Opera (Presto): terminate request with no further events when IFRAME is removed.
|
||||
Chrome: completes request to readyState=4 but responseText is "" so it's pretty much terminated with an extra event for "DONE" state
|
||||
Pass condition is now according to my suggested spec text in https://github.com/whatwg/xhr/pull/3 , if that's not accepted we'll have to amend this test
|
||||
*/
|
||||
var test = async_test()
|
||||
function init() {
|
||||
test.step(function() {
|
||||
var hasErrorEvent = false
|
||||
var client = new self[0].XMLHttpRequest()
|
||||
client.onreadystatechange = function() {
|
||||
test.step(function() {
|
||||
if(client.readyState == 4) {
|
||||
assert_equals(client.responseText, "", "responseText is empty on inactive document error condition")
|
||||
}
|
||||
})
|
||||
}
|
||||
client.addEventListener('error', function(){
|
||||
test.step(function() {
|
||||
hasErrorEvent = true
|
||||
assert_equals(client.readyState, 4, "readyState is 4 when error listener fires")
|
||||
})
|
||||
})
|
||||
client.addEventListener('loadend', function(){
|
||||
test.step(function() {
|
||||
assert_true(hasErrorEvent, "should get an error event")
|
||||
test.done()
|
||||
})
|
||||
})
|
||||
client.open("GET", "folder.txt")
|
||||
client.send(null)
|
||||
document.body.removeChild(document.getElementsByTagName("iframe")[0])
|
||||
})
|
||||
}
|
||||
</script>
|
||||
<iframe src="resources/init.htm"></iframe>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,30 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() resolving URLs (multi-Window; 5)</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::ol[1]/li[2]/ol[1]/li[1]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test(),
|
||||
client,
|
||||
count = 0
|
||||
function init() {
|
||||
test.step(function() {
|
||||
if(0 == count) {
|
||||
client = new self[0].XMLHttpRequest()
|
||||
count++
|
||||
self[0].location.reload()
|
||||
} else if(1 == count) {
|
||||
assert_throws("InvalidStateError", function() { client.open("GET", "...") })
|
||||
test.done()
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
<iframe src="resources/init.htm"></iframe>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,30 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() resolving URLs (multi-Window; 1)</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::ol[1]/li[2]/ol[1]/li[2] following::ol[1]/li[7] following::ol[1]/li[14]/ul/li[2]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test()
|
||||
function init() {
|
||||
test.step(function() {
|
||||
var client = new self[0].XMLHttpRequest()
|
||||
client.onreadystatechange = function() {
|
||||
test.step(function() {
|
||||
if(client.readyState == 4)
|
||||
assert_equals(client.responseText, "bottom\n")
|
||||
test.done()
|
||||
})
|
||||
}
|
||||
client.open("GET", "folder.txt")
|
||||
client.send("")
|
||||
})
|
||||
}
|
||||
</script>
|
||||
<iframe src="resources/init.htm"></iframe>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,44 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>XMLHttpRequest: worker scripts, origin and referrer</title>
|
||||
<link rel="stylesheet" href="/resources/testharness.css" />
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::OL[1]/LI[3] following::OL[1]/LI[3]/ol[1]/li[1] following::OL[1]/LI[3]/ol[1]/li[2] following::OL[1]/LI[3]/ol[1]/li[3]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script type="text/javascript">
|
||||
var test = async_test() // This "test" does not actually do any assertations. It's just there to have multiple, separate, asyncronous sub-tests.
|
||||
var expectations = {
|
||||
'Referer header': 'referer: '+(location.href.replace(/[^/]*$/, ''))+"resources/workerxhr-origin-referrer.js\n",
|
||||
'Origin header': 'origin: '+location.protocol+'//'+location.hostname+((location.port === "")?"":":"+location.port)+'\n',
|
||||
'Request URL test' : (location.href.replace(/[^/]*$/, ''))+'resources/requri.py?full'
|
||||
}
|
||||
// now start the worker
|
||||
var worker = new Worker("resources/workerxhr-origin-referrer.js", true)
|
||||
worker.onmessage = function (e) {
|
||||
var subtest = async_test(e.data.test)
|
||||
subtest.step(function(){
|
||||
var thisExpectation = expectations[e.data.test]
|
||||
delete expectations[e.data.test]
|
||||
assert_equals(e.data.result, thisExpectation)
|
||||
subtest.done()
|
||||
})
|
||||
var allDone = true
|
||||
for(var prop in expectations){
|
||||
allDone = false
|
||||
}
|
||||
if(allDone){
|
||||
test.step(function(){
|
||||
test.done()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>XMLHttpRequest: relative URLs in worker scripts resolved by script URL</title>
|
||||
<link rel="stylesheet" href="/resources/testharness.css" />
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::OL[1]/LI[3] following::OL[1]/LI[3]/ol[1]/li[1]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script type="text/javascript">
|
||||
var test = async_test()
|
||||
var worker = new Worker("resources/workerxhr-simple.js")
|
||||
worker.onmessage = function (e) {
|
||||
test.step(function(){
|
||||
assert_equals(e.data, 'PASSED')
|
||||
test.done()
|
||||
})
|
||||
}
|
||||
worker.postMessage('start')
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: open() - user/pass argument and non same-origin URL doesn't throw</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-open()-method" data-tested-assertations="following::ol/li[9]/ol/li[1] following::ol/li[9]/ol/li[2] following::ol/li[15]/ol/li[1]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var m = "GET",
|
||||
u = "http://test2.w3.org/",
|
||||
a = false
|
||||
test(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
client.open(m, u, a, "x")
|
||||
assert_equals(client.readyState, 1, "open() was successful - 1")
|
||||
var client2 = new XMLHttpRequest()
|
||||
client2.open(m, u, a, "x", "x")
|
||||
assert_equals(client2.readyState, 1, "open() was successful - 2")
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,26 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: overrideMimeType() in DONE state</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-overridemimetype()-method" data-tested-assertations="/following::ol/li[1]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test();
|
||||
var client = new XMLHttpRequest();
|
||||
client.onreadystatechange = test.step_func( function() {
|
||||
if (client.readyState !== 4) return;
|
||||
assert_throws("InvalidStateError", function() { client.overrideMimeType('application/xml;charset=Shift-JIS'); });
|
||||
assert_equals(client.responseXML, null);
|
||||
test.done();
|
||||
});
|
||||
client.open("GET", "resources/status.py?type="+encodeURIComponent('text/plain;charset=iso-8859-1')+'&content=%3Cmsg%3E%83%65%83%58%83%67%3C%2Fmsg%3E');
|
||||
client.send();
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,34 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: overrideMimeType() in HEADERS RECEIVED state, enforcing Shift-JIS encoding</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-overridemimetype()-method" data-tested-assertations="/following::ol/li[1] /following::ol/li[4]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test();
|
||||
var client = new XMLHttpRequest();
|
||||
var readyState2Reached = false;
|
||||
client.onreadystatechange = test.step_func( function() {
|
||||
if(client.readyState===2){
|
||||
readyState2Reached = true;
|
||||
try{
|
||||
client.overrideMimeType('text/plain;charset=Shift-JIS');
|
||||
}catch(e){
|
||||
assert_unreached('overrideMimeType should not throw in state 2');
|
||||
}
|
||||
}
|
||||
if (client.readyState !== 4) return;
|
||||
assert_equals( readyState2Reached, true, "readyState = 2 event fired" );
|
||||
assert_equals( client.responseText, 'テスト', 'overrideMimeType() in HEADERS RECEIVED state set encoding' );
|
||||
test.done();
|
||||
});
|
||||
client.open("GET", "resources/status.py?type="+encodeURIComponent('text/html;charset=UTF-8')+'&content=%83%65%83%58%83%67');
|
||||
client.send( '' );
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,25 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: overrideMimeType() in unsent state, invalid MIME types</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-overridemimetype()-method" data-tested-assertations="/following::ol/li[2]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
test(function() {
|
||||
var client = new XMLHttpRequest();
|
||||
assert_throws("SyntaxError", function() { client.overrideMimeType('text\\plain;charset=Shift-JIS'); });
|
||||
assert_throws("SyntaxError", function() { client.overrideMimeType('text plain;charset=Shift-JIS'); });
|
||||
assert_throws("SyntaxError", function() { client.overrideMimeType('text\nplain;charset=Shift-JIS'); });
|
||||
assert_throws("SyntaxError", function() { client.overrideMimeType('cahrset=Shift-JIS'); });
|
||||
assert_throws("SyntaxError", function() { client.overrideMimeType(null); });
|
||||
assert_throws("SyntaxError", function() { client.overrideMimeType(50212); });
|
||||
assert_throws("SyntaxError", function() { client.overrideMimeType( (new Array(1000)).join('a/b/c/') ); });
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,32 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: overrideMimeType() in LOADING state</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-overridemimetype()-method" data-tested-assertations="/following::ol/li[1]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test();
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest();
|
||||
client.onreadystatechange = test.step_func(function() {
|
||||
if (client.readyState === 3){
|
||||
assert_throws("InvalidStateError", function(){
|
||||
client.overrideMimeType('application/xml;charset=Shift-JIS');
|
||||
});
|
||||
}else if(client.readyState===4){
|
||||
assert_equals(client.responseXML, null);
|
||||
test.done();
|
||||
}
|
||||
});
|
||||
client.open("GET", "resources/status.py?type="+encodeURIComponent('text/plain;charset=iso-8859-1')+'&content=%3Cmsg%3E%83%65%83%58%83%67%3C%2Fmsg%3E');
|
||||
client.send();
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,27 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: overrideMimeType() in open state, enforcing UTF-8 encoding</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-overridemimetype()-method" data-tested-assertations="/following::ol/li[3] /following::ol/li[4]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test();
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest();
|
||||
client.onreadystatechange = function() {
|
||||
if (client.readyState !== 4) return;
|
||||
assert_equals( client.responseText, 'テスト' );
|
||||
test.done();
|
||||
};
|
||||
client.open("GET", "resources/status.py?type="+encodeURIComponent('text/html;charset=Shift-JIS')+'&content='+encodeURIComponent('テスト'));
|
||||
client.overrideMimeType('text/plain;charset=UTF-8');
|
||||
client.send( '' );
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,34 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: overrideMimeType() in open state, XML MIME type with UTF-8 charset</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-overridemimetype()-method" data-tested-assertations="/following::ol/li[3] /following::ol/li[4]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test();
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest();
|
||||
client.onreadystatechange = function() {
|
||||
if (client.readyState !== 4) return;
|
||||
try{
|
||||
var str = client.responseXML.documentElement.tagName+client.responseXML.documentElement.firstChild.tagName+client.responseXML.documentElement.firstChild.textContent;
|
||||
}catch(e){
|
||||
assert_unreached('Exception when reading responseXML');
|
||||
}
|
||||
assert_equals( client.responseXML.documentElement.tagName, 'test' );
|
||||
assert_equals( client.responseXML.documentElement.firstChild.tagName, 'message' );
|
||||
assert_equals( client.responseXML.documentElement.firstChild.textContent, 'Hello World!' );
|
||||
test.done();
|
||||
};
|
||||
client.open("GET", "resources/status.py?type="+encodeURIComponent('text/plain;charset=Shift-JIS')+'&content='+encodeURIComponent('<test><message>Hello World!</message></test>'));
|
||||
client.overrideMimeType('application/xml;charset=UTF-8');
|
||||
client.send();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,27 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: overrideMimeType() in unsent state, enforcing Shift-JIS encoding</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-overridemimetype()-method" data-tested-assertations="/following::ol/li[3] /following::ol/li[4]" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test();
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest();
|
||||
client.overrideMimeType('text/plain;charset=Shift-JIS');
|
||||
client.onreadystatechange = function() {
|
||||
if (client.readyState !== 4) return;
|
||||
assert_equals( client.responseText, 'テスト' );
|
||||
test.done();
|
||||
};
|
||||
client.open("GET", "resources/status.py?type="+encodeURIComponent('text/html;charset=iso-8859-1')+'&content=%83%65%83%58%83%67');
|
||||
client.send( '' );
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,77 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: progress events and GZIP encoding</title>
|
||||
<meta name="timeout" content="long">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#firing-events-using-the-progressevent-interface-for-http" data-tested-assertations="following::p[contains(text(),'content-encodings')]" />
|
||||
<!-- TODO: find better spec reference when https://www.w3.org/Bugs/Public/show_bug.cgi?id=25587 is fixed -->
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var test = async_test()
|
||||
test.step(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
/*
|
||||
|
||||
Two behaviours are considered acceptable, so there are two ways to
|
||||
pass this test
|
||||
|
||||
a) Set data for the compressed resource:
|
||||
* event.total reflects the Content-length of the gzipp'ed resource
|
||||
* event.loaded how many gzipped bytes have arrived over the wire so far
|
||||
* lengthComputable is true
|
||||
|
||||
or
|
||||
|
||||
b) If the implementation does not provide progress details for the compressed
|
||||
resource, set
|
||||
* lengthComputable to false
|
||||
* event.total to 0
|
||||
* event.loaded to the number of bytes available so far after gzip decoding
|
||||
|
||||
Implications of this are tested here as follows:
|
||||
|
||||
* If lengthComputable is true:
|
||||
* Event.total must match Content-length header
|
||||
* event.loaded should be a smaller number while resource is loading
|
||||
and match Content-length when loading is finished
|
||||
* Setting event.loaded to equal event.total for each progress event if the
|
||||
resource is not fully downloaded would be cheating
|
||||
|
||||
* If lengthComputable is false:
|
||||
* event.total should be 0
|
||||
* event.loaded should be the length of the decompressed content, i.e.
|
||||
bigger than Content-length header value when finished loading
|
||||
|
||||
*/
|
||||
client.addEventListener('loadend', test.step_func(function(e){
|
||||
var len = parseInt(client.getResponseHeader('content-length'), 10)
|
||||
if(e.lengthComputable){
|
||||
assert_equals(e.total, len, 'event.total is content-length')
|
||||
assert_equals(e.loaded, len, 'event.loaded should be content-length at loadend')
|
||||
}else{
|
||||
assert_equals(e.total, 0, 'if implementation can\'t compute event.total for gzipped content it is 0')
|
||||
assert_true(e.loaded >= len, 'event.loaded should be set even if total is not computable')
|
||||
}
|
||||
test.done();
|
||||
}), false)
|
||||
client.addEventListener('progress', test.step_func(function(e){
|
||||
if(e.lengthComputable && e.total && e.loaded && e.target.readyState < 4){
|
||||
assert_not_equals(e.total, e.loaded, 'total should not equal loaded while download/decode is incomplete')
|
||||
// We should only do this assertation once
|
||||
// it's theoretically possible that all the data would get in
|
||||
// and a progress event fire before the readyState switches from 3 to 4 -
|
||||
// in this case we might report bogus and random failures. Better to remove the event listener again..
|
||||
client.removeEventListener('progress', arguments.callee, false);
|
||||
}
|
||||
}), false)
|
||||
// image.gif is 165375 bytes compressed. Sending 45000 bytes at a time with 1 second delay will load it in 4 seconds
|
||||
client.open("GET", "resources/image.gif?pipe=gzip|trickle(45000:d1:r2)", true)
|
||||
client.send()
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
31
tests/wpt/web-platform-tests/XMLHttpRequest/readme.txt
Normal file
31
tests/wpt/web-platform-tests/XMLHttpRequest/readme.txt
Normal file
|
@ -0,0 +1,31 @@
|
|||
Currently this testsuite tries to provide tests for XMLHttpRequest level 1.
|
||||
This test suite is not stable and is still under development. Tests may
|
||||
contain bugs and may change over time as a result of those bugs being fixed.
|
||||
|
||||
When more browsers implement XMLHttpRequest level 2 this testsuite will
|
||||
slowly evolve most likely.
|
||||
|
||||
http://dev.w3.org/2006/webapi/XMLHttpRequest/
|
||||
http://dev.w3.org/2006/webapi/XMLHttpRequest-2/
|
||||
|
||||
If the folders above give the status of the feature tested you can assume
|
||||
this is against level 1 unless explicitly stated otherwise.
|
||||
|
||||
NOTE: readyState and onreadystatechange are tested throughout the various
|
||||
tests. statusText is tested together with status.
|
||||
|
||||
NOTE: open-url-base* have absolute paths in them. They need to be adjusted
|
||||
on a per location basis.
|
||||
|
||||
NOTE: open-url-base-inserted-after-open.htm, open-url-base-inserted.htm,
|
||||
send-authentication.htm and open-url-base.htm refer to localhost.
|
||||
|
||||
|
||||
TESTS THAT ARE UNSTABLE AND (PROBABLY) NEED CHANGES
|
||||
responsexml-basic (see email WHATWG)
|
||||
send-authentication (see "user:password" debacle)
|
||||
|
||||
|
||||
TESTS NOT STARTED ON YET
|
||||
|
||||
<iframe> document.domain = w3.org create cross-origin xhr object
|
|
@ -0,0 +1,4 @@
|
|||
def main(request, response):
|
||||
return [("Content-Type", "text/plain"),
|
||||
request.headers.get("Accept-Language", "NO")]
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
def main(request, response):
|
||||
return [("Content-Type", "text/plain")], request.headers.get("accept", "NO")
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
import imp
|
||||
import os
|
||||
|
||||
here = os.path.split(os.path.abspath(__file__))[0]
|
||||
|
||||
def main(request, response):
|
||||
auth = imp.load_source("", os.path.join(here,
|
||||
"..",
|
||||
"authentication.py"))
|
||||
return auth.main(request, response)
|
|
@ -0,0 +1,10 @@
|
|||
import imp
|
||||
import os
|
||||
|
||||
here = os.path.split(os.path.abspath(__file__))[0]
|
||||
|
||||
def main(request, response):
|
||||
auth = imp.load_source("", os.path.join(here,
|
||||
"..",
|
||||
"authentication.py"))
|
||||
return auth.main(request, response)
|
|
@ -0,0 +1,20 @@
|
|||
import imp
|
||||
import os
|
||||
|
||||
def main(request, response):
|
||||
response.headers.set('Access-Control-Allow-Origin', request.headers.get("origin"));
|
||||
response.headers.set('Access-Control-Allow-Credentials', 'true');
|
||||
response.headers.set('Access-Control-Allow-Methods', 'GET');
|
||||
response.headers.set('Access-Control-Allow-Headers', 'authorization, x-user, x-pass');
|
||||
response.headers.set('Access-Control-Expose-Headers', 'x-challenge, xhr-user, ses-user');
|
||||
auth = imp.load_source("", os.path.join(os.path.abspath(os.curdir),
|
||||
"XMLHttpRequest",
|
||||
"resources",
|
||||
"authentication.py"))
|
||||
if request.method == "OPTIONS":
|
||||
return ""
|
||||
else:
|
||||
return auth.main(request, response)
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
import imp
|
||||
import os
|
||||
|
||||
here = os.path.split(os.path.abspath(__file__))[0]
|
||||
|
||||
def main(request, response):
|
||||
auth = imp.load_source("", os.path.join(here,
|
||||
"..",
|
||||
"authentication.py"))
|
||||
return auth.main(request, response)
|
|
@ -0,0 +1,10 @@
|
|||
import imp
|
||||
import os
|
||||
|
||||
here = os.path.split(os.path.abspath(__file__))[0]
|
||||
|
||||
def main(request, response):
|
||||
auth = imp.load_source("", os.path.join(here,
|
||||
"..",
|
||||
"authentication.py"))
|
||||
return auth.main(request, response)
|
|
@ -0,0 +1,13 @@
|
|||
def main(request, response):
|
||||
if request.auth.username == 'usr' and request.auth.password == 'secret':
|
||||
response.headers.set('Content-type', 'text/plain')
|
||||
content = ""
|
||||
else:
|
||||
response.status = 401
|
||||
response.headers.set('Status', '401 Authorization required')
|
||||
response.headers.set('WWW-Authenticate', 'Basic realm="test"')
|
||||
content = 'User name/password wrong or not given: '
|
||||
|
||||
content += "%s\n%s" % (request.auth.username,
|
||||
request.auth.password)
|
||||
return content
|
|
@ -0,0 +1,13 @@
|
|||
def main(request, response):
|
||||
if request.auth.username == 'usr' and request.auth.password == 'secret':
|
||||
response.headers.set('Content-type', 'text/plain')
|
||||
content = ""
|
||||
else:
|
||||
response.status = 401
|
||||
response.headers.set('Status', '401 Authorization required')
|
||||
response.headers.set('WWW-Authenticate', 'Basic realm="test"')
|
||||
content = 'User name/password wrong or not given: '
|
||||
|
||||
content += "%s\n%s" % (request.auth.username,
|
||||
request.auth.password)
|
||||
return content
|
|
@ -0,0 +1,32 @@
|
|||
def main(request, response):
|
||||
if "logout" in request.GET:
|
||||
return ((401, "Unauthorized"),
|
||||
[("WWW-Authenticate", 'Basic realm="test"')],
|
||||
"Logged out, hopefully")
|
||||
|
||||
session_user = request.auth.username
|
||||
session_pass = request.auth.password
|
||||
expected_user_name = request.headers.get("X-User", None)
|
||||
|
||||
token = expected_user_name
|
||||
if session_user is None and session_pass is None:
|
||||
if token is not None and request.server.stash.take(token) is not None:
|
||||
return 'FAIL (did not authorize)'
|
||||
else:
|
||||
if token is not None:
|
||||
request.server.stash.put(token, "1")
|
||||
status = (401, 'Unauthorized')
|
||||
headers = [('WWW-Authenticate', 'Basic realm="test"'),
|
||||
('XHR-USER', expected_user_name),
|
||||
('SES-USER', session_user)]
|
||||
return status, headers, 'FAIL (should be transparent)'
|
||||
else:
|
||||
if request.server.stash.take(token) == "1":
|
||||
challenge = "DID"
|
||||
else:
|
||||
challenge = "DID-NOT"
|
||||
headers = [('XHR-USER', expected_user_name),
|
||||
('SES-USER', session_user),
|
||||
("X-challenge", challenge)]
|
||||
return headers, session_user + "\n" + session_pass;
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
def main(request, response):
|
||||
chunks = ["First chunk\r\n",
|
||||
"Second chunk\r\n",
|
||||
"Yet another (third) chunk\r\n",
|
||||
"Yet another (fourth) chunk\r\n",
|
||||
]
|
||||
response.headers.set("Transfer-Encoding", "chunked");
|
||||
response.headers.set("Trailer", "X-Test-Me");
|
||||
response.headers.set("Content-Type", "text/plain");
|
||||
response.write_status_headers()
|
||||
|
||||
for value in chunks:
|
||||
response.writer.write("%d\r\n" % len(value))
|
||||
response.writer.write(value)
|
||||
response.writer.write("\r\n")
|
||||
response.writer.write("0\r\n")
|
||||
response.writer.write("X-Test-Me: Trailer header value\r\n\r\n")
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
def main(request, response):
|
||||
tag = request.GET.first("tag", None)
|
||||
match = request.headers.get("If-None-Match", None)
|
||||
date = request.GET.first("date", "")
|
||||
modified = request.headers.get("If-Modified-Since", None)
|
||||
if tag:
|
||||
response.headers.set("ETag", '"%s"' % tag)
|
||||
elif date:
|
||||
response.headers.set("Last-Modified", date)
|
||||
|
||||
if ((match is not None and match == tag) or
|
||||
(modified is not None and modified == date)):
|
||||
response.status = (304, "SUPERCOOL")
|
||||
return ""
|
||||
else:
|
||||
response.headers.set("Content-Type", "text/plain")
|
||||
return "MAYBE NOT"
|
|
@ -0,0 +1,18 @@
|
|||
def main(request, response):
|
||||
response_ctype = ''
|
||||
|
||||
if "response_charset_label" in request.GET:
|
||||
response_ctype = ";charset=" + request.GET.first("response_charset_label")
|
||||
|
||||
headers = [("Content-type", "text/plain" + response_ctype),
|
||||
("X-Request-Method", request.method),
|
||||
("X-Request-Query", request.url_parts.query if request.url_parts.query else "NO"),
|
||||
("X-Request-Content-Length", request.headers.get("Content-Length", "NO")),
|
||||
("X-Request-Content-Type", request.headers.get("Content-Type", "NO"))]
|
||||
|
||||
if "content" in request.GET:
|
||||
content = request.GET.first("content")
|
||||
else:
|
||||
content = request.body
|
||||
|
||||
return headers, content
|
|
@ -0,0 +1,19 @@
|
|||
import time
|
||||
|
||||
def main(request, response):
|
||||
headers = [("Access-Control-Allow-Origin", "*"),
|
||||
("Access-Control-Allow-Credentials", "true"),
|
||||
("Access-Control-Allow-Methods", "GET, POST, PUT, FOO"),
|
||||
("Access-Control-Allow-Headers", "x-test, x-foo"),
|
||||
("Access-Control-Expose-Headers", "x-request-method, x-request-content-type, x-request-query, x-request-content-length")]
|
||||
|
||||
if "delay" in request.GET:
|
||||
delay = int(request.GET.first("delay"))
|
||||
time.sleep(delay)
|
||||
|
||||
headers.append(("X-Request-Method", request.method))
|
||||
headers.append(("X-Request-Query", request.url_parts.query if request.url_parts.query else "NO"))
|
||||
headers.append(("X-Request-Content-Length", request.headers.get("Content-Length", "NO")))
|
||||
headers.append(("X-Request-Content-Type", request.headers.get("Content-Type", "NO")))
|
||||
|
||||
return headers, "Test"
|
|
@ -0,0 +1,6 @@
|
|||
import time
|
||||
|
||||
def main(request, response):
|
||||
delay = float(request.GET.first("ms", 500))
|
||||
time.sleep(delay / 1E3);
|
||||
return [("Content-type", "text/plain")], "TEST_DELAY"
|
|
@ -0,0 +1 @@
|
|||
bottom
|
|
@ -0,0 +1,2 @@
|
|||
def main(request, response):
|
||||
return "id:%s;value:%s;" % (request.POST.first("id"), request.POST.first("value"))
|
|
@ -0,0 +1,23 @@
|
|||
import gzip as gzip_module
|
||||
from cStringIO import StringIO
|
||||
|
||||
def main(request, response):
|
||||
if "content" in request.GET:
|
||||
output = request.GET["content"]
|
||||
else:
|
||||
output = request.body
|
||||
|
||||
out = StringIO()
|
||||
with gzip_module.GzipFile(fileobj=out, mode="w") as f:
|
||||
f.write(output)
|
||||
output = out.getvalue()
|
||||
|
||||
headers = [("Content-type", "text/plain"),
|
||||
("Content-Encoding", "gzip"),
|
||||
("X-Request-Method", request.method),
|
||||
("X-Request-Query", request.url_parts.query if request.url_parts.query else "NO"),
|
||||
("X-Request-Content-Length", request.headers.get("Content-Length", "NO")),
|
||||
("X-Request-Content-Type", request.headers.get("Content-Type", "NO")),
|
||||
("Content-Length", len(output))]
|
||||
|
||||
return headers, output
|
|
@ -0,0 +1,12 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
def main(request, response):
|
||||
response.headers.set("Content-Type", "text/plain")
|
||||
response.headers.set("X-Custom-Header", "test")
|
||||
response.headers.set("Set-Cookie", "test")
|
||||
response.headers.set("Set-Cookie2", "test")
|
||||
response.headers.set("X-Custom-Header-Empty", "")
|
||||
response.headers.set("X-Custom-Header-Comma", "1")
|
||||
response.headers.append("X-Custom-Header-Comma", "2")
|
||||
response.headers.set("X-Custom-Header-Bytes", "…")
|
||||
return "TEST"
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue