зеркало из https://github.com/mozilla/gecko-dev.git
Bug 997198 - Quick layout-view tests cleanup; r=bgrins
This commit is contained in:
Родитель
5c4e3ffb08
Коммит
4b3c00e761
|
@ -5,7 +5,7 @@ support-files =
|
|||
head.js
|
||||
|
||||
[browser_layoutview.js]
|
||||
skip-if = true
|
||||
[browser_layoutview_rotate-labels-on-sides.js]
|
||||
[browser_editablemodel.js]
|
||||
[browser_editablemodel_allproperties.js]
|
||||
[browser_editablemodel_border.js]
|
||||
|
|
|
@ -1,142 +1,147 @@
|
|||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
// Test that editing the box-model values works as expected and test various
|
||||
// key bindings
|
||||
|
||||
const TEST_URI = "<style>" +
|
||||
"div { margin: 10px; padding: 3px }" +
|
||||
"#div1 { margin-top: 5px }" +
|
||||
"#div2 { border-bottom: 1em solid black; }" +
|
||||
"#div3 { padding: 2em; }" +
|
||||
"</style>" +
|
||||
"<div id='div1'></div><div id='div2'></div><div id='div3'></div>";
|
||||
|
||||
function getStyle(node, property) {
|
||||
return node.style.getPropertyValue(property);
|
||||
}
|
||||
|
||||
let doc;
|
||||
let inspector;
|
||||
|
||||
let test = asyncTest(function*() {
|
||||
let style = "div { margin: 10px; padding: 3px } #div1 { margin-top: 5px } #div2 { border-bottom: 1em solid black; } #div3 { padding: 2em; }";
|
||||
let html = "<style>" + style + "</style><div id='div1'></div><div id='div2'></div><div id='div3'></div>"
|
||||
yield addTab("data:text/html," + encodeURIComponent(TEST_URI));
|
||||
let {toolbox, inspector, view} = yield openLayoutView();
|
||||
|
||||
let content = yield loadTab("data:text/html," + encodeURIComponent(html));
|
||||
doc = content.document;
|
||||
|
||||
let target = TargetFactory.forTab(gBrowser.selectedTab);
|
||||
let toolbox = yield gDevTools.showToolbox(target, "inspector");
|
||||
inspector = toolbox.getCurrentPanel();
|
||||
|
||||
inspector.sidebar.select("layoutview");
|
||||
yield inspector.sidebar.once("layoutview-ready");
|
||||
yield runTests();
|
||||
yield runTests(inspector, view);
|
||||
// TODO: Closing the toolbox in this test leaks - bug 994314
|
||||
// yield gDevTools.closeToolbox(target);
|
||||
// yield destroyToolbox(inspector);
|
||||
});
|
||||
|
||||
addTest("Test that editing margin dynamically updates the document, pressing escape cancels the changes",
|
||||
function*() {
|
||||
let node = doc.getElementById("div1");
|
||||
function*(inspector, view) {
|
||||
let node = content.document.getElementById("div1");
|
||||
is(getStyle(node, "margin-top"), "", "Should be no margin-top on the element.")
|
||||
let view = yield selectNode(node);
|
||||
yield selectNode(node, inspector);
|
||||
|
||||
let span = view.document.querySelector(".margin.top > span");
|
||||
let span = view.doc.querySelector(".margin.top > span");
|
||||
is(span.textContent, 5, "Should have the right value in the box model.");
|
||||
|
||||
EventUtils.synthesizeMouseAtCenter(span, {}, view);
|
||||
let editor = view.document.querySelector(".styleinspector-propertyeditor");
|
||||
EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView);
|
||||
let editor = view.doc.querySelector(".styleinspector-propertyeditor");
|
||||
ok(editor, "Should have opened the editor.");
|
||||
is(editor.value, "5px", "Should have the right value in the editor.");
|
||||
|
||||
EventUtils.synthesizeKey("3", {}, view);
|
||||
yield waitForUpdate();
|
||||
EventUtils.synthesizeKey("3", {}, view.doc.defaultView);
|
||||
yield waitForUpdate(inspector);
|
||||
|
||||
is(getStyle(node, "margin-top"), "3px", "Should have updated the margin.");
|
||||
|
||||
EventUtils.synthesizeKey("VK_ESCAPE", {}, view);
|
||||
yield waitForUpdate();
|
||||
EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView);
|
||||
yield waitForUpdate(inspector);
|
||||
|
||||
is(getStyle(node, "margin-top"), "", "Should be no margin-top on the element.")
|
||||
is(span.textContent, 5, "Should have the right value in the box model.");
|
||||
});
|
||||
|
||||
addTest("Test that arrow keys work correctly and pressing enter commits the changes",
|
||||
function*() {
|
||||
let node = doc.getElementById("div1");
|
||||
function*(inspector, view) {
|
||||
let node = content.document.getElementById("div1");
|
||||
is(getStyle(node, "margin-left"), "", "Should be no margin-top on the element.")
|
||||
let view = yield selectNode(node);
|
||||
yield selectNode(node, inspector);
|
||||
|
||||
let span = view.document.querySelector(".margin.left > span");
|
||||
let span = view.doc.querySelector(".margin.left > span");
|
||||
is(span.textContent, 10, "Should have the right value in the box model.");
|
||||
|
||||
EventUtils.synthesizeMouseAtCenter(span, {}, view);
|
||||
let editor = view.document.querySelector(".styleinspector-propertyeditor");
|
||||
EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView);
|
||||
let editor = view.doc.querySelector(".styleinspector-propertyeditor");
|
||||
ok(editor, "Should have opened the editor.");
|
||||
is(editor.value, "10px", "Should have the right value in the editor.");
|
||||
|
||||
EventUtils.synthesizeKey("VK_UP", {}, view);
|
||||
yield waitForUpdate();
|
||||
EventUtils.synthesizeKey("VK_UP", {}, view.doc.defaultView);
|
||||
yield waitForUpdate(inspector);
|
||||
|
||||
is(editor.value, "11px", "Should have the right value in the editor.");
|
||||
is(getStyle(node, "margin-left"), "11px", "Should have updated the margin.");
|
||||
|
||||
EventUtils.synthesizeKey("VK_DOWN", {}, view);
|
||||
yield waitForUpdate();
|
||||
EventUtils.synthesizeKey("VK_DOWN", {}, view.doc.defaultView);
|
||||
yield waitForUpdate(inspector);
|
||||
|
||||
is(editor.value, "10px", "Should have the right value in the editor.");
|
||||
is(getStyle(node, "margin-left"), "10px", "Should have updated the margin.");
|
||||
|
||||
EventUtils.synthesizeKey("VK_UP", { shiftKey: true }, view);
|
||||
yield waitForUpdate();
|
||||
EventUtils.synthesizeKey("VK_UP", { shiftKey: true }, view.doc.defaultView);
|
||||
yield waitForUpdate(inspector);
|
||||
|
||||
is(editor.value, "20px", "Should have the right value in the editor.");
|
||||
is(getStyle(node, "margin-left"), "20px", "Should have updated the margin.");
|
||||
EventUtils.synthesizeKey("VK_RETURN", {}, view);
|
||||
EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView);
|
||||
|
||||
is(getStyle(node, "margin-left"), "20px", "Should be the right margin-top on the element.")
|
||||
is(span.textContent, 20, "Should have the right value in the box model.");
|
||||
});
|
||||
|
||||
addTest("Test that deleting the value removes the property but escape undoes that",
|
||||
function*() {
|
||||
let node = doc.getElementById("div1");
|
||||
function*(inspector, view) {
|
||||
let node = content.document.getElementById("div1");
|
||||
is(getStyle(node, "margin-left"), "20px", "Should be the right margin-top on the element.")
|
||||
let view = yield selectNode(node);
|
||||
yield selectNode(node, inspector);
|
||||
|
||||
let span = view.document.querySelector(".margin.left > span");
|
||||
let span = view.doc.querySelector(".margin.left > span");
|
||||
is(span.textContent, 20, "Should have the right value in the box model.");
|
||||
|
||||
EventUtils.synthesizeMouseAtCenter(span, {}, view);
|
||||
let editor = view.document.querySelector(".styleinspector-propertyeditor");
|
||||
EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView);
|
||||
let editor = view.doc.querySelector(".styleinspector-propertyeditor");
|
||||
ok(editor, "Should have opened the editor.");
|
||||
is(editor.value, "20px", "Should have the right value in the editor.");
|
||||
|
||||
EventUtils.synthesizeKey("VK_DELETE", {}, view);
|
||||
yield waitForUpdate();
|
||||
EventUtils.synthesizeKey("VK_DELETE", {}, view.doc.defaultView);
|
||||
yield waitForUpdate(inspector);
|
||||
|
||||
is(editor.value, "", "Should have the right value in the editor.");
|
||||
is(getStyle(node, "margin-left"), "", "Should have updated the margin.");
|
||||
|
||||
EventUtils.synthesizeKey("VK_ESCAPE", {}, view);
|
||||
yield waitForUpdate();
|
||||
EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView);
|
||||
yield waitForUpdate(inspector);
|
||||
|
||||
is(getStyle(node, "margin-left"), "20px", "Should be the right margin-top on the element.")
|
||||
is(span.textContent, 20, "Should have the right value in the box model.");
|
||||
});
|
||||
|
||||
addTest("Test that deleting the value removes the property",
|
||||
function*() {
|
||||
let node = doc.getElementById("div1");
|
||||
node.style.marginRight = "15px";
|
||||
let view = yield selectNode(node);
|
||||
function*(inspector, view) {
|
||||
let node = content.document.getElementById("div1");
|
||||
|
||||
let span = view.document.querySelector(".margin.right > span");
|
||||
node.style.marginRight = "15px";
|
||||
yield waitForUpdate(inspector);
|
||||
|
||||
yield selectNode(node, inspector);
|
||||
|
||||
let span = view.doc.querySelector(".margin.right > span");
|
||||
is(span.textContent, 15, "Should have the right value in the box model.");
|
||||
|
||||
EventUtils.synthesizeMouseAtCenter(span, {}, view);
|
||||
let editor = view.document.querySelector(".styleinspector-propertyeditor");
|
||||
EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView);
|
||||
let editor = view.doc.querySelector(".styleinspector-propertyeditor");
|
||||
ok(editor, "Should have opened the editor.");
|
||||
is(editor.value, "15px", "Should have the right value in the editor.");
|
||||
|
||||
EventUtils.synthesizeKey("VK_DELETE", {}, view);
|
||||
yield waitForUpdate();
|
||||
EventUtils.synthesizeKey("VK_DELETE", {}, view.doc.defaultView);
|
||||
yield waitForUpdate(inspector);
|
||||
|
||||
is(editor.value, "", "Should have the right value in the editor.");
|
||||
is(getStyle(node, "margin-right"), "", "Should have updated the margin.");
|
||||
|
||||
EventUtils.synthesizeKey("VK_RETURN", {}, view);
|
||||
EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView);
|
||||
|
||||
is(getStyle(node, "margin-right"), "", "Should be the right margin-top on the element.")
|
||||
is(span.textContent, 10, "Should have the right value in the box model.");
|
||||
|
|
|
@ -1,133 +1,144 @@
|
|||
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
// Test editing box model values when all values are set
|
||||
|
||||
const TEST_URI = "<style>" +
|
||||
"div { margin: 10px; padding: 3px }" +
|
||||
"#div1 { margin-top: 5px }" +
|
||||
"#div2 { border-bottom: 1em solid black; }" +
|
||||
"#div3 { padding: 2em; }" +
|
||||
"</style>" +
|
||||
"<div id='div1'></div><div id='div2'></div><div id='div3'></div>";
|
||||
|
||||
function getStyle(node, property) {
|
||||
return node.style.getPropertyValue(property);
|
||||
}
|
||||
|
||||
let doc;
|
||||
let inspector;
|
||||
|
||||
let test = asyncTest(function*() {
|
||||
let style = "div { margin: 10px; padding: 3px } #div1 { margin-top: 5px } #div2 { border-bottom: 1em solid black; } #div3 { padding: 2em; }";
|
||||
let html = "<style>" + style + "</style><div id='div1'></div><div id='div2'></div><div id='div3'></div>"
|
||||
yield addTab("data:text/html," + encodeURIComponent(TEST_URI));
|
||||
let {toolbox, inspector, view} = yield openLayoutView();
|
||||
|
||||
let content = yield loadTab("data:text/html," + encodeURIComponent(html));
|
||||
doc = content.document;
|
||||
|
||||
let target = TargetFactory.forTab(gBrowser.selectedTab);
|
||||
let toolbox = yield gDevTools.showToolbox(target, "inspector");
|
||||
inspector = toolbox.getCurrentPanel();
|
||||
|
||||
inspector.sidebar.select("layoutview");
|
||||
yield inspector.sidebar.once("layoutview-ready");
|
||||
yield runTests();
|
||||
yield runTests(inspector, view);
|
||||
// TODO: Closing the toolbox in this test leaks - bug 994314
|
||||
// yield gDevTools.closeToolbox(target);
|
||||
// yield destroyToolbox(inspector);
|
||||
});
|
||||
|
||||
addTest("When all properties are set on the node editing one should work",
|
||||
function*() {
|
||||
let node = doc.getElementById("div1");
|
||||
node.style.padding = "5px";
|
||||
let view = yield selectNode(node);
|
||||
function*(inspector, view) {
|
||||
let node = content.document.getElementById("div1");
|
||||
|
||||
let span = view.document.querySelector(".padding.bottom > span");
|
||||
node.style.padding = "5px";
|
||||
yield waitForUpdate(inspector);
|
||||
|
||||
yield selectNode(node, inspector);
|
||||
|
||||
let span = view.doc.querySelector(".padding.bottom > span");
|
||||
is(span.textContent, 5, "Should have the right value in the box model.");
|
||||
|
||||
EventUtils.synthesizeMouseAtCenter(span, {}, view);
|
||||
let editor = view.document.querySelector(".styleinspector-propertyeditor");
|
||||
EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView);
|
||||
let editor = view.doc.querySelector(".styleinspector-propertyeditor");
|
||||
ok(editor, "Should have opened the editor.");
|
||||
is(editor.value, "5px", "Should have the right value in the editor.");
|
||||
|
||||
EventUtils.synthesizeKey("7", {}, view);
|
||||
yield waitForUpdate();
|
||||
EventUtils.synthesizeKey("7", {}, view.doc.defaultView);
|
||||
yield waitForUpdate(inspector);
|
||||
|
||||
is(editor.value, "7", "Should have the right value in the editor.");
|
||||
is(getStyle(node, "padding-bottom"), "7px", "Should have updated the padding");
|
||||
|
||||
EventUtils.synthesizeKey("VK_RETURN", {}, view);
|
||||
EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView);
|
||||
|
||||
is(getStyle(node, "padding-bottom"), "7px", "Should be the right padding.")
|
||||
is(span.textContent, 7, "Should have the right value in the box model.");
|
||||
});
|
||||
|
||||
addTest("When all properties are set on the node editing one should work",
|
||||
function*() {
|
||||
let node = doc.getElementById("div1");
|
||||
node.style.padding = "5px";
|
||||
let view = yield selectNode(node);
|
||||
function*(inspector, view) {
|
||||
let node = content.document.getElementById("div1");
|
||||
|
||||
let span = view.document.querySelector(".padding.left > span");
|
||||
node.style.padding = "5px";
|
||||
yield waitForUpdate(inspector);
|
||||
|
||||
yield selectNode(node, inspector);
|
||||
|
||||
let span = view.doc.querySelector(".padding.left > span");
|
||||
is(span.textContent, 5, "Should have the right value in the box model.");
|
||||
|
||||
EventUtils.synthesizeMouseAtCenter(span, {}, view);
|
||||
let editor = view.document.querySelector(".styleinspector-propertyeditor");
|
||||
EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView);
|
||||
let editor = view.doc.querySelector(".styleinspector-propertyeditor");
|
||||
ok(editor, "Should have opened the editor.");
|
||||
is(editor.value, "5px", "Should have the right value in the editor.");
|
||||
|
||||
EventUtils.synthesizeKey("8", {}, view);
|
||||
yield waitForUpdate();
|
||||
EventUtils.synthesizeKey("8", {}, view.doc.defaultView);
|
||||
yield waitForUpdate(inspector);
|
||||
|
||||
is(editor.value, "8", "Should have the right value in the editor.");
|
||||
is(getStyle(node, "padding-left"), "8px", "Should have updated the padding");
|
||||
|
||||
EventUtils.synthesizeKey("VK_ESCAPE", {}, view);
|
||||
yield waitForUpdate();
|
||||
EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView);
|
||||
yield waitForUpdate(inspector);
|
||||
|
||||
is(getStyle(node, "padding-left"), "5px", "Should be the right padding.")
|
||||
is(span.textContent, 5, "Should have the right value in the box model.");
|
||||
});
|
||||
|
||||
addTest("When all properties are set on the node deleting one should work",
|
||||
function*() {
|
||||
let node = doc.getElementById("div1");
|
||||
node.style.padding = "5px";
|
||||
let view = yield selectNode(node);
|
||||
function*(inspector, view) {
|
||||
let node = content.document.getElementById("div1");
|
||||
|
||||
let span = view.document.querySelector(".padding.left > span");
|
||||
node.style.padding = "5px";
|
||||
|
||||
yield selectNode(node, inspector);
|
||||
|
||||
let span = view.doc.querySelector(".padding.left > span");
|
||||
is(span.textContent, 5, "Should have the right value in the box model.");
|
||||
|
||||
EventUtils.synthesizeMouseAtCenter(span, {}, view);
|
||||
let editor = view.document.querySelector(".styleinspector-propertyeditor");
|
||||
EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView);
|
||||
let editor = view.doc.querySelector(".styleinspector-propertyeditor");
|
||||
ok(editor, "Should have opened the editor.");
|
||||
is(editor.value, "5px", "Should have the right value in the editor.");
|
||||
|
||||
EventUtils.synthesizeKey("VK_DELETE", {}, view);
|
||||
yield waitForUpdate();
|
||||
EventUtils.synthesizeKey("VK_DELETE", {}, view.doc.defaultView);
|
||||
yield waitForUpdate(inspector);
|
||||
|
||||
is(editor.value, "", "Should have the right value in the editor.");
|
||||
is(getStyle(node, "padding-left"), "", "Should have updated the padding");
|
||||
|
||||
EventUtils.synthesizeKey("VK_RETURN", {}, view);
|
||||
EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView);
|
||||
|
||||
is(getStyle(node, "padding-left"), "", "Should be the right padding.")
|
||||
is(span.textContent, 3, "Should have the right value in the box model.");
|
||||
});
|
||||
|
||||
addTest("When all properties are set on the node deleting one then cancelling should work",
|
||||
function*() {
|
||||
let node = doc.getElementById("div1");
|
||||
node.style.padding = "5px";
|
||||
let view = yield selectNode(node);
|
||||
function*(inspector, view) {
|
||||
let node = content.document.getElementById("div1");
|
||||
|
||||
let span = view.document.querySelector(".padding.left > span");
|
||||
node.style.padding = "5px";
|
||||
yield waitForUpdate(inspector);
|
||||
|
||||
yield selectNode(node, inspector);
|
||||
|
||||
let span = view.doc.querySelector(".padding.left > span");
|
||||
is(span.textContent, 5, "Should have the right value in the box model.");
|
||||
|
||||
EventUtils.synthesizeMouseAtCenter(span, {}, view);
|
||||
let editor = view.document.querySelector(".styleinspector-propertyeditor");
|
||||
EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView);
|
||||
let editor = view.doc.querySelector(".styleinspector-propertyeditor");
|
||||
ok(editor, "Should have opened the editor.");
|
||||
is(editor.value, "5px", "Should have the right value in the editor.");
|
||||
|
||||
EventUtils.synthesizeKey("VK_DELETE", {}, view);
|
||||
yield waitForUpdate();
|
||||
EventUtils.synthesizeKey("VK_DELETE", {}, view.doc.defaultView);
|
||||
yield waitForUpdate(inspector);
|
||||
|
||||
is(editor.value, "", "Should have the right value in the editor.");
|
||||
is(getStyle(node, "padding-left"), "", "Should have updated the padding");
|
||||
|
||||
EventUtils.synthesizeKey("VK_ESCAPE", {}, view);
|
||||
yield waitForUpdate();
|
||||
EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView);
|
||||
yield waitForUpdate(inspector);
|
||||
|
||||
is(getStyle(node, "padding-left"), "5px", "Should be the right padding.")
|
||||
is(span.textContent, 5, "Should have the right value in the box model.");
|
||||
|
|
|
@ -1,55 +1,56 @@
|
|||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
// Test that editing the border value in the box model applies the border style
|
||||
|
||||
const TEST_URI = "<style>" +
|
||||
"div { margin: 10px; padding: 3px }" +
|
||||
"#div1 { margin-top: 5px }" +
|
||||
"#div2 { border-bottom: 1em solid black; }" +
|
||||
"#div3 { padding: 2em; }" +
|
||||
"</style>" +
|
||||
"<div id='div1'></div><div id='div2'></div><div id='div3'></div>";
|
||||
|
||||
function getStyle(node, property) {
|
||||
return node.style.getPropertyValue(property);
|
||||
}
|
||||
|
||||
let doc;
|
||||
let inspector;
|
||||
|
||||
let test = asyncTest(function*() {
|
||||
let style = "div { margin: 10px; padding: 3px } #div1 { margin-top: 5px } #div2 { border-bottom: 1em solid black; } #div3 { padding: 2em; }";
|
||||
let html = "<style>" + style + "</style><div id='div1'></div><div id='div2'></div><div id='div3'></div>"
|
||||
yield addTab("data:text/html," + encodeURIComponent(TEST_URI));
|
||||
let {toolbox, inspector, view} = yield openLayoutView();
|
||||
|
||||
let content = yield loadTab("data:text/html," + encodeURIComponent(html));
|
||||
doc = content.document;
|
||||
|
||||
let target = TargetFactory.forTab(gBrowser.selectedTab);
|
||||
let toolbox = yield gDevTools.showToolbox(target, "inspector");
|
||||
inspector = toolbox.getCurrentPanel();
|
||||
|
||||
inspector.sidebar.select("layoutview");
|
||||
yield inspector.sidebar.once("layoutview-ready");
|
||||
yield runTests();
|
||||
yield runTests(inspector, view);
|
||||
// TODO: Closing the toolbox in this test leaks - bug 994314
|
||||
// yield gDevTools.closeToolbox(target);
|
||||
// yield destroyToolbox(inspector);
|
||||
});
|
||||
|
||||
addTest("Test that adding a border applies a border style when necessary",
|
||||
function*() {
|
||||
let node = doc.getElementById("div1");
|
||||
function*(inspector, view) {
|
||||
let node = content.document.getElementById("div1");
|
||||
is(getStyle(node, "border-top-width"), "", "Should have the right border");
|
||||
is(getStyle(node, "border-top-style"), "", "Should have the right border");
|
||||
let view = yield selectNode(node);
|
||||
yield selectNode(node, inspector);
|
||||
|
||||
let span = view.document.querySelector(".border.top > span");
|
||||
let span = view.doc.querySelector(".border.top > span");
|
||||
is(span.textContent, 0, "Should have the right value in the box model.");
|
||||
|
||||
EventUtils.synthesizeMouseAtCenter(span, {}, view);
|
||||
let editor = view.document.querySelector(".styleinspector-propertyeditor");
|
||||
EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView);
|
||||
let editor = view.doc.querySelector(".styleinspector-propertyeditor");
|
||||
ok(editor, "Should have opened the editor.");
|
||||
is(editor.value, "0", "Should have the right value in the editor.");
|
||||
|
||||
EventUtils.synthesizeKey("1", {}, view);
|
||||
yield waitForUpdate();
|
||||
EventUtils.synthesizeKey("1", {}, view.doc.defaultView);
|
||||
yield waitForUpdate(inspector);
|
||||
|
||||
is(editor.value, "1", "Should have the right value in the editor.");
|
||||
is(getStyle(node, "border-top-width"), "1px", "Should have the right border");
|
||||
is(getStyle(node, "border-top-style"), "solid", "Should have the right border");
|
||||
|
||||
EventUtils.synthesizeKey("VK_ESCAPE", {}, view);
|
||||
yield waitForUpdate();
|
||||
EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView);
|
||||
yield waitForUpdate(inspector);
|
||||
|
||||
is(getStyle(node, "border-top-width"), "", "Should be the right padding.")
|
||||
is(getStyle(node, "border-top-style"), "", "Should have the right border");
|
||||
|
|
|
@ -1,105 +1,107 @@
|
|||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
// Test that units are displayed correctly when editing values in the box model
|
||||
// and that values are retrieved and parsed correctly from the back-end
|
||||
|
||||
const TEST_URI = "<style>" +
|
||||
"div { margin: 10px; padding: 3px }" +
|
||||
"#div1 { margin-top: 5px }" +
|
||||
"#div2 { border-bottom: 1em solid black; }" +
|
||||
"#div3 { padding: 2em; }" +
|
||||
"</style>" +
|
||||
"<div id='div1'></div><div id='div2'></div><div id='div3'></div>";
|
||||
|
||||
function getStyle(node, property) {
|
||||
return node.style.getPropertyValue(property);
|
||||
}
|
||||
|
||||
let doc;
|
||||
let inspector;
|
||||
|
||||
let test = asyncTest(function*() {
|
||||
let style = "div { margin: 10px; padding: 3px } #div1 { margin-top: 5px } #div2 { border-bottom: 1em solid black; } #div3 { padding: 2em; }";
|
||||
let html = "<style>" + style + "</style><div id='div1'></div><div id='div2'></div><div id='div3'></div>"
|
||||
yield addTab("data:text/html," + encodeURIComponent(TEST_URI));
|
||||
let {toolbox, inspector, view} = yield openLayoutView();
|
||||
|
||||
let content = yield loadTab("data:text/html," + encodeURIComponent(html));
|
||||
doc = content.document;
|
||||
|
||||
let target = TargetFactory.forTab(gBrowser.selectedTab);
|
||||
let toolbox = yield gDevTools.showToolbox(target, "inspector");
|
||||
inspector = toolbox.getCurrentPanel();
|
||||
|
||||
inspector.sidebar.select("layoutview");
|
||||
yield inspector.sidebar.once("layoutview-ready");
|
||||
yield runTests();
|
||||
yield runTests(inspector, view);
|
||||
// TODO: Closing the toolbox in this test leaks - bug 994314
|
||||
// yield gDevTools.closeToolbox(target);
|
||||
// yield destroyToolbox(inspector);
|
||||
});
|
||||
|
||||
addTest("Test that entering units works",
|
||||
function*() {
|
||||
let node = doc.getElementById("div1");
|
||||
function*(inspector, view) {
|
||||
let node = content.document.getElementById("div1");
|
||||
is(getStyle(node, "padding-top"), "", "Should have the right padding");
|
||||
let view = yield selectNode(node);
|
||||
yield selectNode(node, inspector);
|
||||
|
||||
let span = view.document.querySelector(".padding.top > span");
|
||||
let span = view.doc.querySelector(".padding.top > span");
|
||||
is(span.textContent, 3, "Should have the right value in the box model.");
|
||||
|
||||
EventUtils.synthesizeMouseAtCenter(span, {}, view);
|
||||
let editor = view.document.querySelector(".styleinspector-propertyeditor");
|
||||
EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView);
|
||||
let editor = view.doc.querySelector(".styleinspector-propertyeditor");
|
||||
ok(editor, "Should have opened the editor.");
|
||||
is(editor.value, "3px", "Should have the right value in the editor.");
|
||||
|
||||
EventUtils.synthesizeKey("1", {}, view);
|
||||
yield waitForUpdate();
|
||||
EventUtils.synthesizeKey("e", {}, view);
|
||||
yield waitForUpdate();
|
||||
EventUtils.synthesizeKey("1", {}, view.doc.defaultView);
|
||||
yield waitForUpdate(inspector);
|
||||
EventUtils.synthesizeKey("e", {}, view.doc.defaultView);
|
||||
yield waitForUpdate(inspector);
|
||||
|
||||
is(getStyle(node, "padding-top"), "", "An invalid value is handled cleanly");
|
||||
|
||||
EventUtils.synthesizeKey("m", {}, view);
|
||||
yield waitForUpdate();
|
||||
EventUtils.synthesizeKey("m", {}, view.doc.defaultView);
|
||||
yield waitForUpdate(inspector);
|
||||
|
||||
is(editor.value, "1em", "Should have the right value in the editor.");
|
||||
is(getStyle(node, "padding-top"), "1em", "Should have updated the padding.");
|
||||
|
||||
EventUtils.synthesizeKey("VK_RETURN", {}, view);
|
||||
EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView);
|
||||
|
||||
is(getStyle(node, "padding-top"), "1em", "Should be the right padding.")
|
||||
is(span.textContent, 16, "Should have the right value in the box model.");
|
||||
});
|
||||
|
||||
addTest("Test that we pick up the value from a higher style rule",
|
||||
function*() {
|
||||
let node = doc.getElementById("div2");
|
||||
function*(inspector, view) {
|
||||
let node = content.document.getElementById("div2");
|
||||
is(getStyle(node, "border-bottom-width"), "", "Should have the right border-bottom-width");
|
||||
let view = yield selectNode(node);
|
||||
yield selectNode(node, inspector);
|
||||
|
||||
let span = view.document.querySelector(".border.bottom > span");
|
||||
let span = view.doc.querySelector(".border.bottom > span");
|
||||
is(span.textContent, 16, "Should have the right value in the box model.");
|
||||
|
||||
EventUtils.synthesizeMouseAtCenter(span, {}, view);
|
||||
let editor = view.document.querySelector(".styleinspector-propertyeditor");
|
||||
EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView);
|
||||
let editor = view.doc.querySelector(".styleinspector-propertyeditor");
|
||||
ok(editor, "Should have opened the editor.");
|
||||
is(editor.value, "1em", "Should have the right value in the editor.");
|
||||
|
||||
EventUtils.synthesizeKey("0", {}, view);
|
||||
yield waitForUpdate();
|
||||
EventUtils.synthesizeKey("0", {}, view.doc.defaultView);
|
||||
yield waitForUpdate(inspector);
|
||||
|
||||
is(editor.value, "0", "Should have the right value in the editor.");
|
||||
is(getStyle(node, "border-bottom-width"), "0px", "Should have updated the border.");
|
||||
|
||||
EventUtils.synthesizeKey("VK_RETURN", {}, view);
|
||||
EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView);
|
||||
|
||||
is(getStyle(node, "border-bottom-width"), "0px", "Should be the right border-bottom-width.")
|
||||
is(span.textContent, 0, "Should have the right value in the box model.");
|
||||
});
|
||||
|
||||
addTest("Test that shorthand properties are parsed correctly",
|
||||
function*() {
|
||||
let node = doc.getElementById("div3");
|
||||
function*(inspector, view) {
|
||||
let node = content.document.getElementById("div3");
|
||||
is(getStyle(node, "padding-right"), "", "Should have the right padding");
|
||||
let view = yield selectNode(node);
|
||||
yield selectNode(node, inspector);
|
||||
|
||||
let span = view.document.querySelector(".padding.right > span");
|
||||
let span = view.doc.querySelector(".padding.right > span");
|
||||
is(span.textContent, 32, "Should have the right value in the box model.");
|
||||
|
||||
EventUtils.synthesizeMouseAtCenter(span, {}, view);
|
||||
let editor = view.document.querySelector(".styleinspector-propertyeditor");
|
||||
EventUtils.synthesizeMouseAtCenter(span, {}, view.doc.defaultView);
|
||||
let editor = view.doc.querySelector(".styleinspector-propertyeditor");
|
||||
ok(editor, "Should have opened the editor.");
|
||||
is(editor.value, "2em", "Should have the right value in the editor.");
|
||||
|
||||
EventUtils.synthesizeKey("VK_RETURN", {}, view);
|
||||
EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView);
|
||||
|
||||
is(getStyle(node, "padding-right"), "", "Should be the right padding.")
|
||||
is(span.textContent, 32, "Should have the right value in the box model.");
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
// Test that the layout-view displays the right values and that it updates when
|
||||
// the node's style is changed
|
||||
|
||||
// Expected values:
|
||||
let res1 = [
|
||||
|
@ -36,46 +42,22 @@ let res2 = [
|
|||
{selector: ".border.right > span", value: 10},
|
||||
];
|
||||
|
||||
let inspector;
|
||||
let view;
|
||||
|
||||
let test = asyncTest(function*() {
|
||||
let style = "div { position: absolute; top: 42px; left: 42px; height: 100px; width: 100px; border: 10px solid black; padding: 20px; margin: 30px auto;}";
|
||||
let html = "<style>" + style + "</style><div></div>"
|
||||
|
||||
let content = yield loadTab("data:text/html," + encodeURIComponent(html));
|
||||
let node = content.document.querySelector("div");
|
||||
ok(node, "node found");
|
||||
yield addTab("data:text/html," + encodeURIComponent(html));
|
||||
let {toolbox, inspector, view} = yield openLayoutView();
|
||||
yield selectNode("div", inspector);
|
||||
|
||||
let target = TargetFactory.forTab(gBrowser.selectedTab);
|
||||
let toolbox = yield gDevTools.showToolbox(target, "inspector");
|
||||
inspector = toolbox.getCurrentPanel();
|
||||
yield runTests(inspector, view);
|
||||
|
||||
info("Inspector open");
|
||||
|
||||
inspector.sidebar.select("layoutview");
|
||||
yield inspector.sidebar.once("layoutview-ready");
|
||||
|
||||
inspector.selection.setNode(node);
|
||||
yield inspector.once("inspector-updated");
|
||||
|
||||
info("Layout view ready");
|
||||
|
||||
view = inspector.sidebar.getWindowForTab("layoutview");
|
||||
ok(!!view.layoutview, "LayoutView document is alive.");
|
||||
|
||||
yield runTests();
|
||||
|
||||
executeSoon(function() {
|
||||
inspector._toolbox.destroy();
|
||||
});
|
||||
|
||||
yield gDevTools.once("toolbox-destroyed");
|
||||
yield destroyToolbox(inspector);
|
||||
});
|
||||
|
||||
addTest("Test that the initial values of the box model are correct",
|
||||
function*() {
|
||||
let viewdoc = view.document;
|
||||
function*(inspector, view) {
|
||||
let viewdoc = view.doc;
|
||||
|
||||
for (let i = 0; i < res1.length; i++) {
|
||||
let elt = viewdoc.querySelector(res1[i].selector);
|
||||
|
@ -84,32 +66,16 @@ function*() {
|
|||
});
|
||||
|
||||
addTest("Test that changing the document updates the box model",
|
||||
function*() {
|
||||
let viewdoc = view.document;
|
||||
function*(inspector, view) {
|
||||
let viewdoc = view.doc;
|
||||
|
||||
let onUpdated = waitForUpdate(inspector);
|
||||
inspector.selection.node.style.height = "150px";
|
||||
inspector.selection.node.style.paddingRight = "50px";
|
||||
|
||||
yield waitForUpdate();
|
||||
yield onUpdated;
|
||||
|
||||
for (let i = 0; i < res2.length; i++) {
|
||||
let elt = viewdoc.querySelector(res2[i].selector);
|
||||
is(elt.textContent, res2[i].value, res2[i].selector + " has the right value after style update.");
|
||||
}
|
||||
});
|
||||
|
||||
addTest("Test that long labels on left/right are rotated 90 degrees",
|
||||
function*() {
|
||||
let viewdoc = view.document;
|
||||
const LONG_TEXT_ROTATE_LIMIT = 3;
|
||||
|
||||
for (let i = 0; i < res1.length; i++) {
|
||||
let elt = viewdoc.querySelector(res1[i].selector);
|
||||
let isLong = elt.textContent.length > LONG_TEXT_ROTATE_LIMIT;
|
||||
let classList = elt.parentNode.classList
|
||||
let canBeRotated = classList.contains("left") || classList.contains("right");
|
||||
let isRotated = classList.contains("rotate");
|
||||
|
||||
is(canBeRotated && isLong, isRotated, res1[i].selector + " correctly rotated.");
|
||||
}
|
||||
});
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
// Test that longer values are rotated on the side
|
||||
|
||||
const res1 = [
|
||||
{selector: ".margin.top > span", value: 30},
|
||||
{selector: ".margin.left > span", value: "auto"},
|
||||
{selector: ".margin.bottom > span", value: 30},
|
||||
{selector: ".margin.right > span", value: "auto"},
|
||||
{selector: ".padding.top > span", value: 20},
|
||||
{selector: ".padding.left > span", value: 2000000},
|
||||
{selector: ".padding.bottom > span", value: 20},
|
||||
{selector: ".padding.right > span", value: 20},
|
||||
{selector: ".border.top > span", value: 10},
|
||||
{selector: ".border.left > span", value: 10},
|
||||
{selector: ".border.bottom > span", value: 10},
|
||||
{selector: ".border.right > span", value: 10},
|
||||
];
|
||||
|
||||
const TEST_URI = encodeURIComponent([
|
||||
"<style>",
|
||||
"div{border:10px solid black; padding: 20px 20px 20px 2000000px; margin: 30px auto;}",
|
||||
"</style>",
|
||||
"<div></div>"
|
||||
].join(""));
|
||||
const LONG_TEXT_ROTATE_LIMIT = 3;
|
||||
|
||||
let test = asyncTest(function*() {
|
||||
yield addTab("data:text/html," + TEST_URI);
|
||||
let {toolbox, inspector, view} = yield openLayoutView();
|
||||
yield selectNode("div", inspector);
|
||||
|
||||
for (let i = 0; i < res1.length; i++) {
|
||||
let elt = view.doc.querySelector(res1[i].selector);
|
||||
let isLong = elt.textContent.length > LONG_TEXT_ROTATE_LIMIT;
|
||||
let classList = elt.parentNode.classList
|
||||
let canBeRotated = classList.contains("left") || classList.contains("right");
|
||||
let isRotated = classList.contains("rotate");
|
||||
|
||||
is(canBeRotated && isLong, isRotated, res1[i].selector + " correctly rotated.");
|
||||
}
|
||||
|
||||
yield destroyToolbox(inspector);
|
||||
});
|
|
@ -1,87 +1,242 @@
|
|||
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
Cu.import("resource://gre/modules/Task.jsm");
|
||||
"use strict";
|
||||
|
||||
const Cu = Components.utils;
|
||||
let {gDevTools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", {});
|
||||
let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
|
||||
const {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {});
|
||||
let TargetFactory = devtools.TargetFactory;
|
||||
let {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {});
|
||||
let {console} = Components.utils.import("resource://gre/modules/devtools/Console.jsm", {});
|
||||
|
||||
Services.prefs.setBoolPref("devtools.inspector.sidebarOpen", true);
|
||||
Services.prefs.setIntPref("devtools.toolbox.footer.height", 350);
|
||||
gDevTools.testing = true;
|
||||
SimpleTest.registerCleanupFunction(() => {
|
||||
Services.prefs.clearUserPref("devtools.inspector.sidebarOpen");
|
||||
Services.prefs.clearUserPref("devtools.toolbox.footer.height");
|
||||
gDevTools.testing = false;
|
||||
});
|
||||
|
||||
// All tests are async in general
|
||||
// All test are asynchronous
|
||||
waitForExplicitFinish();
|
||||
|
||||
function loadTab(url) {
|
||||
let deferred = promise.defer();
|
||||
const TEST_URL_ROOT = "http://example.com/browser/browser/devtools/layoutview/test/";
|
||||
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
// Uncomment to log events
|
||||
// Services.prefs.setBoolPref("devtools.dump.emit", true);
|
||||
// Services.prefs.setBoolPref("devtools.debugger.log", true);
|
||||
|
||||
// Set the testing flag on gDevTools and reset it when the test ends
|
||||
gDevTools.testing = true;
|
||||
registerCleanupFunction(() => gDevTools.testing = false);
|
||||
|
||||
// Clean-up all prefs that might have been changed during a test run
|
||||
// (safer here because if the test fails, then the pref is never reverted)
|
||||
Services.prefs.setIntPref("devtools.toolbox.footer.height", 350);
|
||||
registerCleanupFunction(() => {
|
||||
Services.prefs.clearUserPref("devtools.dump.emit");
|
||||
Services.prefs.clearUserPref("devtools.debugger.log");
|
||||
Services.prefs.clearUserPref("devtools.toolbox.footer.height");
|
||||
Services.prefs.setCharPref("devtools.inspector.activeSidebar", "ruleview");
|
||||
});
|
||||
|
||||
// Auto close the toolbox and close the test tabs when the test ends
|
||||
registerCleanupFunction(() => {
|
||||
// For now, tests must call `yield destroyToolbox(inspector);` at the end.
|
||||
// This should normally be handled automatically here but some tests
|
||||
// are leaking when we do so (browser_editablemodel_border.js)
|
||||
// try {
|
||||
// let target = TargetFactory.forTab(gBrowser.selectedTab);
|
||||
// gDevTools.closeToolbox(target);
|
||||
// } catch (ex) {
|
||||
// dump(ex);
|
||||
// }
|
||||
while (gBrowser.tabs.length > 1) {
|
||||
gBrowser.removeCurrentTab();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Define an async test based on a generator function
|
||||
*/
|
||||
function asyncTest(generator) {
|
||||
return () => Task.spawn(generator).then(null, ok.bind(null, false)).then(finish);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new test tab in the browser and load the given url.
|
||||
* @param {String} url The url to be loaded in the new tab
|
||||
* @return a promise that resolves to the tab object when the url is loaded
|
||||
*/
|
||||
function addTab(url) {
|
||||
let def = promise.defer();
|
||||
|
||||
let tab = gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.selectedBrowser.addEventListener("load", function onload() {
|
||||
gBrowser.selectedBrowser.removeEventListener("load", onload, true);
|
||||
waitForFocus(function() {
|
||||
deferred.resolve(content);
|
||||
info("URL " + url + " loading complete into new test tab");
|
||||
waitForFocus(() => {
|
||||
def.resolve(tab);
|
||||
}, content);
|
||||
}, true);
|
||||
|
||||
content.location = url;
|
||||
|
||||
return deferred.promise;
|
||||
return def.promise;
|
||||
}
|
||||
|
||||
function selectNode(aNode) {
|
||||
info("selecting node");
|
||||
let onSelect = inspector.once("layoutview-updated");
|
||||
inspector.selection.setNode(aNode, "test");
|
||||
return onSelect.then(() => {
|
||||
let view = inspector.sidebar.getWindowForTab("layoutview");
|
||||
ok(!!view.layoutview, "LayoutView document is alive.");
|
||||
/**
|
||||
* Destroy the toolbox
|
||||
* @param {InspectorPanel}
|
||||
* @return a promise that resolves when destroyed
|
||||
*/
|
||||
let destroyToolbox = Task.async(function*(inspector) {
|
||||
let onDestroyed = gDevTools.once("toolbox-destroyed");
|
||||
inspector._toolbox.destroy();
|
||||
yield onDestroyed;
|
||||
});
|
||||
|
||||
return view;
|
||||
});
|
||||
/**
|
||||
* Simple DOM node accesor function that takes either a node or a string css
|
||||
* selector as argument and returns the corresponding node
|
||||
* @param {String|DOMNode} nodeOrSelector
|
||||
* @return {DOMNode}
|
||||
*/
|
||||
function getNode(nodeOrSelector) {
|
||||
return typeof nodeOrSelector === "string" ?
|
||||
content.document.querySelector(nodeOrSelector) :
|
||||
nodeOrSelector;
|
||||
}
|
||||
|
||||
function waitForUpdate() {
|
||||
/**
|
||||
* Set the inspector's current selection to a node or to the first match of the
|
||||
* given css selector
|
||||
* @param {InspectorPanel} inspector The instance of InspectorPanel currently
|
||||
* loaded in the toolbox
|
||||
* @param {String} reason Defaults to "test" which instructs the inspector not
|
||||
* to highlight the node upon selection
|
||||
* @param {String} reason Defaults to "test" which instructs the inspector not
|
||||
* to highlight the node upon selection
|
||||
* @return a promise that resolves when the inspector is updated with the new
|
||||
* node
|
||||
*/
|
||||
function selectNode(nodeOrSelector, inspector, reason="test") {
|
||||
info("Selecting the node " + nodeOrSelector);
|
||||
let node = getNode(nodeOrSelector);
|
||||
let updated = inspector.once("inspector-updated");
|
||||
inspector.selection.setNode(node, reason);
|
||||
return updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 layout-view
|
||||
* sidebar tab selected.
|
||||
* @return a promise that resolves when the inspector is ready and the layout
|
||||
* view is visible and ready
|
||||
*/
|
||||
let openLayoutView = Task.async(function*() {
|
||||
let {toolbox, inspector} = yield openInspector();
|
||||
|
||||
if (!hasSideBarTab(inspector, "layoutview")) {
|
||||
info("Waiting for the layoutview sidebar to be ready");
|
||||
yield inspector.sidebar.once("layoutview-ready");
|
||||
}
|
||||
|
||||
info("Selecting the layoutview sidebar");
|
||||
inspector.sidebar.select("layoutview");
|
||||
|
||||
return {
|
||||
toolbox: toolbox,
|
||||
inspector: inspector,
|
||||
view: inspector.sidebar.getWindowForTab("layoutview")["layoutview"]
|
||||
};
|
||||
});
|
||||
|
||||
/**
|
||||
* Wait for the layoutview-updated event
|
||||
* @return a promise
|
||||
*/
|
||||
function waitForUpdate(inspector) {
|
||||
return inspector.once("layoutview-updated");
|
||||
}
|
||||
|
||||
function asyncTest(testfunc) {
|
||||
return Task.async(function*() {
|
||||
let initialTab = gBrowser.selectedTab;
|
||||
|
||||
yield testfunc();
|
||||
|
||||
// Remove all tabs except for the initial tab. This is basically
|
||||
// gBrowser.removeAllTabsBut without the animation
|
||||
let tabs = gBrowser.visibleTabs;
|
||||
gBrowser.selectedTab = initialTab;
|
||||
for (let i = tabs.length - 1; i >= 0; i--) {
|
||||
if (tabs[i] != initialTab)
|
||||
gBrowser.removeTab(tabs[i]);
|
||||
}
|
||||
|
||||
// Reset the sidebar back to the default
|
||||
Services.prefs.setCharPref("devtools.inspector.activeSidebar", "ruleview");
|
||||
|
||||
finish();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The addTest/runTests function couple provides a simple way to define
|
||||
* subsequent test cases in a test file. Example:
|
||||
*
|
||||
* addTest("what this test does", function*() {
|
||||
* ... actual code for the test ...
|
||||
* });
|
||||
* addTest("what this second test does", function*() {
|
||||
* ... actual code for the second test ...
|
||||
* });
|
||||
* runTests().then(...);
|
||||
*/
|
||||
var TESTS = [];
|
||||
|
||||
function addTest(message, func) {
|
||||
TESTS.push([message, Task.async(func)])
|
||||
}
|
||||
|
||||
var runTests = Task.async(function*() {
|
||||
let runTests = Task.async(function*(...args) {
|
||||
for (let [message, test] of TESTS) {
|
||||
info(message);
|
||||
yield test();
|
||||
info("Running new test case: " + message);
|
||||
yield test.apply(null, args);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -191,7 +191,7 @@ ElementStyle.prototype = {
|
|||
return this.dummyElementPromise.then(() => {
|
||||
if (this.populated != populated) {
|
||||
// Don't care anymore.
|
||||
return promise.reject("unused");
|
||||
return;
|
||||
}
|
||||
|
||||
// Store the current list of rules (if any) during the population
|
||||
|
|
|
@ -37,6 +37,10 @@ registerCleanupFunction(() => {
|
|||
// Uncomment to log events
|
||||
// Services.prefs.setBoolPref("devtools.dump.emit", true);
|
||||
|
||||
// Set the testing flag on gDevTools and reset it when the test ends
|
||||
gDevTools.testing = true;
|
||||
registerCleanupFunction(() => gDevTools.testing = false);
|
||||
|
||||
// Clean-up all prefs that might have been changed during a test run
|
||||
// (safer here because if the test fails, then the pref is never reverted)
|
||||
registerCleanupFunction(() => {
|
||||
|
|
Загрузка…
Ссылка в новой задаче