Bug 422974 ? Prism uses old "Remember password?" mechanism. r=gavin
[wine-gecko.git] / content / base / test / test_bug218236.html
blob0dc1cf85e6637d4e3782badb3c0f77445a9b9edd
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=218236
5 -->
6 <head>
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" />
11 </head>
12 <body>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=218236">Mozilla Bug 218236</a>
14 <p id="display"></p>
15 <div id="content" style="display: none">
17 </div>
18 <pre id="test">
19 <script class="testbody" type="text/javascript">
21 /** Test for Bug 218236 **/
23 SimpleTest.waitForExplicitFinish();
25 /* Test data */
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.
36 var tests = [
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",
43 1, 2, 3, 4, "load",
44 1, 2, 3, 4, "load"], 1, null],
47 var testName = null;
48 var currentState = 0;
49 var currentSequence = null;
50 var expectedSequence = null;
51 var currentCallback = null;
52 var finalizeTimeoutID = null;
54 var request = null;
56 runNextTest();
58 function doAbort1() {
59 if (request.readyState == 1)
60 request.abort();
62 function doAbort2() {
63 if (request.readyState == 2)
64 request.abort();
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
84 testName = test[0]
85 currentState = 0;
86 currentSequence = [];
87 expectedSequence = test[2];
88 currentCallback = test[4];
90 // Start request
91 request.send(null);
93 else
94 SimpleTest.finish();
97 function finalizeTest() {
98 finalizeTimeoutID = null;
99 ok(compareArrays(expectedSequence, currentSequence), "event sequence for '" + testName + "' was " + currentSequence.join(", "));
101 runNextTest();
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
117 // this timeout
118 finalizeTimeoutID = setTimeout(finalizeTest, 0);
121 if (currentCallback)
122 currentCallback();
125 function onLoad() {
126 currentSequence.push("load");
129 function onError() {
130 currentSequence.push("error");
133 function compareArrays(array1, array2) {
134 if (array1.length != array2.length)
135 return false;
137 for (var i = 0; i < array1.length; i++)
138 if (array1[i] != array2[i])
139 return false;
141 return true;
143 </script>
144 </pre>
145 </body>
146 </html>