browser_markup_load_01.js (2366B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 /* eslint-disable mozilla/no-arbitrary-setTimeout */ 4 5 "use strict"; 6 7 // Tests that selecting an element with the 'Inspect Element' context 8 // menu during a page reload doesn't cause the markup view to become empty. 9 // See https://bugzilla.mozilla.org/show_bug.cgi?id=1036324 10 11 const server = createTestHTTPServer(); 12 13 // Register a slow image handler so we can simulate a long time between 14 // a reload and the load event firing. 15 server.registerContentType("gif", "image/gif"); 16 server.registerPathHandler("/slow.gif", function (metadata, response) { 17 info("Image has been requested"); 18 response.processAsync(); 19 setTimeout(() => { 20 info("Image is responding"); 21 response.finish(); 22 }, 500); 23 }); 24 25 // Test page load events. 26 const TEST_URL = 27 "data:text/html," + 28 "<!DOCTYPE html>" + 29 "<head><meta charset='utf-8' /></head>" + 30 "<body>" + 31 "<p>Slow script</p>" + 32 "<img src='http://localhost:" + 33 server.identity.primaryPort + 34 "/slow.gif' />" + 35 "</body>" + 36 "</html>"; 37 38 add_task(async function () { 39 const { inspector, tab } = await openInspectorForURL(TEST_URL); 40 41 const domContentLoaded = waitForLinkedBrowserEvent(tab, "DOMContentLoaded"); 42 const pageLoaded = waitForLinkedBrowserEvent(tab, "load"); 43 44 ok(inspector.markup, "There is a markup view"); 45 46 // Select an element while the tab is in the middle of a slow reload. 47 // Do not await here because we interact with the page during navigation. 48 const onToolboxNavigated = navigateTo(TEST_URL); 49 50 info("Wait for DOMContentLoaded"); 51 await domContentLoaded; 52 53 info("Inspect element via context menu"); 54 const markupLoaded = inspector.once("markuploaded"); 55 await clickOnInspectMenuItem("img"); 56 57 info("Wait for load"); 58 await pageLoaded; 59 60 info("Wait for toolbox navigation"); 61 await onToolboxNavigated; 62 63 info("Wait for markup-loaded after element inspection"); 64 await markupLoaded; 65 info("Wait for multiple children updates after element inspection"); 66 await waitForMultipleChildrenUpdates(inspector); 67 68 ok(inspector.markup, "There is a markup view"); 69 is(inspector.markup._elt.children.length, 1, "The markup view is rendering"); 70 }); 71 72 function waitForLinkedBrowserEvent(tab, event) { 73 return BrowserTestUtils.waitForContentEvent(tab.linkedBrowser, event, true); 74 }