browser/devtools/styleinspector/test/browser_styleinspector_inplace-editor.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 the inplace-editor behavior.
     8 // This test doesn't open the devtools, it just exercises the inplace-editor
     9 // on test elements in the page
    11 let test = asyncTest(function*() {
    12   yield addTab("data:text/html,inline editor tests");
    13   yield testReturnCommit();
    14   yield testBlurCommit();
    15   yield testAdvanceCharCommit();
    16 });
    18 function testReturnCommit() {
    19   info("Testing that pressing return commits the new value");
    20   let def = promise.defer();
    22   createInplaceEditorAndClick({
    23     initial: "explicit initial",
    24     start: function(editor) {
    25       is(editor.input.value, "explicit initial", "Explicit initial value should be used.");
    26       editor.input.value = "Test Value";
    27       EventUtils.sendKey("return");
    28     },
    29     done: onDone("Test Value", true, def)
    30   });
    32   return def.promise;
    33 }
    35 function testBlurCommit() {
    36   info("Testing that bluring the field commits the new value");
    37   let def = promise.defer();
    39   createInplaceEditorAndClick({
    40     start: function(editor) {
    41       is(editor.input.value, "Edit Me!", "textContent of the span used.");
    42       editor.input.value = "Test Value";
    43       editor.input.blur();
    44     },
    45     done: onDone("Test Value", true, def)
    46   });
    48   return def.promise;
    49 }
    51 function testAdvanceCharCommit() {
    52   info("Testing that configured advanceChars commit the new value");
    53   let def = promise.defer();
    55   createInplaceEditorAndClick({
    56     advanceChars: ":",
    57     start: function(editor) {
    58       let input = editor.input;
    59       for each (let ch in "Test:") {
    60         EventUtils.sendChar(ch);
    61       }
    62     },
    63     done: onDone("Test", true, def)
    64   });
    66   return def.promise;
    67 }
    69 function testEscapeCancel() {
    70   info("Testing that escape cancels the new value");
    71   let def = promise.defer();
    73   createInplaceEditorAndClick({
    74     initial: "initial text",
    75     start: function(editor) {
    76       editor.input.value = "Test Value";
    77       EventUtils.sendKey("escape");
    78     },
    79     done: onDone("initial text", false, def)
    80   });
    82   return def.promise;
    83 }
    85 function onDone(value, isCommit, def) {
    86   return function(actualValue, actualCommit) {
    87     info("Inplace-editor's done callback executed, checking its state");
    88     is(actualValue, value, "The value is correct");
    89     is(actualCommit, isCommit, "The commit boolean is correct");
    90     def.resolve();
    91   }
    92 }
    94 function createInplaceEditorAndClick(options) {
    95   clearBody();
    96   let span = options.element = createSpan();
    98   info("Creating an inplace-editor field");
    99   editableField(options);
   101   info("Clicking on the inplace-editor field to turn to edit mode");
   102   span.click();
   103 }
   105 function clearBody() {
   106   info("Clearing the page body");
   107   content.document.body.innerHTML = "";
   108 }
   110 function createSpan() {
   111   info("Creating a new span element");
   112   let span = content.document.createElement("span");
   113   span.setAttribute("tabindex", "0");
   114   span.textContent = "Edit Me!";
   115   content.document.body.appendChild(span);
   116   return span;
   117 }

mercurial