1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/docshell/test/navigation/test_bug386782.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,124 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=386782 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 386782</title> 1.11 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.14 + 1.15 + <script> 1.16 + 1.17 + // This tests if we can load a document whose root is in designMode, 1.18 + // edit it, navigate to a new page, navigate back, still edit, and still 1.19 + // undo/redo. Note that this is different from the case where the 1.20 + // designMode document is in a frame inside the window, as this means 1.21 + // the editable region is not in the root docshell (a less complicated case). 1.22 + 1.23 + 1.24 + var gTests = [ 1.25 + { 1.26 + // <html><body><p>designModeDocument</p></body></html> 1.27 + url: "data:text/html;charset=utf-8,<html><body><p>designModeDocument</p></body></html>", 1.28 + name: 'designModeNavigate', 1.29 + onload: function(doc) doc.designMode = "on", 1.30 + expectedBodyBeforeEdit: '<p>designModeDocument</p>', 1.31 + expectedBodyAfterEdit: '<p>EDITED designModeDocument</p>', 1.32 + expectedBodyAfterSecondEdit: '<p>EDITED TWICE designModeDocument</p>', 1.33 + }, 1.34 + { 1.35 + // <html><body contentEditable="true"><p>contentEditable</p></body></html> 1.36 + url: 'data:text/html;charset=utf-8,<html><body contentEditable="true"><p>contentEditable</p></body></html>', 1.37 + name: 'contentEditableNavigate', 1.38 + expectedBodyBeforeEdit: '<p>contentEditable</p>', 1.39 + expectedBodyAfterEdit: 'EDITED <br><p>contentEditable</p>', 1.40 + expectedBodyAfterSecondEdit: 'EDITED TWICE <br><p>contentEditable</p>', 1.41 + } 1.42 + ]; 1.43 + 1.44 + var gTestNum = -1; 1.45 + var gTest = null; 1.46 + 1.47 + window.onload = goNext(); 1.48 + 1.49 + function goNext() { 1.50 + gTestNum++; 1.51 + if (gTestNum >= gTests.length) { 1.52 + SimpleTest.finish(); 1.53 + return; 1.54 + } 1.55 + gTest = gTests[gTestNum]; 1.56 + gTest.window = window.open(gTest.url, gTest.name, "width=500,height=500"); 1.57 + gTest.window.addEventListener("load", function() { 1.58 + if ("onload" in gTest) { 1.59 + gTest.onload(gTest.window.document); 1.60 + } 1.61 + SimpleTest.waitForFocus(beginTest, gTest.window); 1.62 + }, false); 1.63 + } 1.64 + 1.65 + function beginTest() { 1.66 + gTest.window.document.body.focus(); 1.67 + 1.68 + // WARNING: If the following test fails, give the setTimeout() in the onload() 1.69 + // a bit longer; the doc hasn't had enough time to setup its editor. 1.70 + is(gTest.window.document.body.innerHTML, gTest.expectedBodyBeforeEdit, "Is doc setup yet"); 1.71 + sendString('EDITED ', gTest.window); 1.72 + is(gTest.window.document.body.innerHTML, gTest.expectedBodyAfterEdit, "Editing failed."); 1.73 + 1.74 + gTest.window.location = 'data:text/html;charset=utf-8,SomeOtherDocument'; 1.75 + SimpleTest.waitForFocus(goBack, gTest.window); 1.76 + } 1.77 + 1.78 + function goBack() { 1.79 + gTest.window.history.back(); 1.80 + setTimeout(function() { 1.81 + SimpleTest.waitForFocus(checkStillEditable, gTest.window); 1.82 + }, 0); 1.83 + } 1.84 + 1.85 + function checkStillEditable() { 1.86 + 1.87 + // Check that the contents are correct. 1.88 + is(gTest.window.document.body.innerHTML, gTest.expectedBodyAfterEdit, "Edited contents still correct?"); 1.89 + 1.90 + // Check that we can undo/redo and the contents are correct. 1.91 + gTest.window.document.execCommand("undo", false, null); 1.92 + is(gTest.window.document.body.innerHTML, gTest.expectedBodyBeforeEdit, "Can we undo?"); 1.93 + 1.94 + gTest.window.document.execCommand("redo", false, null); 1.95 + is(gTest.window.document.body.innerHTML, gTest.expectedBodyAfterEdit, "Can we redo?"); 1.96 + 1.97 + // Check that we can still edit the page. 1.98 + gTest.window.document.body.focus(); 1.99 + sendString('TWICE ', gTest.window); 1.100 + is(gTest.window.document.body.innerHTML, gTest.expectedBodyAfterSecondEdit, "Can we still edit?"); 1.101 + 1.102 + gTest.window.close(); 1.103 + goNext(); 1.104 + 1.105 + } 1.106 + 1.107 + </script> 1.108 + 1.109 +</head> 1.110 +<body> 1.111 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=386782">Mozilla Bug 386782</a> 1.112 +<p id="display"></p> 1.113 +<div id="content" style="display: none"> 1.114 + 1.115 +</div> 1.116 +<pre id="test"> 1.117 +<script class="testbody" type="text/javascript"> 1.118 + 1.119 +/** Test for Bug 386782 **/ 1.120 + 1.121 +SimpleTest.waitForExplicitFinish(); 1.122 + 1.123 +</script> 1.124 +</pre> 1.125 +</body> 1.126 +</html> 1.127 +