From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../inspector/test/browser_inspector_startup.js | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 devtools/client/inspector/test/browser_inspector_startup.js (limited to 'devtools/client/inspector/test/browser_inspector_startup.js') diff --git a/devtools/client/inspector/test/browser_inspector_startup.js b/devtools/client/inspector/test/browser_inspector_startup.js new file mode 100644 index 0000000000..7953b5c473 --- /dev/null +++ b/devtools/client/inspector/test/browser_inspector_startup.js @@ -0,0 +1,84 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Tests that the inspector loads early without waiting for load events. + +const server = createTestHTTPServer(); + +// Register a slow image handler so we can simulate a long time between +// a reload and the load event firing. +server.registerContentType("gif", "image/gif"); +function onPageResourceRequest() { + return new Promise(done => { + server.registerPathHandler("/slow.gif", function (metadata, response) { + info("Image has been requested"); + response.processAsync(); + done(response); + }); + }); +} + +// Test page load events. +const TEST_URL = + "data:text/html," + + "" + + "" + + "" + + "

Page loading slowly

" + + "" + + "" + + ""; + +add_task(async function () { + const { inspector, tab } = await openInspectorForURL("about:blank"); + + const domContentLoaded = waitForLinkedBrowserEvent(tab, "DOMContentLoaded"); + const pageLoaded = waitForLinkedBrowserEvent(tab, "load"); + + const markupLoaded = inspector.once("markuploaded"); + const onRequest = onPageResourceRequest(); + + info("Navigate to the slow loading page"); + const target = inspector.toolbox.target; + await target.navigateTo({ url: TEST_URL }); + + info("Wait for request made to the image"); + const response = await onRequest; + + // The request made to the image shouldn't block the DOMContentLoaded event + info("Wait for DOMContentLoaded"); + await domContentLoaded; + + // Nor does it prevent the inspector from loading + info("Wait for markup-loaded"); + await markupLoaded; + + ok(inspector.markup, "There is a markup view"); + is(inspector.markup._elt.children.length, 1, "The markup view is rendering"); + is( + await contentReadyState(tab), + "interactive", + "Page is still loading but the inspector is ready" + ); + + // Ends page load by unblocking the image request + response.finish(); + + // We should then receive the page load event + info("Wait for load"); + await pageLoaded; +}); + +function waitForLinkedBrowserEvent(tab, event) { + return BrowserTestUtils.waitForContentEvent(tab.linkedBrowser, event, true); +} + +function contentReadyState(tab) { + return SpecialPowers.spawn(tab.linkedBrowser, [], function () { + return content.document.readyState; + }); +} -- cgit v1.2.3