|
| 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 file URL requests are properly displayed in the network monitor. |
| 8 | + */ |
| 9 | +add_task(async function test_file_uris() { |
| 10 | + const TEST_URI = Services.io.newFileURI( |
| 11 | + new FileUtils.File(getTestFilePath("html_file_channel.html")) |
| 12 | + ).spec; |
| 13 | + |
| 14 | + const { monitor } = await initNetMonitor(TEST_URI, { |
| 15 | + requestCount: 2, |
| 16 | + waitForLoad: false, |
| 17 | + }); |
| 18 | + info("Starting test... "); |
| 19 | + |
| 20 | + const { document, store, windowRequire } = monitor.panelWin; |
| 21 | + const Actions = windowRequire("devtools/client/netmonitor/src/actions/index"); |
| 22 | + |
| 23 | + store.dispatch(Actions.batchEnable(false)); |
| 24 | + |
| 25 | + const wait = waitForNetworkEvents(monitor, 2); |
| 26 | + reloadBrowser({ waitForLoad: false }); |
| 27 | + await wait; |
| 28 | + |
| 29 | + const htmlEntry = document.querySelectorAll(".request-list-item")[0]; |
| 30 | + ok( |
| 31 | + htmlEntry |
| 32 | + .querySelector(".requests-list-url") |
| 33 | + .innerText.endsWith("file_channel.html"), |
| 34 | + "The url for the html request is correct" |
| 35 | + ); |
| 36 | + is( |
| 37 | + htmlEntry.querySelector(".requests-list-scheme").innerText, |
| 38 | + "file", |
| 39 | + "The scheme for the html request is correct" |
| 40 | + ); |
| 41 | + ok(hasValidSize(htmlEntry), "The request shows a valid size"); |
| 42 | + |
| 43 | + const imageEntry = document.querySelectorAll(".request-list-item")[1]; |
| 44 | + ok( |
| 45 | + imageEntry |
| 46 | + .querySelector(".requests-list-url") |
| 47 | + .innerText.endsWith("test-image.png"), |
| 48 | + "The url for the image request is correct" |
| 49 | + ); |
| 50 | + is( |
| 51 | + imageEntry.querySelector(".requests-list-scheme").innerText, |
| 52 | + "file", |
| 53 | + "The scheme for the image request is correct" |
| 54 | + ); |
| 55 | + ok(hasValidSize(imageEntry), "The request shows a valid size"); |
| 56 | + |
| 57 | + const onResponseContent = monitor.panelWin.api.once( |
| 58 | + TEST_EVENTS.RECEIVED_RESPONSE_CONTENT |
| 59 | + ); |
| 60 | + |
| 61 | + info("Check that a valid image is loaded in the response tab"); |
| 62 | + const waitDOM = waitForDOM(document, "#response-panel .response-image"); |
| 63 | + store.dispatch(Actions.selectRequestByIndex(1)); |
| 64 | + document.querySelector("#response-tab").click(); |
| 65 | + const [imageNode] = await waitDOM; |
| 66 | + await once(imageNode, "load"); |
| 67 | + await onResponseContent; |
| 68 | + |
| 69 | + info("Verify we only have 2 requests, and the chrome request was not listed"); |
| 70 | + const sortedRequests = getSortedRequests(store.getState()); |
| 71 | + is(sortedRequests.length, 2, "Only 2 requests are displayed"); |
| 72 | + |
| 73 | + await teardown(monitor); |
| 74 | +}); |
| 75 | + |
| 76 | +function hasValidSize(request) { |
| 77 | + const VALID_SIZE_RE = /^\d+(\.\d+)? \w+/; |
| 78 | + return VALID_SIZE_RE.test( |
| 79 | + request.querySelector(".requests-list-size").innerText |
| 80 | + ); |
| 81 | +} |
0 commit comments