michael@0: /* vim: set ft=javascript ts=2 et sw=2 tw=80: */ michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: // Test original value is correctly displayed when ESCaping out of the michael@0: // inplace editor in the style inspector. michael@0: michael@0: const originalValue = "#00F"; michael@0: michael@0: // Test data format michael@0: // { michael@0: // value: what char sequence to type, michael@0: // commitKey: what key to type to "commit" the change, michael@0: // modifiers: commitKey modifiers, michael@0: // expected: what value is expected as a result michael@0: // } michael@0: const testData = [ michael@0: {value: "red", commitKey: "VK_ESCAPE", modifiers: {}, expected: originalValue}, michael@0: {value: "red", commitKey: "VK_RETURN", modifiers: {}, expected: "#F00"}, michael@0: {value: "invalid", commitKey: "VK_RETURN", modifiers: {}, expected: "invalid"}, michael@0: {value: "blue", commitKey: "VK_TAB", modifiers: {shiftKey: true}, expected: "blue"} michael@0: ]; michael@0: michael@0: let test = asyncTest(function*() { michael@0: yield addTab("data:text/html,test escaping property change reverts back to original value"); michael@0: michael@0: info("Creating the test document"); michael@0: createDocument(); michael@0: michael@0: info("Opening the rule view"); michael@0: let {toolbox, inspector, view} = yield openRuleView(); michael@0: michael@0: info("Selecting the test node"); michael@0: yield selectNode("#testid", inspector); michael@0: michael@0: info("Iterating over the test data"); michael@0: for (let data of testData) { michael@0: yield runTestData(view, data); michael@0: } michael@0: }); michael@0: michael@0: function createDocument() { michael@0: let style = '' + michael@0: '#testid {' + michael@0: ' color: ' + originalValue + ';' + michael@0: '}'; michael@0: michael@0: let node = content.document.createElement('style'); michael@0: node.setAttribute("type", "text/css"); michael@0: node.textContent = style; michael@0: content.document.getElementsByTagName("head")[0].appendChild(node); michael@0: michael@0: content.document.body.innerHTML = '
Styled Node
'; michael@0: } michael@0: michael@0: function* runTestData(view, {value, commitKey, modifiers, expected}) { michael@0: let idRuleEditor = view.element.children[1]._ruleEditor; michael@0: let propEditor = idRuleEditor.rule.textProps[0].editor; michael@0: michael@0: info("Focusing the inplace editor field"); michael@0: let editor = yield focusEditableField(propEditor.valueSpan); michael@0: is(inplaceEditor(propEditor.valueSpan), editor, "Focused editor should be the value span."); michael@0: michael@0: info("Entering test data " + value) michael@0: for (let ch of value) { michael@0: EventUtils.sendChar(ch, view.doc.defaultView); michael@0: } michael@0: michael@0: info("Waiting for focus on the field"); michael@0: let onBlur = once(editor.input, "blur"); michael@0: michael@0: info("Entering the commit key " + commitKey + " " + modifiers); michael@0: EventUtils.synthesizeKey(commitKey, modifiers); michael@0: yield onBlur; michael@0: michael@0: if (commitKey === "VK_ESCAPE") { michael@0: is(propEditor.valueSpan.textContent, expected, "Value is as expected: " + expected); michael@0: } else { michael@0: yield once(view.element, "CssRuleViewChanged"); michael@0: is(propEditor.valueSpan.textContent, expected, "Value is as expected: " + expected); michael@0: } michael@0: }