browser/components/tabview/test/browser_tabview_pending_tabs.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 "use strict";
     6 const STATE = {
     7   windows: [{
     8     tabs: [{
     9       entries: [{ url: "about:mozilla" }],
    10       hidden: true,
    11       extData: {"tabview-tab": '{"url":"about:mozilla","groupID":1}'}
    12     },{
    13       entries: [{ url: "about:robots" }],
    14       hidden: false,
    15       extData: {"tabview-tab": '{"url":"about:robots","groupID":1}'},
    16     }],
    17     selected: 1,
    18     extData: {
    19       "tabview-groups": '{"nextID":2,"activeGroupId":1, "totalNumber":1}',
    20       "tabview-group":
    21         '{"1":{"bounds":{"left":15,"top":5,"width":280,"height":232},"id":1}}'
    22     }
    23   }]
    24 };
    26 /**
    27  * Make sure that tabs are restored on demand as otherwise the tab will start
    28  * loading immediately and we can't check whether it shows cached data.
    29  */
    30 add_task(function setup() {
    31   Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true);
    33   registerCleanupFunction(() => {
    34     Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand");
    35   });
    36 });
    38 /**
    39  * Ensure that a pending tab shows cached data.
    40  */
    41 add_task(function () {
    42   // Open a new window.
    43   let win = OpenBrowserWindow();
    44   yield promiseDelayedStartupFinished(win);
    46   // Set the window to a specific state.
    47   let ss = Cc["@mozilla.org/browser/sessionstore;1"]
    48              .getService(Ci.nsISessionStore)
    49              .setWindowState(win, JSON.stringify(STATE), true);
    51   // Open Panorama.
    52   yield promiseTabViewShown(win);
    54   let [tab1, tab2] = win.gBrowser.tabs;
    55   let cw = win.TabView.getContentWindow();
    57   // Update the two tabs in reverse order. Panorama will first try to update
    58   // the second tab but will put it back onto the queue once it detects that
    59   // it hasn't loaded yet. It will then try to update the first tab.
    60   cw.TabItems.update(tab2);
    61   cw.TabItems.update(tab1);
    63   let tabItem1 = tab1._tabViewTabItem;
    64   let tabItem2 = tab2._tabViewTabItem;
    66   // Wait for the first tabItem to be updated. Calling update() on the second
    67   // tabItem won't send a notification as that is pushed back onto the queue.
    68   yield promiseTabItemUpdated(tabItem1);
    70   // Check that the first tab doesn't show cached data, the second one does.
    71   ok(!tabItem1.isShowingCachedData(), "doesn't show cached data");
    72   ok(tabItem2.isShowingCachedData(), "shows cached data");
    74   // Cleanup.
    75   yield promiseWindowClosed(win);
    76 });
    78 function promiseTabItemUpdated(tabItem) {
    79   let deferred = Promise.defer();
    81   tabItem.addSubscriber("updated", function onUpdated() {
    82     tabItem.removeSubscriber("updated", onUpdated);
    83     deferred.resolve();
    84   });
    86   return deferred.promise;
    87 }
    89 function promiseAllTabItemsUpdated(win) {
    90   let deferred = Promise.defer();
    91   afterAllTabItemsUpdated(deferred.resolve, win);
    92   return deferred.promise;
    93 }
    95 function promiseDelayedStartupFinished(win) {
    96   let deferred = Promise.defer();
    97   whenDelayedStartupFinished(win, deferred.resolve);
    98   return deferred.promise;
    99 }
   101 function promiseTabViewShown(win) {
   102   let deferred = Promise.defer();
   103   showTabView(deferred.resolve, win);
   104   return deferred.promise;
   105 }
   107 function promiseWindowClosed(win) {
   108   let deferred = Promise.defer();
   110   Services.obs.addObserver(function obs(subject, topic) {
   111     if (subject == win) {
   112       Services.obs.removeObserver(obs, topic);
   113       deferred.resolve();
   114     }
   115   }, "domwindowclosed", false);
   117   win.close();
   118   return deferred.promise;
   119 }

mercurial