1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 const kTestString = " hello hello \n world\nworld ";
11 { desc: "Urlbar strips newlines and surrounding whitespace",
13 expected: kTestString.replace(/\s*\n\s*/g,'')
16 { desc: "Searchbar replaces newlines with spaces",
17 element: document.getElementById('searchbar'),
18 expected: kTestString.replace('\n',' ','g')
23 // Test for bug 23485 and bug 321000.
24 // Urlbar should strip newlines,
25 // search bar should replace newlines with spaces.
27 waitForExplicitFinish();
29 let cbHelper = Cc["@mozilla.org/widget/clipboardhelper;1"].
30 getService(Ci.nsIClipboardHelper);
32 // Put a multi-line string in the clipboard.
33 // Setting the clipboard value is an async OS operation, so we need to poll
34 // the clipboard for valid data before going on.
35 waitForClipboard(kTestString, function() { cbHelper.copyString(kTestString, document); },
39 function next_test() {
41 test_paste(gTests.shift());
46 function test_paste(aCurrentTest) {
47 var element = aCurrentTest.element;
49 // Register input listener.
52 handleEvent: function(event) {
53 element.removeEventListener(event.type, this, false);
55 is(element.value, this.test.expected, this.test.desc);
57 // Clear the field and go to next test.
59 setTimeout(next_test, 0);
62 element.addEventListener("input", inputListener, false);
66 gBrowser.selectedBrowser.focus();
68 // Focus the element and wait for focus event.
69 info("About to focus " + element.id);
70 element.addEventListener("focus", function() {
71 element.removeEventListener("focus", arguments.callee, false);
72 executeSoon(function() {
73 // Pasting is async because the Accel+V codepath ends up going through
74 // nsDocumentViewer::FireClipboardEvent.
75 info("Pasting into " + element.id);
76 EventUtils.synthesizeKey("v", { accelKey: true });