editor/libeditor/html/tests/test_root_element_replacement.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <html>
     2 <head>
     3   <title>Test for root element replacement</title>
     4   <script type="text/javascript"
     5           src="/tests/SimpleTest/SimpleTest.js"></script>
     6   <script type="text/javascript"
     7           src="/tests/SimpleTest/EventUtils.js"></script>
     8   <link rel="stylesheet" type="text/css"
     9           href="/tests/SimpleTest/test.css" />
    10 </head>
    11 <body>
    12 <p id="display">
    13 </p>
    14 <div id="content" style="display: none">
    16 </div>
    17 <pre id="test">
    18 </pre>
    20 <script class="testbody" type="application/javascript">
    22 SimpleTest.waitForExplicitFinish();
    23 SimpleTest.waitForFocus(runTest);
    25 function runDesignModeTest(aDoc, aFocus, aNewSource)
    26 {
    27   aDoc.designMode = "on";
    29   if (aFocus) {
    30     aDoc.documentElement.focus();
    31   }
    33   aDoc.open();
    34   aDoc.write(aNewSource);
    35   aDoc.close();
    36   aDoc.documentElement.focus();
    37 }
    39 function runContentEditableTest(aDoc, aFocus, aNewSource)
    40 {
    41   if (aFocus) {
    42     aDoc.body.setAttribute("contenteditable", "true");
    43     aDoc.body.focus();
    44   }
    46   aDoc.open();
    47   aDoc.write(aNewSource);
    48   aDoc.close();
    49   aDoc.getElementById("focus").focus();
    50 }
    52 var gTestIndex = 0;
    54 const kTests = [
    55   { description: "Replace to '<body></body>', designMode",
    56     initializer: runDesignModeTest,
    57     args: [ "<body></body>" ] },
    58   { description: "Replace to '<html><body></body></html>', designMode",
    59     initializer: runDesignModeTest,
    60     args: [ "<html><body></body></html>" ] },
    61   { description: "Replace to '<html>&nbsp;<body></body></html>', designMode",
    62     initializer: runDesignModeTest,
    63     args: [ "<html> <body></body></html>" ] },
    64   { description: "Replace to '&nbsp;<html>&nbsp;<body></body></html>', designMode",
    65     initializer: runDesignModeTest,
    66     args: [ " <html> <body></body></html>" ] },
    68   { description: "Replace to '<html contenteditable='true'><body></body></html>",
    69     initializer: runContentEditableTest,
    70     args: [ "<html contenteditable='true' id='focus'><body></body></html>" ] },
    71   { description: "Replace to '<html><body contenteditable='true'></body></html>",
    72     initializer: runContentEditableTest,
    73     args: [ "<html><body contenteditable='true' id='focus'></body></html>" ] },
    74   { description: "Replace to '<body contenteditable='true'></body>",
    75     initializer: runContentEditableTest,
    76     args: [ "<body contenteditable='true' id='focus'></body>" ] },
    77 ];
    79 var gIFrame;
    80 var gSetFocusToIFrame = false;
    82 function onLoadIFrame()
    83 {
    84   var frameDoc = gIFrame.contentWindow.document;
    86   var selCon = SpecialPowers.wrap(gIFrame).contentWindow.
    87     QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor).
    88     getInterface(SpecialPowers.Ci.nsIWebNavigation).
    89     QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor).
    90     getInterface(SpecialPowers.Ci.nsISelectionDisplay).
    91     QueryInterface(SpecialPowers.Ci.nsISelectionController);
    92   var utils = SpecialPowers.getDOMWindowUtils(window);
    93   const nsIDOMNode = SpecialPowers.Ci.nsIDOMNode;
    95   // move focus to the HTML editor
    96   const kTest = kTests[gTestIndex];
    97   ok(true, "Running " + kTest.description);
    98   if (kTest.args.length == 1) {
    99     kTest.initializer(frameDoc, gSetFocusToIFrame, kTest.args[0]);
   100     ok(selCon.caretVisible, "caret isn't visible -- " + kTest.description);
   101   } else {
   102     ok(false, "kTests is broken at index=" + gTestIndex);
   103   }
   105   is(utils.IMEStatus, utils.IME_STATUS_ENABLED,
   106      "IME isn't enabled -- " + kTest.description);
   107   synthesizeKey("A", { }, gIFrame.contentWindow);
   108   synthesizeKey("B", { }, gIFrame.contentWindow);
   109   synthesizeKey("C", { }, gIFrame.contentWindow);
   110   var content = frameDoc.body.firstChild;
   111   ok(content, "body doesn't have contents -- " + kTest.description);
   112   if (content) {
   113     is(content.nodeType, nsIDOMNode.TEXT_NODE,
   114        "the content of body isn't text node -- " + kTest.description);
   115     if (content.nodeType == nsIDOMNode.TEXT_NODE) {
   116       is(content.data, "ABC",
   117          "the content of body text isn't 'ABC' -- " + kTest.description);
   118       is(frameDoc.body.innerHTML, "ABC",
   119          "the innerHTML of body isn't 'ABC' -- " + kTest.description);
   120     }
   121   }
   123   document.getElementById("display").removeChild(gIFrame);
   125   // Do next test or finish the tests.
   126   if (++gTestIndex < kTests.length) {
   127     setTimeout(runTest, 0);
   128   } else if (!gSetFocusToIFrame) {
   129     gSetFocusToIFrame = true;
   130     gTestIndex = 0;
   131     setTimeout(runTest, 0);
   132   } else {
   133     SimpleTest.finish();
   134   }
   135 }
   137 function runTest()
   138 {
   139   gIFrame = document.createElement("iframe");
   140   document.getElementById("display").appendChild(gIFrame);
   141   gIFrame.src = "about:blank";
   142   gIFrame.onload = onLoadIFrame;
   143 }
   145 </script>
   146 </body>
   148 </html>

mercurial