diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /devtools/client/debugger/test/mochitest/browser_dbg-link-reload.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/debugger/test/mochitest/browser_dbg-link-reload.js')
-rw-r--r-- | devtools/client/debugger/test/mochitest/browser_dbg-link-reload.js | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/devtools/client/debugger/test/mochitest/browser_dbg-link-reload.js b/devtools/client/debugger/test/mochitest/browser_dbg-link-reload.js new file mode 100644 index 0000000000..c374fc6bba --- /dev/null +++ b/devtools/client/debugger/test/mochitest/browser_dbg-link-reload.js @@ -0,0 +1,65 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ + +/** + * Test reload via an href link, which refers to the same document. + * It seems to cause different codepath compared to F5. + */ + +"use strict"; + +add_task(async function () { + const dbg = await initDebugger( + "doc-reload-link.html", + "doc-reload-link.html" + ); + + info("Add a breakpoint that will be hit on reload"); + await addBreakpoint(dbg, "doc-reload-link.html", 3); + + for (let i = 0; i < 5; i++) { + const onReloaded = waitForReload(dbg.commands); + + info( + "Reload via a link, this causes special race condition different from F5" + ); + await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () { + const reloadLink = content.document.querySelector("a"); + reloadLink.click(); + }); + + info("Wait for paused\n"); + await waitForPaused(dbg); + + info("Check paused location\n"); + const source = findSource(dbg, "doc-reload-link.html"); + assertPausedAtSourceAndLine(dbg, source.id, 3); + + await resume(dbg); + + info("Wait for completion of the page load"); + // This help ensure that the page loaded correctly and prevent pending request at teardown + await onReloaded; + } +}); + +async function waitForReload(commands) { + let resolve; + const onReloaded = new Promise(r => (resolve = r)); + const { resourceCommand } = commands; + const { DOCUMENT_EVENT } = resourceCommand.TYPES; + const onAvailable = resources => { + if (resources.find(resource => resource.name == "dom-complete")) { + resourceCommand.unwatchResources([DOCUMENT_EVENT], { onAvailable }); + resolve(); + } + }; + // Wait for watchResources completion before reloading, otherwise we might miss the dom-complete event + // if watchResources is still pending while the reload already started and finished loading the document early. + await resourceCommand.watchResources([DOCUMENT_EVENT], { + onAvailable, + ignoreExistingResources: true, + }); + return onReloaded; +} |