browser/base/content/test/general/browser_bug537013.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 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 /* Tests for bug 537013 to ensure proper tab-sequestration of find bar. */
     6 let tabs = [];
     7 let texts = [
     8   "This side up.",
     9   "The world is coming to an end. Please log off.",
    10   "Klein bottle for sale. Inquire within.",
    11   "To err is human; to forgive is not company policy."
    12 ];
    14 let Clipboard = Cc["@mozilla.org/widget/clipboard;1"].getService(Ci.nsIClipboard);
    15 let HasFindClipboard = Clipboard.supportsFindClipboard();
    17 function addTabWithText(aText, aCallback) {
    18   let newTab = gBrowser.addTab("data:text/html,<h1 id='h1'>" + aText + "</h1>");
    19   tabs.push(newTab);
    20   gBrowser.selectedTab = newTab;
    21 }
    23 function setFindString(aString) {
    24   gFindBar.open();
    25   gFindBar._findField.focus();
    26   gFindBar._findField.select();
    27   EventUtils.sendString(aString);
    28   is(gFindBar._findField.value, aString, "Set the field correctly!");
    29 }
    31 let newWindow;
    33 function test() {
    34   waitForExplicitFinish();
    35   registerCleanupFunction(function () {
    36     while (tabs.length) {
    37       gBrowser.removeTab(tabs.pop());
    38     }
    39   });
    40   texts.forEach(function(aText) addTabWithText(aText));
    42   // Set up the first tab
    43   gBrowser.selectedTab = tabs[0];
    45   setFindString(texts[0]);
    46   // Turn on highlight for testing bug 891638
    47   gFindBar.getElement("highlight").checked = true;
    49   // Make sure the second tab is correct, then set it up
    50   gBrowser.selectedTab = tabs[1];
    51   gBrowser.selectedTab.addEventListener("TabFindInitialized", continueTests1);
    52   // Initialize the findbar
    53   gFindBar;
    54 }
    55 function continueTests1() {
    56   gBrowser.selectedTab.removeEventListener("TabFindInitialized",
    57                                            continueTests1);
    58   ok(true, "'TabFindInitialized' event properly dispatched!");
    59   ok(gFindBar.hidden, "Second tab doesn't show find bar!");
    60   gFindBar.open();
    61   is(gFindBar._findField.value, texts[0],
    62      "Second tab kept old find value for new initialization!");
    63   setFindString(texts[1]);
    65   // Confirm the first tab is still correct, ensure re-hiding works as expected
    66   gBrowser.selectedTab = tabs[0];
    67   ok(!gFindBar.hidden, "First tab shows find bar!");
    68   // When the Find Clipboard is supported, this test not relevant.
    69   if (!HasFindClipboard)
    70     is(gFindBar._findField.value, texts[0], "First tab persists find value!");
    71   ok(gFindBar.getElement("highlight").checked,
    72      "Highlight button state persists!");
    74   // While we're here, let's test bug 253793
    75   gBrowser.reload();
    76   gBrowser.addEventListener("DOMContentLoaded", continueTests2, true);
    77 }
    79 function continueTests2() {
    80   gBrowser.removeEventListener("DOMContentLoaded", continueTests2, true);
    81   ok(!gFindBar.getElement("highlight").checked, "Highlight button reset!");
    82   gFindBar.close();
    83   ok(gFindBar.hidden, "First tab doesn't show find bar!");
    84   gBrowser.selectedTab = tabs[1];
    85   ok(!gFindBar.hidden, "Second tab shows find bar!");
    86   // Test for bug 892384
    87   is(gFindBar._findField.getAttribute("focused"), "true",
    88      "Open findbar refocused on tab change!");
    89   gURLBar.focus();
    90   gBrowser.selectedTab = tabs[0];
    91   ok(gFindBar.hidden, "First tab doesn't show find bar!");
    93   // Set up a third tab, no tests here
    94   gBrowser.selectedTab = tabs[2];
    95   setFindString(texts[2]);
    97   // Now we jump to the second, then first, and then fourth
    98   gBrowser.selectedTab = tabs[1];
    99   // Test for bug 892384
   100   ok(!gFindBar._findField.hasAttribute("focused"),
   101      "Open findbar not refocused on tab change!");
   102   gBrowser.selectedTab = tabs[0];
   103   gBrowser.selectedTab = tabs[3];
   104   ok(gFindBar.hidden, "Fourth tab doesn't show find bar!");
   105   is(gFindBar, gBrowser.getFindBar(), "Find bar is right one!");
   106   gFindBar.open();
   107   // Disabled the following assertion due to intermittent failure on OSX 10.6 Debug.
   108   if (!HasFindClipboard) {
   109     is(gFindBar._findField.value, texts[1],
   110        "Fourth tab has second tab's find value!");
   111   }
   113   newWindow = gBrowser.replaceTabWithWindow(tabs.pop());
   114   whenDelayedStartupFinished(newWindow, checkNewWindow);
   115 }
   117 // Test that findbar gets restored when a tab is moved to a new window.
   118 function checkNewWindow() {
   119   ok(!newWindow.gFindBar.hidden, "New window shows find bar!");
   120   // Disabled the following assertion due to intermittent failure on OSX 10.6 Debug.
   121   if (!HasFindClipboard) {
   122     is(newWindow.gFindBar._findField.value, texts[1],
   123        "New window find bar has correct find value!");
   124   }
   125   ok(!newWindow.gFindBar.getElement("find-next").disabled,
   126      "New window findbar has enabled buttons!");
   127   newWindow.close();
   128   finish();
   129 }

mercurial