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