4 https://bugzilla.mozilla.org/show_bug.cgi?id=218236
7 <title>Test for Bug
218236</title>
8 <script type=
"text/javascript" src=
"/MochiKit/MochiKit.js"></script>
9 <script type=
"text/javascript" src=
"/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css" />
13 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=218236">Mozilla Bug
218236</a>
15 <div id=
"content" style=
"display: none">
19 <script class=
"testbody" type=
"text/javascript">
21 /** Test for Bug
218236 **/
23 SimpleTest.waitForExplicitFinish();
27 var url_200 = window.location.href;
28 var url_404 = url_200.replace(/[^/]+$/,
"this_file_is_not_going_to_be_there.dummy");
29 var url_connection_error = url_200.replace(/^(\w+:\/\/[^/]+?)(:\d+)?\//,
"$1:9546/");
30 var url_multipart =
"file_bug218236_multipart.txt";
32 // List of tests: name of the test, URL to be requested, expected sequence
33 // of events and optionally a function to be called from readystatechange handler.
34 // Numbers in the list of events are values of XMLHttpRequest.readyState
35 // when readystatechange event is triggered.
37 [
"200 OK", url_200, [
1,
2,
3,
4,
"load"],
0, null],
38 [
"404 Not Found", url_404, [
1,
2,
3,
4,
"load"],
0, null],
39 [
"connection error", url_connection_error, [
1,
2,
4,
"error"],
0, null],
40 [
"abort() call on readyState = 1", url_200, [
1,
4],
0, doAbort1],
41 [
"abort() call on readyState = 2", url_200, [
1,
2,
4],
0, doAbort2],
42 [
"multipart document", url_multipart, [
1,
2,
3,
4,
"load",
44 1,
2,
3,
4,
"load"],
1, null],
49 var currentSequence = null;
50 var expectedSequence = null;
51 var currentCallback = null;
52 var finalizeTimeoutID = null;
59 if (request.readyState ==
1)
63 if (request.readyState ==
2)
67 /* Utility functions */
69 function runNextTest() {
70 if (tests.length
> 0) {
71 var test = tests.shift();
73 netscape.security.PrivilegeManager.enablePrivilege(
"UniversalXPConnect");
75 // Prepare request object
76 request = new XMLHttpRequest();
77 request.multipart = test[
3];
78 request.open(
"GET", test[
1]);
79 request.onreadystatechange = onReadyStateChange;
80 request.onload = onLoad;
81 request.onerror = onError;
83 // Initialize state variables
87 expectedSequence = test[
2];
88 currentCallback = test[
4];
97 function finalizeTest() {
98 finalizeTimeoutID = null;
99 ok(compareArrays(expectedSequence, currentSequence),
"event sequence for '" + testName +
"' was " + currentSequence.join(
", "));
104 function onReadyStateChange() {
105 clearTimeout(finalizeTimeoutID);
106 finalizeTimeoutID = null;
108 // Ignore duplicated calls for the same ready state
109 if (request.readyState != currentState) {
110 currentState = request.readyState;
111 currentSequence.push(currentState);
114 if (currentState ==
4) {
115 // Allow remaining event to fire but then we are finished with this test
116 // unless we get another onReadyStateChange in which case we'll cancel
118 finalizeTimeoutID = setTimeout(finalizeTest,
0);
126 currentSequence.push(
"load");
130 currentSequence.push(
"error");
133 function compareArrays(array1, array2) {
134 if (array1.length != array2.length)
137 for (var i =
0; i < array1.length; i++)
138 if (array1[i] != array2[i])