browser/devtools/styleinspector/test/browser_ruleview_edit-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_edit-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 testEditProperty(view, "border-color", "red");
    1.40 +  yield testEditProperty(view, "background-image", TEST_URL);
    1.41 +});
    1.42 +
    1.43 +function* testEditProperty(view, name, value) {
    1.44 +  info("Test editing existing property name/value fields");
    1.45 +
    1.46 +  let idRuleEditor = view.element.children[1]._ruleEditor;
    1.47 +  let propEditor = idRuleEditor.rule.textProps[0].editor;
    1.48 +
    1.49 +  info("Focusing an existing property name in the rule-view");
    1.50 +  let editor = yield focusEditableField(propEditor.nameSpan, 32, 1);
    1.51 +
    1.52 +  is(inplaceEditor(propEditor.nameSpan), editor, "The property name editor got focused");
    1.53 +  let input = editor.input;
    1.54 +
    1.55 +  info("Entering a new property name, including : to commit and focus the value");
    1.56 +  let onValueFocus = once(idRuleEditor.element, "focus", true);
    1.57 +  let onModifications = idRuleEditor.rule._applyingModifications;
    1.58 +  for (let ch of name + ":") {
    1.59 +    EventUtils.sendChar(ch, view.doc.defaultView);
    1.60 +  }
    1.61 +  yield onValueFocus;
    1.62 +  yield onModifications;
    1.63 +
    1.64 +  // Getting the value editor after focus
    1.65 +  editor = inplaceEditor(view.doc.activeElement);
    1.66 +  input = editor.input;
    1.67 +  is(inplaceEditor(propEditor.valueSpan), editor, "Focus moved to the value.");
    1.68 +
    1.69 +  info("Entering a new value, including ; to commit and blur the value");
    1.70 +  let onBlur = once(input, "blur");
    1.71 +  let onModifications = idRuleEditor.rule._applyingModifications;
    1.72 +  for (let ch of value + ";") {
    1.73 +    EventUtils.sendChar(ch, view.doc.defaultView);
    1.74 +  }
    1.75 +  yield onBlur;
    1.76 +  yield onModifications;
    1.77 +
    1.78 +  let propValue = idRuleEditor.rule.domRule._rawStyle().getPropertyValue(name);
    1.79 +  is(propValue, value, name + " should have been set.");
    1.80 +  is(propEditor.isValid(), true, value + " should be a valid entry");
    1.81 +}

mercurial