1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/tabview/test/browser_tabview_pending_tabs.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,119 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +"use strict"; 1.8 + 1.9 +const STATE = { 1.10 + windows: [{ 1.11 + tabs: [{ 1.12 + entries: [{ url: "about:mozilla" }], 1.13 + hidden: true, 1.14 + extData: {"tabview-tab": '{"url":"about:mozilla","groupID":1}'} 1.15 + },{ 1.16 + entries: [{ url: "about:robots" }], 1.17 + hidden: false, 1.18 + extData: {"tabview-tab": '{"url":"about:robots","groupID":1}'}, 1.19 + }], 1.20 + selected: 1, 1.21 + extData: { 1.22 + "tabview-groups": '{"nextID":2,"activeGroupId":1, "totalNumber":1}', 1.23 + "tabview-group": 1.24 + '{"1":{"bounds":{"left":15,"top":5,"width":280,"height":232},"id":1}}' 1.25 + } 1.26 + }] 1.27 +}; 1.28 + 1.29 +/** 1.30 + * Make sure that tabs are restored on demand as otherwise the tab will start 1.31 + * loading immediately and we can't check whether it shows cached data. 1.32 + */ 1.33 +add_task(function setup() { 1.34 + Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true); 1.35 + 1.36 + registerCleanupFunction(() => { 1.37 + Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand"); 1.38 + }); 1.39 +}); 1.40 + 1.41 +/** 1.42 + * Ensure that a pending tab shows cached data. 1.43 + */ 1.44 +add_task(function () { 1.45 + // Open a new window. 1.46 + let win = OpenBrowserWindow(); 1.47 + yield promiseDelayedStartupFinished(win); 1.48 + 1.49 + // Set the window to a specific state. 1.50 + let ss = Cc["@mozilla.org/browser/sessionstore;1"] 1.51 + .getService(Ci.nsISessionStore) 1.52 + .setWindowState(win, JSON.stringify(STATE), true); 1.53 + 1.54 + // Open Panorama. 1.55 + yield promiseTabViewShown(win); 1.56 + 1.57 + let [tab1, tab2] = win.gBrowser.tabs; 1.58 + let cw = win.TabView.getContentWindow(); 1.59 + 1.60 + // Update the two tabs in reverse order. Panorama will first try to update 1.61 + // the second tab but will put it back onto the queue once it detects that 1.62 + // it hasn't loaded yet. It will then try to update the first tab. 1.63 + cw.TabItems.update(tab2); 1.64 + cw.TabItems.update(tab1); 1.65 + 1.66 + let tabItem1 = tab1._tabViewTabItem; 1.67 + let tabItem2 = tab2._tabViewTabItem; 1.68 + 1.69 + // Wait for the first tabItem to be updated. Calling update() on the second 1.70 + // tabItem won't send a notification as that is pushed back onto the queue. 1.71 + yield promiseTabItemUpdated(tabItem1); 1.72 + 1.73 + // Check that the first tab doesn't show cached data, the second one does. 1.74 + ok(!tabItem1.isShowingCachedData(), "doesn't show cached data"); 1.75 + ok(tabItem2.isShowingCachedData(), "shows cached data"); 1.76 + 1.77 + // Cleanup. 1.78 + yield promiseWindowClosed(win); 1.79 +}); 1.80 + 1.81 +function promiseTabItemUpdated(tabItem) { 1.82 + let deferred = Promise.defer(); 1.83 + 1.84 + tabItem.addSubscriber("updated", function onUpdated() { 1.85 + tabItem.removeSubscriber("updated", onUpdated); 1.86 + deferred.resolve(); 1.87 + }); 1.88 + 1.89 + return deferred.promise; 1.90 +} 1.91 + 1.92 +function promiseAllTabItemsUpdated(win) { 1.93 + let deferred = Promise.defer(); 1.94 + afterAllTabItemsUpdated(deferred.resolve, win); 1.95 + return deferred.promise; 1.96 +} 1.97 + 1.98 +function promiseDelayedStartupFinished(win) { 1.99 + let deferred = Promise.defer(); 1.100 + whenDelayedStartupFinished(win, deferred.resolve); 1.101 + return deferred.promise; 1.102 +} 1.103 + 1.104 +function promiseTabViewShown(win) { 1.105 + let deferred = Promise.defer(); 1.106 + showTabView(deferred.resolve, win); 1.107 + return deferred.promise; 1.108 +} 1.109 + 1.110 +function promiseWindowClosed(win) { 1.111 + let deferred = Promise.defer(); 1.112 + 1.113 + Services.obs.addObserver(function obs(subject, topic) { 1.114 + if (subject == win) { 1.115 + Services.obs.removeObserver(obs, topic); 1.116 + deferred.resolve(); 1.117 + } 1.118 + }, "domwindowclosed", false); 1.119 + 1.120 + win.close(); 1.121 + return deferred.promise; 1.122 +}