Bug 1945801 - Use origin instead of webExposedOrigin for ComputeAlertName r=asuth
This value is for partitioning between origins and thus should use GetOrigin. Differential Revision: https://phabricator.services.mozilla.com/D236713
This commit is contained in:
@@ -153,8 +153,10 @@ nsresult GetOrigin(nsIPrincipal* aPrincipal, nsString& aOrigin) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
MOZ_TRY(
|
||||
nsContentUtils::GetWebExposedOriginSerialization(aPrincipal, aOrigin));
|
||||
nsAutoCString origin;
|
||||
MOZ_TRY(aPrincipal->GetOrigin(origin));
|
||||
|
||||
CopyUTF8toUTF16(origin, aOrigin);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -8,3 +8,6 @@ support-files = [
|
||||
"empty.html",
|
||||
"file_userContextId_openWindow.js",
|
||||
]
|
||||
|
||||
["browser_userContextId_tag.js"]
|
||||
support-files = ["empty.html"]
|
||||
|
||||
103
dom/notification/test/browser/browser_userContextId_tag.js
Normal file
103
dom/notification/test/browser/browser_userContextId_tag.js
Normal file
@@ -0,0 +1,103 @@
|
||||
const URI =
|
||||
"https://example.com/browser/dom/notification/test/browser/empty.html";
|
||||
|
||||
const MOCK_CID = Components.ID("{2a0f83c4-8818-4914-a184-f1172b4eaaa7}");
|
||||
const SYSTEM_CID = Components.ID("{a0ccaaf8-09da-44d8-b250-9ac3e93c8117}");
|
||||
const ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/alerts-service;1";
|
||||
|
||||
// Set up a mock alert service that works as a MITM observer, to observe alert
|
||||
// topics while still using the system alerts service (as we depend on system
|
||||
// backend for tag processing)
|
||||
|
||||
let alertsService = Cc["@mozilla.org/alerts-service;1"].getService(
|
||||
Ci.nsIAlertsService
|
||||
);
|
||||
|
||||
let mockAlertsService = {
|
||||
history: [],
|
||||
|
||||
showAlert(alert, alertListener) {
|
||||
alertsService.showAlert(alert, (subject, topic, data) => {
|
||||
this.history.push({ subject, topic, data });
|
||||
return alertListener.observe(subject, topic, data);
|
||||
});
|
||||
},
|
||||
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIAlertsService"]),
|
||||
|
||||
createInstance(aIID) {
|
||||
return this.QueryInterface(aIID);
|
||||
},
|
||||
};
|
||||
|
||||
registerCleanupFunction(() => {
|
||||
const registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
|
||||
registrar.unregisterFactory(MOCK_CID, mockAlertsService);
|
||||
registrar.registerFactory(SYSTEM_CID, "", ALERTS_SERVICE_CONTRACT_ID, null);
|
||||
});
|
||||
|
||||
add_setup(() => {
|
||||
Components.manager
|
||||
.QueryInterface(Ci.nsIComponentRegistrar)
|
||||
.registerFactory(
|
||||
MOCK_CID,
|
||||
"alerts service",
|
||||
ALERTS_SERVICE_CONTRACT_ID,
|
||||
mockAlertsService
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function no_tag_collision_between_containers() {
|
||||
// Open tabs on two different containers
|
||||
|
||||
let tab1 = BrowserTestUtils.addTab(gBrowser, URI, {
|
||||
userContextId: 3,
|
||||
});
|
||||
let browser1 = gBrowser.getBrowserForTab(tab1);
|
||||
|
||||
let tab2 = BrowserTestUtils.addTab(gBrowser, URI, {
|
||||
userContextId: 4,
|
||||
});
|
||||
let browser2 = gBrowser.getBrowserForTab(tab2);
|
||||
|
||||
gBrowser.selectedTab = tab1;
|
||||
tab1.ownerGlobal.focus();
|
||||
await BrowserTestUtils.browserLoaded(browser1);
|
||||
|
||||
gBrowser.selectedTab = tab2;
|
||||
tab2.ownerGlobal.focus();
|
||||
await BrowserTestUtils.browserLoaded(browser2);
|
||||
|
||||
// Open notifications on each tab with the same tag
|
||||
|
||||
await Promise.all(
|
||||
[browser1, browser2].map(browser =>
|
||||
SpecialPowers.spawn(browser, [], async () => {
|
||||
await SpecialPowers.pushPermissions([
|
||||
{
|
||||
type: "desktop-notification",
|
||||
allow: SpecialPowers.Services.perms.ALLOW_ACTION,
|
||||
context: content.document,
|
||||
},
|
||||
]);
|
||||
|
||||
const notification = new content.Notification("foo", { tag: "bar" });
|
||||
const { promise, resolve, reject } = Promise.withResolvers();
|
||||
notification.onshow = () => resolve();
|
||||
notification.onerror = () => reject("onerror");
|
||||
notification.onclose = () => {};
|
||||
return promise;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
// The notifications should not interfere across containers
|
||||
|
||||
is(mockAlertsService.history.length, 2, "Should observe two alert topics");
|
||||
for (const entry of mockAlertsService.history) {
|
||||
is(entry.topic, "alertshow", "Should only observe alertshow");
|
||||
}
|
||||
|
||||
BrowserTestUtils.removeTab(tab1);
|
||||
BrowserTestUtils.removeTab(tab2);
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
Reference in New Issue
Block a user