browser_net_block-extensions.js (2648B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /** 7 * Test the requests that are blocked by extenstions show correctly. 8 */ 9 add_task(async function () { 10 const extensionName = "Test Blocker"; 11 info(`Start loading the ${extensionName} extension...`); 12 const extension = ExtensionTestUtils.loadExtension({ 13 manifest: { 14 name: extensionName, 15 permissions: ["*://example.com/", "webRequest", "webRequestBlocking"], 16 }, 17 useAddonManager: "temporary", 18 background() { 19 // eslint-disable-next-line no-undef 20 browser.webRequest.onBeforeRequest.addListener( 21 () => { 22 return { 23 cancel: true, 24 }; 25 }, 26 { 27 urls: [ 28 "https://example.com/browser/devtools/client/netmonitor/test/request_0", 29 ], 30 }, 31 ["blocking"] 32 ); 33 // eslint-disable-next-line no-undef 34 browser.test.sendMessage("ready"); 35 }, 36 }); 37 38 await extension.startup(); 39 await extension.awaitMessage("ready"); 40 41 const { tab, monitor } = await initNetMonitor(HTTPS_SINGLE_GET_URL, { 42 requestCount: 2, 43 }); 44 45 const { document } = monitor.panelWin; 46 47 info("Starting test... "); 48 49 const waitForNetworkEventsToComplete = waitForNetworkEvents(monitor, 2); 50 const waitForRequestsToRender = waitForDOM( 51 document, 52 ".requests-list-row-group" 53 ); 54 const waitForReload = BrowserTestUtils.browserLoaded(tab.linkedBrowser); 55 56 await reloadBrowser(); 57 58 await Promise.all([ 59 waitForNetworkEventsToComplete, 60 waitForRequestsToRender, 61 waitForReload, 62 ]); 63 64 // Find the request list item that matches the blocked url 65 const request = document.querySelector( 66 "td.requests-list-url[title*=request_0]" 67 ).parentNode; 68 69 info("Assert the blocked request"); 70 ok( 71 !!request.querySelector(".requests-list-status .status-code-blocked-icon"), 72 "The request blocked status icon is visible" 73 ); 74 75 is( 76 request.querySelector(".requests-list-status .requests-list-status-code") 77 .title, 78 "Blocked", 79 "The request status title is 'Blocked'" 80 ); 81 82 is( 83 request.querySelector(".requests-list-type").innerText, 84 "", 85 "The request shows no type" 86 ); 87 88 is( 89 request.querySelector(".requests-list-transferred").innerText, 90 `Blocked By ${extensionName}`, 91 "The request shows the blocking extension name" 92 ); 93 94 is( 95 request.querySelector(".requests-list-size").innerText, 96 "", 97 "The request shows no size" 98 ); 99 100 await teardown(monitor); 101 info(`Unloading the ${extensionName} extension`); 102 await extension.unload(); 103 });