Bug 1038695 - Show all cookies in Net Monitor, not just first. r=vporof, a=sledru
authorJ. Ryan Stinnett <jryans@gmail.com>
Wed, 23 Jul 2014 10:08:00 +0200
changeset 208179 bce84b70da30
parent 208178 00f079c876f6
child 208180 3808d8fbe348
push id3754
push userryanvm@gmail.com
push date2014-07-28 15:24 +0000
treeherdermozilla-beta@61b30b605194 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvporof, sledru
bugs1038695
milestone32.0
Bug 1038695 - Show all cookies in Net Monitor, not just first. r=vporof, a=sledru
browser/devtools/netmonitor/netmonitor-view.js
browser/devtools/netmonitor/test/browser_net_simple-request-data.js
browser/devtools/netmonitor/test/browser_net_simple-request-details.js
browser/devtools/netmonitor/test/sjs_simple-test-server.sjs
--- a/browser/devtools/netmonitor/netmonitor-view.js
+++ b/browser/devtools/netmonitor/netmonitor-view.js
@@ -2217,17 +2217,17 @@ NetworkDetailsView.prototype = {
       let cookieVar = cookiesScope.addItem(cookie.name, {}, true);
       let cookieValue = yield gNetwork.getString(cookie.value);
       cookieVar.setGrip(cookieValue);
 
       // By default the cookie name and value are shown. If this is the only
       // information available, then nothing else is to be displayed.
       let cookieProps = Object.keys(cookie);
       if (cookieProps.length == 2) {
-        return;
+        continue;
       }
 
       // Display any other information other than the cookie name and value
       // which may be available.
       let rawObject = Object.create(null);
       let otherProps = cookieProps.filter(e => e != "name" && e != "value");
       for (let prop of otherProps) {
         rawObject[prop] = cookie[prop];
--- a/browser/devtools/netmonitor/test/browser_net_simple-request-data.js
+++ b/browser/devtools/netmonitor/test/browser_net_simple-request-data.js
@@ -81,75 +81,75 @@ function test() {
       verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS);
     });
 
     aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_REQUEST_HEADERS, () => {
       let requestItem = RequestsMenu.getItemAtIndex(0);
 
       ok(requestItem.attachment.requestHeaders,
         "There should be a requestHeaders attachment available.");
-      is(requestItem.attachment.requestHeaders.headers.length, 8,
+      is(requestItem.attachment.requestHeaders.headers.length, 9,
         "The requestHeaders attachment has an incorrect |headers| property.");
       isnot(requestItem.attachment.requestHeaders.headersSize, 0,
         "The requestHeaders attachment has an incorrect |headersSize| property.");
       // Can't test for the exact request headers size because the value may
       // vary across platforms ("User-Agent" header differs).
 
       verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS);
     });
 
     aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_REQUEST_COOKIES, () => {
       let requestItem = RequestsMenu.getItemAtIndex(0);
 
       ok(requestItem.attachment.requestCookies,
         "There should be a requestCookies attachment available.");
-      is(requestItem.attachment.requestCookies.cookies.length, 0,
+      is(requestItem.attachment.requestCookies.cookies.length, 2,
         "The requestCookies attachment has an incorrect |cookies| property.");
 
       verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS);
     });
 
     aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_REQUEST_POST_DATA, () => {
       ok(false, "Trap listener: this request doesn't have any post data.")
     });
 
     aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_RESPONSE_HEADERS, () => {
       let requestItem = RequestsMenu.getItemAtIndex(0);
 
       ok(requestItem.attachment.responseHeaders,
         "There should be a responseHeaders attachment available.");
-      is(requestItem.attachment.responseHeaders.headers.length, 9,
+      is(requestItem.attachment.responseHeaders.headers.length, 10,
         "The responseHeaders attachment has an incorrect |headers| property.");
-      is(requestItem.attachment.responseHeaders.headersSize, 255,
+      is(requestItem.attachment.responseHeaders.headersSize, 330,
         "The responseHeaders attachment has an incorrect |headersSize| property.");
 
       verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS);
     });
 
     aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_RESPONSE_COOKIES, () => {
       let requestItem = RequestsMenu.getItemAtIndex(0);
 
       ok(requestItem.attachment.responseCookies,
         "There should be a responseCookies attachment available.");
-      is(requestItem.attachment.responseCookies.cookies.length, 0,
+      is(requestItem.attachment.responseCookies.cookies.length, 2,
         "The responseCookies attachment has an incorrect |cookies| property.");
 
       verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS);
     });
 
     aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.STARTED_RECEIVING_RESPONSE, () => {
       let requestItem = RequestsMenu.getItemAtIndex(0);
 
       is(requestItem.attachment.httpVersion, "HTTP/1.1",
         "The httpVersion attachment has an incorrect value.");
       is(requestItem.attachment.status, "200",
         "The status attachment has an incorrect value.");
       is(requestItem.attachment.statusText, "Och Aye",
         "The statusText attachment has an incorrect value.");
-      is(requestItem.attachment.headersSize, 255,
+      is(requestItem.attachment.headersSize, 330,
         "The headersSize attachment has an incorrect value.");
 
       verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, {
         status: "200",
         statusText: "Och Aye"
       });
     });
 
