зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1499874 - Part 1: Test that restoring a tab removes it from the session store. r=esawin
Differential Revision: https://phabricator.services.mozilla.com/D15329 --HG-- extra : source : f920fb20c379b24bfe0945fafd002065ac112d84 extra : histedit_source : a5b4561928d1c5be30582a0ccaa2b75c7d66bc9c
This commit is contained in:
Родитель
cb158a3b46
Коммит
3bfc0a2e5f
|
@ -50,6 +50,7 @@ skip-if = true # Bug 1241478
|
|||
[test_session_form_data.html]
|
||||
[test_session_parentid.html]
|
||||
[test_session_scroll_position.html]
|
||||
[test_session_undo_close_tab.html]
|
||||
[test_session_zombification.html]
|
||||
[test_settings_fontinflation.html]
|
||||
[test_shared_preferences.html]
|
||||
|
|
|
@ -0,0 +1,122 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=1499874
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test mobile session store undo close tab functionality</title>
|
||||
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/AddTask.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
|
||||
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
|
||||
<script type="application/javascript" src="head.js"></script>
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Tests for Bug 1499874 **/
|
||||
|
||||
"use strict";
|
||||
|
||||
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
ChromeUtils.import("resource://gre/modules/Messaging.jsm");
|
||||
|
||||
const PREFS_MAX_TABS_UNDO = "browser.sessionstore.max_tabs_undo";
|
||||
|
||||
// The chrome window and friends.
|
||||
const chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
|
||||
const BrowserApp = chromeWin.BrowserApp;
|
||||
|
||||
const URL = "data:text/html;charset=utf-8,It%20was%20a%20dark%20and%20stormy%20night.";
|
||||
const TAB_COUNT = 4;
|
||||
|
||||
// Track the tabs where the tests are happening.
|
||||
let tabs = [];
|
||||
|
||||
function cleanupTabs() {
|
||||
tabs.forEach(tab => BrowserApp.closeTab(tab));
|
||||
tabs = [];
|
||||
}
|
||||
|
||||
SimpleTest.registerCleanupFunction(function() {
|
||||
cleanupTabs();
|
||||
});
|
||||
|
||||
let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
|
||||
|
||||
add_task(async function test_removeClosedTabWhenUndoCloseTab() {
|
||||
// Clear closed tabs that might be present from previous tests.
|
||||
Services.prefs.setIntPref(PREFS_MAX_TABS_UNDO, 0);
|
||||
Services.prefs.clearUserPref(PREFS_MAX_TABS_UNDO);
|
||||
let state = ss.getClosedTabs(chromeWin);
|
||||
is(state.length, 0, "no closed tabs at the start");
|
||||
|
||||
// Open a few tabs.
|
||||
const tabEvents = [];
|
||||
for (let i = 0; i < TAB_COUNT; i++) {
|
||||
const tab = BrowserApp.addTab(URL);
|
||||
tabEvents.push(promiseBrowserEvent(tab.browser, "DOMContentLoaded"));
|
||||
tabs.push(tab);
|
||||
}
|
||||
await Promise.all(tabEvents);
|
||||
|
||||
// Close them all again.
|
||||
for (const tab of tabs) {
|
||||
const tabClosed = promiseTabEvent(tab.browser, "SSTabCloseProcessed");
|
||||
BrowserApp.closeTab(tab);
|
||||
await tabClosed;
|
||||
}
|
||||
tabs = [];
|
||||
|
||||
state = ss.getClosedTabs(chromeWin);
|
||||
is(state.length, TAB_COUNT, "expected count of closed tabs in the session store");
|
||||
|
||||
// Without a tab ID in the closed tab data, the session store shouldn't be
|
||||
// able to delete the tab from its collection of closed tabs.
|
||||
const tabDataNoTabId = {...state[0]};
|
||||
delete tabDataNoTabId.tabId;
|
||||
let restoredTab =
|
||||
BrowserApp.getTabForBrowser(ss.undoCloseTab(chromeWin, tabDataNoTabId));
|
||||
tabs.push(restoredTab);
|
||||
await promiseBrowserEvent(restoredTab.browser, "DOMContentLoaded");
|
||||
state = ss.getClosedTabs(chromeWin);
|
||||
is(state.length, TAB_COUNT, "expected count of closed tabs in the session store");
|
||||
|
||||
// Now restore each tab in turn and check that it gets removed from the
|
||||
// session store's closed tab collection.
|
||||
for (let closedTab of state) {
|
||||
// Mimic a little more closely what happens when closing a tab from the
|
||||
// home panels, where the tab data argument for undoCloseTab has been de-
|
||||
// serialised and therefore checking tab data objects for (reference)
|
||||
// equality isn't sufficient to determine which closed tab needs to be
|
||||
// removed from the session store.
|
||||
closedTab = {...closedTab};
|
||||
|
||||
const id = closedTab.tabId;
|
||||
let closedTabs = ss.getClosedTabs(chromeWin);
|
||||
ok(closedTabs.find(tab => tab.tabId == id), "closed tabs collection contains tab");
|
||||
|
||||
restoredTab = BrowserApp.getTabForBrowser(ss.undoCloseTab(chromeWin, closedTab));
|
||||
tabs.push(restoredTab);
|
||||
await promiseBrowserEvent(restoredTab.browser, "DOMContentLoaded");
|
||||
closedTabs = ss.getClosedTabs(chromeWin);
|
||||
todo(!closedTabs.find(tab => tab.tabId == id), "closed tabs collection no longer contains tab");
|
||||
}
|
||||
state = ss.getClosedTabs(chromeWin);
|
||||
todo_is(state.length, 0, "no more closed tabs should be left");
|
||||
|
||||
cleanupTabs();
|
||||
});
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1499874">Mozilla Bug 1499874</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче