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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/styleinspector/test/browser_ruleview_add-property_01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,78 @@
     1.4 +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
     1.5 +/* Any copyright is dedicated to the Public Domain.
     1.6 + http://creativecommons.org/publicdomain/zero/1.0/ */
     1.7 +
     1.8 +"use strict";
     1.9 +
    1.10 +// Testing various inplace-editor behaviors in the rule-view
    1.11 +// FIXME: To be split in several test files, and some of the inplace-editor
    1.12 +// focus/blur/commit/revert stuff should be factored out in head.js
    1.13 +
    1.14 +let TEST_URL = 'url("' + TEST_URL_ROOT + 'doc_test_image.png")';
    1.15 +let PAGE_CONTENT = [
    1.16 +  '<style type="text/css">',
    1.17 +  '  #testid {',
    1.18 +  '    background-color: blue;',
    1.19 +  '  }',
    1.20 +  '  .testclass {',
    1.21 +  '    background-color: green;',
    1.22 +  '  }',
    1.23 +  '</style>',
    1.24 +  '<div id="testid" class="testclass">Styled Node</div>'
    1.25 +].join("\n");
    1.26 +
    1.27 +let test = asyncTest(function*() {
    1.28 +  yield addTab("data:text/html,test rule view user changes");
    1.29 +
    1.30 +  info("Creating the test document");
    1.31 +  content.document.body.innerHTML = PAGE_CONTENT;
    1.32 +
    1.33 +  info("Opening the rule-view");
    1.34 +  let {toolbox, inspector, view} = yield openRuleView();
    1.35 +
    1.36 +  info("Selecting the test element");
    1.37 +  yield selectNode("#testid", inspector);
    1.38 +
    1.39 +  yield testCreateNew(view);
    1.40 +});
    1.41 +
    1.42 +function* testCreateNew(view) {
    1.43 +  info("Test creating a new property");
    1.44 +
    1.45 +  let elementRuleEditor = view.element.children[0]._ruleEditor;
    1.46 +
    1.47 +  info("Focusing a new property name in the rule-view");
    1.48 +  let editor = yield focusEditableField(elementRuleEditor.closeBrace);
    1.49 +
    1.50 +  is(inplaceEditor(elementRuleEditor.newPropSpan), editor, "The new property editor got focused");
    1.51 +  let input = editor.input;
    1.52 +
    1.53 +  info("Entering background-color in the property name editor");
    1.54 +  input.value = "background-color";
    1.55 +
    1.56 +  info("Pressing return to commit and focus the new value field");
    1.57 +  let onValueFocus = once(elementRuleEditor.element, "focus", true);
    1.58 +  let onModifications = elementRuleEditor.rule._applyingModifications;
    1.59 +  EventUtils.synthesizeKey("VK_RETURN", {}, view.doc.defaultView);
    1.60 +  yield onValueFocus;
    1.61 +  yield onModifications;
    1.62 +
    1.63 +  // Getting the new value editor after focus
    1.64 +  editor = inplaceEditor(view.doc.activeElement);
    1.65 +  let textProp = elementRuleEditor.rule.textProps[0];
    1.66 +
    1.67 +  is(elementRuleEditor.rule.textProps.length,  1, "Created a new text property.");
    1.68 +  is(elementRuleEditor.propertyList.children.length, 1, "Created a property editor.");
    1.69 +  is(editor, inplaceEditor(textProp.editor.valueSpan), "Editing the value span now.");
    1.70 +
    1.71 +  info("Entering a value and bluring the field to expect a rule change");
    1.72 +  editor.input.value = "#XYZ";
    1.73 +  let onBlur = once(editor.input, "blur");
    1.74 +  let onModifications = elementRuleEditor.rule._applyingModifications;
    1.75 +  editor.input.blur();
    1.76 +  yield onBlur;
    1.77 +  yield onModifications;
    1.78 +
    1.79 +  is(textProp.value, "#XYZ", "Text prop should have been changed.");
    1.80 +  is(textProp.editor.isValid(), false, "#XYZ should not be a valid entry");
    1.81 +}

mercurial