michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: function getStyle(node, property) { michael@0: return node.style.getPropertyValue(property); michael@0: } michael@0: michael@0: let doc; michael@0: let inspector; michael@0: michael@0: let test = asyncTest(function*() { michael@0: let style = "div { margin: 10px; padding: 3px } #div1 { margin-top: 5px } #div2 { border-bottom: 1em solid black; } #div3 { padding: 2em; }"; michael@0: let html = "
" michael@0: michael@0: let content = yield loadTab("data:text/html," + encodeURIComponent(html)); michael@0: doc = content.document; michael@0: michael@0: let target = TargetFactory.forTab(gBrowser.selectedTab); michael@0: let toolbox = yield gDevTools.showToolbox(target, "inspector"); michael@0: inspector = toolbox.getCurrentPanel(); michael@0: michael@0: inspector.sidebar.select("layoutview"); michael@0: yield inspector.sidebar.once("layoutview-ready"); michael@0: yield runTests(); michael@0: // TODO: Closing the toolbox in this test leaks - bug 994314 michael@0: // yield gDevTools.closeToolbox(target); michael@0: }); michael@0: michael@0: addTest("Test that entering units works", michael@0: function*() { michael@0: let node = doc.getElementById("div1"); michael@0: is(getStyle(node, "padding-top"), "", "Should have the right padding"); michael@0: let view = yield selectNode(node); michael@0: michael@0: let span = view.document.querySelector(".padding.top > span"); michael@0: is(span.textContent, 3, "Should have the right value in the box model."); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(span, {}, view); michael@0: let editor = view.document.querySelector(".styleinspector-propertyeditor"); michael@0: ok(editor, "Should have opened the editor."); michael@0: is(editor.value, "3px", "Should have the right value in the editor."); michael@0: michael@0: EventUtils.synthesizeKey("1", {}, view); michael@0: yield waitForUpdate(); michael@0: EventUtils.synthesizeKey("e", {}, view); michael@0: yield waitForUpdate(); michael@0: michael@0: is(getStyle(node, "padding-top"), "", "An invalid value is handled cleanly"); michael@0: michael@0: EventUtils.synthesizeKey("m", {}, view); michael@0: yield waitForUpdate(); michael@0: michael@0: is(editor.value, "1em", "Should have the right value in the editor."); michael@0: is(getStyle(node, "padding-top"), "1em", "Should have updated the padding."); michael@0: michael@0: EventUtils.synthesizeKey("VK_RETURN", {}, view); michael@0: yield waitForUpdate(); michael@0: michael@0: is(getStyle(node, "padding-top"), "1em", "Should be the right padding.") michael@0: is(span.textContent, 16, "Should have the right value in the box model."); michael@0: }); michael@0: michael@0: addTest("Test that we pick up the value from a higher style rule", michael@0: function*() { michael@0: let node = doc.getElementById("div2"); michael@0: is(getStyle(node, "border-bottom-width"), "", "Should have the right border-bottom-width"); michael@0: let view = yield selectNode(node); michael@0: michael@0: let span = view.document.querySelector(".border.bottom > span"); michael@0: is(span.textContent, 16, "Should have the right value in the box model."); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(span, {}, view); michael@0: let editor = view.document.querySelector(".styleinspector-propertyeditor"); michael@0: ok(editor, "Should have opened the editor."); michael@0: is(editor.value, "1em", "Should have the right value in the editor."); michael@0: michael@0: EventUtils.synthesizeKey("0", {}, view); michael@0: yield waitForUpdate(); michael@0: michael@0: is(editor.value, "0", "Should have the right value in the editor."); michael@0: is(getStyle(node, "border-bottom-width"), "0px", "Should have updated the border."); michael@0: michael@0: EventUtils.synthesizeKey("VK_RETURN", {}, view); michael@0: yield waitForUpdate(); michael@0: michael@0: is(getStyle(node, "border-bottom-width"), "0px", "Should be the right border-bottom-width.") michael@0: is(span.textContent, 0, "Should have the right value in the box model."); michael@0: }); michael@0: michael@0: addTest("Test that shorthand properties are parsed correctly", michael@0: function*() { michael@0: let node = doc.getElementById("div3"); michael@0: is(getStyle(node, "padding-right"), "", "Should have the right padding"); michael@0: let view = yield selectNode(node); michael@0: michael@0: let span = view.document.querySelector(".padding.right > span"); michael@0: is(span.textContent, 32, "Should have the right value in the box model."); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(span, {}, view); michael@0: let editor = view.document.querySelector(".styleinspector-propertyeditor"); michael@0: ok(editor, "Should have opened the editor."); michael@0: is(editor.value, "2em", "Should have the right value in the editor."); michael@0: michael@0: EventUtils.synthesizeKey("VK_RETURN", {}, view); michael@0: yield waitForUpdate(); michael@0: michael@0: is(getStyle(node, "padding-right"), "", "Should be the right padding.") michael@0: is(span.textContent, 32, "Should have the right value in the box model."); michael@0: });