Bug 957243 - Fix test_bug602838.html to not assume server response ordering. r=mayhemer, a=test-only
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 29 Jul 2014 21:33:17 -0400
changeset 208201 97b81de9d1a5
parent 208200 4fc9c8d8a4ae
child 208202 4bb3a5226b75
push id3764
push userryanvm@gmail.com
push date2014-07-30 15:35 +0000
treeherdermozilla-beta@97b81de9d1a5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer, test-only
bugs957243, 602838
milestone32.0
Bug 957243 - Fix test_bug602838.html to not assume server response ordering. r=mayhemer, a=test-only
content/base/test/script_bug602838.sjs
--- a/content/base/test/script_bug602838.sjs
+++ b/content/base/test/script_bug602838.sjs
@@ -1,18 +1,37 @@
+function setOurState(data) {
+  x = { data: data, QueryInterface: function(iid) { return this } };
+  x.wrappedJSObject = x;
+  setObjectState("bug602838", x);
+}
+
+function getOurState() {
+  var data;
+  getObjectState("bug602838", function(x) {
+    // x can be null if no one has set any state yet
+    if (x) {
+      data = x.wrappedJSObject.data;
+    }
+  });
+  return data;
+}
+
 function handleRequest(request, response)
 {
   if (request.queryString) {
-    let blockedResponse = null;
-    getObjectState("bug602838", function(x) { blockedResponse = x.wrappedJSObject.r });
-    blockedResponse.finish();
-    setObjectState("bug602838", null);
+    let blockedResponse = getOurState();
+    if (typeof(blockedResponse) == "object") {
+      blockedResponse.finish();
+      setOurState(null);
+    } else {
+      setOurState("unblocked");
+    }
     return;
   }
   response.setHeader("Cache-Control", "no-cache", false);
   response.setHeader("Content-Type", "text/javascript", false);
   response.write("ok(asyncRan, 'Async script should have run first.'); firstRan = true;");
-  response.processAsync();
-
-  x = { r: response, QueryInterface: function(iid) { return this } };
-  x.wrappedJSObject = x;
-  setObjectState("bug602838", x);
+  if (getOurState() != "unblocked") {
+    response.processAsync();
+    setOurState(response);
+  }
 }