1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/content/tests/chrome/test_bug253481.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,90 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.6 +<?xml-stylesheet 1.7 + href="chrome://mochikit/content/tests/SimpleTest/test.css" 1.8 + type="text/css"?> 1.9 +<!-- 1.10 +https://bugzilla.mozilla.org/show_bug.cgi?id=253481 1.11 +--> 1.12 +<window title="Mozilla Bug 253481" 1.13 + xmlns:html="http://www.w3.org/1999/xhtml" 1.14 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.15 + 1.16 + <script type="application/javascript" 1.17 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.18 + <script type="application/javascript" 1.19 + src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 1.20 + 1.21 +<body xmlns="http://www.w3.org/1999/xhtml"> 1.22 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=253481">Mozilla Bug 253481</a> 1.23 +<p id="display"></p> 1.24 +<div id="content" style="display: none"> 1.25 + 1.26 +</div> 1.27 +</body> 1.28 + 1.29 +<description> 1.30 + Tests pasting of multi-line content into a single-line xul:textbox. 1.31 +</description> 1.32 + 1.33 +<vbox> 1.34 +<textbox id="pasteintact" newlines="pasteintact"/> 1.35 +<textbox id="pastetofirst" newlines="pastetofirst"/> 1.36 +<textbox id="replacewithspaces" newlines="replacewithspaces"/> 1.37 +<textbox id="strip" newlines="strip"/> 1.38 +<textbox id="replacewithcommas" newlines="replacewithcommas"/> 1.39 +<textbox id="stripsurroundingwhitespace" newlines="stripsurroundingwhitespace"/> 1.40 +</vbox> 1.41 +<script class="testbody" type="application/javascript;version=1.7"> 1.42 +<![CDATA[ 1.43 +/** Test for Bug 253481 **/ 1.44 +function testPaste(name, element, expected) { 1.45 + element.value = ""; 1.46 + element.focus(); 1.47 + synthesizeKey("v", { accelKey: true }); 1.48 + is(element.value, expected, name); 1.49 +} 1.50 + 1.51 +SimpleTest.waitForExplicitFinish(); 1.52 + 1.53 +SimpleTest.waitForFocus(function() { 1.54 +setTimeout(function() { 1.55 +var testString = "\n hello hello \n world\nworld \n"; 1.56 +var expectedResults = { 1.57 +// even "pasteintact" strips leading/trailing newlines 1.58 +"pasteintact": testString.replace(/^\n/, '').replace(/\n$/, ''), 1.59 +// "pastetofirst" strips leading newlines 1.60 +"pastetofirst": testString.replace(/^\n/, '').split(/\n/)[0], 1.61 +// "replacewithspaces" strips trailing newlines first - bug 432415 1.62 +"replacewithspaces": testString.replace(/\n$/, '').replace(/\n/g,' '), 1.63 +// "strip" is pretty straightforward 1.64 +"strip": testString.replace(/\n/g,''), 1.65 +// "replacewithcommas" strips leading and trailing newlines first 1.66 +"replacewithcommas": testString.replace(/^\n/, '').replace(/\n$/, '').replace(/\n/g,','), 1.67 +// "stripsurroundingwhitespace" strips all newlines and whitespace around them 1.68 +"stripsurroundingwhitespace": testString.replace(/\s*\n\s*/g,'') 1.69 +}; 1.70 + 1.71 +// Put a multi-line string in the clipboard 1.72 +SimpleTest.waitForClipboard(testString, function() { 1.73 + var clip = Components.classes["@mozilla.org/widget/clipboardhelper;1"] 1.74 + .getService(Components.interfaces.nsIClipboardHelper); 1.75 + clip.copyString(testString, document); 1.76 +}, function() { 1.77 + for (let [item, expected] in Iterator(expectedResults)) { 1.78 + testPaste(item, $(item), expected); 1.79 + } 1.80 + 1.81 + SimpleTest.finish(); 1.82 +}, function() { 1.83 + ok(false, "Could not copy the string to clipboard, giving up"); 1.84 + 1.85 + SimpleTest.finish(); 1.86 +}); 1.87 +}, 0); 1.88 +}); 1.89 + 1.90 +]]> 1.91 +</script> 1.92 + 1.93 +</window>