Bug 1242234 - Debugging intermittent
authorBrian Grinstead <bgrinstead@mozilla.com>
Wed, 30 Mar 2016 18:24:06 -0700
changeset 729926 36184a62823bdc92a1ab25bc46c80da835299638
parent 729601 e14db462d31d566570e3bece66d5380f7b1ad400
child 729927 9b6fa04c9520f7e80dd67a70677f246d45cd6ed6
push id117151
push userbgrinstead@mozilla.com
push dateThu, 31 Mar 2016 01:24:55 +0000
treeherdertry@9b6fa04c9520 [default view] [failures only]
bugs1242234
milestone48.0a1
Bug 1242234 - Debugging intermittent MozReview-Commit-ID: IIVOczLD3zS
devtools/client/framework/test/shared-head.js
devtools/client/webconsole/test/browser_webconsole_netlogging.js
--- a/devtools/client/framework/test/shared-head.js
+++ b/devtools/client/framework/test/shared-head.js
@@ -249,16 +249,31 @@ var openToolboxForTab = Task.async(funct
  * toolbox has been opened. Resolves to the toolbox.
  */
 var openNewTabAndToolbox = Task.async(function*(url, toolId, hostType) {
   let tab = yield addTab(url);
   return openToolboxForTab(tab, toolId, hostType)
 });
 
 /**
+ * Close a tab and if necessary, the toolbox that belongs to it
+ * @param {Tab} tab The tab to close.
+ * @return {Promise} Resolves when the toolbox and tab have been destroyed and
+ * closed.
+ */
+var closeTabAndToolbox = Task.async(function*(tab = gBrowser.selectedTab) {
+  let target = TargetFactory.forTab(gBrowser.selectedTab);
+  if (target) {
+    yield gDevTools.closeToolbox(target);
+  }
+
+  gBrowser.removeCurrentTab();
+});
+
+/**
  * Close a toolbox and the current tab.
  * @param {Toolbox} toolbox The toolbox to close.
  * @return {Promise} Resolves when the toolbox and tab have been destroyed and
  * closed.
  */
 function closeToolboxAndTab(toolbox) {
   return toolbox.destroy().then(function() {
     gBrowser.removeCurrentTab();
--- a/devtools/client/webconsole/test/browser_webconsole_netlogging.js
+++ b/devtools/client/webconsole/test/browser_webconsole_netlogging.js
@@ -2,30 +2,42 @@
 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 // Tests response logging for different request types.
 
 "use strict";
 
+SimpleTest.testInChaosMode();
+SimpleTest.requestCompleteLog();
+
 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() {
+
+  // Enable logging in the UI.  Not needed to pass test but makes it easier
+  // to debug interactively.
+  yield new Promise(resolve => {
+    SpecialPowers.pushPrefEnv({"set":
+      [["devtools.webconsole.filter.networkinfo", true]
+    ]}, resolve);
+  });
+
   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];
@@ -35,16 +47,18 @@ add_task(function* testPageLoad() {
   is(request.request.url, TEST_NETWORK_REQUEST_URI,
     "Logged network entry is page load");
   is(request.request.method, "GET", "Method is correct");
   ok(!postData.postData.text, "No request body was stored");
   ok(!postData.postDataDiscarded,
     "Request body was not discarded");
   is(responseContent.content.text.indexOf("<!DOCTYPE HTML>"), 0,
     "Response body's beginning is okay");
+
+  yield closeTabAndToolbox();
 });
 
 add_task(function* testXhrGet() {
   let hud = yield loadPageAndGetHud(TEST_NETWORK_REQUEST_URI);
 
   let finishedRequest = waitForFinishedRequest(TEST_DATA_REQUEST_PREDICATE);
   content.wrappedJSObject.testXhrGet();
   let request = yield finishedRequest;
@@ -57,16 +71,18 @@ add_task(function* testXhrGet() {
   const responseContent = yield getPacket(client, "getResponseContent", args);
 
   is(request.request.method, "GET", "Method is correct");
   ok(!postData.postData.text, "No request body was sent");
   ok(!postData.postDataDiscarded,
     "Request body was not discarded");
   is(responseContent.content.text, TEST_DATA_JSON_CONTENT,
     "Response is correct");
+
+  yield closeTabAndToolbox();
 });
 
 add_task(function* testXhrPost() {
   let hud = yield loadPageAndGetHud(TEST_NETWORK_REQUEST_URI);
 
   let finishedRequest = waitForFinishedRequest(TEST_DATA_REQUEST_PREDICATE);
   content.wrappedJSObject.testXhrPost();
   let request = yield finishedRequest;
@@ -77,16 +93,18 @@ add_task(function* testXhrPost() {
   let args = [request.actor];
   const postData = yield getPacket(client, "getRequestPostData", args);
   const responseContent = yield getPacket(client, "getResponseContent", args);
 
   is(request.request.method, "POST", "Method is correct");
   is(postData.postData.text, "Hello world!", "Request body was logged");
   is(responseContent.content.text, TEST_DATA_JSON_CONTENT,
     "Response is correct");
+
+  yield closeTabAndToolbox();
 });
 
 add_task(function* testFormSubmission() {
   let hud = yield loadPageAndGetHud(TEST_NETWORK_REQUEST_URI);
 
   // The form POSTs to the page URL but over https (page over http).
   let finishedRequest = waitForFinishedRequest(PAGE_REQUEST_PREDICATE);
   ContentTask.spawn(gBrowser.selectedBrowser, { }, `function()
@@ -98,19 +116,23 @@ add_task(function* testFormSubmission() 
 
   ok(request, "testFormSubmission() was logged");
 
   let client = hud.ui.webConsoleClient;
   let args = [request.actor];
   const postData = yield getPacket(client, "getRequestPostData", args);
   const responseContent = yield getPacket(client, "getResponseContent", args);
 
+  info("XXX DEBUG REQUEST: " + JSON.stringify(request));
+
   is(request.request.method, "POST", "Method is correct");
   isnot(postData.postData.text
     .indexOf("Content-Type: application/x-www-form-urlencoded"), -1,
     "Content-Type is correct");
   isnot(postData.postData.text
     .indexOf("Content-Length: 20"), -1, "Content-length is correct");
   isnot(postData.postData.text
     .indexOf("name=foo+bar&age=144"), -1, "Form data is correct");
   is(responseContent.content.text.indexOf("<!DOCTYPE HTML>"), 0,
     "Response body's beginning is okay");
+
+  yield closeTabAndToolbox();
 });