1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/editor/libeditor/html/tests/test_bug551704.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,125 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=551704 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 551704</title> 1.11 + <script type="application/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 +</head> 1.15 +<body> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=551704">Mozilla Bug 551704</a> 1.17 +<p id="display"></p> 1.18 +<div id="content"> 1.19 + <div id="preformatted" style="white-space: pre" contenteditable>a b</div> 1.20 + <div id="test1" contenteditable><br></div> 1.21 + <div id="test2" contenteditable>a<br></div> 1.22 + <div id="test3" contenteditable style="white-space: pre"><br></div> 1.23 + <div id="test4" contenteditable style="white-space: pre">a<br></div> 1.24 + <div id="test5" contenteditable></div> 1.25 + <div id="test6" contenteditable>a</div> 1.26 + <div id="test7" contenteditable style="white-space: pre"></div> 1.27 + <div id="test8" contenteditable style="white-space: pre">a</div> 1.28 +</div> 1.29 +<pre id="test"> 1.30 +<script type="application/javascript"> 1.31 + 1.32 +function testLineBreak(div, type, expectedText, expectedHTML, callback) 1.33 +{ 1.34 + div.focus(); 1.35 + getSelection().collapse(div, 0); 1.36 + type(); 1.37 + is(div.innerHTML, expectedHTML, "The expected HTML after editing should be correct"); 1.38 + SimpleTest.waitForClipboard(expectedText, 1.39 + function() { 1.40 + getSelection().selectAllChildren(div); 1.41 + synthesizeKey("C", {accelKey: true}); 1.42 + }, 1.43 + function() { 1.44 + var t = document.createElement("textarea"); 1.45 + document.body.appendChild(t); 1.46 + t.focus(); 1.47 + synthesizeKey("V", {accelKey: true}); 1.48 + is(t.value, expectedText, "The expected text should be copied to the clipboard"); 1.49 + callback(); 1.50 + }, 1.51 + function() { 1.52 + SimpleTest.finish(); 1.53 + } 1.54 + ); 1.55 +} 1.56 + 1.57 +function typeABCDEF() { 1.58 + synthesizeKey("a", {}); 1.59 + typeBCDEF_chars(); 1.60 +} 1.61 + 1.62 +function typeBCDEF() { 1.63 + synthesizeKey("VK_RIGHT", {}); 1.64 + typeBCDEF_chars(); 1.65 +} 1.66 + 1.67 +function typeBCDEF_chars() { 1.68 + synthesizeKey("b", {}); 1.69 + synthesizeKey("c", {}); 1.70 + synthesizeKey("VK_RETURN", {}); 1.71 + synthesizeKey("d", {}); 1.72 + synthesizeKey("e", {}); 1.73 + synthesizeKey("f", {}); 1.74 +} 1.75 + 1.76 +/** Test for Bug 551704 **/ 1.77 +SimpleTest.waitForExplicitFinish(); 1.78 +SimpleTest.waitForFocus(function() { 1.79 + var preformatted = document.getElementById("preformatted"); 1.80 + is(preformatted.innerHTML, "a\nb", "No BR node should be injected for preformatted editable fields"); 1.81 + 1.82 + var iframe = document.createElement("iframe"); 1.83 + iframe.addEventListener("load", function() { 1.84 + var sel = iframe.contentWindow.getSelection(); 1.85 + is(sel.rangeCount, 0, "There should be no range in the selection initially"); 1.86 + iframe.contentDocument.designMode = "on"; 1.87 + sel = iframe.contentWindow.getSelection(); 1.88 + is(sel.rangeCount, 1, "There should be a single range in the selection after setting designMode"); 1.89 + var range = sel.getRangeAt(0); 1.90 + ok(range.collapsed, "The range should be collapsed"); 1.91 + is(range.startContainer, iframe.contentDocument.body.firstChild, "The range should start on the text"); 1.92 + is(range.startOffset, 0, "The start offset should be zero"); 1.93 + 1.94 + continueTest(); 1.95 + }, false); 1.96 + iframe.src = "data:text/html,foo"; 1.97 + document.getElementById("content").appendChild(iframe); 1.98 +}); 1.99 + 1.100 +function continueTest() { 1.101 + var divs = []; 1.102 + for (var i = 0; i < 8; ++i) { 1.103 + divs[i] = document.getElementById("test" + (i+1)); 1.104 + } 1.105 + var current = 0; 1.106 + function doNextTest() { 1.107 + if (current == divs.length) { 1.108 + SimpleTest.finish(); 1.109 + return; 1.110 + } 1.111 + var div = divs[current++]; 1.112 + if (div.textContent == "a") { 1.113 + var type = typeBCDEF; 1.114 + } else { 1.115 + var type = typeABCDEF; 1.116 + } 1.117 + var expectedHTML = "abc<br>def<br>"; 1.118 + var expectedText = "abc\ndef"; 1.119 + testLineBreak(div, type, expectedText, expectedHTML, doNextTest); 1.120 + } 1.121 + 1.122 + doNextTest(); 1.123 +} 1.124 + 1.125 +</script> 1.126 +</pre> 1.127 +</body> 1.128 +</html>