Bug 1162871 - Test that duplicateTab() does wait for the flush to complete and includes flushed data r=billm

This commit is contained in:
Tim Taubert 2015-05-08 15:15:32 +02:00
Родитель 8722006f14
Коммит 1675a6ff9c
4 изменённых файлов: 86 добавлений и 13 удалений

Просмотреть файл

@ -65,6 +65,7 @@ support-files =
[browser_aboutPrivateBrowsing.js]
[browser_aboutSessionRestore.js]
[browser_async_duplicate_tab.js]
[browser_async_remove_tab.js]
run-if = e10s
[browser_attributes.js]

Просмотреть файл

@ -3,10 +3,6 @@
"use strict";
let tmp = {};
Cu.import("resource:///modules/sessionstore/SessionSaver.jsm", tmp);
let {SessionSaver} = tmp;
const URL = ROOT + "browser_454908_sample.html";
const PASS = "pwd-" + Math.random();

Просмотреть файл

@ -0,0 +1,78 @@
"use strict";
const URL = "data:text/html;charset=utf-8,<a href=%23>clickme</a>";
add_task(function* test_duplicate() {
// Create new tab.
let tab = gBrowser.addTab(URL);
let browser = tab.linkedBrowser;
yield promiseBrowserLoaded(browser);
// Flush to empty any queued update messages.
yield TabStateFlusher.flush(browser);
// Click the link to navigate, this will add second shistory entry.
yield ContentTask.spawn(browser, null, function* () {
return new Promise(resolve => {
addEventListener("hashchange", function onHashChange() {
removeEventListener("hashchange", onHashChange);
resolve();
});
// Click the link.
content.document.querySelector("a").click();
});
});
// Duplicate the tab.
let tab2 = ss.duplicateTab(window, tab);
// Wait until the tab has fully restored.
yield promiseTabRestored(tab2);
yield TabStateFlusher.flush(tab2.linkedBrowser);
// There should be two history entries now.
let {entries} = JSON.parse(ss.getTabState(tab2));
is(entries.length, 2, "there are two shistory entries");
// Cleanup.
yield promiseRemoveTab(tab2);
yield promiseRemoveTab(tab);
});
add_task(function* test_duplicate_remove() {
// Create new tab.
let tab = gBrowser.addTab(URL);
let browser = tab.linkedBrowser;
yield promiseBrowserLoaded(browser);
// Flush to empty any queued update messages.
yield TabStateFlusher.flush(browser);
// Click the link to navigate, this will add second shistory entry.
yield ContentTask.spawn(browser, null, function* () {
return new Promise(resolve => {
addEventListener("hashchange", function onHashChange() {
removeEventListener("hashchange", onHashChange);
resolve();
});
// Click the link.
content.document.querySelector("a").click();
});
});
// Duplicate the tab.
let tab2 = ss.duplicateTab(window, tab);
// Before the duplication finished, remove the tab.
yield Promise.all([promiseRemoveTab(tab), promiseTabRestored(tab2)]);
yield TabStateFlusher.flush(tab2.linkedBrowser);
// There should be two history entries now.
let {entries} = JSON.parse(ss.getTabState(tab2));
is(entries.length, 2, "there are two shistory entries");
// Cleanup.
yield promiseRemoveTab(tab2);
});

Просмотреть файл

@ -25,16 +25,14 @@ registerCleanupFunction(() => {
}
});
let tmp = {};
Cu.import("resource://gre/modules/Promise.jsm", tmp);
Cu.import("resource://gre/modules/Task.jsm", tmp);
Cu.import("resource:///modules/sessionstore/SessionStore.jsm", tmp);
Cu.import("resource:///modules/sessionstore/SessionSaver.jsm", tmp);
Cu.import("resource:///modules/sessionstore/SessionFile.jsm", tmp);
Cu.import("resource:///modules/sessionstore/TabState.jsm", tmp);
let {Promise, Task, SessionStore, SessionSaver, SessionFile, TabState} = tmp;
const {Promise} = Cu.import("resource://gre/modules/Promise.jsm", {});
const {SessionStore} = Cu.import("resource:///modules/sessionstore/SessionStore.jsm", {});
const {SessionSaver} = Cu.import("resource:///modules/sessionstore/SessionSaver.jsm", {});
const {SessionFile} = Cu.import("resource:///modules/sessionstore/SessionFile.jsm", {});
const {TabState} = Cu.import("resource:///modules/sessionstore/TabState.jsm", {});
const {TabStateFlusher} = Cu.import("resource:///modules/sessionstore/TabStateFlusher.jsm", {});
let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
const ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
// Some tests here assume that all restored tabs are loaded without waiting for
// the user to bring them to the foreground. We ensure this by resetting the