1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/sessionstore/test/browser_590563.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,78 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +function test() { 1.8 + let oldState = { 1.9 + windows: [{ 1.10 + tabs: [ 1.11 + { entries: [{ url: "about:mozilla" }], hidden: true }, 1.12 + { entries: [{ url: "about:blank" }], hidden: false } 1.13 + ] 1.14 + }] 1.15 + }; 1.16 + let pageData = { 1.17 + url: "about:sessionrestore", 1.18 + formdata: { id: { "sessionData": oldState } } 1.19 + }; 1.20 + let state = { windows: [{ tabs: [{ entries: [pageData] }] }] }; 1.21 + 1.22 + waitForExplicitFinish(); 1.23 + 1.24 + newWindowWithState(state, function (win) { 1.25 + registerCleanupFunction(function () win.close()); 1.26 + 1.27 + is(gBrowser.tabs.length, 1, "The total number of tabs should be 1"); 1.28 + is(gBrowser.visibleTabs.length, 1, "The total number of visible tabs should be 1"); 1.29 + 1.30 + executeSoon(function () { 1.31 + waitForFocus(function () { 1.32 + middleClickTest(win); 1.33 + finish(); 1.34 + }, win); 1.35 + }); 1.36 + }); 1.37 +} 1.38 + 1.39 +function middleClickTest(win) { 1.40 + let browser = win.gBrowser.selectedBrowser; 1.41 + let tree = browser.contentDocument.getElementById("tabList"); 1.42 + is(tree.view.rowCount, 3, "There should be three items"); 1.43 + 1.44 + let x = {}, y = {}, width = {}, height = {}; 1.45 + 1.46 + // click on the first tab item 1.47 + tree.treeBoxObject.getCoordsForCellItem(1, tree.columns[1], "text", x, y, width, height); 1.48 + EventUtils.synthesizeMouse(tree.body, x.value, y.value, { button: 1 }, 1.49 + browser.contentWindow); 1.50 + // click on the second tab item 1.51 + tree.treeBoxObject.getCoordsForCellItem(2, tree.columns[1], "text", x, y, width, height); 1.52 + EventUtils.synthesizeMouse(tree.body, x.value, y.value, { button: 1 }, 1.53 + browser.contentWindow); 1.54 + 1.55 + is(win.gBrowser.tabs.length, 3, 1.56 + "The total number of tabs should be 3 after restoring 2 tabs by middle click."); 1.57 + is(win.gBrowser.visibleTabs.length, 3, 1.58 + "The total number of visible tabs should be 3 after restoring 2 tabs by middle click"); 1.59 +} 1.60 + 1.61 +function newWindowWithState(state, callback) { 1.62 + let opts = "chrome,all,dialog=no,height=800,width=800"; 1.63 + let win = window.openDialog(getBrowserURL(), "_blank", opts); 1.64 + 1.65 + win.addEventListener("load", function onLoad() { 1.66 + win.removeEventListener("load", onLoad, false); 1.67 + 1.68 + let tab = win.gBrowser.selectedTab; 1.69 + 1.70 + // The form data will be restored before SSTabRestored, so we want to listen 1.71 + // for that on the currently selected tab (it will be reused) 1.72 + tab.addEventListener("SSTabRestored", function onRestored() { 1.73 + tab.removeEventListener("SSTabRestored", onRestored, true); 1.74 + callback(win); 1.75 + }, true); 1.76 + 1.77 + executeSoon(function () { 1.78 + ss.setWindowState(win, JSON.stringify(state), true); 1.79 + }); 1.80 + }, false); 1.81 +}