1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_bug321000.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,80 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +const kTestString = " hello hello \n world\nworld "; 1.11 + 1.12 +var gTests = [ 1.13 + 1.14 + { desc: "Urlbar strips newlines and surrounding whitespace", 1.15 + element: gURLBar, 1.16 + expected: kTestString.replace(/\s*\n\s*/g,'') 1.17 + }, 1.18 + 1.19 + { desc: "Searchbar replaces newlines with spaces", 1.20 + element: document.getElementById('searchbar'), 1.21 + expected: kTestString.replace('\n',' ','g') 1.22 + }, 1.23 + 1.24 +]; 1.25 + 1.26 +// Test for bug 23485 and bug 321000. 1.27 +// Urlbar should strip newlines, 1.28 +// search bar should replace newlines with spaces. 1.29 +function test() { 1.30 + waitForExplicitFinish(); 1.31 + 1.32 + let cbHelper = Cc["@mozilla.org/widget/clipboardhelper;1"]. 1.33 + getService(Ci.nsIClipboardHelper); 1.34 + 1.35 + // Put a multi-line string in the clipboard. 1.36 + // Setting the clipboard value is an async OS operation, so we need to poll 1.37 + // the clipboard for valid data before going on. 1.38 + waitForClipboard(kTestString, function() { cbHelper.copyString(kTestString, document); }, 1.39 + next_test, finish); 1.40 +} 1.41 + 1.42 +function next_test() { 1.43 + if (gTests.length) 1.44 + test_paste(gTests.shift()); 1.45 + else 1.46 + finish(); 1.47 +} 1.48 + 1.49 +function test_paste(aCurrentTest) { 1.50 + var element = aCurrentTest.element; 1.51 + 1.52 + // Register input listener. 1.53 + var inputListener = { 1.54 + test: aCurrentTest, 1.55 + handleEvent: function(event) { 1.56 + element.removeEventListener(event.type, this, false); 1.57 + 1.58 + is(element.value, this.test.expected, this.test.desc); 1.59 + 1.60 + // Clear the field and go to next test. 1.61 + element.value = ""; 1.62 + setTimeout(next_test, 0); 1.63 + } 1.64 + } 1.65 + element.addEventListener("input", inputListener, false); 1.66 + 1.67 + // Focus the window. 1.68 + window.focus(); 1.69 + gBrowser.selectedBrowser.focus(); 1.70 + 1.71 + // Focus the element and wait for focus event. 1.72 + info("About to focus " + element.id); 1.73 + element.addEventListener("focus", function() { 1.74 + element.removeEventListener("focus", arguments.callee, false); 1.75 + executeSoon(function() { 1.76 + // Pasting is async because the Accel+V codepath ends up going through 1.77 + // nsDocumentViewer::FireClipboardEvent. 1.78 + info("Pasting into " + element.id); 1.79 + EventUtils.synthesizeKey("v", { accelKey: true }); 1.80 + }); 1.81 + }, false); 1.82 + element.focus(); 1.83 +}