Bug 1064458 - Remove 'Log request and response bodies' preference. r=bgrins

This commit is contained in:
Lin Clark 2016-01-11 19:08:00 +01:00
parent 4e5541bbcb
commit be61131443
15 changed files with 83 additions and 331 deletions

View File

@ -11,11 +11,6 @@
<!ENTITY window.title "Web Console">
<!ENTITY browserConsole.title "Browser Console">
<!-- LOCALIZATION NOTE (saveBodies.label): You can see this string in the Web
- Console context menu. -->
<!ENTITY saveBodies.label "Log Request and Response Bodies">
<!ENTITY saveBodies.accesskey "L">
<!-- LOCALIZATION NOTE (openURL.label): You can see this string in the Web
- Console context menu. -->
<!ENTITY openURL.label "Open URL in New Tab">

View File

@ -73,11 +73,8 @@ var HarAutomation = Class({
this.tabClient = this.toolbox.target.activeTab;
this.webConsoleClient = this.toolbox.target.activeConsole;
let netPrefs = { "NetworkMonitor.saveRequestAndResponseBodies": true };
this.webConsoleClient.setPreferences(netPrefs, () => {
this.tabWatcher = new TabWatcher(this.toolbox, this);
this.tabWatcher.connect();
});
this.tabWatcher = new TabWatcher(this.toolbox, this);
this.tabWatcher.connect();
},
pageLoadBegin: function(aResponse) {

View File

@ -10,7 +10,6 @@ var { classes: Cc, interfaces: Ci, utils: Cu } = Components;
const NET_STRINGS_URI = "chrome://devtools/locale/netmonitor.properties";
const PKI_STRINGS_URI = "chrome://pippki/locale/pippki.properties";
const LISTENERS = [ "NetworkActivity" ];
const NET_PREFS = { "NetworkMonitor.saveRequestAndResponseBodies": true };
// The panel's window global is an EventEmitter firing the following events:
const EVENTS = {
@ -223,13 +222,6 @@ var NetMonitorController = {
this.tabClient = this._target.activeTab;
}
let connectWebConsole = () => {
let deferred = promise.defer();
this.webConsoleClient = this._target.activeConsole;
this.webConsoleClient.setPreferences(NET_PREFS, deferred.resolve);
return deferred.promise;
};
let connectTimeline = () => {
// Don't start up waiting for timeline markers if the server isn't
// recent enough to emit the markers we're interested in.
@ -239,7 +231,7 @@ var NetMonitorController = {
}
};
yield connectWebConsole();
this.webConsoleClient = this._target.activeConsole;
yield connectTimeline();
this.TargetEventsHandler.connect();

View File

@ -171,6 +171,7 @@ skip-if = buildapp == 'mulet' || e10s # Bug 1042253 - webconsole e10s tests
[browser_console_log_inspectable_object.js]
[browser_console_native_getters.js]
[browser_console_navigation_marker.js]
[browser_console_netlogging.js]
[browser_console_nsiconsolemessage.js]
skip-if = buildapp == 'mulet'
[browser_console_optimized_out_vars.js]
@ -300,7 +301,6 @@ skip-if = os != "mac"
[browser_webconsole_bug_817834_add_edited_input_to_history.js]
[browser_webconsole_bug_837351_securityerrors.js]
skip-if = buildapp == 'mulet'
[browser_webconsole_bug_915141_toggle_response_logging_with_keyboard.js]
[browser_webconsole_filter_buttons_contextmenu.js]
[browser_webconsole_bug_1006027_message_timestamps_incorrect.js]
skip-if = e10s # Bug 1042253 - webconsole e10s tests (Linux debug intermittent)

View File

@ -0,0 +1,50 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Tests that network log messages bring up the network panel.
"use strict";
const TEST_URI = "data:text/html;charset=utf-8,Web Console network " +
"logging tests";
const TEST_NETWORK_REQUEST_URI =
"http://example.com/browser/devtools/client/webconsole/test/" +
"test-network-request.html";
var hud;
function test() {
loadTab(TEST_URI).then((tab) => {
HUDService.openBrowserConsoleOrFocus().then(aHud => {
hud = aHud;
HUDService.lastFinishedRequest.callback = testResponse;
BrowserTestUtils.loadURI(gBrowser.selectedBrowser,
TEST_NETWORK_REQUEST_URI);
});
});
}
function testResponse(request) {
hud.ui.webConsoleClient.getResponseContent(request.actor,
function(contentPacket) {
hud.ui.webConsoleClient.getRequestPostData(request.actor,
function(postDataPacket) {
// Check if page load was logged correctly.
ok(request, "Page load was logged");
is(request.request.url, TEST_NETWORK_REQUEST_URI,
"Logged network entry is page load");
is(request.request.method, "GET", "Method is correct");
ok(!postDataPacket.postData.text, "No request body was stored");
ok(postDataPacket.postDataDiscarded, "Request body was discarded");
ok(!contentPacket.content.text, "No response body was stored");
ok(contentPacket.contentDiscarded || request.fromCache,
"Response body was discarded or response came from the cache");
executeSoon(finishTest);
});
});
}

View File

@ -54,11 +54,6 @@ add_task(function* () {
let hud = yield openConsole();
yield hud.ui.setSaveRequestAndResponseBodies(true);
ok(hud.ui._saveRequestAndResponseBodies,
"The saveRequestAndResponseBodies property was successfully set.");
let gotLastRequest = waitForRequest();
let loaded = loadBrowser(browser);

View File

@ -33,20 +33,15 @@ function consoleOpened(hud) {
let deferred = promise.defer();
webConsoleClient = hud.ui.webConsoleClient;
hud.ui.setSaveRequestAndResponseBodies(true).then(() => {
ok(hud.ui._saveRequestAndResponseBodies,
"The saveRequestAndResponseBodies property was successfully set.");
HUDService.lastFinishedRequest.callback = (aHttpRequest) => {
let status = aHttpRequest.response.status;
lastFinishedRequests[status] = aHttpRequest;
if ("301" in lastFinishedRequests &&
"404" in lastFinishedRequests) {
deferred.resolve();
}
};
content.location = TEST_URI2;
});
HUDService.lastFinishedRequest.callback = (aHttpRequest) => {
let status = aHttpRequest.response.status;
lastFinishedRequests[status] = aHttpRequest;
if ("301" in lastFinishedRequests &&
"404" in lastFinishedRequests) {
deferred.resolve();
}
};
content.location = TEST_URI2;
return deferred.promise;
}

View File

@ -1,124 +0,0 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// Tests that the 'Log Request and Response Bodies' buttons can be toggled
// with keyboard.
"use strict";
const TEST_URI = "data:text/html;charset=utf-8,Web Console test for " +
"bug 915141: Toggle log response bodies with keyboard";
var hud;
function test() {
let saveBodiesMenuItem;
let saveBodiesContextMenuItem;
loadTab(TEST_URI).then(({tab: tab}) => {
return openConsole(tab);
})
.then((aHud) => {
hud = aHud;
saveBodiesMenuItem = hud.ui.rootElement.querySelector("#saveBodies");
saveBodiesContextMenuItem = hud.ui.rootElement.querySelector("#saveBodiesContextMenu");
// Test the context menu action.
info("Testing 'Log Request and Response Bodies' menuitem of right click " +
"context menu.");
return openPopup(saveBodiesContextMenuItem);
})
.then(() => {
is(saveBodiesContextMenuItem.getAttribute("checked"), "false",
"Context menu: 'log responses' is not checked before action.");
is(hud.ui._saveRequestAndResponseBodies, false,
"Context menu: Responses are not logged before action.");
EventUtils.synthesizeKey("VK_DOWN", {});
EventUtils.synthesizeKey("VK_RETURN", {});
return waitForUpdate(saveBodiesContextMenuItem);
})
.then(() => {
is(saveBodiesContextMenuItem.getAttribute("checked"), "true",
"Context menu: 'log responses' is checked after menuitem was selected " +
"with keyboard.");
is(hud.ui._saveRequestAndResponseBodies, true,
"Context menu: Responses are saved after menuitem was selected with " +
"keyboard.");
return openPopup(saveBodiesMenuItem);
})
.then(() => {
// Test the 'Net' menu item.
info("Testing 'Log Request and Response Bodies' menuitem of 'Net' menu " +
"in the console.");
// 'Log Request and Response Bodies' should be selected due to previous
// test.
is(saveBodiesMenuItem.getAttribute("checked"), "true",
"Console net menu: 'log responses' is checked before action.");
is(hud.ui._saveRequestAndResponseBodies, true,
"Console net menu: Responses are logged before action.");
// The correct item is the last one in the menu.
EventUtils.synthesizeKey("VK_UP", {});
EventUtils.synthesizeKey("VK_RETURN", {});
return waitForUpdate(saveBodiesMenuItem);
})
.then(() => {
is(saveBodiesMenuItem.getAttribute("checked"), "false",
"Console net menu: 'log responses' is NOT checked after menuitem was " +
"selected with keyboard.");
is(hud.ui._saveRequestAndResponseBodies, false,
"Responses are NOT saved after menuitem was selected with keyboard.");
hud = null;
})
.then(finishTest);
}
/**
* Opens and waits for the menu containing menuItem to open.
* @param menuItem MenuItem
* A MenuItem in a menu that should be opened.
* @return A promise that's resolved once menu is open.
*/
function openPopup(menuItem) {
let menu = menuItem.parentNode;
let menuOpened = promise.defer();
let uiUpdated = promise.defer();
// The checkbox menuitem is updated asynchronously on 'popupshowing' event so
// it's better to wait for both the update to happen and the menu to open
// before continuing or the test might fail due to a race between menu being
// shown and the item updated to have the correct state.
hud.ui.once("save-bodies-ui-toggled", uiUpdated.resolve);
menu.addEventListener("popupshown", function onPopup() {
menu.removeEventListener("popupshown", onPopup);
menuOpened.resolve();
});
menu.openPopup();
return Promise.all([menuOpened.promise, uiUpdated.promise]);
}
/**
* Waits for the settings and menu containing menuItem to update.
* @param menuItem MenuItem
* The menuitem that should be updated.
* @return A promise that's resolved once the settings and menus are updated.
*/
function waitForUpdate(menuItem) {
info("Waiting for settings update to complete.");
let deferred = promise.defer();
hud.ui.once("save-bodies-pref-reversed", function() {
hud.ui.once("save-bodies-ui-toggled", deferred.resolve);
// The checked state is only updated once the popup is shown.
menuItem.parentNode.openPopup();
});
return deferred.promise;
}

View File

@ -74,58 +74,16 @@ function testPageLoad() {
"Logged network entry is page load");
is(lastRequest.request.method, "GET", "Method is correct");
ok(!lastRequest.request.postData.text, "No request body was stored");
ok(lastRequest.discardRequestBody, "Request body was discarded");
ok(!lastRequest.response.content.text, "No response body was stored");
ok(lastRequest.discardResponseBody || lastRequest.fromCache,
"Response body was discarded or response came from the cache");
lastRequest = null;
requestCallback = null;
executeSoon(testPageLoadBody);
};
content.location = TEST_NETWORK_REQUEST_URI;
}
function testPageLoadBody() {
// Turn on logging of request bodies and check again.
hud.ui.setSaveRequestAndResponseBodies(true).then(() => {
ok(hud.ui._saveRequestAndResponseBodies,
"The saveRequestAndResponseBodies property was successfully set.");
testPageLoadBodyAfterSettingUpdate();
});
}
function testPageLoadBodyAfterSettingUpdate() {
let loaded = false;
let requestCallbackInvoked = false;
requestCallback = function() {
ok(lastRequest, "Page load was logged again");
ok(!lastRequest.discardResponseBody, "Response body was not discarded");
ok(!lastRequest.discardRequestBody, "Request body was not discarded");
is(lastRequest.response.content.text.indexOf("<!DOCTYPE HTML>"), 0,
"Response body's beginning is okay");
lastRequest = null;
requestCallback = null;
requestCallbackInvoked = true;
if (loaded) {
executeSoon(testXhrGet);
}
executeSoon(testXhrGet);
};
browser.addEventListener("load", function onLoad() {
browser.removeEventListener("load", onLoad, true);
loaded = true;
if (requestCallbackInvoked) {
executeSoon(testXhrGet);
}
}, true);
content.location.reload();
content.location = TEST_NETWORK_REQUEST_URI;
}
function testXhrGet() {

View File

@ -367,42 +367,13 @@ WebConsoleFrame.prototype = {
_destroyer: null,
// Used in tests.
_saveRequestAndResponseBodies: false,
_saveRequestAndResponseBodies: true,
// Chevron width at the starting of Web Console's input box.
_chevronWidth: 0,
// Width of the monospace characters in Web Console's input box.
_inputCharWidth: 0,
/**
* Tells whether to save the bodies of network requests and responses.
* Disabled by default to save memory.
*
* @return boolean
* The saveRequestAndResponseBodies pref value.
*/
getSaveRequestAndResponseBodies:
function WCF_getSaveRequestAndResponseBodies() {
let deferred = promise.defer();
let toGet = [
"NetworkMonitor.saveRequestAndResponseBodies"
];
// Make sure the web console client connection is established first.
this.webConsoleClient.getPreferences(toGet, response => {
if (!response.error) {
this._saveRequestAndResponseBodies = response.preferences[toGet[0]];
deferred.resolve(this._saveRequestAndResponseBodies);
}
else {
deferred.reject(response.error);
}
});
return deferred.promise;
},
/**
* Setter for saving of network request and response bodies.
*
@ -560,47 +531,6 @@ WebConsoleFrame.prototype = {
// calculations.
this._updateCharSize();
let updateSaveBodiesPrefUI = (element) => {
this.getSaveRequestAndResponseBodies().then(value => {
element.setAttribute("checked", value);
this.emit("save-bodies-ui-toggled");
});
}
let reverseSaveBodiesPref = ({ target: element }) => {
this.getSaveRequestAndResponseBodies().then(value => {
this.setSaveRequestAndResponseBodies(!value);
element.setAttribute("checked", value);
this.emit("save-bodies-pref-reversed");
});
}
let saveBodiesDisabled = !this.getFilterState("networkinfo") &&
!this.getFilterState("netxhr") &&
!this.getFilterState("network");
let saveBodies = doc.getElementById("saveBodies");
saveBodies.addEventListener("command", reverseSaveBodiesPref);
saveBodies.disabled = saveBodiesDisabled;
let saveBodiesContextMenu = doc.getElementById("saveBodiesContextMenu");
saveBodiesContextMenu.addEventListener("command", reverseSaveBodiesPref);
saveBodiesContextMenu.disabled = saveBodiesDisabled;
saveBodies.parentNode.addEventListener("popupshowing", () => {
updateSaveBodiesPrefUI(saveBodies);
saveBodies.disabled = !this.getFilterState("networkinfo") &&
!this.getFilterState("netxhr") &&
!this.getFilterState("network");
});
saveBodiesContextMenu.parentNode.addEventListener("popupshowing", () => {
updateSaveBodiesPrefUI(saveBodiesContextMenu);
saveBodiesContextMenu.disabled = !this.getFilterState("networkinfo") &&
!this.getFilterState("netxhr") &&
!this.getFilterState("network");
});
let clearButton = doc.getElementsByClassName("webconsole-clear-console-button")[0];
clearButton.addEventListener("command", () => {
this.owner._onClearButton();
@ -951,15 +881,6 @@ WebConsoleFrame.prototype = {
let prefKey = target.getAttribute("prefKey");
this.setFilterState(prefKey, state);
// Disable the log response and request body if network logging is off.
if (prefKey == "networkinfo" || prefKey == "netxhr" || prefKey == "network") {
let checkState = !this.getFilterState("networkinfo") &&
!this.getFilterState("netxhr") &&
!this.getFilterState("network");
this.document.getElementById("saveBodies").disabled = checkState;
this.document.getElementById("saveBodiesContextMenu").disabled = checkState;
}
// Adjust the state of the button appropriately.
let menuPopup = target.parentNode;
@ -5089,8 +5010,13 @@ WebConsoleConnectionProxy.prototype = {
}
this.webConsoleClient = webConsoleClient;
this._hasNativeConsoleAPI = response.nativeConsoleAPI;
// There is no way to view response bodies from the Browser Console, so do
// not waste the memory.
let saveBodies = !this.webConsoleFrame.owner._browserConsole;
this.webConsoleFrame.setSaveRequestAndResponseBodies(saveBodies);
this.webConsoleClient.on("networkEvent", this._onNetworkEvent);
this.webConsoleClient.on("networkEventUpdate", this._onNetworkEventUpdate);

View File

@ -72,8 +72,6 @@ function goUpdateConsoleCommands() {
<popupset id="mainPopupSet">
<menupopup id="output-contextmenu" onpopupshowing="goUpdateGlobalEditMenuItems()">
<menuitem id="saveBodiesContextMenu" type="checkbox" label="&saveBodies.label;"
accesskey="&saveBodies.accesskey;"/>
<menuitem id="menu_openURL" label="&openURL.label;"
accesskey="&openURL.accesskey;" command="consoleCmd_openURL"
selection="network" selectionType="single"/>
@ -110,9 +108,6 @@ function goUpdateConsoleCommands() {
prefKey="netxhr"/>
<menuitem label="&btnConsoleLog;" type="checkbox" autocheck="false"
prefKey="networkinfo"/>
<menuseparator id="saveBodiesSeparator" />
<menuitem id="saveBodies" type="checkbox" label="&saveBodies.label;"
accesskey="&saveBodies.accesskey;"/>
</menupopup>
</toolbarbutton>
<toolbarbutton label="&btnPageCSS.label;" type="menu-button"

View File

@ -524,11 +524,10 @@ NetworkMonitor.prototype = {
owner: null,
/**
* Whether to save the bodies of network requests and responses. Disabled by
* default to save memory.
* Whether to save the bodies of network requests and responses.
* @type boolean
*/
saveRequestAndResponseBodies: false,
saveRequestAndResponseBodies: true,
/**
* Object that holds the HTTP activity objects for ongoing requests.
@ -1243,7 +1242,7 @@ NetworkMonitorChild.prototype = {
appId: null,
owner: null,
_netEvents: null,
_saveRequestAndResponseBodies: false,
_saveRequestAndResponseBodies: true,
get saveRequestAndResponseBodies() {
return this._saveRequestAndResponseBodies;

View File

@ -87,7 +87,7 @@ function onNetworkEventUpdate(aState, aType, aPacket)
status: "200",
statusText: "OK",
headersSize: /^\d+$/,
discardResponseBody: true,
discardResponseBody: false,
},
};
break;
@ -104,8 +104,8 @@ function onNetworkEventUpdate(aState, aType, aPacket)
case "responseContent":
expectedPacket = {
mimeType: "application/json",
contentSize: 0,
discardResponseBody: true,
contentSize: 1070,
discardResponseBody: false,
};
break;
case "eventTimings":
@ -180,7 +180,7 @@ function onRequestPostData(aState, aResponse)
info("checking request POST data");
ok(!aResponse.postData.text, "no request POST data");
ok(aResponse.postDataDiscarded, "request POST data was discarded");
ok(!aResponse.postDataDiscarded, "request POST data was not discarded");
onResponseHeaders = onResponseHeaders.bind(null, aState);
aState.client.getResponseHeaders(aState.netActor,
@ -225,8 +225,8 @@ function onResponseContent(aState, aResponse)
{
info("checking response content");
ok(!aResponse.content.text, "no response content");
ok(aResponse.contentDiscarded, "response content was discarded");
ok(aResponse.content.text, "response content text");
ok(!aResponse.contentDiscarded, "response content was not discarded");
onEventTimings = onEventTimings.bind(null, aState);
aState.client.getEventTimings(aState.netActor,

View File

@ -25,7 +25,7 @@ function startTest()
function onAttach(aState, aResponse)
{
info("enable network request and response body logging");
info("set long string length");
window.ORIGINAL_LONG_STRING_LENGTH = DebuggerServer.LONG_STRING_LENGTH;
window.ORIGINAL_LONG_STRING_INITIAL_LENGTH =
@ -34,18 +34,6 @@ function onAttach(aState, aResponse)
DebuggerServer.LONG_STRING_LENGTH = 400;
DebuggerServer.LONG_STRING_INITIAL_LENGTH = 400;
onSetPreferences = onSetPreferences.bind(null, aState);
aState.client.setPreferences({
"NetworkMonitor.saveRequestAndResponseBodies": true,
}, onSetPreferences);
}
function onSetPreferences(aState, aResponse)
{
is(aResponse.updated.length, 1, "updated prefs length");
is(aResponse.updated[0], "NetworkMonitor.saveRequestAndResponseBodies",
"updated prefs length");
info("test network POST request");
onNetworkEvent = onNetworkEvent.bind(null, aState);

View File

@ -25,20 +25,6 @@ function startTest()
function onAttach(aState, aResponse)
{
info("enable network request and response body logging");
onSetPreferences = onSetPreferences.bind(null, aState);
aState.client.setPreferences({
"NetworkMonitor.saveRequestAndResponseBodies": true,
}, onSetPreferences);
}
function onSetPreferences(aState, aResponse)
{
is(aResponse.updated.length, 1, "updated prefs length");
is(aResponse.updated[0], "NetworkMonitor.saveRequestAndResponseBodies",
"updated prefs length");
info("test network POST request");
onNetworkEvent = onNetworkEvent.bind(null, aState);