Bug 1239920 - Fix other usages of waitForFinishedRequest() to ignore unexpected requests in webconsole tests. r=bgrins, a=test-only
authorSami Jaktholm <sjakthol@outlook.com>
Fri, 25 Mar 2016 08:09:25 +0200
changeset 323765 69aa935f881de82592f98d9e425d63e0daa4bd58
parent 323764 bf4bb009194db162e9368863a4533bb9788cfd94
child 323766 3efaae4308c69b90a3756a04a53c3814b852e27a
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins, test-only
bugs1239920
milestone47.0a2
Bug 1239920 - Fix other usages of waitForFinishedRequest() to ignore unexpected requests in webconsole tests. r=bgrins, a=test-only If test timings shift in the future, the unexpected requests could occur during any test. Since there are many tests that use waitForFinishedRequest(), any of them could start to fail intermittently at any point. These changes fix other usages of wwaitForFinishedRequest() to include a predicate that ignores the requests that are unexpected during the test. MozReview-Commit-ID: Er0xyt3YBj6
devtools/client/webconsole/test/browser_webconsole_bug_632817.js
devtools/client/webconsole/test/browser_webconsole_netlogging.js
devtools/client/webconsole/test/browser_webconsole_netlogging_panel.js
--- a/devtools/client/webconsole/test/browser_webconsole_bug_632817.js
+++ b/devtools/client/webconsole/test/browser_webconsole_bug_632817.js
@@ -15,16 +15,25 @@ const TEST_IMG = "http://example.com/bro
                  "test/test-image.png";
 
 const TEST_DATA_JSON_CONTENT =
   '{ id: "test JSON data", myArray: [ "foo", "bar", "baz", "biff" ] }';
 
 const TEST_URI = "data:text/html;charset=utf-8,Web Console network logging " +
                  "tests";
 
