Bug 1407515 - more detailed test of Open in New Tab draft
authorTom Glowka <glowka.tom@gmail.com>
Fri, 30 Mar 2018 04:33:42 +0200
changeset 775113 edf9b2a8d1d7460358445a5bf86f91cfbe73b36e
parent 775112 9ba01ea8f1450619eed970c79b7df0faa2bb0d0f
push id104611
push userbmo:glowka.tom@gmail.com
push dateFri, 30 Mar 2018 03:02:03 +0000
bugs1407515
milestone61.0a1
Bug 1407515 - more detailed test of Open in New Tab MozReview-Commit-ID: Cd7HCTg3kCJ
devtools/client/netmonitor/test/browser.ini
devtools/client/netmonitor/test/browser_net_open_request_in_tab.js
devtools/client/netmonitor/test/head.js
--- a/devtools/client/netmonitor/test/browser.ini
+++ b/devtools/client/netmonitor/test/browser.ini
@@ -35,21 +35,23 @@ support-files =
   html_single-get-page.html
   html_send-beacon.html
   html_sorting-test-page.html
   html_statistics-test-page.html
   html_status-codes-test-page.html
   html_api-calls-test-page.html
   html_copy-as-curl.html
   html_curl-utils.html
+  html_open-request-in-tab.html
   sjs_content-type-test-server.sjs
   sjs_cors-test-server.sjs
   sjs_https-redirect-test-server.sjs
   sjs_hsts-test-server.sjs
   sjs_json-test-server.sjs
+  sjs_method-test-server.sjs
   sjs_simple-test-server.sjs
   sjs_simple-unsorted-cookies-test-server.sjs
   sjs_sorting-test-server.sjs
   sjs_status-codes-test-server.sjs
   sjs_truncate-test-server.sjs
   test-image.png
   service-workers/status-codes.html
   service-workers/status-codes-service-worker.js
--- a/devtools/client/netmonitor/test/browser_net_open_request_in_tab.js
+++ b/devtools/client/netmonitor/test/browser_net_open_request_in_tab.js
@@ -3,38 +3,87 @@
 
 "use strict";
 
 /**
  * Tests if Open in new tab works.
  */
 
 add_task(async function() {
-  let { tab, monitor } = await initNetMonitor(CUSTOM_GET_URL);
+  let { tab, monitor } = await initNetMonitor(OPEN_REQUEST_IN_TAB_URL);
   info("Starting test...");
 
   let { document, store, windowRequire } = monitor.panelWin;
   let contextMenuDoc = monitor.panelWin.parent.document;
   let Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
+  let newTab;
 
   store.dispatch(Actions.batchEnable(false));
 
-  // Execute requests.
-  await performRequests(monitor, tab, 1);
+  // Post data may be fetched for other componentes (eg. headers panel)
+  // and as a side-effect in those situation hide existing bug (Bug 1407515)
+  await changeDefaultDetailsPanel;
 
-  wait = waitForDOM(contextMenuDoc, "#request-list-context-newtab");
-  EventUtils.sendMouseEvent({ type: "mousedown" },
-    document.querySelectorAll(".request-list-item")[0]);
-  EventUtils.sendMouseEvent({ type: "contextmenu" },
-    document.querySelectorAll(".request-list-item")[0]);
-  await wait;
+  // Open GET request in new tab
+  await performRequest("GET");
+  newTab = await openLastRequestInTab();
+  await checkTabResponse(newTab, "GET");
 
-  let onTabOpen = once(gBrowser.tabContainer, "TabOpen", false);
-  monitor.panelWin.parent.document
-    .querySelector("#request-list-context-newtab").click();
-  await onTabOpen;
-
-  ok(true, "A new tab has been opened");
+  // Open POST request in new tab
+  await performRequest("POST");
+  newTab = await openLastRequestInTab();
+  await checkTabResponse(newTab, "POST");
 
   await teardown(monitor);
 
   gBrowser.removeCurrentTab();
+
+  async function openLastRequestInTab() {
+    let wait = waitForDOM(contextMenuDoc, "#request-list-context-newtab");
+    let requestItems = document.querySelectorAll(".request-list-item");
+    let lastRequest = requestItems[requestItems.length - 1];
+    EventUtils.sendMouseEvent({ type: "mousedown" }, lastRequest);
+    EventUtils.sendMouseEvent({ type: "contextmenu" }, lastRequest);
+    await wait;
+
+    let onTabOpen = once(gBrowser.tabContainer, "TabOpen", false);
+    monitor.panelWin.parent.document
+      .querySelector("#request-list-context-newtab").click();
+    await onTabOpen;
+    ok(true, "A new tab has been opened");
+
+    let awaitedTab = gBrowser.selectedTab;
+    await BrowserTestUtils.browserLoaded(awaitedTab.linkedBrowser);
+    info("The tab load completed");
+
+    return awaitedTab;
+  }
+
+  async function performRequest(method) {
+    let wait = waitForNetworkEvents(monitor, 1);
+    await ContentTask.spawn(tab.linkedBrowser, method, async function(meth) {
+      content.wrappedJSObject.performRequest(meth);
+    });
+    await wait;
+  }
+
+  async function checkTabResponse(checkedTab, method) {
+    await ContentTask.spawn(checkedTab.linkedBrowser, method, async function(met) {
+      // let wait = waitForDOM(contextMenuDoc, "#request-list-context-newtab");
+      let win = content.wrappedJSObject;
+      // console.log(win.document.querySelectorAll("*"));
+      console.log("#######################################");
+      console.log(win.document.body.innerHTML);
+
+      let responseRE = RegExp(met + (met == "POST" ? "\n*\s*foo\=bar\&amp;baz\=42" : ""));
+      ok(win.document.body.innerHTML.match(responseRE), "Method and data matching");
+    });
+  }
+
+  async function changeDefaultDetailsPanel() {
+    EventUtils.sendMouseEvent({ type: "click" },
+    document.querySelector(".network-details-panel-toggle"));
+    EventUtils.sendMouseEvent({ type: "click" },
+      document.querySelector("#security-tab"));
+    await waitUntil(() => document.querySelector(
+      "#security-panel .security-info-value"));
+    };
 });
