| 
2 | 2 | 
 
  | 
3 | 3 | const INSTALL_PAGE = `${BASE}/file_install_extensions.html`;  | 
4 | 4 | const INSTALL_XPI = `${BASE}/browser_webext_permissions.xpi`;  | 
 | 5 | +const ID = "permissions@test.mozilla.org"; // Add-on ID of INSTALL_XPI.  | 
5 | 6 | 
 
  | 
6 | 7 | // With the new dialog design both wildcards and non-wildcards host  | 
7 | 8 | // permissions are expected to be shown as a single permission entry  | 
@@ -68,7 +69,7 @@ add_task(async function test_tab_switch_dismiss() {  | 
68 | 69 |   BrowserTestUtils.removeTab(switchTo);  | 
69 | 70 |   await installCanceled;  | 
70 | 71 | 
 
  | 
71 |  | -  let addon = await AddonManager.getAddonByID("permissions@test.mozilla.org");  | 
 | 72 | +  let addon = await AddonManager.getAddonByID(ID);  | 
72 | 73 |   is(addon, null, "Extension is not installed");  | 
73 | 74 | 
 
  | 
74 | 75 |   BrowserTestUtils.removeTab(tab);  | 
@@ -114,10 +115,70 @@ add_task(async function test_add_tab_by_user_and_switch() {  | 
114 | 115 |   await listener.canceledPromise;  | 
115 | 116 |   info("Extension installation is canceled");  | 
116 | 117 | 
 
  | 
117 |  | -  let addon = await AddonManager.getAddonByID("permissions@test.mozilla.org");  | 
 | 118 | +  let addon = await AddonManager.getAddonByID(ID);  | 
118 | 119 |   is(addon, null, "Extension is not installed");  | 
119 | 120 | 
 
  | 
120 | 121 |   AddonManager.removeInstallListener(listener);  | 
121 | 122 |   BrowserTestUtils.removeTab(tab);  | 
122 | 123 |   BrowserTestUtils.removeTab(newTab);  | 
123 | 124 | });  | 
 | 125 | + | 
 | 126 | +// Regression test for https://bugzilla.mozilla.org/show_bug.cgi?id=1974419  | 
 | 127 | +// ExtensionPermissions.get() lazily populates the StartupCache. This method  | 
 | 128 | +// should not be used when an extension is not installed, to avoid persisting  | 
 | 129 | +// permission data for a non-installed extension.  | 
 | 130 | +add_task(async function test_no_permissions_stored_after_dismiss() {  | 
 | 131 | +  // This part could fail if any of the tests before (which also trigger  | 
 | 132 | +  // installation of INSTALL_XPI) somehow populate the permissions.  | 
 | 133 | +  Assert.deepEqual(  | 
 | 134 | +    await getCachedPermissions(ID),  | 
 | 135 | +    null,  | 
 | 136 | +    "ExtensionPermissions should not contain entry before installation"  | 
 | 137 | +  );  | 
 | 138 | + | 
 | 139 | +  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, INSTALL_PAGE);  | 
 | 140 | + | 
 | 141 | +  let installCanceled = new Promise(resolve => {  | 
 | 142 | +    let listener = {  | 
 | 143 | +      onInstallCancelled() {  | 
 | 144 | +        AddonManager.removeInstallListener(listener);  | 
 | 145 | +        resolve();  | 
 | 146 | +      },  | 
 | 147 | +    };  | 
 | 148 | +    AddonManager.addInstallListener(listener);  | 
 | 149 | +  });  | 
 | 150 | + | 
 | 151 | +  SpecialPowers.spawn(gBrowser.selectedBrowser, [INSTALL_XPI], function (url) {  | 
 | 152 | +    content.wrappedJSObject.installMozAM(url);  | 
 | 153 | +  });  | 
 | 154 | + | 
 | 155 | +  const panel = await promisePopupNotificationShown("addon-webext-permissions");  | 
 | 156 | + | 
 | 157 | +  let privateBrowsingCheckbox = panel.querySelector(  | 
 | 158 | +    ".webext-perm-privatebrowsing > moz-checkbox"  | 
 | 159 | +  );  | 
 | 160 | +  ok(  | 
 | 161 | +    BrowserTestUtils.isVisible(privateBrowsingCheckbox),  | 
 | 162 | +    "Private browsing checkbox is present in install prompt"  | 
 | 163 | +  );  | 
 | 164 | +  Assert.deepEqual(  | 
 | 165 | +    await getCachedPermissions(ID),  | 
 | 166 | +    null,  | 
 | 167 | +    "ExtensionPermissions should not be written to during installation"  | 
 | 168 | +  );  | 
 | 169 | + | 
 | 170 | +  // Cancel installation.  | 
 | 171 | +  panel.secondaryButton.click();  | 
 | 172 | +  await installCanceled;  | 
 | 173 | + | 
 | 174 | +  let addon = await AddonManager.getAddonByID(ID);  | 
 | 175 | +  is(addon, null, "Extension is not installed");  | 
 | 176 | + | 
 | 177 | +  Assert.deepEqual(  | 
 | 178 | +    await getCachedPermissions(ID),  | 
 | 179 | +    null,  | 
 | 180 | +    "ExtensionPermissions should not be written to after installation"  | 
 | 181 | +  );  | 
 | 182 | + | 
 | 183 | +  BrowserTestUtils.removeTab(tab);  | 
 | 184 | +});  | 
0 commit comments