browser/base/content/test/general/browser_bug321000.js

branch
TOR_BUG_3246
changeset 6
8bccb770b82d
equal deleted inserted replaced
-1:000000000000 0:75d1f0aca0a1
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/. */
6
7 const kTestString = " hello hello \n world\nworld ";
8
9 var gTests = [
10
11 { desc: "Urlbar strips newlines and surrounding whitespace",
12 element: gURLBar,
13 expected: kTestString.replace(/\s*\n\s*/g,'')
14 },
15
16 { desc: "Searchbar replaces newlines with spaces",
17 element: document.getElementById('searchbar'),
18 expected: kTestString.replace('\n',' ','g')
19 },
20
21 ];
22
23 // Test for bug 23485 and bug 321000.
24 // Urlbar should strip newlines,
25 // search bar should replace newlines with spaces.
26 function test() {
27 waitForExplicitFinish();
28
29 let cbHelper = Cc["@mozilla.org/widget/clipboardhelper;1"].
30 getService(Ci.nsIClipboardHelper);
31
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); },
36 next_test, finish);
37 }
38
39 function next_test() {
40 if (gTests.length)
41 test_paste(gTests.shift());
42 else
43 finish();
44 }
45
46 function test_paste(aCurrentTest) {
47 var element = aCurrentTest.element;
48
49 // Register input listener.
50 var inputListener = {
51 test: aCurrentTest,
52 handleEvent: function(event) {
53 element.removeEventListener(event.type, this, false);
54
55 is(element.value, this.test.expected, this.test.desc);
56
57 // Clear the field and go to next test.
58 element.value = "";
59 setTimeout(next_test, 0);
60 }
61 }
62 element.addEventListener("input", inputListener, false);
63
64 // Focus the window.
65 window.focus();
66 gBrowser.selectedBrowser.focus();
67
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 });
77 });
78 }, false);
79 element.focus();
80 }

mercurial