browser/devtools/styleinspector/test/browser_ruleview_livepreview.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 // Test that changes are previewed when editing a property value
     9 // Format
    10 // {
    11 //   value : what to type in the field
    12 //   expected : expected computed style on the targeted element
    13 // }
    14 const TEST_DATA = [
    15   {value: "inline", expected: "inline"},
    16   {value: "inline-block", expected: "inline-block"},
    18   // Invalid property values should not apply, and should fall back to default
    19   {value: "red", expected: "block"},
    20   {value: "something", expected: "block"},
    22   {escape: true, value: "inline", expected: "block"}
    23 ];
    25 let test = asyncTest(function*() {
    26   yield addTab("data:text/html,test rule view live preview on user changes");
    28   let style = '#testid {display:block;}';
    29   let styleNode = addStyle(content.document, style);
    30   content.document.body.innerHTML = '<div id="testid">Styled Node</div><span>inline element</span>';
    31   let testElement = getNode("#testid");
    33   let {toolbox, inspector, view} = yield openRuleView();
    34   yield selectNode(testElement, inspector);
    36   for (let data of TEST_DATA) {
    37     yield testLivePreviewData(data, view, testElement);
    38   }
    39 });
    42 function* testLivePreviewData(data, ruleView, testElement) {
    43   let idRuleEditor = ruleView.element.children[1]._ruleEditor;
    44   let propEditor = idRuleEditor.rule.textProps[0].editor;
    46   info("Focusing the property value inplace-editor");
    47   let editor = yield focusEditableField(propEditor.valueSpan);
    48   is(inplaceEditor(propEditor.valueSpan), editor, "The focused editor is the value");
    50   info("Enter a value in the editor")
    51   for (let ch of data.value) {
    52     EventUtils.sendChar(ch, ruleView.doc.defaultView);
    53   }
    54   if (data.escape) {
    55     EventUtils.synthesizeKey("VK_ESCAPE", {});
    56   } else {
    57     EventUtils.synthesizeKey("VK_RETURN", {});
    58   }
    60   yield wait(1);
    62   // While the editor is still focused in, the display should have changed already
    63   is(content.getComputedStyle(testElement).display,
    64     data.expected,
    65     "Element should be previewed as " + data.expected);
    66 }

mercurial