forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1014466 - Part 3: Test case for async XHR reuse. r=khuey
- Loading branch information
Showing
5 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1234567890 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ABCDEFGH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |