browser/devtools/styleinspector/test/browser_ruleview_add-property_01.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/ */
     5 "use strict";
     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
    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");
    24 let test = asyncTest(function*() {
    25   yield addTab("data:text/html,test rule view user changes");
    27   info("Creating the test document");
    28   content.document.body.innerHTML = PAGE_CONTENT;
    30   info("Opening the rule-view");
    31   let {toolbox, inspector, view} = yield openRuleView();
    33   info("Selecting the test element");
    34   yield selectNode("#testid", inspector);
    36   yield testCreateNew(view);
    37 });
    39 function* testCreateNew(view) {
    40   info("Test creating a new property");
    42   let elementRuleEditor = view.element.children[0]._ruleEditor;
    44   info("Focusing a new property name in the rule-view");
    45   let editor = yield focusEditableField(elementRuleEditor.closeBrace);
    47   is(inplaceEditor(elementRuleEditor.newPropSpan), editor, "The new property editor got focused");
    48   let input = editor.input;
    50   info("Entering background-color in the property name editor");
    51   input.value = "background-color";
    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;
    60   // Getting the new value editor after focus
    61   editor = inplaceEditor(view.doc.activeElement);
    62   let textProp = elementRuleEditor.rule.textProps[0];
    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.");
    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;
    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 }

mercurial