зеркало из https://github.com/mozilla/gecko-dev.git
Bug 871323 - Fix and enable offline mochitests for B2G - remove most of the enablePrivilege calls and use pushPermissions. r=honzab.moz
This commit is contained in:
Родитель
1ff81c5f6d
Коммит
8935d35d8f
|
@ -23,15 +23,13 @@ QueryInterface: function(iid) {
|
|||
return this;
|
||||
},
|
||||
onCacheEntryAvailable: function(desc, accessGranted, status) {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
|
||||
if (!desc) {
|
||||
this.fetch(this.callback);
|
||||
return;
|
||||
}
|
||||
|
||||
var stream = desc.QueryInterface(Ci.nsICacheEntryDescriptor).openInputStream(0);
|
||||
var sstream = SpecialPowers.Cc["@mozilla.org/scriptableinputstream;1"]
|
||||
var sstream = Cc["@mozilla.org/scriptableinputstream;1"]
|
||||
.createInstance(SpecialPowers.Ci.nsIScriptableInputStream);
|
||||
sstream.init(stream);
|
||||
this.contents[desc.key] = sstream.read(sstream.available());
|
||||
|
@ -98,9 +96,8 @@ setup: function()
|
|||
{
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
|
||||
var prefBranch = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
|
||||
try {
|
||||
this._allowedByDefault = prefBranch.getBoolPref("offline-apps.allow_by_default");
|
||||
this._allowedByDefault = SpecialPowers.getBoolPref("offline-apps.allow_by_default");
|
||||
} catch (e) {}
|
||||
|
||||
if (this._allowedByDefault) {
|
||||
|
@ -117,19 +114,11 @@ setup: function()
|
|||
// enable the pref and spawn a new window to perform the actual
|
||||
// tests. It will use this window to report successes and
|
||||
// failures.
|
||||
var pm = Cc["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Ci.nsIPermissionManager);
|
||||
var uri = Cc["@mozilla.org/network/io-service;1"]
|
||||
.getService(Ci.nsIIOService)
|
||||
.newURI(window.location.href, null, null);
|
||||
var principal = SpecialPowers.Cc["@mozilla.org/scriptsecuritymanager;1"]
|
||||
.getService(Ci.nsIScriptSecurityManager)
|
||||
.getNoAppCodebasePrincipal(uri);
|
||||
|
||||
if (pm.testPermissionFromPrincipal(principal, "offline-app") != 0) {
|
||||
if (SpecialPowers.testPermission("offline-app", Ci.nsIPermissionManager.ALLOW_ACTION, document)) {
|
||||
ok(false, "Previous test failed to clear offline-app permission! Expect failures.");
|
||||
}
|
||||
pm.addFromPrincipal(principal, "offline-app", Ci.nsIPermissionManager.ALLOW_ACTION);
|
||||
SpecialPowers.addPermission("offline-app", Ci.nsIPermissionManager.ALLOW_ACTION, document);
|
||||
|
||||
// Tests must run as toplevel windows. Open a slave window to run
|
||||
// the test.
|
||||
|
@ -155,18 +144,7 @@ teardown: function(callback)
|
|||
this.waitForUpdates(function(self) {
|
||||
// Remove the offline-app permission we gave ourselves.
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
|
||||
var pm = Cc["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Ci.nsIPermissionManager);
|
||||
var uri = Cc["@mozilla.org/network/io-service;1"]
|
||||
.getService(Ci.nsIIOService)
|
||||
.newURI(window.location.href, null, null);
|
||||
var principal = SpecialPowers.Cc["@mozilla.org/scriptsecuritymanager;1"]
|
||||
.getService(Ci.nsIScriptSecurityManager)
|
||||
.getNoAppCodebasePrincipal(uri);
|
||||
|
||||
pm.removeFromPrincipal(principal, "offline-app");
|
||||
SpecialPowers.removePermission("offline-app", window.document);
|
||||
|
||||
// Clear all overrides on the server
|
||||
for (override in self._pathOverrides)
|
||||
|
@ -227,8 +205,6 @@ clear: function()
|
|||
|
||||
waitForUpdates: function(callback)
|
||||
{
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
|
||||
var self = this;
|
||||
var observer = {
|
||||
notified: false,
|
||||
|
@ -243,7 +219,7 @@ waitForUpdates: function(callback)
|
|||
return;
|
||||
}
|
||||
|
||||
var updateservice = SpecialPowers.Cc["@mozilla.org/offlinecacheupdate-service;1"]
|
||||
var updateservice = Cc["@mozilla.org/offlinecacheupdate-service;1"]
|
||||
.getService(SpecialPowers.Ci.nsIOfflineCacheUpdateService);
|
||||
var updatesPending = updateservice.numUpdates;
|
||||
if (updatesPending == 0) {
|
||||
|
@ -280,7 +256,6 @@ waitForAdd: function(url, onFinished) {
|
|||
|
||||
var waitForAddListener = {
|
||||
onCacheEntryAvailable: function(entry, access, status) {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
if (entry) {
|
||||
entry.close();
|
||||
onFinished();
|
||||
|
@ -370,7 +345,6 @@ priv: function(func)
|
|||
{
|
||||
var self = this;
|
||||
return function() {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
func(arguments);
|
||||
}
|
||||
},
|
||||
|
@ -391,7 +365,6 @@ checkCacheEntries: function(entries, callback)
|
|||
|
||||
checkCache: function(url, expectEntry, callback)
|
||||
{
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
var cacheSession = this.getActiveSession();
|
||||
this._checkCache(cacheSession, url, expectEntry, callback);
|
||||
},
|
||||
|
@ -410,7 +383,6 @@ _checkCache: function(cacheSession, url, expectEntry, callback)
|
|||
|
||||
var _checkCacheListener = {
|
||||
onCacheEntryAvailable: function(entry, access, status) {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
if (entry) {
|
||||
if (expectEntry) {
|
||||
OfflineTest.ok(true, url + " should exist in the offline cache");
|
||||
|
|
|
@ -6,6 +6,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=445544
|
|||
<head>
|
||||
<title>Test for Bug 445544</title>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript" src="/tests/dom/tests/mochitest/ajax/offline/offlineTests.js"></script>
|
||||
|
||||
|
|
|
@ -18,7 +18,10 @@
|
|||
var result = new Array();
|
||||
var expectedUpdates = 3; // 2 iframes and our self
|
||||
|
||||
init();
|
||||
applicationCache.oncached = onUpdatePassed;
|
||||
applicationCache.onnoupdate = onUpdatePassed;
|
||||
|
||||
SpecialPowers.pushPermissions([{'type': 'offline-app', 'allow': true, 'context': document}], init);
|
||||
|
||||
function onUpdatePassed()
|
||||
{
|
||||
|
@ -28,20 +31,10 @@ function onUpdatePassed()
|
|||
|
||||
function init()
|
||||
{
|
||||
var Cc = SpecialPowers.Cc;
|
||||
var Ci = SpecialPowers.Ci;
|
||||
var pm = Cc["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Ci.nsIPermissionManager);
|
||||
var uri = Cc["@mozilla.org/network/io-service;1"]
|
||||
.getService(Ci.nsIIOService)
|
||||
.newURI(window.location.href, null, null);
|
||||
var principal = SpecialPowers.Cc["@mozilla.org/scriptsecuritymanager;1"]
|
||||
.getService(Ci.nsIScriptSecurityManager)
|
||||
.getNoAppCodebasePrincipal(uri);
|
||||
pm.addFromPrincipal(principal, "offline-app", Ci.nsIPermissionManager.ALLOW_ACTION);
|
||||
|
||||
applicationCache.oncached = onUpdatePassed;
|
||||
applicationCache.onnoupdate = onUpdatePassed;
|
||||
var iframes = document.getElementsByTagName('iframe');
|
||||
iframes[0].src = "460353_iframe_nomanifest.html";
|
||||
iframes[1].src = "460353_iframe_ownmanifest.html";
|
||||
iframes[2].src = "460353_iframe_samemanifest.html";
|
||||
}
|
||||
|
||||
function frameOnLoad(frameid, status)
|
||||
|
@ -79,18 +72,6 @@ function finish()
|
|||
SimpleTest.ok(result["noman"].updateOK == undefined, "Frame with no manifest cache update didn't pass");
|
||||
SimpleTest.is(result["noman"].cacheStatus || -1, -1, "Frame with no manifest cache status was undefined");
|
||||
|
||||
var Cc = SpecialPowers.Cc;
|
||||
var Ci = SpecialPowers.Ci;
|
||||
var pm = Cc["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Ci.nsIPermissionManager);
|
||||
var uri = Cc["@mozilla.org/network/io-service;1"]
|
||||
.getService(Ci.nsIIOService)
|
||||
.newURI(window.location.href, null, null);
|
||||
var principal = SpecialPowers.Cc["@mozilla.org/scriptsecuritymanager;1"]
|
||||
.getService(Ci.nsIScriptSecurityManager)
|
||||
.getNoAppCodebasePrincipal(uri);
|
||||
pm.removeFromPrincipal(principal, "offline-app");
|
||||
|
||||
OfflineTest.waitForUpdates(function() {
|
||||
cleanCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/simpleManifest.cacheManifest");
|
||||
cleanCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingManifest.sjs");
|
||||
|
@ -112,8 +93,8 @@ SimpleTest.waitForExplicitFinish();
|
|||
</script>
|
||||
|
||||
<body>
|
||||
<iframe src="460353_iframe_nomanifest.html"></iframe>
|
||||
<iframe src="460353_iframe_ownmanifest.html"></iframe>
|
||||
<iframe src="460353_iframe_samemanifest.html"></iframe>
|
||||
<iframe></iframe>
|
||||
<iframe></iframe>
|
||||
<iframe></iframe>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -14,8 +14,10 @@
|
|||
after cancelation.
|
||||
*/
|
||||
|
||||
ok(applicationCache.mozItems.length == 0,
|
||||
"applicationCache.mozItems should be available and empty before associating with a cache.");
|
||||
if (SpecialPowers.isMainProcess()) {
|
||||
ok(applicationCache.mozItems.length == 0,
|
||||
"applicationCache.mozItems should be available and empty before associating with a cache.");
|
||||
}
|
||||
|
||||
function updateCanceled()
|
||||
{
|
||||
|
|
|
@ -13,8 +13,10 @@
|
|||
of the parallel loading code.
|
||||
*/
|
||||
|
||||
ok(applicationCache.mozItems.length == 0,
|
||||
"applicationCache.mozItems should be available and empty before associating with a cache.");
|
||||
if (SpecialPowers.isMainProcess()) {
|
||||
ok(applicationCache.mozItems.length == 0,
|
||||
"applicationCache.mozItems should be available and empty before associating with a cache.");
|
||||
}
|
||||
|
||||
function manifestUpdated()
|
||||
{
|
||||
|
|
|
@ -9,34 +9,20 @@
|
|||
|
||||
var gTestWin;
|
||||
|
||||
var Cc = SpecialPowers.Cc;
|
||||
var Ci = SpecialPowers.Ci;
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
// Enable the offline-app permission before loading the new window
|
||||
var pm = Cc["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Ci.nsIPermissionManager);
|
||||
var uri = Cc["@mozilla.org/network/io-service;1"]
|
||||
.getService(Ci.nsIIOService)
|
||||
.newURI(window.location.href, null, null);
|
||||
var principal = SpecialPowers.Cc["@mozilla.org/scriptsecuritymanager;1"]
|
||||
.getService(Ci.nsIScriptSecurityManager)
|
||||
.getNoAppCodebasePrincipal(uri);
|
||||
SpecialPowers.pushPermissions([{'type': 'offline-app', 'allow': true, 'context': document}], startTest);
|
||||
|
||||
pm.addFromPrincipal(principal, "offline-app", Ci.nsIPermissionManager.ALLOW_ACTION);
|
||||
|
||||
// now this will properly load the manifest.
|
||||
gTestWin = window.open("missing.html");
|
||||
|
||||
function finish()
|
||||
{
|
||||
pm.removeFromPrincipal(principal, "offline-app");
|
||||
function startTest() {
|
||||
// now this will properly load the manifest.
|
||||
gTestWin = window.open("missing.html");
|
||||
}
|
||||
|
||||
function finish() {
|
||||
gTestWin.close();
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
</script>
|
||||
|
||||
</head>
|
||||
|
|
|
@ -22,7 +22,9 @@ function expectInvalidState(fn, desc) {
|
|||
}
|
||||
|
||||
is(typeof(applicationCache), "object");
|
||||
is(applicationCache.mozLength, 0, "applicationCache.mozLength should be 0");
|
||||
if (SpecialPowers.isMainProcess()) {
|
||||
is(applicationCache.mozLength, 0, "applicationCache.mozLength should be 0");
|
||||
}
|
||||
is(applicationCache.status, 0, "applicationCache.status should be 0 (UNCACHED)");
|
||||
|
||||
expectInvalidState(function() { applicationCache.update(); },
|
||||
|
|
|
@ -9,36 +9,23 @@
|
|||
|
||||
var gTestWin;
|
||||
|
||||
var Cc = SpecialPowers.Cc;
|
||||
var Ci = SpecialPowers.Ci;
|
||||
SpecialPowers.pushPermissions([{'type': 'offline-app', 'allow': true, 'context': document}], startTest);
|
||||
|
||||
// Enable the offline-app permission before loading the new window
|
||||
var pm = Cc["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Ci.nsIPermissionManager);
|
||||
var uri = Cc["@mozilla.org/network/io-service;1"]
|
||||
.getService(Ci.nsIIOService)
|
||||
.newURI(window.location.href, null, null);
|
||||
var principal = SpecialPowers.Cc["@mozilla.org/scriptsecuritymanager;1"]
|
||||
.getService(Ci.nsIScriptSecurityManager)
|
||||
.getNoAppCodebasePrincipal(uri);
|
||||
pm.addFromPrincipal(principal, "offline-app", Ci.nsIPermissionManager.ALLOW_ACTION);
|
||||
|
||||
// Make the obsoleting.sjs return a valid manifest
|
||||
var req = new XMLHttpRequest();
|
||||
req.open("GET", "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/obsoletingManifest.sjs?state=manifestPresent");
|
||||
req.setRequestHeader("Content-Type", "text/cache-manifest");
|
||||
req.send("");
|
||||
req.onreadystatechange = function() {
|
||||
if (req.readyState == 4) {
|
||||
// now this will properly load the manifest.
|
||||
gTestWin = window.open("obsolete.html");
|
||||
function startTest() {
|
||||
// Make the obsoleting.sjs return a valid manifest
|
||||
var req = new XMLHttpRequest();
|
||||
req.open("GET", "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/obsoletingManifest.sjs?state=manifestPresent");
|
||||
req.setRequestHeader("Content-Type", "text/cache-manifest");
|
||||
req.send("");
|
||||
req.onreadystatechange = function() {
|
||||
if (req.readyState == 4) {
|
||||
// now this will properly load the manifest.
|
||||
gTestWin = window.open("obsolete.html");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function finish()
|
||||
{
|
||||
pm.removeFromPrincipal(principal, "offline-app");
|
||||
|
||||
function finish() {
|
||||
gTestWin.close();
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
<head>
|
||||
<title>Updating implicit</title>
|
||||
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript" src="/tests/dom/tests/mochitest/ajax/offline/offlineTests.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
|
Загрузка…
Ссылка в новой задаче