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 original value is correctly displayed when ESCaping out of the |
michael@0 | 8 | // inplace editor in the style inspector. |
michael@0 | 9 | |
michael@0 | 10 | const originalValue = "#00F"; |
michael@0 | 11 | |
michael@0 | 12 | // Test data format |
michael@0 | 13 | // { |
michael@0 | 14 | // value: what char sequence to type, |
michael@0 | 15 | // commitKey: what key to type to "commit" the change, |
michael@0 | 16 | // modifiers: commitKey modifiers, |
michael@0 | 17 | // expected: what value is expected as a result |
michael@0 | 18 | // } |
michael@0 | 19 | const testData = [ |
michael@0 | 20 | {value: "red", commitKey: "VK_ESCAPE", modifiers: {}, expected: originalValue}, |
michael@0 | 21 | {value: "red", commitKey: "VK_RETURN", modifiers: {}, expected: "#F00"}, |
michael@0 | 22 | {value: "invalid", commitKey: "VK_RETURN", modifiers: {}, expected: "invalid"}, |
michael@0 | 23 | {value: "blue", commitKey: "VK_TAB", modifiers: {shiftKey: true}, expected: "blue"} |
michael@0 | 24 | ]; |
michael@0 | 25 | |
michael@0 | 26 | let test = asyncTest(function*() { |
michael@0 | 27 | yield addTab("data:text/html,test escaping property change reverts back to original value"); |
michael@0 | 28 | |
michael@0 | 29 | info("Creating the test document"); |
michael@0 | 30 | createDocument(); |
michael@0 | 31 | |
michael@0 | 32 | info("Opening the rule view"); |
michael@0 | 33 | let {toolbox, inspector, view} = yield openRuleView(); |
michael@0 | 34 | |
michael@0 | 35 | info("Selecting the test node"); |
michael@0 | 36 | yield selectNode("#testid", inspector); |
michael@0 | 37 | |
michael@0 | 38 | info("Iterating over the test data"); |
michael@0 | 39 | for (let data of testData) { |
michael@0 | 40 | yield runTestData(view, data); |
michael@0 | 41 | } |
michael@0 | 42 | }); |
michael@0 | 43 | |
michael@0 | 44 | function createDocument() { |
michael@0 | 45 | let style = '' + |
michael@0 | 46 | '#testid {' + |
michael@0 | 47 | ' color: ' + originalValue + ';' + |
michael@0 | 48 | '}'; |
michael@0 | 49 | |
michael@0 | 50 | let node = content.document.createElement('style'); |
michael@0 | 51 | node.setAttribute("type", "text/css"); |
michael@0 | 52 | node.textContent = style; |
michael@0 | 53 | content.document.getElementsByTagName("head")[0].appendChild(node); |
michael@0 | 54 | |
michael@0 | 55 | content.document.body.innerHTML = '<div id="testid">Styled Node</div>'; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | function* runTestData(view, {value, commitKey, modifiers, expected}) { |
michael@0 | 59 | let idRuleEditor = view.element.children[1]._ruleEditor; |
michael@0 | 60 | let propEditor = idRuleEditor.rule.textProps[0].editor; |
michael@0 | 61 | |
michael@0 | 62 | info("Focusing the inplace editor field"); |
michael@0 | 63 | let editor = yield focusEditableField(propEditor.valueSpan); |
michael@0 | 64 | is(inplaceEditor(propEditor.valueSpan), editor, "Focused editor should be the value span."); |
michael@0 | 65 | |
michael@0 | 66 | info("Entering test data " + value) |
michael@0 | 67 | for (let ch of value) { |
michael@0 | 68 | EventUtils.sendChar(ch, view.doc.defaultView); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | info("Waiting for focus on the field"); |
michael@0 | 72 | let onBlur = once(editor.input, "blur"); |
michael@0 | 73 | |
michael@0 | 74 | info("Entering the commit key " + commitKey + " " + modifiers); |
michael@0 | 75 | EventUtils.synthesizeKey(commitKey, modifiers); |
michael@0 | 76 | yield onBlur; |
michael@0 | 77 | |
michael@0 | 78 | if (commitKey === "VK_ESCAPE") { |
michael@0 | 79 | is(propEditor.valueSpan.textContent, expected, "Value is as expected: " + expected); |
michael@0 | 80 | } else { |
michael@0 | 81 | yield once(view.element, "CssRuleViewChanged"); |
michael@0 | 82 | is(propEditor.valueSpan.textContent, expected, "Value is as expected: " + expected); |
michael@0 | 83 | } |
michael@0 | 84 | } |