Bug 1196665 - Add originAttributes into SpecialPowers. r=bholley

From 7bb0fbba24f4f65d3fa83efe223b1431cd71fdb6 Mon Sep 17 00:00:00 2001
---
 dom/apps/tests/test_third_party_homescreen.html    |   8 +-
 .../test/test_messagemanager_assertpermission.html |   4 +-
 dom/base/test/test_messagemanager_targetchain.html |  16 +--
 ...rowserElement_AllowEmbedAppsInNestedOOIframe.js |  11 +-
 .../mochitest/browserElement_CopyPaste.js          |   9 +-
 .../browserElement_DisallowEmbedAppsInOOP.js       |   9 +-
 .../mochitest/browserElement_Proxy.js              |  10 +-
 .../browserElement_SetInputMethodActive.js         |   3 +-
 .../mochitest/browserElement_SetVisibleFrames.js   |  17 ++--
 .../mochitest/browserElement_SetVisibleFrames2.js  |  16 +--
 .../priority/test_ExpectingSystemMessage2.html     |  16 +--
 .../mochitest/priority/test_NestedFrames.html      |  16 +--
 dom/cache/test/mochitest/driver.js                 |  11 +-
 .../test/mochitest/test_cache_orphaned_body.html   |  33 +-----
 .../test/mochitest/test_cache_orphaned_cache.html  |  33 +-----
 dom/cache/test/mochitest/test_cache_restart.html   |  11 +-
 dom/cache/test/mochitest/test_cache_shrink.html    |  33 +-----
 dom/indexedDB/test/file.js                         |  12 +--
 dom/indexedDB/test/helpers.js                      |   9 +-
 dom/indexedDB/test/webapp_clearBrowserData.js      |   6 +-
 dom/inputmethod/mochitest/test_bug1043828.html     |   5 +-
 dom/inputmethod/mochitest/test_bug944397.html      |   5 +-
 .../mochitest/test_focus_blur_manage_events.html   |   5 +-
 .../mochitest/test_input_registry_events.html      |   5 +-
 .../mochitest/test_simple_manage_events.html       |   5 +-
 .../tests/test_permission_for_nested_oop_app.html  |   3 +-
 .../tests/test_permission_for_two_oop_apps.html    |   3 +-
 dom/ipc/tests/test_permission_helper.js            |  21 ++--
 .../test_permission_when_oop_app_crashes.html      |   3 +-
 dom/tv/test/mochitest/head.js                      |   5 +-
 .../test_SpecialPowersPushAppPermissions.html      |  14 ++-
 .../tests/Harness_sanity/test_bug816847.html       |   6 +-
 .../components/SpecialPowersObserver.js            |   4 +-
 .../content/SpecialPowersObserverAPI.js            |  24 +----
 testing/specialpowers/content/specialpowersAPI.js  | 111 ++++++++-------------
 35 files changed, 173 insertions(+), 329 deletions(-)
This commit is contained in:
Yoshi Huang 2015-10-07 14:35:43 +08:00
Родитель 1509beca39
Коммит 176a15f268
35 изменённых файлов: 173 добавлений и 329 удалений

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

@ -164,11 +164,11 @@ function runTest() {
ok(app, "App is non-null");
is(app.manifestURL, gManifestURL, "App manifest url is correct.");
var context = {"manifestURL": app.manifestURL, "isInBrowserElement": false};
var context = {manifestURL: app.manifestURL};
SpecialPowers.pushPermissions([{"type": "homescreen-webapps-manage",
"allow": 1,
"context": context}], continueTest);
SpecialPowers.pushPermissions([{type: "homescreen-webapps-manage",
allow: 1,
context: context}], continueTest);
yield undefined;
// Launch the app.

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

@ -32,8 +32,8 @@ function setUp() {
let appId = gAppsService.getAppLocalIdByManifestURL(APP_MANIFEST);
SpecialPowers.addPermission("foobar", true, { url: APP_URL,
appId: appId,
isInBrowserElement: false });
originAttributes: { appId: appId }
});
SpecialPowers.pushPrefEnv({"set":[['dom.mozBrowserFramesEnabled', true],
['dom.ipc.browser_frames.oop_by_default', true]]}, runNextTest);
}

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

