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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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  ";
     9 var gTests = [
    11   { desc: "Urlbar strips newlines and surrounding whitespace",
    12     element: gURLBar,
    13     expected: kTestString.replace(/\s*\n\s*/g,'')
    14   },
    16   { desc: "Searchbar replaces newlines with spaces",
    17     element: document.getElementById('searchbar'),
    18     expected: kTestString.replace('\n',' ','g')
    19   },
    21 ];
    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();
    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); },
    36                    next_test, finish);
    37 }
    39 function next_test() {
    40   if (gTests.length)
    41     test_paste(gTests.shift());
    42   else
    43     finish();
    44 }
    46 function test_paste(aCurrentTest) {
    47   var element = aCurrentTest.element;
    49   // Register input listener.
    50   var inputListener = {
    51     test: aCurrentTest,
    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.
    58       element.value = "";
    59       setTimeout(next_test, 0);
    60     }
    61   }
    62   element.addEventListener("input", inputListener, false);
    64   // Focus the window.
    65   window.focus();
    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 });
    77     });
    78   }, false);
    79   element.focus();
    80 }

mercurial