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