@ -103,15 +103,17 @@
addEventListener("load", function() {
var principal = SpecialPowers.wrap(document).nodePrincipal;
SpecialPowers.pushPermissions([
{ "type": "browser", "allow": 1, "context": { "url": principal.URI.spec,
"appId": principal.appId,
"isInBrowserElement": false }},
{ "type": "browser", "allow": 1, "context": { "url": principal.URI.spec,
"appId": principal.appId,
"isInBrowserElement": true }}
{ type: "browser", allow: 1, context: { url: principal.URI.spec,
originAttributes: {
appId: principal.appId
}}},
{ type: "browser", allow: 1, context: { url: principal.URI.spec,
originAttributes: {
appId: principal.appId,
inBrowser: true }}}
], () => {
SpecialPowers.pushPrefEnv({
"set": [
set: [
["dom.mozBrowserFramesEnabled", true],
["dom.ipc.browser_frames.oop_by_default", false],
]

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

@ -22,17 +22,16 @@ function runTest() {
document.body.appendChild(iframe);
var context = { 'url': 'http://example.org',
'appId': SpecialPowers.Ci.nsIScriptSecurityManager.NO_APP_ID,
'isInBrowserElement': true };
var context = {url: 'http://example.org',
originAttributes: {inBrowser: true}};
SpecialPowers.pushPermissions([
{'type': 'browser', 'allow': 1, 'context': context},
{'type': 'embed-apps', 'allow': 1, 'context': context}
{type: 'browser', allow: 1, context: context},
{type: 'embed-apps', allow: 1, context: context}
], function() {
iframe.src = 'http://example.org/tests/dom/browser-element/mochitest/file_browserElement_AllowEmbedAppsInNestedOOIframe.html';
});
}
addEventListener('testready', () => {
SpecialPowers.pushPrefEnv({"set": [["dom.ipc.tabs.nested.enabled", true]]}, runTest);
SpecialPowers.pushPrefEnv({set: [["dom.ipc.tabs.nested.enabled", true]]}, runTest);
});

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

@ -343,13 +343,14 @@ function testCut2(e) {
// Give our origin permission to open browsers, and remove it when the test is complete.
var principal = SpecialPowers.wrap(document).nodePrincipal;
var context = { 'url': SpecialPowers.wrap(principal.URI).spec,
'appId': principal.appId,
'isInBrowserElement': true };
var context = { url: SpecialPowers.wrap(principal.URI).spec,
originAttributes: {
appId: principal.appId,
inBrowser: true }};
addEventListener('testready', function() {
SpecialPowers.pushPermissions([
{'type': 'browser', 'allow': 1, 'context': context}
{type: 'browser', allow: 1, context: context}
], runTest);
});

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

@ -28,12 +28,11 @@ function runTest() {
document.body.appendChild(iframe);
var context = { 'url': 'http://example.org',
'appId': SpecialPowers.Ci.nsIScriptSecurityManager.NO_APP_ID,
'isInBrowserElement': true };
var context = {url: 'http://example.org',
originAttributes: {inBrowser: true}};
SpecialPowers.pushPermissions([
{'type': 'browser', 'allow': 1, 'context': context},
{'type': 'embed-apps', 'allow': 1, 'context': context}
{type: 'browser', allow: 1, context: context},
{type: 'embed-apps', allow: 1, context: context}
], function() {
iframe.src = 'http://example.org/tests/dom/browser-element/mochitest/file_browserElement_DisallowEmbedAppsInOOP.html';
});

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

@ -14,16 +14,18 @@ function runTest() {
allow: true,
context: {
url: frameUrl,
appId: SpecialPowers.Ci.nsIScriptSecurityManager.NO_APP_ID,
isInBrowserElement: true
originAttributes: {
inBrowser: true
}
}
},{
type: 'browser',
allow: true,
context: {
url: frameUrl,
appId: SpecialPowers.Ci.nsIScriptSecurityManager.NO_APP_ID,
isInBrowserElement: true
originAttributes: {
inBrowser: true
}
}
}], createFrame);
}

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

@ -36,8 +36,7 @@ function runTest() {
allow: true,
context: {
url: imeUrl,
appId: SpecialPowers.Ci.nsIScriptSecurityManager.NO_APP_ID,
isInBrowserElement: true
originAttributes: {inBrowser: true}
}
}], SimpleTest.waitForFocus.bind(SimpleTest, createFrames));
}

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

@ -18,9 +18,11 @@ var iframe;
function runTest() {
var principal = SpecialPowers.wrap(document).nodePrincipal;
SpecialPowers.addPermission("browser", true, { url: SpecialPowers.wrap(principal.URI).spec,
appId: principal.appId,
isInBrowserElement: true });
SpecialPowers.addPermission("browser", true, {url: SpecialPowers.wrap(principal.URI).spec,
originAttributes: {
appId: principal.appId,
inBrowser: true
}});
iframe = document.createElement('iframe');
iframe.setAttribute('mozbrowser', 'true');
@ -75,10 +77,11 @@ function finish() {
iframe.removeEventListener('mozbrowsershowmodalprompt', checkMessage);
var principal = SpecialPowers.wrap(document).nodePrincipal;
SpecialPowers.removePermission("browser", { url: SpecialPowers.wrap(principal.URI).spec,
appId: principal.appId,
isInBrowserElement: true });
SpecialPowers.removePermission("browser", {url: SpecialPowers.wrap(principal.URI).spec,
originAttributes: {
appId: principal.appId,
inBrowser: true
}});
SimpleTest.finish();
}

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

@ -12,9 +12,11 @@ browserElementTestHelpers.addPermission();
function runTest() {
var principal = SpecialPowers.wrap(document).nodePrincipal;
SpecialPowers.addPermission("browser", true, { url: SpecialPowers.wrap(principal.URI).spec,
appId: principal.appId,
isInBrowserElement: true });
SpecialPowers.addPermission("browser", true, {url: SpecialPowers.wrap(principal.URI).spec,
originAttributes: {
appId: principal.appId,
inBrowser: true
}});
var iframe = document.createElement('iframe');
iframe.setAttribute('mozbrowser', 'true');
@ -56,9 +58,11 @@ function runTest() {
function finish() {
var principal = SpecialPowers.wrap(document).nodePrincipal;
SpecialPowers.removePermission("browser", { url: SpecialPowers.wrap(principal.URI).spec,
appId: principal.appId,
isInBrowserElement: true });
SpecialPowers.removePermission("browser", {url: SpecialPowers.wrap(principal.URI).spec,
originAttributes: {
appId: principal.appId,
inBrowser: true
}});
SimpleTest.finish();
}

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

@ -22,15 +22,19 @@ SpecialPowers.addPermission("embed-apps", true, document);
// Give our origin permission to open browsers, and remove it when the test is complete.
var principal = SpecialPowers.wrap(document).nodePrincipal;
SpecialPowers.addPermission("browser", true, { url: SpecialPowers.wrap(principal.URI).spec,
appId: principal.appId,
isInBrowserElement: true });
SpecialPowers.addPermission("browser", true, {url: SpecialPowers.wrap(principal.URI).spec,
originAttributes: {
appId: principal.appId,
inBrowser: true
}});
addEventListener('unload', function() {
var principal = SpecialPowers.wrap(document).nodePrincipal;
SpecialPowers.removePermission("browser", { url: SpecialPowers.wrap(principal.URI).spec,
appId: principal.appId,
isInBrowserElement: true });
SpecialPowers.removePermission("browser", {url: SpecialPowers.wrap(principal.URI).spec,
originAttributes: {
appId: principal.appId,
inBrowser: true
}});
});
function runTest() {

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

@ -21,15 +21,19 @@ browserElementTestHelpers.enableProcessPriorityManager();
// Give our origin permission to open browsers, and remove it when the test is complete.
var principal = SpecialPowers.wrap(document).nodePrincipal;
SpecialPowers.addPermission("browser", true, { url: SpecialPowers.wrap(principal.URI).spec,
appId: principal.appId,
isInBrowserElement: true });
SpecialPowers.addPermission("browser", true, {url: SpecialPowers.wrap(principal.URI).spec,
originAttributes: {
appId: principal.appId,
inBrowser: true
}});
addEventListener('unload', function() {
var principal = SpecialPowers.wrap(document).nodePrincipal;
SpecialPowers.removePermission("browser", { url: SpecialPowers.wrap(principal.URI).spec,
appId: principal.appId,
isInBrowserElement: true });
SpecialPowers.removePermission("browser", {url: SpecialPowers.wrap(principal.URI).spec,
originAttributes: {
appId: principal.appId,
inBrowser: true
}});
});
function runTest() {

11
dom/cache/test/mochitest/driver.js поставляемый
Просмотреть файл

@ -35,16 +35,7 @@ function runTests(testFile, order) {
// adapted from dom/indexedDB/test/helpers.js
function clearStorage() {
return new Promise(function(resolve, reject) {
var principal = SpecialPowers.wrap(document).nodePrincipal;
var appId, inBrowser;
var nsIPrincipal = SpecialPowers.Components.interfaces.nsIPrincipal;
if (principal.appId != nsIPrincipal.UNKNOWN_APP_ID &&
principal.appId != nsIPrincipal.NO_APP_ID) {
appId = principal.appId;
inBrowser = principal.isInBrowserElement;
}
SpecialPowers.clearStorageForURI(document.documentURI, resolve, appId,
inBrowser);
SpecialPowers.clearStorageForDoc(SpecialPowers.wrap(document), resolve);
});
}

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

@ -24,46 +24,19 @@ function setupTestIframe() {
function clearStorage() {
return new Promise(function(resolve, reject) {
var principal = SpecialPowers.wrap(document).nodePrincipal;
var appId, inBrowser;
var nsIPrincipal = SpecialPowers.Components.interfaces.nsIPrincipal;
if (principal.appId != nsIPrincipal.UNKNOWN_APP_ID &&
principal.appId != nsIPrincipal.NO_APP_ID) {
appId = principal.appId;
inBrowser = principal.isInBrowserElement;
}
SpecialPowers.clearStorageForURI(document.documentURI, resolve, appId,
inBrowser);
SpecialPowers.clearStorageForDoc(SpecialPowers.wrap(document), resolve);
});
}
function storageUsage() {
return new Promise(function(resolve, reject) {
var principal = SpecialPowers.wrap(document).nodePrincipal;
var appId, inBrowser;
var nsIPrincipal = SpecialPowers.Components.interfaces.nsIPrincipal;
if (principal.appId != nsIPrincipal.UNKNOWN_APP_ID &&
principal.appId != nsIPrincipal.NO_APP_ID) {
appId = principal.appId;
inBrowser = principal.isInBrowserElement;
}
SpecialPowers.getStorageUsageForURI(document.documentURI, resolve, appId,
inBrowser);
SpecialPowers.getStorageUsageForDoc(SpecialPowers.wrap(document), resolve);
});
}
function resetStorage() {
return new Promise(function(resolve, reject) {
var principal = SpecialPowers.wrap(document).nodePrincipal;
var appId, inBrowser;
var nsIPrincipal = SpecialPowers.Components.interfaces.nsIPrincipal;
if (principal.appId != nsIPrincipal.UNKNOWN_APP_ID &&
principal.appId != nsIPrincipal.NO_APP_ID) {
appId = principal.appId;
inBrowser = principal.isInBrowserElement;
}
SpecialPowers.resetStorageForURI(document.documentURI, resolve, appId,
inBrowser);
SpecialPowers.resetStorageForDoc(SpecialPowers.wrap(document), resolve);
});
}

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

@ -24,46 +24,19 @@ function setupTestIframe() {
function clearStorage() {
return new Promise(function(resolve, reject) {
var principal = SpecialPowers.wrap(document).nodePrincipal;
var appId, inBrowser;
var nsIPrincipal = SpecialPowers.Components.interfaces.nsIPrincipal;
if (principal.appId != nsIPrincipal.UNKNOWN_APP_ID &&
principal.appId != nsIPrincipal.NO_APP_ID) {
appId = principal.appId;
inBrowser = principal.isInBrowserElement;
}
SpecialPowers.clearStorageForURI(document.documentURI, resolve, appId,
inBrowser);
SpecialPowers.clearStorageForDoc(SpecialPowers.wrap(document), resolve);
});
}
function storageUsage() {
return new Promise(function(resolve, reject) {
var principal = SpecialPowers.wrap(document).nodePrincipal;
var appId, inBrowser;
var nsIPrincipal = SpecialPowers.Components.interfaces.nsIPrincipal;
if (principal.appId != nsIPrincipal.UNKNOWN_APP_ID &&
principal.appId != nsIPrincipal.NO_APP_ID) {
appId = principal.appId;
inBrowser = principal.isInBrowserElement;
}
SpecialPowers.getStorageUsageForURI(document.documentURI, resolve, appId,
inBrowser);
SpecialPowers.getStorageUsageForDoc(SpecialPowers.wrap(document), resolve);
});
}
function resetStorage() {
return new Promise(function(resolve, reject) {
var principal = SpecialPowers.wrap(document).nodePrincipal;
var appId, inBrowser;
var nsIPrincipal = SpecialPowers.Components.interfaces.nsIPrincipal;
if (principal.appId != nsIPrincipal.UNKNOWN_APP_ID &&
principal.appId != nsIPrincipal.NO_APP_ID) {
appId = principal.appId;
inBrowser = principal.isInBrowserElement;
}
SpecialPowers.resetStorageForURI(document.documentURI, resolve, appId,
inBrowser);
SpecialPowers.resetStorageForDoc(SpecialPowers.wrap(document), resolve);
});
}

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

@ -23,16 +23,7 @@ function setupTestIframe() {
function resetStorage() {
return new Promise(function(resolve, reject) {
var principal = SpecialPowers.wrap(document).nodePrincipal;
var appId, inBrowser;
var nsIPrincipal = SpecialPowers.Components.interfaces.nsIPrincipal;
if (principal.appId != nsIPrincipal.UNKNOWN_APP_ID &&
principal.appId != nsIPrincipal.NO_APP_ID) {
appId = principal.appId;
inBrowser = principal.isInBrowserElement;
}
SpecialPowers.resetStorageForURI(document.documentURI, resolve, appId,
inBrowser);
SpecialPowers.resetStorageForDoc(SpecialPowers.wrap(document), resolve);
});
}

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

@ -24,46 +24,19 @@ function setupTestIframe() {
function clearStorage() {
return new Promise(function(resolve, reject) {
var principal = SpecialPowers.wrap(document).nodePrincipal;
var appId, inBrowser;
var nsIPrincipal = SpecialPowers.Components.interfaces.nsIPrincipal;
if (principal.appId != nsIPrincipal.UNKNOWN_APP_ID &&
principal.appId != nsIPrincipal.NO_APP_ID) {
appId = principal.appId;
inBrowser = principal.isInBrowserElement;
}
SpecialPowers.clearStorageForURI(document.documentURI, resolve, appId,
inBrowser);
SpecialPowers.clearStorageForDoc(SpecialPowers.wrap(document), resolve);
});
}
function storageUsage() {
return new Promise(function(resolve, reject) {
var principal = SpecialPowers.wrap(document).nodePrincipal;
var appId, inBrowser;
var nsIPrincipal = SpecialPowers.Components.interfaces.nsIPrincipal;
if (principal.appId != nsIPrincipal.UNKNOWN_APP_ID &&
principal.appId != nsIPrincipal.NO_APP_ID) {
appId = principal.appId;
inBrowser = principal.isInBrowserElement;
}
SpecialPowers.getStorageUsageForURI(document.documentURI, resolve, appId,
inBrowser);
SpecialPowers.getStorageUsageForDoc(SpecialPowers.wrap(document), resolve);
});
}
function resetStorage() {
return new Promise(function(resolve, reject) {
var principal = SpecialPowers.wrap(document).nodePrincipal;
var appId, inBrowser;
var nsIPrincipal = SpecialPowers.Components.interfaces.nsIPrincipal;
if (principal.appId != nsIPrincipal.UNKNOWN_APP_ID &&
principal.appId != nsIPrincipal.NO_APP_ID) {
appId = principal.appId;
inBrowser = principal.isInBrowserElement;
}
SpecialPowers.resetStorageForURI(document.documentURI, resolve, appId,
inBrowser);
SpecialPowers.resetStorageForDoc(SpecialPowers.wrap(document), resolve);
});
}

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

@ -189,17 +189,7 @@ function grabFileUsageAndContinueHandler(usage, fileUsage)
function getUsage(usageHandler)
{
let principal = SpecialPowers.wrap(document).nodePrincipal;
let appId, inBrowser;
if (principal.appId != Components.interfaces.nsIPrincipal.UNKNOWN_APP_ID &&
principal.appId != Components.interfaces.nsIPrincipal.NO_APP_ID) {
appId = principal.appId;
inBrowser = principal.isInBrowserElement;
}
SpecialPowers.getStorageUsageForURI(window.document.documentURI,
usageHandler,
appId,
inBrowser);
SpecialPowers.getStorageUsageForDoc(SpecialPowers.wrap(document), usageHandler);
}
function getFileId(file)

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

@ -34,14 +34,7 @@ function executeSoon(aFun)
}
function clearAllDatabases(callback) {
let principal = SpecialPowers.wrap(document).nodePrincipal;
let appId, inBrowser;
if (principal.appId != Components.interfaces.nsIPrincipal.UNKNOWN_APP_ID &&
principal.appId != Components.interfaces.nsIPrincipal.NO_APP_ID) {
appId = principal.appId;
inBrowser = principal.isInBrowserElement;
}
SpecialPowers.clearStorageForURI(document.documentURI, callback, appId, inBrowser);
SpecialPowers.clearStorageForDoc(SpecialPowers.wrap(document), callback);
}
var testHarnessGenerator = testHarnessSteps();

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

@ -117,11 +117,9 @@ function start()
}
SpecialPowers.addPermission("browser", true, document);
SpecialPowers.addPermission("browser", true, { manifestURL: manifestURL,
isInBrowserElement: false });
SpecialPowers.addPermission("browser", true, { manifestURL: manifestURL });
SpecialPowers.addPermission("embed-apps", true, document);
SpecialPowers.addPermission("indexedDB", true, { manifestURL: manifestURL,
isInBrowserElement: false });
SpecialPowers.addPermission("indexedDB", true, { manifestURL: manifestURL });
SpecialPowers.setAllAppsLaunchable(true);

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

@ -91,8 +91,9 @@ function runTest() {
allow: true,
context: {
url: imeUrl,
appId: SpecialPowers.Ci.nsIScriptSecurityManager.NO_APP_ID,
isInBrowserElement: true
originAttributes: {
inBrowser: true
}
}
}], function() {
keyboardA.src = imeUrl;

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

@ -78,8 +78,9 @@ function runTest() {
allow: true,
context: {
url: imeUrl,
appId: SpecialPowers.Ci.nsIScriptSecurityManager.NO_APP_ID,
isInBrowserElement: true
originAttributes: {
inBrowser: true
}
}
}], function() {
// STEP 2c: Tell Gecko to use this iframe as its keyboard app

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

@ -141,8 +141,9 @@ function setupInputAppFrame() {
allow: true,
context: {
url: imeUrl,
appId: SpecialPowers.Ci.nsIScriptSecurityManager.NO_APP_ID,
isInBrowserElement: true
originAttributes: {
inBrowser: true
}
}
}], function() {
let mm = SpecialPowers.getBrowserFrameMessageManager(inputAppFrame);

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

@ -70,8 +70,9 @@ function setupInputAppFrame() {
allow: true,
context: {
url: imeUrl,
appId: SpecialPowers.Ci.nsIScriptSecurityManager.NO_APP_ID,
isInBrowserElement: true
originAttributes: {
inBrowser: true
}
}
}], function() {
let mm = appFrameMM =

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

@ -103,8 +103,9 @@ function setupInputAppFrame() {
allow: true,
context: {
url: imeUrl,
appId: SpecialPowers.Ci.nsIScriptSecurityManager.NO_APP_ID,
isInBrowserElement: true
originAttributes: {
inBrowser: true
}
}
}], function() {
let mm = appFrameMM =

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

@ -33,8 +33,7 @@ var tests = [
function() {
var appId = gAppsService.getAppLocalIdByManifestURL(embedAppHostedManifestURL);
var context = { url: embedApp.origin,
appId: appId,
isInBrowserElement: false };
originAttributes: { appId: appId } };
setupOpenAppPermission(context, runTests);
},

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

@ -33,8 +33,7 @@ var tests = [
function() {
var appId = gAppsService.getAppLocalIdByManifestURL(embedAppHostedManifestURL);
var context = { url: embedApp.origin,
appId: appId,
isInBrowserElement: false };
originAttributes: { appId: appId } };
setupOpenAppPermission(context, runTests);
},

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

@ -53,8 +53,7 @@ function test1() {
if (!SpecialPowers.hasPermission( PERMISSION_TYPE,
{ url: APP_URL,
appId: appId,
isInBrowserElement: false })) {
originAttributes: { appId: appId }})) {
errorHandler('[test 1] App should have permission: ' + PERMISSION_TYPE);
}
@ -82,8 +81,7 @@ function test2() {
if (!SpecialPowers.hasPermission( PERMISSION_TYPE,
{ url: APP_URL,
appId: appId,
isInBrowserElement: false })) {
originAttributes: { appId: appId }})) {
errorHandler('[test 2] App should have permission: ' + PERMISSION_TYPE);
}
@ -111,8 +109,7 @@ function test3() {
if (!SpecialPowers.hasPermission(PERMISSION_TYPE,
{ url: APP_URL,
appId: appId,
isInBrowserElement: false })) {
originAttributes: { appId: appId }})) {
errorHandler('[test 3] App should have permission: ' + PERMISSION_TYPE);
}
}
@ -148,8 +145,7 @@ function test4() {
if (!SpecialPowers.hasPermission(PERMISSION_TYPE,
{ url: APP_URL,
appId: appId,
isInBrowserElement: false })) {
originAttributes: { appId: appId }})) {
errorHandler('[test 4] App should have permission: ' + PERMISSION_TYPE);
}
}
@ -174,8 +170,7 @@ function test5() {
if (!SpecialPowers.hasPermission( PERMISSION_TYPE,
{ url: APP_URL,
appId: appId,
isInBrowserElement: false })) {
originAttributes: { appId: appId }})) {
errorHandler('[test 5] App should have permission: ' + PERMISSION_TYPE);
}
@ -290,8 +285,7 @@ function addPermissionToApp(appURL, manifestURL) {
"expireType":permManager.EXPIRE_SESSION,
"expireTime":now + SESSION_PERSIST_MINUTES*60*1000,
"context": { url: appURL,
appId: appId,
isInBrowserElement:false }
originAttributes: { appId: appId } }
}
], function() {
runTests();
@ -303,8 +297,7 @@ function runNextIfAppHasPermission(round, expect, appURL, manifestURL) {
var hasPerm = SpecialPowers.hasPermission(PERMISSION_TYPE,
{ url: appURL,
appId: appId,
isInBrowserElement: false });
originAttributes: { appId: appId }});
var result = (expect==hasPerm);
if (result) {
runTests();

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

@ -33,8 +33,7 @@ var tests = [
function() {
var appId = gAppsService.getAppLocalIdByManifestURL(embedAppHostedManifestURL);
var context = { url: embedApp.origin,
appId: appId,
isInBrowserElement: false };
originAttributes: { appId: appId } };
setupOpenAppPermission(context, runTests);
},

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

@ -22,8 +22,9 @@ function installApp(aTestToken, aTemplate) {
var appId = gAppsService.getAppLocalIdByManifestURL(gApp.manifestURL);
SpecialPowers.addPermission("tv", true, { url: gApp.origin,
appId: appId,
isInBrowserElement: false });
originAttributes: {
appId: appId
}});
runTest();
}

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

@ -69,8 +69,7 @@ function installApp(aTestToken, aTemplate) {
function pushPermissionsToApp() {
var appId = gAppsService.getAppLocalIdByManifestURL(gApp.manifestURL);
var context = { url: gApp.origin,
appId: appId,
isInBrowserElement: false };
originAttributes: {appId: appId}};
SpecialPowers.pushPermissions([
{ "type": "pAppPermission", "allow": true, "context": context }
], testPermissionsForApp);
@ -79,8 +78,7 @@ function pushPermissionsToApp() {
function testPermissionsForApp() {
var appId = gAppsService.getAppLocalIdByManifestURL(gApp.manifestURL);
var context = { url: gApp.origin,
appId: appId,
isInBrowserElement: false };
originAttributes: {appId: appId}};
ok(SpecialPowers.hasPermission('pAppPermission', context), 'pAppPermission should have permission');
uninstallApp();
}
@ -95,10 +93,10 @@ function uninstallApp() {
function testPermissionsForSelfAndApp() {
var appId = gAppsService.getAppLocalIdByManifestURL(gApp.manifestURL);
var context = { url: gApp.origin,
appId: appId,
isInBrowserElement: false };
ok(!SpecialPowers.hasPermission('pAppPermission', context), 'pAppPermission should not have permission');
is(appId, 0, "appId should become NO_APP_ID");
// since gApp is uninstalled, calling SpecialPowers.hasPermission with the
// app's properties (manifestURL, origin, principal, ... etc) will throw.
// So we don't need to test hasPermission for the app.
ok(SpecialPowers.hasPermission('pAppPermission', document), 'pAppPermission should have permission');

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

@ -57,8 +57,7 @@ function starttest(){
SpecialPowers.addPermission(perms[0], true, origin);
SpecialPowers.addPermission(perms[1], true, {manifestURL: manifest});
SpecialPowers.addPermission(perms[2], true, document);
SpecialPowers.addPermission(perms[3], true, {url: origin,
appId: Ci.nsIScriptSecurityManager.NO_APP_ID});
SpecialPowers.addPermission(perms[3], true, {url: origin});
is(Services.perms.testPermissionFromPrincipal(noappPrincipal, perms[0]),
allow, "Set permission by string");
@ -74,8 +73,7 @@ function starttest(){
SpecialPowers.removePermission(perms[0], origin);
SpecialPowers.removePermission(perms[1], {manifestURL: manifest});
SpecialPowers.removePermission(perms[2], document);
SpecialPowers.removePermission(perms[3], {url: origin,
appId: Ci.nsIScriptSecurityManager.NO_APP_ID});
SpecialPowers.removePermission(perms[3], {url: origin});
is(Services.perms.testPermissionFromPrincipal(noappPrincipal, perms[0]),
unknown, "Removed permission by string");

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

@ -234,7 +234,9 @@ SpecialPowersObserver.prototype = new SpecialPowersObserverAPI();
// We need to ensure that it looks the same as a real permission,
// so we fake these properties.
msg.permission = {
principal: { appId: permission.principal.appId },
principal: {
originAttributes: {appId: permission.principal.appId}
},
type: permission.type
};
default:

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

@ -321,11 +321,7 @@ SpecialPowersObserverAPI.prototype = {
case "SPPermissionManager": {
let msg = aMessage.json;
let secMan = Services.scriptSecurityManager;
// TODO: Bug 1196665 - Add originAttributes into SpecialPowers
let attrs = {appId: msg.appId, inBrowser: msg.isInBrowserElement};
let principal = secMan.createCodebasePrincipal(this._getURI(msg.url), attrs);
let principal = msg.principal;
switch (msg.op) {
case "add":
@ -336,17 +332,10 @@ SpecialPowersObserverAPI.prototype = {
break;
case "has":
let hasPerm = Services.perms.testPermissionFromPrincipal(principal, msg.type);
if (hasPerm == Ci.nsIPermissionManager.ALLOW_ACTION)
return true;
return false;
break;
return hasPerm == Ci.nsIPermissionManager.ALLOW_ACTION;
case "test":
let testPerm = Services.perms.testPermissionFromPrincipal(principal, msg.type, msg.value);
if (testPerm == msg.value) {
return true;
}
return false;
break;
return testPerm == msg.value;
default:
throw new SpecialPowersError(
"Invalid operation for SPPermissionManager");
@ -510,18 +499,13 @@ SpecialPowersObserverAPI.prototype = {
.frameLoader
.messageManager;
let msg = aMessage.data;
let principal = msg.principal;
let op = msg.op;
if (op != 'clear' && op != 'getUsage' && op != 'reset') {
throw new SpecialPowersError('Invalid operation for SPQuotaManager');
}
let secMan = Services.scriptSecurityManager;
let principal = secMan.createCodebasePrincipal(this._getURI(msg.uri), {
appId: msg.appId,
inBrowser: msg.inBrowser,
});
if (op == 'clear') {
qm.clearStoragesForPrincipal(principal);
} else if (op == 'reset') {

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

@ -786,8 +786,8 @@ SpecialPowersAPI.prototype = {
originalValue = Ci.nsICookiePermission.ACCESS_LIMIT_THIRD_PARTY;
}
let [url, appId, isInBrowserElement, isSystem] = this._getInfoFromPermissionArg(context);
if (isSystem) {
let principal = this._getPrincipalFromArg(context);
if (principal.isSystemPrincipal) {
continue;
}
@ -810,9 +810,7 @@ SpecialPowersAPI.prototype = {
'type': permission.type,
'permission': perm,
'value': perm,
'url': url,
'appId': appId,
'isInBrowserElement': isInBrowserElement,
'principal': principal,
'expireType': (typeof permission.expireType === "number") ?
permission.expireType : 0, // default: EXPIRE_NEVER
'expireTime': (typeof permission.expireTime === "number") ?
@ -967,7 +965,7 @@ SpecialPowersAPI.prototype = {
for (var j = 0; j < undos.length; j++) {
var undo = undos[j];
if (undo.op == this._obsDataMap[aData] &&
undo.appId == permission.principal.appId &&
undo.principal.originAttributes.appId == permission.principal.originAttributes.appId &&
undo.type == permission.type) {
// Remove this undo item if it has been done by others(not
// specialpowers itself.)
@ -1820,57 +1818,40 @@ SpecialPowersAPI.prototype = {
.messageManager);
},
_getInfoFromPermissionArg: function(arg) {
let url = "";
let appId = Ci.nsIScriptSecurityManager.NO_APP_ID;
let isInBrowserElement = false;
let isSystem = false;
_getPrincipalFromArg: function(arg) {
let principal;
let secMan = Services.scriptSecurityManager;
if (typeof(arg) == "string") {
// It's an URL.
url = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService)
.newURI(arg, null, null)
.spec;
let uri = Services.io.newURI(arg, null, null);
principal = secMan.createCodebasePrincipal(uri, {});
} else if (arg.manifestURL) {
// It's a thing representing an app.
let appsSvc = Cc["@mozilla.org/AppsService;1"]
.getService(Ci.nsIAppsService)
let app = appsSvc.getAppByManifestURL(arg.manifestURL);
if (!app) {
throw "No app for this manifest!";
}
appId = appsSvc.getAppLocalIdByManifestURL(arg.manifestURL);
url = app.origin;
isInBrowserElement = arg.isInBrowserElement || false;
principal = app.principal;
} else if (arg.nodePrincipal) {
// It's a document.
isSystem = (arg.nodePrincipal instanceof Ci.nsIPrincipal) &&
Cc["@mozilla.org/scriptsecuritymanager;1"].
getService(Ci.nsIScriptSecurityManager).
isSystemPrincipal(arg.nodePrincipal);
if (!isSystem) {
// System principals don't have a URL associated with them, and they
// don't really need any permissions to be registered with the
// permission manager anyway.
url = arg.nodePrincipal.URI.spec;
appId = arg.nodePrincipal.appId;
isInBrowserElement = arg.nodePrincipal.isInBrowserElement;
}
// In some tests the arg is a wrapped DOM element, so we unwrap it first.
principal = unwrapIfWrapped(arg).nodePrincipal;
} else {
url = arg.url;
appId = arg.appId;
isInBrowserElement = arg.isInBrowserElement;
let uri = Services.io.newURI(arg.url, null, null);
let attrs = arg.originAttributes || {};
principal = secMan.createCodebasePrincipal(uri, attrs);
}
return [ url, appId, isInBrowserElement, isSystem ];
return principal;
},
addPermission: function(type, allow, arg, expireType, expireTime) {
let [url, appId, isInBrowserElement, isSystem] = this._getInfoFromPermissionArg(arg);
if (isSystem) {
let principal = this._getPrincipalFromArg(arg);
if (principal.isSystemPrincipal) {
return; // nothing to do
}
@ -1886,9 +1867,7 @@ SpecialPowersAPI.prototype = {
'op': 'add',
'type': type,
'permission': permission,
'url': url,
'appId': appId,
'isInBrowserElement': isInBrowserElement,
'principal': principal,
'expireType': (typeof expireType === "number") ? expireType : 0,
'expireTime': (typeof expireTime === "number") ? expireTime : 0
};
@ -1897,51 +1876,46 @@ SpecialPowersAPI.prototype = {
},
removePermission: function(type, arg) {
let [url, appId, isInBrowserElement, isSystem] = this._getInfoFromPermissionArg(arg);
if (isSystem) {
let principal = this._getPrincipalFromArg(arg);
if (principal.isSystemPrincipal) {
return; // nothing to do
}
var msg = {
'op': 'remove',
'type': type,
'url': url,
'appId': appId,
'isInBrowserElement': isInBrowserElement
'principal': principal
};
this._sendSyncMessage('SPPermissionManager', msg);
},
hasPermission: function (type, arg) {
let [url, appId, isInBrowserElement, isSystem] = this._getInfoFromPermissionArg(arg);
if (isSystem) {
let principal = this._getPrincipalFromArg(arg);
if (principal.isSystemPrincipal) {
return true; // system principals have all permissions
}
var msg = {
'op': 'has',
'type': type,
'url': url,
'appId': appId,
'isInBrowserElement': isInBrowserElement
'principal': principal
};
return this._sendSyncMessage('SPPermissionManager', msg)[0];
},
testPermission: function (type, value, arg) {
let [url, appId, isInBrowserElement, isSystem] = this._getInfoFromPermissionArg(arg);
if (isSystem) {
let principal = this._getPrincipalFromArg(arg);
if (principal.isSystemPrincipal) {
return true; // system principals have all permissions
}
var msg = {
'op': 'test',
'type': type,
'value': value,
'url': url,
'appId': appId,
'isInBrowserElement': isInBrowserElement
'value': value,
'principal': principal
};
return this._sendSyncMessage('SPPermissionManager', msg)[0];
},
@ -1966,28 +1940,20 @@ SpecialPowersAPI.prototype = {
this._sendSyncMessage('SPObserverService', msg);
},
clearStorageForURI: function(uri, callback, appId, inBrowser) {
this._quotaManagerRequest('clear', uri, appId, inBrowser, callback);
clearStorageForDoc: function(wrappedDocument, callback) {
this._quotaManagerRequest('clear', wrappedDocument, callback);
},
getStorageUsageForURI: function(uri, callback, appId, inBrowser) {
this._quotaManagerRequest('getUsage', uri, appId, inBrowser, callback);
getStorageUsageForDoc: function(wrappedDocument, callback) {
this._quotaManagerRequest('getUsage', wrappedDocument, callback);
},
// Technically this restarts the QuotaManager for all URIs, but we need
// a specific one to perform the synchronized callback when the reset is
// complete.
resetStorageForURI: function(uri, callback, appId, inBrowser) {
this._quotaManagerRequest('reset', uri, appId, inBrowser, callback);
resetStorageForDoc: function(wrappedDocument, callback) {
this._quotaManagerRequest('reset', wrappedDocument, callback);
},
_quotaManagerRequest: function(op, uri, appId, inBrowser, callback) {
_quotaManagerRequest: function(op, wrappedDocument, callback) {
const messageTopic = "SPQuotaManager";
if (uri instanceof Ci.nsIURI) {
uri = uri.spec;
}
const id = Cc["@mozilla.org/uuid-generator;1"]
.getService(Ci.nsIUUIDGenerator)
.generateUUID()
@ -2024,7 +1990,8 @@ SpecialPowersAPI.prototype = {
this._quotaManagerCallbackInfos = [ callbackInfo ];
}
let msg = { op: op, uri: uri, appId: appId, inBrowser: inBrowser, id: id };
let principal = unwrapIfWrapped(wrappedDocument).nodePrincipal;
let msg = { op: op, principal: principal, id: id };
this._sendAsyncMessage(messageTopic, msg);
},