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" style="background-color:red;">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 testCreateNewEscape(view); |
michael@0 | 37 | }); |
michael@0 | 38 | |
michael@0 | 39 | function* testCreateNewEscape(view) { |
michael@0 | 40 | info("Test creating a new property and escaping"); |
michael@0 | 41 | |
michael@0 | 42 | let elementRuleEditor = view.element.children[0]._ruleEditor; |
michael@0 | 43 | |
michael@0 | 44 | info("Focusing a new property name in the rule-view"); |
michael@0 | 45 | let editor = yield focusEditableField(elementRuleEditor.closeBrace); |
michael@0 | 46 | |
michael@0 | 47 | is(inplaceEditor(elementRuleEditor.newPropSpan), editor, "The new property editor got focused."); |
michael@0 | 48 | let input = editor.input; |
michael@0 | 49 | |
michael@0 | 50 | info("Entering a value in the property name editor"); |
michael@0 | 51 | input.value = "color"; |
michael@0 | 52 | |
michael@0 | 53 | info("Pressing return to commit and focus the new value field"); |
michael@0 | 54 | let onValueFocus = once(elementRuleEditor.element, "focus", true); |
michael@0 | 55 | let onModifications = elementRuleEditor.rule._applyingModifications; |
michael@0 | 56 | EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView); |
michael@0 | 57 | yield onValueFocus; |
michael@0 | 58 | yield onModifications; |
michael@0 | 59 | |
michael@0 | 60 | // Getting the new value editor after focus |
michael@0 | 61 | editor = inplaceEditor(view.doc.activeElement); |
michael@0 | 62 | let textProp = elementRuleEditor.rule.textProps[1]; |
michael@0 | 63 | |
michael@0 | 64 | is(elementRuleEditor.rule.textProps.length, 2, "Created a new text property."); |
michael@0 | 65 | is(elementRuleEditor.propertyList.children.length, 2, "Created a property editor."); |
michael@0 | 66 | is(editor, inplaceEditor(textProp.editor.valueSpan), "Editing the value span now."); |
michael@0 | 67 | |
michael@0 | 68 | info("Entering a property value"); |
michael@0 | 69 | editor.input.value = "red"; |
michael@0 | 70 | |
michael@0 | 71 | info("Escaping out of the field"); |
michael@0 | 72 | EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView); |
michael@0 | 73 | |
michael@0 | 74 | info("Checking that the previous field is focused"); |
michael@0 | 75 | let focusedElement = inplaceEditor(elementRuleEditor.rule.textProps[0].editor.valueSpan).input; |
michael@0 | 76 | is(focusedElement, focusedElement.ownerDocument.activeElement, "Correct element has focus"); |
michael@0 | 77 | |
michael@0 | 78 | let onModifications = elementRuleEditor.rule._applyingModifications; |
michael@0 | 79 | EventUtils.synthesizeKey("VK_ESCAPE", {}, view.doc.defaultView); |
michael@0 | 80 | yield onModifications; |
michael@0 | 81 | |
michael@0 | 82 | is(elementRuleEditor.rule.textProps.length, 1, "Removed the new text property."); |
michael@0 | 83 | is(elementRuleEditor.propertyList.children.length, 1, "Removed the property editor."); |
michael@0 | 84 | } |