Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* vim: set ft=javascript ts=2 et sw=2 tw=80: */ |
michael@0 | 2 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 4 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | // Test that changes are previewed when editing a property value |
michael@0 | 8 | |
michael@0 | 9 | // Format |
michael@0 | 10 | // { |
michael@0 | 11 | // value : what to type in the field |
michael@0 | 12 | // expected : expected computed style on the targeted element |
michael@0 | 13 | // } |
michael@0 | 14 | const TEST_DATA = [ |
michael@0 | 15 | {value: "inline", expected: "inline"}, |
michael@0 | 16 | {value: "inline-block", expected: "inline-block"}, |
michael@0 | 17 | |
michael@0 | 18 | // Invalid property values should not apply, and should fall back to default |
michael@0 | 19 | {value: "red", expected: "block"}, |
michael@0 | 20 | {value: "something", expected: "block"}, |
michael@0 | 21 | |
michael@0 | 22 | {escape: true, value: "inline", expected: "block"} |
michael@0 | 23 | ]; |
michael@0 | 24 | |
michael@0 | 25 | let test = asyncTest(function*() { |
michael@0 | 26 | yield addTab("data:text/html,test rule view live preview on user changes"); |
michael@0 | 27 | |
michael@0 | 28 | let style = '#testid {display:block;}'; |
michael@0 | 29 | let styleNode = addStyle(content.document, style); |
michael@0 | 30 | content.document.body.innerHTML = '<div id="testid">Styled Node</div><span>inline element</span>'; |
michael@0 | 31 | let testElement = getNode("#testid"); |
michael@0 | 32 | |
michael@0 | 33 | let {toolbox, inspector, view} = yield openRuleView(); |
michael@0 | 34 | yield selectNode(testElement, inspector); |
michael@0 | 35 | |
michael@0 | 36 | for (let data of TEST_DATA) { |
michael@0 | 37 | yield testLivePreviewData(data, view, testElement); |
michael@0 | 38 | } |
michael@0 | 39 | }); |
michael@0 | 40 | |
michael@0 | 41 | |
michael@0 | 42 | function* testLivePreviewData(data, ruleView, testElement) { |
michael@0 | 43 | let idRuleEditor = ruleView.element.children[1]._ruleEditor; |
michael@0 | 44 | let propEditor = idRuleEditor.rule.textProps[0].editor; |
michael@0 | 45 | |
michael@0 | 46 | info("Focusing the property value inplace-editor"); |
michael@0 | 47 | let editor = yield focusEditableField(propEditor.valueSpan); |
michael@0 | 48 | is(inplaceEditor(propEditor.valueSpan), editor, "The focused editor is the value"); |
michael@0 | 49 | |
michael@0 | 50 | info("Enter a value in the editor") |
michael@0 | 51 | for (let ch of data.value) { |
michael@0 | 52 | EventUtils.sendChar(ch, ruleView.doc.defaultView); |
michael@0 | 53 | } |
michael@0 | 54 | if (data.escape) { |
michael@0 | 55 | EventUtils.synthesizeKey("VK_ESCAPE", {}); |
michael@0 | 56 | } else { |
michael@0 | 57 | EventUtils.synthesizeKey("VK_RETURN", {}); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | yield wait(1); |
michael@0 | 61 | |
michael@0 | 62 | // While the editor is still focused in, the display should have changed already |
michael@0 | 63 | is(content.getComputedStyle(testElement).display, |
michael@0 | 64 | data.expected, |
michael@0 | 65 | "Element should be previewed as " + data.expected); |
michael@0 | 66 | } |