test_IPProtection.js (2027B)
1 /* Any copyright is dedicated to the Public Domain. 2 https://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const { IPProtection } = ChromeUtils.importESModule( 7 "moz-src:///browser/components/ipprotection/IPProtection.sys.mjs" 8 ); 9 10 /** 11 * Tests that we can set a state and pass it to a fake element. 12 */ 13 add_task(function test_update_icon_status() { 14 const browser = Services.appShell.createWindowlessBrowser(true); 15 const principal = Services.scriptSecurityManager.getSystemPrincipal(); 16 browser.docShell.createAboutBlankDocumentViewer(principal, principal); 17 const document = browser.docShell.docViewer.DOMDocument; 18 let fakeToolbarItem = document.createXULElement("toolbaritem"); 19 20 Assert.equal( 21 fakeToolbarItem.classList.length, 22 0, 23 "Toolbaritem class list should be empty" 24 ); 25 26 let ipProtectionOn = { 27 isActive: true, 28 isError: false, 29 }; 30 IPProtection.updateIconStatus(fakeToolbarItem, ipProtectionOn); 31 32 Assert.ok( 33 fakeToolbarItem.classList.contains("ipprotection-on"), 34 "Toolbaritem classlist should include ipprotection-on" 35 ); 36 37 // isError should override the active status even if isActive is set to true 38 let ipProtectionError = { 39 isActive: true, 40 isError: true, 41 }; 42 IPProtection.updateIconStatus(fakeToolbarItem, ipProtectionError); 43 44 Assert.ok( 45 fakeToolbarItem.classList.contains("ipprotection-error"), 46 "Toolbaritem classlist should include ipprotection-error" 47 ); 48 Assert.ok( 49 !fakeToolbarItem.classList.contains("ipprotection-on"), 50 "Toolbaritem classlist should not include ipprotection-on" 51 ); 52 53 let ipProtectionOff = { 54 isActive: false, 55 isError: false, 56 }; 57 IPProtection.updateIconStatus(fakeToolbarItem, ipProtectionOff); 58 59 Assert.ok( 60 !fakeToolbarItem.classList.contains("ipprotection-error"), 61 "Toolbaritem classlist should not include ipprotection-error" 62 ); 63 Assert.ok( 64 !fakeToolbarItem.classList.contains("ipprotection-on"), 65 "Toolbaritem classlist should not include ipprotection-on" 66 ); 67 });