browser_net_statistics-edge-case.js (4017B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /** 7 * Tests if the statistics panel displays correctly for a page containing 8 * requests which have been known to create issues in the past for this Panel: 9 * - cached image (http-on-resource-cache-response) requests in the content 10 * process 11 * - long polling requests remaining open for a long time 12 */ 13 14 add_task(async function () { 15 // We start the netmonitor on a basic page to avoid opening the panel on 16 // an incomplete polling request. 17 const { monitor } = await initNetMonitor(SIMPLE_URL, { 18 enableCache: true, 19 }); 20 21 // The navigation should lead to 3 requests (html + image + long polling). 22 // Additionally we will have a 4th request to call unblock(), so there are 4 23 // requests in total. 24 // However we need to make sure that unblock() is only called once the long 25 // polling request has been started, so we wait for network events in 2 sets: 26 // - first the 3 initial requests, with only 2 completing 27 // - then the unblock request, bundled with the completion of the long polling 28 let onNetworkEvents = waitForNetworkEvents(monitor, 3, { 29 expectedPayloadReady: 2, 30 expectedEventTimings: 2, 31 }); 32 33 // Here we explicitly do not await on navigateTo. 34 // The netmonitor will not emit "reloaded" if there are pending requests, 35 // so if the long polling request already started, we will never receive the 36 // event. Waiting for the network events should be sufficient here. 37 const onNavigationCompleted = navigateTo(STATISTICS_EDGE_CASE_URL); 38 39 info("Wait for the 3 first network events (initial)"); 40 await onNetworkEvents; 41 42 // Prepare to wait for the second set of network events. 43 onNetworkEvents = waitForNetworkEvents(monitor, 1, { 44 expectedPayloadReady: 2, 45 expectedEventTimings: 2, 46 }); 47 48 // Calling unblock() should allow for the polling request to be displayed and 49 // to complete, so we can consistently expect 2 events and 2 timings. 50 info("Call unblock()"); 51 await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => 52 content.wrappedJSObject.unblock() 53 ); 54 55 info("Wait for polling and unblock (initial)"); 56 await onNetworkEvents; 57 58 info("Wait for the navigation to complete"); 59 await onNavigationCompleted; 60 61 // Opening the statistics panel will trigger a reload, expect the same requests 62 // again, we use the same pattern to wait for network events. 63 onNetworkEvents = waitForNetworkEvents(monitor, 3, { 64 expectedPayloadReady: 2, 65 expectedEventTimings: 2, 66 }); 67 68 info("Open the statistics panel"); 69 const panel = monitor.panelWin; 70 const { document, store, windowRequire, connector } = panel; 71 const Actions = windowRequire("devtools/client/netmonitor/src/actions/index"); 72 store.dispatch(Actions.openStatistics(connector, true)); 73 74 await waitFor( 75 () => !!document.querySelector(".statistics-panel"), 76 "The statistics panel is displayed" 77 ); 78 79 await waitFor( 80 () => 81 document.querySelectorAll( 82 ".table-chart-container:not([placeholder=true])" 83 ).length == 2, 84 "Two real table charts appear to be rendered correctly." 85 ); 86 87 info("Close statistics panel"); 88 store.dispatch(Actions.openStatistics(connector, false)); 89 90 await waitFor( 91 () => !!document.querySelector(".monitor-panel"), 92 "The regular netmonitor panel is displayed" 93 ); 94 info("Wait for the 3 first network events (after opening statistics panel)"); 95 await onNetworkEvents; 96 97 onNetworkEvents = waitForNetworkEvents(monitor, 1, { 98 expectedPayloadReady: 2, 99 expectedEventTimings: 2, 100 }); 101 102 info("Call unblock()"); 103 await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => 104 content.wrappedJSObject.unblock() 105 ); 106 107 // We need to cleanly wait for all events to be finished, otherwise the UI 108 // will throw many unhandled promise rejections. 109 info("Wait for polling and unblock (after opening statistics panel)"); 110 await onNetworkEvents; 111 112 await teardown(monitor); 113 });