browser/components/tabview/test/browser_tabview_bug650573.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 let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
michael@0 5 let stateBackup = ss.getBrowserState();
michael@0 6
michael@0 7 function test() {
michael@0 8 waitForExplicitFinish();
michael@0 9
michael@0 10 registerCleanupFunction(function () {
michael@0 11 ss.setBrowserState(stateBackup);
michael@0 12 });
michael@0 13
michael@0 14 TabView._initFrame(function() {
michael@0 15 executeSoon(testRestoreNormal);
michael@0 16 });
michael@0 17 }
michael@0 18
michael@0 19 function testRestoreNormal() {
michael@0 20 testRestore("normal", function () {
michael@0 21 waitForBrowserState(JSON.parse(stateBackup), testRestorePinned);
michael@0 22 });
michael@0 23 }
michael@0 24
michael@0 25 function testRestorePinned() {
michael@0 26 gBrowser.loadOneTab("about:blank", {inBackground: true});
michael@0 27 gBrowser.pinTab(gBrowser.tabs[0]);
michael@0 28
michael@0 29 testRestore("pinned", function () {
michael@0 30 waitForBrowserState(JSON.parse(stateBackup), testRestoreHidden);
michael@0 31 });
michael@0 32 }
michael@0 33
michael@0 34 function testRestoreHidden() {
michael@0 35 let groupItem = createGroupItemWithBlankTabs(window, 20, 20, 20, 1);
michael@0 36 let tabItem = groupItem.getChild(0);
michael@0 37
michael@0 38 hideGroupItem(groupItem, function () {
michael@0 39 testRestore("hidden", function () {
michael@0 40 isnot(tabItem.container.style.display, "none", "tabItem is visible");
michael@0 41 waitForFocus(finish);
michael@0 42 });
michael@0 43 });
michael@0 44 }
michael@0 45
michael@0 46 function testRestore(prefix, callback) {
michael@0 47 waitForBrowserState(createBrowserState(), function () {
michael@0 48 is(gBrowser.tabs.length, 2, prefix + ": two tabs restored");
michael@0 49
michael@0 50 let cw = TabView.getContentWindow();
michael@0 51 is(cw.GroupItems.groupItems.length, 2, prefix + ": we have two groupItems");
michael@0 52
michael@0 53 let [groupItem1, groupItem2] = cw.GroupItems.groupItems;
michael@0 54 is(groupItem1.id, "1st-group-id", prefix + ": groupItem1's ID is valid");
michael@0 55 is(groupItem1.getChildren().length, 1, prefix + ": groupItem1 has one child");
michael@0 56
michael@0 57 is(groupItem2.id, "2nd-group-id", prefix + ": groupItem2's ID is valid");
michael@0 58 is(groupItem2.getChildren().length, 1, prefix + ": groupItem2 has one child");
michael@0 59
michael@0 60 callback();
michael@0 61 });
michael@0 62 }
michael@0 63
michael@0 64 function waitForBrowserState(state, callback) {
michael@0 65 window.addEventListener("SSWindowStateReady", function onReady() {
michael@0 66 window.removeEventListener("SSWindowStateReady", onReady, false);
michael@0 67 executeSoon(callback);
michael@0 68 }, false);
michael@0 69
michael@0 70 ss.setBrowserState(JSON.stringify(state));
michael@0 71 }
michael@0 72
michael@0 73 function createBrowserState() {
michael@0 74 let bounds = {left: 20, top: 20, width: 20, height: 20};
michael@0 75
michael@0 76 let tabViewGroups = {nextID: 99, activeGroupId: 1};
michael@0 77 let tabViewGroup = {
michael@0 78 "1st-group-id": {bounds: bounds, title: "new group 1", id: "1st-group-id"},
michael@0 79 "2nd-group-id": {bounds: bounds, title: "new group 2", id: "2nd-group-id"}
michael@0 80 };
michael@0 81
michael@0 82 let tab1Data = {bounds: bounds, url: "about:rights", groupID: "2nd-group-id"};
michael@0 83 let tab1 = {
michael@0 84 entries: [{url: "about:rights"}],
michael@0 85 extData: {"tabview-tab": JSON.stringify(tab1Data)}
michael@0 86 };
michael@0 87
michael@0 88 let tab2Data = {bounds: bounds, url: "about:mozilla", groupID: "1st-group-id"};
michael@0 89 let tab2 = {
michael@0 90 entries: [{url: "about:mozilla"}],
michael@0 91 extData: {"tabview-tab": JSON.stringify(tab2Data)}
michael@0 92 };
michael@0 93
michael@0 94 return {windows: [{
michael@0 95 tabs: [tab1, tab2],
michael@0 96 selected: 1,
michael@0 97 extData: {"tabview-groups": JSON.stringify(tabViewGroups),
michael@0 98 "tabview-group": JSON.stringify(tabViewGroup)}
michael@0 99 }]};
michael@0 100 }

mercurial