Bug 687220: Add test for event handlers on the xhr.upload object in workers. r=bent
authorJonas Sicking <jonas@sicking.cc>
Thu, 10 Nov 2011 16:29:34 -0800
changeset 80146 1374294a61191a19ba6f52be7ee980b1f5186532
parent 80145 cd90cf2bad07adab02e042254a050e575b1efc2b
child 80180 50c1bcb49c7678efed1d9592bbbc95cb9dc77c84
child 80246 ea4aca245aac98829e61ce5027b6e605b5d45182
push id323
push userrcampbell@mozilla.com
push dateTue, 15 Nov 2011 21:58:36 +0000
treeherderfx-team@3ea216303184 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs687220
milestone11.0a1
Bug 687220: Add test for event handlers on the xhr.upload object in workers. r=bent
dom/workers/test/test_xhr.html
dom/workers/test/xhr_worker.js
--- a/dom/workers/test/test_xhr.html
+++ b/dom/workers/test/test_xhr.html
@@ -18,32 +18,39 @@ Tests of DOM Worker Threads XHR(Bug 4504
 <div id="content" style="display: none">
 
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
   var worker = new Worker("xhr_worker.js");
 
+  var gotUploadLoad = false, gotLoadend = false;
+
   worker.onmessage = function(event) {
     is(event.target, worker);
-    var args = eval(event.data);
+    var args = event.data;
     switch (args.type) {
       case "progress": {
         ok(parseInt(args.current) <= parseInt(args.total));
       } break;
       case "error": {
         ok(false, "XHR error: " + args.error);
       } break;
+      case "upload.load": {
+        gotUploadLoad = true;
+      } break;
       case "load": {
-        is(args.data, "A noisy noise annoys an oyster.");
+        ok(gotUploadLoad, "Should have gotten upload load event");
+        gotLoadend = true;
+        is(args.data, "A noisy noise annoys an oyster.", "correct data");
         document.getElementById("content").textContent = args.data;
       } break;
       case "loadend": {
-        ok(true, "Should have got loadend.");
+        ok(gotLoadend, "Should have gotten load.");
         SimpleTest.finish();
         break;
       }
       default: {
         ok(false, "Unexpected message");
         SimpleTest.finish();
       }
     }
--- a/dom/workers/test/xhr_worker.js
+++ b/dom/workers/test/xhr_worker.js
@@ -7,70 +7,74 @@ var xhr = new XMLHttpRequest();
 function onload(event) {
   if (event.target != xhr) {
     throw "onload event.target != xhr";
   }
 
   if (event.target.status != 200) {
     var message = { type: "error",
                     error: event.target.status };
-    postMessage(message.toSource());
+    postMessage(message);
   }
 
   var message = { type: "load",
                   data: xhr.responseText };
-  postMessage(message.toSource());
+  postMessage(message);
 }
 
 xhr.onload = onload;
 xhr.addEventListener("load", onload, false);
 xhr.removeEventListener("load", onload, false);
 if (!xhr.onload) {
   var message = { type: "error",
                   error: "Lost message listener!" };
-  postMessage(message.toSource());
+  postMessage(message);
 }
 
 xhr.addEventListener("error", function(event) {
   if (event.target != xhr) {
     throw "onerror event.target != xhr";
   }
   var message = { type: "error",
                   error: event.target.status };
-  postMessage(message.toSource());
+  postMessage(message);
 }, false);
 
 function onprogress(event) {
   if (event.target != xhr) {
     throw "onprogress event.target != xhr";
   }
   var message = { type: "progress",
                   current: event.loaded,
                   total: event.total };
-  postMessage(message.toSource());
+  postMessage(message);
 }
 xhr.addEventListener("progress", onprogress, false);
 
 xhr.addEventListener("foopety", function(event) {}, false);
 xhr.removeEventListener("doopety", function(event) {}, false);
 
 xhr.onloadend = function(event) {
   var message = { type: "loadend" };
-  postMessage(message.toSource());  
+  postMessage(message);  
 }
 
 var upload = xhr.upload;
 upload.onprogress = function(event) { };
-upload.addEventListener("readystatechange", function(event) { }, false);
-upload.removeEventListener("readystatechange", function(event) { }, false);
+upload.addEventListener("foo", function(event) { }, false);
+upload.removeEventListener("foo", function(event) { }, false);
 upload.addEventListener("load", function(event) { }, false);
-upload.removeEventListener("readystatechange", function(event) { }, false);
+upload.removeEventListener("foo", function(event) { }, false);
+upload.onload = function(event) {
+  var message = { type: "upload.load" };
+  postMessage(message);
+}
 
 onmessage = function(event) {
   if (xhr.DONE != 4 || XMLHttpRequest.DONE != 4) {
     throw "xhr constants not correct!";
   }
   if (xhr.readystate > xhr.UNSENT) {
     throw "XHR already running!";
   }
-  xhr.open("GET", event.data);
-  xhr.send(null);
+  xhr.open("POST", event.data);
+  xhr.send("Data to send");
 }