--- a/devtools/client/netmonitor/test/head.js
+++ b/devtools/client/netmonitor/test/head.js
@@ -58,26 +58,28 @@ const INFINITE_GET_URL = EXAMPLE_URL + "
 const CUSTOM_GET_URL = EXAMPLE_URL + "html_custom-get-page.html";
 const SINGLE_GET_URL = EXAMPLE_URL + "html_single-get-page.html";
 const STATISTICS_URL = EXAMPLE_URL + "html_statistics-test-page.html";
 const CURL_URL = EXAMPLE_URL + "html_copy-as-curl.html";
 const CURL_UTILS_URL = EXAMPLE_URL + "html_curl-utils.html";
 const SEND_BEACON_URL = EXAMPLE_URL + "html_send-beacon.html";
 const CORS_URL = EXAMPLE_URL + "html_cors-test-page.html";
 const PAUSE_URL = EXAMPLE_URL + "html_pause-test-page.html";
+const OPEN_REQUEST_IN_TAB_URL = EXAMPLE_URL + "html_open-request-in-tab.html";
 
 const SIMPLE_SJS = EXAMPLE_URL + "sjs_simple-test-server.sjs";
 const SIMPLE_UNSORTED_COOKIES_SJS = EXAMPLE_URL + "sjs_simple-unsorted-cookies-test-server.sjs";
 const CONTENT_TYPE_SJS = EXAMPLE_URL + "sjs_content-type-test-server.sjs";
 const HTTPS_CONTENT_TYPE_SJS = HTTPS_EXAMPLE_URL + "sjs_content-type-test-server.sjs";
 const STATUS_CODES_SJS = EXAMPLE_URL + "sjs_status-codes-test-server.sjs";
 const SORTING_SJS = EXAMPLE_URL + "sjs_sorting-test-server.sjs";
 const HTTPS_REDIRECT_SJS = EXAMPLE_URL + "sjs_https-redirect-test-server.sjs";
 const CORS_SJS_PATH = "/browser/devtools/client/netmonitor/test/sjs_cors-test-server.sjs";
 const HSTS_SJS = EXAMPLE_URL + "sjs_hsts-test-server.sjs";
+const METHOD_SJS = EXAMPLE_URL + "sjs_method-test-server.sjs";
 
 const HSTS_BASE_URL = EXAMPLE_URL;
 const HSTS_PAGE_URL = CUSTOM_GET_URL;
 
 const TEST_IMAGE = EXAMPLE_URL + "test-image.png";
 const TEST_IMAGE_DATA_URI = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAHWSURBVHjaYvz//z8DJQAggJiQOe/fv2fv7Oz8rays/N+VkfG/iYnJfyD/1+rVq7ffu3dPFpsBAAHEAHIBCJ85c8bN2Nj4vwsDw/8zQLwKiO8CcRoQu0DxqlWrdsHUwzBAAIGJmTNnPgYa9j8UqhFElwPxf2MIDeIrKSn9FwSJoRkAEEAM0DD4DzMAyPi/G+QKY4hh5WAXGf8PDQ0FGwJ22d27CjADAAIIrLmjo+MXA9R2kAHvGBA2wwx6B8W7od6CeQcggKCmCEL8bgwxYCbUIGTDVkHDBia+CuotgACCueD3TDQN75D4xmAvCoK9ARMHBzAw0AECiBHkAlC0Mdy7x9ABNA3obAZXIAa6iKEcGlMVQHwWyjYuL2d4v2cPg8vZswx7gHyAAAK7AOif7SAbOqCmn4Ha3AHFsIDtgPq/vLz8P4MSkJ2W9h8ggBjevXvHDo4FQUQg/kdypqCg4H8lUIACnQ/SOBMYI8bAsAJFPcj1AAEEjwVQqLpAbXmH5BJjqI0gi9DTAAgDBBCcAVLkgmQ7yKCZxpCQxqUZhAECCJ4XgMl493ug21ZD+aDAXH0WLM4A9MZPXJkJIIAwTAR5pQMalaCABQUULttBGCCAGCnNzgABBgAMJ5THwGvJLAAAAABJRU5ErkJggg==";
 
 /* eslint-enable no-unused-vars, max-len */