browser_inspector_startup.js (2530B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Tests that the inspector loads early without waiting for load events. 7 8 const server = createTestHTTPServer(); 9 10 // Register a slow image handler so we can simulate a long time between 11 // a reload and the load event firing. 12 server.registerContentType("gif", "image/gif"); 13 function onPageResourceRequest() { 14 return new Promise(done => { 15 server.registerPathHandler("/slow.gif", function (metadata, response) { 16 info("Image has been requested"); 17 response.processAsync(); 18 done(response); 19 }); 20 }); 21 } 22 23 // Test page load events. 24 const TEST_URL = 25 "data:text/html," + 26 "<!DOCTYPE html>" + 27 "<head><meta charset='utf-8' /></head>" + 28 "<body>" + 29 "<p>Page loading slowly</p>" + 30 "<img src='http://localhost:" + 31 server.identity.primaryPort + 32 "/slow.gif' />" + 33 "</body>" + 34 "</html>"; 35 36 add_task(async function () { 37 const { inspector, tab } = await openInspectorForURL("about:blank"); 38 39 const domContentLoaded = waitForLinkedBrowserEvent(tab, "DOMContentLoaded"); 40 const pageLoaded = waitForLinkedBrowserEvent(tab, "load"); 41 42 const markupLoaded = inspector.once("markuploaded"); 43 const onRequest = onPageResourceRequest(); 44 45 info("Navigate to the slow loading page"); 46 // Avoid waiting for the new document to load as it is blocked via onRequest's promise. 47 await inspector.toolbox.commands.targetCommand.navigateTo(TEST_URL, false); 48 49 info("Wait for request made to the image"); 50 const response = await onRequest; 51 52 // The request made to the image shouldn't block the DOMContentLoaded event 53 info("Wait for DOMContentLoaded"); 54 await domContentLoaded; 55 56 // Nor does it prevent the inspector from loading 57 info("Wait for markup-loaded"); 58 await markupLoaded; 59 60 ok(inspector.markup, "There is a markup view"); 61 is(inspector.markup._elt.children.length, 1, "The markup view is rendering"); 62 is( 63 await contentReadyState(tab), 64 "interactive", 65 "Page is still loading but the inspector is ready" 66 ); 67 68 // Ends page load by unblocking the image request 69 response.finish(); 70 71 // We should then receive the page load event 72 info("Wait for load"); 73 await pageLoaded; 74 }); 75 76 function waitForLinkedBrowserEvent(tab, event) { 77 return BrowserTestUtils.waitForContentEvent(tab.linkedBrowser, event, true); 78 } 79 80 function contentReadyState(tab) { 81 return SpecialPowers.spawn(tab.linkedBrowser, [], function () { 82 return content.document.readyState; 83 }); 84 }