From 5be1c5612cf3b0a9f6b59e926af05171eeba8ebd Mon Sep 17 00:00:00 2001 From: Brian Hackett Date: Sun, 13 Oct 2019 19:10:14 +0000 Subject: [PATCH] Bug 1580104 - Wait for recording to initialize before loading URLs, r=jlast. Differential Revision: https://phabricator.services.mozilla.com/D49090 --HG-- extra : moz-landing-system : lando --- devtools/client/webreplay/menu.js | 7 +++++-- .../webreplay/mochitest/browser_dbg_rr_record.js | 6 +----- .../webreplay/mochitest/browser_dbg_rr_replay-01.js | 6 +----- .../webreplay/mochitest/browser_dbg_rr_replay-02.js | 6 +----- .../webreplay/mochitest/browser_dbg_rr_replay-03.js | 6 +----- devtools/client/webreplay/mochitest/head.js | 12 +++++++++--- devtools/server/actors/replay/replay.js | 12 ++++++++++++ 7 files changed, 30 insertions(+), 25 deletions(-) diff --git a/devtools/client/webreplay/menu.js b/devtools/client/webreplay/menu.js index 356c929954c6..3ad5168f41fa 100644 --- a/devtools/client/webreplay/menu.js +++ b/devtools/client/webreplay/menu.js @@ -44,8 +44,11 @@ function ReloadAndRecordTab() { newFrameloader: true, remoteType: E10SUtils.DEFAULT_REMOTE_TYPE, }); - gBrowser.loadURI(url, { - triggeringPrincipal: gBrowser.selectedBrowser.contentPrincipal, + Services.ppmm.addMessageListener("RecordingInitialized", function listener() { + Services.ppmm.removeMessageListener("RecordingInitialized", listener); + gBrowser.loadURI(url, { + triggeringPrincipal: gBrowser.selectedBrowser.contentPrincipal, + }); }); Services.telemetry.scalarAdd("devtools.webreplay.reload_recording", 1); } diff --git a/devtools/client/webreplay/mochitest/browser_dbg_rr_record.js b/devtools/client/webreplay/mochitest/browser_dbg_rr_record.js index e569ec8760d4..eb0bfad7fc38 100644 --- a/devtools/client/webreplay/mochitest/browser_dbg_rr_record.js +++ b/devtools/client/webreplay/mochitest/browser_dbg_rr_record.js @@ -6,11 +6,7 @@ // Test basic recording of a tab without any debugging. add_task(async function() { - const recordingTab = BrowserTestUtils.addTab(gBrowser, null, { - recordExecution: "*", - }); - gBrowser.selectedTab = recordingTab; - openTrustedLinkIn(EXAMPLE_URL + "doc_rr_basic.html", "current"); + const recordingTab = await openRecordingTab("doc_rr_basic.html"); await once(Services.ppmm, "RecordingFinished"); await gBrowser.removeTab(recordingTab); diff --git a/devtools/client/webreplay/mochitest/browser_dbg_rr_replay-01.js b/devtools/client/webreplay/mochitest/browser_dbg_rr_replay-01.js index b6ec5a5088d1..13eb45ebce7a 100644 --- a/devtools/client/webreplay/mochitest/browser_dbg_rr_replay-01.js +++ b/devtools/client/webreplay/mochitest/browser_dbg_rr_replay-01.js @@ -7,11 +7,7 @@ // Basic test for saving a recording and then replaying it in a new tab. add_task(async function() { const recordingFile = newRecordingFile(); - const recordingTab = BrowserTestUtils.addTab(gBrowser, null, { - recordExecution: "*", - }); - gBrowser.selectedTab = recordingTab; - openTrustedLinkIn(EXAMPLE_URL + "doc_rr_basic.html", "current"); + const recordingTab = await openRecordingTab("doc_rr_basic.html"); await once(Services.ppmm, "RecordingFinished"); const remoteTab = recordingTab.linkedBrowser.frameLoader.remoteTab; diff --git a/devtools/client/webreplay/mochitest/browser_dbg_rr_replay-02.js b/devtools/client/webreplay/mochitest/browser_dbg_rr_replay-02.js index 9c95be6151e0..1af71a660558 100644 --- a/devtools/client/webreplay/mochitest/browser_dbg_rr_replay-02.js +++ b/devtools/client/webreplay/mochitest/browser_dbg_rr_replay-02.js @@ -9,11 +9,7 @@ add_task(async function() { waitForExplicitFinish(); const recordingFile = newRecordingFile(); - const recordingTab = BrowserTestUtils.addTab(gBrowser, null, { - recordExecution: "*", - }); - gBrowser.selectedTab = recordingTab; - openTrustedLinkIn(EXAMPLE_URL + "doc_rr_continuous.html", "current"); + const recordingTab = await openRecordingTab("doc_rr_continuous.html"); let dbg = await attachDebugger(recordingTab); diff --git a/devtools/client/webreplay/mochitest/browser_dbg_rr_replay-03.js b/devtools/client/webreplay/mochitest/browser_dbg_rr_replay-03.js index 353da78b75e6..474bfa5877ea 100644 --- a/devtools/client/webreplay/mochitest/browser_dbg_rr_replay-03.js +++ b/devtools/client/webreplay/mochitest/browser_dbg_rr_replay-03.js @@ -10,11 +10,7 @@ add_task(async function() { await pushPref("devtools.recordreplay.enableRewinding", false); const recordingFile = newRecordingFile(); - const recordingTab = BrowserTestUtils.addTab(gBrowser, null, { - recordExecution: "*", - }); - gBrowser.selectedTab = recordingTab; - openTrustedLinkIn(EXAMPLE_URL + "doc_rr_basic.html", "current"); + const recordingTab = await openRecordingTab("doc_rr_basic.html"); await once(Services.ppmm, "RecordingFinished"); const remoteTab = recordingTab.linkedBrowser.frameLoader.remoteTab; diff --git a/devtools/client/webreplay/mochitest/head.js b/devtools/client/webreplay/mochitest/head.js index 2fb01710db8e..18ab6ec17948 100644 --- a/devtools/client/webreplay/mochitest/head.js +++ b/devtools/client/webreplay/mochitest/head.js @@ -27,6 +27,14 @@ async function attachDebugger(tab) { return { ...dbg, tab, threadFront }; } +async function openRecordingTab(url) { + const tab = BrowserTestUtils.addTab(gBrowser, null, { recordExecution: "*" }); + gBrowser.selectedTab = tab; + await once(Services.ppmm, "RecordingInitialized"); + openTrustedLinkIn(EXAMPLE_URL + url, "current"); + return tab; +} + async function attachRecordingDebugger( url, { waitForRecording, disableLogging, skipInterrupt } = {} @@ -35,9 +43,7 @@ async function attachRecordingDebugger( await pushPref("devtools.recordreplay.logging", true); } - const tab = BrowserTestUtils.addTab(gBrowser, null, { recordExecution: "*" }); - gBrowser.selectedTab = tab; - openTrustedLinkIn(EXAMPLE_URL + url, "current"); + const tab = await openRecordingTab(url); if (waitForRecording) { await once(Services.ppmm, "RecordingFinished"); diff --git a/devtools/server/actors/replay/replay.js b/devtools/server/actors/replay/replay.js index 63ed84a27ca2..84fc1959ae44 100644 --- a/devtools/server/actors/replay/replay.js +++ b/devtools/server/actors/replay/replay.js @@ -80,6 +80,18 @@ dbg.onNewGlobalObject = function(global) { } }; +// If we are recording, we need to notify the UI process when the content global +// has been initialized in this process, which will allow URLs to be loaded. +Services.obs.addObserver( + { + observe(subject, topic, data) { + assert(topic == "content-document-global-created"); + Services.cpmm.sendAsyncMessage("RecordingInitialized"); + }, + }, + "content-document-global-created" +); + /////////////////////////////////////////////////////////////////////////////// // Utilities ///////////////////////////////////////////////////////////////////////////////