зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1361428 - Split up browser_615394-SSWindowState_events.js. r=mikedeboer
MozReview-Commit-ID: 53FZf1xXd1K --HG-- rename : browser/components/sessionstore/test/browser_615394-SSWindowState_events.js => browser/components/sessionstore/test/browser_615394-SSWindowState_events_duplicateTab.js rename : browser/components/sessionstore/test/browser_615394-SSWindowState_events.js => browser/components/sessionstore/test/browser_615394-SSWindowState_events_setBrowserState.js rename : browser/components/sessionstore/test/browser_615394-SSWindowState_events.js => browser/components/sessionstore/test/browser_615394-SSWindowState_events_setTabState.js rename : browser/components/sessionstore/test/browser_615394-SSWindowState_events.js => browser/components/sessionstore/test/browser_615394-SSWindowState_events_setWindowState.js rename : browser/components/sessionstore/test/browser_615394-SSWindowState_events.js => browser/components/sessionstore/test/browser_615394-SSWindowState_events_undoCloseTab.js rename : browser/components/sessionstore/test/browser_615394-SSWindowState_events.js => browser/components/sessionstore/test/browser_615394-SSWindowState_events_undoCloseWindow.js extra : rebase_source : 4a026542cd2716f2fccf49792064d89cc343d873
This commit is contained in:
Родитель
a71bcd1f3c
Коммит
7e8d0c8454
|
@ -183,7 +183,12 @@ skip-if = true # Needs to be rewritten as Marionette test, bug 995916
|
|||
[browser_600545.js]
|
||||
[browser_601955.js]
|
||||
[browser_607016.js]
|
||||
[browser_615394-SSWindowState_events.js]
|
||||
[browser_615394-SSWindowState_events_duplicateTab.js]
|
||||
[browser_615394-SSWindowState_events_setBrowserState.js]
|
||||
[browser_615394-SSWindowState_events_setTabState.js]
|
||||
[browser_615394-SSWindowState_events_setWindowState.js]
|
||||
[browser_615394-SSWindowState_events_undoCloseTab.js]
|
||||
[browser_615394-SSWindowState_events_undoCloseWindow.js]
|
||||
[browser_618151.js]
|
||||
[browser_623779.js]
|
||||
[browser_624727.js]
|
||||
|
|
|
@ -1,363 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const stateBackup = JSON.parse(ss.getBrowserState());
|
||||
const testState = {
|
||||
windows: [{
|
||||
tabs: [
|
||||
{ entries: [{ url: "about:blank", triggeringPrincipal_base64 }] },
|
||||
{ entries: [{ url: "about:rights", triggeringPrincipal_base64 }] }
|
||||
]
|
||||
}]
|
||||
};
|
||||
const lameMultiWindowState = { windows: [
|
||||
{
|
||||
tabs: [
|
||||
{ entries: [{ url: "http://example.org#1", triggeringPrincipal_base64 }], extData: { "uniq": r() } },
|
||||
{ entries: [{ url: "http://example.org#2", triggeringPrincipal_base64 }], extData: { "uniq": r() } },
|
||||
{ entries: [{ url: "http://example.org#3", triggeringPrincipal_base64 }], extData: { "uniq": r() } },
|
||||
{ entries: [{ url: "http://example.org#4", triggeringPrincipal_base64 }], extData: { "uniq": r() } }
|
||||
],
|
||||
selected: 1
|
||||
},
|
||||
{
|
||||
tabs: [
|
||||
{ entries: [{ url: "http://example.com#1", triggeringPrincipal_base64 }], extData: { "uniq": r() } },
|
||||
{ entries: [{ url: "http://example.com#2", triggeringPrincipal_base64 }], extData: { "uniq": r() } },
|
||||
{ entries: [{ url: "http://example.com#3", triggeringPrincipal_base64 }], extData: { "uniq": r() } },
|
||||
{ entries: [{ url: "http://example.com#4", triggeringPrincipal_base64 }], extData: { "uniq": r() } },
|
||||
],
|
||||
selected: 3
|
||||
}
|
||||
] };
|
||||
|
||||
|
||||
function getOuterWindowID(aWindow) {
|
||||
return aWindow.QueryInterface(Ci.nsIInterfaceRequestor).
|
||||
getInterface(Ci.nsIDOMWindowUtils).outerWindowID;
|
||||
}
|
||||
|
||||
function test() {
|
||||
/** Test for Bug 615394 - Session Restore should notify when it is beginning and ending a restore **/
|
||||
waitForExplicitFinish();
|
||||
// Preemptively extend the timeout to prevent [orange]
|
||||
requestLongerTimeout(4);
|
||||
runNextTest();
|
||||
}
|
||||
|
||||
|
||||
var tests = [
|
||||
test_setTabState,
|
||||
test_duplicateTab,
|
||||
test_undoCloseTab,
|
||||
test_setWindowState,
|
||||
test_setBrowserState,
|
||||
test_undoCloseWindow
|
||||
];
|
||||
function runNextTest() {
|
||||
// set an empty state & run the next test, or finish
|
||||
if (tests.length) {
|
||||
// Enumerate windows and close everything but our primary window. We can't
|
||||
// use waitForFocus() because apparently it's buggy. See bug 599253.
|
||||
var windowsEnum = Services.wm.getEnumerator("navigator:browser");
|
||||
let closeWinPromises = [];
|
||||
while (windowsEnum.hasMoreElements()) {
|
||||
var currentWindow = windowsEnum.getNext();
|
||||
if (currentWindow != window) {
|
||||
closeWinPromises.push(BrowserTestUtils.closeWindow(currentWindow));
|
||||
}
|
||||
}
|
||||
|
||||
Promise.all(closeWinPromises).then(() => {
|
||||
let currentTest = tests.shift();
|
||||
info("prepping for " + currentTest.name);
|
||||
waitForBrowserState(testState, currentTest);
|
||||
});
|
||||
} else {
|
||||
waitForBrowserState(stateBackup, finish);
|
||||
}
|
||||
}
|
||||
|
||||
/** ACTUAL TESTS **/
|
||||
|
||||
function test_setTabState() {
|
||||
let tab = gBrowser.tabs[1];
|
||||
let newTabState = JSON.stringify({ entries: [{ url: "http://example.org", triggeringPrincipal_base64 }], extData: { foo: "bar" } });
|
||||
let busyEventCount = 0;
|
||||
let readyEventCount = 0;
|
||||
|
||||
function onSSWindowStateBusy(aEvent) {
|
||||
busyEventCount++;
|
||||
}
|
||||
|
||||
function onSSWindowStateReady(aEvent) {
|
||||
readyEventCount++;
|
||||
is(ss.getTabValue(tab, "foo"), "bar");
|
||||
ss.setTabValue(tab, "baz", "qux");
|
||||
}
|
||||
|
||||
function onSSTabRestoring(aEvent) {
|
||||
if (aEvent.target == tab) {
|
||||
is(busyEventCount, 1);
|
||||
is(readyEventCount, 1);
|
||||
is(ss.getTabValue(tab, "baz"), "qux");
|
||||
is(tab.linkedBrowser.currentURI.spec, "http://example.org/");
|
||||
|
||||
window.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
window.removeEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
gBrowser.tabContainer.removeEventListener("SSTabRestoring", onSSTabRestoring);
|
||||
|
||||
runNextTest();
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
window.addEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
gBrowser.tabContainer.addEventListener("SSTabRestoring", onSSTabRestoring);
|
||||
// Browser must be inserted in order to restore.
|
||||
gBrowser._insertBrowser(tab);
|
||||
ss.setTabState(tab, newTabState);
|
||||
}
|
||||
|
||||
|
||||
function test_duplicateTab() {
|
||||
let tab = gBrowser.tabs[1];
|
||||
let busyEventCount = 0;
|
||||
let readyEventCount = 0;
|
||||
let newTab;
|
||||
|
||||
// We'll look to make sure this value is on the duplicated tab
|
||||
ss.setTabValue(tab, "foo", "bar");
|
||||
|
||||
function onSSWindowStateBusy(aEvent) {
|
||||
busyEventCount++;
|
||||
}
|
||||
|
||||
function onSSWindowStateReady(aEvent) {
|
||||
newTab = gBrowser.tabs[2];
|
||||
readyEventCount++;
|
||||
is(ss.getTabValue(newTab, "foo"), "bar");
|
||||
ss.setTabValue(newTab, "baz", "qux");
|
||||
}
|
||||
|
||||
function onSSTabRestoring(aEvent) {
|
||||
if (aEvent.target == newTab) {
|
||||
is(busyEventCount, 1);
|
||||
is(readyEventCount, 1);
|
||||
is(ss.getTabValue(newTab, "baz"), "qux");
|
||||
is(newTab.linkedBrowser.currentURI.spec, "about:rights");
|
||||
|
||||
window.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
window.removeEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
gBrowser.tabContainer.removeEventListener("SSTabRestoring", onSSTabRestoring);
|
||||
|
||||
runNextTest();
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
window.addEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
gBrowser.tabContainer.addEventListener("SSTabRestoring", onSSTabRestoring);
|
||||
|
||||
gBrowser._insertBrowser(tab);
|
||||
newTab = ss.duplicateTab(window, tab);
|
||||
}
|
||||
|
||||
|
||||
function test_undoCloseTab() {
|
||||
let tab = gBrowser.tabs[1],
|
||||
busyEventCount = 0,
|
||||
readyEventCount = 0,
|
||||
reopenedTab;
|
||||
|
||||
ss.setTabValue(tab, "foo", "bar");
|
||||
|
||||
function onSSWindowStateBusy(aEvent) {
|
||||
busyEventCount++;
|
||||
}
|
||||
|
||||
function onSSWindowStateReady(aEvent) {
|
||||
reopenedTab = gBrowser.tabs[1];
|
||||
readyEventCount++;
|
||||
is(ss.getTabValue(reopenedTab, "foo"), "bar");
|
||||
ss.setTabValue(reopenedTab, "baz", "qux");
|
||||
}
|
||||
|
||||
function onSSTabRestored(aEvent) {
|
||||
is(busyEventCount, 1);
|
||||
is(readyEventCount, 1);
|
||||
is(ss.getTabValue(reopenedTab, "baz"), "qux");
|
||||
is(reopenedTab.linkedBrowser.currentURI.spec, "about:rights");
|
||||
|
||||
window.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
window.removeEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
gBrowser.tabContainer.removeEventListener("SSTabRestored", onSSTabRestored);
|
||||
|
||||
runNextTest();
|
||||
}
|
||||
|
||||
window.addEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
window.addEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
gBrowser.tabContainer.addEventListener("SSTabRestored", onSSTabRestored);
|
||||
|
||||
gBrowser.removeTab(tab);
|
||||
reopenedTab = ss.undoCloseTab(window, 0);
|
||||
}
|
||||
|
||||
|
||||
function test_setWindowState() {
|
||||
let newState = {
|
||||
windows: [{
|
||||
tabs: [
|
||||
{ entries: [{ url: "about:mozilla", triggeringPrincipal_base64 }], extData: { "foo": "bar" } },
|
||||
{ entries: [{ url: "http://example.org", triggeringPrincipal_base64 }], extData: { "baz": "qux" } }
|
||||
]
|
||||
}]
|
||||
};
|
||||
|
||||
let busyEventCount = 0,
|
||||
readyEventCount = 0,
|
||||
tabRestoredCount = 0;
|
||||
|
||||
function onSSWindowStateBusy(aEvent) {
|
||||
busyEventCount++;
|
||||
}
|
||||
|
||||
function onSSWindowStateReady(aEvent) {
|
||||
readyEventCount++;
|
||||
is(ss.getTabValue(gBrowser.tabs[0], "foo"), "bar");
|
||||
is(ss.getTabValue(gBrowser.tabs[1], "baz"), "qux");
|
||||
}
|
||||
|
||||
function onSSTabRestored(aEvent) {
|
||||
if (++tabRestoredCount < 2)
|
||||
return;
|
||||
|
||||
is(busyEventCount, 1);
|
||||
is(readyEventCount, 1);
|
||||
is(gBrowser.tabs[0].linkedBrowser.currentURI.spec, "about:mozilla");
|
||||
is(gBrowser.tabs[1].linkedBrowser.currentURI.spec, "http://example.org/");
|
||||
|
||||
window.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
window.removeEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
gBrowser.tabContainer.removeEventListener("SSTabRestored", onSSTabRestored);
|
||||
|
||||
runNextTest();
|
||||
}
|
||||
|
||||
window.addEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
window.addEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
gBrowser.tabContainer.addEventListener("SSTabRestored", onSSTabRestored);
|
||||
|
||||
ss.setWindowState(window, JSON.stringify(newState), true);
|
||||
}
|
||||
|
||||
|
||||
function test_setBrowserState() {
|
||||
// We'll track events per window so we are sure that they are each happening once
|
||||
// pre window.
|
||||
let windowEvents = {};
|
||||
windowEvents[getOuterWindowID(window)] = { busyEventCount: 0, readyEventCount: 0 };
|
||||
|
||||
// waitForBrowserState does it's own observing for windows, but doesn't attach
|
||||
// the listeners we want here, so do it ourselves.
|
||||
let newWindow;
|
||||
function windowObserver(aSubject, aTopic, aData) {
|
||||
if (aTopic == "domwindowopened") {
|
||||
newWindow = aSubject.QueryInterface(Ci.nsIDOMWindow);
|
||||
newWindow.addEventListener("load", function() {
|
||||
Services.ww.unregisterNotification(windowObserver);
|
||||
|
||||
windowEvents[getOuterWindowID(newWindow)] = { busyEventCount: 0, readyEventCount: 0 };
|
||||
|
||||
newWindow.addEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
newWindow.addEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
}, {once: true});
|
||||
}
|
||||
}
|
||||
|
||||
function onSSWindowStateBusy(aEvent) {
|
||||
windowEvents[getOuterWindowID(aEvent.originalTarget)].busyEventCount++;
|
||||
}
|
||||
|
||||
function onSSWindowStateReady(aEvent) {
|
||||
windowEvents[getOuterWindowID(aEvent.originalTarget)].readyEventCount++;
|
||||
}
|
||||
|
||||
window.addEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
window.addEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
Services.ww.registerNotification(windowObserver);
|
||||
|
||||
waitForBrowserState(lameMultiWindowState, function() {
|
||||
let checkedWindows = 0;
|
||||
for (let id of Object.keys(windowEvents)) {
|
||||
let winEvents = windowEvents[id];
|
||||
is(winEvents.busyEventCount, 1,
|
||||
"[test_setBrowserState] window" + id + " busy event count correct");
|
||||
is(winEvents.readyEventCount, 1,
|
||||
"[test_setBrowserState] window" + id + " ready event count correct");
|
||||
checkedWindows++;
|
||||
}
|
||||
is(checkedWindows, 2,
|
||||
"[test_setBrowserState] checked 2 windows");
|
||||
window.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
window.removeEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
newWindow.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
newWindow.removeEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
runNextTest();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function test_undoCloseWindow() {
|
||||
let newWindow, reopenedWindow;
|
||||
|
||||
function firstWindowObserver(aSubject, aTopic, aData) {
|
||||
if (aTopic == "domwindowopened") {
|
||||
newWindow = aSubject.QueryInterface(Ci.nsIDOMWindow);
|
||||
Services.ww.unregisterNotification(firstWindowObserver);
|
||||
}
|
||||
}
|
||||
Services.ww.registerNotification(firstWindowObserver);
|
||||
|
||||
waitForBrowserState(lameMultiWindowState, function() {
|
||||
// Close the window which isn't window
|
||||
BrowserTestUtils.closeWindow(newWindow).then(() => {
|
||||
// Now give it time to close
|
||||
reopenedWindow = ss.undoCloseWindow(0);
|
||||
reopenedWindow.addEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
reopenedWindow.addEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
|
||||
reopenedWindow.addEventListener("load", function() {
|
||||
reopenedWindow.gBrowser.tabContainer.addEventListener("SSTabRestored", onSSTabRestored);
|
||||
}, {once: true});
|
||||
});
|
||||
});
|
||||
|
||||
let busyEventCount = 0,
|
||||
readyEventCount = 0,
|
||||
tabRestoredCount = 0;
|
||||
// These will listen to the reopened closed window...
|
||||
function onSSWindowStateBusy(aEvent) {
|
||||
busyEventCount++;
|
||||
}
|
||||
|
||||
function onSSWindowStateReady(aEvent) {
|
||||
readyEventCount++;
|
||||
}
|
||||
|
||||
function onSSTabRestored(aEvent) {
|
||||
if (++tabRestoredCount < 4)
|
||||
return;
|
||||
|
||||
is(busyEventCount, 1);
|
||||
is(readyEventCount, 1);
|
||||
|
||||
reopenedWindow.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
reopenedWindow.removeEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
reopenedWindow.gBrowser.tabContainer.removeEventListener("SSTabRestored", onSSTabRestored);
|
||||
|
||||
BrowserTestUtils.closeWindow(reopenedWindow).then(runNextTest);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const testState = {
|
||||
windows: [{
|
||||
tabs: [
|
||||
{ entries: [{ url: "about:blank", triggeringPrincipal_base64 }] },
|
||||
{ entries: [{ url: "about:rights", triggeringPrincipal_base64 }] }
|
||||
]
|
||||
}]
|
||||
};
|
||||
|
||||
function test() {
|
||||
/** Test for Bug 615394 - Session Restore should notify when it is beginning and ending a restore **/
|
||||
waitForExplicitFinish();
|
||||
|
||||
waitForBrowserState(testState, test_duplicateTab);
|
||||
}
|
||||
|
||||
function test_duplicateTab() {
|
||||
let tab = gBrowser.tabs[1];
|
||||
let busyEventCount = 0;
|
||||
let readyEventCount = 0;
|
||||
let newTab;
|
||||
|
||||
// We'll look to make sure this value is on the duplicated tab
|
||||
ss.setTabValue(tab, "foo", "bar");
|
||||
|
||||
function onSSWindowStateBusy(aEvent) {
|
||||
busyEventCount++;
|
||||
}
|
||||
|
||||
function onSSWindowStateReady(aEvent) {
|
||||
newTab = gBrowser.tabs[2];
|
||||
readyEventCount++;
|
||||
is(ss.getTabValue(newTab, "foo"), "bar");
|
||||
ss.setTabValue(newTab, "baz", "qux");
|
||||
}
|
||||
|
||||
function onSSTabRestoring(aEvent) {
|
||||
if (aEvent.target == newTab) {
|
||||
is(busyEventCount, 1);
|
||||
is(readyEventCount, 1);
|
||||
is(ss.getTabValue(newTab, "baz"), "qux");
|
||||
is(newTab.linkedBrowser.currentURI.spec, "about:rights");
|
||||
|
||||
window.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
window.removeEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
gBrowser.tabContainer.removeEventListener("SSTabRestoring", onSSTabRestoring);
|
||||
|
||||
gBrowser.removeTab(tab);
|
||||
gBrowser.removeTab(newTab);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
window.addEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
gBrowser.tabContainer.addEventListener("SSTabRestoring", onSSTabRestoring);
|
||||
|
||||
gBrowser._insertBrowser(tab);
|
||||
newTab = ss.duplicateTab(window, tab);
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const lameMultiWindowState = { windows: [
|
||||
{
|
||||
tabs: [
|
||||
{ entries: [{ url: "http://example.org#1", triggeringPrincipal_base64 }], extData: { "uniq": r() } },
|
||||
{ entries: [{ url: "http://example.org#2", triggeringPrincipal_base64 }], extData: { "uniq": r() } },
|
||||
{ entries: [{ url: "http://example.org#3", triggeringPrincipal_base64 }], extData: { "uniq": r() } },
|
||||
{ entries: [{ url: "http://example.org#4", triggeringPrincipal_base64 }], extData: { "uniq": r() } }
|
||||
],
|
||||
selected: 1
|
||||
},
|
||||
{
|
||||
tabs: [
|
||||
{ entries: [{ url: "http://example.com#1", triggeringPrincipal_base64 }], extData: { "uniq": r() } },
|
||||
{ entries: [{ url: "http://example.com#2", triggeringPrincipal_base64 }], extData: { "uniq": r() } },
|
||||
{ entries: [{ url: "http://example.com#3", triggeringPrincipal_base64 }], extData: { "uniq": r() } },
|
||||
{ entries: [{ url: "http://example.com#4", triggeringPrincipal_base64 }], extData: { "uniq": r() } },
|
||||
],
|
||||
selected: 3
|
||||
}
|
||||
] };
|
||||
|
||||
|
||||
function getOuterWindowID(aWindow) {
|
||||
return aWindow.QueryInterface(Ci.nsIInterfaceRequestor).
|
||||
getInterface(Ci.nsIDOMWindowUtils).outerWindowID;
|
||||
}
|
||||
|
||||
function test() {
|
||||
/** Test for Bug 615394 - Session Restore should notify when it is beginning and ending a restore **/
|
||||
waitForExplicitFinish();
|
||||
|
||||
// We'll track events per window so we are sure that they are each happening once
|
||||
// pre window.
|
||||
let windowEvents = {};
|
||||
windowEvents[getOuterWindowID(window)] = { busyEventCount: 0, readyEventCount: 0 };
|
||||
|
||||
// waitForBrowserState does it's own observing for windows, but doesn't attach
|
||||
// the listeners we want here, so do it ourselves.
|
||||
let newWindow;
|
||||
function windowObserver(aSubject, aTopic, aData) {
|
||||
if (aTopic == "domwindowopened") {
|
||||
Services.ww.unregisterNotification(windowObserver);
|
||||
|
||||
newWindow = aSubject.QueryInterface(Ci.nsIDOMWindow);
|
||||
newWindow.addEventListener("load", function() {
|
||||
windowEvents[getOuterWindowID(newWindow)] = { busyEventCount: 0, readyEventCount: 0 };
|
||||
|
||||
newWindow.addEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
newWindow.addEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
}, {once: true});
|
||||
}
|
||||
}
|
||||
|
||||
function onSSWindowStateBusy(aEvent) {
|
||||
windowEvents[getOuterWindowID(aEvent.originalTarget)].busyEventCount++;
|
||||
}
|
||||
|
||||
function onSSWindowStateReady(aEvent) {
|
||||
windowEvents[getOuterWindowID(aEvent.originalTarget)].readyEventCount++;
|
||||
}
|
||||
|
||||
window.addEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
window.addEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
Services.ww.registerNotification(windowObserver);
|
||||
|
||||
waitForBrowserState(lameMultiWindowState, function() {
|
||||
let checkedWindows = 0;
|
||||
for (let id of Object.keys(windowEvents)) {
|
||||
let winEvents = windowEvents[id];
|
||||
is(winEvents.busyEventCount, 1, "window" + id + " busy event count correct");
|
||||
is(winEvents.readyEventCount, 1, "window" + id + " ready event count correct");
|
||||
checkedWindows++;
|
||||
}
|
||||
is(checkedWindows, 2, "checked 2 windows");
|
||||
window.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
window.removeEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
newWindow.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
newWindow.removeEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
|
||||
newWindow.close();
|
||||
while (gBrowser.tabs.length > 1) {
|
||||
gBrowser.removeTab(gBrowser.tabs[1]);
|
||||
}
|
||||
|
||||
finish();
|
||||
});
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const testState = {
|
||||
windows: [{
|
||||
tabs: [
|
||||
{ entries: [{ url: "about:blank", triggeringPrincipal_base64 }] },
|
||||
{ entries: [{ url: "about:rights", triggeringPrincipal_base64 }] }
|
||||
]
|
||||
}]
|
||||
};
|
||||
|
||||
function test() {
|
||||
/** Test for Bug 615394 - Session Restore should notify when it is beginning and ending a restore **/
|
||||
waitForExplicitFinish();
|
||||
|
||||
waitForBrowserState(testState, test_setTabState);
|
||||
}
|
||||
|
||||
function test_setTabState() {
|
||||
let tab = gBrowser.tabs[1];
|
||||
let newTabState = JSON.stringify({ entries: [{ url: "http://example.org", triggeringPrincipal_base64 }], extData: { foo: "bar" } });
|
||||
let busyEventCount = 0;
|
||||
let readyEventCount = 0;
|
||||
|
||||
function onSSWindowStateBusy(aEvent) {
|
||||
busyEventCount++;
|
||||
}
|
||||
|
||||
function onSSWindowStateReady(aEvent) {
|
||||
readyEventCount++;
|
||||
is(ss.getTabValue(tab, "foo"), "bar");
|
||||
ss.setTabValue(tab, "baz", "qux");
|
||||
}
|
||||
|
||||
function onSSTabRestoring(aEvent) {
|
||||
is(busyEventCount, 1);
|
||||
is(readyEventCount, 1);
|
||||
is(ss.getTabValue(tab, "baz"), "qux");
|
||||
is(tab.linkedBrowser.currentURI.spec, "http://example.org/");
|
||||
|
||||
window.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
window.removeEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
|
||||
gBrowser.removeTab(tab)
|
||||
finish();
|
||||
}
|
||||
|
||||
window.addEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
window.addEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
tab.addEventListener("SSTabRestoring", onSSTabRestoring, { once: true });
|
||||
// Browser must be inserted in order to restore.
|
||||
gBrowser._insertBrowser(tab);
|
||||
ss.setTabState(tab, newTabState);
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
function test() {
|
||||
/** Test for Bug 615394 - Session Restore should notify when it is beginning and ending a restore **/
|
||||
waitForExplicitFinish();
|
||||
|
||||
let newState = {
|
||||
windows: [{
|
||||
tabs: [
|
||||
{ entries: [{ url: "about:mozilla", triggeringPrincipal_base64 }], extData: { "foo": "bar" } },
|
||||
{ entries: [{ url: "http://example.org", triggeringPrincipal_base64 }], extData: { "baz": "qux" } }
|
||||
]
|
||||
}]
|
||||
};
|
||||
|
||||
let busyEventCount = 0,
|
||||
readyEventCount = 0,
|
||||
tabRestoredCount = 0;
|
||||
|
||||
function onSSWindowStateBusy(aEvent) {
|
||||
busyEventCount++;
|
||||
}
|
||||
|
||||
function onSSWindowStateReady(aEvent) {
|
||||
readyEventCount++;
|
||||
is(ss.getTabValue(gBrowser.tabs[0], "foo"), "bar");
|
||||
is(ss.getTabValue(gBrowser.tabs[1], "baz"), "qux");
|
||||
}
|
||||
|
||||
function onSSTabRestored(aEvent) {
|
||||
if (++tabRestoredCount < 2)
|
||||
return;
|
||||
|
||||
is(busyEventCount, 1);
|
||||
is(readyEventCount, 1);
|
||||
is(gBrowser.tabs[0].linkedBrowser.currentURI.spec, "about:mozilla");
|
||||
is(gBrowser.tabs[1].linkedBrowser.currentURI.spec, "http://example.org/");
|
||||
|
||||
window.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
window.removeEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
gBrowser.tabContainer.removeEventListener("SSTabRestored", onSSTabRestored);
|
||||
|
||||
gBrowser.removeTab(gBrowser.tabs[1]);
|
||||
finish();
|
||||
}
|
||||
|
||||
window.addEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
window.addEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
gBrowser.tabContainer.addEventListener("SSTabRestored", onSSTabRestored);
|
||||
|
||||
ss.setWindowState(window, JSON.stringify(newState), true);
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const testState = {
|
||||
windows: [{
|
||||
tabs: [
|
||||
{ entries: [{ url: "about:blank", triggeringPrincipal_base64 }] },
|
||||
{ entries: [{ url: "about:rights", triggeringPrincipal_base64 }] }
|
||||
]
|
||||
}]
|
||||
};
|
||||
|
||||
function test() {
|
||||
/** Test for Bug 615394 - Session Restore should notify when it is beginning and ending a restore **/
|
||||
waitForExplicitFinish();
|
||||
|
||||
waitForBrowserState(testState, test_undoCloseTab);
|
||||
}
|
||||
|
||||
function test_undoCloseTab() {
|
||||
let tab = gBrowser.tabs[1],
|
||||
busyEventCount = 0,
|
||||
readyEventCount = 0,
|
||||
reopenedTab;
|
||||
|
||||
ss.setTabValue(tab, "foo", "bar");
|
||||
|
||||
function onSSWindowStateBusy(aEvent) {
|
||||
busyEventCount++;
|
||||
}
|
||||
|
||||
function onSSWindowStateReady(aEvent) {
|
||||
reopenedTab = gBrowser.tabs[1];
|
||||
readyEventCount++;
|
||||
is(ss.getTabValue(reopenedTab, "foo"), "bar");
|
||||
ss.setTabValue(reopenedTab, "baz", "qux");
|
||||
}
|
||||
|
||||
function onSSTabRestored(aEvent) {
|
||||
is(busyEventCount, 1);
|
||||
is(readyEventCount, 1);
|
||||
is(ss.getTabValue(reopenedTab, "baz"), "qux");
|
||||
is(reopenedTab.linkedBrowser.currentURI.spec, "about:rights");
|
||||
|
||||
window.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
window.removeEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
|
||||
gBrowser.removeTab(gBrowser.tabs[1]);
|
||||
finish();
|
||||
}
|
||||
|
||||
window.addEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
window.addEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
gBrowser.tabContainer.addEventListener("SSTabRestored", onSSTabRestored, { once: true });
|
||||
|
||||
gBrowser.removeTab(tab);
|
||||
reopenedTab = ss.undoCloseTab(window, 0);
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const lameMultiWindowState = { windows: [
|
||||
{
|
||||
tabs: [
|
||||
{ entries: [{ url: "http://example.org#1", triggeringPrincipal_base64 }], extData: { "uniq": r() } },
|
||||
{ entries: [{ url: "http://example.org#2", triggeringPrincipal_base64 }], extData: { "uniq": r() } },
|
||||
{ entries: [{ url: "http://example.org#3", triggeringPrincipal_base64 }], extData: { "uniq": r() } },
|
||||
{ entries: [{ url: "http://example.org#4", triggeringPrincipal_base64 }], extData: { "uniq": r() } }
|
||||
],
|
||||
selected: 1
|
||||
},
|
||||
{
|
||||
tabs: [
|
||||
{ entries: [{ url: "http://example.com#1", triggeringPrincipal_base64 }], extData: { "uniq": r() } },
|
||||
{ entries: [{ url: "http://example.com#2", triggeringPrincipal_base64 }], extData: { "uniq": r() } },
|
||||
{ entries: [{ url: "http://example.com#3", triggeringPrincipal_base64 }], extData: { "uniq": r() } },
|
||||
{ entries: [{ url: "http://example.com#4", triggeringPrincipal_base64 }], extData: { "uniq": r() } },
|
||||
],
|
||||
selected: 3
|
||||
}
|
||||
] };
|
||||
|
||||
function test() {
|
||||
/** Test for Bug 615394 - Session Restore should notify when it is beginning and ending a restore **/
|
||||
waitForExplicitFinish();
|
||||
|
||||
let newWindow, reopenedWindow;
|
||||
|
||||
function firstWindowObserver(aSubject, aTopic, aData) {
|
||||
if (aTopic == "domwindowopened") {
|
||||
newWindow = aSubject.QueryInterface(Ci.nsIDOMWindow);
|
||||
Services.ww.unregisterNotification(firstWindowObserver);
|
||||
}
|
||||
}
|
||||
Services.ww.registerNotification(firstWindowObserver);
|
||||
|
||||
waitForBrowserState(lameMultiWindowState, function() {
|
||||
// Close the window which isn't window
|
||||
BrowserTestUtils.closeWindow(newWindow).then(() => {
|
||||
// Now give it time to close
|
||||
reopenedWindow = ss.undoCloseWindow(0);
|
||||
reopenedWindow.addEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
reopenedWindow.addEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
|
||||
reopenedWindow.addEventListener("load", function() {
|
||||
reopenedWindow.gBrowser.tabContainer.addEventListener("SSTabRestored", onSSTabRestored);
|
||||
}, {once: true});
|
||||
});
|
||||
});
|
||||
|
||||
let busyEventCount = 0,
|
||||
readyEventCount = 0,
|
||||
tabRestoredCount = 0;
|
||||
// These will listen to the reopened closed window...
|
||||
function onSSWindowStateBusy(aEvent) {
|
||||
busyEventCount++;
|
||||
}
|
||||
|
||||
function onSSWindowStateReady(aEvent) {
|
||||
readyEventCount++;
|
||||
}
|
||||
|
||||
function onSSTabRestored(aEvent) {
|
||||
if (++tabRestoredCount < 4)
|
||||
return;
|
||||
|
||||
is(busyEventCount, 1);
|
||||
is(readyEventCount, 1);
|
||||
|
||||
reopenedWindow.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy);
|
||||
reopenedWindow.removeEventListener("SSWindowStateReady", onSSWindowStateReady);
|
||||
reopenedWindow.gBrowser.tabContainer.removeEventListener("SSTabRestored", onSSTabRestored);
|
||||
|
||||
reopenedWindow.close();
|
||||
while (gBrowser.tabs.length > 1) {
|
||||
gBrowser.removeTab(gBrowser.tabs[1]);
|
||||
}
|
||||
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
Загрузка…
Ссылка в новой задаче