diff --git a/devtools/client/responsive/test/browser/browser.ini b/devtools/client/responsive/test/browser/browser.ini index 5f68af1133c7..332e05dd90e4 100644 --- a/devtools/client/responsive/test/browser/browser.ini +++ b/devtools/client/responsive/test/browser/browser.ini @@ -53,6 +53,7 @@ tags = devtools webextensions [browser_mouse_resize.js] [browser_navigation.js] [browser_network_throttling.js] +[browser_old-rdm_reload_conditions.js] [browser_orientationchange_event.js] [browser_page_redirection.js] skip-if = os == "linux" diff --git a/devtools/client/responsive/test/browser/browser_old-rdm_reload_conditions.js b/devtools/client/responsive/test/browser/browser_old-rdm_reload_conditions.js new file mode 100644 index 000000000000..36135eb5773e --- /dev/null +++ b/devtools/client/responsive/test/browser/browser_old-rdm_reload_conditions.js @@ -0,0 +1,38 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Verify that reload conditions restore old-RDM's tab to the proper state. +// Bug 1585097: This test will be deleted once browser UI-enabled RDM is shipped to stable. + +const TEST_URL = "data:text/html;charset=utf-8,"; + +addRDMTask( + null, + async function() { + info("Ensure reload conditions for touch simulation are enabled."); + reloadOnTouchChange(true); + + const tab = await addTab(TEST_URL); + const { ui } = await openRDM(tab); + await toggleTouchSimulation(ui); + + info("Wait for the UI's target to reload when opening RDM."); + await once(ui.currentTarget, "navigate"); + ok(true, "RDM's tab target reloaded"); + + info("Wait for the tab to reload when closing RDM."); + const reloaded = BrowserTestUtils.waitForContentEvent( + tab.linkedBrowser, + "load", + true + ); + await closeRDM(tab); + await reloaded; + ok(true, "Tab reloaded"); + + reloadOnTouchChange(false); + }, + { usingBrowserUI: false, onlyPrefAndTask: true } +); diff --git a/devtools/client/responsive/ui.js b/devtools/client/responsive/ui.js index 4403cb4b8978..b07d6a7a98b2 100644 --- a/devtools/client/responsive/ui.js +++ b/devtools/client/responsive/ui.js @@ -350,6 +350,8 @@ class ResponsiveUI { (options.reason === "TabClose" || options.reason === "BeforeTabRemotenessChange")); + let currentTarget; + // Ensure init has finished before starting destroy if (!isTabContentDestroying) { await this.inited; @@ -365,6 +367,10 @@ class ResponsiveUI { this.hideBrowserUI(); } + // Save reference to tab target before RDM stops listening to it. Will need it if + // the tab has to be reloaded to remove the emulated settings created by RDM. + currentTarget = this.currentTarget; + this.targetList.unwatchTargets( [this.targetList.TYPES.FRAME], this.onTargetAvailable @@ -416,8 +422,8 @@ class ResponsiveUI { reloadNeeded |= (await this.updateTouchSimulation()) && this.reloadOnChange("touchSimulation"); - if (reloadNeeded) { - this.getViewportBrowser().reload(); + if (reloadNeeded && currentTarget) { + await currentTarget.reload(); } } @@ -604,7 +610,7 @@ class ResponsiveUI { (await this.updateTouchSimulation(touch)) && this.reloadOnChange("touchSimulation"); if (reloadNeeded) { - this.getViewportBrowser().reload(); + this.reloadBrowser(); } // Used by tests this.emit("device-changed"); @@ -631,7 +637,7 @@ class ResponsiveUI { (await this.updateTouchSimulation(enabled)) && this.reloadOnChange("touchSimulation"); if (reloadNeeded) { - this.getViewportBrowser().reload(); + this.reloadBrowser(); } // Used by tests this.emit("touch-simulation-changed"); @@ -643,7 +649,7 @@ class ResponsiveUI { (await this.updateUserAgent(userAgent)) && this.reloadOnChange("userAgent"); if (reloadNeeded) { - this.getViewportBrowser().reload(); + this.reloadBrowser(); } this.emit("user-agent-changed"); } @@ -670,7 +676,7 @@ class ResponsiveUI { (await this.updateTouchSimulation()) && this.reloadOnChange("touchSimulation"); if (reloadNeeded) { - this.getViewportBrowser().reload(); + this.reloadBrowser(); } // Used by tests this.emit("device-association-removed"); @@ -911,7 +917,7 @@ class ResponsiveUI { this.reloadOnChange("userAgent"); } if (reloadNeeded) { - this.getViewportBrowser().reload(); + this.reloadBrowser(); } } @@ -1197,6 +1203,13 @@ class ResponsiveUI { }); } } + + /** + * Reload the current tab. + */ + async reloadBrowser() { + await this.currentTarget.reload(); + } } module.exports = ResponsiveUI;