Bug 892488 - Get rid of the offline application cache prompt, r=ehsan+jonas

This commit is contained in:
Honza Bambas 2013-08-16 11:34:21 +02:00
Родитель 04afb27dcd
Коммит 5763d2ceb2
44 изменённых файлов: 400 добавлений и 180 удалений

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

@ -36,6 +36,7 @@ MOCHITEST_FILES = \
test_offline_gzip.html \
test_offlineNotification.html \
video.ogg \
offlineByDefault.js \
$(NULL)
# test_contextmenu.html and test_contextmenu_input are disabled on Linux due to bug 513558

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

@ -14,6 +14,7 @@ registerCleanupFunction(function() {
var principal = Services.scriptSecurityManager.getNoAppCodebasePrincipal(uri);
Services.perms.removeFromPrincipal(principal, "offline-app");
Services.prefs.clearUserPref("offline-apps.quota.warn");
Services.prefs.clearUserPref("offline-apps.allow_by_default");
});
// Check that the "preferences" UI is opened and showing which websites have
@ -70,5 +71,6 @@ function test() {
PopupNotifications.panel.firstElementChild.button.click();
}, true);
Services.prefs.setBoolPref("offline-apps.allow_by_default", false);
gBrowser.contentWindow.location = URL;
}

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

@ -0,0 +1,17 @@
var offlineByDefault = {
defaultValue: false,
prefBranch: SpecialPowers.Cc["@mozilla.org/preferences-service;1"].getService(SpecialPowers.Ci.nsIPrefBranch),
set: function(allow) {
try {
this.defaultValue = this.prefBranch.getBoolPref("offline-apps.allow_by_default");
} catch (e) {
this.defaultValue = false
}
this.prefBranch.setBoolPref("offline-apps.allow_by_default", allow);
},
reset: function() {
this.prefBranch.setBoolPref("offline-apps.allow_by_default", this.defaultValue);
}
}
offlineByDefault.set(false);

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

@ -6,6 +6,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=462856
<head>
<title>Test offline app notification</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="offlineByDefault.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body onload="loaded()">
@ -52,6 +53,8 @@ window.addEventListener("message", function(event) {
pm.removeFromPrincipal(principal1, "offline-app");
pm.removeFromPrincipal(principal2, "offline-app");
offlineByDefault.reset();
SimpleTest.finish();
}
}, false);

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

@ -13,6 +13,7 @@ cache, it can be fetched from the cache successfully.
src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript"
src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="offlineByDefault.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body onload="loaded()">
@ -46,6 +47,7 @@ function finishTest() {
window.removeEventListener("message", handleMessageEvents, false);
offlineByDefault.reset();
SimpleTest.finish();
}

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

