browser/components/tabview/test/browser_tabview_bug624265_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 function test() {
     5   let tests = [];
     7   let getContentWindow = function (aWindow) {
     8     return aWindow.TabView.getContentWindow();
     9   }
    11   let assertOneSingleGroupItem = function (aWindow) {
    12     is(getContentWindow(aWindow).GroupItems.groupItems.length, 1, 'There is one single groupItem');
    13   }
    15   let assertNumberOfVisibleTabs = function (aWindow, numTabs) {
    16     is(aWindow.gBrowser.visibleTabs.length, numTabs, 'There should be ' + numTabs + ' visible tabs');
    17   }
    19   let next = function (aWindow) {
    20     while (aWindow.gBrowser.tabs.length-1)
    21       aWindow.gBrowser.removeTab(aWindow.gBrowser.tabs[1]);
    23     hideTabView(function() {
    24       let callback = tests.shift();
    26       if (!callback) {
    27         executeSoon(function() {
    28           assertOneSingleGroupItem(aWindow);
    29           aWindow.close();
    30           finish();
    31         });
    32       } else {
    33         assertOneSingleGroupItem(aWindow);
    34         callback(aWindow);
    35       }
    36     }, aWindow);
    37   }
    39   // [624265] testing undo close tab
    40   let testUndoCloseTabs = function (aWindow) {
    41     aWindow.gBrowser.loadOneTab('http://mochi.test:8888/', {inBackground: true});
    42     aWindow.gBrowser.loadOneTab('http://mochi.test:8888/', {inBackground: true});
    44     afterAllTabsLoaded(function () {
    45       assertNumberOfVisibleTabs(aWindow, 3);
    47       aWindow.gBrowser.removeTab(aWindow.gBrowser.tabs[1]);
    48       aWindow.gBrowser.selectedTab = aWindow.gBrowser.tabs[1];
    50       restoreTab(function () {
    51         assertNumberOfVisibleTabs(aWindow, 3);
    52         assertOneSingleGroupItem(aWindow);
    53         next(aWindow);
    54       }, 0, aWindow);
    55     }, aWindow);
    56   }
    58   // [623792] duplicating tab via middle click on reload button
    59   let testDuplicateTab = function (aWindow) {
    60     aWindow.gBrowser.loadOneTab('http://mochi.test:8888/', {inBackground: true});
    62     afterAllTabsLoaded(function () {
    63       // Valid choices for 'where' are window|tabshifted|tab
    64       aWindow.duplicateTabIn(aWindow.gBrowser.selectedTab, 'tab');
    66       afterAllTabsLoaded(function () {
    67         assertNumberOfVisibleTabs(aWindow, 3);
    68         assertOneSingleGroupItem(aWindow);
    69         next(aWindow);
    70       }, aWindow);
    71     }, aWindow);
    72   }
    74   // [623792] duplicating tabs via middle click on forward/back buttons
    75   let testBackForwardDuplicateTab = function (aWindow) {
    76     let tab = aWindow.gBrowser.loadOneTab('http://mochi.test:8888/#1', {inBackground: true});
    77     aWindow.gBrowser.selectedTab = tab;
    79     afterAllTabsLoaded(function () {
    80       tab.linkedBrowser.loadURI('http://mochi.test:8888/#2');
    82       afterAllTabsLoaded(function () {
    83         ok(aWindow.gBrowser.canGoBack, 'browser can go back in history');
    84         aWindow.BrowserBack({button: 1});
    86         afterAllTabsLoaded(function () {
    87           assertNumberOfVisibleTabs(aWindow, 3);
    89           ok(aWindow.gBrowser.canGoForward, 'browser can go forward in history');
    90           aWindow.BrowserForward({button: 1});
    92           afterAllTabsLoaded(function () {
    93             assertNumberOfVisibleTabs(aWindow, 4);
    94             assertOneSingleGroupItem(aWindow);
    95             next(aWindow);
    96           }, aWindow);
    97         }, aWindow);
    98       }, aWindow);
    99     }, aWindow);
   100   }
   102   // [624102] check state after return from private browsing
   103   let testPrivateBrowsing = function (aWindow) {
   104     aWindow.gBrowser.loadOneTab('http://mochi.test:8888/#1', {inBackground: true});
   105     aWindow.gBrowser.loadOneTab('http://mochi.test:8888/#2', {inBackground: true});
   107     let cw = getContentWindow(aWindow);
   108     let box = new cw.Rect(20, 20, 250, 200);
   109     let groupItem = new cw.GroupItem([], {bounds: box, immediately: true});
   110     cw.UI.setActive(groupItem);
   112     aWindow.gBrowser.selectedTab = aWindow.gBrowser.loadOneTab('http://mochi.test:8888/#3', {inBackground: true});
   113     aWindow.gBrowser.loadOneTab('http://mochi.test:8888/#4', {inBackground: true});
   115     afterAllTabsLoaded(function () {
   116       assertNumberOfVisibleTabs(aWindow, 2);
   118       enterAndLeavePrivateBrowsing(function () {
   119         assertNumberOfVisibleTabs(aWindow, 2);
   120         aWindow.gBrowser.selectedTab = aWindow.gBrowser.tabs[0];
   121         closeGroupItem(cw.GroupItems.groupItems[1], function() {
   122           next(aWindow);
   123         });
   124       });
   125     }, aWindow);
   126   }
   128   function testOnWindow(aIsPrivate, aCallback) {
   129     let win = OpenBrowserWindow({private: aIsPrivate});
   130     win.addEventListener("load", function onLoad() {
   131       win.removeEventListener("load", onLoad, false);
   132       executeSoon(function() { aCallback(win) });
   133     }, false);
   134   }
   136   function enterAndLeavePrivateBrowsing(callback) {
   137     testOnWindow(true, function (aWindow) {
   138       aWindow.close();
   139       callback();
   140     });
   141   }
   143   waitForExplicitFinish();
   145   // Tests for #624265
   146   tests.push(testUndoCloseTabs);
   148   // Tests for #623792
   149   tests.push(testDuplicateTab);
   150   tests.push(testBackForwardDuplicateTab);
   152   // Tests for #624102
   153   tests.push(testPrivateBrowsing);
   155   testOnWindow(false, function(aWindow) {
   156     loadTabView(function() {
   157       next(aWindow);
   158     }, aWindow);
   159   });
   160 }
   162 function loadTabView(callback, aWindow) {
   163   showTabView(function () {
   164     hideTabView(callback, aWindow);
   165   }, aWindow);
   166 }

mercurial