Bug 1151368 - Add test for DevTools request blocking. r=Honza
authorJ. Ryan Stinnett <jryans@gmail.com>
Fri, 19 Apr 2019 18:25:46 +0000
changeset 470250 6d168f63dd8d5567c198695fcde87e6340ef33a8
parent 470249 b9a2a553d0c4f8b9bd3f98e9680b925c746c5f81
child 470251 89bac5e8dbb68876891ca741c882fc0d716ea72d
push id112851
push userrgurzau@mozilla.com
push dateSat, 20 Apr 2019 10:03:47 +0000
treeherdermozilla-inbound@a092972b53f0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersHonza
bugs1151368
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1151368 - Add test for DevTools request blocking. r=Honza Differential Revision: https://phabricator.services.mozilla.com/D26582
devtools/client/netmonitor/test/browser.ini
devtools/client/netmonitor/test/browser_net_block.js
--- a/devtools/client/netmonitor/test/browser.ini
+++ b/devtools/client/netmonitor/test/browser.ini
@@ -65,16 +65,17 @@ support-files =
   !/devtools/client/shared/test/shared-head.js
   !/devtools/client/shared/test/telemetry-test-helpers.js
 
 [browser_net_accessibility-01.js]
 [browser_net_accessibility-02.js]
 [browser_net_api-calls.js]
 [browser_net_background_update.js]
 [browser_net_autoscroll.js]
+[browser_net_block.js]
 [browser_net_cached-status.js]
 skip-if = verify
 [browser_net_cause.js]
 [browser_net_cause_redirect.js]
 [browser_net_cause_source_map.js]
 [browser_net_service-worker-status.js]
 skip-if = (verify && !debug && (os == 'linux'))
 [browser_net_charts-01.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/netmonitor/test/browser_net_block.js
@@ -0,0 +1,100 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Test blocking and unblocking a request.
+ */
+
+add_task(async function() {
+  const { tab, monitor } = await initNetMonitor(SIMPLE_URL);
+  info("Starting test... ");
+
+  const { document, store, windowRequire, parent } = monitor.panelWin;
+  const {
+    getSelectedRequest,
+  } = windowRequire("devtools/client/netmonitor/src/selectors/index");
+  const parentDocument = parent.document;
+  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
+  store.dispatch(Actions.batchEnable(false));
+
+  // Reload to have one request in the list
+  let waitForEvents = waitForNetworkEvents(monitor, 1);
+  BrowserTestUtils.loadURI(tab.linkedBrowser, SIMPLE_URL);
+  await waitForEvents;
+
+  // Capture normal request
+  let normalRequestState;
+  let normalRequestSize;
+  {
+    const firstRequest = document.querySelectorAll(".request-list-item")[0];
+    const waitForHeaders = waitUntil(() => document.querySelector(".headers-overview"));
+    EventUtils.sendMouseEvent({ type: "mousedown" }, firstRequest);
+    await waitForHeaders;
+    normalRequestState = getSelectedRequest(store.getState());
+    normalRequestSize =
+      firstRequest.querySelector(".requests-list-transferred").textContent;
+    info("Captured normal request");
+    // Mark as blocked
+    EventUtils.sendMouseEvent({ type: "contextmenu" }, firstRequest);
+    const contextBlock = parentDocument.querySelector("#request-list-context-block-url");
+    contextBlock.click();
+    info("Set request to blocked");
+  }
+
+  // Reload to have one request in the list
+  info("Reloading to check block");
+  // We can't use the normal waiting methods because a canceled request won't send all
+  // the extra update packets.
+  waitForEvents = waitForNetworkEvents(monitor, 1);
+  tab.linkedBrowser.reload();
+  await waitForEvents;
+
+  // Capture blocked request, then unblock
+  let blockedRequestState;
+  let blockedRequestSize;
+  {
+    const firstRequest = document.querySelectorAll(".request-list-item")[0];
+    blockedRequestSize =
+      firstRequest.querySelector(".requests-list-transferred").textContent;
+    EventUtils.sendMouseEvent({ type: "mousedown" }, firstRequest);
+    blockedRequestState = getSelectedRequest(store.getState());
+    info("Captured blocked request");
+    // Mark as unblocked
+    EventUtils.sendMouseEvent({ type: "contextmenu" }, firstRequest);
+    const contextUnblock =
+      parentDocument.querySelector("#request-list-context-unblock-url");
+    contextUnblock.click();
+    info("Set request to unblocked");
+  }
+
+  // Reload to have one request in the list
+  info("Reloading to check unblock");
+  waitForEvents = waitForNetworkEvents(monitor, 1);
+  tab.linkedBrowser.reload();
+  await waitForEvents;
+
+  // Capture unblocked request
+  let unblockedRequestState;
+  let unblockedRequestSize;
+  {
+    const firstRequest = document.querySelectorAll(".request-list-item")[0];
+    unblockedRequestSize =
+      firstRequest.querySelector(".requests-list-transferred").textContent;
+    EventUtils.sendMouseEvent({ type: "mousedown" }, firstRequest);
+    unblockedRequestState = getSelectedRequest(store.getState());
+    info("Captured unblocked request");
+  }
+
+  ok(!normalRequestState.blockedReason, "Normal request is not blocked");
+  ok(!normalRequestSize.includes("blocked"), "Normal request has a size");
+
+  ok(blockedRequestState.blockedReason, "Blocked request is blocked");
+  ok(blockedRequestSize.includes("blocked"), "Blocked request shows reason as size");
+
+  ok(!unblockedRequestState.blockedReason, "Unblocked request is not blocked");
+  ok(!unblockedRequestSize.includes("blocked"), "Unblocked request has a size");
+
+  return teardown(monitor);
+});