docshell/test/navigation/test_bug386782.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 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=386782
     5 -->
     6 <head>
     7   <title>Test for Bug 386782</title>
     8   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     9   <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    10   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    12   <script>
    14     // This tests if we can load a document whose root is in designMode,
    15     // edit it, navigate to a new page, navigate back, still edit, and still
    16     // undo/redo. Note that this is different from the case where the
    17     // designMode document is in a frame inside the window, as this means
    18     // the editable region is not in the root docshell (a less complicated case).  
    21     var gTests = [
    22       {
    23         // <html><body><p>designModeDocument</p></body></html>
    24         url: "data:text/html;charset=utf-8,<html><body><p>designModeDocument</p></body></html>",
    25         name: 'designModeNavigate',
    26         onload: function(doc) doc.designMode = "on",
    27         expectedBodyBeforeEdit: '<p>designModeDocument</p>',
    28         expectedBodyAfterEdit:  '<p>EDITED designModeDocument</p>',
    29         expectedBodyAfterSecondEdit: '<p>EDITED TWICE designModeDocument</p>',
    30       },
    31       {
    32         // <html><body contentEditable="true"><p>contentEditable</p></body></html>
    33         url: 'data:text/html;charset=utf-8,<html><body contentEditable="true"><p>contentEditable</p></body></html>',
    34         name: 'contentEditableNavigate',
    35         expectedBodyBeforeEdit: '<p>contentEditable</p>',
    36         expectedBodyAfterEdit:  'EDITED <br><p>contentEditable</p>',
    37         expectedBodyAfterSecondEdit: 'EDITED TWICE <br><p>contentEditable</p>',
    38       }
    39     ];
    41     var gTestNum = -1;
    42     var gTest = null;
    44     window.onload = goNext();
    46     function goNext() {
    47       gTestNum++;
    48       if (gTestNum >= gTests.length) {
    49         SimpleTest.finish();
    50         return;
    51       }
    52       gTest = gTests[gTestNum];
    53       gTest.window = window.open(gTest.url, gTest.name, "width=500,height=500");
    54       gTest.window.addEventListener("load", function() {
    55         if ("onload" in gTest) {
    56           gTest.onload(gTest.window.document);
    57         }
    58         SimpleTest.waitForFocus(beginTest, gTest.window);
    59       }, false);
    60     }
    62     function beginTest() {
    63       gTest.window.document.body.focus();
    65       // WARNING: If the following test fails, give the setTimeout() in the onload()
    66       // a bit longer; the doc hasn't had enough time to setup its editor.
    67       is(gTest.window.document.body.innerHTML, gTest.expectedBodyBeforeEdit, "Is doc setup yet");
    68       sendString('EDITED ', gTest.window);
    69       is(gTest.window.document.body.innerHTML, gTest.expectedBodyAfterEdit, "Editing failed.");
    71       gTest.window.location = 'data:text/html;charset=utf-8,SomeOtherDocument';
    72       SimpleTest.waitForFocus(goBack, gTest.window);
    73     }
    75     function goBack() {
    76       gTest.window.history.back();
    77       setTimeout(function() {
    78         SimpleTest.waitForFocus(checkStillEditable, gTest.window);
    79       }, 0);
    80     }
    82     function checkStillEditable() {
    84       // Check that the contents are correct.
    85       is(gTest.window.document.body.innerHTML, gTest.expectedBodyAfterEdit, "Edited contents still correct?");
    87       // Check that we can undo/redo and the contents are correct.
    88       gTest.window.document.execCommand("undo", false, null);
    89       is(gTest.window.document.body.innerHTML, gTest.expectedBodyBeforeEdit, "Can we undo?");
    91       gTest.window.document.execCommand("redo", false, null);
    92       is(gTest.window.document.body.innerHTML, gTest.expectedBodyAfterEdit, "Can we redo?");
    94       // Check that we can still edit the page.
    95       gTest.window.document.body.focus();
    96       sendString('TWICE ', gTest.window);
    97       is(gTest.window.document.body.innerHTML, gTest.expectedBodyAfterSecondEdit, "Can we still edit?");
    99       gTest.window.close();
   100       goNext();
   102     }
   104   </script>
   106 </head>
   107 <body>
   108 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=386782">Mozilla Bug 386782</a>
   109 <p id="display"></p>
   110 <div id="content" style="display: none">
   112 </div>
   113 <pre id="test">
   114 <script class="testbody" type="text/javascript">
   116 /** Test for Bug 386782 **/
   118 SimpleTest.waitForExplicitFinish();
   120 </script>
   121 </pre>
   122 </body>
   123 </html>

mercurial