browser_extension_update_background_noprompt.js (4391B)
1 const { AddonManagerPrivate } = ChromeUtils.importESModule( 2 "resource://gre/modules/AddonManager.sys.mjs" 3 ); 4 5 const { AddonTestUtils } = ChromeUtils.importESModule( 6 "resource://testing-common/AddonTestUtils.sys.mjs" 7 ); 8 9 AddonTestUtils.initMochitest(this); 10 AddonTestUtils.hookAMTelemetryEvents(); 11 12 const ID_PERMS = "update_perms@tests.mozilla.org"; 13 const ID_ORIGINS = "update_origins@tests.mozilla.org"; 14 15 function getBadgeStatus() { 16 let menuButton = document.getElementById("PanelUI-menu-button"); 17 return menuButton.getAttribute("badge-status"); 18 } 19 20 // Set some prefs that apply to all the tests in this file 21 add_setup(async function () { 22 await SpecialPowers.pushPrefEnv({ 23 set: [ 24 ["test.wait300msAfterTabSwitch", true], 25 // We don't have pre-pinned certificates for the local mochitest server 26 ["extensions.install.requireBuiltInCerts", false], 27 ["extensions.update.requireBuiltInCerts", false], 28 // Don't require the extensions to be signed 29 ["xpinstall.signatures.required", false], 30 ], 31 }); 32 33 // Navigate away from the initial page so that about:addons always 34 // opens in a new tab during tests 35 BrowserTestUtils.startLoadingURIString( 36 gBrowser.selectedBrowser, 37 "about:robots" 38 ); 39 await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser); 40 41 registerCleanupFunction(async function () { 42 // Return to about:blank when we're done 43 BrowserTestUtils.startLoadingURIString( 44 gBrowser.selectedBrowser, 45 "about:blank" 46 ); 47 await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, { 48 wantLoad: "about:blank", 49 }); 50 }); 51 }); 52 53 // Helper function to test an upgrade that should not show a prompt 54 async function testNoPrompt(origUrl, id) { 55 await SpecialPowers.pushPrefEnv({ 56 set: [ 57 // Turn on background updates 58 ["extensions.update.enabled", true], 59 60 // Point updates to the local mochitest server 61 [ 62 "extensions.update.background.url", 63 `${BASE}/browser_webext_update.json`, 64 ], 65 ], 66 }); 67 Services.fog.testResetFOG(); 68 69 // Install version 1.0 of the test extension 70 let addon = await promiseInstallAddon(origUrl); 71 72 ok(addon, "Addon was installed"); 73 74 let sawPopup = false; 75 PopupNotifications.panel.addEventListener( 76 "popupshown", 77 () => (sawPopup = true), 78 { once: true } 79 ); 80 81 // Trigger an update check and wait for the update to be applied. 82 let updatePromise = waitForUpdate(addon); 83 AddonManagerPrivate.backgroundUpdateCheck(); 84 await updatePromise; 85 86 // There should be no notifications about the update 87 is(getBadgeStatus(), null, "Should not have addon alert badge"); 88 89 await gCUITestUtils.openMainMenu(); 90 let addons = PanelUI.addonNotificationContainer; 91 is(addons.children.length, 0, "Have 0 updates in the PanelUI menu"); 92 await gCUITestUtils.hideMainMenu(); 93 94 ok(!sawPopup, "Should not have seen permissions notification"); 95 96 addon = await AddonManager.getAddonByID(id); 97 is(addon.version, "2.0", "Update should have applied"); 98 99 await addon.uninstall(); 100 await SpecialPowers.popPrefEnv(); 101 102 // Test that the expected telemetry events have been recorded (and that they do not 103 // include the permission_prompt event). 104 const amEvents = AddonTestUtils.getAMTelemetryEvents(); 105 const updateEventsSteps = amEvents 106 .filter(evt => { 107 return evt.method === "update" && evt.extra && evt.extra.addon_id == id; 108 }) 109 .map(evt => { 110 return evt.extra.step; 111 }); 112 113 let expected = [ 114 "started", 115 "download_started", 116 "download_completed", 117 "completed", 118 ]; 119 // Expect telemetry events related to a completed update with no permissions_prompt event. 120 Assert.deepEqual( 121 expected, 122 updateEventsSteps, 123 "Got the steps from the collected telemetry events" 124 ); 125 126 Assert.deepEqual( 127 expected, 128 AddonTestUtils.getAMGleanEvents("update", { addon_id: id }).map( 129 e => e.step 130 ), 131 "Got the steps from the collected Glean events." 132 ); 133 } 134 135 // Test that an update that adds new non-promptable permissions is just 136 // applied without showing a notification dialog. 137 add_task(() => 138 testNoPrompt(`${BASE}/browser_webext_update_perms1.xpi`, ID_PERMS) 139 ); 140 141 // Test that an update that narrows origin permissions is just applied without 142 // showing a notification promt 143 add_task(() => 144 testNoPrompt(`${BASE}/browser_webext_update_origins1.xpi`, ID_ORIGINS) 145 );