зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1436665 - Do not fire events on window, update tests; r=ochameau
MozReview-Commit-ID: BbZJQiipg3K --HG-- extra : rebase_source : d5ac5c6edd0aa8d247a0bc5b114a4e0466217114
This commit is contained in:
Родитель
d322d234a9
Коммит
d0bf801d95
|
@ -82,7 +82,7 @@ function devtools_page() {
|
|||
function waitForRequestAdded(toolbox) {
|
||||
return new Promise(resolve => {
|
||||
let netPanel = toolbox.getPanel("netmonitor");
|
||||
netPanel.panelWin.once("NetMonitor:RequestAdded", () => {
|
||||
netPanel.panelWin.api.once("NetMonitor:RequestAdded", () => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -34,6 +34,7 @@ function initialize(api) {
|
|||
|
||||
// Inject to global window for testing
|
||||
window.Netmonitor = app;
|
||||
window.api = api;
|
||||
window.store = app.api.store;
|
||||
window.connector = app.api.connector;
|
||||
window.actions = app.api.actions;
|
||||
|
|
|
@ -414,11 +414,6 @@ class FirefoxConnector {
|
|||
if (this.owner) {
|
||||
this.owner.emit(type, data);
|
||||
}
|
||||
|
||||
// Consumed mainly by tests.
|
||||
if (typeof window != "undefined") {
|
||||
window.emit(type, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -627,11 +627,6 @@ class FirefoxDataProvider {
|
|||
if (this.owner) {
|
||||
this.owner.emit(type, data);
|
||||
}
|
||||
|
||||
// Consumed mainly by tests.
|
||||
if (typeof window != "undefined") {
|
||||
window.emit(type, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ async function throttleUploadTest(actuallyThrottle) {
|
|||
});
|
||||
|
||||
// Execute one POST request on the page and wait till its done.
|
||||
let onEventTimings = monitor.panelWin.once(EVENTS.RECEIVED_EVENT_TIMINGS);
|
||||
let onEventTimings = monitor.panelWin.api.once(EVENTS.RECEIVED_EVENT_TIMINGS);
|
||||
let wait = waitForNetworkEvents(monitor, 1);
|
||||
await ContentTask.spawn(tab.linkedBrowser, { size }, async function(args) {
|
||||
content.wrappedJSObject.executeTest2(args.size);
|
||||
|
|
|
@ -48,7 +48,7 @@ add_task(async function() {
|
|||
});
|
||||
|
||||
wait = waitForDOM(document, ".CodeMirror-code");
|
||||
let onResponseContent = monitor.panelWin.once(EVENTS.RECEIVED_RESPONSE_CONTENT);
|
||||
let onResponseContent = monitor.panelWin.api.once(EVENTS.RECEIVED_RESPONSE_CONTENT);
|
||||
store.dispatch(Actions.toggleNetworkDetails());
|
||||
EventUtils.sendMouseEvent({ type: "click" },
|
||||
document.querySelector("#response-tab"));
|
||||
|
|
|
@ -32,7 +32,7 @@ add_task(async function() {
|
|||
});
|
||||
|
||||
let onNetworkEvents = waitForNetworkEvents(monitor, 1);
|
||||
let onEventTimings = waitFor(monitor.panelWin, EVENTS.RECEIVED_EVENT_TIMINGS);
|
||||
let onEventTimings = waitFor(monitor.panelWin.api, EVENTS.RECEIVED_EVENT_TIMINGS);
|
||||
tab.linkedBrowser.reload();
|
||||
await Promise.all([onNetworkEvents, onEventTimings]);
|
||||
|
||||
|
|
|
@ -268,7 +268,7 @@ add_task(async function() {
|
|||
}
|
||||
|
||||
async function selectIndexAndWaitForJSONView(index) {
|
||||
let onResponseContent = monitor.panelWin.once(EVENTS.RECEIVED_RESPONSE_CONTENT);
|
||||
let onResponseContent = monitor.panelWin.api.once(EVENTS.RECEIVED_RESPONSE_CONTENT);
|
||||
let tabpanel = document.querySelector("#response-panel");
|
||||
let waitDOM = waitForDOM(tabpanel, ".treeTable");
|
||||
store.dispatch(Actions.selectRequestByIndex(index));
|
||||
|
@ -281,7 +281,7 @@ add_task(async function() {
|
|||
}
|
||||
|
||||
async function selectIndexAndWaitForImageView(index) {
|
||||
let onResponseContent = monitor.panelWin.once(EVENTS.RECEIVED_RESPONSE_CONTENT);
|
||||
let onResponseContent = monitor.panelWin.api.once(EVENTS.RECEIVED_RESPONSE_CONTENT);
|
||||
let tabpanel = document.querySelector("#response-panel");
|
||||
let waitDOM = waitForDOM(tabpanel, ".response-image");
|
||||
store.dispatch(Actions.selectRequestByIndex(index));
|
||||
|
|
|
@ -28,7 +28,7 @@ add_task(async function() {
|
|||
is(getSelectedRequest(store.getState()), null,
|
||||
"There should be no selected item in the requests menu.");
|
||||
|
||||
let networkEvent = monitor.panelWin.once(EVENTS.NETWORK_EVENT);
|
||||
let networkEvent = monitor.panelWin.api.once(EVENTS.NETWORK_EVENT);
|
||||
tab.linkedBrowser.reload();
|
||||
await networkEvent;
|
||||
|
||||
|
|
|
@ -24,11 +24,11 @@ add_task(async function() {
|
|||
assertRequestCount(store, 1);
|
||||
|
||||
let noRequest = true;
|
||||
monitor.panelWin.once(EVENTS.NETWORK_EVENT, () => {
|
||||
monitor.panelWin.api.once(EVENTS.NETWORK_EVENT, () => {
|
||||
noRequest = false;
|
||||
});
|
||||
|
||||
monitor.panelWin.once(EVENTS.NETWORK_EVENT_UPDATED, () => {
|
||||
monitor.panelWin.api.once(EVENTS.NETWORK_EVENT_UPDATED, () => {
|
||||
noRequest = false;
|
||||
});
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ add_task(async function() {
|
|||
|
||||
for (let testcase of TEST_DATA) {
|
||||
info("Testing Security tab visibility for " + testcase.desc);
|
||||
let onNewItem = monitor.panelWin.once(EVENTS.NETWORK_EVENT);
|
||||
let onNewItem = monitor.panelWin.api.once(EVENTS.NETWORK_EVENT);
|
||||
let onComplete = testcase.isBroken ?
|
||||
waitForSecurityBrokenNetworkEvent() :
|
||||
waitForNetworkEvents(monitor, 1);
|
||||
|
@ -106,7 +106,7 @@ add_task(async function() {
|
|||
];
|
||||
|
||||
let promises = awaitedEvents.map((event) => {
|
||||
return monitor.panelWin.once(EVENTS[event]);
|
||||
return monitor.panelWin.api.once(EVENTS[event]);
|
||||
});
|
||||
|
||||
return Promise.all(promises);
|
||||
|
|
|
@ -34,7 +34,7 @@ function test() {
|
|||
|
||||
function expectEvent(evt, cb) {
|
||||
promiseList.push(new Promise((resolve, reject) => {
|
||||
monitor.panelWin.once(evt, _ => {
|
||||
monitor.panelWin.api.once(evt, _ => {
|
||||
cb().then(resolve, reject);
|
||||
});
|
||||
}));
|
||||
|
@ -151,7 +151,7 @@ function test() {
|
|||
);
|
||||
});
|
||||
|
||||
monitor.panelWin.once(EVENTS.RECEIVED_REQUEST_POST_DATA, () => {
|
||||
monitor.panelWin.api.once(EVENTS.RECEIVED_REQUEST_POST_DATA, () => {
|
||||
ok(false, "Trap listener: this request doesn't have any post data.");
|
||||
});
|
||||
|
||||
|
|
|
@ -161,7 +161,7 @@ add_task(async function() {
|
|||
}
|
||||
|
||||
async function testCookiesTab() {
|
||||
let onEvent = monitor.panelWin.once(EVENTS.TAB_UPDATED);
|
||||
let onEvent = monitor.panelWin.api.once(EVENTS.TAB_UPDATED);
|
||||
EventUtils.sendMouseEvent({ type: "mousedown" },
|
||||
document.querySelectorAll("#details-pane tab")[1]);
|
||||
await onEvent;
|
||||
|
@ -204,7 +204,7 @@ add_task(async function() {
|
|||
}
|
||||
|
||||
async function testResponseTab() {
|
||||
let onEvent = monitor.panelWin.once(EVENTS.TAB_UPDATED);
|
||||
let onEvent = monitor.panelWin.api.once(EVENTS.TAB_UPDATED);
|
||||
EventUtils.sendMouseEvent({ type: "mousedown" },
|
||||
document.querySelectorAll("#details-pane tab")[3]);
|
||||
await onEvent;
|
||||
|
|
|
@ -155,13 +155,13 @@ function waitForTimelineMarkers(monitor) {
|
|||
info(`Got marker: ${marker.name}`);
|
||||
markers.push(marker);
|
||||
if (markers.length == 2) {
|
||||
monitor.panelWin.off(EVENTS.TIMELINE_EVENT, handleTimelineEvent);
|
||||
monitor.panelWin.api.off(EVENTS.TIMELINE_EVENT, handleTimelineEvent);
|
||||
info("Got two timeline markers, done waiting");
|
||||
resolve(markers);
|
||||
}
|
||||
}
|
||||
|
||||
monitor.panelWin.on(EVENTS.TIMELINE_EVENT, handleTimelineEvent);
|
||||
monitor.panelWin.api.on(EVENTS.TIMELINE_EVENT, handleTimelineEvent);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -212,14 +212,14 @@ function waitForAllRequestsFinished(monitor) {
|
|||
}
|
||||
|
||||
// All requests are done - unsubscribe from events and resolve!
|
||||
window.off(EVENTS.NETWORK_EVENT, onRequest);
|
||||
window.off(EVENTS.PAYLOAD_READY, onTimings);
|
||||
window.api.off(EVENTS.NETWORK_EVENT, onRequest);
|
||||
window.api.off(EVENTS.PAYLOAD_READY, onTimings);
|
||||
info("All requests finished");
|
||||
resolve();
|
||||
}
|
||||
|
||||
window.on(EVENTS.NETWORK_EVENT, onRequest);
|
||||
window.on(EVENTS.PAYLOAD_READY, onTimings);
|
||||
window.api.on(EVENTS.NETWORK_EVENT, onRequest);
|
||||
window.api.on(EVENTS.PAYLOAD_READY, onTimings);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -248,12 +248,12 @@ let updatedTypes = [
|
|||
// Start collecting all networkEventUpdate event when panel is opened.
|
||||
// removeTab() should be called once all corresponded RECEIVED_* events finished.
|
||||
function startNetworkEventUpdateObserver(panelWin) {
|
||||
updatingTypes.forEach((type) => panelWin.on(type, actor => {
|
||||
updatingTypes.forEach((type) => panelWin.api.on(type, actor => {
|
||||
let key = actor + "-" + updatedTypes[updatingTypes.indexOf(type)];
|
||||
finishedQueue[key] = finishedQueue[key] ? finishedQueue[key] + 1 : 1;
|
||||
}));
|
||||
|
||||
updatedTypes.forEach((type) => panelWin.on(type, actor => {
|
||||
updatedTypes.forEach((type) => panelWin.api.on(type, actor => {
|
||||
let key = actor + "-" + type;
|
||||
finishedQueue[key] = finishedQueue[key] ? finishedQueue[key] - 1 : -1;
|
||||
}));
|
||||
|
@ -389,14 +389,14 @@ function waitForNetworkEvents(monitor, getRequests) {
|
|||
|
||||
// Wait until networkEvent & payloadReady finish for each request.
|
||||
if (networkEvent >= getRequests && payloadReady >= getRequests) {
|
||||
panel.off(EVENTS.NETWORK_EVENT, onNetworkEvent);
|
||||
panel.off(EVENTS.PAYLOAD_READY, onPayloadReady);
|
||||
panel.api.off(EVENTS.NETWORK_EVENT, onNetworkEvent);
|
||||
panel.api.off(EVENTS.PAYLOAD_READY, onPayloadReady);
|
||||
executeSoon(resolve);
|
||||
}
|
||||
}
|
||||
|
||||
panel.on(EVENTS.NETWORK_EVENT, onNetworkEvent);
|
||||
panel.on(EVENTS.PAYLOAD_READY, onPayloadReady);
|
||||
panel.api.on(EVENTS.NETWORK_EVENT, onNetworkEvent);
|
||||
panel.api.on(EVENTS.PAYLOAD_READY, onPayloadReady);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -563,7 +563,7 @@ function verifyRequestItemTarget(document, requestList, requestItem, method,
|
|||
|
||||
/**
|
||||
* Helper function for waiting for an event to fire before resolving a promise.
|
||||
* Example: waitFor(aMonitor.panelWin, EVENT_NAME);
|
||||
* Example: waitFor(aMonitor.panelWin.api, EVENT_NAME);
|
||||
*
|
||||
* @param object subject
|
||||
* The event emitter object that is being listened to.
|
||||
|
@ -737,7 +737,7 @@ async function showColumn(monitor, column) {
|
|||
*/
|
||||
async function selectIndexAndWaitForSourceEditor(monitor, index) {
|
||||
let document = monitor.panelWin.document;
|
||||
let onResponseContent = monitor.panelWin.once(EVENTS.RECEIVED_RESPONSE_CONTENT);
|
||||
let onResponseContent = monitor.panelWin.api.once(EVENTS.RECEIVED_RESPONSE_CONTENT);
|
||||
// Select the request first, as it may try to fetch whatever is the current request's
|
||||
// responseContent if we select the ResponseTab first.
|
||||
EventUtils.sendMouseEvent({ type: "mousedown" },
|
||||
|
|
|
@ -18,7 +18,7 @@ add_task(async function task() {
|
|||
let toolbox = gDevTools.getToolbox(target);
|
||||
|
||||
let monitor = toolbox.getCurrentPanel();
|
||||
let netReady = monitor.panelWin.once("NetMonitor:PayloadReady");
|
||||
let netReady = monitor.panelWin.api.once("NetMonitor:PayloadReady");
|
||||
|
||||
// Fire an XHR POST request.
|
||||
await ContentTask.spawn(gBrowser.selectedBrowser, null, function() {
|
||||
|
@ -69,7 +69,7 @@ async function testNetworkMessage(messageNode) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Wait until all lazily fetch requests in netmonitor get finsished.
|
||||
* Wait until all lazily fetch requests in netmonitor get finished.
|
||||
* Otherwise test will be shutdown too early and cause failure.
|
||||
*/
|
||||
async function waitForLazyRequests(toolbox) {
|
||||
|
|
|
@ -46,14 +46,14 @@ function waitForAllRequestsFinished(expectedRequests) {
|
|||
// Have all the requests finished yet?
|
||||
if (payloadReady >= expectedRequests && timingsUpdated >= expectedRequests) {
|
||||
// All requests are done - unsubscribe from events and resolve!
|
||||
window.off(EVENTS.PAYLOAD_READY, onPayloadReady);
|
||||
window.off(EVENTS.RECEIVED_EVENT_TIMINGS, onTimingsUpdated);
|
||||
window.api.off(EVENTS.PAYLOAD_READY, onPayloadReady);
|
||||
window.api.off(EVENTS.RECEIVED_EVENT_TIMINGS, onTimingsUpdated);
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
|
||||
window.on(EVENTS.PAYLOAD_READY, onPayloadReady);
|
||||
window.on(EVENTS.RECEIVED_EVENT_TIMINGS, onTimingsUpdated);
|
||||
window.api.on(EVENTS.PAYLOAD_READY, onPayloadReady);
|
||||
window.api.on(EVENTS.RECEIVED_EVENT_TIMINGS, onTimingsUpdated);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -41,11 +41,11 @@ function waitForPayload(count, panelWin) {
|
|||
|
||||
function maybeResolve() {
|
||||
if (payloadReady >= count) {
|
||||
panelWin.off(EVENTS.PAYLOAD_READY, onPayloadReady);
|
||||
panelWin.api.off(EVENTS.PAYLOAD_READY, onPayloadReady);
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
|
||||
panelWin.on(EVENTS.PAYLOAD_READY, onPayloadReady);
|
||||
panelWin.api.on(EVENTS.PAYLOAD_READY, onPayloadReady);
|
||||
});
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче