bug1014466_worker.js (1622B)
1 /** 2 * Any copyright is dedicated to the Public Domain. 3 * http://creativecommons.org/publicdomain/zero/1.0/ 4 */ 5 6 /* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */ 7 8 function ok(a, msg) { 9 postMessage({ type: "status", status: !!a, msg }); 10 } 11 12 onmessage = function (event) { 13 function getResponse(url) { 14 var xhr = new XMLHttpRequest(); 15 xhr.open("GET", url, false); 16 xhr.send(); 17 return xhr.responseText; 18 } 19 20 const testFile1 = "bug1014466_data1.txt"; 21 const testFile2 = "bug1014466_data2.txt"; 22 const testData1 = getResponse(testFile1); 23 const testData2 = getResponse(testFile2); 24 25 var response_count = 0; 26 var xhr = new XMLHttpRequest(); 27 xhr.onreadystatechange = function () { 28 if (xhr.readyState == xhr.DONE && xhr.status == 200) { 29 response_count++; 30 switch (response_count) { 31 case 1: 32 ok(xhr.responseText == testData1, "Check data 1"); 33 test_data2(); 34 break; 35 case 2: 36 ok(xhr.responseText == testData2, "Check data 2"); 37 postMessage({ type: "finish" }); 38 break; 39 default: 40 ok(false, "Unexpected response received"); 41 postMessage({ type: "finish" }); 42 break; 43 } 44 } 45 }; 46 xhr.onerror = function (e) { 47 ok(false, "Got an error event: " + e); 48 postMessage({ type: "finish" }); 49 }; 50 51 function test_data1() { 52 xhr.open("GET", testFile1, true); 53 xhr.responseType = "text"; 54 xhr.send(); 55 } 56 57 function test_data2() { 58 xhr.abort(); 59 xhr.open("GET", testFile2, true); 60 xhr.responseType = "text"; 61 xhr.send(); 62 } 63 64 test_data1(); 65 };