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.

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

mercurial