Bug 1302616 - Be more precise when waiting for request in browser_webconsole_bug_599725_response_headers.js. a=test-only
authorBrian Grinstead <bgrinstead@mozilla.com>
Fri, 07 Oct 2016 14:43:48 -0700
changeset 350679 2e702e2a5251c8f316df664fa6bae347fad001ab
parent 350678 4d0f2d5b85a75093569a37120bf8ee47a156bc9e
child 350680 bb1a6a0a53479c19d1920dd6155a84a3e9cd84c1
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstest-only
bugs1302616
milestone50.0
Bug 1302616 - Be more precise when waiting for request in browser_webconsole_bug_599725_response_headers.js. a=test-only MozReview-Commit-ID: 8KdlAzxZ4ZE
devtools/client/webconsole/test/browser_webconsole_bug_599725_response_headers.js
--- a/devtools/client/webconsole/test/browser_webconsole_bug_599725_response_headers.js
+++ b/devtools/client/webconsole/test/browser_webconsole_bug_599725_response_headers.js
@@ -4,69 +4,61 @@
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 const INIT_URI = "data:text/plain;charset=utf8,hello world";
 const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
                  "test/test-bug-599725-response-headers.sjs";
 
-var loads = 0;
-function performTest(request, console) {
+function performTest(request, hud) {
   let deferred = promise.defer();
 
   let headers = null;
 
   function readHeader(name) {
     for (let header of headers) {
       if (header.name == name) {
         return header.value;
       }
     }
     return null;
   }
 
-  console.webConsoleClient.getResponseHeaders(request.actor,
+  hud.ui.proxy.webConsoleClient.getResponseHeaders(request.actor,
     function (response) {
       headers = response.headers;
       ok(headers, "we have the response headers for reload");
 
       let contentType = readHeader("Content-Type");
       let contentLength = readHeader("Content-Length");
 
       ok(!contentType, "we do not have the Content-Type header");
       isnot(contentLength, 60, "Content-Length != 60");
 
       executeSoon(deferred.resolve);
     });
 
-  HUDService.lastFinishedRequest.callback = null;
-
   return deferred.promise;
 }
 
-function waitForRequest() {
-  let deferred = promise.defer();
-  HUDService.lastFinishedRequest.callback = (req, console) => {
-    loads++;
-    ok(req, "page load was logged");
-    if (loads != 2) {
-      return;
-    }
-    performTest(req, console).then(deferred.resolve);
-  };
-  return deferred.promise;
-}
+let waitForRequest = Task.async(function*(hud) {
+  let request = yield waitForFinishedRequest(req=> {
+    return req.response.status === "304";
+  });
+
+  yield performTest(request, hud);
+});
 
 add_task(function* () {
   let { browser } = yield loadTab(INIT_URI);
 
-  yield openConsole();
+  let hud = yield openConsole();
 
-  let gotLastRequest = waitForRequest();
+  let gotLastRequest = waitForRequest(hud);
 
   let loaded = loadBrowser(browser);
   BrowserTestUtils.loadURI(browser, TEST_URI);
   yield loaded;
 
   let reloaded = loadBrowser(browser);
   ContentTask.spawn(browser, null, "() => content.location.reload()");
   yield reloaded;