Bug 1610377 - [remote] Wait for history index selected when using gBrowser.gotoIndex(). r=remote-protocol-reviewers,maja_zf

Differential Revision: https://phabricator.services.mozilla.com/D62589

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Henrik Skupin 2020-02-13 08:56:04 +00:00
parent ed04cb5f4b
commit 6d33e6a9bf
3 changed files with 64 additions and 15 deletions

View File

@ -3,6 +3,10 @@
"use strict"; "use strict";
const { SessionStore } = ChromeUtils.import(
"resource:///modules/sessionstore/SessionStore.jsm"
);
add_task(async function singleEntry({ client }) { add_task(async function singleEntry({ client }) {
const { Page } = client; const { Page } = client;
@ -35,7 +39,7 @@ add_task(async function multipleEntriesWithFirstIndex({ client }) {
await loadURL(entry.userTypedURL); await loadURL(entry.userTypedURL);
} }
gBrowser.gotoIndex(0); await gotoHistoryIndex(0);
const history = await Page.getNavigationHistory(); const history = await Page.getNavigationHistory();
assertHistoryEntries(history, data, 0); assertHistoryEntries(history, data, 0);

View File

@ -65,7 +65,7 @@ add_task(async function oneEntryForwardInHistory({ client }) {
await loadURL(entry.userTypedURL); await loadURL(entry.userTypedURL);
} }
gBrowser.gotoIndex(0); await gotoHistoryIndex(0);
const { currentIndex, entries } = await Page.getNavigationHistory(); const { currentIndex, entries } = await Page.getNavigationHistory();
await Page.navigateToHistoryEntry({ entryId: entries[currentIndex + 1].id }); await Page.navigateToHistoryEntry({ entryId: entries[currentIndex + 1].id });
@ -109,7 +109,7 @@ add_task(async function toLastEntryInHistory({ client }) {
await loadURL(entry.userTypedURL); await loadURL(entry.userTypedURL);
} }
gBrowser.gotoIndex(0); await gotoHistoryIndex(0);
const { entries } = await Page.getNavigationHistory(); const { entries } = await Page.getNavigationHistory();
await Page.navigateToHistoryEntry({ await Page.navigateToHistoryEntry({

View File

@ -10,6 +10,15 @@ Services.scriptloader.loadSubScript(
this this
); );
const {
clearInterval,
clearTimeout,
setInterval,
setTimeout
} = ChromeUtils.import(
"resource://gre/modules/Timer.jsm"
);
function assertHistoryEntries(history, expectedData, expectedIndex) { function assertHistoryEntries(history, expectedData, expectedIndex) {
const { currentIndex, entries } = history; const { currentIndex, entries } = history;
@ -40,6 +49,21 @@ function assertHistoryEntries(history, expectedData, expectedIndex) {
}); });
} }
function generateHistoryData(count) {
const data = [];
for (let index = 0; index < count; index++) {
const url = toDataURL(`<head><title>Test ${index + 1}</title></head>`);
data.push({
url,
userTypedURL: url,
title: `Test ${index + 1}`,
});
}
return data;
}
async function getContentSize() { async function getContentSize() {
return SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => { return SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
const docEl = content.document.documentElement; const docEl = content.document.documentElement;
@ -64,17 +88,38 @@ async function getViewportSize() {
}); });
} }
function generateHistoryData(count) { function getCurrentHistoryIndex() {
const data = []; return new Promise(resolve => {
SessionStore.getSessionHistory(window.gBrowser.selectedTab, history => {
for (let index = 0; index < count; index++) { resolve(history.index);
const url = toDataURL(`<head><title>Test ${index + 1}</title></head>`);
data.push({
url,
userTypedURL: url,
title: `Test ${index + 1}`,
}); });
} });
}
return data;
async function gotoHistoryIndex(index) {
gBrowser.gotoIndex(index);
return new Promise((resolve, reject) => {
let intervalId, timeoutId;
const onTimer = async type => {
switch (type) {
case "check":
const currentIndex = await getCurrentHistoryIndex();
if (currentIndex == index) {
clearInterval(intervalId);
clearTimeout(timeoutId);
resolve();
}
break;
case "timeout":
clearInterval(intervalId);
reject(new Error(`History navigation to index ${index} failed`));
break;
}
};
timeoutId = setTimeout(onTimer, 1000, "timeout");
intervalId = setInterval(onTimer, 10, "check");
});
} }