Bug 1531303 - Refactored tests using PermissionManager URI methods to use PermissionTestUtils. r=johannh

Differential Revision: https://phabricator.services.mozilla.com/D41029

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Paul Zuehlcke 2019-08-15 14:32:48 +00:00
Родитель f2675da6d6
Коммит 89fb47a8d9
96 изменённых файлов: 730 добавлений и 484 удалений

Просмотреть файл

@ -4,6 +4,10 @@ const { PlacesTestUtils } = ChromeUtils.import(
"resource://testing-common/PlacesTestUtils.jsm"
);
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
let notificationURL =
"http://example.org/browser/browser/base/content/test/alerts/file_dom_notifications.html";
let oldShowFavicons;
@ -97,7 +101,7 @@ add_task(async function test_notificationClose() {
});
add_task(async function cleanup() {
Services.perms.remove(makeURI(notificationURL), "desktop-notification");
PermissionTestUtils.remove(notificationURL, "desktop-notification");
if (typeof oldShowFavicons == "boolean") {
Services.prefs.setBoolPref("alerts.showFavicons", oldShowFavicons);
}

Просмотреть файл

@ -1,5 +1,9 @@
"use strict";
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
var tab;
var notificationURL =
"http://example.org/browser/browser/base/content/test/alerts/file_dom_notifications.html";
@ -35,8 +39,8 @@ function onAlertShowing() {
return;
}
ok(
Services.perms.testExactPermission(
makeURI(notificationURL),
PermissionTestUtils.testExactPermission(
notificationURL,
"desktop-notification"
),
"Permission should exist prior to removal"

Просмотреть файл

@ -4,6 +4,10 @@
"use strict";
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
var tab;
var notification;
var notificationURL =
@ -104,5 +108,5 @@ add_task(async function test_notificationPreventDefaultAndSwitchTabs() {
});
add_task(async function cleanup() {
Services.perms.remove(makeURI(notificationURL), "desktop-notification");
PermissionTestUtils.remove(notificationURL, "desktop-notification");
});

Просмотреть файл

@ -2,13 +2,16 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
add_task(async function test() {
let uriString = "http://example.com/";
let cookieBehavior = "network.cookie.cookieBehavior";
let uriObj = Services.io.newURI(uriString);
await SpecialPowers.pushPrefEnv({ set: [[cookieBehavior, 2]] });
Services.perms.add(uriObj, "cookie", Services.perms.ALLOW_ACTION);
PermissionTestUtils.add(uriString, "cookie", Services.perms.ALLOW_ACTION);
await BrowserTestUtils.withNewTab(
{ gBrowser, url: uriString },
@ -23,5 +26,5 @@ add_task(async function test() {
}
);
Services.perms.add(uriObj, "cookie", Services.perms.UNKNOWN_ACTION);
PermissionTestUtils.add(uriString, "cookie", Services.perms.UNKNOWN_ACTION);
});

Просмотреть файл

@ -5,6 +5,9 @@
var { WebChannel } = ChromeUtils.import(
"resource://gre/modules/WebChannel.jsm"
);
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
const TEST_URL_TAIL =
"example.com/browser/browser/base/content/test/general/test_remoteTroubleshoot.html";
@ -54,13 +57,13 @@ add_task(async function() {
);
// Add a permission manager entry for our URI.
Services.perms.add(
PermissionTestUtils.add(
TEST_URI_GOOD,
"remote-troubleshooting",
Services.perms.ALLOW_ACTION
);
registerCleanupFunction(() => {
Services.perms.remove(TEST_URI_GOOD, "remote-troubleshooting");
PermissionTestUtils.remove(TEST_URI_GOOD, "remote-troubleshooting");
});
// Try again - now we are expecting a response with the actual data.

Просмотреть файл

@ -1,6 +1,9 @@
const { SitePermissions } = ChromeUtils.import(
"resource:///modules/SitePermissions.jsm"
);
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
const TEST_ORIGIN = "https://example.com";
const TEST_ORIGIN_CERT_ERROR = "https://expired.example.com";
@ -209,7 +212,7 @@ add_task(async function test_cookie_permission() {
defaultCheckbox.dispatchEvent(new Event("command"));
is(
Services.perms.testPermission(gBrowser.currentURI, "cookie"),
PermissionTestUtils.testPermission(gBrowser.currentURI, "cookie"),
SitePermissions.ALLOW,
"Unchecking the default checkbox should pick the default permission."
);
@ -223,7 +226,7 @@ add_task(async function test_cookie_permission() {
blockRadioButton.dispatchEvent(new Event("command"));
is(
Services.perms.testPermission(gBrowser.currentURI, "cookie"),
PermissionTestUtils.testPermission(gBrowser.currentURI, "cookie"),
SitePermissions.BLOCK,
"Selecting a value in the radio group should set the corresponding permission"
);
@ -232,7 +235,7 @@ add_task(async function test_cookie_permission() {
allowRadioButton.dispatchEvent(new Event("command"));
is(
Services.perms.testPermission(gBrowser.currentURI, "cookie"),
PermissionTestUtils.testPermission(gBrowser.currentURI, "cookie"),
SitePermissions.ALLOW,
"Selecting a value in the radio group should set the corresponding permission"
);
@ -242,7 +245,7 @@ add_task(async function test_cookie_permission() {
defaultCheckbox.dispatchEvent(new Event("command"));
is(
Services.perms.testPermission(gBrowser.currentURI, "cookie"),
PermissionTestUtils.testPermission(gBrowser.currentURI, "cookie"),
SitePermissions.UNKNOWN,
"Checking the default checkbox should reset the permission."
);

Просмотреть файл

@ -105,11 +105,15 @@ add_task(async function setup() {
let uri = Services.io.newURI(PERMISSIONS_PAGE);
let uri2 = Services.io.newURI("https://example.org");
let uri3 = Services.io.newURI("http://sub.example.org");
Services.perms.add(uri, "geo", Services.perms.ALLOW_ACTION);
Services.perms.add(uri3, "desktop-notification", Services.perms.ALLOW_ACTION);
Services.perms.add(uri2, "microphone", Services.perms.DENY_ACTION);
Services.perms.add(uri, "camera", Services.perms.DENY_ACTION);
Services.perms.add(uri2, "geo", Services.perms.DENY_ACTION);
PermissionTestUtils.add(uri, "geo", Services.perms.ALLOW_ACTION);
PermissionTestUtils.add(
uri3,
"desktop-notification",
Services.perms.ALLOW_ACTION
);
PermissionTestUtils.add(uri2, "microphone", Services.perms.DENY_ACTION);
PermissionTestUtils.add(uri, "camera", Services.perms.DENY_ACTION);
PermissionTestUtils.add(uri2, "geo", Services.perms.DENY_ACTION);
registerCleanupFunction(() => {
Services.perms.removeAll();
@ -132,10 +136,7 @@ add_task(async function testAccept() {
checkEventTelemetry("accept");
Services.telemetry.clearEvents();
Services.perms.remove(
Services.io.newURI(PERMISSIONS_PAGE),
"desktop-notification"
);
PermissionTestUtils.remove(PERMISSIONS_PAGE, "desktop-notification");
});
});
@ -151,10 +152,7 @@ add_task(async function testDeny() {
checkEventTelemetry("deny");
Services.telemetry.clearEvents();
Services.perms.remove(
Services.io.newURI(PERMISSIONS_PAGE),
"desktop-notification"
);
PermissionTestUtils.remove(PERMISSIONS_PAGE, "desktop-notification");
});
});
@ -174,8 +172,5 @@ add_task(async function testLeave() {
checkEventTelemetry("leave");
Services.telemetry.clearEvents();
Services.perms.remove(
Services.io.newURI(PERMISSIONS_PAGE),
"desktop-notification"
);
PermissionTestUtils.remove(PERMISSIONS_PAGE, "desktop-notification");
});

Просмотреть файл

@ -41,12 +41,12 @@ function testPostPrompt(task) {
EventUtils.synthesizeMouseAtCenter(notification.button, {});
is(
Services.perms.testPermission(uri, "desktop-notification"),
PermissionTestUtils.testPermission(uri, "desktop-notification"),
Ci.nsIPermissionManager.ALLOW_ACTION,
"User can override the default deny by using the prompt"
);
Services.perms.remove(uri, "desktop-notification");
PermissionTestUtils.remove(uri, "desktop-notification");
});
}

Просмотреть файл

@ -1 +1,4 @@
ChromeUtils.import("resource:///modules/SitePermissions.jsm", this);
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);

Просмотреть файл

@ -7,6 +7,9 @@
const { SitePermissions } = ChromeUtils.import(
"resource:///modules/SitePermissions.jsm"
);
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
const baseURL = getRootDirectory(gTestPath).replace(
"chrome://mochitests/content",
@ -209,7 +212,7 @@ add_task(async function check_explicit_default_permission() {
// DENY only works if triggered through Services.perms (it's very edge-casey),
// since SitePermissions.jsm considers setting default permissions to be removal.
Services.perms.add(URI, "popup", Ci.nsIPermissionManager.DENY_ACTION);
PermissionTestUtils.add(URI, "popup", Ci.nsIPermissionManager.DENY_ACTION);
await openIdentityPopup();
let menulist = document.getElementById("identity-popup-popup-menulist");

Просмотреть файл

@ -77,7 +77,7 @@ add_task(async function deleteStorageOnlyCustomPermissionInAboutURL() {
// Custom permission without considering OriginAttributes
let uri = Services.io.newURI("about:newtab");
Services.perms.add(uri, "cookie", Ci.nsICookiePermission.ACCESS_SESSION);
PermissionTestUtils.add(uri, "cookie", Ci.nsICookiePermission.ACCESS_SESSION);
// Let's create a tab with some data.
await SiteDataTestUtils.addToIndexedDB("about:newtab", "foo", "bar", {});
@ -102,5 +102,5 @@ add_task(async function deleteStorageOnlyCustomPermissionInAboutURL() {
};
});
Services.perms.remove(uri, "cookie");
PermissionTestUtils.remove(uri, "cookie");
});

Просмотреть файл

@ -22,7 +22,11 @@ add_task(async function subDomains() {
// Domains and data
let uriA = Services.io.newURI("https://www.mozilla.org");
Services.perms.add(uriA, "cookie", Ci.nsICookiePermission.ACCESS_SESSION);
PermissionTestUtils.add(
uriA,
"cookie",
Ci.nsICookiePermission.ACCESS_SESSION
);
Services.cookies.add(
uriA.host,
@ -40,7 +44,7 @@ add_task(async function subDomains() {
await createIndexedDB(uriA.host, {});
let uriB = Services.io.newURI("https://mozilla.org");
Services.perms.add(uriB, "cookie", Ci.nsICookiePermission.ACCESS_ALLOW);
PermissionTestUtils.add(uriB, "cookie", Ci.nsICookiePermission.ACCESS_ALLOW);
Services.cookies.add(
uriB.host,
@ -85,8 +89,8 @@ add_task(async function subDomains() {
);
// Cleaning up permissions
Services.perms.remove(uriA, "cookie");
Services.perms.remove(uriB, "cookie");
PermissionTestUtils.remove(uriA, "cookie");
PermissionTestUtils.remove(uriB, "cookie");
});
// session only cookie life-time, 2 domains (mozilla.org, www.mozilla.org),
@ -108,7 +112,7 @@ add_task(async function subDomains() {
// Domains and data
let uriA = Services.io.newURI("https://sub.mozilla.org");
Services.perms.add(uriA, "cookie", Ci.nsICookiePermission.ACCESS_ALLOW);
PermissionTestUtils.add(uriA, "cookie", Ci.nsICookiePermission.ACCESS_ALLOW);
Services.cookies.add(
uriA.host,
@ -170,5 +174,5 @@ add_task(async function subDomains() {
);
// Cleaning up permissions
Services.perms.remove(uriA, "cookie");
PermissionTestUtils.remove(uriA, "cookie");
});

Просмотреть файл

@ -19,12 +19,15 @@ add_task(async function test() {
let numAtStart = countPermissions();
// Add a permission entry
var pm = Services.perms;
pm.add(Services.io.newURI("http://example.com"), "testing", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com",
"testing",
Services.perms.ALLOW_ACTION
);
// Sanity check
ok(
pm.enumerator.hasMoreElements(),
Services.perms.enumerator.hasMoreElements(),
"Permission manager should have elements, since we just added one"
);

Просмотреть файл

@ -8,6 +8,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
PlacesUtils: "resource://gre/modules/PlacesUtils.jsm",
Sanitizer: "resource:///modules/Sanitizer.jsm",
SiteDataTestUtils: "resource://testing-common/SiteDataTestUtils.jsm",
PermissionTestUtils: "resource://testing-common/PermissionTestUtils.jsm",
});
function createIndexedDB(host, originAttributes) {
@ -98,7 +99,7 @@ async function deleteOnShutdown(opt) {
// Custom permission without considering OriginAttributes
if (opt.cookiePermission !== undefined) {
let uri = Services.io.newURI("https://www.example.com");
Services.perms.add(uri, "cookie", opt.cookiePermission);
PermissionTestUtils.add(uri, "cookie", opt.cookiePermission);
}
// Let's create a tab with some data.
@ -151,7 +152,7 @@ async function deleteOnShutdown(opt) {
if (opt.cookiePermission !== undefined) {
let uri = Services.io.newURI("https://www.example.com");
Services.perms.remove(uri, "cookie");
PermissionTestUtils.remove(uri, "cookie");
}
}

Просмотреть файл

@ -1,5 +1,9 @@
"use strict";
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
const ROOT = getRootDirectory(gTestPath).replace(
"chrome://mochitests/content/",
"http://example.com/"
@ -66,10 +70,9 @@ add_task(async function() {
Services.tm.dispatchToMainThread(resolve);
});
// check permission is set
let ps = Services.perms;
is(
ps.ALLOW_ACTION,
ps.testPermission(makeURI(pageWithAlert), "focus-tab-by-prompt"),
Services.perms.ALLOW_ACTION,
PermissionTestUtils.testPermission(pageWithAlert, "focus-tab-by-prompt"),
"Tab switching should now be allowed"
);

Просмотреть файл

@ -4,6 +4,10 @@
"use strict";
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
const TRACKING_PAGE =
"http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html";
@ -113,10 +117,14 @@ add_task(async function testTrackersSubView() {
await assertSitesListed(true);
info("Testing trackers subview with TP enabled and a CB exception.");
let uri = Services.io.newURI("https://tracking.example.org");
Services.perms.add(uri, "trackingprotection", Services.perms.ALLOW_ACTION);
PermissionTestUtils.add(
uri,
"trackingprotection",
Services.perms.ALLOW_ACTION
);
await assertSitesListed(false);
info("Testing trackers subview with TP enabled and a CB exception removed.");
Services.perms.remove(uri, "trackingprotection");
PermissionTestUtils.remove(uri, "trackingprotection");
await assertSitesListed(true);
Services.prefs.clearUserPref(TP_PREF);

Просмотреть файл

@ -12,8 +12,8 @@ add_task(async function test_unsigned() {
});
let testURI = makeURI("https://example.com/");
Services.perms.add(testURI, "install", Services.perms.ALLOW_ACTION);
registerCleanupFunction(() => Services.perms.remove(testURI, "install"));
PermissionTestUtils.add(testURI, "install", Services.perms.ALLOW_ACTION);
registerCleanupFunction(() => PermissionTestUtils.remove(testURI, "install"));
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);

Просмотреть файл

@ -27,6 +27,10 @@ ChromeUtils.import(
);
let gCUITestUtils = new CustomizableUITestUtils(window);
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
/**
* Wait for the given PopupNotification to display
*
@ -309,8 +313,8 @@ async function testInstallMethod(installFn, telemetryBase) {
}
let testURI = makeURI("https://example.com/");
Services.perms.add(testURI, "install", Services.perms.ALLOW_ACTION);
registerCleanupFunction(() => Services.perms.remove(testURI, "install"));
PermissionTestUtils.add(testURI, "install", Services.perms.ALLOW_ACTION);
registerCleanupFunction(() => PermissionTestUtils.remove(testURI, "install"));
async function runOnce(filename, cancel) {
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);

Просмотреть файл

@ -328,23 +328,27 @@ var gTests = [
);
function checkDevicePermissions(aDevice, aExpected) {
let Perms = Services.perms;
let uri = gBrowser.selectedBrowser.documentURI;
let devicePerms = Perms.testExactPermission(uri, aDevice);
let devicePerms = PermissionTestUtils.testExactPermission(
uri,
aDevice
);
if (aExpected === undefined) {
is(
devicePerms,
Perms.UNKNOWN_ACTION,
Services.perms.UNKNOWN_ACTION,
"no " + aDevice + " persistent permissions"
);
} else {
is(
devicePerms,
aExpected ? Perms.ALLOW_ACTION : Perms.DENY_ACTION,
aExpected
? Services.perms.ALLOW_ACTION
: Services.perms.DENY_ACTION,
aDevice + " persistently " + (aExpected ? "allowed" : "denied")
);
}
Perms.remove(uri, aDevice);
PermissionTestUtils.remove(uri, aDevice);
}
checkDevicePermissions("microphone", aExpectedAudioPerm);
checkDevicePermissions("camera", aExpectedVideoPerm);
@ -355,7 +359,7 @@ var gTests = [
}
// 3 cases where the user accepts the device prompt.
info("audio+video, user grants, expect both perms set to allow");
info("audio+video, user grants, expect both Services.perms set to allow");
await checkPerm(true, true, true, true);
info(
"audio only, user grants, check audio perm set to allow, video perm not set"
@ -375,7 +379,7 @@ var gTests = [
"video only, user denies, expect video perm set to deny, audio perm not set"
);
await checkPerm(false, true, undefined, false, true);
info("audio+video, user denies, expect both perms set to deny");
info("audio+video, user denies, expect both Services.perms set to deny");
await checkPerm(true, true, false, false, true);
},
},
@ -390,21 +394,24 @@ var gTests = [
aRequestVideo,
aExpectStream
) {
let Perms = Services.perms;
let uri = gBrowser.selectedBrowser.documentURI;
if (aAllowAudio !== undefined) {
Perms.add(
PermissionTestUtils.add(
uri,
"microphone",
aAllowAudio ? Perms.ALLOW_ACTION : Perms.DENY_ACTION
aAllowAudio
? Services.perms.ALLOW_ACTION
: Services.perms.DENY_ACTION
);
}
if (aAllowVideo !== undefined) {
Perms.add(
PermissionTestUtils.add(
uri,
"camera",
aAllowVideo ? Perms.ALLOW_ACTION : Perms.DENY_ACTION
aAllowVideo
? Services.perms.ALLOW_ACTION
: Services.perms.DENY_ACTION
);
}
@ -458,8 +465,8 @@ var gTests = [
}
}
Perms.remove(uri, "camera");
Perms.remove(uri, "microphone");
PermissionTestUtils.remove(uri, "camera");
PermissionTestUtils.remove(uri, "microphone");
}
// Set both permissions identically
@ -522,12 +529,11 @@ var gTests = [
desc: "Stop Sharing removes persistent permissions",
run: async function checkStopSharingRemovesPersistentPermissions() {
async function stopAndCheckPerm(aRequestAudio, aRequestVideo) {
let Perms = Services.perms;
let uri = gBrowser.selectedBrowser.documentURI;
// Initially set both permissions to 'allow'.
Perms.add(uri, "microphone", Perms.ALLOW_ACTION);
Perms.add(uri, "camera", Perms.ALLOW_ACTION);
PermissionTestUtils.add(uri, "microphone", Services.perms.ALLOW_ACTION);
PermissionTestUtils.add(uri, "camera", Services.perms.ALLOW_ACTION);
let indicator = promiseIndicatorWindow();
// Start sharing what's been requested.
@ -544,25 +550,44 @@ var gTests = [
await stopSharing(aRequestVideo ? "camera" : "microphone");
// Check that permissions have been removed as expected.
let audioPerm = Perms.testExactPermission(uri, "microphone");
let audioPerm = PermissionTestUtils.testExactPermission(
uri,
"microphone"
);
if (aRequestAudio) {
is(audioPerm, Perms.UNKNOWN_ACTION, "microphone permissions removed");
is(
audioPerm,
Services.perms.UNKNOWN_ACTION,
"microphone permissions removed"
);
} else {
is(audioPerm, Perms.ALLOW_ACTION, "microphone permissions untouched");
is(
audioPerm,
Services.perms.ALLOW_ACTION,
"microphone permissions untouched"
);
}
let videoPerm = Perms.testExactPermission(uri, "camera");
let videoPerm = PermissionTestUtils.testExactPermission(uri, "camera");
if (aRequestVideo) {
is(videoPerm, Perms.UNKNOWN_ACTION, "camera permissions removed");
is(
videoPerm,
Services.perms.UNKNOWN_ACTION,
"camera permissions removed"
);
} else {
is(videoPerm, Perms.ALLOW_ACTION, "camera permissions untouched");
is(
videoPerm,
Services.perms.ALLOW_ACTION,
"camera permissions untouched"
);
}
// Cleanup.
await closeStream(true);
Perms.remove(uri, "camera");
Perms.remove(uri, "microphone");
PermissionTestUtils.remove(uri, "camera");
PermissionTestUtils.remove(uri, "microphone");
}
info("request audio+video, stop sharing resets both");
@ -645,10 +670,9 @@ var gTests = [
await BrowserTestUtils.browserLoaded(browser);
// Initially set both permissions to 'allow'.
let Perms = Services.perms;
let uri = browser.documentURI;
Perms.add(uri, "microphone", Perms.ALLOW_ACTION);
Perms.add(uri, "camera", Perms.ALLOW_ACTION);
PermissionTestUtils.add(uri, "microphone", Services.perms.ALLOW_ACTION);
PermissionTestUtils.add(uri, "camera", Services.perms.ALLOW_ACTION);
// Request devices and expect a prompt despite the saved 'Allow' permission,
// because the connection isn't secure.
@ -673,8 +697,8 @@ var gTests = [
// Cleanup.
await closeStream(true);
Perms.remove(uri, "camera");
Perms.remove(uri, "microphone");
PermissionTestUtils.remove(uri, "camera");
PermissionTestUtils.remove(uri, "microphone");
},
},
];

Просмотреть файл

@ -65,16 +65,15 @@ var gTests = [
await indicator;
await checkSharingUI({ video: true, audio: true });
let Perms = Services.perms;
let uri = Services.io.newURI("https://example.com/");
is(
Perms.testExactPermission(uri, "microphone"),
Perms.ALLOW_ACTION,
PermissionTestUtils.testExactPermission(uri, "microphone"),
Services.perms.ALLOW_ACTION,
"microphone persistently allowed"
);
is(
Perms.testExactPermission(uri, "camera"),
Perms.ALLOW_ACTION,
PermissionTestUtils.testExactPermission(uri, "camera"),
Services.perms.ALLOW_ACTION,
"camera persistently allowed"
);
@ -82,13 +81,13 @@ var gTests = [
// The persistent permissions for the frame should have been removed.
is(
Perms.testExactPermission(uri, "microphone"),
Perms.UNKNOWN_ACTION,
PermissionTestUtils.testExactPermission(uri, "microphone"),
Services.perms.UNKNOWN_ACTION,
"microphone not persistently allowed"
);
is(
Perms.testExactPermission(uri, "camera"),
Perms.UNKNOWN_ACTION,
PermissionTestUtils.testExactPermission(uri, "camera"),
Services.perms.UNKNOWN_ACTION,
"camera not persistently allowed"
);

Просмотреть файл

@ -4,6 +4,9 @@ var { XPCOMUtils } = ChromeUtils.import(
var { SitePermissions } = ChromeUtils.import(
"resource:///modules/SitePermissions.jsm"
);
var { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
const PREF_PERMISSION_FAKE = "media.navigator.permission.fake";
const PREF_AUDIO_LOOPBACK = "media.audio_loopback_dev";

Просмотреть файл

@ -15,6 +15,9 @@ const { updateAppInfo, getAppInfo } = ChromeUtils.import(
const { FileTestUtils } = ChromeUtils.import(
"resource://testing-common/FileTestUtils.jsm"
);
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
updateAppInfo({
name: "XPCShell",

Просмотреть файл

@ -14,26 +14,26 @@ add_task(async function test_setup_preexisting_permissions() {
// No ALLOW -> DENY override for popup and install permissions,
// because their policies only supports the Allow parameter.
Services.perms.add(
URI("https://www.pre-existing-allow.com"),
PermissionTestUtils.add(
"https://www.pre-existing-allow.com",
"camera",
Ci.nsIPermissionManager.ALLOW_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION
);
Services.perms.add(
URI("https://www.pre-existing-allow.com"),
PermissionTestUtils.add(
"https://www.pre-existing-allow.com",
"microphone",
Ci.nsIPermissionManager.ALLOW_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION
);
Services.perms.add(
URI("https://www.pre-existing-allow.com"),
PermissionTestUtils.add(
"https://www.pre-existing-allow.com",
"geo",
Ci.nsIPermissionManager.ALLOW_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION
);
Services.perms.add(
URI("https://www.pre-existing-allow.com"),
PermissionTestUtils.add(
"https://www.pre-existing-allow.com",
"desktop-notification",
Ci.nsIPermissionManager.ALLOW_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION
@ -42,26 +42,26 @@ add_task(async function test_setup_preexisting_permissions() {
// Pre-existing DENY permissions that should be overriden
// with ALLOW.
Services.perms.add(
URI("https://www.pre-existing-deny.com"),
PermissionTestUtils.add(
"https://www.pre-existing-deny.com",
"camera",
Ci.nsIPermissionManager.DENY_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION
);
Services.perms.add(
URI("https://www.pre-existing-deny.com"),
PermissionTestUtils.add(
"https://www.pre-existing-deny.com",
"microphone",
Ci.nsIPermissionManager.DENY_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION
);
Services.perms.add(
URI("https://www.pre-existing-deny.com"),
PermissionTestUtils.add(
"https://www.pre-existing-deny.com",
"geo",
Ci.nsIPermissionManager.DENY_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION
);
Services.perms.add(
URI("https://www.pre-existing-deny.com"),
PermissionTestUtils.add(
"https://www.pre-existing-deny.com",
"desktop-notification",
Ci.nsIPermissionManager.DENY_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION
@ -103,13 +103,13 @@ function checkPermission(url, expected, permissionName) {
let uri = Services.io.newURI(`https://www.${url}`);
equal(
Services.perms.testPermission(uri, permissionName),
PermissionTestUtils.testPermission(uri, permissionName),
expectedValue,
`Correct (${permissionName}=${expected}) for URL ${url}`
);
if (expected != "UNKNOWN") {
let permission = Services.perms.getPermissionObjectForURI(
let permission = PermissionTestUtils.getPermissionObject(
uri,
permissionName,
true
@ -153,26 +153,26 @@ add_task(async function test_notifications_policy() {
add_task(async function test_change_permission() {
// Checks that changing a permission will still retain the
// value set through the engine.
Services.perms.add(
URI("https://www.allow.com"),
PermissionTestUtils.add(
"https://www.allow.com",
"camera",
Ci.nsIPermissionManager.DENY_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION
);
Services.perms.add(
URI("https://www.allow.com"),
PermissionTestUtils.add(
"https://www.allow.com",
"microphone",
Ci.nsIPermissionManager.DENY_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION
);
Services.perms.add(
URI("https://www.allow.com"),
PermissionTestUtils.add(
"https://www.allow.com",
"geo",
Ci.nsIPermissionManager.DENY_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION
);
Services.perms.add(
URI("https://www.allow.com"),
PermissionTestUtils.add(
"https://www.allow.com",
"desktop-notification",
Ci.nsIPermissionManager.DENY_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION
@ -185,26 +185,26 @@ add_task(async function test_change_permission() {
// Also change one un-managed permission to make sure it doesn't
// cause any problems to the policy engine or the permission manager.
Services.perms.add(
URI("https://www.unmanaged.com"),
PermissionTestUtils.add(
"https://www.unmanaged.com",
"camera",
Ci.nsIPermissionManager.DENY_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION
);
Services.perms.add(
URI("https://www.unmanaged.com"),
PermissionTestUtils.add(
"https://www.unmanaged.com",
"microphone",
Ci.nsIPermissionManager.DENY_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION
);
Services.perms.add(
URI("https://www.unmanaged.com"),
PermissionTestUtils.add(
"https://www.unmanaged.com",
"geo",
Ci.nsIPermissionManager.DENY_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION
);
Services.perms.add(
URI("https://www.unmanaged.com"),
PermissionTestUtils.add(
"https://www.unmanaged.com",
"desktop-notification",
Ci.nsIPermissionManager.DENY_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION

Просмотреть файл

@ -14,15 +14,15 @@ add_task(async function test_setup_preexisting_permissions() {
// No ALLOW -> DENY override for popup and install permissions,
// because their policies only supports the Allow parameter.
Services.perms.add(
URI("https://www.pre-existing-allow.com"),
PermissionTestUtils.add(
"https://www.pre-existing-allow.com",
"cookie",
Ci.nsIPermissionManager.ALLOW_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION
);
Services.perms.add(
URI("https://www.pre-existing-allow.com"),
PermissionTestUtils.add(
"https://www.pre-existing-allow.com",
"plugin:flash",
Ci.nsIPermissionManager.ALLOW_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION
@ -30,29 +30,29 @@ add_task(async function test_setup_preexisting_permissions() {
// Pre-existing DENY permissions that should be overriden
// with ALLOW.
Services.perms.add(
URI("https://www.pre-existing-deny.com"),
PermissionTestUtils.add(
"https://www.pre-existing-deny.com",
"popup",
Ci.nsIPermissionManager.DENY_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION
);
Services.perms.add(
URI("https://www.pre-existing-deny.com"),
PermissionTestUtils.add(
"https://www.pre-existing-deny.com",
"install",
Ci.nsIPermissionManager.DENY_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION
);
Services.perms.add(
URI("https://www.pre-existing-deny.com"),
PermissionTestUtils.add(
"https://www.pre-existing-deny.com",
"cookie",
Ci.nsIPermissionManager.DENY_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION
);
Services.perms.add(
URI("https://www.pre-existing-deny.com"),
PermissionTestUtils.add(
"https://www.pre-existing-deny.com",
"plugin:flash",
Ci.nsIPermissionManager.DENY_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION
@ -73,13 +73,13 @@ function checkPermission(url, expected, permissionName) {
let uri = Services.io.newURI(`https://www.${url}`);
equal(
Services.perms.testPermission(uri, permissionName),
PermissionTestUtils.testPermission(uri, permissionName),
expectedValue,
`Correct (${permissionName}=${expected}) for URL ${url}`
);
if (expected != "UNKNOWN") {
let permission = Services.perms.getPermissionObjectForURI(
let permission = PermissionTestUtils.getPermissionObject(
uri,
permissionName,
true
@ -123,8 +123,8 @@ add_task(async function test_flash_policy() {
add_task(async function test_change_permission() {
// Checks that changing a permission will still retain the
// value set through the engine.
Services.perms.add(
URI("https://www.allow.com"),
PermissionTestUtils.add(
"https://www.allow.com",
"cookie",
Ci.nsIPermissionManager.DENY_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION
@ -134,8 +134,8 @@ add_task(async function test_change_permission() {
// Also change one un-managed permission to make sure it doesn't
// cause any problems to the policy engine or the permission manager.
Services.perms.add(
URI("https://www.unmanaged.com"),
PermissionTestUtils.add(
"https://www.unmanaged.com",
"cookie",
Ci.nsIPermissionManager.DENY_ACTION,
Ci.nsIPermissionManager.EXPIRE_SESSION

Просмотреть файл

@ -4,12 +4,16 @@
* This test is testing the cookie "permission" for a specific URI.
*/
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
const TEST_PAGE = "http://example.net";
const uri = Services.io.newURI(TEST_PAGE);
function disableCookies() {
Services.cookies.removeAll();
Services.perms.add(uri, "cookie", Services.perms.DENY_ACTION);
PermissionTestUtils.add(uri, "cookie", Services.perms.DENY_ACTION);
}
function ensureCookieNotSet(aBrowser) {
@ -33,7 +37,7 @@ IsolationTestTools.runTests(
function enableCookies() {
Services.cookies.removeAll();
Services.perms.add(uri, "cookie", Services.perms.ALLOW_ACTION);
PermissionTestUtils.add(uri, "cookie", Services.perms.ALLOW_ACTION);
}
function ensureCookieSet(aBrowser) {

Просмотреть файл

@ -138,7 +138,11 @@ add_task(async function testAdd() {
await runTest(
async (params, observeAllPromise, apply) => {
let uri = Services.io.newURI("http://test.com");
Services.perms.add(uri, "popup", Ci.nsIPermissionManager.DENY_ACTION);
PermissionTestUtils.add(
uri,
"popup",
Ci.nsIPermissionManager.DENY_ACTION
);
info("Adding unrelated permission should not change display.");
assertListContents(params, []);
@ -146,7 +150,7 @@ add_task(async function testAdd() {
apply();
await observeAllPromise;
Services.perms.remove(uri, "popup");
PermissionTestUtils.remove(uri, "popup");
},
params => {
return [
@ -412,7 +416,11 @@ add_task(async function testSort() {
for (let URL of ["http://a", "http://z", "http://b"]) {
let URI = Services.io.newURI(URL);
Services.perms.add(URI, "cookie", Ci.nsIPermissionManager.ALLOW_ACTION);
PermissionTestUtils.add(
URI,
"cookie",
Ci.nsIPermissionManager.ALLOW_ACTION
);
}
assertListContents(params, [
@ -439,7 +447,7 @@ add_task(async function testSort() {
for (let URL of ["http://a", "http://z", "http://b"]) {
let uri = Services.io.newURI(URL);
Services.perms.remove(uri, "cookie");
PermissionTestUtils.remove(uri, "cookie");
}
},
params => {

Просмотреть файл

@ -2,6 +2,9 @@
* http://creativecommons.org/publicdomain/zero/1.0/ */
ChromeUtils.import("resource://gre/modules/Promise.jsm", this);
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
const kDefaultWait = 2000;

Просмотреть файл

@ -6,6 +6,9 @@
var tmp = {};
ChromeUtils.import("resource:///modules/translation/Translation.jsm", tmp);
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
var { Translation } = tmp;
const kLanguagesPref = "browser.translation.neverForLanguages";
@ -240,7 +243,7 @@ var gTests = [
);
// Cleanup.
Services.perms.remove(makeURI("http://example.com"), "translate");
PermissionTestUtils.remove("http://example.com", "translate");
notif.close();
},
},
@ -307,9 +310,16 @@ var gTests = [
run: async function checkDomainExceptions() {
// Put 2 exceptions before opening the window to check the list is
// displayed on load.
let perms = Services.perms;
perms.add(makeURI("http://example.org"), "translate", perms.DENY_ACTION);
perms.add(makeURI("http://example.com"), "translate", perms.DENY_ACTION);
PermissionTestUtils.add(
"http://example.org",
"translate",
Services.perms.DENY_ACTION
);
PermissionTestUtils.add(
"http://example.com",
"translate",
Services.perms.DENY_ACTION
);
// Open the translation exceptions dialog.
let win = openDialog(
@ -339,14 +349,18 @@ var gTests = [
is(getDomainExceptions().length, 1, "One exception in the permissions");
// Clear the permissions, and check the last item is removed from the display.
perms.remove(makeURI("http://example.org"), "translate");
perms.remove(makeURI("http://example.com"), "translate");
PermissionTestUtils.remove("http://example.org", "translate");
PermissionTestUtils.remove("http://example.com", "translate");
is(tree.view.rowCount, 0, "The site exceptions list is empty");
ok(remove.disabled, "The 'Remove Site' button is disabled");
ok(removeAll.disabled, "The 'Remove All Site' button is disabled");
// Add an item and check it appears.
perms.add(makeURI("http://example.com"), "translate", perms.DENY_ACTION);
PermissionTestUtils.add(
"http://example.com",
"translate",
Services.perms.DENY_ACTION
);
is(tree.view.rowCount, 1, "The site exceptions list has 1 item");
ok(remove.disabled, "The 'Remove Site' button is disabled");
ok(!removeAll.disabled, "The 'Remove All Sites' button is enabled");

Просмотреть файл

@ -60,8 +60,7 @@ add_task(async function test_windowless_UITour() {
// Allow the URL to use the UITour.
info("Adding UITour permission to the test page.");
let pageURI = Services.io.newURI(pageURL);
Services.perms.add(pageURI, "uitour", Services.perms.ALLOW_ACTION);
PermissionTestUtils.add(gTestPath, "uitour", Services.perms.ALLOW_ACTION);
// UITour's ping will resolve this promise.
await new Promise(resolve => {

Просмотреть файл

@ -9,6 +9,10 @@ ChromeUtils.defineModuleGetter(
"resource:///modules/UITour.jsm"
);
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
const SINGLE_TRY_TIMEOUT = 100;
const NUMBER_OF_TRIES = 30;
@ -446,10 +450,18 @@ function setup_UITourTest() {
// Use `add_task(setup_UITourTest);` instead as we will fold this into `setup_UITourTest` once all tests are using `add_UITour_task`.
function UITourTest(usingAddTask = false) {
Services.prefs.setBoolPref("browser.uitour.enabled", true);
let testHttpsUri = Services.io.newURI("https://example.org");
let testHttpUri = Services.io.newURI("http://example.org");
Services.perms.add(testHttpsUri, "uitour", Services.perms.ALLOW_ACTION);
Services.perms.add(testHttpUri, "uitour", Services.perms.ALLOW_ACTION);
let testHttpsOrigin = "https://example.org";
let testHttpOrigin = "http://example.org";
PermissionTestUtils.add(
testHttpsOrigin,
"uitour",
Services.perms.ALLOW_ACTION
);
PermissionTestUtils.add(
testHttpOrigin,
"uitour",
Services.perms.ALLOW_ACTION
);
// If a test file is using add_task, we don't need to have a test function or
// call `waitForExplicitFinish`.
@ -465,8 +477,8 @@ function UITourTest(usingAddTask = false) {
}
delete window.gTestTab;
Services.prefs.clearUserPref("browser.uitour.enabled");
Services.perms.remove(testHttpsUri, "uitour");
Services.perms.remove(testHttpUri, "uitour");
PermissionTestUtils.remove(testHttpsOrigin, "uitour");
PermissionTestUtils.remove(testHttpOrigin, "uitour");
});
// When using tasks, the harness will call the next added task for us.

Просмотреть файл

@ -13,6 +13,9 @@ const { SiteDataManager } = ChromeUtils.import(
const { SiteDataTestUtils } = ChromeUtils.import(
"resource://testing-common/SiteDataTestUtils.jsm"
);
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"setTimeout",
@ -119,7 +122,7 @@ add_task(async function testRemove() {
await SiteDataManager.updateSites();
let uri = Services.io.newURI(EXAMPLE_ORIGIN);
Services.perms.add(uri, "camera", Services.perms.ALLOW_ACTION);
PermissionTestUtils.add(uri, "camera", Services.perms.ALLOW_ACTION);
SiteDataTestUtils.addToCookies(EXAMPLE_ORIGIN, "foo1", "bar1");
SiteDataTestUtils.addToCookies(EXAMPLE_ORIGIN, "foo2", "bar2");
@ -151,25 +154,25 @@ add_task(async function testRemove() {
let cookies = Services.cookies.countCookiesFromHost("example.com");
Assert.equal(cookies, 0, "Has cleared cookies for example.com");
let perm = Services.perms.testPermission(uri, "persistent-storage");
let perm = PermissionTestUtils.testPermission(uri, "persistent-storage");
Assert.equal(
perm,
Services.perms.UNKNOWN_ACTION,
"Cleared the persistent-storage permission."
);
perm = Services.perms.testPermission(uri, "camera");
perm = PermissionTestUtils.testPermission(uri, "camera");
Assert.equal(
perm,
Services.perms.ALLOW_ACTION,
"Did not clear other permissions."
);
Services.perms.remove(uri, "camera");
PermissionTestUtils.remove(uri, "camera");
});
add_task(async function testRemoveSiteData() {
let uri = Services.io.newURI(EXAMPLE_ORIGIN);
Services.perms.add(uri, "camera", Services.perms.ALLOW_ACTION);
PermissionTestUtils.add(uri, "camera", Services.perms.ALLOW_ACTION);
SiteDataTestUtils.addToCookies(EXAMPLE_ORIGIN, "foo1", "bar1");
SiteDataTestUtils.addToCookies(EXAMPLE_ORIGIN, "foo2", "bar2");
@ -199,18 +202,18 @@ add_task(async function testRemoveSiteData() {
let cookies = Services.cookies.countCookiesFromHost("example.org");
Assert.equal(cookies, 0, "Has cleared cookies for example.org");
let perm = Services.perms.testPermission(uri, "persistent-storage");
let perm = PermissionTestUtils.testPermission(uri, "persistent-storage");
Assert.equal(
perm,
Services.perms.UNKNOWN_ACTION,
"Cleared the persistent-storage permission."
);
perm = Services.perms.testPermission(uri, "camera");
perm = PermissionTestUtils.testPermission(uri, "camera");
Assert.equal(
perm,
Services.perms.ALLOW_ACTION,
"Did not clear other permissions."
);
Services.perms.remove(uri, "camera");
PermissionTestUtils.remove(uri, "camera");
});

Просмотреть файл

@ -15,7 +15,11 @@ function* testSteps() {
info("Setting permissions");
Services.perms.add(uri, "indexedDB", Ci.nsIPermissionManager.ALLOW_ACTION);
Services.perms.addFromPrincipal(
principal,
"indexedDB",
Ci.nsIPermissionManager.ALLOW_ACTION
);
// The idle-daily notification is disabled in xpchsell tests, so we don't
// need to do anything special to disable it for this test.

Просмотреть файл

@ -20,8 +20,14 @@ function* testSteps() {
const origin = "https://example.com";
// Avoid trying to show permission prompts on a window.
let uri = Services.io.newURI(origin);
Services.perms.add(uri, "indexedDB", Ci.nsIPermissionManager.ALLOW_ACTION);
let principal = Services.scriptSecurityManager.createContentPrincipalFromOrigin(
origin
);
Services.perms.addFromPrincipal(
principal,
"indexedDB",
Ci.nsIPermissionManager.ALLOW_ACTION
);
const objectStoreName = "Foo";
const data = { key: 1, value: "bar" };
@ -30,7 +36,6 @@ function* testSteps() {
Services.prefs.setBoolPref("dom.indexedDB.storageOption.enabled", false);
// Open a database with content privileges.
let principal = getPrincipal(origin);
let request = indexedDB.openForPrincipal(principal, name, {
version,
storage: "persistent",

Просмотреть файл

@ -1,5 +1,9 @@
"use strict";
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
const ORIGIN_URI = Services.io.newURI("https://example.com");
const PERMISSION_NAME = "desktop-notification";
const PROMPT_ALLOW_BUTTON = -1;
@ -45,7 +49,7 @@ function clickDoorhangerButton(aButtonIndex) {
* closes.
*/
function tabWithRequest(task, permission) {
Services.perms.remove(ORIGIN_URI, PERMISSION_NAME);
PermissionTestUtils.remove(ORIGIN_URI, PERMISSION_NAME);
return BrowserTestUtils.withNewTab(
{
@ -94,7 +98,7 @@ add_task(async function setup() {
);
SimpleTest.registerCleanupFunction(() => {
Services.prefs.clearUserPref("dom.webnotifications.requireuserinteraction");
Services.perms.remove(ORIGIN_URI, PERMISSION_NAME);
PermissionTestUtils.remove(ORIGIN_URI, PERMISSION_NAME);
});
});
@ -109,7 +113,7 @@ add_task(async function test_requestPermission_granted() {
);
is(
Services.perms.testPermission(ORIGIN_URI, PERMISSION_NAME),
PermissionTestUtils.testPermission(ORIGIN_URI, PERMISSION_NAME),
Services.perms.ALLOW_ACTION,
"Check permission in perm. manager"
);
@ -126,7 +130,7 @@ add_task(async function test_requestPermission_denied_temporarily() {
);
is(
Services.perms.testPermission(ORIGIN_URI, PERMISSION_NAME),
PermissionTestUtils.testPermission(ORIGIN_URI, PERMISSION_NAME),
Services.perms.UNKNOWN_ACTION,
"Check permission in perm. manager"
);
@ -143,7 +147,7 @@ add_task(async function test_requestPermission_denied_permanently() {
);
is(
Services.perms.testPermission(ORIGIN_URI, PERMISSION_NAME),
PermissionTestUtils.testPermission(ORIGIN_URI, PERMISSION_NAME),
Services.perms.DENY_ACTION,
"Check permission in perm. manager"
);

Просмотреть файл

@ -24,6 +24,9 @@ var { PlacesUtils } = ChromeUtils.import(
var { ObjectUtils } = ChromeUtils.import(
"resource://gre/modules/ObjectUtils.jsm"
);
var { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
ChromeUtils.defineModuleGetter(
this,

Просмотреть файл

@ -23,13 +23,13 @@ function visitURI(uri, timestamp) {
var putRecord = async function({ scope, perm, quota, lastPush, lastVisit }) {
let uri = Services.io.newURI(scope);
Services.perms.add(
PermissionTestUtils.add(
uri,
"desktop-notification",
Ci.nsIPermissionManager[perm]
);
registerCleanupFunction(() => {
Services.perms.remove(uri, "desktop-notification");
PermissionTestUtils.remove(uri, "desktop-notification");
});
await visitURI(uri, lastVisit);
@ -156,7 +156,7 @@ add_task(async function test_perm_restored() {
(subject, data) => data == "https://example.info/expired-perm-revoked"
);
Services.perms.add(
PermissionTestUtils.add(
permURI,
"desktop-notification",
Ci.nsIPermissionManager.ALLOW_ACTION

Просмотреть файл

@ -20,13 +20,13 @@ function run_test() {
let putRecord = async function(perm, record) {
let uri = Services.io.newURI(record.scope);
Services.perms.add(
PermissionTestUtils.add(
uri,
"desktop-notification",
Ci.nsIPermissionManager[perm]
);
registerCleanupFunction(() => {
Services.perms.remove(uri, "desktop-notification");
PermissionTestUtils.remove(uri, "desktop-notification");
});
await db.put(record);

Просмотреть файл

@ -90,7 +90,7 @@ function testPermissionCheck(props) {
`Record ${JSON.stringify(props)} should not have permission yet`
);
let permURI = Services.io.newURI(props.scope);
Services.perms.add(
PermissionTestUtils.add(
permURI,
"desktop-notification",
Ci.nsIPermissionManager.ALLOW_ACTION
@ -101,7 +101,7 @@ function testPermissionCheck(props) {
`Record ${JSON.stringify(props)} should have permission`
);
} finally {
Services.perms.remove(permURI, "desktop-notification");
PermissionTestUtils.remove(permURI, "desktop-notification");
}
}

Просмотреть файл

@ -1,5 +1,9 @@
"use strict";
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
const BASE_URI = "http://mochi.test:8888/browser/dom/serviceworkers/test/";
const PAGE_URI = BASE_URI + "empty.html";
const SCOPE = PAGE_URI + "?storage_permission";
@ -47,8 +51,8 @@ add_task(async function setup() {
});
add_task(async function test_allow_permission() {
Services.perms.add(
Services.io.newURI(PAGE_URI),
PermissionTestUtils.add(
PAGE_URI,
"cookie",
Ci.nsICookiePermission.ACCESS_ALLOW
);
@ -67,8 +71,8 @@ add_task(async function test_allow_permission() {
});
add_task(async function test_deny_permission() {
Services.perms.add(
Services.io.newURI(PAGE_URI),
PermissionTestUtils.add(
PAGE_URI,
"cookie",
Ci.nsICookiePermission.ACCESS_DENY
);
@ -84,12 +88,12 @@ add_task(async function test_deny_permission() {
is(controller, null, "page should be not controlled with storage denied");
BrowserTestUtils.removeTab(tab);
Services.perms.remove(Services.io.newURI(PAGE_URI), "cookie");
PermissionTestUtils.remove(PAGE_URI, "cookie");
});
add_task(async function test_session_permission() {
Services.perms.add(
Services.io.newURI(PAGE_URI),
PermissionTestUtils.add(
PAGE_URI,
"cookie",
Ci.nsICookiePermission.ACCESS_SESSION
);
@ -105,14 +109,14 @@ add_task(async function test_session_permission() {
is(controller, null, "page should be not controlled with session storage");
BrowserTestUtils.removeTab(tab);
Services.perms.remove(Services.io.newURI(PAGE_URI), "cookie");
PermissionTestUtils.remove(PAGE_URI, "cookie");
});
// Test to verify an about:blank iframe successfully inherits the
// parent's controller when storage is blocked between opening the
// parent page and creating the iframe.
add_task(async function test_block_storage_before_blank_iframe() {
Services.perms.remove(Services.io.newURI(PAGE_URI), "cookie");
PermissionTestUtils.remove(PAGE_URI, "cookie");
let tab = BrowserTestUtils.addTab(gBrowser, SCOPE);
let browser = gBrowser.getBrowserForTab(tab);
@ -156,7 +160,7 @@ add_task(async function test_block_storage_before_blank_iframe() {
// parent's controller when storage is blocked between opening the
// parent page and creating the iframe.
add_task(async function test_block_storage_before_blob_iframe() {
Services.perms.remove(Services.io.newURI(PAGE_URI), "cookie");
PermissionTestUtils.remove(PAGE_URI, "cookie");
let tab = BrowserTestUtils.addTab(gBrowser, SCOPE);
let browser = gBrowser.getBrowserForTab(tab);
@ -212,7 +216,7 @@ add_task(async function test_block_storage_before_blob_iframe() {
// explicitly check if the worker is controlled since we don't expose
// WorkerNavigator.serviceWorkers.controller yet.
add_task(async function test_block_storage_before_blob_worker() {
Services.perms.remove(Services.io.newURI(PAGE_URI), "cookie");
PermissionTestUtils.remove(PAGE_URI, "cookie");
let tab = BrowserTestUtils.addTab(gBrowser, SCOPE);
let browser = gBrowser.getBrowserForTab(tab);
@ -265,7 +269,7 @@ add_task(async function test_block_storage_before_blob_worker() {
});
add_task(async function cleanup() {
Services.perms.remove(Services.io.newURI(PAGE_URI), "cookie");
PermissionTestUtils.remove(PAGE_URI, "cookie");
let tab = BrowserTestUtils.addTab(gBrowser, PAGE_URI);
let browser = gBrowser.getBrowserForTab(tab);

Просмотреть файл

@ -1,3 +1,7 @@
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
const BEHAVIOR_ACCEPT = Ci.nsICookieService.BEHAVIOR_ACCEPT;
const BEHAVIOR_REJECT = Ci.nsICookieService.BEHAVIOR_REJECT;
@ -86,10 +90,8 @@ this.CookiePolicyHelper = {
await SpecialPowers.pushPrefEnv({ set: prefs });
}
let uri = Services.io.newURI(TEST_DOMAIN);
// Let's set the first cookie pref.
Services.perms.add(uri, "cookie", config.fromPermission);
PermissionTestUtils.add(TEST_DOMAIN, "cookie", config.fromPermission);
await SpecialPowers.pushPrefEnv({
set: [["network.cookie.cookieBehavior", config.fromBehavior]],
});
@ -133,7 +135,7 @@ this.CookiePolicyHelper = {
);
// Now, let's change the cookie settings
Services.perms.add(uri, "cookie", config.toPermission);
PermissionTestUtils.add(TEST_DOMAIN, "cookie", config.toPermission);
await SpecialPowers.pushPrefEnv({
set: [["network.cookie.cookieBehavior", config.toBehavior]],
});

Просмотреть файл

@ -1,6 +1,9 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
/**
* This is testcase do following steps to make sure bug767025 removing
@ -107,7 +110,7 @@ function do_app_cache(manifestURL, pageURL) {
Ci.nsIOfflineCacheUpdateService
);
Services.perms.add(
PermissionTestUtils.add(
manifestURL,
"offline-app",
Ci.nsIPermissionManager.ALLOW_ACTION

Просмотреть файл

@ -31,6 +31,9 @@
*/
const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
// const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
@ -141,7 +144,7 @@ function do_app_cache(manifestURL, pageURL, pinned) {
Ci.nsIOfflineCacheUpdateService
);
Services.perms.add(
PermissionTestUtils.add(
manifestURL,
"pin-app",
pinned

Просмотреть файл

@ -15,7 +15,11 @@
"use strict";
add_task(async _ => {
let uri = Services.io.newURI("https://example.net");
Services.perms.add(uri, "trackingprotection-pb", Services.perms.ALLOW_ACTION);
PermissionTestUtils.add(
uri,
"trackingprotection-pb",
Services.perms.ALLOW_ACTION
);
registerCleanupFunction(_ => {
Services.perms.removeAll();

Просмотреть файл

@ -4,13 +4,13 @@
/* import-globals-from antitracking_head.js */
add_task(async _ => {
Services.perms.add(
Services.io.newURI("https://tracking.example.org"),
PermissionTestUtils.add(
"https://tracking.example.org",
"cookie",
Services.perms.ALLOW_ACTION
);
Services.perms.add(
Services.io.newURI("https://tracking.example.com"),
PermissionTestUtils.add(
"https://tracking.example.com",
"cookie",
Services.perms.ALLOW_ACTION
);

Просмотреть файл

@ -4,13 +4,13 @@
/* import-globals-from antitracking_head.js */
add_task(async _ => {
Services.perms.add(
Services.io.newURI("https://tracking.example.org"),
PermissionTestUtils.add(
"https://tracking.example.org",
"cookie",
Services.perms.DENY_ACTION
);
Services.perms.add(
Services.io.newURI("https://tracking.example.com"),
PermissionTestUtils.add(
"https://tracking.example.com",
"cookie",
Services.perms.DENY_ACTION
);

Просмотреть файл

@ -13,8 +13,10 @@ AntiTracking.runTest(
let Services = SpecialPowers.Services;
// We would use TEST_3RD_PARTY_DOMAIN here, except that the variable isn't
// accessible in the context of the web page...
let uri = Services.io.newURI("https://tracking.example.org/");
for (let perm of Services.perms.getAllForURI(uri)) {
let principal = Services.scriptSecurityManager.createContentPrincipalFromOrigin(
"https://tracking.example.org/"
);
for (let perm of Services.perms.getAllForPrincipal(principal)) {
// Ignore permissions other than storage access
if (!perm.type.startsWith("3rdPartyStorage^")) {
continue;

Просмотреть файл

@ -13,8 +13,10 @@ AntiTracking.runTest(
let Services = SpecialPowers.Services;
// We would use TEST_3RD_PARTY_DOMAIN here, except that the variable isn't
// accessible in the context of the web page...
let uri = Services.io.newURI("https://tracking.example.org/");
for (let perm of Services.perms.getAllForURI(uri)) {
let principal = Services.scriptSecurityManager.createContentPrincipalFromOrigin(
"https://tracking.example.org/"
);
for (let perm of Services.perms.getAllForPrincipal(principal)) {
// Ignore permissions other than storage access
if (!perm.type.startsWith("3rdPartyStorage^")) {
continue;

Просмотреть файл

@ -242,119 +242,29 @@ async function preparePermissionsFromOtherSites(topPage) {
// For the first page, don't do anything
} else if (topPage == TEST_TOP_PAGE_2) {
// For the second page, only add the permission from the first page
Services.perms.add(
Services.io.newURI(TEST_DOMAIN),
type,
permission,
expireType,
0
);
PermissionTestUtils.add(TEST_DOMAIN, type, permission, expireType, 0);
} else if (topPage == TEST_TOP_PAGE_3) {
// For the third page, add the permissions from the first two pages
Services.perms.add(
Services.io.newURI(TEST_DOMAIN),
type,
permission,
expireType,
0
);
Services.perms.add(
Services.io.newURI(TEST_DOMAIN_2),
type,
permission,
expireType,
0
);
PermissionTestUtils.add(TEST_DOMAIN, type, permission, expireType, 0);
PermissionTestUtils.add(TEST_DOMAIN_2, type, permission, expireType, 0);
} else if (topPage == TEST_TOP_PAGE_4) {
// For the fourth page, add the permissions from the first three pages
Services.perms.add(
Services.io.newURI(TEST_DOMAIN),
type,
permission,
expireType,
0
);
Services.perms.add(
Services.io.newURI(TEST_DOMAIN_2),
type,
permission,
expireType,
0
);
Services.perms.add(
Services.io.newURI(TEST_DOMAIN_3),
type,
permission,
expireType,
0
);
PermissionTestUtils.add(TEST_DOMAIN, type, permission, expireType, 0);
PermissionTestUtils.add(TEST_DOMAIN_2, type, permission, expireType, 0);
PermissionTestUtils.add(TEST_DOMAIN_3, type, permission, expireType, 0);
} else if (topPage == TEST_TOP_PAGE_5) {
// For the fifth page, add the permissions from the first four pages
Services.perms.add(
Services.io.newURI(TEST_DOMAIN),
type,
permission,
expireType,
0
);
Services.perms.add(
Services.io.newURI(TEST_DOMAIN_2),
type,
permission,
expireType,
0
);
Services.perms.add(
Services.io.newURI(TEST_DOMAIN_3),
type,
permission,
expireType,
0
);
Services.perms.add(
Services.io.newURI(TEST_DOMAIN_4),
type,
permission,
expireType,
0
);
PermissionTestUtils.add(TEST_DOMAIN, type, permission, expireType, 0);
PermissionTestUtils.add(TEST_DOMAIN_2, type, permission, expireType, 0);
PermissionTestUtils.add(TEST_DOMAIN_3, type, permission, expireType, 0);
PermissionTestUtils.add(TEST_DOMAIN_4, type, permission, expireType, 0);
} else if (topPage == TEST_TOP_PAGE_6) {
// For the sixth page, add the permissions from the first five pages
Services.perms.add(
Services.io.newURI(TEST_DOMAIN),
type,
permission,
expireType,
0
);
Services.perms.add(
Services.io.newURI(TEST_DOMAIN_2),
type,
permission,
expireType,
0
);
Services.perms.add(
Services.io.newURI(TEST_DOMAIN_3),
type,
permission,
expireType,
0
);
Services.perms.add(
Services.io.newURI(TEST_DOMAIN_4),
type,
permission,
expireType,
0
);
Services.perms.add(
Services.io.newURI(TEST_DOMAIN_5),
type,
permission,
expireType,
0
);
PermissionTestUtils.add(TEST_DOMAIN, type, permission, expireType, 0);
PermissionTestUtils.add(TEST_DOMAIN_2, type, permission, expireType, 0);
PermissionTestUtils.add(TEST_DOMAIN_3, type, permission, expireType, 0);
PermissionTestUtils.add(TEST_DOMAIN_4, type, permission, expireType, 0);
PermissionTestUtils.add(TEST_DOMAIN_5, type, permission, expireType, 0);
} else {
ok(false, "Unexpected top page: " + topPage);
}

Просмотреть файл

@ -31,7 +31,7 @@ add_task(async function() {
let uri = Services.io.newURI(TEST_DOMAIN);
is(
Services.perms.testPermission(uri, "storageAccessAPI"),
PermissionTestUtils.testPermission(uri, "storageAccessAPI"),
Services.perms.UNKNOWN_ACTION,
"Before user-interaction we don't have a permission"
);

Просмотреть файл

@ -56,6 +56,10 @@ const { UrlClassifierTestUtils } = ChromeUtils.import(
"resource://testing-common/UrlClassifierTestUtils.jsm"
);
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
Services.scriptloader.loadSubScript(
"chrome://mochitests/content/browser/toolkit/components/antitracking/test/browser/antitracking_head.js",
this

Просмотреть файл

@ -147,8 +147,13 @@ async function waitUntilPermission(url, name) {
let id = setInterval(_ => {
let Services = SpecialPowers.Services;
let uri = Services.io.newURI(url);
let principal = Services.scriptSecurityManager.createContentPrincipal(
uri,
{}
);
if (
Services.perms.testPermission(uri, name) == Services.perms.ALLOW_ACTION
Services.perms.testPermissionFromPrincipal(principal, name) ==
Services.perms.ALLOW_ACTION
) {
clearInterval(id);
resolve();
@ -174,11 +179,17 @@ async function interactWithTracker() {
function isOnContentBlockingAllowList() {
let url = new URL(SpecialPowers.wrap(top).location.href);
let origin = SpecialPowers.Services.io.newURI("https://" + url.host);
let principal = SpecialPowers.Services.scriptSecurityManager.createContentPrincipal(
origin,
{}
);
let types = ["trackingprotection", "trackingprotection-pb"];
return types.some(type => {
return (
SpecialPowers.Services.perms.testPermission(origin, type) ==
SpecialPowers.Services.perms.ALLOW_ACTION
SpecialPowers.Services.perms.testPermissionFromPrincipal(
principal,
type
) == SpecialPowers.Services.perms.ALLOW_ACTION
);
});
}

Просмотреть файл

@ -5,6 +5,10 @@
/* eslint-disable no-var */
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
const ENCTYPE_BASE64 = 0;
const ENCTYPE_SDR = 1;
const PERMISSION_SAVE_LOGINS = "login-saving";
@ -83,12 +87,14 @@ function getAllDisabledHostsFromPermissionManager() {
}
function setLoginSavingEnabled(origin, enabled) {
let uri = Services.io.newURI(origin);
if (enabled) {
Services.perms.remove(uri, PERMISSION_SAVE_LOGINS);
PermissionTestUtils.remove(origin, PERMISSION_SAVE_LOGINS);
} else {
Services.perms.add(uri, PERMISSION_SAVE_LOGINS, Services.perms.DENY_ACTION);
PermissionTestUtils.add(
origin,
PERMISSION_SAVE_LOGINS,
Services.perms.DENY_ACTION
);
}
}

Просмотреть файл

@ -13,6 +13,9 @@ const { TelemetryUtils } = ChromeUtils.import(
const { ObjectUtils } = ChromeUtils.import(
"resource://gre/modules/ObjectUtils.jsm"
);
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
const HC_PERMISSION = "hc_telemetry";
@ -95,7 +98,11 @@ add_task(async function test_untrusted_http_origin() {
// Try to use the API on a non-secure host.
const testHost = "http://example.org";
let testHttpUri = Services.io.newURI(testHost);
Services.perms.add(testHttpUri, HC_PERMISSION, Services.perms.ALLOW_ACTION);
PermissionTestUtils.add(
testHttpUri,
HC_PERMISSION,
Services.perms.ALLOW_ACTION
);
let url = getRootDirectory(gTestPath) + "hybrid_content.html";
url = url.replace("chrome://mochitests/content", testHost);
let newTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, url);
@ -127,7 +134,7 @@ add_task(async function test_untrusted_http_origin() {
// Finally clean up the listener.
BrowserTestUtils.removeTab(newTab);
Services.perms.remove(testHttpUri, HC_PERMISSION);
PermissionTestUtils.remove(testHttpUri, HC_PERMISSION);
Services.mm.removeMessageListener(messageName, makeTestFail);
Services.telemetry.setEventRecordingEnabled("telemetry.test", false);
});
@ -195,7 +202,11 @@ add_task(async function test_trusted_disabled_hybrid_telemetry() {
// Try to use the API on a secure host.
const testHost = "https://example.org";
let testHttpsUri = Services.io.newURI(testHost);
Services.perms.add(testHttpsUri, HC_PERMISSION, Services.perms.ALLOW_ACTION);
PermissionTestUtils.add(
testHttpsUri,
HC_PERMISSION,
Services.perms.ALLOW_ACTION
);
let url = getRootDirectory(gTestPath) + "hybrid_content.html";
url = url.replace("chrome://mochitests/content", testHost);
let newTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, url);
@ -228,7 +239,7 @@ add_task(async function test_trusted_disabled_hybrid_telemetry() {
// Finally clean up the listener.
await SpecialPowers.popPrefEnv();
BrowserTestUtils.removeTab(newTab);
Services.perms.remove(testHttpsUri, HC_PERMISSION);
PermissionTestUtils.remove(testHttpsUri, HC_PERMISSION);
Services.mm.removeMessageListener(messageName, makeTestFail);
Services.telemetry.setEventRecordingEnabled("telemetry.test", false);
});
@ -239,7 +250,11 @@ add_task(async function test_hybrid_content_with_iframe() {
// Open a trusted page that can use in the HCT in a new tab.
const testOuterPageHost = "https://example.com";
let testHttpsUri = Services.io.newURI(testOuterPageHost);
Services.perms.add(testHttpsUri, HC_PERMISSION, Services.perms.ALLOW_ACTION);
PermissionTestUtils.add(
testHttpsUri,
HC_PERMISSION,
Services.perms.ALLOW_ACTION
);
let url = getRootDirectory(gTestPath) + "hybrid_content.html";
let outerUrl = url.replace("chrome://mochitests/content", testOuterPageHost);
let newTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, outerUrl);
@ -297,7 +312,7 @@ add_task(async function test_hybrid_content_with_iframe() {
// Cleanup permissions and remove the tab.
BrowserTestUtils.removeTab(newTab);
Services.mm.removeMessageListener(messageName, makeTestFail);
Services.perms.remove(testHttpsUri, HC_PERMISSION);
PermissionTestUtils.remove(testHttpsUri, HC_PERMISSION);
Services.telemetry.setEventRecordingEnabled("telemetry.test", false);
});
@ -325,7 +340,11 @@ add_task(async function test_hybrid_content_recording() {
// Give the test host enough privileges to use the API and open the test page.
let testHttpsUri = Services.io.newURI(testHost);
Services.perms.add(testHttpsUri, HC_PERMISSION, Services.perms.ALLOW_ACTION);
PermissionTestUtils.add(
testHttpsUri,
HC_PERMISSION,
Services.perms.ALLOW_ACTION
);
let url = getRootDirectory(gTestPath) + "hybrid_content.html";
url = url.replace("chrome://mochitests/content", testHost);
let newTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, url);
@ -398,7 +417,7 @@ add_task(async function test_hybrid_content_recording() {
// Cleanup permissions and remove the tab.
BrowserTestUtils.removeTab(newTab);
Services.perms.remove(testHttpsUri, HC_PERMISSION);
PermissionTestUtils.remove(testHttpsUri, HC_PERMISSION);
});
add_task(async function test_can_upload() {
@ -410,7 +429,11 @@ add_task(async function test_can_upload() {
// Give the test host enough privileges to use the API and open the test page.
let testHttpsUri = Services.io.newURI(testHost);
Services.perms.add(testHttpsUri, HC_PERMISSION, Services.perms.ALLOW_ACTION);
PermissionTestUtils.add(
testHttpsUri,
HC_PERMISSION,
Services.perms.ALLOW_ACTION
);
let url = getRootDirectory(gTestPath) + "hybrid_content.html";
url = url.replace("chrome://mochitests/content", testHost);
let newTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, url);
@ -445,14 +468,17 @@ add_task(async function test_can_upload() {
// Cleanup permissions and remove the tab.
BrowserTestUtils.removeTab(newTab);
Services.perms.remove(testHttpsUri, HC_PERMISSION);
PermissionTestUtils.remove(testHttpsUri, HC_PERMISSION);
});
add_task(async function test_hct_for_discopane() {
const discoHost = "https://discovery.addons.mozilla.org";
let discoHttpsUri = Services.io.newURI(discoHost);
let permission = Services.perms.testPermission(discoHttpsUri, HC_PERMISSION);
let permission = PermissionTestUtils.testPermission(
discoHttpsUri,
HC_PERMISSION
);
ok(
permission == Services.perms.ALLOW_ACTION,
@ -496,7 +522,7 @@ add_task(async function test_init_rejects() {
// Give the test host HCT privileges and test that init doesn't throw.
const testHostPrivileges = "https://example.com";
let testUrlPrivileges = Services.io.newURI(testHostPrivileges);
Services.perms.add(
PermissionTestUtils.add(
testUrlPrivileges,
HC_PERMISSION,
Services.perms.ALLOW_ACTION
@ -534,5 +560,5 @@ add_task(async function test_init_rejects() {
// Cleanup permissions and remove the tab.
BrowserTestUtils.removeTab(newTab);
BrowserTestUtils.removeTab(otherTab);
Services.perms.remove(testUrlPrivileges, HC_PERMISSION);
PermissionTestUtils.remove(testUrlPrivileges, HC_PERMISSION);
});

Просмотреть файл

@ -13,6 +13,9 @@ const TEST_PERM = "test-permission";
const { PermissionsUtils } = ChromeUtils.import(
"resource://gre/modules/PermissionsUtils.jsm"
);
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
function run_test() {
test_importfromPrefs();
@ -79,7 +82,7 @@ function test_importfromPrefs() {
for (let url of unknown) {
let uri = Services.io.newURI(url);
Assert.equal(
Services.perms.testPermission(uri, TEST_PERM),
PermissionTestUtils.testPermission(uri, TEST_PERM),
Services.perms.UNKNOWN_ACTION
);
}
@ -99,21 +102,21 @@ function test_importfromPrefs() {
for (let url of whitelisted) {
let uri = Services.io.newURI(url);
Assert.equal(
Services.perms.testPermission(uri, TEST_PERM),
PermissionTestUtils.testPermission(uri, TEST_PERM),
Services.perms.ALLOW_ACTION
);
}
for (let url of blacklisted) {
let uri = Services.io.newURI(url);
Assert.equal(
Services.perms.testPermission(uri, TEST_PERM),
PermissionTestUtils.testPermission(uri, TEST_PERM),
Services.perms.DENY_ACTION
);
}
for (let url of untouched) {
let uri = Services.io.newURI(url);
Assert.equal(
Services.perms.testPermission(uri, TEST_PERM),
PermissionTestUtils.testPermission(uri, TEST_PERM),
Services.perms.UNKNOWN_ACTION
);
}

Просмотреть файл

@ -6,6 +6,9 @@
const { WebChannel } = ChromeUtils.import(
"resource://gre/modules/WebChannel.jsm"
);
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
const ERROR_ID_ORIGIN_REQUIRED =
"WebChannel id and originOrPermission are required.";
@ -93,13 +96,13 @@ add_task(function test_web_channel_listen() {
add_task(function test_web_channel_listen_permission() {
return new Promise((resolve, reject) => {
// add a new permission
Services.perms.add(
PermissionTestUtils.add(
VALID_WEB_CHANNEL_ORIGIN,
TEST_PERMISSION_NAME,
Services.perms.ALLOW_ACTION
);
registerCleanupFunction(() =>
Services.perms.remove(VALID_WEB_CHANNEL_ORIGIN, TEST_PERMISSION_NAME)
PermissionTestUtils.remove(VALID_WEB_CHANNEL_ORIGIN, TEST_PERMISSION_NAME)
);
let channel = new WebChannel(VALID_WEB_CHANNEL_ID, TEST_PERMISSION_NAME, {
broker: MockWebChannelBroker,

Просмотреть файл

@ -5,6 +5,10 @@
// Checks that permissions set in preferences are correctly imported but can
// be removed by the user.
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
const XPI_MIMETYPE = "application/x-xpinstall";
function newPrincipal(uri) {
@ -30,8 +34,8 @@ add_task(async function setup() {
"https://test5.com"
);
Services.perms.add(
NetUtil.newURI("https://www.test9.com"),
PermissionTestUtils.add(
"https://www.test9.com",
"install",
Ci.nsIPermissionManager.ALLOW_ACTION
);

Просмотреть файл

@ -8,8 +8,11 @@ function test() {
Harness.finalContentEvent = "InstallComplete";
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
var triggers = encodeURIComponent(
JSON.stringify({
@ -46,7 +49,7 @@ function install_ended(install, addon) {
const finish_test = async function(count) {
is(count, 1, "1 Add-on should have been successfully installed");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
const results = await ContentTask.spawn(
gBrowser.selectedBrowser,

Просмотреть файл

@ -9,8 +9,11 @@ function test() {
Harness.finalContentEvent = "InstallComplete";
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
var inner_url = encodeURIComponent(
TESTROOT +
@ -46,7 +49,7 @@ function install_ended(install, addon) {
const finish_test = async function(count) {
is(count, 1, "1 Add-on should have been successfully installed");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
const results = await ContentTask.spawn(
gBrowser.selectedBrowser,

Просмотреть файл

@ -16,8 +16,11 @@ function test() {
Services.prefs.setIntPref("network.auth.subresource-http-auth-allow", 2);
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
var triggers = encodeURIComponent(
JSON.stringify({
@ -51,7 +54,7 @@ function finish_test(count) {
);
authMgr.clearAll();
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
Services.prefs.clearUserPref(
"network.auth.non-web-content-triggered-resources-http-auth-allow"

Просмотреть файл

@ -16,8 +16,11 @@ function test() {
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
var triggers = encodeURIComponent(
JSON.stringify({
@ -56,7 +59,7 @@ function finish_test(count) {
);
authMgr.clearAll();
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
Services.prefs.clearUserPref(
"network.auth.non-web-content-triggered-resources-http-auth-allow"

Просмотреть файл

@ -15,8 +15,11 @@ function test() {
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
var triggers = encodeURIComponent(
JSON.stringify({
@ -55,7 +58,7 @@ function finish_test(count) {
);
authMgr.clearAll();
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
Services.prefs.clearUserPref(
"network.auth.non-web-content-triggered-resources-http-auth-allow"

Просмотреть файл

@ -14,8 +14,11 @@ function test() {
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
var triggers = encodeURIComponent(
JSON.stringify({
@ -54,7 +57,7 @@ function finish_test(count) {
);
authMgr.clearAll();
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
Services.prefs.clearUserPref(
"network.auth.non-web-content-triggered-resources-http-auth-allow"

Просмотреть файл

@ -6,8 +6,11 @@ function test() {
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
var triggers = encodeURIComponent(
JSON.stringify({
@ -33,7 +36,7 @@ function download_failed(install) {
function finish_test(count) {
is(count, 0, "No add-ons should have been installed");
Services.perms.remove(makeURI("http://example.com/"), "install");
PermissionTestUtils.remove("http://example.com/", "install");
gBrowser.removeCurrentTab();
Harness.finish();

Просмотреть файл

@ -6,8 +6,11 @@ function test() {
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
var triggers = encodeURIComponent(
JSON.stringify({
@ -33,7 +36,7 @@ function download_failed(install) {
function finish_test(count) {
is(count, 0, "No add-ons should have been installed");
Services.perms.remove(makeURI("http://example.com/"), "install");
PermissionTestUtils.remove("http://example.com/", "install");
gBrowser.removeCurrentTab();
Harness.finish();

Просмотреть файл

@ -5,8 +5,11 @@ function test() {
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
BrowserTestUtils.loadURI(gBrowser, TESTROOT + "bug540558.html");
@ -18,7 +21,7 @@ function check_xpi_install(install, addon) {
function finish_test(count) {
is(count, 1, "1 Add-on should have been successfully installed");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();

Просмотреть файл

@ -8,8 +8,11 @@ function test() {
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.org/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.org/",
"install",
Services.perms.ALLOW_ACTION
);
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
BrowserTestUtils.loadURI(gBrowser, TESTROOT + "bug645699.html");
@ -36,7 +39,7 @@ function confirm_install(panel) {
function finish_test(count) {
is(count, 0, "0 Add-ons should have been successfully installed");
Services.perms.remove(makeURI("http://addons.mozilla.org"), "install");
PermissionTestUtils.remove("http://addons.mozilla.org", "install");
gBrowser.removeCurrentTab();
Harness.finish();

Просмотреть файл

@ -15,8 +15,11 @@ function test() {
delete Services.ww;
is(Services.ww, undefined, "Services.ww should now be undefined");
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
var triggers = encodeURIComponent(
JSON.stringify({
@ -51,7 +54,7 @@ function finish_test(count) {
Services.ww = gWindowWatcher;
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
Harness.finish();
}

Просмотреть файл

@ -29,8 +29,11 @@ function test() {
Harness.finalContentEvent = "InstallComplete";
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
var triggers = encodeURIComponent(
JSON.stringify({
@ -76,7 +79,7 @@ const finish_test = async function(count) {
Services.obs.removeObserver(check_channel, "http-on-before-connect");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
const results = await ContentTask.spawn(
gBrowser.selectedBrowser,

Просмотреть файл

@ -7,8 +7,11 @@ function test() {
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
var triggers = encodeURIComponent(
JSON.stringify({
@ -29,7 +32,7 @@ function download_failed(install) {
function finish_test(count) {
is(count, 0, "No add-ons should have been installed");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();

Просмотреть файл

@ -20,8 +20,11 @@ function test() {
Ci.nsICookie.SAMESITE_NONE
);
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
var triggers = encodeURIComponent(
JSON.stringify({
@ -51,7 +54,7 @@ function finish_test(count) {
{}
);
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();

Просмотреть файл

@ -20,8 +20,11 @@ function test() {
Ci.nsICookie.SAMESITE_NONE
);
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
Services.prefs.setIntPref("network.cookie.cookieBehavior", 1);
@ -55,7 +58,7 @@ function finish_test(count) {
Services.prefs.clearUserPref("network.cookie.cookieBehavior");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();

Просмотреть файл

@ -21,8 +21,11 @@ function test() {
Ci.nsICookie.SAMESITE_NONE
);
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
Services.prefs.setIntPref("network.cookie.cookieBehavior", 1);
@ -55,7 +58,7 @@ function finish_test(count) {
);
Services.prefs.clearUserPref("network.cookie.cookieBehavior");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();

Просмотреть файл

@ -6,8 +6,11 @@ function test() {
Harness.finalContentEvent = "InstallComplete";
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
var triggers = encodeURIComponent(
JSON.stringify({
@ -27,7 +30,7 @@ function download_failed(install) {
const finish_test = async function(count) {
is(count, 0, "No add-ons should have been installed");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
const results = await ContentTask.spawn(
gBrowser.selectedBrowser,

Просмотреть файл

@ -53,7 +53,7 @@ function install_blocked(installInfo) {
function finish_test(count) {
is(count, 0, "No add-ons should have been installed");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();

Просмотреть файл

@ -422,7 +422,7 @@ var TESTS = [
let installs = await AddonManager.getAllInstalls();
is(installs.length, 0, "Should be no pending installs");
let installPerm = Services.perms.testPermission(
let installPerm = PermissionTestUtils.testPermission(
gBrowser.currentURI,
"install"
);
@ -480,8 +480,11 @@ var TESTS = [
let originalTab = gBrowser.selectedTab;
let tab;
gBrowser.selectedTab = originalTab;
let pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
let progressPromise = waitForProgressNotification();
let dialogPromise = waitForInstallDialog();
@ -532,15 +535,18 @@ var TESTS = [
addon.uninstall();
Services.perms.remove(makeURI("http://example.com/"), "install");
PermissionTestUtils.remove("http://example.com/", "install");
Services.prefs.clearUserPref("extensions.allowPrivateBrowsingByDefault");
await removeTabAndWaitForNotificationClose();
},
async function test_failedDownload() {
let pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
let progressPromise = waitForProgressNotification();
let failPromise = waitForNotification("addon-install-failed");
@ -563,13 +569,16 @@ var TESTS = [
"Should have seen the right message"
);
Services.perms.remove(makeURI("http://example.com/"), "install");
PermissionTestUtils.remove("http://example.com/", "install");
await removeTabAndWaitForNotificationClose();
},
async function test_corruptFile() {
let pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
let progressPromise = waitForProgressNotification();
let failPromise = waitForNotification("addon-install-failed");
@ -593,13 +602,16 @@ var TESTS = [
"Should have seen the right message"
);
Services.perms.remove(makeURI("http://example.com/"), "install");
PermissionTestUtils.remove("http://example.com/", "install");
await removeTabAndWaitForNotificationClose();
},
async function test_incompatible() {
let pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
let progressPromise = waitForProgressNotification();
let failPromise = waitForNotification("addon-install-failed");
@ -629,7 +641,7 @@ var TESTS = [
"Should have seen the right message"
);
Services.perms.remove(makeURI("http://example.com/"), "install");
PermissionTestUtils.remove("http://example.com/", "install");
await removeTabAndWaitForNotificationClose();
},
@ -807,8 +819,11 @@ var TESTS = [
},
async function test_cancel() {
let pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
let notificationPromise = waitForNotification(PROGRESS_NOTIFICATION);
let triggers = encodeURIComponent(
@ -862,7 +877,7 @@ var TESTS = [
let installs = await AddonManager.getAllInstalls();
is(installs.length, 0, "Should be no pending install");
Services.perms.remove(makeURI("http://example.com/"), "install");
PermissionTestUtils.remove("http://example.com/", "install");
BrowserTestUtils.removeTab(gBrowser.selectedTab);
},

Просмотреть файл

@ -5,8 +5,11 @@ function test() {
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
var triggers = encodeURIComponent(
JSON.stringify({
@ -26,7 +29,7 @@ function download_failed(install) {
function finish_test(count) {
is(count, 0, "No add-ons should have been installed");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();

Просмотреть файл

@ -6,8 +6,11 @@ function test() {
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
var triggers = encodeURIComponent(
JSON.stringify({
@ -34,7 +37,7 @@ function install_ended(install, addon) {
function finish_test(count) {
is(count, 1, "1 Add-on should have been successfully installed");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();

Просмотреть файл

@ -6,8 +6,11 @@ function test() {
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
var triggers = encodeURIComponent(
JSON.stringify({
@ -34,7 +37,7 @@ function install_ended(install, addon) {
function finish_test(count) {
is(count, 1, "1 Add-on should have been successfully installed");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();

Просмотреть файл

@ -7,8 +7,11 @@ function test() {
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
Services.prefs.setBoolPref(PREF_INSTALL_REQUIREBUILTINCERTS, false);
var url = "https://example.com/browser/" + RELATIVE_DIR + "hashRedirect.sjs";
@ -41,7 +44,7 @@ function install_ended(install, addon) {
function finish_test(count) {
is(count, 1, "1 Add-on should have been successfully installed");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
Services.prefs.clearUserPref(PREF_INSTALL_REQUIREBUILTINCERTS);
gBrowser.removeCurrentTab();

Просмотреть файл

@ -7,8 +7,11 @@ function test() {
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
Services.prefs.setBoolPref(PREF_INSTALL_REQUIREBUILTINCERTS, false);
var url = "https://example.com/browser/" + RELATIVE_DIR + "hashRedirect.sjs";
@ -38,7 +41,7 @@ function download_failed(install) {
function finish_test(count) {
is(count, 0, "0 Add-ons should have been successfully installed");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
Services.prefs.clearUserPref(PREF_INSTALL_REQUIREBUILTINCERTS);
gBrowser.removeCurrentTab();

Просмотреть файл

@ -6,8 +6,11 @@ function test() {
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
Services.prefs.setBoolPref(PREF_INSTALL_REQUIREBUILTINCERTS, false);
var url = "https://example.com/browser/" + RELATIVE_DIR + "hashRedirect.sjs";
@ -38,7 +41,7 @@ function install_ended(install, addon) {
function finish_test(count) {
is(count, 1, "1 Add-on should have been successfully installed");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
Services.prefs.clearUserPref(PREF_INSTALL_REQUIREBUILTINCERTS);
gBrowser.removeCurrentTab();

Просмотреть файл

@ -6,8 +6,11 @@ function test() {
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
var url = "http://example.com/browser/" + RELATIVE_DIR + "hashRedirect.sjs";
url += "?sha1:foobar|" + TESTROOT + "amosigned.xpi";
@ -36,7 +39,7 @@ function install_ended(install, addon) {
function finish_test(count) {
is(count, 1, "1 Add-on should have been successfully installed");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();

Просмотреть файл

@ -6,8 +6,11 @@ function test() {
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
Services.prefs.setBoolPref(PREF_INSTALL_REQUIREBUILTINCERTS, false);
var url = "https://example.com/browser/" + RELATIVE_DIR + "hashRedirect.sjs";
@ -39,7 +42,7 @@ function install_ended(install, addon) {
function finish_test(count) {
is(count, 1, "1 Add-on should have been successfully installed");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
Services.prefs.clearUserPref(PREF_INSTALL_REQUIREBUILTINCERTS);
gBrowser.removeCurrentTab();

Просмотреть файл

@ -20,8 +20,11 @@ function test() {
Harness.installsCompletedCallback = finish_failed_download;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
Services.prefs.setBoolPref(PREF_INSTALL_REQUIREBUILTINCERTS, false);
// Set up the redirect to give a bad hash
@ -93,7 +96,7 @@ function install_ended(install, addon) {
function finish_test(count) {
is(count, 1, "1 Add-on should have been successfully installed");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
Services.prefs.clearUserPref(PREF_INSTALL_REQUIREBUILTINCERTS);
gBrowser.removeCurrentTab();

Просмотреть файл

@ -5,8 +5,11 @@ function test() {
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
BrowserTestUtils.loadURI(
@ -23,7 +26,7 @@ function install_ended(install, addon) {
function finish_test(count) {
is(count, 1, "1 Add-on should have been successfully installed");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();

Просмотреть файл

@ -17,8 +17,7 @@ async function test() {
win = await BrowserTestUtils.openNewBrowserWindow();
Harness.setup(win);
const pm = Services.perms;
pm.add(exampleURI, "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(exampleURI, "install", Services.perms.ALLOW_ACTION);
const triggers = encodeURIComponent(
JSON.stringify({
@ -45,7 +44,7 @@ function confirm_install(panel) {
async function finish_test(count) {
is(count, 1, "1 Add-on should have been successfully installed");
Services.perms.remove(exampleURI, "install");
PermissionTestUtils.remove(exampleURI, "install");
const results = await ContentTask.spawn(
win.gBrowser.selectedBrowser,

Просмотреть файл

@ -7,8 +7,11 @@ function test() {
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
var triggers = encodeURIComponent(
JSON.stringify({
@ -59,7 +62,7 @@ function finish_test(count) {
Services.io.offline = false;
} catch (ex) {}
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
wait_for_online();
}

Просмотреть файл

@ -32,8 +32,11 @@ async function test() {
gPrivateWin = await BrowserTestUtils.openNewBrowserWindow({ private: true });
Harness.setup(gPrivateWin);
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
var triggers = encodeURIComponent(
JSON.stringify({
@ -83,7 +86,7 @@ const finish_test = async function(count) {
Services.obs.removeObserver(check_channel, "http-on-before-connect");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
const results = await ContentTask.spawn(
gPrivateWin.gBrowser.selectedBrowser,

Просмотреть файл

@ -7,8 +7,11 @@ function test() {
Harness.finalContentEvent = "InstallComplete";
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
var triggers = encodeURIComponent(
JSON.stringify({
@ -40,7 +43,7 @@ function install_ended(install, addon) {
const finish_test = async function(count) {
is(count, 1, "1 Add-on should have been successfully installed");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
const results = await ContentTask.spawn(
gBrowser.selectedBrowser,

Просмотреть файл

@ -7,8 +7,11 @@ function test() {
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
var triggers = encodeURIComponent(
JSON.stringify({
@ -34,7 +37,7 @@ function install_ended(install, addon) {
function finish_test(count) {
is(count, 1, "1 Add-on should have been successfully installed");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();

Просмотреть файл

@ -5,8 +5,11 @@ function test() {
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
BrowserTestUtils.loadURI(
@ -23,7 +26,7 @@ function install_ended(install, addon) {
function finish_test(count) {
is(count, 1, "1 Add-on should have been successfully installed");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();

Просмотреть файл

@ -7,8 +7,11 @@ function test() {
Harness.finalContentEvent = "InstallComplete";
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
BrowserTestUtils.loadURI(gBrowser, TESTROOT + "triggerredirect.html");
@ -26,7 +29,7 @@ function install_ended(install, addon) {
function finish_test(count) {
is(count, 1, "1 Add-on should have been successfully installed");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
is(
gBrowser.currentURI.spec,

Просмотреть файл

@ -8,8 +8,11 @@ function test() {
Harness.finalContentEvent = "InstallComplete";
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
var triggers = encodeURIComponent(
JSON.stringify({
@ -41,7 +44,7 @@ function install_ended(install, addon) {
const finish_test = async function(count) {
is(count, 1, "1 Add-on should have been successfully installed");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
const results = await ContentTask.spawn(
gBrowser.selectedBrowser,

Просмотреть файл

@ -9,8 +9,11 @@ function test() {
Harness.finalContentEvent = "InstallComplete";
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
var inner_url = encodeURIComponent(
TESTROOT +
@ -46,7 +49,7 @@ function install_ended(install, addon) {
const finish_test = async function(count) {
is(count, 1, "1 Add-on should have been successfully installed");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
const results = await ContentTask.spawn(
gBrowser.selectedBrowser,

Просмотреть файл

@ -9,8 +9,11 @@ function test() {
Harness.finalContentEvent = "InstallComplete";
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
PermissionTestUtils.add(
"http://example.com/",
"install",
Services.perms.ALLOW_ACTION
);
var inner_url = encodeURIComponent(
TESTROOT +
@ -45,7 +48,7 @@ function finish_test(count) {
);
is(count, 0, "No add-ons should have been installed");
Services.perms.remove(makeURI("http://example.com"), "install");
PermissionTestUtils.remove("http://example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();

Просмотреть файл

@ -1,5 +1,9 @@
/* eslint no-unused-vars: ["error", {vars: "local", args: "none"}] */
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
const RELATIVE_DIR = "toolkit/mozapps/extensions/test/xpinstall/";
const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR;