Bug 1363914 - Added tests for filter flags: protocol, domain, remote-ip, has-response-headers, cause, transferred, larger-than and size; r?honza draft
authorMatt R <matthieu.rigolot@gmail.com>
Tue, 23 May 2017 19:18:37 +0100
changeset 584737 cbeb6fc93d05
parent 582001 5b74bbf20e80
child 630501 f023d4f80515
push id60867
push userbmo:matthieu.rigolot@gmail.com
push dateThu, 25 May 2017 23:01:58 +0000
reviewershonza
bugs1363914
milestone55.0a1
Bug 1363914 - Added tests for filter flags: protocol, domain, remote-ip, has-response-headers, cause, transferred, larger-than and size; r?honza MozReview-Commit-ID: 5074qyestx8
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
@@ -201,17 +201,17 @@ function isFlagFilterMatch(item, { type,
   }
   if (negative) {
     return !match;
   }
   return match;
 }
 
 function isSizeMatch(value, size) {
-  return value >= (size - size / 10) && value < (size + size / 10);
+  return value >= (size - size / 10) && value <= (size + size / 10);
 }
 
 function isTextFilterMatch({ url }, text) {
   let lowerCaseUrl = url.toLowerCase();
   let lowerCaseText = text.toLowerCase();
   let textLength = text.length;
   // Support negative filtering
   if (text.startsWith("-") && textLength > 1) {
--- a/devtools/client/netmonitor/test/browser_net_filter-flags.js
+++ b/devtools/client/netmonitor/test/browser_net_filter-flags.js
@@ -11,16 +11,17 @@ const REQUESTS = [
   { url: "sjs_content-type-test-server.sjs?fmt=html&res=undefined&text=Sample" +
          "&cookies=1" },
   { url: "sjs_content-type-test-server.sjs?fmt=css&text=sample" },
   { url: "sjs_content-type-test-server.sjs?fmt=js&text=sample" },
   { url: "sjs_content-type-test-server.sjs?fmt=font" },
   { url: "sjs_content-type-test-server.sjs?fmt=image" },
   { url: "sjs_content-type-test-server.sjs?fmt=audio" },
   { url: "sjs_content-type-test-server.sjs?fmt=video" },
+  { url: "sjs_content-type-test-server.sjs?fmt=gzip" },
   { url: "sjs_status-codes-test-server.sjs?sts=304" },
 ];
 
 const EXPECTED_REQUESTS = [
   {
     method: "GET",
     url: CONTENT_TYPE_SJS + "?fmt=html",
     data: {
@@ -105,16 +106,28 @@ const EXPECTED_REQUESTS = [
       status: 200,
       statusText: "OK",
       type: "webm",
       fullMimeType: "video/webm"
     },
   },
   {
     method: "GET",
+    url: CONTENT_TYPE_SJS + "?fmt=gzip",
+    data: {
+      fuzzyUrl: true,
+      status: 200,
+      statusText: "OK",
+      displayedStatus: "200",
+      type: "plain",
+      fullMimeType: "text/plain"
+    }
+  },
+  {
+    method: "GET",
     url: STATUS_CODES_SJS + "?sts=304",
     data: {
       status: 304,
       statusText: "Not Modified",
       displayedStatus: "304",
       type: "plain",
       fullMimeType: "text/plain; charset=utf-8"
     }
@@ -140,107 +153,196 @@ add_task(function* () {
 
   let waitNetwork = waitForNetworkEvents(monitor, REQUESTS.length);
   loadCommonFrameScript();
   yield performRequestsInContent(REQUESTS);
   yield waitNetwork;
 
   // Test running flag once requests finish running
   setFreetextFilter("is:running");
-  testContents([0, 0, 0, 0, 0, 0, 0, 0, 0]);
+  testContents([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
 
   // Test cached flag
   setFreetextFilter("is:from-cache");
-  testContents([0, 0, 0, 0, 0, 0, 0, 0, 1]);
+  testContents([0, 0, 0, 0, 0, 0, 0, 0, 0, 1]);
 
   setFreetextFilter("is:cached");
-  testContents([0, 0, 0, 0, 0, 0, 0, 0, 1]);
+  testContents([0, 0, 0, 0, 0, 0, 0, 0, 0, 1]);
 
   // Test negative cached flag
   setFreetextFilter("-is:from-cache");
-  testContents([1, 1, 1, 1, 1, 1, 1, 1, 0]);
+  testContents([1, 1, 1, 1, 1, 1, 1, 1, 1, 0]);
 
   setFreetextFilter("-is:cached");
-  testContents([1, 1, 1, 1, 1, 1, 1, 1, 0]);
+  testContents([1, 1, 1, 1, 1, 1, 1, 1, 1, 0]);
 
   // Test status-code flag
   setFreetextFilter("status-code:200");
-  testContents([1, 1, 1, 1, 1, 1, 1, 1, 0]);
+  testContents([1, 1, 1, 1, 1, 1, 1, 1, 1, 0]);
 
   // Test status-code negative flag
   setFreetextFilter("-status-code:200");
-  testContents([0, 0, 0, 0, 0, 0, 0, 0, 1]);
+  testContents([0, 0, 0, 0, 0, 0, 0, 0, 0, 1]);
 
   // Test mime-type flag
   setFreetextFilter("mime-type:HtmL");
-  testContents([1, 1, 0, 0, 0, 0, 0, 0, 0]);
+  testContents([1, 1, 0, 0, 0, 0, 0, 0, 0, 0]);
 
   // Test mime-type negative flag
   setFreetextFilter("-mime-type:HtmL");
-  testContents([0, 0, 1, 1, 1, 1, 1, 1, 1]);
+  testContents([0, 0, 1, 1, 1, 1, 1, 1, 1, 1]);
 
   // Test method flag
   setFreetextFilter("method:get");
-  testContents([1, 1, 1, 1, 1, 1, 1, 1, 1]);
+  testContents([1, 1, 1, 1, 1, 1, 1, 1, 1, 1]);
 
   // Test unmatched method flag
   setFreetextFilter("method:post");
-  testContents([0, 0, 0, 0, 0, 0, 0, 0, 0]);
+  testContents([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
 
   // Test scheme flag (all requests are http)
   setFreetextFilter("scheme:http");
-  testContents([1, 1, 1, 1, 1, 1, 1, 1, 1]);
+  testContents([1, 1, 1, 1, 1, 1, 1, 1, 1, 1]);
 
   setFreetextFilter("scheme:https");
-  testContents([0, 0, 0, 0, 0, 0, 0, 0, 0]);
+  testContents([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
 
   // Test regex filter
   setFreetextFilter("regexp:content.*?Sam");
-  testContents([1, 1, 0, 0, 0, 0, 0, 0, 0]);
+  testContents([1, 1, 0, 0, 0, 0, 0, 0, 0, 0]);
 
   // Test set-cookie-name flag
   setFreetextFilter("set-cookie-name:name2");
-  testContents([0, 1, 0, 0, 0, 0, 0, 0, 0]);
+  testContents([0, 1, 0, 0, 0, 0, 0, 0, 0, 0]);
 
   setFreetextFilter("set-cookie-name:not-existing");
-  testContents([0, 0, 0, 0, 0, 0, 0, 0, 0]);
+  testContents([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
 
   // Test set-cookie-value flag
   setFreetextFilter("set-cookie-value:value2");
-  testContents([0, 1, 0, 0, 0, 0, 0, 0, 0]);
+  testContents([0, 1, 0, 0, 0, 0, 0, 0, 0, 0]);
 
   setFreetextFilter("set-cookie-value:not-existing");
-  testContents([0, 0, 0, 0, 0, 0, 0, 0, 0]);
+  testContents([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
 
   // Test set-cookie-domain flag
   setFreetextFilter("set-cookie-domain:.example.com");
-  testContents([0, 1, 0, 0, 0, 0, 0, 0, 0]);
+  testContents([0, 1, 0, 0, 0, 0, 0, 0, 0, 0]);
 
   setFreetextFilter("set-cookie-domain:.foo.example.com");
-  testContents([0, 1, 0, 0, 0, 0, 0, 0, 0]);
+  testContents([0, 1, 0, 0, 0, 0, 0, 0, 0, 0]);
 
   setFreetextFilter("set-cookie-domain:.not-existing.example.com");
-  testContents([0, 0, 0, 0, 0, 0, 0, 0, 0]);
+  testContents([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
+
+  // Test size
+  setFreetextFilter("size:-1");
+  testContents([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
+
+  setFreetextFilter("size:0");
+  testContents([0, 0, 0, 0, 1, 1, 1, 1, 0, 1]);
+
+  setFreetextFilter("size:34");
+  testContents([0, 0, 1, 1, 0, 0, 0, 0, 0, 0]);
+
+  // Testing the lower bound
+  setFreetextFilter("size:9.659k");
+  testContents([0, 0, 0, 0, 0, 0, 0, 0, 1, 0]);
+
+  // Testing the actual value
+  setFreetextFilter("size:10989");
+  testContents([0, 0, 0, 0, 0, 0, 0, 0, 1, 0]);
+
+  // Testing the upper bound
+  setFreetextFilter("size:11.804k");
+  testContents([0, 0, 0, 0, 0, 0, 0, 0, 1, 0]);
+
+  // Test transferred
+  setFreetextFilter("transferred:0");
+  testContents([0, 0, 0, 0, 1, 1, 1, 1, 0, 1]);
+
+  setFreetextFilter("transferred:1");
+  testContents([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
+
+  setFreetextFilter("transferred:34");
+  testContents([0, 0, 1, 1, 0, 0, 0, 0, 0, 0]);
+
+  // Test larger-than
+  setFreetextFilter("larger-than:-1");
+  testContents([1, 1, 1, 1, 1, 1, 1, 1, 1, 1]);
+
+  setFreetextFilter("larger-than:0");
+  testContents([1, 1, 1, 1, 0, 0, 0, 0, 1, 0]);
+
+  setFreetextFilter("larger-than:33");
+  testContents([0, 0, 1, 1, 0, 0, 0, 0, 1, 0]);
+
+  setFreetextFilter("larger-than:34");
+  testContents([0, 0, 0, 0, 0, 0, 0, 0, 1, 0]);
+
+  setFreetextFilter("larger-than:10.73k");
+  testContents([0, 0, 0, 0, 0, 0, 0, 0, 1, 0]);
+
+  setFreetextFilter("larger-than:10.732k");
+  testContents([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
 
   // Test transferred-larger-than
   setFreetextFilter("transferred-larger-than:-1");
-  testContents([1, 1, 1, 1, 1, 1, 1, 1, 1]);
+  testContents([1, 1, 1, 1, 1, 1, 1, 1, 1, 1]);
 
   setFreetextFilter("transferred-larger-than:0");
-  testContents([1, 1, 1, 1, 0, 0, 0, 0, 0]);
+  testContents([1, 1, 1, 1, 0, 0, 0, 0, 1, 0]);
 
   setFreetextFilter("transferred-larger-than:33");
-  testContents([0, 0, 1, 1, 0, 0, 0, 0, 0]);
+  testContents([0, 0, 1, 1, 0, 0, 0, 0, 1, 0]);
 
   setFreetextFilter("transferred-larger-than:34");
-  testContents([0, 0, 0, 0, 0, 0, 0, 0, 0]);
+  testContents([0, 0, 0, 0, 0, 0, 0, 0, 1, 0]);
+
+  setFreetextFilter("transferred-larger-than:10.73k");
+  testContents([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
+
+  // Test cause
+  setFreetextFilter("cause:xhr");
+  testContents([1, 1, 1, 1, 1, 1, 1, 1, 1, 1]);
+
+  setFreetextFilter("cause:script");
+  testContents([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
+
+  // Test has-response-header
+  setFreetextFilter("has-response-header:Content-Type");
+  testContents([1, 1, 1, 1, 1, 1, 1, 1, 1, 1]);
+
+  setFreetextFilter("has-response-header:Last-Modified");
+  testContents([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
+
+  // Test remote-ip
+  setFreetextFilter("remote-ip:127.0.0.1");
+  testContents([1, 1, 1, 1, 1, 1, 1, 1, 1, 1]);
+
+  setFreetextFilter("remote-ip:192.168.1.2");
+  testContents([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
+
+  // Test domain
+  setFreetextFilter("domain:example.com");
+  testContents([1, 1, 1, 1, 1, 1, 1, 1, 1, 1]);
+
+  setFreetextFilter("domain:wrongexample.com");
+  testContents([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
+
+  // Test protocol
+  setFreetextFilter("protocol:http/1");
+  testContents([1, 1, 1, 1, 1, 1, 1, 1, 1, 1]);
+
+  setFreetextFilter("protocol:http/2");
+  testContents([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
 
   // Test mixing flags
   setFreetextFilter("-mime-type:HtmL status-code:200");
-  testContents([0, 0, 1, 1, 1, 1, 1, 1, 0]);
+  testContents([0, 0, 1, 1, 1, 1, 1, 1, 1, 0]);
 
   yield teardown(monitor);
 
   function testContents(visibility) {
     const items = getSortedRequests(store.getState());
     const visibleItems = getDisplayedRequests(store.getState());
 
     is(items.size, visibility.length,