--- a/browser/devtools/netmonitor/test/browser_net_simple-request-details.js
+++ b/browser/devtools/netmonitor/test/browser_net_simple-request-details.js
@@ -30,17 +30,17 @@ function test() {
         "There should be a selected item in the requests menu.");
       is(RequestsMenu.selectedIndex, 0,
         "The first item should be selected in the requests menu.");
       is(NetMonitorView.detailsPaneHidden, false,
         "The details pane should not be hidden after toggle button was pressed.");
 
       yield waitFor(aMonitor.panelWin, TAB_UPDATED)
       testHeadersTab();
-      testCookiesTab();
+      yield testCookiesTab();
       testParamsTab();
       yield testResponseTab();
       testTimingsTab();
       yield teardown(aMonitor);
       finish();
     });
 
     function testHeadersTab() {
@@ -58,28 +58,28 @@ function test() {
         "GET", "The method summary value is incorrect.");
       is(tabpanel.querySelector("#headers-summary-status-circle").getAttribute("code"),
         "200", "The status summary code is incorrect.");
       is(tabpanel.querySelector("#headers-summary-status-value").getAttribute("value"),
         "200 Och Aye", "The status summary value is incorrect.");
 
       is(tabpanel.querySelectorAll(".variables-view-scope").length, 2,
         "There should be 2 header scopes displayed in this tabpanel.");
-      is(tabpanel.querySelectorAll(".variable-or-property").length, 17,
-        "There should be 17 header values displayed in this tabpanel.");
+      is(tabpanel.querySelectorAll(".variable-or-property").length, 19,
+        "There should be 19 header values displayed in this tabpanel.");
 
       is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 0,
         "The empty notice should not be displayed in this tabpanel.");
 
       let responseScope = tabpanel.querySelectorAll(".variables-view-scope")[0];
       let requestScope = tabpanel.querySelectorAll(".variables-view-scope")[1];
 
       is(responseScope.querySelector(".name").getAttribute("value"),
         L10N.getStr("responseHeaders") + " (" +
-        L10N.getFormatStr("networkMenu.sizeKB", L10N.numberWithDecimals(255/1024, 3)) + ")",
+        L10N.getFormatStr("networkMenu.sizeKB", L10N.numberWithDecimals(330/1024, 3)) + ")",
         "The response headers scope doesn't have the correct title.");
 
       ok(requestScope.querySelector(".name").getAttribute("value").contains(
         L10N.getStr("requestHeaders") + " (0"),
         "The request headers scope doesn't have the correct title.");
       // Can't test for full request headers title because the size may
       // vary across platforms ("User-Agent" header differs). We're pretty
       // sure it's smaller than 1 MB though, so it starts with a 0.
