Bug 1356957 - call updateRequest once when update request in netmonitor-controller;r=rickychien

MozReview-Commit-ID: J6lLXNlnJnM

--HG--
extra : rebase_source : b8e20d3f9c5b206ad90de7d078b04e1e211d670b
This commit is contained in:
Fred Lin 2017-04-17 14:21:59 +08:00
Родитель d838010e1d
Коммит d8e9a0a65d
6 изменённых файлов: 128 добавлений и 146 удалений

Просмотреть файл

@ -40,7 +40,6 @@ const RequestListColumnFile = createClass({
img({ img({
className: "requests-list-icon", className: "requests-list-icon",
src: responseContentDataUri, src: responseContentDataUri,
"data-type": responseContentDataUri ? "thumbnail" : undefined,
}), }),
urlDetails.baseNameWithQuery urlDetails.baseNameWithQuery
) )

Просмотреть файл

@ -93,18 +93,6 @@ const EVENTS = {
UPDATING_RESPONSE_CONTENT: "NetMonitor:NetworkEventUpdating:ResponseContent", UPDATING_RESPONSE_CONTENT: "NetMonitor:NetworkEventUpdating:ResponseContent",
RECEIVED_RESPONSE_CONTENT: "NetMonitor:NetworkEventUpdated:ResponseContent", RECEIVED_RESPONSE_CONTENT: "NetMonitor:NetworkEventUpdated:ResponseContent",
// When the request post params are displayed in the UI.
REQUEST_POST_PARAMS_DISPLAYED: "NetMonitor:RequestPostParamsAvailable",
// When the image response thumbnail is displayed in the UI.
RESPONSE_IMAGE_THUMBNAIL_DISPLAYED:
"NetMonitor:ResponseImageThumbnailAvailable",
// Fired when charts have been displayed in the PerformanceStatisticsView.
PLACEHOLDER_CHARTS_DISPLAYED: "NetMonitor:PlaceholderChartsDisplayed",
PRIMED_CACHE_CHART_DISPLAYED: "NetMonitor:PrimedChartsDisplayed",
EMPTY_CACHE_CHART_DISPLAYED: "NetMonitor:EmptyChartsDisplayed",
// Fired once the NetMonitorController establishes a connection to the debug // Fired once the NetMonitorController establishes a connection to the debug
// target. // target.
CONNECTED: "connected", CONNECTED: "connected",

Просмотреть файл

@ -7,10 +7,7 @@
const { TimelineFront } = require("devtools/shared/fronts/timeline"); const { TimelineFront } = require("devtools/shared/fronts/timeline");
const { CurlUtils } = require("devtools/client/shared/curl"); const { CurlUtils } = require("devtools/client/shared/curl");
const { ACTIVITY_TYPE, EVENTS } = require("./constants"); const { ACTIVITY_TYPE, EVENTS } = require("./constants");
const { const { getDisplayedRequestById } = require("./selectors/index");
getRequestById,
getDisplayedRequestById,
} = require("./selectors/index");
const { const {
fetchHeaders, fetchHeaders,
formDataURI, formDataURI,
@ -307,7 +304,6 @@ function NetworkEventsHandler() {
this._onRequestPostData = this._onRequestPostData.bind(this); this._onRequestPostData = this._onRequestPostData.bind(this);
this._onResponseHeaders = this._onResponseHeaders.bind(this); this._onResponseHeaders = this._onResponseHeaders.bind(this);
this._onResponseCookies = this._onResponseCookies.bind(this); this._onResponseCookies = this._onResponseCookies.bind(this);
this._onResponseContent = this._onResponseContent.bind(this);
this._onSecurityInfo = this._onSecurityInfo.bind(this); this._onSecurityInfo = this._onSecurityInfo.bind(this);
this._onEventTimings = this._onEventTimings.bind(this); this._onEventTimings = this._onEventTimings.bind(this);
} }
@ -428,45 +424,11 @@ NetworkEventsHandler.prototype = {
.then(() => window.emit(EVENTS.REQUEST_ADDED, id)); .then(() => window.emit(EVENTS.REQUEST_ADDED, id));
}, },
async updateRequest(id, data) { async fetchImage(mimeType, responseContent) {
await this.actions.updateRequest(id, data, true); let payload = {};
let { if (mimeType && responseContent && responseContent.content) {
responseContent, let { encoding, text } = responseContent.content;
responseCookies,
responseHeaders,
requestCookies,
requestHeaders,
requestPostData,
} = data;
let request = getRequestById(window.gStore.getState(), id);
if (requestHeaders && requestHeaders.headers && requestHeaders.headers.length) {
let headers = await fetchHeaders(requestHeaders, getLongString);
if (headers) {
await this.actions.updateRequest(
id,
{ requestHeaders: headers },
true,
);
}
}
if (responseHeaders && responseHeaders.headers && responseHeaders.headers.length) {
let headers = await fetchHeaders(responseHeaders, getLongString);
if (headers) {
await this.actions.updateRequest(
id,
{ responseHeaders: headers },
true,
);
}
}
if (request && responseContent && responseContent.content) {
let { mimeType } = request;
let { text, encoding } = responseContent.content;
let response = await getLongString(text); let response = await getLongString(text);
let payload = {};
if (mimeType.includes("image/")) { if (mimeType.includes("image/")) {
payload.responseContentDataUri = formDataURI(mimeType, encoding, response); payload.responseContentDataUri = formDataURI(mimeType, encoding, response);
@ -474,16 +436,36 @@ NetworkEventsHandler.prototype = {
responseContent.content.text = response; responseContent.content.text = response;
payload.responseContent = responseContent; payload.responseContent = responseContent;
}
return payload;
},
await this.actions.updateRequest(id, payload, true); async fetchRequestHeaders(requestHeaders) {
let payload = {};
if (mimeType.includes("image/")) { if (requestHeaders && requestHeaders.headers && requestHeaders.headers.length) {
window.emit(EVENTS.RESPONSE_IMAGE_THUMBNAIL_DISPLAYED); let headers = await fetchHeaders(requestHeaders, getLongString);
if (headers) {
payload.requestHeaders = headers;
} }
} }
return payload;
},
// Search the POST data upload stream for request headers and add async fetchResponseHeaders(responseHeaders) {
// them as a separate property, different from the classic headers. let payload = {};
if (responseHeaders && responseHeaders.headers && responseHeaders.headers.length) {
let headers = await fetchHeaders(responseHeaders, getLongString);
if (headers) {
payload.responseHeaders = headers;
}
}
return payload;
},
// Search the POST data upload stream for request headers and add
// them as a separate property, different from the classic headers.
async fetchPostData(requestPostData) {
let payload = {};
if (requestPostData && requestPostData.postData) { if (requestPostData && requestPostData.postData) {
let { text } = requestPostData.postData; let { text } = requestPostData.postData;
let postData = await getLongString(text); let postData = await getLongString(text);
@ -491,35 +473,15 @@ NetworkEventsHandler.prototype = {
const headersSize = headers.reduce((acc, { name, value }) => { const headersSize = headers.reduce((acc, { name, value }) => {
return acc + name.length + value.length + 2; return acc + name.length + value.length + 2;
}, 0); }, 0);
let payload = {};
requestPostData.postData.text = postData; requestPostData.postData.text = postData;
payload.requestPostData = Object.assign({}, requestPostData); payload.requestPostData = Object.assign({}, requestPostData);
payload.requestHeadersFromUploadStream = { headers, headersSize }; payload.requestHeadersFromUploadStream = { headers, headersSize };
await this.actions.updateRequest(id, payload, true);
}
// Fetch request and response cookies long value.
// Actor does not provide full sized cookie value when the value is too long
// To display values correctly, we need fetch them in each request.
if (requestCookies) {
let reqCookies = [];
// request store cookies in requestCookies or requestCookies.cookies
let cookies = requestCookies.cookies ?
requestCookies.cookies : requestCookies;
// make sure cookies is iterable
if (typeof cookies[Symbol.iterator] === "function") {
for (let cookie of cookies) {
reqCookies.push(Object.assign({}, cookie, {
value: await getLongString(cookie.value),
}));
}
if (reqCookies.length) {
await this.actions.updateRequest(id, { requestCookies: reqCookies }, true);
}
}
} }
return payload;
},
async fetchResponseCookies(responseCookies) {
let payload = {};
if (responseCookies) { if (responseCookies) {
let resCookies = []; let resCookies = [];
// response store cookies in responseCookies or responseCookies.cookies // response store cookies in responseCookies or responseCookies.cookies
@ -533,10 +495,70 @@ NetworkEventsHandler.prototype = {
})); }));
} }
if (resCookies.length) { if (resCookies.length) {
await this.actions.updateRequest(id, { responseCookies: resCookies }, true); payload.responseCookies = resCookies;
} }
} }
} }
return payload;
},
// Fetch request and response cookies long value.
// Actor does not provide full sized cookie value when the value is too long
// To display values correctly, we need fetch them in each request.
async fetchRequestCookies(requestCookies) {
let payload = {};
if (requestCookies) {
let reqCookies = [];
// request store cookies in requestCookies or requestCookies.cookies
let cookies = requestCookies.cookies ?
requestCookies.cookies : requestCookies;
// make sure cookies is iterable
if (typeof cookies[Symbol.iterator] === "function") {
for (let cookie of cookies) {
reqCookies.push(Object.assign({}, cookie, {
value: await getLongString(cookie.value),
}));
}
if (reqCookies.length) {
payload.requestCookies = reqCookies;
}
}
}
return payload;
},
async updateRequest(id, data) {
let {
mimeType,
responseContent,
responseCookies,
responseHeaders,
requestCookies,
requestHeaders,
requestPostData,
} = data;
// fetch request detail contents in parallel
let [
imageObj,
requestHeadersObj,
responseHeadersObj,
postDataObj,
requestCookiesObj,
responseCookiesObj,
] = await Promise.all([
this.fetchImage(mimeType, responseContent),
this.fetchRequestHeaders(requestHeaders),
this.fetchResponseHeaders(responseHeaders),
this.fetchPostData(requestPostData),
this.fetchRequestCookies(requestCookies),
this.fetchResponseCookies(responseCookies),
]);
let payload = Object.assign({}, data,
imageObj, requestHeadersObj, responseHeadersObj,
postDataObj, requestCookiesObj, responseCookiesObj);
await this.actions.updateRequest(id, payload, true);
}, },
/** /**
@ -568,9 +590,10 @@ NetworkEventsHandler.prototype = {
case "securityInfo": case "securityInfo":
this.updateRequest(actor, { this.updateRequest(actor, {
securityState: networkInfo.securityInfo, securityState: networkInfo.securityInfo,
}).then(() => {
this.webConsoleClient.getSecurityInfo(actor, this._onSecurityInfo);
window.emit(EVENTS.UPDATING_SECURITY_INFO, actor);
}); });
this.webConsoleClient.getSecurityInfo(actor, this._onSecurityInfo);
window.emit(EVENTS.UPDATING_SECURITY_INFO, actor);
break; break;
case "responseHeaders": case "responseHeaders":
this.webConsoleClient.getResponseHeaders(actor, this.webConsoleClient.getResponseHeaders(actor,
@ -590,25 +613,26 @@ NetworkEventsHandler.prototype = {
status: networkInfo.response.status, status: networkInfo.response.status,
statusText: networkInfo.response.statusText, statusText: networkInfo.response.statusText,
headersSize: networkInfo.response.headersSize headersSize: networkInfo.response.headersSize
}).then(() => {
window.emit(EVENTS.STARTED_RECEIVING_RESPONSE, actor);
}); });
window.emit(EVENTS.STARTED_RECEIVING_RESPONSE, actor);
break; break;
case "responseContent": case "responseContent":
this.updateRequest(actor, {
contentSize: networkInfo.response.bodySize,
transferredSize: networkInfo.response.transferredSize,
mimeType: networkInfo.response.content.mimeType
});
this.webConsoleClient.getResponseContent(actor, this.webConsoleClient.getResponseContent(actor,
this._onResponseContent); this._onResponseContent.bind(this, {
contentSize: networkInfo.response.bodySize,
transferredSize: networkInfo.response.transferredSize,
mimeType: networkInfo.response.content.mimeType
}));
window.emit(EVENTS.UPDATING_RESPONSE_CONTENT, actor); window.emit(EVENTS.UPDATING_RESPONSE_CONTENT, actor);
break; break;
case "eventTimings": case "eventTimings":
this.updateRequest(actor, { this.updateRequest(actor, {
totalTime: networkInfo.totalTime totalTime: networkInfo.totalTime
}).then(() => {
this.webConsoleClient.getEventTimings(actor, this._onEventTimings);
window.emit(EVENTS.UPDATING_EVENT_TIMINGS, actor);
}); });
this.webConsoleClient.getEventTimings(actor, this._onEventTimings);
window.emit(EVENTS.UPDATING_EVENT_TIMINGS, actor);
break; break;
} }
}, },
@ -700,13 +724,14 @@ NetworkEventsHandler.prototype = {
/** /**
* Handles additional information received for a "responseContent" packet. * Handles additional information received for a "responseContent" packet.
* *
* @param object data
* The message received from the server event.
* @param object response * @param object response
* The message received from the server. * The message received from the server.
*/ */
_onResponseContent: function (response) { _onResponseContent: function (data, response) {
this.updateRequest(response.from, { let payload = Object.assign({ responseContent: response }, data);
responseContent: response this.updateRequest(response.from, payload).then(() => {
}).then(() => {
window.emit(EVENTS.RECEIVED_RESPONSE_CONTENT, response.from); window.emit(EVENTS.RECEIVED_RESPONSE_CONTENT, response.from);
}); });
}, },