@ -1503,6 +1503,12 @@ public:
*/
static bool OfflineAppAllowed(nsIPrincipal *aPrincipal);
/**
* If offline-apps.allow_by_default is true, we set offline-app permission
* for the principal and return true. Otherwise false.
*/
static bool MaybeAllowOfflineAppByDefault(nsIPrincipal *aPrincipal);
/**
* Increases the count of blockers preventing scripts from running.
* NOTE: You might want to use nsAutoScriptBlocker rather than calling

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

@ -1061,8 +1061,11 @@ nsContentSink::ProcessOfflineManifest(const nsAString& aManifestSpec)
action = CACHE_SELECTION_RESELECT_WITHOUT_MANIFEST;
}
else {
// Only continue if the document has permission to use offline APIs.
if (!nsContentUtils::OfflineAppAllowed(mDocument->NodePrincipal())) {
// Only continue if the document has permission to use offline APIs or
// when preferences indicate to permit it automatically.
if (!nsContentUtils::OfflineAppAllowed(mDocument->NodePrincipal()) &&
!nsContentUtils::MaybeAllowOfflineAppByDefault(mDocument->NodePrincipal()) &&
!nsContentUtils::OfflineAppAllowed(mDocument->NodePrincipal())) {
return;
}

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

@ -1405,6 +1405,38 @@ nsContentUtils::OfflineAppAllowed(nsIPrincipal *aPrincipal)
return NS_SUCCEEDED(rv) && allowed;
}
bool
nsContentUtils::MaybeAllowOfflineAppByDefault(nsIPrincipal *aPrincipal)
{
if (!Preferences::GetRootBranch())
return false;
nsresult rv;
bool allowedByDefault;
rv = Preferences::GetRootBranch()->GetBoolPref(
"offline-apps.allow_by_default", &allowedByDefault);
if (NS_FAILED(rv))
return false;
if (!allowedByDefault)
return false;
nsCOMPtr<nsIPermissionManager> permissionManager =
do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
if (!permissionManager)
return false;
rv = permissionManager->AddFromPrincipal(
aPrincipal, "offline-app", nsIPermissionManager::ALLOW_ACTION,
nsIPermissionManager::EXPIRE_NEVER, 0);
if (NS_FAILED(rv))
return false;
// We have added the permission
return true;
}
// static
void
nsContentUtils::Shutdown()

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

@ -84,7 +84,6 @@ nsDOMOfflineResourceList::nsDOMOfflineResourceList(nsIURI *aManifestURI,
, mManifestURI(aManifestURI)
, mDocumentURI(aDocumentURI)
, mExposeCacheUpdateStatus(true)
, mDontSetDocumentCache(false)
, mStatus(nsIDOMOfflineResourceList::IDLE)
, mCachedKeys(nullptr)
, mCachedKeysCount(0)
@ -429,6 +428,11 @@ nsDOMOfflineResourceList::GetStatus(uint16_t *aStatus)
}
}
if (mAvailableApplicationCache) {
*aStatus = nsIDOMOfflineResourceList::UPDATEREADY;
return NS_OK;
}
*aStatus = mStatus;
return NS_OK;
}
@ -455,10 +459,6 @@ nsDOMOfflineResourceList::Update()
window, getter_AddRefs(update));
NS_ENSURE_SUCCESS(rv, rv);
// Since we are invoking the cache update, cache on the document must not
// be updated until swapCache() method is called on applicationCache object.
mDontSetDocumentCache = true;
return NS_OK;
}
@ -488,6 +488,8 @@ nsDOMOfflineResourceList::SwapCache()
mAvailableApplicationCache->GetClientID(availClientId);
if (availClientId == currClientId)
return NS_ERROR_DOM_INVALID_STATE_ERR;
} else if (mStatus != OBSOLETE) {
return NS_ERROR_DOM_INVALID_STATE_ERR;
}
ClearCachedKeys();
@ -629,16 +631,36 @@ nsDOMOfflineResourceList::UpdateStateChanged(nsIOfflineCacheUpdate *aUpdate,
NS_IMETHODIMP
nsDOMOfflineResourceList::ApplicationCacheAvailable(nsIApplicationCache *aApplicationCache)
{
mAvailableApplicationCache = aApplicationCache;
nsCOMPtr<nsIApplicationCache> currentAppCache = GetDocumentAppCache();
if (currentAppCache) {
// Document already has a cache, we cannot override it. swapCache is
// here to do it on demand.
if (!mDontSetDocumentCache) {
nsCOMPtr<nsIApplicationCacheContainer> appCacheContainer =
GetDocumentAppCacheContainer();
// If the newly available cache is identical to the current cache, then
// just ignore this event.
if (aApplicationCache == currentAppCache) {
return NS_OK;
}
if (appCacheContainer)
appCacheContainer->SetApplicationCache(aApplicationCache);
nsCString currClientId, availClientId;
currentAppCache->GetClientID(currClientId);
aApplicationCache->GetClientID(availClientId);
if (availClientId == currClientId) {
return NS_OK;
}
mAvailableApplicationCache = aApplicationCache;
return NS_OK;
}
nsCOMPtr<nsIApplicationCacheContainer> appCacheContainer =
GetDocumentAppCacheContainer();
if (appCacheContainer) {
appCacheContainer->SetApplicationCache(aApplicationCache);
}
mAvailableApplicationCache = nullptr;
return NS_OK;
}
@ -737,14 +759,12 @@ nsDOMOfflineResourceList::UpdateCompleted(nsIOfflineCacheUpdate *aUpdate)
mCacheUpdate->RemoveObserver(this);
mCacheUpdate = nullptr;
mDontSetDocumentCache = false;
if (NS_SUCCEEDED(rv) && succeeded && !partial) {
mStatus = nsIDOMOfflineResourceList::IDLE;
if (isUpgrade) {
mStatus = nsIDOMOfflineResourceList::UPDATEREADY;
SendEvent(NS_LITERAL_STRING(UPDATEREADY_STR));
} else {
mStatus = nsIDOMOfflineResourceList::IDLE;
SendEvent(NS_LITERAL_STRING(CACHED_STR));
}
}

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

@ -157,7 +157,6 @@ private:
nsCOMPtr<nsIApplicationCache> mAvailableApplicationCache;
nsCOMPtr<nsIOfflineCacheUpdate> mCacheUpdate;
bool mExposeCacheUpdateStatus;
bool mDontSetDocumentCache;
uint16_t mStatus;
// The set of dynamic keys for this application cache object.

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

@ -12,6 +12,10 @@ applicationCache.oncached = function() {
parent.frameOnUpdate("same", true, applicationCache.status);
}
applicationCache.onnoupdate = function() {
parent.frameOnUpdate("same", true, applicationCache.status);
}
</script>
</head>

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

@ -28,8 +28,7 @@ function startTest()
testScriptPresence("namespace1/sub2/script2.js", "scriptNo2Function();", true);
testScriptPresence("namespace2/script3.js", "scriptNo3Function();", true);
opener.OfflineTest.teardown();
opener.OfflineTest.finish();
opener.OfflineTest.teardownAndFinish();
window.close(window);
}

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

@ -16,16 +16,15 @@ function manifestUpdated()
var foreign2cache = appCacheService.chooseApplicationCache(
"http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/foreign2.html", OfflineTest.loadContext());
OfflineTest.ok(foreign2cache, "Foreign 2 cache present, chosen for foreign2.html");
OfflineTest.is(foreign2cache.manifestURI.asciiSpec, "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/foreign2.cacheManifest")
window.opener.OfflineTest.ok(foreign2cache, "Foreign 2 cache present, chosen for foreign2.html");
window.opener.OfflineTest.is(foreign2cache.manifestURI.asciiSpec, "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/foreign2.cacheManifest")
var foreign1cache = OfflineTest.getActiveCache(
"http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/foreign1.cacheManifest");
OfflineTest.ok(foreign1cache, "Foreign 1 cache loaded");
window.opener.OfflineTest.ok(foreign1cache, "Foreign 1 cache loaded");
foreign1cache.discard();
OfflineTest.teardown();
OfflineTest.finish();
window.opener.onDone();
}
function onLoaded()
@ -33,36 +32,33 @@ function onLoaded()
var appCacheService = SpecialPowers.Components.classes["@mozilla.org/network/application-cache-service;1"]
.getService(SpecialPowers.Ci.nsIApplicationCacheService);
var foreign1cache = OfflineTest.getActiveCache(
var foreign1cache = window.opener.OfflineTest.getActiveCache(
"http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/foreign1.cacheManifest");
OfflineTest.ok(foreign1cache, "Foreign 1 cache loaded");
window.opener.OfflineTest.ok(foreign1cache, "Foreign 1 cache loaded");
var foreign2cache = OfflineTest.getActiveCache(
var foreign2cache = window.opener.OfflineTest.getActiveCache(
"http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/foreign2.cacheManifest");
OfflineTest.ok(!foreign2cache, "Foreign 2 cache not present");
window.opener.OfflineTest.ok(!foreign2cache, "Foreign 2 cache not present");
foreign1cache = appCacheService.chooseApplicationCache(
"http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/foreign2.html", OfflineTest.loadContext());
OfflineTest.ok(!foreign1cache, "foreign2.html not chosen from foreign1 cache");
"http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/foreign2.html", window.opener.OfflineTest.loadContext());
window.opener.OfflineTest.ok(!foreign1cache, "foreign2.html not chosen from foreign1 cache");
try
{
OfflineTest.ok(applicationCache.status == SpecialPowers.Ci.nsIDOMOfflineResourceList.UNCACHED,
window.opener.OfflineTest.ok(applicationCache.status == SpecialPowers.Ci.nsIDOMOfflineResourceList.UNCACHED,
"there is no associated application cache");
}
catch (ex)
{
OfflineTest.ok(false, "applicationCache.status must not throw an exception");
window.opener.OfflineTest.ok(false, "applicationCache.status must not throw an exception");
}
}
if (OfflineTest.setup())
{
applicationCache.onerror = OfflineTest.failEvent;
applicationCache.onupdateready = OfflineTest.failEvent;
applicationCache.onnoupdate = OfflineTest.failEvent;
applicationCache.oncached = OfflineTest.priv(manifestUpdated);
}
applicationCache.onerror = window.opener.OfflineTest.failEvent;
applicationCache.onupdateready = window.opener.OfflineTest.failEvent;
applicationCache.onnoupdate = window.opener.OfflineTest.failEvent;
applicationCache.oncached = window.opener.OfflineTest.priv(manifestUpdated);
</script>

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

@ -12,7 +12,7 @@
// (since we don't get those events)
function doneLoading()
{
window.top.childFinished();
window.parent.childFinished();
}
if (OfflineTest.setupChild()) {

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

@ -58,6 +58,8 @@ fetch: function(callback)
var OfflineTest = {
_allowedByDefault: false,
_hasSlave: false,
// The window where test results should be sent.
@ -71,6 +73,11 @@ _SJSsStated: [],
setupChild: function()
{
if (this._allowedByDefault) {
this._masterWindow = window;
return true;
}
if (window.parent.OfflineTest._hasSlave) {
return false;
}
@ -91,6 +98,17 @@ 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");
} catch (e) {}
if (this._allowedByDefault) {
this._masterWindow = window;
return true;
}
if (!window.opener || !window.opener.OfflineTest ||
!window.opener.OfflineTest._hasSlave) {
// Offline applications must be toplevel windows and have the
@ -126,35 +144,46 @@ setup: function()
return true;
},
teardown: function()
teardownAndFinish: function()
{
// Remove the offline-app permission we gave ourselves.
this.teardown(function(self) { self.finish(); });
},
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
teardown: function(callback)
{
// First wait for any pending scheduled updates to finish
this.waitForUpdates(function(self) {
// Remove the offline-app permission we gave ourselves.
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 = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager)
.getNoAppCodebasePrincipal(uri);
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
pm.removeFromPrincipal(principal, "offline-app");
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 = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager)
.getNoAppCodebasePrincipal(uri);
// Clear all overrides on the server
for (override in this._pathOverrides)
this.deleteData(this._pathOverrides[override]);
for (statedSJS in this._SJSsStated)
this.setSJSState(this._SJSsStated[statedSJS], "");
pm.removeFromPrincipal(principal, "offline-app");
this.clear();
// Clear all overrides on the server
for (override in self._pathOverrides)
self.deleteData(self._pathOverrides[override]);
for (statedSJS in self._SJSsStated)
self.setSJSState(self._SJSsStated[statedSJS], "");
self.clear();
callback(self);
});
},
finish: function()
{
if (this._masterWindow) {
if (this._allowedByDefault) {
SimpleTest.executeSoon(SimpleTest.finish);
} else if (this._masterWindow) {
// Slave window: pass control back to master window, close itself.
this._masterWindow.SimpleTest.executeSoon(this._masterWindow.OfflineTest.finish);
window.close();
@ -196,6 +225,48 @@ clear: function()
}
},
waitForUpdates: function(callback)
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var self = this;
var observer = {
notified: false,
observe: function(subject, topic, data) {
if (subject) {
subject.QueryInterface(SpecialPowers.Ci.nsIOfflineCacheUpdate);
dump("Update of " + subject.manifestURI.spec + " finished\n");
}
SimpleTest.executeSoon(function() {
if (observer.notified) {
return;
}
var updateservice = SpecialPowers.Cc["@mozilla.org/offlinecacheupdate-service;1"]
.getService(SpecialPowers.Ci.nsIOfflineCacheUpdateService);
var updatesPending = updateservice.numUpdates;
if (updatesPending == 0) {
try {
SpecialPowers.removeObserver(observer, "offline-cache-update-completed");
} catch(ex) {}
dump("All pending updates done\n");
observer.notified = true;
callback(self);
return;
}
dump("Waiting for " + updateservice.numUpdates + " update(s) to finish\n");
});
}
}
SpecialPowers.addObserver(observer, "offline-cache-update-completed", false);
// Call now to check whether there are some updates scheduled
observer.observe();
},
failEvent: function(e)
{
OfflineTest.ok(false, "Unexpected event: " + e.type);
@ -237,7 +308,19 @@ waitForAdd: function(url, onFinished) {
manifestURL: function(overload)
{
var manifestURLspec = overload || window.top.document.documentElement.getAttribute("manifest");
var manifestURLspec;
if (overload) {
manifestURLspec = overload;
} else {
var win = window;
while (win && !win.document.documentElement.getAttribute("manifest")) {
if (win == win.parent)
break;
win = win.parent;
}
if (win)
manifestURLspec = win.document.documentElement.getAttribute("manifest");
}
var ios = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService)
@ -267,8 +350,9 @@ getActiveCache: function(overload)
getActiveSession: function()
{
var cache = this.getActiveCache();
if (!cache)
if (!cache) {
return null;
}
var cacheService = Cc["@mozilla.org/network/cache-service;1"]
.getService(Ci.nsICacheService);
@ -302,6 +386,7 @@ checkCacheEntries: function(entries, callback)
checkCache: function(url, expectEntry, callback)
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var cacheSession = this.getActiveSession();
this._checkCache(cacheSession, url, expectEntry, callback);
},
@ -310,11 +395,11 @@ _checkCache: function(cacheSession, url, expectEntry, callback)
{
if (!cacheSession) {
if (expectEntry) {
this.ok(false, url + " should exist in the offline cache");
this.ok(false, url + " should exist in the offline cache (no session)");
} else {
this.ok(true, url + " should not exist in the offline cache");
this.ok(true, url + " should not exist in the offline cache (no session)");
}
setTimeout(this.priv(callback), 0);
if (callback) setTimeout(this.priv(callback), 0);
return;
}
@ -346,7 +431,7 @@ _checkCache: function(cacheSession, url, expectEntry, callback)
OfflineTest.ok(false, "got invalid error for " + url);
}
}
setTimeout(OfflineTest.priv(callback), 0);
if (callback) setTimeout(OfflineTest.priv(callback), 0);
}
};

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

@ -11,8 +11,7 @@
var gGotChecking = false;
function finishTest() {
OfflineTest.teardown();
OfflineTest.finish();
OfflineTest.teardownAndFinish();
}
function handleError() {

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

@ -17,8 +17,7 @@ var gTimeoutId;
function finish()
{
gTestWin.close();
OfflineTest.teardown();
OfflineTest.finish();
OfflineTest.teardownAndFinish();
}
function error()

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

@ -16,10 +16,16 @@
<script class="testbody" type="text/javascript">
var result = new Array();
var expectedUpdates = 2;
var expectedUpdates = 3; // 2 iframes and our self
init();
function onUpdatePassed()
{
if (!(--expectedUpdates))
SimpleTest.executeSoon(finish);
}
function init()
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
@ -35,6 +41,9 @@ function init()
.getService(Ci.nsIScriptSecurityManager)
.getNoAppCodebasePrincipal(uri);
pm.addFromPrincipal(principal, "offline-app", Ci.nsIPermissionManager.ALLOW_ACTION);
applicationCache.oncached = onUpdatePassed;
applicationCache.onnoupdate = onUpdatePassed;
}
function frameOnLoad(frameid, status)
@ -52,8 +61,7 @@ function frameOnUpdate(frameid, ok, status)
result[frameid].updateOK = ok;
result[frameid].cacheStatus = status;
if (!(--expectedUpdates))
finish();
onUpdatePassed();
}
function finish()
@ -87,10 +95,12 @@ function finish()
.getNoAppCodebasePrincipal(uri);
pm.removeFromPrincipal(principal, "offline-app");
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");
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");
SimpleTest.finish();
SimpleTest.finish();
});
}
function cleanCache(manifestURL)
@ -98,6 +108,7 @@ function cleanCache(manifestURL)
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var cache = OfflineTest.getActiveCache(manifestURL);
dump("Discarding cache for " + manifestURL + " cache=" + cache + "\n");
if (cache)
cache.discard();
}

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

@ -15,10 +15,10 @@ function manifestUpdated()
function onFallbackLoad(fallbackIdentification)
{
OfflineTest.is(fallbackIdentification, 1, "Got correct fallback for namespace1");
OfflineTest.is(fallbackIdentification, 1, "Got correct fallback for namespace1 (2)");
OfflineTest.teardown();
OfflineTest.finish();
applicationCache.onerror = function() {}; // the update invoked by the iframe will finish after we discard the cache, ignore error
OfflineTest.teardownAndFinish();
}
SimpleTest.waitForExplicitFinish();
@ -26,7 +26,6 @@ SimpleTest.waitForExplicitFinish();
if (OfflineTest.setup()) {
applicationCache.onerror = OfflineTest.failEvent;
applicationCache.onupdateready = OfflineTest.failEvent;
applicationCache.onnoupdate = OfflineTest.failEvent;
applicationCache.oncached = OfflineTest.priv(manifestUpdated);
}

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

@ -31,8 +31,7 @@ function finishTheTest()
{
OfflineTest.is(gImageLoaded[1], true, "Image from a different origin not cointained in the offline cache has loaded");
OfflineTest.is(gImageLoaded[2], true, "Image not cointained in the offline cache has loaded");
OfflineTest.teardown();
OfflineTest.finish();
OfflineTest.teardownAndFinish();
}
if (OfflineTest.setup()) {

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

@ -19,46 +19,44 @@ ok(applicationCache.mozItems.length == 0,
function updateCanceled()
{
OfflineTest.checkCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/744719-cancel.cacheManifest", false);
OfflineTest.checkCache("http://mochi.test:8888/tests/SimpleTest/SimpleTest.js", false);
OfflineTest.checkCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/offlineTests.js", false);
OfflineTest.checkCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/744719-cancel.cacheManifest", false, null);
OfflineTest.checkCache("http://mochi.test:8888/tests/SimpleTest/SimpleTest.js", false, null);
OfflineTest.checkCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/offlineTests.js", false, null);
OfflineTest.checkCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/nonexistent744719?010", false);
OfflineTest.checkCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/nonexistent744719?010", false, null);
var URL = "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/subresource744719.html?";
OfflineTest.checkCache(URL + "001", false);
OfflineTest.checkCache(URL + "002", false);
OfflineTest.checkCache(URL + "003", false);
OfflineTest.checkCache(URL + "004", false);
OfflineTest.checkCache(URL + "005", false);
OfflineTest.checkCache(URL + "006", false);
OfflineTest.checkCache(URL + "007", false);
OfflineTest.checkCache(URL + "008", false);
OfflineTest.checkCache(URL + "009", false);
OfflineTest.checkCache(URL + "011", false);
OfflineTest.checkCache(URL + "012", false);
OfflineTest.checkCache(URL + "013", false);
OfflineTest.checkCache(URL + "014", false);
OfflineTest.checkCache(URL + "015", false);
OfflineTest.checkCache(URL + "016", false);
OfflineTest.checkCache(URL + "017", false);
OfflineTest.checkCache(URL + "018", false);
OfflineTest.checkCache(URL + "019", false);
OfflineTest.checkCache(URL + "020", false);
OfflineTest.checkCache(URL + "021", false);
OfflineTest.checkCache(URL + "022", false);
OfflineTest.checkCache(URL + "023", false);
OfflineTest.checkCache(URL + "024", false);
OfflineTest.checkCache(URL + "025", false);
OfflineTest.checkCache(URL + "026", false);
OfflineTest.checkCache(URL + "027", false);
OfflineTest.checkCache(URL + "028", false);
OfflineTest.checkCache(URL + "029", false);
OfflineTest.checkCache(URL + "030", false);
OfflineTest.checkCache(URL + "001", false, null);
OfflineTest.checkCache(URL + "002", false, null);
OfflineTest.checkCache(URL + "003", false, null);
OfflineTest.checkCache(URL + "004", false, null);
OfflineTest.checkCache(URL + "005", false, null);
OfflineTest.checkCache(URL + "006", false, null);
OfflineTest.checkCache(URL + "007", false, null);
OfflineTest.checkCache(URL + "008", false, null);
OfflineTest.checkCache(URL + "009", false, null);
OfflineTest.checkCache(URL + "011", false, null);
OfflineTest.checkCache(URL + "012", false, null);
OfflineTest.checkCache(URL + "013", false, null);
OfflineTest.checkCache(URL + "014", false, null);
OfflineTest.checkCache(URL + "015", false, null);
OfflineTest.checkCache(URL + "016", false, null);
OfflineTest.checkCache(URL + "017", false, null);
OfflineTest.checkCache(URL + "018", false, null);
OfflineTest.checkCache(URL + "019", false, null);
OfflineTest.checkCache(URL + "020", false, null);
OfflineTest.checkCache(URL + "021", false, null);
OfflineTest.checkCache(URL + "022", false, null);
OfflineTest.checkCache(URL + "023", false, null);
OfflineTest.checkCache(URL + "024", false, null);
OfflineTest.checkCache(URL + "025", false, null);
OfflineTest.checkCache(URL + "026", false, null);
OfflineTest.checkCache(URL + "027", false, null);
OfflineTest.checkCache(URL + "028", false, null);
OfflineTest.checkCache(URL + "029", false, null);
OfflineTest.checkCache(URL + "030", false, null);
OfflineTest.teardown();
OfflineTest.finish();
OfflineTest.teardownAndFinish();
}
if (OfflineTest.setup()) {

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

@ -52,11 +52,9 @@ function manifestUpdated()
OfflineTest.checkCache(URL + "027", true);
OfflineTest.checkCache(URL + "028", true);
OfflineTest.checkCache(URL + "029", true);
OfflineTest.checkCache(URL + "030", true);
OfflineTest.teardown();
OfflineTest.finish();
OfflineTest.checkCache(URL + "030", true, function() {
OfflineTest.teardownAndFinish();
});
}
if (OfflineTest.setup()) {

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

@ -35,8 +35,7 @@ function manifestUpdated()
OfflineTest.checkCacheEntries(
entries,
function() {
OfflineTest.teardown();
OfflineTest.finish();
OfflineTest.teardownAndFinish();
});
}

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

@ -18,15 +18,13 @@ var updateService = Cc['@mozilla.org/offlinecacheupdate-service;1']
function manifestCached () {
OfflineTest.ok(false, "The update was supposed to be canceled");
OfflineTest.teardown();
OfflineTest.finish();
OfflineTest.teardownAndFinish();
}
function onError () {
OfflineTest.ok(true, "Expected error: Update canceled");
OfflineTest.teardown();
OfflineTest.finish();
OfflineTest.teardownAndFinish();
}
function onProgress () {
@ -43,6 +41,7 @@ function onProgress () {
if (OfflineTest.setup()) {
applicationCache.onerror = OfflineTest.priv(onError);
applicationCache.onnoupdate = OfflineTest.failEvent;
applicationCache.onprogress = OfflineTest.priv(onProgress);
applicationCache.oncached = OfflineTest.priv(manifestCached);
}

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

@ -18,8 +18,7 @@ var gCacheContents = null;
function finish()
{
OfflineTest.teardown();
OfflineTest.finish();
OfflineTest.teardownAndFinish();
}
function manifestUpdatedAgain()

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

@ -96,8 +96,7 @@ function onFallbackLoad(fallbackIdentification)
function finishTest()
{
OfflineTest.teardown();
OfflineTest.finish();
OfflineTest.teardownAndFinish();
}
function finalize()

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

@ -19,9 +19,11 @@
* chosen by foreign.html page.
*/
var win;
function manifestUpdated()
{
var appCacheService = SpecialPowers.Components.classes["@mozilla.org/network/application-cache-service;1"]
var appCacheService = SpecialPowers.Cc["@mozilla.org/network/application-cache-service;1"]
.getService(SpecialPowers.Ci.nsIApplicationCacheService);
foreign1cache = appCacheService.chooseApplicationCache(
@ -30,7 +32,13 @@ function manifestUpdated()
OfflineTest.ok(foreign1cache, "foreign2.html chosen from foreign1 cache");
OfflineTest.is(foreign1cache.manifestURI.asciiSpec, "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/foreign1.cacheManifest")
window.location = "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/foreign2.html";
win = window.open("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/foreign2.html");
}
function onDone() // called by the open window after stuff is finished
{
win.close();
OfflineTest.teardownAndFinish();
}
SimpleTest.waitForExplicitFinish();

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

@ -13,8 +13,7 @@ var gGotDownloading = false;
function finishTest()
{
OfflineTest.teardown();
OfflineTest.finish();
OfflineTest.teardownAndFinish();
}
function noUpdate()

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

@ -32,8 +32,7 @@ var errorReceived = false;
function finish() {
obs.notifyObservers(updateService, "disk-space-watcher", "free");
OfflineTest.teardown();
OfflineTest.finish();
OfflineTest.teardownAndFinish();
}
if (OfflineTest.setup()) {
@ -46,7 +45,6 @@ if (OfflineTest.setup()) {
aUpdate.removeObserver(this);
errorReceived = true;
OfflineTest.ok(true, "Expected error. Update canceled");
finish();
break;
case Ci.nsIOfflineCacheUpdateObserver.STATE_FINISHED:
OfflineTest.ok(errorReceived,

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

@ -22,8 +22,7 @@ var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
function finish() {
obs.notifyObservers(updateService, "disk-space-watcher", "free");
OfflineTest.teardown();
OfflineTest.finish();
OfflineTest.teardownAndFinish();
}
function onError() {

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

@ -12,8 +12,7 @@ var gGotChecking = false;
var gGotDownloading = false;
function finishTest() {
OfflineTest.teardown();
OfflineTest.finish();
OfflineTest.teardownAndFinish();
}
function handleError() {

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

@ -23,8 +23,7 @@ function checkEntries() {
function childFinished()
{
OfflineTest.teardown();
OfflineTest.finish();
OfflineTest.teardownAndFinish();
}
if (OfflineTest.setup()) {

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

@ -99,8 +99,7 @@ function finalize()
OfflineTest.is(gGotDynamicVersion, 1, "Dynamic entry loaded");
OfflineTest.ok(gGotOnError, "Got onerror event invoked by implicit page load in offline mode");
OfflineTest.teardown();
OfflineTest.finish();
OfflineTest.teardownAndFinish();
}
}

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

@ -15,8 +15,7 @@ function manifestUpdated()
xhr.send();
OfflineTest.is(xhr.status, 200, "Should have fallen back.");
OfflineTest.teardown();
OfflineTest.finish();
OfflineTest.teardownAndFinish();
}
if (OfflineTest.setup()) {

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

@ -25,8 +25,7 @@ function manifestError()
function finish()
{
OfflineTest.teardown();
OfflineTest.finish();
OfflineTest.teardownAndFinish();
}
SimpleTest.waitForExplicitFinish();

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

@ -108,8 +108,7 @@ function manifestError()
function finish()
{
OfflineTest.teardown();
OfflineTest.finish();
OfflineTest.teardownAndFinish();
}
SimpleTest.waitForExplicitFinish();

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

@ -9,8 +9,7 @@
function finish()
{
OfflineTest.teardown();
OfflineTest.finish();
OfflineTest.teardownAndFinish();
}
function failAndFinish(e)

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

@ -49,8 +49,7 @@ function removeItem()
false,
function() {
// We're done
OfflineTest.teardown();
OfflineTest.finish();
OfflineTest.teardownAndFinish();
});
}

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

@ -68,8 +68,7 @@ function manifestUpdated()
observe: function(subject, topic, data) {
OfflineTest.is(topic, "offline-cache-update-unavailable", "No update avail (2)");
OfflineTest.teardown();
OfflineTest.finish();
OfflineTest.teardownAndFinish();
}
});
}

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

@ -38,7 +38,7 @@ function waitForLocations(frames, doneFunc)
if (frame)
// toString() might cause problems when this test will
// completely be changed to test IDN behavior.
OfflineTest.waitForAdd(frame.location.toString(), function()
OfflineTest.waitForAdd(frame, function()
{
waitForLocations(frames, doneFunc);
}
@ -94,7 +94,7 @@ function frameLoad(version)
{
var call = gCallOnUpdatingFrameLoad;
gCallOnUpdatingFrameLoad = null;
OfflineTest.priv(call)();
SimpleTest.executeSoon(OfflineTest.priv(call));
}
}
@ -112,12 +112,15 @@ function manifestCached()
OfflineTest.is(gStep, 0, "Got manifestCached in step 0, gStep=" + gStep);
reloadLocations([fallbackFrame1, fallbackFrame2]);
waitForLocations([fallbackFrame1, fallbackFrame2],
fallbackLoaded);
waitForLocations(
["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback.html"],
fallbackLoaded
);
}
function fallbackLoaded()
{
dump("in fallbackLoaded\n");
applicationCache.mozAdd("http://mochi.test:8888/tests/SimpleTest/EventUtils.js");
OfflineTest.waitForAdd("http://mochi.test:8888/tests/SimpleTest/EventUtils.js",
dynamicLoaded);
@ -126,7 +129,7 @@ function fallbackLoaded()
function dynamicLoaded()
{
window.open("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingImplicit.html");
// window.onload invokes implicitLoaded()
// window.applicationCache.noupdate invokes implicitLoaded()
}
function implicitLoaded(aWindow, errorOccured)
@ -237,8 +240,8 @@ function manifestUpdated()
OfflineTest.setSJSState("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingIframe.sjs", "second");
gGotFrameVersion = 0;
gCallOnUpdatingFrameLoad = function() {applicationCache.update();};
updatingFrame.location.reload();
// Since the frame is offline-cached, reload of it invokes update
});
break;
@ -298,6 +301,7 @@ function manifestNoUpdate()
applicationCache.onnoupdate = null;
OfflineTest.ok(gStep == 3, "Got manifestNoUpdate in step 3, gStep=" + gStep);
++gStep;
OfflineTest.is(applicationCache.status, SpecialPowers.Ci.nsIDOMOfflineResourceList.UPDATEREADY,
"we have associated application cache and update is pending (4)");
@ -314,8 +318,7 @@ function checkNewVersionOfIFrame()
{
OfflineTest.is(gGotFrameVersion, 2, "IFrame version 2");
OfflineTest.teardown();
OfflineTest.finish();
OfflineTest.teardownAndFinish();
}
// End of the test function chain

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

