Bug 1336198 - Part 10: Fix race condition in boxmodel tests. r=gl

MozReview-Commit-ID: IDBgbnlMX2c
This commit is contained in:
Julian Descottes 2017-02-22 20:48:23 +01:00
Родитель 0e26022e8e
Коммит e3b9ccf930
6 изменённых файлов: 73 добавлений и 21 удалений

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

@ -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);

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

@ -19,12 +19,13 @@ registerCleanupFunction(() => {
/**
* Highlight a node and set the inspector's current selection to the node or
* the first match of the given css selector.
* @param {String|NodeFront} selectorOrNodeFront
* The selector for the node to be set, or the nodeFront
* @param {InspectorPanel} inspector
* The instance of InspectorPanel currently loaded in the toolbox
* @return a promise that resolves when the inspector is updated with the new
* node
*
* @param {String|NodeFront} selectorOrNodeFront
* The selector for the node to be set, or the nodeFront.
* @param {InspectorPanel} inspector
* The instance of InspectorPanel currently loaded in the toolbox.
* @return {Promise} a promise that resolves when the inspector is updated with the new
* node.
*/
function* selectAndHighlightNode(selectorOrNodeFront, inspector) {
info("Highlighting and selecting the node " + selectorOrNodeFront);
@ -38,8 +39,9 @@ function* selectAndHighlightNode(selectorOrNodeFront, inspector) {
/**
* Open the toolbox, with the inspector tool visible, and the computed view
* sidebar tab selected to display the box model view.
* @return a promise that resolves when the inspector is ready and the box model
* view is visible and ready
*
* @return {Promise} a promise that resolves when the inspector is ready and the box model
* view is visible and ready.
*/
function openBoxModelView() {
return openInspectorSidebarTab("computedview").then(data => {
@ -66,10 +68,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 +122,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,