Bug 1014466 - Part 3: Test case for async XHR reuse. r=khuey CLOSED TREE
authorShian-Yow Wu <swu@mozilla.com>
Fri, 06 Jun 2014 12:12:19 +0100
changeset 206307 94137dfc452001c2cf9b05c3893d102d3a2c88c5
parent 206306 5d3e9e9171bbd3d82ec9b75bb95b20c38f49e35a
child 206308 5ea529f39d44101aec5ddba815e84dbe40c21c4b
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs1014466
milestone32.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1014466 - Part 3: Test case for async XHR reuse. r=khuey CLOSED TREE
dom/workers/test/bug1014466_data1.txt
dom/workers/test/bug1014466_data2.txt
dom/workers/test/bug1014466_worker.js
dom/workers/test/mochitest.ini
dom/workers/test/test_bug1014466.html
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/bug1014466_data1.txt
@@ -0,0 +1,1 @@
+1234567890
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/bug1014466_data2.txt
@@ -0,0 +1,1 @@
+ABCDEFGH
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/bug1014466_worker.js
@@ -0,0 +1,64 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+function ok(a, msg) {
+  postMessage({type: "status", status: !!a, msg: msg });
+}
+
+onmessage = function(event) {
+
+  function getResponse(url) {
+    var xhr = new XMLHttpRequest();
+    xhr.open("GET", url, false);
+    xhr.send();
+    return xhr.responseText;
+  }
+
+  const testFile1 = "bug1014466_data1.txt";
+  const testFile2 = "bug1014466_data2.txt";
+  const testData1 = getResponse(testFile1);
+  const testData2 = getResponse(testFile2);
+
+  var response_count = 0;
+  var xhr = new XMLHttpRequest();
+  xhr.onreadystatechange = function() {
+    if (xhr.readyState == xhr.DONE && xhr.status == 200) {
+      response_count++;
+      switch (response_count) {
+        case 1:
+          ok(xhr.responseText == testData1, "Check data 1");
+          test_data2();
+          break;
+        case 2:
+          ok(xhr.responseText == testData2, "Check data 2");
+          postMessage({type: "finish" });
+          break;
+        default:
+          ok(false, "Unexpected response received");
+          postMessage({type: "finish" });
+          break;
+      }
+    }
+  }
+  xhr.onerror = function(event) {
+    ok(false, "Got an error event: " + event);
+    postMessage({type: "finish" });
+  }
+
+  function test_data1() {
+    xhr.open("GET", testFile1, true);
+    xhr.responseType = "text";
+    xhr.send();
+  }
+
+  function test_data2() {
+    xhr.abort();
+    xhr.open("GET", testFile2, true);
+    xhr.responseType = "text";
+    xhr.send();
+  }
+
+  test_data1();
+}
--- a/dom/workers/test/mochitest.ini
+++ b/dom/workers/test/mochitest.ini
@@ -1,12 +1,15 @@
 [DEFAULT]
 support-files =
   WorkerTest_badworker.js
   atob_worker.js
+  bug1014466_data1.txt
+  bug1014466_data2.txt
+  bug1014466_worker.js
   bug1020226_worker.js
   bug1020226_frame.html
   clearTimeouts_worker.js
   closeOnGC_server.sjs
   closeOnGC_worker.js
   close_worker.js
   content_worker.js
   console_worker.js
@@ -75,16 +78,17 @@ support-files =
   subdir/relativeLoad_sub_import.js
 
 [test_404.html]
 [test_atob.html]
 [test_blobConstructor.html]
 [test_blobWorkers.html]
 [test_bug949946.html]
 [test_bug1010784.html]
+[test_bug1014466.html]
 [test_bug1020226.html]
 [test_chromeWorker.html]
 [test_clearTimeouts.html]
 [test_close.html]
 [test_closeOnGC.html]
 skip-if = (buildapp == 'b2g' && (toolkit != 'gonk' || debug)) || toolkit == 'android' #bug 881404 # b2g-debug(times out) b2g-desktop(times out)
 [test_console.html]
 [test_consoleReplaceable.html]
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/test_bug1014466.html
@@ -0,0 +1,42 @@
+<!--
+2   Any copyright is dedicated to the Public Domain.
+3   http://creativecommons.org/publicdomain/zero/1.0/
+4 -->
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1014466
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1014466</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1014466">Mozilla Bug 1014466</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+  var worker = new Worker("bug1014466_worker.js");
+
+  worker.onmessage = function(event) {
+    if (event.data.type == 'finish') {
+      SimpleTest.finish();
+    } else if (event.data.type == 'status') {
+      ok(event.data.status, event.data.msg);
+    }
+  };
+
+  worker.postMessage(true);
+
+  SimpleTest.waitForExplicitFinish();
+
+</script>
+</pre>
+</body>
+</html>