Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | const kTestString = " hello hello \n world\nworld "; |
michael@0 | 8 | |
michael@0 | 9 | var gTests = [ |
michael@0 | 10 | |
michael@0 | 11 | { desc: "Urlbar strips newlines and surrounding whitespace", |
michael@0 | 12 | element: gURLBar, |
michael@0 | 13 | expected: kTestString.replace(/\s*\n\s*/g,'') |
michael@0 | 14 | }, |
michael@0 | 15 | |
michael@0 | 16 | { desc: "Searchbar replaces newlines with spaces", |
michael@0 | 17 | element: document.getElementById('searchbar'), |
michael@0 | 18 | expected: kTestString.replace('\n',' ','g') |
michael@0 | 19 | }, |
michael@0 | 20 | |
michael@0 | 21 | ]; |
michael@0 | 22 | |
michael@0 | 23 | // Test for bug 23485 and bug 321000. |
michael@0 | 24 | // Urlbar should strip newlines, |
michael@0 | 25 | // search bar should replace newlines with spaces. |
michael@0 | 26 | function test() { |
michael@0 | 27 | waitForExplicitFinish(); |
michael@0 | 28 | |
michael@0 | 29 | let cbHelper = Cc["@mozilla.org/widget/clipboardhelper;1"]. |
michael@0 | 30 | getService(Ci.nsIClipboardHelper); |
michael@0 | 31 | |
michael@0 | 32 | // Put a multi-line string in the clipboard. |
michael@0 | 33 | // Setting the clipboard value is an async OS operation, so we need to poll |
michael@0 | 34 | // the clipboard for valid data before going on. |
michael@0 | 35 | waitForClipboard(kTestString, function() { cbHelper.copyString(kTestString, document); }, |
michael@0 | 36 | next_test, finish); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | function next_test() { |
michael@0 | 40 | if (gTests.length) |
michael@0 | 41 | test_paste(gTests.shift()); |
michael@0 | 42 | else |
michael@0 | 43 | finish(); |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | function test_paste(aCurrentTest) { |
michael@0 | 47 | var element = aCurrentTest.element; |
michael@0 | 48 | |
michael@0 | 49 | // Register input listener. |
michael@0 | 50 | var inputListener = { |
michael@0 | 51 | test: aCurrentTest, |
michael@0 | 52 | handleEvent: function(event) { |
michael@0 | 53 | element.removeEventListener(event.type, this, false); |
michael@0 | 54 | |
michael@0 | 55 | is(element.value, this.test.expected, this.test.desc); |
michael@0 | 56 | |
michael@0 | 57 | // Clear the field and go to next test. |
michael@0 | 58 | element.value = ""; |
michael@0 | 59 | setTimeout(next_test, 0); |
michael@0 | 60 | } |
michael@0 | 61 | } |
michael@0 | 62 | element.addEventListener("input", inputListener, false); |
michael@0 | 63 | |
michael@0 | 64 | // Focus the window. |
michael@0 | 65 | window.focus(); |
michael@0 | 66 | gBrowser.selectedBrowser.focus(); |
michael@0 | 67 | |
michael@0 | 68 | // Focus the element and wait for focus event. |
michael@0 | 69 | info("About to focus " + element.id); |
michael@0 | 70 | element.addEventListener("focus", function() { |
michael@0 | 71 | element.removeEventListener("focus", arguments.callee, false); |
michael@0 | 72 | executeSoon(function() { |
michael@0 | 73 | // Pasting is async because the Accel+V codepath ends up going through |
michael@0 | 74 | // nsDocumentViewer::FireClipboardEvent. |
michael@0 | 75 | info("Pasting into " + element.id); |
michael@0 | 76 | EventUtils.synthesizeKey("v", { accelKey: true }); |
michael@0 | 77 | }); |
michael@0 | 78 | }, false); |
michael@0 | 79 | element.focus(); |
michael@0 | 80 | } |