Bug 1398522 - Sort 'Request-Headers' and 'Response-Headers' in 'Headers' tab. r=Honza
authorabhinav <abhinav.koppula@gmail.com>
Sun, 17 Sep 2017 12:24:06 +0530
changeset 431688 10fe5727b04f216f68515ecb832768435a39fad8
parent 431687 bbedfc5fd8be2f4ce3442c31b93fc658c69ff68c
child 431689 003763b2e7309a445e6cacc960fab82135a3c442
push id7785
push userryanvm@gmail.com
push dateThu, 21 Sep 2017 13:39:55 +0000
treeherdermozilla-beta@06d4034a8a03 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersHonza
bugs1398522
milestone57.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 1398522 - Sort 'Request-Headers' and 'Response-Headers' in 'Headers' tab. r=Honza MozReview-Commit-ID: AbRboDl5ADU
devtools/client/netmonitor/src/components/headers-panel.js
devtools/client/netmonitor/test/browser.ini
devtools/client/netmonitor/test/browser_net_headers_sorted.js
--- a/devtools/client/netmonitor/src/components/headers-panel.js
+++ b/devtools/client/netmonitor/src/components/headers-panel.js
@@ -61,22 +61,26 @@ const HeadersPanel = createClass({
   getInitialState() {
     return {
       rawHeadersOpened: false,
     };
   },
 
   getProperties(headers, title) {
     if (headers && headers.headers.length) {
-      return {
-        [`${title} (${getFormattedSize(headers.headersSize, 3)})`]:
+      let headerKey = `${title} (${getFormattedSize(headers.headersSize, 3)})`;
+      let propertiesResult = {
+        [headerKey]:
           headers.headers.reduce((acc, { name, value }) =>
             name ? Object.assign(acc, { [name]: value }) : acc
           , {})
       };
+
+      propertiesResult[headerKey] = this.sortByKey(propertiesResult[headerKey]);
+      return propertiesResult;
     }
 
     return null;
   },
 
   toggleRawHeaders() {
     this.setState({
       rawHeadersOpened: !this.state.rawHeadersOpened,
@@ -119,16 +123,26 @@ const HeadersPanel = createClass({
         })),
         headerDocURL ? MDNLink({
           url: headerDocURL,
         }) : null
       )
     );
   },
 
+  sortByKey: function (object) {
+    let result = {};
+    Object.keys(object).sort(function (left, right) {
+      return left.toLowerCase().localeCompare(right.toLowerCase());
+    }).forEach(function (key) {
+      result[key] = object[key];
+    });
+    return result;
+  },
+
   render() {
     const {
       openLink,
       cloneSelectedRequest,
       request: {
         fromCache,
         fromServiceWorker,
         httpVersion,
--- a/devtools/client/netmonitor/test/browser.ini
+++ b/devtools/client/netmonitor/test/browser.ini
@@ -111,16 +111,17 @@ skip-if = (os == 'linux' && debug && bit
 [browser_net_filter-01.js]
 skip-if = (os == 'linux' && debug && bits == 32) # Bug 1303439
 [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_sorted.js]
 [browser_net_icon-preview.js]
 [browser_net_image-tooltip.js]
 [browser_net_json-b64.js]
 [browser_net_json-null.js]
 [browser_net_json-long.js]
 [browser_net_json-malformed.js]
 [browser_net_json_custom_mime.js]
 [browser_net_json_text_mime.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/netmonitor/test/browser_net_headers_sorted.js
@@ -0,0 +1,55 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Tests if Request-Headers and Response-Headers are sorted in Headers tab.
+ */
+add_task(function* () {
+  let { tab, monitor } = yield initNetMonitor(SIMPLE_SJS);
+  info("Starting test... ");
+
+  let { document, store, windowRequire } = monitor.panelWin;
+  let Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
+
+  store.dispatch(Actions.batchEnable(false));
+
+  tab.linkedBrowser.reload();
+
+  let wait = waitForNetworkEvents(monitor, 1);
+  yield wait;
+
+  wait = waitForDOM(document, ".headers-overview");
+  EventUtils.sendMouseEvent({ type: "mousedown" },
+    document.querySelectorAll(".request-list-item")[0]);
+  yield wait;
+
+  info("Check if Request-Headers and Response-Headers are sorted");
+  let expectedResponseHeaders = ["cache-control", "connection", "content-length",
+                                 "content-type", "date", "expires", "foo-bar",
+                                 "pragma", "server", "set-cookie"];
+  let expectedRequestHeaders = ["Accept", "Accept-Encoding", "Accept-Language",
+                                "Cache-Control", "Connection", "Cookie", "Host",
+                                "Pragma", "Upgrade-Insecure-Requests", "User-Agent"];
+
+  let labelCells = document.querySelectorAll(".treeLabelCell");
+  let actualResponseHeaders = [];
+  let actualRequestHeaders = [];
+
+  for (let i = 1; i < 11; i++) {
+    actualResponseHeaders.push(labelCells[i].innerText);
+  }
+
+  for (let i = 12; i < labelCells.length; i++) {
+    actualRequestHeaders.push(labelCells[i].innerText);
+  }
+
+  is(actualResponseHeaders.toString(), expectedResponseHeaders.toString(),
+    "Response Headers are sorted");
+
+  is(actualRequestHeaders.toString(), expectedRequestHeaders.toString(),
+    "Request Headers are sorted");
+
+  yield teardown(monitor);
+});