Просмотреть файл

@ -9,22 +9,21 @@
add_task(function* () { add_task(function* () {
let { tab, monitor } = yield initNetMonitor(CONTENT_TYPE_WITHOUT_CACHE_URL); let { tab, monitor } = yield initNetMonitor(CONTENT_TYPE_WITHOUT_CACHE_URL);
const SELECTOR = ".requests-list-icon[src]";
info("Starting test... "); info("Starting test... ");
let { document, gStore, windowRequire } = monitor.panelWin; let { document, gStore, windowRequire } = monitor.panelWin;
let Actions = windowRequire("devtools/client/netmonitor/src/actions/index"); let Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
let { NetMonitorController } = let { NetMonitorController } =
windowRequire("devtools/client/netmonitor/src/netmonitor-controller"); windowRequire("devtools/client/netmonitor/src/netmonitor-controller");
let { let { ACTIVITY_TYPE } = windowRequire("devtools/client/netmonitor/src/constants");
ACTIVITY_TYPE,
EVENTS,
} = windowRequire("devtools/client/netmonitor/src/constants");
gStore.dispatch(Actions.batchEnable(false)); gStore.dispatch(Actions.batchEnable(false));
let wait = waitForEvents(); let wait = waitForNetworkEvents(monitor, CONTENT_TYPE_WITHOUT_CACHE_REQUESTS);
yield performRequests(); yield performRequests();
yield wait; yield wait;
yield waitUntil(() => !!document.querySelector(SELECTOR));
info("Checking the image thumbnail when all items are shown."); info("Checking the image thumbnail when all items are shown.");
checkImageThumbnail(); checkImageThumbnail();
@ -38,22 +37,16 @@ add_task(function* () {
checkImageThumbnail(); checkImageThumbnail();
info("Reloading the debuggee and performing all requests again..."); info("Reloading the debuggee and performing all requests again...");
wait = waitForEvents(); wait = waitForNetworkEvents(monitor, CONTENT_TYPE_WITHOUT_CACHE_REQUESTS);
yield reloadAndPerformRequests(); yield reloadAndPerformRequests();
yield wait; yield wait;
yield waitUntil(() => !!document.querySelector(SELECTOR));
info("Checking the image thumbnail after a reload."); info("Checking the image thumbnail after a reload.");
checkImageThumbnail(); checkImageThumbnail();
yield teardown(monitor); yield teardown(monitor);
function waitForEvents() {
return promise.all([
waitForNetworkEvents(monitor, CONTENT_TYPE_WITHOUT_CACHE_REQUESTS),
monitor.panelWin.once(EVENTS.RESPONSE_IMAGE_THUMBNAIL_DISPLAYED)
]);
}
function performRequests() { function performRequests() {
return ContentTask.spawn(tab.linkedBrowser, {}, function* () { return ContentTask.spawn(tab.linkedBrowser, {}, function* () {
content.wrappedJSObject.performRequests(); content.wrappedJSObject.performRequests();
@ -66,12 +59,11 @@ add_task(function* () {
} }
function checkImageThumbnail() { function checkImageThumbnail() {
is(document.querySelectorAll(".requests-list-icon[data-type=thumbnail]").length, 1, is(document.querySelectorAll(SELECTOR).length, 1,
"There should be only one image request with a thumbnail displayed."); "There should be only one image request with a thumbnail displayed.");
is(document.querySelector(".requests-list-icon[data-type=thumbnail]").src, is(document.querySelector(SELECTOR).src, TEST_IMAGE_DATA_URI,
TEST_IMAGE_DATA_URI,
"The image requests-list-icon thumbnail is displayed correctly."); "The image requests-list-icon thumbnail is displayed correctly.");
is(document.querySelector(".requests-list-icon[data-type=thumbnail]").hidden, false, is(document.querySelector(SELECTOR).hidden, false,
"The image requests-list-icon thumbnail should not be hidden."); "The image requests-list-icon thumbnail should not be hidden.");
} }
}); });

Просмотреть файл

@ -11,25 +11,22 @@ const IMAGE_TOOLTIP_REQUESTS = 1;
*/ */
add_task(function* test() { add_task(function* test() {
let { tab, monitor } = yield initNetMonitor(IMAGE_TOOLTIP_URL); let { tab, monitor } = yield initNetMonitor(IMAGE_TOOLTIP_URL);
const SELECTOR = ".requests-list-icon[src]";
info("Starting test... "); info("Starting test... ");
let { document, gStore, windowRequire } = monitor.panelWin; let { document, gStore, windowRequire } = monitor.panelWin;
let Actions = windowRequire("devtools/client/netmonitor/src/actions/index"); let Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
let { NetMonitorController } = let { NetMonitorController } =
windowRequire("devtools/client/netmonitor/src/netmonitor-controller"); windowRequire("devtools/client/netmonitor/src/netmonitor-controller");
let { let { ACTIVITY_TYPE } = windowRequire("devtools/client/netmonitor/src/constants");
ACTIVITY_TYPE,
EVENTS,
} = windowRequire("devtools/client/netmonitor/src/constants");
let toolboxDoc = monitor.panelWin.parent.document; let toolboxDoc = monitor.panelWin.parent.document;
gStore.dispatch(Actions.batchEnable(false)); gStore.dispatch(Actions.batchEnable(false));
let onEvents = waitForNetworkEvents(monitor, IMAGE_TOOLTIP_REQUESTS); let onEvents = waitForNetworkEvents(monitor, IMAGE_TOOLTIP_REQUESTS);
let onThumbnail = monitor.panelWin.once(EVENTS.RESPONSE_IMAGE_THUMBNAIL_DISPLAYED);
yield performRequests(); yield performRequests();
yield onEvents; yield onEvents;
yield onThumbnail; yield waitUntil(() => !!document.querySelector(SELECTOR));
info("Checking the image thumbnail after a few requests were made..."); info("Checking the image thumbnail after a few requests were made...");
yield showTooltipAndVerify(document.querySelectorAll(".request-list-item")[0]); yield showTooltipAndVerify(document.querySelectorAll(".request-list-item")[0]);
@ -41,13 +38,12 @@ add_task(function* test() {
// +1 extra document reload // +1 extra document reload
onEvents = waitForNetworkEvents(monitor, IMAGE_TOOLTIP_REQUESTS + 1); onEvents = waitForNetworkEvents(monitor, IMAGE_TOOLTIP_REQUESTS + 1);
onThumbnail = monitor.panelWin.once(EVENTS.RESPONSE_IMAGE_THUMBNAIL_DISPLAYED);
info("Reloading the debuggee and performing all requests again..."); info("Reloading the debuggee and performing all requests again...");
yield NetMonitorController.triggerActivity(ACTIVITY_TYPE.RELOAD.WITH_CACHE_ENABLED); yield NetMonitorController.triggerActivity(ACTIVITY_TYPE.RELOAD.WITH_CACHE_ENABLED);
yield performRequests(); yield performRequests();
yield onEvents; yield onEvents;
yield onThumbnail; yield waitUntil(() => !!document.querySelector(SELECTOR));
info("Checking the image thumbnail after a reload."); info("Checking the image thumbnail after a reload.");
yield showTooltipAndVerify(document.querySelectorAll(".request-list-item")[1]); yield showTooltipAndVerify(document.querySelectorAll(".request-list-item")[1]);

Просмотреть файл

@ -193,7 +193,7 @@ function test() {
); );
}); });
monitor.panelWin.once(EVENTS.UPDATING_RESPONSE_CONTENT, () => { monitor.panelWin.once(EVENTS.RECEIVED_RESPONSE_CONTENT, () => {
let requestItem = getSortedRequests(gStore.getState()).get(0); let requestItem = getSortedRequests(gStore.getState()).get(0);
is(requestItem.transferredSize, "12", is(requestItem.transferredSize, "12",
@ -203,24 +203,6 @@ function test() {
is(requestItem.mimeType, "text/plain; charset=utf-8", is(requestItem.mimeType, "text/plain; charset=utf-8",
"The mimeType data has an incorrect value."); "The mimeType data has an incorrect value.");
verifyRequestItemTarget(
document,
getDisplayedRequests(gStore.getState()),
requestItem,
"GET",
SIMPLE_SJS,
{
type: "plain",
fullMimeType: "text/plain; charset=utf-8",
transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 12),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 12),
}
);
});
monitor.panelWin.once(EVENTS.RECEIVED_RESPONSE_CONTENT, () => {
let requestItem = getSortedRequests(gStore.getState()).get(0);
ok(requestItem.responseContent, ok(requestItem.responseContent,
"There should be a responseContent data available."); "There should be a responseContent data available.");
// eslint-disable-next-line mozilla/no-cpows-in-tests // eslint-disable-next-line mozilla/no-cpows-in-tests