browser_net_requests_with_empty_response.js (1678B)
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 that the request for a 404 where no content is sent. 8 */ 9 10 function setupServer() { 11 const httpServer = createTestHTTPServer(); 12 httpServer.registerContentType("html", "text/html"); 13 14 httpServer.registerPathHandler("/status", function (request, response) { 15 response.setStatusLine(request.httpVersion, 404, "Not Found"); 16 }); 17 return httpServer; 18 } 19 add_task(async function () { 20 Services.prefs.setBoolPref( 21 "browser.http.blank_page_with_error_response.enabled", 22 false 23 ); 24 const httpServer = setupServer(); 25 const port = httpServer.identity.primaryPort; 26 const URL = `http://localhost:${port}/status`; 27 28 const { monitor } = await initNetMonitor(URL, { 29 requestCount: 1, 30 waitForLoad: false, 31 }); 32 info("Starting test... "); 33 34 const { document, store, windowRequire } = monitor.panelWin; 35 const Actions = windowRequire("devtools/client/netmonitor/src/actions/index"); 36 37 store.dispatch(Actions.batchEnable(false)); 38 39 const wait = waitForNetworkEvents(monitor, 1, { expectedEventTimings: 1 }); 40 reloadBrowser({ waitForLoad: false }); 41 await wait; 42 43 const firstItem = document.querySelectorAll(".request-list-item")[0]; 44 await waitUntil( 45 () => firstItem.querySelector(".requests-list-status").innerText !== "" 46 ); 47 is( 48 firstItem.querySelector(".requests-list-url").innerText, 49 URL, 50 "The url in the displayed request is correct" 51 ); 52 is( 53 firstItem.querySelector(".requests-list-status").innerText, 54 "404", 55 "The request status code is correct" 56 ); 57 58 await teardown(monitor); 59 });