browser_displayURI.js (4539B)
1 /* 2 * Make sure that the correct origin is shown for permission prompts. 3 */ 4 5 async function check(contentTask, options = {}) { 6 await BrowserTestUtils.withNewTab( 7 "https://test1.example.com/", 8 async function (browser) { 9 let popupShownPromise = waitForNotificationPanel(); 10 await SpecialPowers.spawn(browser, [], contentTask); 11 let panel = await popupShownPromise; 12 let notification = panel.children[0]; 13 let body = notification.querySelector(".popup-notification-body"); 14 ok( 15 body.innerHTML.includes("example.com"), 16 "Check that at least the eTLD+1 is present in the markup" 17 ); 18 } 19 ); 20 21 let channel = NetUtil.newChannel({ 22 uri: getRootDirectory(gTestPath), 23 loadUsingSystemPrincipal: true, 24 }); 25 channel = channel.QueryInterface(Ci.nsIFileChannel); 26 27 await BrowserTestUtils.withNewTab( 28 channel.file.path, 29 async function (browser) { 30 let popupShownPromise = waitForNotificationPanel(); 31 await SpecialPowers.spawn(browser, [], contentTask); 32 let panel = await popupShownPromise; 33 let notification = panel.children[0]; 34 let body = notification.querySelector(".popup-notification-body"); 35 ok( 36 body.innerHTML.includes("local file"), 37 `file:// URIs should be displayed as local file.` 38 ); 39 } 40 ); 41 42 if (!options.skipOnExtension) { 43 // Test the scenario also on the extension page if not explicitly unsupported 44 // (e.g. an extension page can't be navigated on a blob URL). 45 let extension = ExtensionTestUtils.loadExtension({ 46 manifest: { 47 name: "Test Extension Name", 48 }, 49 background() { 50 let { browser } = this; 51 browser.test.sendMessage( 52 "extension-tab-url", 53 browser.runtime.getURL("extension-tab-page.html") 54 ); 55 }, 56 files: { 57 "extension-tab-page.html": `<!DOCTYPE html><html><body></body></html>`, 58 }, 59 }); 60 61 await extension.startup(); 62 let extensionURI = await extension.awaitMessage("extension-tab-url"); 63 64 await BrowserTestUtils.withNewTab(extensionURI, async function (browser) { 65 let popupShownPromise = waitForNotificationPanel(); 66 await SpecialPowers.spawn(browser, [], contentTask); 67 let panel = await popupShownPromise; 68 let notification = panel.children[0]; 69 let body = notification.querySelector(".popup-notification-body"); 70 ok( 71 body.innerHTML.includes("Test Extension Name"), 72 "Check the the extension name is present in the markup" 73 ); 74 }); 75 76 await extension.unload(); 77 } 78 } 79 80 add_setup(async function () { 81 await SpecialPowers.pushPrefEnv({ 82 set: [ 83 ["media.navigator.permission.fake", true], 84 ["media.navigator.permission.force", true], 85 ["dom.vr.always_support_vr", true], 86 ], 87 }); 88 }); 89 90 add_task(async function test_displayURI_geo() { 91 await check(async function () { 92 content.navigator.geolocation.getCurrentPosition(() => {}); 93 }); 94 }); 95 96 const kVREnabled = SpecialPowers.getBoolPref("dom.vr.enabled"); 97 if (kVREnabled) { 98 add_task(async function test_displayURI_xr() { 99 await check(async function () { 100 content.navigator.getVRDisplays(); 101 }); 102 }); 103 } 104 105 add_task(async function test_displayURI_camera() { 106 await check(async function () { 107 content.navigator.mediaDevices.getUserMedia({ video: true, fake: true }); 108 }); 109 }); 110 111 add_task(async function test_displayURI_geo_blob() { 112 await check( 113 async function () { 114 let text = 115 "<script>navigator.geolocation.getCurrentPosition(() => {})</script>"; 116 let blob = new Blob([text], { type: "text/html" }); 117 let url = content.URL.createObjectURL(blob); 118 content.location.href = url; 119 }, 120 { skipOnExtension: true } 121 ); 122 }); 123 124 if (kVREnabled) { 125 add_task(async function test_displayURI_xr_blob() { 126 await check( 127 async function () { 128 let text = "<script>navigator.getVRDisplays()</script>"; 129 let blob = new Blob([text], { type: "text/html" }); 130 let url = content.URL.createObjectURL(blob); 131 content.location.href = url; 132 }, 133 { skipOnExtension: true } 134 ); 135 }); 136 } 137 138 add_task(async function test_displayURI_camera_blob() { 139 await check( 140 async function () { 141 let text = 142 "<script>navigator.mediaDevices.getUserMedia({video: true, fake: true})</script>"; 143 let blob = new Blob([text], { type: "text/html" }); 144 let url = content.URL.createObjectURL(blob); 145 content.location.href = url; 146 }, 147 { skipOnExtension: true } 148 ); 149 });