@ -12,8 +12,7 @@ function manifestUpdated()
{
OfflineTest.ok(true, "Application cache updated.");
OfflineTest.teardown();
OfflineTest.finish();
OfflineTest.teardownAndFinish();
}
if (OfflineTest.setup()) {

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

@ -1,6 +1,16 @@
#filter substitution
package @ANDROID_PACKAGE_NAME@.tests;
import @ANDROID_PACKAGE_NAME@.*;
import android.app.Activity;
import android.content.SharedPreferences;
import java.lang.reflect.Method;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/* This test will test if doorhangers are displayed and dismissed
The test will test:
* geolocation doorhangers - sharing and not sharing the location dismisses the doorhanger
@ -65,6 +75,45 @@ public class testDoorHanger extends BaseTest {
// Make sure doorhanger is hidden
mAsserter.is(mSolo.searchText(GEO_MESSAGE), false, "Geolocation doorhanger notification is hidden when opening a new tab");
boolean offlineAllowedByDefault = true;
try {
// Save offline-allow-by-default preferences first
JSONArray getPrefData = new JSONArray();
getPrefData.put("offline-apps.allow_by_default");
JSONObject message = new JSONObject();
message.put("requestId", "testDoorHanger");
message.put("preferences", getPrefData);
Actions.RepeatedEventExpecter eventExpecter = mActions.expectGeckoEvent("Preferences:Data");
mActions.sendGeckoEvent("Preferences:Get", message.toString());
JSONObject data = null;
String requestId = "";
// Wait until we get the correct "Preferences:Data" event
while (!requestId.equals("testDoorHanger")) {
data = new JSONObject(eventExpecter.blockForEventData());
requestId = data.getString("requestId");
}
eventExpecter.unregisterListener();
JSONArray preferences = data.getJSONArray("preferences");
if (preferences.length() > 0) {
JSONObject pref = (JSONObject) preferences.get(0);
offlineAllowedByDefault = pref.getBoolean("value");
}
// Turn off offline-allow-by-default
JSONObject jsonPref = new JSONObject();
jsonPref.put("name", "offline-apps.allow_by_default");
jsonPref.put("type", "bool");
jsonPref.put("value", false);
mActions.sendGeckoEvent("Preferences:Set", jsonPref.toString());
} catch (JSONException e) {
mAsserter.ok(false, "exception getting preference", e.toString());
}
// Load offline storage page
loadUrl(OFFLINE_STORAGE_URL);
waitForText(OFFLINE_MESSAGE);
@ -84,6 +133,18 @@ public class testDoorHanger extends BaseTest {
loadUrl(OFFLINE_STORAGE_URL);
mAsserter.is(mSolo.searchText(OFFLINE_MESSAGE), false, "Offline storage doorhanger is no longer triggered");
try {
// Revert offline setting
JSONObject jsonPref = new JSONObject();
jsonPref.put("name", "offline-apps.allow_by_default");
jsonPref.put("type", "boolean");
jsonPref.put("value", offlineAllowedByDefault);
mActions.sendGeckoEvent("Preferences:Set", jsonPref.toString());
} catch (JSONException e) {
mAsserter.ok(false, "exception setting preference", e.toString());
}
// Load login page
loadUrl(LOGIN_URL);
waitForText(LOGIN_MESSAGE);

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

@ -61,6 +61,8 @@ pref("browser.cache.disk_cache_ssl", true);
pref("browser.cache.check_doc_frequency", 3);
pref("browser.cache.offline.enable", true);
// enable offline apps by default, disable prompt
pref("offline-apps.allow_by_default", true);
// offline cache capacity in kilobytes
pref("browser.cache.offline.capacity", 512000);

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

@ -686,22 +686,14 @@ OfflineAppPermForURI(nsIURI *aURI,
const char *permName = pinned ? "pin-app" : "offline-app";
permissionManager->TestExactPermission(innerURI, permName, &perm);
if (perm == nsIPermissionManager::UNKNOWN_ACTION && !pinned) {
static const char kPrefName[] = "offline-apps.allow_by_default";
if (aPrefBranch) {
aPrefBranch->GetBoolPref(kPrefName, aAllowed);
} else {
*aAllowed = Preferences::GetBool(kPrefName, false);
}
return NS_OK;
}
if (perm == nsIPermissionManager::ALLOW_ACTION ||
perm == nsIOfflineCacheUpdateService::ALLOW_NO_WARN) {
*aAllowed = true;
}
// offline-apps.allow_by_default is now effective at the cache selection
// algorithm code (nsContentSink).
return NS_OK;
}