@@ -95,55 +95,57 @@ function test() {
       is(responseScope.querySelectorAll(".variables-view-variable .name")[2].getAttribute("value"),
         "Content-Length", "The third response header name was incorrect.");
       is(responseScope.querySelectorAll(".variables-view-variable .value")[2].getAttribute("value"),
         "\"12\"", "The third response header value was incorrect.");
       is(responseScope.querySelectorAll(".variables-view-variable .name")[3].getAttribute("value"),
         "Content-Type", "The fourth response header name was incorrect.");
       is(responseScope.querySelectorAll(".variables-view-variable .value")[3].getAttribute("value"),
         "\"text/plain; charset=utf-8\"", "The fourth response header value was incorrect.");
-      is(responseScope.querySelectorAll(".variables-view-variable .name")[8].getAttribute("value"),
+      is(responseScope.querySelectorAll(".variables-view-variable .name")[9].getAttribute("value"),
         "foo-bar", "The last response header name was incorrect.");
-      is(responseScope.querySelectorAll(".variables-view-variable .value")[8].getAttribute("value"),
+      is(responseScope.querySelectorAll(".variables-view-variable .value")[9].getAttribute("value"),
         "\"baz\"", "The last response header value was incorrect.");
 
       is(requestScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"),
         "Host", "The first request header name was incorrect.");
       is(requestScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"),
         "\"example.com\"", "The first request header value was incorrect.");
-      is(requestScope.querySelectorAll(".variables-view-variable .name")[5].getAttribute("value"),
+      is(requestScope.querySelectorAll(".variables-view-variable .name")[6].getAttribute("value"),
         "Connection", "The ante-penultimate request header name was incorrect.");
-      is(requestScope.querySelectorAll(".variables-view-variable .value")[5].getAttribute("value"),
+      is(requestScope.querySelectorAll(".variables-view-variable .value")[6].getAttribute("value"),
         "\"keep-alive\"", "The ante-penultimate request header value was incorrect.");
-      is(requestScope.querySelectorAll(".variables-view-variable .name")[6].getAttribute("value"),
+      is(requestScope.querySelectorAll(".variables-view-variable .name")[7].getAttribute("value"),
         "Pragma", "The penultimate request header name was incorrect.");
-      is(requestScope.querySelectorAll(".variables-view-variable .value")[6].getAttribute("value"),
+      is(requestScope.querySelectorAll(".variables-view-variable .value")[7].getAttribute("value"),
         "\"no-cache\"", "The penultimate request header value was incorrect.");
-      is(requestScope.querySelectorAll(".variables-view-variable .name")[7].getAttribute("value"),
+      is(requestScope.querySelectorAll(".variables-view-variable .name")[8].getAttribute("value"),
         "Cache-Control", "The last request header name was incorrect.");
-      is(requestScope.querySelectorAll(".variables-view-variable .value")[7].getAttribute("value"),
+      is(requestScope.querySelectorAll(".variables-view-variable .value")[8].getAttribute("value"),
         "\"no-cache\"", "The last request header value was incorrect.");
     }
 
     function testCookiesTab() {
       EventUtils.sendMouseEvent({ type: "mousedown" },
         document.querySelectorAll("#details-pane tab")[1]);
 
-      let tab = document.querySelectorAll("#details-pane tab")[1];
-      let tabpanel = document.querySelectorAll("#details-pane tabpanel")[1];
+      return Task.spawn(function*() {
+        yield waitFor(aMonitor.panelWin, TAB_UPDATED);
 
-      is(tab.getAttribute("selected"), "true",
-        "The cookies tab in the network details pane should be selected.");
+        let tab = document.querySelectorAll("#details-pane tab")[1];
+        let tabpanel = document.querySelectorAll("#details-pane tabpanel")[1];
 
-      is(tabpanel.querySelectorAll(".variables-view-scope").length, 0,
-        "There should be no cookie scopes displayed in this tabpanel.");
-      is(tabpanel.querySelectorAll(".variable-or-property").length, 0,
-        "There should be no cookie values displayed in this tabpanel.");
-      is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 1,
-        "The empty notice should be displayed in this tabpanel.");
+        is(tab.getAttribute("selected"), "true",
+          "The cookies tab in the network details pane should be selected.");
+
+        is(tabpanel.querySelectorAll(".variables-view-scope").length, 2,
+          "There should be 2 cookie scopes displayed in this tabpanel.");
+        is(tabpanel.querySelectorAll(".variable-or-property").length, 6,
+          "There should be 6 cookie values displayed in this tabpanel.");
+      });
     }
 
     function testParamsTab() {
       EventUtils.sendMouseEvent({ type: "mousedown" },
         document.querySelectorAll("#details-pane tab")[2]);
 
       let tab = document.querySelectorAll("#details-pane tab")[2];
       let tabpanel = document.querySelectorAll("#details-pane tabpanel")[2];
--- a/browser/devtools/netmonitor/test/sjs_simple-test-server.sjs
+++ b/browser/devtools/netmonitor/test/sjs_simple-test-server.sjs
@@ -3,12 +3,15 @@
 
 function handleRequest(request, response) {
   response.setStatusLine(request.httpVersion, 200, "Och Aye");
 
   response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
   response.setHeader("Pragma", "no-cache");
   response.setHeader("Expires", "0");
 
+  response.setHeader("Set-Cookie", "bob=true; Max-Age=10; HttpOnly", true);
+  response.setHeader("Set-Cookie", "tom=cool; Max-Age=10; HttpOnly", true);
+
   response.setHeader("Content-Type", "text/plain; charset=utf-8", false);
   response.setHeader("Foo-Bar", "baz", false);
   response.write("Hello world!");
 }