Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=218236 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 218236</title> |
michael@0 | 8 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 10 | </head> |
michael@0 | 11 | <body> |
michael@0 | 12 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=218236">Mozilla Bug 218236</a> |
michael@0 | 13 | <p id="display"></p> |
michael@0 | 14 | <div id="content" style="display: none"> |
michael@0 | 15 | |
michael@0 | 16 | </div> |
michael@0 | 17 | <pre id="test"> |
michael@0 | 18 | <script class="testbody" type="text/javascript"> |
michael@0 | 19 | |
michael@0 | 20 | /** Test for Bug 218236 **/ |
michael@0 | 21 | |
michael@0 | 22 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 23 | |
michael@0 | 24 | /* Test data */ |
michael@0 | 25 | |
michael@0 | 26 | var url_200 = window.location.href; |
michael@0 | 27 | var url_404 = url_200.replace(/[^/]+$/, "this_file_is_not_going_to_be_there.dummy"); |
michael@0 | 28 | var url_connection_error = url_200.replace(/^(\w+:\/\/[^/]+?)(:\d+)?\//, "$1:9546/"); |
michael@0 | 29 | |
michael@0 | 30 | // List of tests: name of the test, URL to be requested, expected sequence |
michael@0 | 31 | // of events and optionally a function to be called from readystatechange handler. |
michael@0 | 32 | // Numbers in the list of events are values of XMLHttpRequest.readyState |
michael@0 | 33 | // when readystatechange event is triggered. |
michael@0 | 34 | var tests = [ |
michael@0 | 35 | ["200 OK", url_200, [1, 2, 3, 4, "load"], null], |
michael@0 | 36 | ["404 Not Found", url_404, [1, 2, 3, 4, "load"], null], |
michael@0 | 37 | ["connection error", url_connection_error, [1, 2, 4, "error"], null], |
michael@0 | 38 | ["abort() call on readyState = 1", url_200, [1, 4], null, doAbort1], |
michael@0 | 39 | ["abort() call on readyState = 2", url_200, [1, 2, 4], doAbort2], |
michael@0 | 40 | ]; |
michael@0 | 41 | |
michael@0 | 42 | var testName = null; |
michael@0 | 43 | var currentState = 0; |
michael@0 | 44 | var currentSequence = null; |
michael@0 | 45 | var expectedSequence = null; |
michael@0 | 46 | var currentCallback = null; |
michael@0 | 47 | var finalizeTimeoutID = null; |
michael@0 | 48 | |
michael@0 | 49 | var request = null; |
michael@0 | 50 | |
michael@0 | 51 | runNextTest(); |
michael@0 | 52 | |
michael@0 | 53 | function doAbort1() { |
michael@0 | 54 | if (request.readyState == 1) |
michael@0 | 55 | request.abort(); |
michael@0 | 56 | } |
michael@0 | 57 | function doAbort2() { |
michael@0 | 58 | if (request.readyState == 2) |
michael@0 | 59 | request.abort(); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | /* Utility functions */ |
michael@0 | 63 | |
michael@0 | 64 | function runNextTest() { |
michael@0 | 65 | if (tests.length > 0) { |
michael@0 | 66 | var test = tests.shift(); |
michael@0 | 67 | |
michael@0 | 68 | // Initialize state variables |
michael@0 | 69 | testName = test[0] |
michael@0 | 70 | currentState = 0; |
michael@0 | 71 | currentSequence = []; |
michael@0 | 72 | expectedSequence = test[2]; |
michael@0 | 73 | currentCallback = test[3]; |
michael@0 | 74 | postSendCallback = test[4]; |
michael@0 | 75 | |
michael@0 | 76 | // Prepare request object |
michael@0 | 77 | request = new XMLHttpRequest(); |
michael@0 | 78 | request.onreadystatechange = onReadyStateChange; |
michael@0 | 79 | request.open("GET", test[1]); |
michael@0 | 80 | request.onload = onLoad; |
michael@0 | 81 | request.onerror = onError; |
michael@0 | 82 | |
michael@0 | 83 | // Start request |
michael@0 | 84 | request.send(null); |
michael@0 | 85 | if (postSendCallback) |
michael@0 | 86 | postSendCallback(); |
michael@0 | 87 | } |
michael@0 | 88 | else |
michael@0 | 89 | SimpleTest.finish(); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | function finalizeTest() { |
michael@0 | 93 | finalizeTimeoutID = null; |
michael@0 | 94 | ok(compareArrays(expectedSequence, currentSequence), "event sequence for '" + testName + "' was " + currentSequence.join(", ")); |
michael@0 | 95 | |
michael@0 | 96 | runNextTest(); |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | function onReadyStateChange() { |
michael@0 | 100 | clearTimeout(finalizeTimeoutID); |
michael@0 | 101 | finalizeTimeoutID = null; |
michael@0 | 102 | |
michael@0 | 103 | currentState = request.readyState; |
michael@0 | 104 | currentSequence.push(currentState); |
michael@0 | 105 | |
michael@0 | 106 | if (currentState == 4) { |
michael@0 | 107 | // Allow remaining event to fire but then we are finished with this test |
michael@0 | 108 | // unless we get another onReadyStateChange in which case we'll cancel |
michael@0 | 109 | // this timeout |
michael@0 | 110 | finalizeTimeoutID = setTimeout(finalizeTest, 0); |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | if (currentCallback) |
michael@0 | 114 | currentCallback(); |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | function onLoad() { |
michael@0 | 118 | currentSequence.push("load"); |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | function onError() { |
michael@0 | 122 | currentSequence.push("error"); |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | function compareArrays(array1, array2) { |
michael@0 | 126 | if (array1.length != array2.length) |
michael@0 | 127 | return false; |
michael@0 | 128 | |
michael@0 | 129 | for (var i = 0; i < array1.length; i++) |
michael@0 | 130 | if (array1[i] != array2[i]) |
michael@0 | 131 | return false; |
michael@0 | 132 | |
michael@0 | 133 | return true; |
michael@0 | 134 | } |
michael@0 | 135 | </script> |
michael@0 | 136 | </pre> |
michael@0 | 137 | </body> |
michael@0 | 138 | </html> |
michael@0 | 139 |