browser_styleeditor_fetch-from-netmonitor.js (2674B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // A test to ensure Style Editor only issues 1 request for each stylesheet (instead of 2) 7 // by using the cache on the platform. 8 9 const EMPTY_TEST_URL = TEST_BASE_HTTPS + "doc_empty.html"; 10 const TEST_URL = TEST_BASE_HTTPS + "doc_fetch_from_netmonitor.html"; 11 12 add_task(async function () { 13 info("Opening netmonitor"); 14 // Navigate first to an empty document in order to: 15 // * avoid introducing a cross process navigation when calling navigateTo() 16 // * properly wait for request updates when calling navigateTo, while showToolbox 17 // won't necessarily wait for all pending requests. (If we were loading TEST_URL 18 // in the tab, we might have pending updates in the netmonitor which won't be 19 // awaited for by showToolbox) 20 const tab = await addTab(EMPTY_TEST_URL); 21 const toolbox = await gDevTools.showToolboxForTab(tab, { 22 toolId: "netmonitor", 23 }); 24 const monitor = toolbox.getPanel("netmonitor"); 25 const { store, windowRequire } = monitor.panelWin; 26 const Actions = windowRequire("devtools/client/netmonitor/src/actions/index"); 27 const { getSortedRequests } = windowRequire( 28 "devtools/client/netmonitor/src/selectors/index" 29 ); 30 31 store.dispatch(Actions.batchEnable(false)); 32 33 info("Navigating to test page"); 34 await navigateTo(TEST_URL); 35 36 info("Opening Style Editor"); 37 const styleeditor = await toolbox.selectTool("styleeditor"); 38 const ui = styleeditor.UI; 39 40 info("Waiting for the sources to be loaded."); 41 await ui.editors[0].getSourceEditor(); 42 await ui.selectStyleSheet(ui.editors[1].styleSheet); 43 await ui.editors[1].getSourceEditor(); 44 45 // Wait till there is 4 requests in Netmonitor store. 46 await waitUntil(() => getSortedRequests(store.getState()).length == 4); 47 48 info("Checking Netmonitor contents."); 49 const shortRequests = []; 50 const longRequests = []; 51 const hugeRequests = []; 52 for (const item of getSortedRequests(store.getState())) { 53 if (item.url.endsWith("doc_short_string.css")) { 54 shortRequests.push(item); 55 } 56 if (item.url.endsWith("doc_long_string.css")) { 57 longRequests.push(item); 58 } 59 if (item.url.endsWith("sjs_huge-css-server.sjs")) { 60 hugeRequests.push(item); 61 } 62 } 63 64 is( 65 shortRequests.length, 66 1, 67 "Got one request for doc_short_string.css after Style Editor was loaded." 68 ); 69 is( 70 longRequests.length, 71 1, 72 "Got one request for doc_long_string.css after Style Editor was loaded." 73 ); 74 75 is( 76 hugeRequests.length, 77 1, 78 "Got one requests for sjs_huge-css-server.sjs after Style Editor was loaded." 79 ); 80 });