Bug 1415796 - Fix test failures of SessionStore if comformant Promise handling is applied. r=JanH

1. Improve BrowserApp._handleTabClosed() to remove Tab correctly if a new tab is
   added during "TabClose" dispatching.
2. Resolve "load" event in next event tick to simulate visiting a different page
   properly, so the session history will be added correctly.
This commit is contained in:
Bevis Tseng 2018-01-08 14:18:50 +08:00
Родитель f4cfe8596a
Коммит fc6a4ac122
3 изменённых файлов: 14 добавлений и 7 удалений

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

@ -1279,6 +1279,9 @@ var BrowserApp = {
}
}
// Retrieve updated tabIndex again for the removal because the index could
// be changed if a new tab is added by the event listener.
tabIndex = this._tabs.indexOf(aTab);
aTab.destroy();
this._tabs.splice(tabIndex, 1);
},

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

@ -5,7 +5,7 @@ function fuzzyEquals(a, b) {
return (Math.abs(a - b) < 1e-6);
}
function promiseBrowserEvent(browser, eventType) {
function promiseBrowserEvent(browser, eventType, options) {
return new Promise((resolve) => {
function handle(event) {
// Since we'll be redirecting, don't make assumptions about the given URL and the loaded URL
@ -15,7 +15,11 @@ function promiseBrowserEvent(browser, eventType) {
}
info("Received event " + eventType + " from browser");
browser.removeEventListener(eventType, handle, true);
resolve(event);
if (options && options.resolveAtNextTick) {
setTimeout(() => resolve(event), 0);
} else {
resolve(event);
}
}
browser.addEventListener(eventType, handle, true);

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

@ -96,7 +96,7 @@ add_task(function* test_formdata() {
// Create a new tab.
let tab = gBrowserApp.addTab(URL);
let browser = tab.browser;
yield promiseBrowserEvent(browser, "load");
yield promiseBrowserEvent(browser, "load", { resolveAtNextTick: true });
// Modify form data.
setInputValue(browser, {id: "txt", value: OUTER_VALUE});
@ -151,7 +151,7 @@ add_task(function* test_formdata2() {
// Create a new tab.
let tab = gBrowserApp.addTab(URL);
let browser = tab.browser;
yield promiseBrowserEvent(browser, "load");
yield promiseBrowserEvent(browser, "load", { resolveAtNextTick: true });
// Modify form data.
setInputValue(browser, {id: "txt", value: OUTER_VALUE});
@ -172,7 +172,7 @@ add_task(function* test_formdata2() {
// Restore the closed tab.
let closedTabData = ss.getClosedTabs(gChromeWin)[0];
let browser = ss.undoCloseTab(gChromeWin, closedTabData);
yield promiseBrowserEvent(browser, "load");
yield promiseBrowserEvent(browser, "load", { resolveAtNextTick: true });
// Check the form data.
is(getInputValue(browser, {id: "txt"}), OUTER_VALUE, "outer value restored correctly");
@ -211,7 +211,7 @@ add_task(function* test_formdata_navigation() {
// Create a new tab.
let tab = gBrowserApp.addTab(URL);
let browser = tab.browser;
yield promiseBrowserEvent(browser, "load");
yield promiseBrowserEvent(browser, "load", { resolveAtNextTick: true });
// Modify form data.
setInputValue(browser, {id: "txt", value: OUTER_VALUE});
@ -251,7 +251,7 @@ add_task(function* test_formdata_navigation() {
// Restore the closed tab.
let closedTabData = ss.getClosedTabs(gChromeWin)[0];
let browser = ss.undoCloseTab(gChromeWin, closedTabData);
yield promiseBrowserEvent(browser, "load");
yield promiseBrowserEvent(browser, "load", { resolveAtNextTick: true });
// Check the form data.
is(getInputValue(browser, {id: "txt"}), OUTER_VALUE, "outer value restored correctly");