mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
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:
parent
ed04cb5f4b
commit
6d33e6a9bf
@ -3,6 +3,10 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
const { SessionStore } = ChromeUtils.import(
|
||||
"resource:///modules/sessionstore/SessionStore.jsm"
|
||||
);
|
||||
|
||||
add_task(async function singleEntry({ client }) {
|
||||
const { Page } = client;
|
||||
|
||||
@ -35,7 +39,7 @@ add_task(async function multipleEntriesWithFirstIndex({ client }) {
|
||||
await loadURL(entry.userTypedURL);
|
||||
}
|
||||
|
||||
gBrowser.gotoIndex(0);
|
||||
await gotoHistoryIndex(0);
|
||||
|
||||
const history = await Page.getNavigationHistory();
|
||||
assertHistoryEntries(history, data, 0);
|
||||
|
@ -65,7 +65,7 @@ add_task(async function oneEntryForwardInHistory({ client }) {
|
||||
await loadURL(entry.userTypedURL);
|
||||
}
|
||||
|
||||
gBrowser.gotoIndex(0);
|
||||
await gotoHistoryIndex(0);
|
||||
|
||||
const { currentIndex, entries } = await Page.getNavigationHistory();
|
||||
await Page.navigateToHistoryEntry({ entryId: entries[currentIndex + 1].id });
|
||||
@ -109,7 +109,7 @@ add_task(async function toLastEntryInHistory({ client }) {
|
||||
await loadURL(entry.userTypedURL);
|
||||
}
|
||||
|
||||
gBrowser.gotoIndex(0);
|
||||
await gotoHistoryIndex(0);
|
||||
|
||||
const { entries } = await Page.getNavigationHistory();
|
||||
await Page.navigateToHistoryEntry({
|
||||
|
@ -10,6 +10,15 @@ Services.scriptloader.loadSubScript(
|
||||
this
|
||||
);
|
||||
|
||||
const {
|
||||
clearInterval,
|
||||
clearTimeout,
|
||||
setInterval,
|
||||
setTimeout
|
||||
} = ChromeUtils.import(
|
||||
"resource://gre/modules/Timer.jsm"
|
||||
);
|
||||
|
||||
function assertHistoryEntries(history, expectedData, expectedIndex) {
|
||||
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() {
|
||||
return SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
|
||||
const docEl = content.document.documentElement;
|
||||
@ -64,17 +88,38 @@ async function getViewportSize() {
|
||||
});
|
||||
}
|
||||
|
||||
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}`,
|
||||
function getCurrentHistoryIndex() {
|
||||
return new Promise(resolve => {
|
||||
SessionStore.getSessionHistory(window.gBrowser.selectedTab, history => {
|
||||
resolve(history.index);
|
||||
});
|
||||
}
|
||||
|
||||
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");
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user