docshell/test/navigation/test_bug386782.html

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.

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

mercurial