content/base/test/test_xhr_abort_after_load.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <title>Test bug 482935</title>
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <link rel="stylesheet" type="text/css" href=" /tests/SimpleTest/test.css" />
michael@0 7 </head>
michael@0 8 <body onload="onWindowLoad()">
michael@0 9 <script class="testbody" type="text/javascript">"use strict";
michael@0 10 SimpleTest.waitForExplicitFinish();
michael@0 11
michael@0 12 var url = "file_XHR_pass1.xml";
michael@0 13
michael@0 14 function onWindowLoad() {
michael@0 15 runTest();
michael@0 16 }
michael@0 17
michael@0 18 function runTest() {
michael@0 19 var testFunctions = [
michael@0 20 startTest1,
michael@0 21 startTest2,
michael@0 22 startTest3,
michael@0 23 ];
michael@0 24
michael@0 25 function nextTest() {
michael@0 26 if (testFunctions.length == 0) {
michael@0 27 SimpleTest.finish();
michael@0 28 return;
michael@0 29 }
michael@0 30 (testFunctions.shift())();
michael@0 31 }
michael@0 32
michael@0 33 nextTest();
michael@0 34
michael@0 35 var xhr;
michael@0 36 function startTest1() {
michael@0 37 xhr = new XMLHttpRequest();
michael@0 38 xhr.onload = onLoad1;
michael@0 39 xhr.open("GET", url);
michael@0 40 xhr.send();
michael@0 41 }
michael@0 42
michael@0 43 function onLoad1() {
michael@0 44 is(xhr.readyState, xhr.DONE, "readyState should be DONE");
michael@0 45 xhr.onabort = onAbort1;
michael@0 46 xhr.abort();
michael@0 47
michael@0 48 function onAbort1(e) {
michael@0 49 ok(false, e.type + " event should not be fired!");
michael@0 50 }
michael@0 51
michael@0 52 is(xhr.readyState, xhr.UNSENT, "readyState should be UNSENT");
michael@0 53 nextTest();
michael@0 54 }
michael@0 55
michael@0 56 function startTest2() {
michael@0 57 xhr = new XMLHttpRequest();
michael@0 58 xhr.onloadstart = onAfterSend;
michael@0 59 xhr.open("GET", url);
michael@0 60 xhr.send();
michael@0 61 }
michael@0 62
michael@0 63 function startTest3() {
michael@0 64 xhr = new XMLHttpRequest();
michael@0 65 xhr.open("GET", url);
michael@0 66 xhr.send();
michael@0 67 onAfterSend();
michael@0 68 }
michael@0 69
michael@0 70 function onAfterSend() {
michael@0 71 is(xhr.readyState, xhr.OPENED, "readyState should be OPENED");
michael@0 72 var sent = false;
michael@0 73 try {
michael@0 74 xhr.send();
michael@0 75 } catch (e) {
michael@0 76 sent = true;
michael@0 77 }
michael@0 78 ok(sent, "send() flag should be set");
michael@0 79 var aborted = false;
michael@0 80 xhr.onabort = onAbort2;
michael@0 81 xhr.abort();
michael@0 82
michael@0 83 function onAbort2() {
michael@0 84 is(xhr.readyState, xhr.DONE, "readyState should be DONE");
michael@0 85 aborted = true;
michael@0 86 }
michael@0 87
michael@0 88 ok(aborted, "abort event should be fired");
michael@0 89 is(xhr.readyState, xhr.UNSENT, "readyState should be UNSENT");
michael@0 90 nextTest();
michael@0 91 }
michael@0 92 }
michael@0 93
michael@0 94 </script>
michael@0 95 </body>
michael@0 96 </html>

mercurial