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

mercurial