|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 function test() { |
|
5 let oldState = { |
|
6 windows: [{ |
|
7 tabs: [ |
|
8 { entries: [{ url: "about:mozilla" }], hidden: true }, |
|
9 { entries: [{ url: "about:blank" }], hidden: false } |
|
10 ] |
|
11 }] |
|
12 }; |
|
13 let pageData = { |
|
14 url: "about:sessionrestore", |
|
15 formdata: { id: { "sessionData": oldState } } |
|
16 }; |
|
17 let state = { windows: [{ tabs: [{ entries: [pageData] }] }] }; |
|
18 |
|
19 waitForExplicitFinish(); |
|
20 |
|
21 newWindowWithState(state, function (win) { |
|
22 registerCleanupFunction(function () win.close()); |
|
23 |
|
24 is(gBrowser.tabs.length, 1, "The total number of tabs should be 1"); |
|
25 is(gBrowser.visibleTabs.length, 1, "The total number of visible tabs should be 1"); |
|
26 |
|
27 executeSoon(function () { |
|
28 waitForFocus(function () { |
|
29 middleClickTest(win); |
|
30 finish(); |
|
31 }, win); |
|
32 }); |
|
33 }); |
|
34 } |
|
35 |
|
36 function middleClickTest(win) { |
|
37 let browser = win.gBrowser.selectedBrowser; |
|
38 let tree = browser.contentDocument.getElementById("tabList"); |
|
39 is(tree.view.rowCount, 3, "There should be three items"); |
|
40 |
|
41 let x = {}, y = {}, width = {}, height = {}; |
|
42 |
|
43 // click on the first tab item |
|
44 tree.treeBoxObject.getCoordsForCellItem(1, tree.columns[1], "text", x, y, width, height); |
|
45 EventUtils.synthesizeMouse(tree.body, x.value, y.value, { button: 1 }, |
|
46 browser.contentWindow); |
|
47 // click on the second tab item |
|
48 tree.treeBoxObject.getCoordsForCellItem(2, tree.columns[1], "text", x, y, width, height); |
|
49 EventUtils.synthesizeMouse(tree.body, x.value, y.value, { button: 1 }, |
|
50 browser.contentWindow); |
|
51 |
|
52 is(win.gBrowser.tabs.length, 3, |
|
53 "The total number of tabs should be 3 after restoring 2 tabs by middle click."); |
|
54 is(win.gBrowser.visibleTabs.length, 3, |
|
55 "The total number of visible tabs should be 3 after restoring 2 tabs by middle click"); |
|
56 } |
|
57 |
|
58 function newWindowWithState(state, callback) { |
|
59 let opts = "chrome,all,dialog=no,height=800,width=800"; |
|
60 let win = window.openDialog(getBrowserURL(), "_blank", opts); |
|
61 |
|
62 win.addEventListener("load", function onLoad() { |
|
63 win.removeEventListener("load", onLoad, false); |
|
64 |
|
65 let tab = win.gBrowser.selectedTab; |
|
66 |
|
67 // The form data will be restored before SSTabRestored, so we want to listen |
|
68 // for that on the currently selected tab (it will be reused) |
|
69 tab.addEventListener("SSTabRestored", function onRestored() { |
|
70 tab.removeEventListener("SSTabRestored", onRestored, true); |
|
71 callback(win); |
|
72 }, true); |
|
73 |
|
74 executeSoon(function () { |
|
75 ss.setWindowState(win, JSON.stringify(state), true); |
|
76 }); |
|
77 }, false); |
|
78 } |