browser/components/tabview/test/browser_tabview_privatebrowsing_perwindowpb.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 let normalURLs = [];
     5 let pbTabURL = "about:privatebrowsing";
     6 let groupTitles = [];
     7 let normalIteration = 0;
     9 function test() {
    10   waitForExplicitFinish();
    12   testOnWindow(false, function(win) {
    13     showTabView(function() {
    14       onTabViewLoadedAndShown(win);
    15     }, win);
    16   });
    17 }
    19 function testOnWindow(aIsPrivate, aCallback) {
    20   let win = OpenBrowserWindow({private: aIsPrivate});
    21   win.addEventListener("load", function onLoad() {
    22     win.removeEventListener("load", onLoad, false);
    23     executeSoon(function() { aCallback(win); });
    24   }, false);
    25 }
    27 function onTabViewLoadedAndShown(aWindow) {
    28   ok(aWindow.TabView.isVisible(), "Tab View is visible");
    30   // Establish initial state
    31   let contentWindow = aWindow.TabView.getContentWindow();
    32   verifyCleanState(aWindow, "start", contentWindow);
    34   // create a group
    35   let box = new contentWindow.Rect(20, 20, 180, 180);
    36   let groupItem = new contentWindow.GroupItem([], {bounds: box, title: "test1"});
    37   let id = groupItem.id;
    38   is(contentWindow.GroupItems.groupItems.length, 2, "we now have two groups");
    39   registerCleanupFunction(function() {
    40     contentWindow.GroupItems.groupItem(id).close();
    41   });
    43   // make it the active group so new tabs will be added to it
    44   contentWindow.UI.setActive(groupItem);
    46   // collect the group titles
    47   let count = contentWindow.GroupItems.groupItems.length;
    48   for (let a = 0; a < count; a++) {
    49     let gi = contentWindow.GroupItems.groupItems[a];
    50     groupTitles[a] = gi.getTitle();
    51   }
    53   contentWindow.gPrefBranch.setBoolPref("animate_zoom", false);
    55   // Create a second tab
    56   aWindow.gBrowser.addTab("about:mozilla");
    57   is(aWindow.gBrowser.tabs.length, 2, "we now have 2 tabs");
    59   registerCleanupFunction(function() {
    60     aWindow.gBrowser.removeTab(aWindow.gBrowser.tabs[1]);
    61     contentWindow.gPrefBranch.clearUserPref("animate_zoom");
    62   });
    64   afterAllTabsLoaded(function() {
    65     // Get normal tab urls
    66     for (let a = 0; a < aWindow.gBrowser.tabs.length; a++)
    67       normalURLs.push(aWindow.gBrowser.tabs[a].linkedBrowser.currentURI.spec);
    69     // verify that we're all set up for our test
    70     verifyNormal(aWindow);
    72     // Open private window and make sure Tab View becomes hidden
    73     testOnWindow(true, function(privateWin) {
    74       whenTabViewIsHidden(function() {
    75         ok(!privateWin.TabView.isVisible(), "Tab View is no longer visible");
    76         verifyPB(privateWin);
    77         // Close private window
    78         privateWin.close();
    79         // Get back to normal window, make sure Tab View is shown again
    80         whenTabViewIsShown(function() {
    81           ok(aWindow.TabView.isVisible(), "Tab View is visible again");
    82           verifyNormal(aWindow);
    84           hideTabView(function() {
    85             onTabViewHidden(aWindow, contentWindow);
    86           }, aWindow);
    87         }, aWindow);
    88       }, privateWin);
    89     });
    90   }, aWindow);
    91 }
    93 function onTabViewHidden(aWindow, aContentWindow) {
    94   ok(!aWindow.TabView.isVisible(), "Tab View is not visible");
    96   // Open private window and make sure Tab View is hidden
    97   testOnWindow(true, function(privateWin) {
    98     ok(!privateWin.TabView.isVisible(), "Tab View is still not visible");
    99     verifyPB(privateWin);
   100     // Close private window
   101     privateWin.close();
   103     //  Get back to normal window
   104     verifyNormal(aWindow);
   106     // end game
   107     ok(!aWindow.TabView.isVisible(), "we finish with Tab View not visible");
   109     // verify after all cleanups
   110     registerCleanupFunction(function() {
   111       verifyCleanState(aWindow, "finish", aContentWindow);
   112       aWindow.close();
   113     });
   115     finish();
   116   });
   117 }
   119 function verifyCleanState(aWindow, aMode, aContentWindow) {
   120   let prefix = "we " + aMode + " with ";
   121   is(aWindow.gBrowser.tabs.length, 1, prefix + "one tab");
   122   is(aContentWindow.GroupItems.groupItems.length, 1, prefix + "1 group");
   123   ok(aWindow.gBrowser.tabs[0]._tabViewTabItem.parent == aContentWindow.GroupItems.groupItems[0],
   124       "the tab is in the group");
   125   ok(!PrivateBrowsingUtils.isWindowPrivate(aWindow), prefix + "private browsing off");
   126 }
   128 function verifyPB(aWindow) {
   129   showTabView(function() {
   130     let cw = aWindow.TabView.getContentWindow();
   131     ok(PrivateBrowsingUtils.isWindowPrivate(aWindow), "window is private");
   132     is(aWindow.gBrowser.tabs.length, 1, "we have 1 tab in private window");
   133     is(cw.GroupItems.groupItems.length, 1, "we have 1 group in private window");
   134     ok(aWindow.gBrowser.tabs[0]._tabViewTabItem.parent == cw.GroupItems.groupItems[0],
   135         "the tab is in the group");
   136     let browser = aWindow.gBrowser.tabs[0].linkedBrowser;
   137     browser.addEventListener("load", function onLoad() {
   138       browser.removeEventListener("load", onLoad, true);
   139       is(browser.currentURI.spec, pbTabURL, "correct URL for private browsing");
   140     }, true);
   141   }, aWindow);
   142 }
   144 function verifyNormal(aWindow) {
   145   let contentWindow = aWindow.TabView.getContentWindow();
   146   let prefix = "verify normal " + normalIteration + ": ";
   147   normalIteration++;
   149   ok(!PrivateBrowsingUtils.isWindowPrivate(aWindow), prefix + "private browsing off");
   151   let tabCount = aWindow.gBrowser.tabs.length;
   152   let groupCount = contentWindow.GroupItems.groupItems.length;
   153   is(tabCount, 2, prefix + "we have 2 tabs");
   154   is(groupCount, 2, prefix + "we have 2 groups");
   155   ok(tabCount == groupCount, prefix + "same number of tabs as groups");
   156   for (let a = 0; a < tabCount; a++) {
   157     let tab = aWindow.gBrowser.tabs[a];
   158     is(tab.linkedBrowser.currentURI.spec, normalURLs[a],
   159         prefix + "correct URL");
   161     let groupItem = contentWindow.GroupItems.groupItems[a];
   162     is(groupItem.getTitle(), groupTitles[a], prefix + "correct group title");
   164     ok(tab._tabViewTabItem.parent == groupItem,
   165         prefix + "tab " + a + " is in group " + a);
   166   }
   167 }

mercurial