Bug 1726240 - [devtools] Wait for target switching in RDM navigation helpers r=Honza

Wait for target available to be fully processed by responsive UI in tests

Differential Revision: https://phabricator.services.mozilla.com/D123326
This commit is contained in:
Julian Descottes 2021-08-25 07:11:58 +00:00
parent eb00182e36
commit 077a35b79f
3 changed files with 31 additions and 7 deletions

View File

@ -607,9 +607,15 @@ function waitForViewportScroll(ui) {
}
async function load(browser, url) {
const loaded = BrowserTestUtils.browserLoaded(browser, false, null, false);
const onBrowserLoaded = BrowserTestUtils.browserLoaded(
browser,
false,
null,
false
);
const onTargetSwitch = waitForTargetSwitch(browser);
BrowserTestUtils.loadURI(browser, url);
await loaded;
await Promise.all([onBrowserLoaded, onTargetSwitch]);
}
/**
@ -622,15 +628,32 @@ async function reloadViewport(ui) {
}
function back(browser) {
const shown = waitForPageShow(browser);
const promises = [waitForTargetSwitch(browser), waitForPageShow(browser)];
browser.goBack();
return shown;
return Promise.all(promises);
}
function forward(browser) {
const shown = waitForPageShow(browser);
const promises = [waitForTargetSwitch(browser), waitForPageShow(browser)];
browser.goForward();
return shown;
return Promise.all(promises);
}
async function waitForTargetSwitch(browser) {
const targetSwitchDisabled = !isServerTargetSwitchingEnabled();
if (targetSwitchDisabled) {
// If server-side target switching is disabled assume no target switch.
return;
}
const tab = gBrowser.getTabForBrowser(browser);
const ui = ResponsiveUIManager.getResponsiveUIForTab(tab);
if (!ui) {
return;
}
info("Waiting for Responsive UI target switch");
await ui.once("responsive-ui-target-switch-done");
}
function addDeviceForTest(device) {

View File

@ -1049,6 +1049,7 @@ class ResponsiveUI {
}
await this.restoreActorState(isTargetSwitching);
this.emitForTests("responsive-ui-target-switch-done");
}
}
// This just needed to setup watching for network resources,

View File

@ -642,7 +642,7 @@ function isFissionEnabled() {
}
function isServerTargetSwitchingEnabled() {
return Services.prefs.getBoolPref("devtools.target-switching.server.enabled");
return Services.prefs.getBoolPref(TARGET_SWITCHING_PREF);
}
/**