Bug 825427 - Intermittent browser_responsiveruleview.js; r=miker

This commit is contained in:
Patrick Brosset 2014-04-18 10:11:30 +02:00
parent 0d1b33eb26
commit d887fe0116
3 changed files with 111 additions and 32 deletions

View File

@ -15,7 +15,7 @@ function test() {
waitForFocus(startTest, content);
}, true);
content.location = "data:text/html,<html><style>" +
content.location = "data:text/html;charset=utf-8,<html><style>" +
"div {" +
" width: 500px;" +
" height: 10px;" +
@ -53,24 +53,21 @@ function test() {
instance.setSize(500, 500);
openView("computedview", onInspectorUIOpen);
openComputedView().then(onInspectorUIOpen);
}
function onInspectorUIOpen(aInspector, aComputedView) {
inspector = aInspector;
function onInspectorUIOpen(args) {
inspector = args.inspector;
computedView = args.view;
ok(inspector, "Got inspector instance");
let div = content.document.getElementsByTagName("div")[0];
inspector.selection.setNode(div);
inspector.once("inspector-updated", testShrink);
}
function testShrink() {
computedView = inspector.sidebar.getWindowForTab("computedview").computedview.view;
ok(computedView, "We have access to the Computed View object");
is(computedWidth(), "500px", "Should show 500px initially.");
inspector.once("computed-view-refreshed", function onShrink() {

View File

@ -16,7 +16,7 @@ function test() {
waitForFocus(startTest, content);
}, true);
content.location = "data:text/html,<html><style>" +
content.location = "data:text/html;charset=utf-8,<html><style>" +
"div {" +
" width: 500px;" +
" height: 10px;" +
@ -49,12 +49,12 @@ function test() {
instance.setSize(500, 500);
openView("ruleview", onInspectorUIOpen);
openRuleView().then(onInspectorUIOpen);
}
function onInspectorUIOpen(aInspector, aRuleView) {
inspector = aInspector;
ruleView = aRuleView;
function onInspectorUIOpen(args) {
inspector = args.inspector;
ruleView = args.view;
ok(inspector, "Got inspector instance");
let div = content.document.getElementsByTagName("div")[0];

View File

@ -15,27 +15,109 @@ SimpleTest.registerCleanupFunction(() => {
gDevTools.testing = false;
});
function openInspector(callback)
{
/**
* Open the toolbox, with the inspector tool visible.
* @return a promise that resolves when the inspector is ready
*/
let openInspector = Task.async(function*() {
info("Opening the inspector");
let target = TargetFactory.forTab(gBrowser.selectedTab);
gDevTools.showToolbox(target, "inspector").then(function(toolbox) {
callback(toolbox.getCurrentPanel());
});
let inspector, toolbox;
// Checking if the toolbox and the inspector are already loaded
// The inspector-updated event should only be waited for if the inspector
// isn't loaded yet
toolbox = gDevTools.getToolbox(target);
if (toolbox) {
inspector = toolbox.getPanel("inspector");
if (inspector) {
info("Toolbox and inspector already open");
return {
toolbox: toolbox,
inspector: inspector
};
}
}
info("Opening the toolbox");
toolbox = yield gDevTools.showToolbox(target, "inspector");
yield waitForToolboxFrameFocus(toolbox);
inspector = toolbox.getPanel("inspector");
info("Waiting for the inspector to update");
yield inspector.once("inspector-updated");
return {
toolbox: toolbox,
inspector: inspector
};
});
/**
* Wait for the toolbox frame to receive focus after it loads
* @param {Toolbox} toolbox
* @return a promise that resolves when focus has been received
*/
function waitForToolboxFrameFocus(toolbox) {
info("Making sure that the toolbox's frame is focused");
let def = promise.defer();
let win = toolbox.frame.contentWindow;
waitForFocus(def.resolve, win);
return def.promise;
}
function openView(name, callback)
{
openInspector(inspector => {
function onReady() {
inspector.sidebar.select(name);
let { view } = inspector.sidebar.getWindowForTab(name)[name];
callback(inspector, view);
}
/**
* Open the toolbox, with the inspector tool visible, and the sidebar that
* corresponds to the given id selected
* @return a promise that resolves when the inspector is ready and the sidebar
* view is visible and ready
*/
let openInspectorSideBar = Task.async(function*(id) {
let {toolbox, inspector} = yield openInspector();
if (inspector.sidebar.getTab(name)) {
onReady();
} else {
inspector.sidebar.once(name + "-ready", onReady);
}
});
if (!hasSideBarTab(inspector, id)) {
info("Waiting for the " + id + " sidebar to be ready");
yield inspector.sidebar.once(id + "-ready");
}
info("Selecting the " + id + " sidebar");
inspector.sidebar.select(id);
return {
toolbox: toolbox,
inspector: inspector,
view: inspector.sidebar.getWindowForTab(id)[id].view
};
});
/**
* Checks whether the inspector's sidebar corresponding to the given id already
* exists
* @param {InspectorPanel}
* @param {String}
* @return {Boolean}
*/
function hasSideBarTab(inspector, id) {
return !!inspector.sidebar.getWindowForTab(id);
}
/**
* Open the toolbox, with the inspector tool visible, and the computed-view
* sidebar tab selected.
* @return a promise that resolves when the inspector is ready and the computed
* view is visible and ready
*/
function openComputedView() {
return openInspectorSideBar("computedview");
}
/**
* Open the toolbox, with the inspector tool visible, and the rule-view
* sidebar tab selected.
* @return a promise that resolves when the inspector is ready and the rule
* view is visible and ready
*/
function openRuleView() {
return openInspectorSideBar("ruleview");
}