1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/test_xhr_abort_after_load.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,96 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Test bug 482935</title> 1.8 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 + <link rel="stylesheet" type="text/css" href=" /tests/SimpleTest/test.css" /> 1.10 +</head> 1.11 +<body onload="onWindowLoad()"> 1.12 +<script class="testbody" type="text/javascript">"use strict"; 1.13 +SimpleTest.waitForExplicitFinish(); 1.14 + 1.15 +var url = "file_XHR_pass1.xml"; 1.16 + 1.17 +function onWindowLoad() { 1.18 + runTest(); 1.19 +} 1.20 + 1.21 +function runTest() { 1.22 + var testFunctions = [ 1.23 + startTest1, 1.24 + startTest2, 1.25 + startTest3, 1.26 + ]; 1.27 + 1.28 + function nextTest() { 1.29 + if (testFunctions.length == 0) { 1.30 + SimpleTest.finish(); 1.31 + return; 1.32 + } 1.33 + (testFunctions.shift())(); 1.34 + } 1.35 + 1.36 + nextTest(); 1.37 + 1.38 + var xhr; 1.39 + function startTest1() { 1.40 + xhr = new XMLHttpRequest(); 1.41 + xhr.onload = onLoad1; 1.42 + xhr.open("GET", url); 1.43 + xhr.send(); 1.44 + } 1.45 + 1.46 + function onLoad1() { 1.47 + is(xhr.readyState, xhr.DONE, "readyState should be DONE"); 1.48 + xhr.onabort = onAbort1; 1.49 + xhr.abort(); 1.50 + 1.51 + function onAbort1(e) { 1.52 + ok(false, e.type + " event should not be fired!"); 1.53 + } 1.54 + 1.55 + is(xhr.readyState, xhr.UNSENT, "readyState should be UNSENT"); 1.56 + nextTest(); 1.57 + } 1.58 + 1.59 + function startTest2() { 1.60 + xhr = new XMLHttpRequest(); 1.61 + xhr.onloadstart = onAfterSend; 1.62 + xhr.open("GET", url); 1.63 + xhr.send(); 1.64 + } 1.65 + 1.66 + function startTest3() { 1.67 + xhr = new XMLHttpRequest(); 1.68 + xhr.open("GET", url); 1.69 + xhr.send(); 1.70 + onAfterSend(); 1.71 + } 1.72 + 1.73 + function onAfterSend() { 1.74 + is(xhr.readyState, xhr.OPENED, "readyState should be OPENED"); 1.75 + var sent = false; 1.76 + try { 1.77 + xhr.send(); 1.78 + } catch (e) { 1.79 + sent = true; 1.80 + } 1.81 + ok(sent, "send() flag should be set"); 1.82 + var aborted = false; 1.83 + xhr.onabort = onAbort2; 1.84 + xhr.abort(); 1.85 + 1.86 + function onAbort2() { 1.87 + is(xhr.readyState, xhr.DONE, "readyState should be DONE"); 1.88 + aborted = true; 1.89 + } 1.90 + 1.91 + ok(aborted, "abort event should be fired"); 1.92 + is(xhr.readyState, xhr.UNSENT, "readyState should be UNSENT"); 1.93 + nextTest(); 1.94 + } 1.95 +} 1.96 + 1.97 +</script> 1.98 +</body> 1.99 +</html>