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

This commit is contained in:
Honza Bambas 2013-08-14 17:17:00 +02:00
parent b2b21d09fa
commit e83bbcc4cd
25 changed files with 309 additions and 107 deletions

View File

@ -35,6 +35,7 @@ MOCHITEST_FILES = \
test_feed_discovery.html \
test_offline_gzip.html \
test_offlineNotification.html \
offlineByDefault.js \
video.ogg \
$(NULL)

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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();
}

View File

@ -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

View File

@ -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;
}

View File

@ -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()

View File

@ -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));
}
}

View File

@ -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.

View File

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

View File

@ -10,59 +10,57 @@
function manifestUpdated()
{
dump(">>>>>>>>>>>>>> MANIFESTUPDATED\n");
var appCacheService = SpecialPowers.Components.classes["@mozilla.org/network/application-cache-service;1"]
.getService(SpecialPowers.Ci.nsIApplicationCacheService);
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()
{
dump(">>>>>>>>>>>>>> ONLOADED\n");
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>

View File

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

View File

@ -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
@ -154,7 +172,9 @@ teardown: function()
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();
@ -237,12 +257,25 @@ 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)
var baseURI = ios.newURI(window.location.href, null, null);
dump("manifestURLspec=" + manifestURLspec + "\n");
return ios.newURI(manifestURLspec, null, baseURI);
},
@ -261,14 +294,17 @@ getActiveCache: function(overload)
var serv = Cc["@mozilla.org/network/application-cache-service;1"]
.getService(Ci.nsIApplicationCacheService);
var groupID = serv.buildGroupID(this.manifestURL(overload), this.loadContext());
dump("Getting active cache for " + groupID + " (o=" + overload + ")\n");
return serv.getActiveCache(groupID);
},
getActiveSession: function()
{
var cache = this.getActiveCache();
if (!cache)
if (!cache) {
dump("No active cache\n");
return null;
}
var cacheService = Cc["@mozilla.org/network/cache-service;1"]
.getService(Ci.nsICacheService);
@ -302,6 +338,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 +347,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 +383,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);
}
};

View File

@ -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()
@ -98,6 +106,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();
}

View File

@ -15,8 +15,9 @@ function manifestUpdated()
function onFallbackLoad(fallbackIdentification)
{
OfflineTest.is(fallbackIdentification, 1, "Got correct fallback for namespace1");
OfflineTest.is(fallbackIdentification, 1, "Got correct fallback for namespace1 (2)");
applicationCache.onerror = function() {}; // the update invoked by the iframe will finish after we discard the cache, ignore error
OfflineTest.teardown();
OfflineTest.finish();
}

View File

@ -19,42 +19,42 @@ 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();

View File

@ -52,11 +52,10 @@ 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.teardown();
OfflineTest.finish();
});
}
if (OfflineTest.setup()) {

View File

@ -43,6 +43,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);
}

View File

@ -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,15 @@ 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
{
dump(">>>>>>>>>>>>>> ON-DONE\n");
win.close();
OfflineTest.teardown();
OfflineTest.finish();
}
SimpleTest.waitForExplicitFinish();

View File

@ -46,7 +46,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,

View File

@ -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)");

View File

@ -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);

View File

@ -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);

View File

@ -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;
}