Bug 1014466 - Part 3: Test case for async XHR reuse. r=khuey

This commit is contained in:
Shian-Yow Wu 2014-06-06 12:17:55 +08:00
parent 04a13e40b5
commit 0e83486db9
5 changed files with 112 additions and 0 deletions

View File

@ -0,0 +1 @@
1234567890

View File

@ -0,0 +1 @@
ABCDEFGH

View File

@ -0,0 +1,64 @@
/**
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
function ok(a, msg) {
postMessage({type: "status", status: !!a, msg: msg });
}
onmessage = function(event) {
function getResponse(url) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, false);
xhr.send();
return xhr.responseText;
}
const testFile1 = "bug1014466_data1.txt";
const testFile2 = "bug1014466_data2.txt";
const testData1 = getResponse(testFile1);
const testData2 = getResponse(testFile2);
var response_count = 0;
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == xhr.DONE && xhr.status == 200) {
response_count++;
switch (response_count) {
case 1:
ok(xhr.responseText == testData1, "Check data 1");
test_data2();
break;
case 2:
ok(xhr.responseText == testData2, "Check data 2");
postMessage({type: "finish" });
break;
default:
ok(false, "Unexpected response received");
postMessage({type: "finish" });
break;
}
}
}
xhr.onerror = function(event) {
ok(false, "Got an error event: " + event);
postMessage({type: "finish" });
}
function test_data1() {
xhr.open("GET", testFile1, true);
xhr.responseType = "text";
xhr.send();
}
function test_data2() {
xhr.abort();
xhr.open("GET", testFile2, true);
xhr.responseType = "text";
xhr.send();
}
test_data1();
}

View File

@ -2,6 +2,9 @@
support-files = support-files =
WorkerTest_badworker.js WorkerTest_badworker.js
atob_worker.js atob_worker.js
bug1014466_data1.txt
bug1014466_data2.txt
bug1014466_worker.js
bug1020226_worker.js bug1020226_worker.js
bug1020226_frame.html bug1020226_frame.html
clearTimeouts_worker.js clearTimeouts_worker.js
@ -80,6 +83,7 @@ support-files =
[test_blobWorkers.html] [test_blobWorkers.html]
[test_bug949946.html] [test_bug949946.html]
[test_bug1010784.html] [test_bug1010784.html]
[test_bug1014466.html]
[test_bug1020226.html] [test_bug1020226.html]
[test_chromeWorker.html] [test_chromeWorker.html]
[test_clearTimeouts.html] [test_clearTimeouts.html]

View File

@ -0,0 +1,42 @@
<!--
2 Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/
4 -->
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1014466
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1014466</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1014466">Mozilla Bug 1014466</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
var worker = new Worker("bug1014466_worker.js");
worker.onmessage = function(event) {
if (event.data.type == 'finish') {
SimpleTest.finish();
} else if (event.data.type == 'status') {
ok(event.data.status, event.data.msg);
}
};
worker.postMessage(true);
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>