+const PAGE_REQUEST_PREDICATE =
+  ({ request }) => request.url.endsWith("test-network-request.html");
+
+const TEST_DATA_REQUEST_PREDICATE =
+  ({ request }) => request.url.endsWith("test-data.json");
+
+const XHR_WARN_REQUEST_PREDICATE =
+  ({ request }) => request.url.endsWith("sjs_cors-test-server.sjs");
+
 let hud;
 
 add_task(function*() {
   const PREF = "devtools.webconsole.persistlog";
   const NET_PREF = "devtools.webconsole.filter.networkinfo";
   const NETXHR_PREF = "devtools.webconsole.filter.netxhr";
   const MIXED_AC_PREF = "security.mixed_content.block_active_content";
   let original = Services.prefs.getBoolPref(NET_PREF);
@@ -51,79 +60,76 @@ add_task(function*() {
   yield testXhrPost();
   yield testFormSubmission();
   yield testLiveFilteringOnSearchStrings();
 });
 
 function testPageLoad() {
 
   BrowserTestUtils.loadURI(gBrowser.selectedBrowser, TEST_NETWORK_REQUEST_URI);
-  let lastRequest = yield new Promise(resolve => {
-    HUDService.lastFinishedRequest.callback = function(request) {
-      resolve(request);
-    };
-  });
+  let lastRequest = yield waitForFinishedRequest(PAGE_REQUEST_PREDICATE);
 
   // Check if page load was logged correctly.
   ok(lastRequest, "Page load was logged");
   is(lastRequest.request.url, TEST_NETWORK_REQUEST_URI,
     "Logged network entry is page load");
   is(lastRequest.request.method, "GET", "Method is correct");
 }
 
 function testXhrGet() {
   // Start the XMLHttpRequest() GET test.
   ContentTask.spawn(gBrowser.selectedBrowser, {}, function*() {
     content.wrappedJSObject.testXhrGet();
   });
 
-  let lastRequest = yield waitForFinishedRequest();
+  let lastRequest = yield waitForFinishedRequest(TEST_DATA_REQUEST_PREDICATE);
 
   ok(lastRequest, "testXhrGet() was logged");
   is(lastRequest.request.method, "GET", "Method is correct");
   ok(lastRequest.isXHR, "It's an XHR request");
 }
 
 function testXhrWarn() {
   // Start the XMLHttpRequest() warn test.
   ContentTask.spawn(gBrowser.selectedBrowser, {}, function*() {
     content.wrappedJSObject.testXhrWarn();
   });
 
-  let lastRequest = yield waitForFinishedRequest();
+  let lastRequest = yield waitForFinishedRequest(XHR_WARN_REQUEST_PREDICATE);
 
   ok(lastRequest, "testXhrWarn() was logged");
   is(lastRequest.request.method, "GET", "Method is correct");
   ok(lastRequest.isXHR, "It's an XHR request");
   is(lastRequest.securityInfo, "insecure", "It's an insecure request");
 }
 
 function testXhrPost() {
   // Start the XMLHttpRequest() POST test.
   ContentTask.spawn(gBrowser.selectedBrowser, {}, function*() {
     content.wrappedJSObject.testXhrPost();
   });
 
-  let lastRequest = yield waitForFinishedRequest();
+  let lastRequest = yield waitForFinishedRequest(TEST_DATA_REQUEST_PREDICATE);
 
   ok(lastRequest, "testXhrPost() was logged");
   is(lastRequest.request.method, "POST", "Method is correct");
   ok(lastRequest.isXHR, "It's an XHR request");
 }
 
 function testFormSubmission() {
   // Start the form submission test. As the form is submitted, the page is
   // loaded again. Bind to the load event to catch when this is done.
   ContentTask.spawn(gBrowser.selectedBrowser, {}, function*() {
     let form = content.document.querySelector("form");
     ok(form, "we have the HTML form");
     form.submit();
   });
 
-  let lastRequest = yield waitForFinishedRequest();
+  // The form POSTs to the page URL but over https (page over http).
+  let lastRequest = yield waitForFinishedRequest(PAGE_REQUEST_PREDICATE);
 
   ok(lastRequest, "testFormSubmission() was logged");
   is(lastRequest.request.method, "POST", "Method is correct");
 
   // There should be 3 network requests pointing to the HTML file.
   waitForMessages({
     webconsole: hud,
     messages: [
--- a/devtools/client/webconsole/test/browser_webconsole_netlogging.js
+++ b/devtools/client/webconsole/test/browser_webconsole_netlogging.js
@@ -9,18 +9,24 @@
 
 const TEST_NETWORK_REQUEST_URI =
   "http://example.com/browser/devtools/client/webconsole/test/" +
   "test-network-request.html";
 
 const TEST_DATA_JSON_CONTENT =
   '{ id: "test JSON data", myArray: [ "foo", "bar", "baz", "biff" ] }';
 
+const PAGE_REQUEST_PREDICATE =
+  ({ request }) => request.url.endsWith("test-network-request.html");
+
+const TEST_DATA_REQUEST_PREDICATE =
+  ({ request }) => request.url.endsWith("test-data.json");
+
 add_task(function* testPageLoad() {
-  let finishedRequest = waitForFinishedRequest();
+  let finishedRequest = waitForFinishedRequest(PAGE_REQUEST_PREDICATE);
   let hud = yield loadPageAndGetHud(TEST_NETWORK_REQUEST_URI);
   let request = yield finishedRequest;
 
   ok(request, "Page load was logged");
 
   let client = hud.ui.webConsoleClient;
   let args = [request.actor];
   const postData = yield getPacket(client, "getRequestPostData", args);
@@ -34,17 +40,17 @@ add_task(function* testPageLoad() {
     "Request body was not discarded");
   is(responseContent.content.text.indexOf("<!DOCTYPE HTML>"), 0,
     "Response body's beginning is okay");
 });
 
 add_task(function* testXhrGet() {
   let hud = yield loadPageAndGetHud(TEST_NETWORK_REQUEST_URI);
 
-  let finishedRequest = waitForFinishedRequest();
+  let finishedRequest = waitForFinishedRequest(TEST_DATA_REQUEST_PREDICATE);
   content.wrappedJSObject.testXhrGet();
   let request = yield finishedRequest;
 
   ok(request, "testXhrGet() was logged");
 
   let client = hud.ui.webConsoleClient;
   let args = [request.actor];
   const postData = yield getPacket(client, "getRequestPostData", args);
@@ -56,17 +62,17 @@ add_task(function* testXhrGet() {
     "Request body was not discarded");
   is(responseContent.content.text, TEST_DATA_JSON_CONTENT,
     "Response is correct");
 });
 
 add_task(function* testXhrPost() {
   let hud = yield loadPageAndGetHud(TEST_NETWORK_REQUEST_URI);
 
-  let finishedRequest = waitForFinishedRequest();
+  let finishedRequest = waitForFinishedRequest(TEST_DATA_REQUEST_PREDICATE);
   content.wrappedJSObject.testXhrPost();
   let request = yield finishedRequest;
 
   ok(request, "testXhrPost() was logged");
 
   let client = hud.ui.webConsoleClient;
   let args = [request.actor];
   const postData = yield getPacket(client, "getRequestPostData", args);
@@ -76,17 +82,18 @@ add_task(function* testXhrPost() {
   is(postData.postData.text, "Hello world!", "Request body was logged");
   is(responseContent.content.text, TEST_DATA_JSON_CONTENT,
     "Response is correct");
 });
 
 add_task(function* testFormSubmission() {
   let hud = yield loadPageAndGetHud(TEST_NETWORK_REQUEST_URI);
 
-  let finishedRequest = waitForFinishedRequest();
+  // The form POSTs to the page URL but over https (page over http).
+  let finishedRequest = waitForFinishedRequest(PAGE_REQUEST_PREDICATE);
   ContentTask.spawn(gBrowser.selectedBrowser, { }, `function()
   {
     let form = content.document.querySelector("form");
     form.submit();
   }`);
   let request = yield finishedRequest;
 
   ok(request, "testFormSubmission() was logged");
--- a/devtools/client/webconsole/test/browser_webconsole_netlogging_panel.js
+++ b/devtools/client/webconsole/test/browser_webconsole_netlogging_panel.js
@@ -6,17 +6,20 @@
 
 "use strict";
 
 const TEST_NETWORK_REQUEST_URI =
   "http://example.com/browser/devtools/client/webconsole/test/" +
   "test-network-request.html";
 
 add_task(function* () {
-  let finishedRequest = waitForFinishedRequest();
+  let finishedRequest = waitForFinishedRequest(({ request }) => {
+    return request.url.endsWith("test-network-request.html");
+  });
+
   const hud = yield loadPageAndGetHud(TEST_NETWORK_REQUEST_URI);
   let request = yield finishedRequest;
 
   yield hud.ui.openNetworkPanel(request.actor);
   let toolbox = gDevTools.getToolbox(hud.target);
   is(toolbox.currentToolId, "netmonitor", "Network panel was opened");
   let panel = toolbox.getCurrentPanel();
   let selected = panel.panelWin.NetMonitorView.RequestsMenu.selectedItem;