mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 15:25:52 +00:00
Bug 1336198 - part10: fix race condition in boxmodel tests;r=gl
MozReview-Commit-ID: IDBgbnlMX2c --HG-- extra : rebase_source : 60363b4b4c4971212e333e50af01572d9c36e9d8 extra : histedit_source : 8169b297ed90c299b0330718c6eab831f7b2a927
This commit is contained in:
parent
6497838a23
commit
04420c38c3
@ -126,8 +126,16 @@ BoxModel.prototype = {
|
||||
|
||||
/**
|
||||
* Updates the box model panel by dispatching the new layout data.
|
||||
*
|
||||
* @param {String} reason
|
||||
* Optional string describing the reason why the boxmodel is updated.
|
||||
*/
|
||||
updateBoxModel() {
|
||||
updateBoxModel(reason) {
|
||||
this._updateReasons = this._updateReasons || [];
|
||||
if (reason) {
|
||||
this._updateReasons.push(reason);
|
||||
}
|
||||
|
||||
let lastRequest = Task.spawn((function* () {
|
||||
if (!(this.isPanelVisible() &&
|
||||
this.inspector.selection.isConnected() &&
|
||||
@ -151,9 +159,11 @@ BoxModel.prototype = {
|
||||
return this._lastRequest;
|
||||
}
|
||||
|
||||
this._lastRequest = null;
|
||||
this.inspector.emit("boxmodel-view-updated", this._updateReasons);
|
||||
|
||||
this._lastRequest = null;
|
||||
this._updateReasons = [];
|
||||
|
||||
this.inspector.emit("boxmodel-view-updated");
|
||||
return null;
|
||||
}).bind(this)).catch(console.error);
|
||||
|
||||
@ -173,7 +183,7 @@ BoxModel.prototype = {
|
||||
this.trackReflows();
|
||||
}
|
||||
|
||||
this.updateBoxModel();
|
||||
this.updateBoxModel("new-selection");
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -17,14 +17,16 @@ add_task(function* () {
|
||||
yield testFirstPage(inspector, view, testActor);
|
||||
|
||||
info("Navigate to the second page");
|
||||
let onMarkupLoaded = waitForMarkupLoaded(inspector);
|
||||
yield testActor.eval(`content.location.href="${IFRAME2}"`);
|
||||
yield inspector.once("markuploaded");
|
||||
yield onMarkupLoaded;
|
||||
|
||||
yield testSecondPage(inspector, view, testActor);
|
||||
|
||||
info("Go back to the first page");
|
||||
onMarkupLoaded = waitForMarkupLoaded(inspector);
|
||||
yield testActor.eval("content.history.back();");
|
||||
yield inspector.once("markuploaded");
|
||||
yield onMarkupLoaded;
|
||||
|
||||
yield testBackToFirstPage(inspector, view, testActor);
|
||||
});
|
||||
|
@ -14,8 +14,9 @@ add_task(function* () {
|
||||
yield assertBoxModelView(inspector, view, testActor);
|
||||
|
||||
info("Reload the page");
|
||||
let onMarkupLoaded = waitForMarkupLoaded(inspector);
|
||||
yield testActor.reload();
|
||||
yield inspector.once("markuploaded");
|
||||
yield onMarkupLoaded;
|
||||
|
||||
info("Test that the box model view works on the reloaded page");
|
||||
yield assertBoxModelView(inspector, view, testActor);
|
||||
|
@ -40,8 +40,9 @@ function* testReflowsAfterIframeDeletion(inspector, view, testActor) {
|
||||
"iframe");
|
||||
|
||||
info("Deleting the iframe2");
|
||||
let onInspectorUpdated = inspector.once("inspector-updated");
|
||||
yield removeIframe2(testActor);
|
||||
yield inspector.once("inspector-updated");
|
||||
yield onInspectorUpdated;
|
||||
|
||||
info("Selecting the test node in iframe1");
|
||||
yield selectNodeInIframe1("p", inspector);
|
||||
|
@ -66,10 +66,37 @@ function openBoxModelView() {
|
||||
|
||||
/**
|
||||
* Wait for the boxmodel-view-updated event.
|
||||
* @return a promise
|
||||
*
|
||||
* @param {InspectorPanel} inspector
|
||||
* The instance of InspectorPanel currently loaded in the toolbox.
|
||||
* @param {Boolean} waitForSelectionUpdate
|
||||
* Should the boxmodel-view-updated event come from a new selection.
|
||||
* @return {Promise} a promise
|
||||
*/
|
||||
function waitForUpdate(inspector) {
|
||||
return inspector.once("boxmodel-view-updated");
|
||||
function waitForUpdate(inspector, waitForSelectionUpdate) {
|
||||
return new Promise(resolve => {
|
||||
inspector.on("boxmodel-view-updated", function onUpdate(e, reasons) {
|
||||
// Wait for another update event if we are waiting for a selection related event.
|
||||
if (waitForSelectionUpdate && !reasons.includes("new-selection")) {
|
||||
return;
|
||||
}
|
||||
|
||||
inspector.off("boxmodel-view-updated", onUpdate);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for both boxmode-view-updated and markuploaded events.
|
||||
*
|
||||
* @return {Promise} a promise that resolves when both events have been received.
|
||||
*/
|
||||
function waitForMarkupLoaded(inspector) {
|
||||
return Promise.all([
|
||||
waitForUpdate(inspector),
|
||||
inspector.once("markuploaded"),
|
||||
]);
|
||||
}
|
||||
|
||||
function getStyle(testActor, selector, propertyName) {
|
||||
@ -93,6 +120,7 @@ function setStyle(testActor, selector, propertyName, value) {
|
||||
*/
|
||||
var _selectNode = selectNode;
|
||||
selectNode = function* (node, inspector, reason) {
|
||||
let onUpdate = waitForUpdate(inspector, true);
|
||||
yield _selectNode(node, inspector, reason);
|
||||
yield waitForUpdate(inspector);
|
||||
yield onUpdate;
|
||||
};
|
||||
|
@ -52,7 +52,15 @@ var openInspectorSidebarTab = Task.async(function* (id) {
|
||||
let {toolbox, inspector, testActor} = yield openInspector();
|
||||
|
||||
info("Selecting the " + id + " sidebar");
|
||||
inspector.sidebar.select(id);
|
||||
|
||||
if (id === "computedview" || id === "layoutview") {
|
||||
// The layout and computed views should wait until the box-model widget is ready.
|
||||
let onBoxModelViewReady = inspector.once("boxmodel-view-updated");
|
||||
inspector.sidebar.select(id);
|
||||
yield onBoxModelViewReady;
|
||||
} else {
|
||||
inspector.sidebar.select(id);
|
||||
}
|
||||
|
||||
return {
|
||||
toolbox,
|
||||
|
Loading…
Reference in New Issue
Block a user