browser_check_identity_state_pdf.js (2311B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 /* 5 * Tests that sites opened via the PDF viewer have the correct identity state. 6 */ 7 8 "use strict"; 9 10 function testIdentityMode(uri, expectedState, message) { 11 return BrowserTestUtils.withNewTab(uri, () => { 12 is(getIdentityMode(), expectedState, message); 13 }); 14 } 15 16 add_setup(async function () { 17 await SpecialPowers.pushPrefEnv({ 18 set: [["test.wait300msAfterTabSwitch", true]], 19 }); 20 }); 21 22 /** 23 * Test site identity state for PDFs served via file URI. 24 */ 25 add_task(async function test_pdf_fileURI() { 26 let path = getTestFilePath("./file_pdf.pdf"); 27 info("path:" + path); 28 29 await testIdentityMode( 30 path, 31 "localResource", 32 "Identity should be localResource for a PDF served via file URI" 33 ); 34 }); 35 36 /** 37 * Test site identity state for PDFs served via blob URI. 38 */ 39 add_task(async function test_pdf_blobURI() { 40 let uri = 41 getRootDirectory(gTestPath).replace( 42 "chrome://mochitests/content", 43 "https://example.com" 44 ) + "file_pdf_blob.html"; 45 46 await BrowserTestUtils.withNewTab(uri, async browser => { 47 let newTabOpened = BrowserTestUtils.waitForNewTab(gBrowser, null, true); 48 49 await BrowserTestUtils.synthesizeMouseAtCenter("a", {}, browser); 50 await newTabOpened; 51 52 is( 53 getIdentityMode(), 54 "localResource", 55 "Identity should be localResource for a PDF served via blob URI" 56 ); 57 58 BrowserTestUtils.removeTab(gBrowser.selectedTab); 59 }); 60 }); 61 62 /** 63 * Test site identity state for PDFs served via HTTP. 64 */ 65 add_task(async function test_pdf_http() { 66 let expectedIdentity = Services.prefs.getBoolPref( 67 "security.insecure_connection_text.enabled" 68 ) 69 ? "notSecure notSecureText" 70 : "notSecure"; 71 const PDF_URI_NOSCHEME = 72 getRootDirectory(gTestPath).replace( 73 "chrome://mochitests/content", 74 "example.com" 75 ) + "file_pdf.pdf"; 76 77 await testIdentityMode( 78 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 79 "http://" + PDF_URI_NOSCHEME, 80 expectedIdentity, 81 `Identity should be ${expectedIdentity} for a PDF served via HTTP.` 82 ); 83 await testIdentityMode( 84 "https://" + PDF_URI_NOSCHEME, 85 "verifiedDomain", 86 "Identity should be verifiedDomain for a PDF served via HTTPS." 87 ); 88 });