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 all sorts of additions and updates of properties in the rule-view |
michael@0 | 8 | // FIXME: TO BE SPLIT IN *MANY* SMALLER TESTS |
michael@0 | 9 | |
michael@0 | 10 | let test = asyncTest(function*() { |
michael@0 | 11 | yield addTab("data:text/html;charset=utf-8,browser_ruleview_ui.js"); |
michael@0 | 12 | let {toolbox, inspector, view} = yield openRuleView(); |
michael@0 | 13 | |
michael@0 | 14 | info("Creating the test document"); |
michael@0 | 15 | let style = "" + |
michael@0 | 16 | "#testid {" + |
michael@0 | 17 | " background-color: blue;" + |
michael@0 | 18 | "}" + |
michael@0 | 19 | ".testclass, .unmatched {" + |
michael@0 | 20 | " background-color: green;" + |
michael@0 | 21 | "}"; |
michael@0 | 22 | let styleNode = addStyle(content.document, style); |
michael@0 | 23 | content.document.body.innerHTML = "<div id='testid' class='testclass'>Styled Node</div>" + |
michael@0 | 24 | "<div id='testid2'>Styled Node</div>"; |
michael@0 | 25 | |
michael@0 | 26 | yield testCreateNew(inspector, view); |
michael@0 | 27 | yield inspector.once("inspector-updated"); |
michael@0 | 28 | }); |
michael@0 | 29 | |
michael@0 | 30 | function* testCreateNew(inspector, ruleView) { |
michael@0 | 31 | // Create a new property. |
michael@0 | 32 | let elementRuleEditor = ruleView.element.children[0]._ruleEditor; |
michael@0 | 33 | let editor = yield focusEditableField(elementRuleEditor.closeBrace); |
michael@0 | 34 | |
michael@0 | 35 | is(inplaceEditor(elementRuleEditor.newPropSpan), editor, |
michael@0 | 36 | "Next focused editor should be the new property editor."); |
michael@0 | 37 | |
michael@0 | 38 | let input = editor.input; |
michael@0 | 39 | |
michael@0 | 40 | ok(input.selectionStart === 0 && input.selectionEnd === input.value.length, |
michael@0 | 41 | "Editor contents are selected."); |
michael@0 | 42 | |
michael@0 | 43 | // Try clicking on the editor's input again, shouldn't cause trouble (see bug 761665). |
michael@0 | 44 | EventUtils.synthesizeMouse(input, 1, 1, {}, ruleView.doc.defaultView); |
michael@0 | 45 | input.select(); |
michael@0 | 46 | |
michael@0 | 47 | info("Entering the property name"); |
michael@0 | 48 | input.value = "background-color"; |
michael@0 | 49 | |
michael@0 | 50 | info("Pressing RETURN and waiting for the value field focus"); |
michael@0 | 51 | let onFocus = once(elementRuleEditor.element, "focus", true); |
michael@0 | 52 | EventUtils.sendKey("return", ruleView.doc.defaultView); |
michael@0 | 53 | yield onFocus; |
michael@0 | 54 | yield elementRuleEditor.rule._applyingModifications; |
michael@0 | 55 | |
michael@0 | 56 | editor = inplaceEditor(ruleView.doc.activeElement); |
michael@0 | 57 | |
michael@0 | 58 | is(elementRuleEditor.rule.textProps.length, 1, "Should have created a new text property."); |
michael@0 | 59 | is(elementRuleEditor.propertyList.children.length, 1, "Should have created a property editor."); |
michael@0 | 60 | let textProp = elementRuleEditor.rule.textProps[0]; |
michael@0 | 61 | is(editor, inplaceEditor(textProp.editor.valueSpan), "Should be editing the value span now."); |
michael@0 | 62 | |
michael@0 | 63 | editor.input.value = "purple"; |
michael@0 | 64 | let onBlur = once(editor.input, "blur"); |
michael@0 | 65 | editor.input.blur(); |
michael@0 | 66 | yield onBlur; |
michael@0 | 67 | yield elementRuleEditor.rule._applyingModifications; |
michael@0 | 68 | |
michael@0 | 69 | is(textProp.value, "purple", "Text prop should have been changed."); |
michael@0 | 70 | } |