Bug 1354495 - Add regex filtering for network monitor. r=ntim
authorRuturaj K. Vartak <ruturaj@gmail.com>
Fri, 28 Apr 2017 20:07:00 +0100
changeset 355768 5bc16cdc9f854e2617bb0d00a2c8c251b9b16ce2
parent 355767 e6343ab01a43a330302c7f05ef98ea73a953f1a9
child 355769 fec7caf1bf50842109e948e3cf0f4335b49148f2
push id89736
push userntim.bugs@gmail.com
push dateSat, 29 Apr 2017 11:24:25 +0000
treeherdermozilla-inbound@5bc16cdc9f85 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersntim
bugs1354495
milestone55.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 1354495 - Add regex filtering for network monitor. r=ntim - Impelemnted "regexp" prefix filter - Added a test case MozReview-Commit-ID: HxteI0s0pto
devtools/client/netmonitor/src/utils/filter-text-utils.js
devtools/client/netmonitor/test/browser_net_filter-flags.js
--- a/devtools/client/netmonitor/src/utils/filter-text-utils.js
+++ b/devtools/client/netmonitor/src/utils/filter-text-utils.js
@@ -41,16 +41,17 @@ const FILTER_FLAGS = [
   "scheme",
   "set-cookie-domain",
   "set-cookie-name",
   "set-cookie-value",
   "mime-type",
   "larger-than",
   "is",
   "has-response-header",
+  "regexp",
 ];
 
 /*
   The function `parseFilters` is from:
   https://github.com/ChromeDevTools/devtools-frontend/
 
   front_end/network/FilterSuggestionBuilder.js#L138-L163
   Commit f340aefd7ec9b702de9366a812288cfb12111fce
@@ -88,16 +89,18 @@ function parseFilters(query) {
     });
   }
 
   return { text, flags };
 }
 
 function processFlagFilter(type, value) {
   switch (type) {
+    case "regexp":
+      return value;
     case "size":
     case "transferred":
     case "larger-than":
       let multiplier = 1;
       if (value.endsWith("k")) {
         multiplier = 1024;
         value = value.substring(0, value.length - 1);
       } else if (value.endsWith("m")) {
@@ -177,16 +180,24 @@ function isFlagFilterMatch(item, { type,
       } else if (value === "running") {
         match = !item.status;
       }
       break;
     case "scheme":
       let scheme = new URL(item.url).protocol.replace(":", "").toLowerCase();
       match = scheme === value;
       break;
+    case "regexp":
+      try {
+        let pattern = new RegExp(value);
+        match = pattern.test(item.url);
+      } catch (e) {
+        match = false;
+      }
+      break;
     case "set-cookie-domain":
       if (responseCookies.length > 0) {
         let host = item.urlDetails.host;
         let i = responseCookies.findIndex(c => {
           let domain = c.hasOwnProperty("domain") ? c.domain : host;
           return domain === value;
         });
         match = i > -1;
--- a/devtools/client/netmonitor/test/browser_net_filter-flags.js
+++ b/devtools/client/netmonitor/test/browser_net_filter-flags.js
@@ -178,16 +178,20 @@ add_task(function* () {
 
   setFreetextFilter("scheme:https");
   testContents([0, 0, 0, 0, 0, 0, 0, 0]);
 
   // Test mixing flags
   setFreetextFilter("-mime-type:HtmL status-code:200");
   testContents([0, 1, 1, 1, 1, 1, 1, 0]);
 
+  // Test regex filter
+  setFreetextFilter("regexp:content.*?Sam");
+  testContents([1, 0, 0, 0, 0, 0, 0, 0]);
+
   yield teardown(monitor);
 
   function testContents(visibility) {
     const items = getSortedRequests(gStore.getState());
     const visibleItems = getDisplayedRequests(gStore.getState());
 
     is(items.size, visibility.length,
       "There should be a specific amount of items in the requests menu.");