test_bug386782.html (4643B)
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 src="/tests/SimpleTest/SimpleTest.js"></script> 9 <script 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 var gTests = [ 21 { 22 // <html><body><p>designModeDocument</p></body></html> 23 url: "file_bug386782_designmode.html", 24 name: "designModeNavigate", 25 onload(doc) { doc.designMode = "on"; }, 26 expectedBodyBeforeEdit: "<p>designModeDocument</p>", 27 expectedBodyAfterEdit: "<p>EDITED designModeDocument</p>", 28 expectedBodyAfterSecondEdit: "<p>EDITED TWICE designModeDocument</p>", 29 }, 30 { 31 // <html><body contentEditable="true"><p>contentEditable</p></body></html> 32 url: "file_bug386782_contenteditable.html", 33 name: "contentEditableNavigate", 34 expectedBodyBeforeEdit: "<p>contentEditable</p>", 35 expectedBodyAfterEdit: "EDITED <p>contentEditable</p>", 36 expectedBodyAfterSecondEdit: "EDITED TWICE <p>contentEditable</p>", 37 }, 38 ]; 39 40 var gTest = null; 41 42 add_task(async () => { 43 while (gTests.length) { 44 gTest = gTests.shift(); 45 await runTest(); 46 } 47 }); 48 49 async function runTest() { 50 gTest.window = window.open(gTest.url, gTest.name, "width=500,height=500"); 51 let e = await new Promise(r => window.onmessage = r); 52 is(e.data.persisted, false, "Initial load cannot be persisted"); 53 if ("onload" in gTest) { 54 gTest.onload(gTest.window.document); 55 } 56 await SimpleTest.promiseFocus(gTest.window); 57 58 gTest.window.document.body.focus(); 59 60 // WARNING: If the following test fails, give the setTimeout() in the onload() 61 // a bit longer; the doc hasn't had enough time to setup its editor. 62 is(gTest.window.document.body.innerHTML, gTest.expectedBodyBeforeEdit, "Is doc setup yet"); 63 sendString("EDITED ", gTest.window); 64 is(gTest.window.document.body.innerHTML, gTest.expectedBodyAfterEdit, "Editing failed."); 65 66 gTest.window.location = "about:blank"; 67 await new Promise(r => gTest.window.onpagehide = r); 68 // The active document is updated synchronously after "pagehide" (and 69 // its associated microtasks), so, after waiting for the next global 70 // task, gTest.window will be proxying the realm associated with the 71 // "about:blank" document. 72 // https://html.spec.whatwg.org/multipage/browsing-the-web.html#update-the-session-history-with-the-new-page 73 await new Promise(r => setTimeout(r)); 74 is(gTest.window.location.href, "about:blank", "location.href"); 75 await SimpleTest.promiseFocus(gTest.window, true); 76 77 gTest.window.history.back(); 78 e = await new Promise(r => window.onmessage = r); 79 // Skip the test if the page is not loaded from the bf-cache when going back. 80 if (e.data.persisted) { 81 checkStillEditable(); 82 } 83 gTest.window.close(); 84 } 85 86 function checkStillEditable() { 87 // Check that the contents are correct. 88 is(gTest.window.document.body.innerHTML, gTest.expectedBodyAfterEdit, "Edited contents still correct?"); 89 90 // Check that we can undo/redo and the contents are correct. 91 gTest.window.document.execCommand("undo", false, null); 92 is(gTest.window.document.body.innerHTML, gTest.expectedBodyBeforeEdit, "Can we undo?"); 93 94 gTest.window.document.execCommand("redo", false, null); 95 is(gTest.window.document.body.innerHTML, gTest.expectedBodyAfterEdit, "Can we redo?"); 96 97 // Check that we can still edit the page. 98 gTest.window.document.body.focus(); 99 sendString("TWICE ", gTest.window); 100 is(gTest.window.document.body.innerHTML, gTest.expectedBodyAfterSecondEdit, "Can we still edit?"); 101 } 102 103 </script> 104 105 </head> 106 <body> 107 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=386782">Mozilla Bug 386782</a> 108 <p id="display"></p> 109 <div id="content" style="display: none"> 110 111 </div> 112 <pre id="test"> 113 <script class="testbody" type="text/javascript"> 114 115 /** Test for Bug 386782 */ 116 117 SimpleTest.waitForExplicitFinish(); 118 119 </script> 120 </pre> 121 </body> 122 </html>