|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 "use strict"; |
|
5 |
|
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 }; |
|
25 |
|
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); |
|
32 |
|
33 registerCleanupFunction(() => { |
|
34 Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand"); |
|
35 }); |
|
36 }); |
|
37 |
|
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); |
|
45 |
|
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); |
|
50 |
|
51 // Open Panorama. |
|
52 yield promiseTabViewShown(win); |
|
53 |
|
54 let [tab1, tab2] = win.gBrowser.tabs; |
|
55 let cw = win.TabView.getContentWindow(); |
|
56 |
|
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); |
|
62 |
|
63 let tabItem1 = tab1._tabViewTabItem; |
|
64 let tabItem2 = tab2._tabViewTabItem; |
|
65 |
|
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); |
|
69 |
|
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"); |
|
73 |
|
74 // Cleanup. |
|
75 yield promiseWindowClosed(win); |
|
76 }); |
|
77 |
|
78 function promiseTabItemUpdated(tabItem) { |
|
79 let deferred = Promise.defer(); |
|
80 |
|
81 tabItem.addSubscriber("updated", function onUpdated() { |
|
82 tabItem.removeSubscriber("updated", onUpdated); |
|
83 deferred.resolve(); |
|
84 }); |
|
85 |
|
86 return deferred.promise; |
|
87 } |
|
88 |
|
89 function promiseAllTabItemsUpdated(win) { |
|
90 let deferred = Promise.defer(); |
|
91 afterAllTabItemsUpdated(deferred.resolve, win); |
|
92 return deferred.promise; |
|
93 } |
|
94 |
|
95 function promiseDelayedStartupFinished(win) { |
|
96 let deferred = Promise.defer(); |
|
97 whenDelayedStartupFinished(win, deferred.resolve); |
|
98 return deferred.promise; |
|
99 } |
|
100 |
|
101 function promiseTabViewShown(win) { |
|
102 let deferred = Promise.defer(); |
|
103 showTabView(deferred.resolve, win); |
|
104 return deferred.promise; |
|
105 } |
|
106 |
|
107 function promiseWindowClosed(win) { |
|
108 let deferred = Promise.defer(); |
|
109 |
|
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); |
|
116 |
|
117 win.close(); |
|
118 return deferred.promise; |
|
119 } |