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 | // Testing various inplace-editor behaviors in the rule-view |
michael@0 | 8 | // FIXME: To be split in several test files, and some of the inplace-editor |
michael@0 | 9 | // focus/blur/commit/revert stuff should be factored out in head.js |
michael@0 | 10 | |
michael@0 | 11 | let TEST_URL = 'url("' + TEST_URL_ROOT + 'doc_test_image.png")'; |
michael@0 | 12 | let PAGE_CONTENT = [ |
michael@0 | 13 | '<style type="text/css">', |
michael@0 | 14 | ' #testid {', |
michael@0 | 15 | ' background-color: blue;', |
michael@0 | 16 | ' }', |
michael@0 | 17 | ' .testclass {', |
michael@0 | 18 | ' background-color: green;', |
michael@0 | 19 | ' }', |
michael@0 | 20 | '</style>', |
michael@0 | 21 | '<div id="testid" class="testclass">Styled Node</div>' |
michael@0 | 22 | ].join("\n"); |
michael@0 | 23 | |
michael@0 | 24 | let test = asyncTest(function*() { |
michael@0 | 25 | yield addTab("data:text/html,test rule view user changes"); |
michael@0 | 26 | |
michael@0 | 27 | info("Creating the test document"); |
michael@0 | 28 | content.document.body.innerHTML = PAGE_CONTENT; |
michael@0 | 29 | |
michael@0 | 30 | info("Opening the rule-view"); |
michael@0 | 31 | let {toolbox, inspector, view} = yield openRuleView(); |
michael@0 | 32 | |
michael@0 | 33 | info("Selecting the test element"); |
michael@0 | 34 | yield selectNode("#testid", inspector); |
michael@0 | 35 | |
michael@0 | 36 | yield testEditProperty(view, "border-color", "red"); |
michael@0 | 37 | yield testEditProperty(view, "background-image", TEST_URL); |
michael@0 | 38 | }); |
michael@0 | 39 | |
michael@0 | 40 | function* testEditProperty(view, name, value) { |
michael@0 | 41 | info("Test editing existing property name/value fields"); |
michael@0 | 42 | |
michael@0 | 43 | let idRuleEditor = view.element.children[1]._ruleEditor; |
michael@0 | 44 | let propEditor = idRuleEditor.rule.textProps[0].editor; |
michael@0 | 45 | |
michael@0 | 46 | info("Focusing an existing property name in the rule-view"); |
michael@0 | 47 | let editor = yield focusEditableField(propEditor.nameSpan, 32, 1); |
michael@0 | 48 | |
michael@0 | 49 | is(inplaceEditor(propEditor.nameSpan), editor, "The property name editor got focused"); |
michael@0 | 50 | let input = editor.input; |
michael@0 | 51 | |
michael@0 | 52 | info("Entering a new property name, including : to commit and focus the value"); |
michael@0 | 53 | let onValueFocus = once(idRuleEditor.element, "focus", true); |
michael@0 | 54 | let onModifications = idRuleEditor.rule._applyingModifications; |
michael@0 | 55 | for (let ch of name + ":") { |
michael@0 | 56 | EventUtils.sendChar(ch, view.doc.defaultView); |
michael@0 | 57 | } |
michael@0 | 58 | yield onValueFocus; |
michael@0 | 59 | yield onModifications; |
michael@0 | 60 | |
michael@0 | 61 | // Getting the value editor after focus |
michael@0 | 62 | editor = inplaceEditor(view.doc.activeElement); |
michael@0 | 63 | input = editor.input; |
michael@0 | 64 | is(inplaceEditor(propEditor.valueSpan), editor, "Focus moved to the value."); |
michael@0 | 65 | |
michael@0 | 66 | info("Entering a new value, including ; to commit and blur the value"); |
michael@0 | 67 | let onBlur = once(input, "blur"); |
michael@0 | 68 | let onModifications = idRuleEditor.rule._applyingModifications; |
michael@0 | 69 | for (let ch of value + ";") { |
michael@0 | 70 | EventUtils.sendChar(ch, view.doc.defaultView); |
michael@0 | 71 | } |
michael@0 | 72 | yield onBlur; |
michael@0 | 73 | yield onModifications; |
michael@0 | 74 | |
michael@0 | 75 | let propValue = idRuleEditor.rule.domRule._rawStyle().getPropertyValue(name); |
michael@0 | 76 | is(propValue, value, name + " should have been set."); |
michael@0 | 77 | is(propEditor.isValid(), true, value + " should be a valid entry"); |
michael@0 | 78 | } |