Bug 1492730 - network: show resent XHR when filtering r=honza
authormeagonqz <meag.harty@gmail.com>
Tue, 25 Sep 2018 00:31:09 -0400
changeset 488295 c6e6514203c9172dd1cbc99c505d42ae84e8b32a
parent 488294 4de4f6aaef1056ec2d7f3555f7afb1595fb0e4ed
child 488296 374ebbfb522e2343178ed85f54ff623d851a2afe
push id246
push userfmarier@mozilla.com
push dateSat, 13 Oct 2018 00:15:40 +0000
reviewershonza
bugs1492730
milestone64.0a1
Bug 1492730 - network: show resent XHR when filtering r=honza
devtools/client/netmonitor/src/selectors/requests.js
devtools/client/netmonitor/test/browser.ini
devtools/client/netmonitor/test/browser_net_edit_resend_with_filtering.js
--- a/devtools/client/netmonitor/src/selectors/requests.js
+++ b/devtools/client/netmonitor/src/selectors/requests.js
@@ -30,20 +30,27 @@ function sortWithClones(requests, sorter
       return -1;
     }
     b = requests.get(bOrigId);
   }
 
   return sorter(a, b);
 }
 
-const getFilterFn = createSelector(
+/**
+ * Take clones into account when filtering. If a request is
+ * a clone, it's not filtered out.
+ */
+const getFilterWithCloneFn = createSelector(
   state => state.filters,
   filters => r => {
     const matchesType = Object.keys(filters.requestFilterTypes).some(filter => {
+      if (r.id.endsWith("-clone")) {
+        return true;
+      }
       return filters.requestFilterTypes[filter] && Filters[filter] && Filters[filter](r);
     });
     return matchesType && isFreetextMatch(r, filters.requestFilterText);
   }
 );
 
 const getTypeFilterFn = createSelector(
   state => state.filters,
@@ -73,17 +80,17 @@ const getSortedRequests = createSelector
     arr.isEmpty = () => this.length == 0;
     arr.size = arr.length;
     return arr;
   }
 );
 
 const getDisplayedRequests = createSelector(
   state => state.requests,
-  getFilterFn,
+  getFilterWithCloneFn,
   getSortFn,
   ({ requests }, filterFn, sortFn) => {
     const arr = [...requests.values()].filter(filterFn).sort(sortFn);
     arr.get = index => arr[index];
     arr.isEmpty = () => this.length == 0;
     arr.size = arr.length;
     return arr;
   }
--- a/devtools/client/netmonitor/test/browser.ini
+++ b/devtools/client/netmonitor/test/browser.ini
@@ -115,16 +115,17 @@ skip-if = (verify && debug && os == 'win
 subsuite = clipboard
 [browser_net_cors_requests.js]
 [browser_net_cyrillic-01.js]
 [browser_net_cyrillic-02.js]
 [browser_net_frame.js]
 skip-if = (os == 'mac') # Bug 1479782
 [browser_net_header-docs.js]
 [browser_net_edit_resend_caret.js]
+[browser_net_edit_resend_with_filtering.js]
 [browser_net_filter-01.js]
 [browser_net_filter-02.js]
 [browser_net_filter-03.js]
 [browser_net_filter-04.js]
 [browser_net_filter-autocomplete.js]
 [browser_net_filter-flags.js]
 [browser_net_footer-summary.js]
 [browser_net_headers-alignment.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/netmonitor/test/browser_net_edit_resend_with_filtering.js
@@ -0,0 +1,55 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* 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/ */
+
+"use strict";
+
+/**
+ * Tests if resending a XHR request while filtering XHR displays
+ * the correct requests
+ */
+add_task(async function() {
+  const { tab, monitor } = await initNetMonitor(POST_RAW_URL);
+
+  const { document, store, windowRequire, parent } = monitor.panelWin;
+  const parentDocument = parent.document;
+  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
+  store.dispatch(Actions.batchEnable(false));
+
+  // Execute XHR request and filter by XHR
+  await performRequests(monitor, tab, 1);
+  document.querySelector(".requests-list-filter-xhr-button").click();
+
+  // Confirm XHR request and click it
+  const xhrRequestItem = document.querySelectorAll(".request-list-item")[0];
+  EventUtils.sendMouseEvent({ type: "mousedown" }, xhrRequestItem);
+
+  const {
+    getSelectedRequest
+  } = windowRequire("devtools/client/netmonitor/src/selectors/index");
+  const firstRequest = getSelectedRequest(store.getState());
+
+  // Open context menu and execute "Edit & Resend".
+  EventUtils.sendMouseEvent({ type: "contextmenu" }, xhrRequestItem);
+  parentDocument.querySelector("#request-list-context-resend").click();
+
+  // Click Resend
+  await waitUntil(() => document.querySelector("#custom-request-send-button"));
+  document.querySelector("#custom-request-send-button").click();
+
+  // Filtering by "other" so the resent request is visible after completion
+  document.querySelector(".requests-list-filter-other-button").click();
+
+  // Select the cloned request
+  document.querySelectorAll(".request-list-item")[0].click();
+  const resendRequest = getSelectedRequest(store.getState());
+
+  ok(resendRequest.id !== firstRequest.id,
+    "The second XHR request was made and is unique");
+
+  ok(resendRequest.id.replace(/-clone$/, "") == firstRequest.id,
+    "The second XHR request is a clone of the first");
+
+  return teardown(monitor);
+});