From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../test/xpinstall/browser_containers.js | 116 +++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 toolkit/mozapps/extensions/test/xpinstall/browser_containers.js (limited to 'toolkit/mozapps/extensions/test/xpinstall/browser_containers.js') diff --git a/toolkit/mozapps/extensions/test/xpinstall/browser_containers.js b/toolkit/mozapps/extensions/test/xpinstall/browser_containers.js new file mode 100644 index 0000000000..4aa6db40f0 --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpinstall/browser_containers.js @@ -0,0 +1,116 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +"use strict"; + +const { AddonTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/AddonTestUtils.sys.mjs" +); + +AddonTestUtils.initMochitest(this); + +const MY_CONTEXT = 2; +let gDidSeeChannel = false; + +function check_channel(subject) { + if (!(subject instanceof Ci.nsIHttpChannel)) { + return; + } + let channel = subject.QueryInterface(Ci.nsIHttpChannel); + let uri = channel.URI; + if (!uri || !uri.spec.endsWith("amosigned.xpi")) { + return; + } + gDidSeeChannel = true; + ok(true, "Got request for " + uri.spec); + + let loadInfo = channel.loadInfo; + is( + loadInfo.originAttributes.userContextId, + MY_CONTEXT, + "Got expected usercontextid" + ); +} +// ---------------------------------------------------------------------------- +// Tests we send the right cookies when installing through an InstallTrigger call +function test() { + // This test depends on InstallTrigger.install availability. + setInstallTriggerPrefs(); + + Harness.installConfirmCallback = confirm_install; + Harness.installEndedCallback = install_ended; + Harness.installsCompletedCallback = finish_test; + Harness.finalContentEvent = "InstallComplete"; + Harness.setup(); + + let principal = Services.scriptSecurityManager.createContentPrincipal( + Services.io.newURI("http://example.com/"), + { userContextId: MY_CONTEXT } + ); + + PermissionTestUtils.add(principal, "install", Services.perms.ALLOW_ACTION); + + var triggers = encodeURIComponent( + JSON.stringify({ + "Unsigned XPI": { + URL: TESTROOT + "amosigned.xpi", + IconURL: TESTROOT + "icon.png", + toString() { + return this.URL; + }, + }, + }) + ); + gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, "", { + userContextId: MY_CONTEXT, + }); + Services.obs.addObserver(check_channel, "http-on-before-connect"); + BrowserTestUtils.loadURIString( + gBrowser, + TESTROOT + "installtrigger.html?" + triggers + ); +} + +function confirm_install(panel) { + is(panel.getAttribute("name"), "XPI Test", "Should have seen the name"); + return true; +} + +function install_ended(install, addon) { + AddonTestUtils.checkInstallInfo(install, { + method: "installTrigger", + source: "test-host", + sourceURL: /http:\/\/example.com\/.*\/installtrigger.html/, + }); + return addon.uninstall(); +} + +const finish_test = async function (count) { + ok( + gDidSeeChannel, + "Should have seen the request for the XPI and verified it was sent the right way." + ); + is(count, 1, "1 Add-on should have been successfully installed"); + + Services.obs.removeObserver(check_channel, "http-on-before-connect"); + + PermissionTestUtils.remove("http://example.com", "install"); + + const results = await SpecialPowers.spawn( + gBrowser.selectedBrowser, + [], + () => { + return { + return: content.document.getElementById("return").textContent, + status: content.document.getElementById("status").textContent, + }; + } + ); + + is(results.return, "true", "installTrigger should have claimed success"); + is(results.status, "0", "Callback should have seen a success"); + + gBrowser.removeCurrentTab(); + Harness.finish(); +}; -- cgit v1.2.3