Skip to content

Commit

Permalink
Merge pull request #128 from w3c/hallvors/XHRtestBugFixes2
Browse files Browse the repository at this point in the history
XHR test bug fixes - second attempt
We are basically done with the review of this full set in https://critic.hoppipolla.co.uk/r/134. Further refinements are to be proceeded bit by bit during the interop.
  • Loading branch information
jungkees committed Jul 4, 2013
2 parents 8b2c935 + 826e780 commit 9dde2fb
Show file tree
Hide file tree
Showing 170 changed files with 1,951 additions and 330 deletions.
3 changes: 3 additions & 0 deletions XMLHttpRequest/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,6 @@ xmlhttprequest-timeout-worker-simple.html
xmlhttprequest-timeout-worker-synconworker.html
xmlhttprequest-timeout-worker-twice.html
xmlhttprequest-unsent.htm
manual send-authentication-existing-session-interactive.htm
manual send-authentication-prompt-interactive.htm
manual send-authentication-prompt-interactive-2.htm
18 changes: 16 additions & 2 deletions XMLHttpRequest/abort-after-send.htm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
<title>XMLHttpRequest: abort() after send()</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-abort()-method" data-tested-assertations="/following-sibling::ol/li[1] /following-sibling::ol/li[3] /following-sibling::ol/li[6] /following-sibling::ol/li[6]/ol/li[1] /following-sibling::ol/li[6]/ol/li[3] /following-sibling::ol/li[7]" />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#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="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-responsetext-attribute" data-tested-assertations="following::ol/li[3]" />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-responsexml-attribute" data-tested-assertations="following::ol/li[3]" />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#dom-xmlhttprequest-getallresponseheaders" data-tested-assertations="following::ol/li[2]" />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#dom-xmlhttprequest-getresponseheader" data-tested-assertations="following::ol/li[2]" />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-status-attribute" data-tested-assertations="following::ol/li[2]" />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-statustext-attribute" data-tested-assertations="following::ol/li[2]" />
<link rel="help" href="http://xhr.spec.whatwg.org/#infrastructure-for-the-send()-method" data-tested-assertations="following::dt[1] following::dd[1]" />
</head>
<body>
<div id="log"></div>
Expand All @@ -14,7 +21,7 @@
var client = new XMLHttpRequest(),
control_flag = false,
result = [],
expected = [1, 4] // open() -> 1, abort() -> 4
expected = [1, 4, 'progress', 'abort', 'loadend'] // open() -> 1, abort() -> 4
client.onreadystatechange = function() {
test.step(function() {
result.push(client.readyState)
Expand All @@ -25,16 +32,23 @@
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>
Expand Down
2 changes: 1 addition & 1 deletion XMLHttpRequest/abort-during-done.htm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>XMLHttpRequest: abort() during DONE</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-abort()-method" data-tested-assertations="/following-sibling::ol/li[6] /following-sibling::ol/li[7]" />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-abort()-method" data-tested-assertations="following-sibling::ol/li[4] following-sibling::ol/li[5]" />
</head>
<body>
<div id="log"></div>
Expand Down
6 changes: 4 additions & 2 deletions XMLHttpRequest/abort-during-open.htm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<title>XMLHttpRequest: abort() during OPEN</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-abort()-method" data-tested-assertations="/following-sibling::ol/li[6] /following-sibling::ol/li[7]" />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-abort()-method" data-tested-assertations="following-sibling::ol/li[4] following-sibling::ol/li[5]" />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-send()-method" data-tested-assertations="following-sibling::ol/li[1]" />
</head>
<body>
<div id="log"></div>
Expand All @@ -18,8 +19,9 @@
assert_unreached()
})
}
client.abort();
client.abort()
assert_equals(client.readyState, 0)
assert_throws("InvalidStateError", function() { client.send("test") }, "calling send() after abort()")
})
test.done()
</script>
Expand Down
2 changes: 1 addition & 1 deletion XMLHttpRequest/abort-during-unsent.htm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>XMLHttpRequest: abort() during UNSENT</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-abort()-method" data-tested-assertations="/following-sibling::ol/li[6] /following-sibling::ol/li[7]" />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-abort()-method" data-tested-assertations="following-sibling::ol/li[4] following-sibling::ol/li[5]" />
</head>
<body>
<div id="log"></div>
Expand Down
42 changes: 42 additions & 0 deletions XMLHttpRequest/abort-during-upload.htm
Original file line number Diff line number Diff line change
@@ -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="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#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="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#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.php?ms=1000")
client.addEventListener('progress', logEvt)
client.addEventListener('abort', logEvt)
client.addEventListener('loadend', function (e) {
logEvt(e)
test.step(function() {
assert_equals(client.readyState, 0)
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>
15 changes: 7 additions & 8 deletions XMLHttpRequest/abort-event-abort.htm
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
<head>
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-abort()-method" data-tested-assertations="following-sibling::ol/li[4]/ol/li[5]" />
<script src="/resources/testharness.js"></script>
<title>XMLHttpRequest: The abort() method: Fire a progress event named abort</title>
<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();
var test = async_test()

test.step(function()
{
var xhr = new XMLHttpRequest();
var xhr = new XMLHttpRequest()

xhr.onreadystatechange = function()
{
Expand All @@ -31,14 +31,13 @@
{
test.step(function()
{
assert_true(e instanceof ProgressEvent);
assert_equals(e.type, "abort");
test.done();
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.php", true);
xhr.send();
xhr.open("GET", "./resources/content.php", true); // This should cause a readystatechange event that calls abort()
assert_throws("InvalidStateError", function(){ xhr.send() })
test.done()
});
</script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion XMLHttpRequest/abort-event-listeners.htm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<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="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-abort()-method" data-tested-assertations="/following-sibling::ol/li[6] /following-sibling::ol/li[7]" />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-abort()-method" data-tested-assertations="following-sibling::ol/li[6] following-sibling::ol/li[7]" />
</head>
<body>
<div id="log"></div>
Expand Down
15 changes: 14 additions & 1 deletion XMLHttpRequest/data-uri-basic.htm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<title>XMLHttpRequest: basic data uri</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#data:-urls-and-http" data-tested-assertations="/following::ul[1] /following::ul[2]" />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#data:-urls-and-http" data-tested-assertations="following::ul/li[2] following::ul/li[3] following::ul/li[4] following::ul/li[5]" />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-send()-method" data-tested-assertations="following::ul/li[10]/dl/dt[2]" />

<div id="log"></div>

Expand All @@ -24,12 +25,24 @@
do_test("GET responseText", 'GET', "data:text/plain,Hello, World!", function (client) {
assert_equals(client.responseText, "Hello, World!")
});
do_test("GET responseText base64", 'GET', "data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D", function (client) {
assert_equals(client.responseText, "Hello, World!")
});
do_test("GET status", 'GET', "data:text/plain,Hello, World!", function (client) {
assert_equals(client.status, 200);
});
do_test("GET statusText", 'GET', "data:text/plain,Hello, World!", function (client) {
assert_equals(client.statusText, "OK");
});
do_test("GET Content-Type", 'GET', "data:text/plain,Hello, World!", function (client) {
assert_equals(client.getResponseHeader('Content-Type'), 'text/plain');
});
do_test("GET Content-Type with param", 'GET', "data:text/html;charset=utf-8,<p>Hello, World!", function (client) {
assert_equals(client.getResponseHeader('Content-Type'), 'text/html;charset=utf-8');
});
do_test("GET getAllResponseHeaders", 'GET', "data:text/plain,Hello, World!", function (client) {
assert_equals(client.getAllResponseHeaders(), 'content-type: text/plain');
});
do_test("POST responseText", 'POST', "data:text/plain,Hello, World!", function (client) {
assert_equals(client.responseText, null);
});
Expand Down
10 changes: 5 additions & 5 deletions XMLHttpRequest/data-uri.htm
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<title>XMLHttpRequest: data uri</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#data:-urls-and-http" data-tested-assertations="/following::ul[1] /following::ul[2]" />

<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#data:-urls-and-http" data-tested-assertations="following::ul/li[1] following::ul/li[2] following::ul/li[4]" />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-send()-method" data-tested-assertations="following::ul/li[10]/dl/dt[2]" />
<div id="log"></div>

<script>
function do_test(method, uri, charset) {
function do_test(method, uri, charset, namePostfix) {
if (typeof charset === 'undefined' || charset === null) charset = 'text/plain';
var test = async_test("XHR method " + method + " with charset " + charset);
var test = async_test("XHR method " + method + " with charset " + charset+(namePostfix||''));
test.step(function() {
var client = new XMLHttpRequest();
client.onreadystatechange = test.step_func(function () {
Expand All @@ -30,7 +30,7 @@
});
}
do_test('GET', "data:text/plain,Hello, World!");
do_test('GET', "data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==");
do_test('GET', "data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==", undefined, " (base64)");
do_test('GET', "data:text/html,Hello, World!", 'text/html');
do_test('GET', "data:image/png,Hello, World!", 'image/png');
do_test('POST', "data:text/plain,Hello, World!");
Expand Down
6 changes: 3 additions & 3 deletions XMLHttpRequest/event-abort.htm
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<title>XMLHttpRequest: abort event</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#handler-xhr-onabort" data-tested-assertations="/../.." />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#event-xhr-abort" data-tested-assertations="/../.." />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#dom-xmlhttprequest-abort" data-tested-assertations="/following-sibling::ol//ol//ol/li[3]" />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#handler-xhr-onabort" data-tested-assertations="../.." />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#event-xhr-abort" data-tested-assertations="../.." />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#dom-xmlhttprequest-abort" data-tested-assertations="following::ol//ol//ol/li[3]" />
</head>
<body>
<div id="log"></div>
Expand Down
13 changes: 8 additions & 5 deletions XMLHttpRequest/event-load.htm
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<!doctype html>
<meta charset=utf-8>
<title>XMLHttpRequest: load event</title>
<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="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#handler-xhr-onload" data-tested-assertations="/../.." />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#event-xhr-load" data-tested-assertations="/../.." />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#switch-done" data-tested-assertations="/following-sibling::ol//li[6]" />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#handler-xhr-onload" data-tested-assertations="../.." />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#event-xhr-load" data-tested-assertations="../.." />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#infrastructure-for-the-send()-method" data-tested-assertations="following::a[contains(@href,'#switch-done')]/.." />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#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() {
client.onload = test.step_func(function(e) {
assert_true(e instanceof ProgressEvent);
assert_equals(e.type, "load");
assert_equals(client.readyState, 4);
test.done();
});
Expand Down
6 changes: 5 additions & 1 deletion XMLHttpRequest/event-loadend.htm
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#handler-xhr-onloadend" data-tested-assertations="/../.." />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#event-xhr-loadend" data-tested-assertations="/../.." />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#infrastructure-for-the-send()-method" data-tested-assertations="/following-sibling::ol/li[10]" />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#infrastructure-for-the-send()-method" data-tested-assertations="following::a[contains(@href,'#switch-done')]/.." />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#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() {
client.onloadend = test.step_func(function(e) {
assert_true(e instanceof ProgressEvent);
assert_equals(e.type, "loadend");
test.done();
});
client.onreadystatechange = function() {
Expand Down
14 changes: 8 additions & 6 deletions XMLHttpRequest/event-loadstart.htm
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@
<title>XMLHttpRequest: loadstart event</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#handler-xhr-onloadstart" data-tested-assertations="/../.." />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#event-xhr-loadstart" data-tested-assertations="/../.." />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-send()-method" data-tested-assertations="/following-sibling::ol/li[9]//li[2]" />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#handler-xhr-onloadstart" data-tested-assertations="../.." />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#event-xhr-loadstart" data-tested-assertations="../.." />
<link rel="help" href="http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#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() {
client.onloadstart = test.step_func(function(e) {
assert_true(e instanceof ProgressEvent);
assert_equals(e.type, "loadstart");
assert_equals(client.readyState, 1);
test.done();
});
client.open("GET", "resources/well-formed.xml");
client.send(null);
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>
Expand Down
Loading

0 comments on commit 9dde2fb

Please sign in to comment.