docshell/test/navigation/test_bug386782.html

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:e7966542ea8a
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" />
11
12 <script>
13
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).
19
20
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 ];
40
41 var gTestNum = -1;
42 var gTest = null;
43
44 window.onload = goNext();
45
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 }
61
62 function beginTest() {
63 gTest.window.document.body.focus();
64
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.");
70
71 gTest.window.location = 'data:text/html;charset=utf-8,SomeOtherDocument';
72 SimpleTest.waitForFocus(goBack, gTest.window);
73 }
74
75 function goBack() {
76 gTest.window.history.back();
77 setTimeout(function() {
78 SimpleTest.waitForFocus(checkStillEditable, gTest.window);
79 }, 0);
80 }
81
82 function checkStillEditable() {
83
84 // Check that the contents are correct.
85 is(gTest.window.document.body.innerHTML, gTest.expectedBodyAfterEdit, "Edited contents still correct?");
86
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?");
90
91 gTest.window.document.execCommand("redo", false, null);
92 is(gTest.window.document.body.innerHTML, gTest.expectedBodyAfterEdit, "Can we redo?");
93
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?");
98
99 gTest.window.close();
100 goNext();
101
102 }
103
104 </script>
105
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">
111
112 </div>
113 <pre id="test">
114 <script class="testbody" type="text/javascript">
115
116 /** Test for Bug 386782 **/
117
118 SimpleTest.waitForExplicitFinish();
119
120 </script>
121 </pre>
122 </body>
123 </html>
124

mercurial