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 217302 add6dcab0ca77182dab55a523505af68b63b9489
parent 217301 2954916649492036a4072f85b3e3cb63538ad6f5
child 217303 e2dd9299b843e46fee276a186f3d9c076f039f8d
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer, test-only
bugs957243, 602838
milestone33.0a2
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);
+  }
 }