1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/layoutview/test/browser_editablemodel_allproperties.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,136 @@ 1.4 + 1.5 +/* Any copyright is dedicated to the Public Domain. 1.6 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.7 + 1.8 +function getStyle(node, property) { 1.9 + return node.style.getPropertyValue(property); 1.10 +} 1.11 + 1.12 +let doc; 1.13 +let inspector; 1.14 + 1.15 +let test = asyncTest(function*() { 1.16 + let style = "div { margin: 10px; padding: 3px } #div1 { margin-top: 5px } #div2 { border-bottom: 1em solid black; } #div3 { padding: 2em; }"; 1.17 + let html = "<style>" + style + "</style><div id='div1'></div><div id='div2'></div><div id='div3'></div>" 1.18 + 1.19 + let content = yield loadTab("data:text/html," + encodeURIComponent(html)); 1.20 + doc = content.document; 1.21 + 1.22 + let target = TargetFactory.forTab(gBrowser.selectedTab); 1.23 + let toolbox = yield gDevTools.showToolbox(target, "inspector"); 1.24 + inspector = toolbox.getCurrentPanel(); 1.25 + 1.26 + inspector.sidebar.select("layoutview"); 1.27 + yield inspector.sidebar.once("layoutview-ready"); 1.28 + yield runTests(); 1.29 + // TODO: Closing the toolbox in this test leaks - bug 994314 1.30 + // yield gDevTools.closeToolbox(target); 1.31 +}); 1.32 + 1.33 +addTest("When all properties are set on the node editing one should work", 1.34 +function*() { 1.35 + let node = doc.getElementById("div1"); 1.36 + node.style.padding = "5px"; 1.37 + let view = yield selectNode(node); 1.38 + 1.39 + let span = view.document.querySelector(".padding.bottom > span"); 1.40 + is(span.textContent, 5, "Should have the right value in the box model."); 1.41 + 1.42 + EventUtils.synthesizeMouseAtCenter(span, {}, view); 1.43 + let editor = view.document.querySelector(".styleinspector-propertyeditor"); 1.44 + ok(editor, "Should have opened the editor."); 1.45 + is(editor.value, "5px", "Should have the right value in the editor."); 1.46 + 1.47 + EventUtils.synthesizeKey("7", {}, view); 1.48 + yield waitForUpdate(); 1.49 + 1.50 + is(editor.value, "7", "Should have the right value in the editor."); 1.51 + is(getStyle(node, "padding-bottom"), "7px", "Should have updated the padding"); 1.52 + 1.53 + EventUtils.synthesizeKey("VK_RETURN", {}, view); 1.54 + yield waitForUpdate(); 1.55 + 1.56 + is(getStyle(node, "padding-bottom"), "7px", "Should be the right padding.") 1.57 + is(span.textContent, 7, "Should have the right value in the box model."); 1.58 +}); 1.59 + 1.60 +addTest("When all properties are set on the node editing one should work", 1.61 +function*() { 1.62 + let node = doc.getElementById("div1"); 1.63 + node.style.padding = "5px"; 1.64 + let view = yield selectNode(node); 1.65 + 1.66 + let span = view.document.querySelector(".padding.left > span"); 1.67 + is(span.textContent, 5, "Should have the right value in the box model."); 1.68 + 1.69 + EventUtils.synthesizeMouseAtCenter(span, {}, view); 1.70 + let editor = view.document.querySelector(".styleinspector-propertyeditor"); 1.71 + ok(editor, "Should have opened the editor."); 1.72 + is(editor.value, "5px", "Should have the right value in the editor."); 1.73 + 1.74 + EventUtils.synthesizeKey("8", {}, view); 1.75 + yield waitForUpdate(); 1.76 + 1.77 + is(editor.value, "8", "Should have the right value in the editor."); 1.78 + is(getStyle(node, "padding-left"), "8px", "Should have updated the padding"); 1.79 + 1.80 + EventUtils.synthesizeKey("VK_ESCAPE", {}, view); 1.81 + yield waitForUpdate(); 1.82 + 1.83 + is(getStyle(node, "padding-left"), "5px", "Should be the right padding.") 1.84 + is(span.textContent, 5, "Should have the right value in the box model."); 1.85 +}); 1.86 + 1.87 +addTest("When all properties are set on the node deleting one should work", 1.88 +function*() { 1.89 + let node = doc.getElementById("div1"); 1.90 + node.style.padding = "5px"; 1.91 + let view = yield selectNode(node); 1.92 + 1.93 + let span = view.document.querySelector(".padding.left > span"); 1.94 + is(span.textContent, 5, "Should have the right value in the box model."); 1.95 + 1.96 + EventUtils.synthesizeMouseAtCenter(span, {}, view); 1.97 + let editor = view.document.querySelector(".styleinspector-propertyeditor"); 1.98 + ok(editor, "Should have opened the editor."); 1.99 + is(editor.value, "5px", "Should have the right value in the editor."); 1.100 + 1.101 + EventUtils.synthesizeKey("VK_DELETE", {}, view); 1.102 + yield waitForUpdate(); 1.103 + 1.104 + is(editor.value, "", "Should have the right value in the editor."); 1.105 + is(getStyle(node, "padding-left"), "", "Should have updated the padding"); 1.106 + 1.107 + EventUtils.synthesizeKey("VK_RETURN", {}, view); 1.108 + yield waitForUpdate(); 1.109 + 1.110 + is(getStyle(node, "padding-left"), "", "Should be the right padding.") 1.111 + is(span.textContent, 3, "Should have the right value in the box model."); 1.112 +}); 1.113 + 1.114 +addTest("When all properties are set on the node deleting one then cancelling should work", 1.115 +function*() { 1.116 + let node = doc.getElementById("div1"); 1.117 + node.style.padding = "5px"; 1.118 + let view = yield selectNode(node); 1.119 + 1.120 + let span = view.document.querySelector(".padding.left > span"); 1.121 + is(span.textContent, 5, "Should have the right value in the box model."); 1.122 + 1.123 + EventUtils.synthesizeMouseAtCenter(span, {}, view); 1.124 + let editor = view.document.querySelector(".styleinspector-propertyeditor"); 1.125 + ok(editor, "Should have opened the editor."); 1.126 + is(editor.value, "5px", "Should have the right value in the editor."); 1.127 + 1.128 + EventUtils.synthesizeKey("VK_DELETE", {}, view); 1.129 + yield waitForUpdate(); 1.130 + 1.131 + is(editor.value, "", "Should have the right value in the editor."); 1.132 + is(getStyle(node, "padding-left"), "", "Should have updated the padding"); 1.133 + 1.134 + EventUtils.synthesizeKey("VK_ESCAPE", {}, view); 1.135 + yield waitForUpdate(); 1.136 + 1.137 + is(getStyle(node, "padding-left"), "5px", "Should be the right padding.") 1.138 + is(span.textContent, 5, "Should have the right value in the box model."); 1.139 +});