browser/devtools/styleinspector/test/browser_ruleview_livepreview.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_livepreview.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,66 @@
     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 +// Test that changes are previewed when editing a property value
    1.11 +
    1.12 +// Format
    1.13 +// {
    1.14 +//   value : what to type in the field
    1.15 +//   expected : expected computed style on the targeted element
    1.16 +// }
    1.17 +const TEST_DATA = [
    1.18 +  {value: "inline", expected: "inline"},
    1.19 +  {value: "inline-block", expected: "inline-block"},
    1.20 +
    1.21 +  // Invalid property values should not apply, and should fall back to default
    1.22 +  {value: "red", expected: "block"},
    1.23 +  {value: "something", expected: "block"},
    1.24 +
    1.25 +  {escape: true, value: "inline", expected: "block"}
    1.26 +];
    1.27 +
    1.28 +let test = asyncTest(function*() {
    1.29 +  yield addTab("data:text/html,test rule view live preview on user changes");
    1.30 +
    1.31 +  let style = '#testid {display:block;}';
    1.32 +  let styleNode = addStyle(content.document, style);
    1.33 +  content.document.body.innerHTML = '<div id="testid">Styled Node</div><span>inline element</span>';
    1.34 +  let testElement = getNode("#testid");
    1.35 +
    1.36 +  let {toolbox, inspector, view} = yield openRuleView();
    1.37 +  yield selectNode(testElement, inspector);
    1.38 +
    1.39 +  for (let data of TEST_DATA) {
    1.40 +    yield testLivePreviewData(data, view, testElement);
    1.41 +  }
    1.42 +});
    1.43 +
    1.44 +
    1.45 +function* testLivePreviewData(data, ruleView, testElement) {
    1.46 +  let idRuleEditor = ruleView.element.children[1]._ruleEditor;
    1.47 +  let propEditor = idRuleEditor.rule.textProps[0].editor;
    1.48 +
    1.49 +  info("Focusing the property value inplace-editor");
    1.50 +  let editor = yield focusEditableField(propEditor.valueSpan);
    1.51 +  is(inplaceEditor(propEditor.valueSpan), editor, "The focused editor is the value");
    1.52 +
    1.53 +  info("Enter a value in the editor")
    1.54 +  for (let ch of data.value) {
    1.55 +    EventUtils.sendChar(ch, ruleView.doc.defaultView);
    1.56 +  }
    1.57 +  if (data.escape) {
    1.58 +    EventUtils.synthesizeKey("VK_ESCAPE", {});
    1.59 +  } else {
    1.60 +    EventUtils.synthesizeKey("VK_RETURN", {});
    1.61 +  }
    1.62 +
    1.63 +  yield wait(1);
    1.64 +
    1.65 +  // While the editor is still focused in, the display should have changed already
    1.66 +  is(content.getComputedStyle(testElement).display,
    1.67 +    data.expected,
    1.68 +    "Element should be previewed as " + data.expected);
    1.69 +}

mercurial