browser_net_persistent_logs.js (2358B)
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 network monitor leaks on initialization and sudden destruction. 8 * You can also use this initialization format as a template for other tests. 9 */ 10 11 add_task(async function () { 12 const { monitor } = await initNetMonitor(SINGLE_GET_URL, { 13 requestCount: 1, 14 }); 15 info("Starting test... "); 16 17 const { document, store, windowRequire } = monitor.panelWin; 18 const Actions = windowRequire("devtools/client/netmonitor/src/actions/index"); 19 20 store.dispatch(Actions.batchEnable(false)); 21 22 Services.prefs.setBoolPref("devtools.netmonitor.persistlog", false); 23 24 await reloadAndWait(); 25 26 // Using waitUntil in the test is necessary to ensure all requests are added correctly. 27 // Because reloadAndWait call may catch early uncaught requests from initNetMonitor, so 28 // the actual number of requests after reloadAndWait could be wrong since all requests 29 // haven't finished. 30 await waitUntil( 31 () => document.querySelectorAll(".request-list-item").length === 2 32 ); 33 is( 34 document.querySelectorAll(".request-list-item").length, 35 2, 36 "The request list should have two items at this point." 37 ); 38 39 await reloadAndWait(); 40 41 await waitUntil( 42 () => document.querySelectorAll(".request-list-item").length === 2 43 ); 44 // Since the reload clears the log, we still expect two requests in the log 45 is( 46 document.querySelectorAll(".request-list-item").length, 47 2, 48 "The request list should still have two items at this point." 49 ); 50 51 // Now we toggle the persistence logs on 52 Services.prefs.setBoolPref("devtools.netmonitor.persistlog", true); 53 54 await reloadAndWait(); 55 56 await waitUntil( 57 () => document.querySelectorAll(".request-list-item").length === 4 58 ); 59 // Since we togged the persistence logs, we expect four items after the reload 60 is( 61 document.querySelectorAll(".request-list-item").length, 62 4, 63 "The request list should now have four items at this point." 64 ); 65 66 Services.prefs.setBoolPref("devtools.netmonitor.persistlog", false); 67 return teardown(monitor); 68 69 /** 70 * Reload the page and wait for 2 GET requests. 71 */ 72 async function reloadAndWait() { 73 const wait = waitForNetworkEvents(monitor, 2); 74 await reloadBrowser(); 75 return wait; 76 } 77 });