Bug 1694662 - Remove appcache tests r=necko-reviewers,dragana

Differential Revision: https://phabricator.services.mozilla.com/D106444
This commit is contained in:
Valentin Gosu
2021-04-30 07:20:19 +00:00
parent 1e176311c4
commit 12af03c3ec
17 changed files with 10 additions and 2010 deletions

View File

@@ -75,7 +75,7 @@ function createURI(uri) {
return Services.io.newURI(uri);
}
function getCacheStorage(where, lci, appcache) {
function getCacheStorage(where, lci) {
if (!lci) {
lci = Services.loadContextInfo.default;
}
@@ -84,8 +84,6 @@ function getCacheStorage(where, lci, appcache) {
return Services.cache2.diskCacheStorage(lci, false);
case "memory":
return Services.cache2.memoryCacheStorage(lci);
case "appcache":
return Services.cache2.appCacheStorage(lci, appcache);
case "pin":
return Services.cache2.pinningCacheStorage(lci);
}
@@ -97,8 +95,6 @@ function OpenCacheEntry(key, where, flags, lci) {
key = createURI(key);
function CacheListener() {}
CacheListener.prototype = {
_appCache: null,
QueryInterface: ChromeUtils.generateQI(["nsICacheEntryOpenCallback"]),
onCacheEntryCheck(entry) {
@@ -110,7 +106,7 @@ function OpenCacheEntry(key, where, flags, lci) {
},
run() {
let storage = getCacheStorage(where, lci, this._appCache);
let storage = getCacheStorage(where, lci);
storage.asyncOpenURI(key, "", flags, this);
},
};

View File

@@ -19,7 +19,6 @@ function get_cache_service() {
function evict_cache_entries(where) {
var clearDisk = !where || where == "disk" || where == "all";
var clearMem = !where || where == "memory" || where == "all";
var clearAppCache = where == "appcache";
var svc = get_cache_service();
var storage;
@@ -33,11 +32,6 @@ function evict_cache_entries(where) {
storage = svc.diskCacheStorage(Services.loadContextInfo.default, false);
storage.asyncEvictStorage(null);
}
if (clearAppCache) {
storage = svc.appCacheStorage(Services.loadContextInfo.default, null);
storage.asyncEvictStorage(null);
}
}
function createURI(urispec) {
@@ -47,7 +41,7 @@ function createURI(urispec) {
return ioServ.newURI(urispec);
}
function getCacheStorage(where, lci, appcache) {
function getCacheStorage(where, lci) {
if (!lci) {
lci = Services.loadContextInfo.default;
}
@@ -57,21 +51,17 @@ function getCacheStorage(where, lci, appcache) {
return svc.diskCacheStorage(lci, false);
case "memory":
return svc.memoryCacheStorage(lci);
case "appcache":
return svc.appCacheStorage(lci, appcache);
case "pin":
return svc.pinningCacheStorage(lci);
}
return null;
}
function asyncOpenCacheEntry(key, where, flags, lci, callback, appcache) {
function asyncOpenCacheEntry(key, where, flags, lci, callback) {
key = createURI(key);
function CacheListener() {}
CacheListener.prototype = {
_appCache: appcache,
QueryInterface: ChromeUtils.generateQI(["nsICacheEntryOpenCallback"]),
onCacheEntryCheck(entry) {
@@ -92,7 +82,7 @@ function asyncOpenCacheEntry(key, where, flags, lci, callback, appcache) {
},
run() {
var storage = getCacheStorage(where, lci, this._appCache);
var storage = getCacheStorage(where, lci);
storage.asyncOpenURI(key, "", flags, this);
},
};
@@ -136,13 +126,7 @@ function get_device_entry_count(where, lci, continuation) {
storage.asyncVisitStorage(visitor, false);
}
function asyncCheckCacheEntryPresence(
key,
where,
shouldExist,
continuation,
appCache
) {
function asyncCheckCacheEntryPresence(key, where, shouldExist, continuation) {
asyncOpenCacheEntry(
key,
where,
@@ -161,7 +145,6 @@ function asyncCheckCacheEntryPresence(
Assert.equal(null, entry);
}
continuation();
},
appCache
}
);
}

View File

@@ -7,7 +7,6 @@
// names for cache devices
const kDiskDevice = "disk";
const kMemoryDevice = "memory";
const kOfflineDevice = "appcache";
const kCacheA = "http://cache/A";
const kCacheA2 = "http://cache/A2";
@@ -28,12 +27,10 @@ const entries = [
[kCacheA, kTestContent, kMemoryDevice, true],
[kCacheA2, kTestContent, kDiskDevice, false],
[kCacheB, kTestContent, kDiskDevice, true],
[kCacheC, kTestContent, kOfflineDevice, true],
];
var store_idx;
var store_cb = null;
var appCache = null;
function store_entries(cb) {
if (cb) {
@@ -53,8 +50,7 @@ function store_entries(cb) {
Services.loadContextInfo.custom(false, {
privateBrowsingId: entries[store_idx][3] ? 0 : 1,
}),
store_data,
appCache
store_data
);
}
@@ -102,8 +98,7 @@ function check_entries(cb, pbExited) {
Services.loadContextInfo.custom(false, {
privateBrowsingId: entries[check_idx][3] ? 0 : 1,
}),
check_data,
appCache
check_data
);
}
@@ -131,13 +126,6 @@ function run_test() {
// Simulate a profile dir for xpcshell
do_get_profile();
Services.prefs.setBoolPref("browser.cache.offline.enable", true);
Services.prefs.setBoolPref("browser.cache.offline.storage.enable", true);
appCache = Cc["@mozilla.org/network/application-cache-service;1"]
.getService(Ci.nsIApplicationCacheService)
.getApplicationCache("fake-client-id|fake-group-id");
// Start off with an empty cache
evict_cache_entries();

View File

@@ -1,315 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
"use strict";
const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
/**
* This testcase does the following steps to make sure that bug767025 removes
* files as expected.
*
* STEPS:
* - Schedule a offline cache update for app.manifest.
* - pages/foo1, pages/foo2, pages/foo3, and pages/foo4 are cached.
* - Activate pages/foo1
* - Doom pages/foo1, and pages/foo2.
* - pages/foo1 should keep alive while pages/foo2 was gone.
* - Activate pages/foo3
* - Evict all documents.
* - all documents except pages/foo1 are gone since pages/foo1 & pages/foo3
* are activated.
*/
const kNS_OFFLINECACHEUPDATESERVICE_CONTRACTID =
"@mozilla.org/offlinecacheupdate-service;1";
const kNS_CACHESTORAGESERVICE_CONTRACTID =
"@mozilla.org/netwerk/cache-storage-service;1";
const kNS_APPLICATIONCACHESERVICE_CONTRACTID =
"@mozilla.org/network/application-cache-service;1";
const kManifest =
"CACHE MANIFEST\n" +
"/pages/foo1\n" +
"/pages/foo2\n" +
"/pages/foo3\n" +
"/pages/foo4\n";
const kDataFileSize = 1024; // file size for each content page
const kHttpLocation = "http://localhost:4444/";
function manifest_handler(metadata, response) {
info("manifest\n");
response.setHeader("content-type", "text/cache-manifest");
response.write(kManifest);
}
function datafile_handler(metadata, response) {
info("datafile_handler\n");
let data = "";
while (data.length < kDataFileSize) {
data =
data +
Math.random()
.toString(36)
.substring(2, 15);
}
response.setHeader("content-type", "text/plain");
response.write(data.substring(0, kDataFileSize));
}
function app_handler(metadata, response) {
info("app_handler\n");
response.setHeader("content-type", "text/html");
response.write("<html></html>");
}
var httpServer;
function init_profile() {
var ps = Cc["@mozilla.org/preferences-service;1"].getService(
Ci.nsIPrefBranch
);
dump(ps.getBoolPref("browser.cache.offline.enable"));
ps.setBoolPref("browser.cache.offline.enable", true);
ps.setBoolPref("browser.cache.offline.storage.enable", true);
ps.setComplexValue(
"browser.cache.offline.parent_directory",
Ci.nsIFile,
do_get_profile()
);
info("profile " + do_get_profile());
}
function init_http_server() {
httpServer = new HttpServer();
httpServer.registerPathHandler("/app.appcache", manifest_handler);
httpServer.registerPathHandler("/app", app_handler);
for (let i = 1; i <= 4; i++) {
httpServer.registerPathHandler("/pages/foo" + i, datafile_handler);
}
httpServer.start(4444);
}
function clean_app_cache() {
let cache_service = Cc[kNS_CACHESTORAGESERVICE_CONTRACTID].getService(
Ci.nsICacheStorageService
);
let storage = cache_service.appCacheStorage(
Services.loadContextInfo.default,
null
);
storage.asyncEvictStorage(null);
}
function do_app_cache(manifestURL, pageURL) {
let update_service = Cc[kNS_OFFLINECACHEUPDATESERVICE_CONTRACTID].getService(
Ci.nsIOfflineCacheUpdateService
);
PermissionTestUtils.add(
manifestURL,
"offline-app",
Ci.nsIPermissionManager.ALLOW_ACTION
);
let update = update_service.scheduleUpdate(
manifestURL,
pageURL,
Services.scriptSecurityManager.getSystemPrincipal(),
null
); /* no window */
return update;
}
function watch_update(update, stateChangeHandler, cacheAvailHandler) {
let observer = {
QueryInterface: ChromeUtils.generateQI([]),
updateStateChanged: stateChangeHandler,
applicationCacheAvailable: cacheAvailHandler,
};
~update.addObserver(observer);
return update;
}
function start_and_watch_app_cache(
manifestURL,
pageURL,
stateChangeHandler,
cacheAvailHandler
) {
let ioService = Cc["@mozilla.org/network/io-service;1"].getService(
Ci.nsIIOService
);
let update = do_app_cache(
ioService.newURI(manifestURL),
ioService.newURI(pageURL)
);
watch_update(update, stateChangeHandler, cacheAvailHandler);
return update;
}
const {
STATE_FINISHED: STATE_FINISHED,
STATE_CHECKING: STATE_CHECKING,
STATE_ERROR: STATE_ERROR,
} = Ci.nsIOfflineCacheUpdateObserver;
/*
* Start caching app1 as a non-pinned app.
*/
function start_cache_nonpinned_app() {
info("Start non-pinned App1");
start_and_watch_app_cache(
kHttpLocation + "app.appcache",
kHttpLocation + "app",
function(update, state) {
switch (state) {
case STATE_FINISHED:
check_bug();
break;
case STATE_ERROR:
do_throw("App cache state = " + state);
break;
}
},
function(appcache) {
info("app avail " + appcache + "\n");
}
);
}
var hold_entry_foo1 = null;
function check_bug() {
// activate foo1
asyncOpenCacheEntry(
kHttpLocation + "pages/foo1",
"appcache",
Ci.nsICacheStorage.OPEN_READONLY,
null,
function(status, entry, appcache) {
let storage = get_cache_service().appCacheStorage(
Services.loadContextInfo.default,
appcache
);
// Doom foo1 & foo2
storage.asyncDoomURI(createURI(kHttpLocation + "pages/foo1"), "", {
onCacheEntryDoomed() {
storage.asyncDoomURI(createURI(kHttpLocation + "pages/foo2"), "", {
onCacheEntryDoomed() {
check_evict_cache(appcache);
},
});
},
});
hold_entry_foo1 = entry;
}
);
}
function check_evict_cache(appcache) {
// Only foo2 should be removed.
let file = do_get_profile().clone();
file.append("OfflineCache");
file.append("5");
file.append("9");
file.append("8379C6596B8CA4-0");
Assert.equal(file.exists(), true);
file = do_get_profile().clone();
file.append("OfflineCache");
file.append("C");
file.append("2");
file.append("5F356A168B5E3B-0");
Assert.equal(file.exists(), false);
// activate foo3
asyncOpenCacheEntry(
kHttpLocation + "pages/foo3",
"appcache",
Ci.nsICacheStorage.OPEN_READONLY,
null,
function(status, entry, appcache) {
// evict all documents.
let storage = get_cache_service().appCacheStorage(
Services.loadContextInfo.default,
appcache
);
storage.asyncEvictStorage(null);
// All documents are removed except foo1 & foo3.
syncWithCacheIOThread(function() {
// foo1
let file = do_get_profile().clone();
file.append("OfflineCache");
file.append("5");
file.append("9");
file.append("8379C6596B8CA4-0");
Assert.equal(file.exists(), true);
file = do_get_profile().clone();
file.append("OfflineCache");
file.append("0");
file.append("0");
file.append("61FEE819921D39-0");
Assert.equal(file.exists(), false);
file = do_get_profile().clone();
file.append("OfflineCache");
file.append("3");
file.append("9");
file.append("0D8759F1DE5452-0");
Assert.equal(file.exists(), false);
file = do_get_profile().clone();
file.append("OfflineCache");
file.append("C");
file.append("2");
file.append("5F356A168B5E3B-0");
Assert.equal(file.exists(), false);
// foo3
file = do_get_profile().clone();
file.append("OfflineCache");
file.append("D");
file.append("C");
file.append("1ADCCC843B5C00-0");
Assert.equal(file.exists(), true);
file = do_get_profile().clone();
file.append("OfflineCache");
file.append("F");
file.append("0");
file.append("FC3E6D6C1164E9-0");
Assert.equal(file.exists(), false);
httpServer.stop(do_test_finished);
}, true /* force even with the new cache back end */);
},
appcache
);
}
function run_test() {
if (typeof _XPCSHELL_PROCESS == "undefined" || _XPCSHELL_PROCESS != "child") {
init_profile();
clean_app_cache();
}
init_http_server();
start_cache_nonpinned_app();
do_test_pending();
}

View File

@@ -1,104 +0,0 @@
"use strict";
// https://bugzilla.mozilla.org/show_bug.cgi?id=760955
const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");
var httpServer = null;
const testFileName = "test_nsHttpChannel_CacheForOfflineUse-no-store";
const cacheClientID = testFileName + "|fake-group-id";
const basePath = "/" + testFileName + "/";
XPCOMUtils.defineLazyGetter(this, "baseURI", function() {
return "http://localhost:" + httpServer.identity.primaryPort + basePath;
});
const normalEntry = "normal";
const noStoreEntry = "no-store";
var cacheUpdateObserver = null;
var appCache = null;
function make_channel_for_offline_use(url, callback, ctx) {
var chan = NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true });
var cacheService = Cc[
"@mozilla.org/network/application-cache-service;1"
].getService(Ci.nsIApplicationCacheService);
appCache = cacheService.getApplicationCache(cacheClientID);
var appCacheChan = chan.QueryInterface(Ci.nsIApplicationCacheChannel);
appCacheChan.applicationCacheForWrite = appCache;
return chan;
}
function make_uri(url) {
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
return ios.newURI(url);
}
const responseBody = "response body";
// A HTTP channel for updating the offline cache should normally succeed.
function normalHandler(metadata, response) {
info("normalHandler");
response.setHeader("Content-Type", "text/plain");
response.bodyOutputStream.write(responseBody, responseBody.length);
}
function checkNormal(request, buffer) {
Assert.equal(buffer, responseBody);
asyncCheckCacheEntryPresence(
baseURI + normalEntry,
"appcache",
true,
run_next_test,
appCache
);
}
add_test(function test_normal() {
var chan = make_channel_for_offline_use(baseURI + normalEntry);
chan.asyncOpen(new ChannelListener(checkNormal, chan));
});
// An HTTP channel for updating the offline cache should fail when it gets a
// response with Cache-Control: no-store.
function noStoreHandler(metadata, response) {
info("noStoreHandler");
response.setHeader("Content-Type", "text/plain");
response.setHeader("Cache-Control", "no-store");
response.bodyOutputStream.write(responseBody, responseBody.length);
}
function checkNoStore(request, buffer) {
Assert.equal(buffer, "");
asyncCheckCacheEntryPresence(
baseURI + noStoreEntry,
"appcache",
false,
run_next_test,
appCache
);
}
add_test(function test_noStore() {
var chan = make_channel_for_offline_use(baseURI + noStoreEntry);
// The no-store should cause the channel to fail to load.
chan.asyncOpen(new ChannelListener(checkNoStore, chan, CL_EXPECT_FAILURE));
});
function run_test() {
do_get_profile();
var ps = Cc["@mozilla.org/preferences-service;1"].getService(
Ci.nsIPrefBranch
);
ps.setBoolPref("browser.cache.offline.enable", true);
ps.setBoolPref("browser.cache.offline.storage.enable", true);
httpServer = new HttpServer();
httpServer.registerPathHandler(basePath + normalEntry, normalHandler);
httpServer.registerPathHandler(basePath + noStoreEntry, noStoreHandler);
httpServer.start(-1);
run_next_test();
}
function finish_test(request, buffer) {
httpServer.stop(do_test_finished);
}

View File

@@ -1,131 +0,0 @@
"use strict";
const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");
var httpServer = null;
// Need to randomize, because apparently no one clears our cache
var randomPath = "/redirect/" + Math.random();
XPCOMUtils.defineLazyGetter(this, "randomURI", function() {
return "http://localhost:" + httpServer.identity.primaryPort + randomPath;
});
var cacheUpdateObserver = null;
function make_channel(url, callback, ctx) {
return NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true });
}
function make_uri(url) {
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
return ios.newURI(url);
}
var responseBody = "Content body";
// start the test with loading this master entry referencing the manifest
function masterEntryHandler(metadata, response) {
var masterEntryContent = "<html manifest='/manifest'></html>";
response.setHeader("Content-Type", "text/html");
response.bodyOutputStream.write(
masterEntryContent,
masterEntryContent.length
);
}
// manifest defines fallback namespace from any /redirect path to /content
function manifestHandler(metadata, response) {
var manifestContent = "CACHE MANIFEST\nFALLBACK:\nredirect /content\n";
response.setHeader("Content-Type", "text/cache-manifest");
response.bodyOutputStream.write(manifestContent, manifestContent.length);
}
// content handler correctly returns some plain text data
function contentHandler(metadata, response) {
response.setHeader("Content-Type", "text/plain");
response.bodyOutputStream.write(responseBody, responseBody.length);
}
// finally check we got fallback content
function finish_test(request, buffer) {
Assert.equal(buffer, "");
httpServer.stop(do_test_finished);
}
function run_test() {
httpServer = new HttpServer();
httpServer.registerPathHandler("/masterEntry", masterEntryHandler);
httpServer.registerPathHandler("/manifest", manifestHandler);
httpServer.registerPathHandler("/content", contentHandler);
httpServer.start(-1);
var pm = Cc["@mozilla.org/permissionmanager;1"].getService(
Ci.nsIPermissionManager
);
var ssm = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(
Ci.nsIScriptSecurityManager
);
var uri = make_uri("http://localhost:" + httpServer.identity.primaryPort);
var principal = ssm.createContentPrincipal(uri, {});
if (pm.testPermissionFromPrincipal(principal, "offline-app") != 0) {
dump(
"Previous test failed to clear offline-app permission! Expect failures.\n"
);
}
pm.addFromPrincipal(
principal,
"offline-app",
Ci.nsIPermissionManager.ALLOW_ACTION
);
var ps = Cc["@mozilla.org/preferences-service;1"].getService(
Ci.nsIPrefBranch
);
dump(ps.getBoolPref("browser.cache.offline.enable"));
ps.setBoolPref("browser.cache.offline.enable", true);
ps.setBoolPref("browser.cache.offline.storage.enable", true);
ps.setComplexValue(
"browser.cache.offline.parent_directory",
Ci.nsIFile,
do_get_profile()
);
cacheUpdateObserver = {
observe() {
dump("got offline-cache-update-completed\n");
// offline cache update completed.
// In this test the randomURI doesn't exists
var chan = make_channel(randomURI);
chan.loadFlags =
Ci.nsIRequest.INHIBIT_CACHING |
Ci.nsIRequest.LOAD_FROM_CACHE |
Ci.nsICachingChannel.LOAD_ONLY_FROM_CACHE;
chan.notificationCallbacks = new ChannelEventSink(ES_ABORT_REDIRECT);
var chanac = chan.QueryInterface(Ci.nsIApplicationCacheChannel);
chanac.chooseApplicationCache = true;
chan.asyncOpen(new ChannelListener(finish_test, null, CL_EXPECT_FAILURE));
},
};
var os = Cc["@mozilla.org/observer-service;1"].getService(
Ci.nsIObserverService
);
os.addObserver(cacheUpdateObserver, "offline-cache-update-completed");
var us = Cc["@mozilla.org/offlinecacheupdate-service;1"].getService(
Ci.nsIOfflineCacheUpdateService
);
us.scheduleUpdate(
make_uri(
"http://localhost:" + httpServer.identity.primaryPort + "/manifest"
),
make_uri(
"http://localhost:" + httpServer.identity.primaryPort + "/masterEntry"
),
Services.scriptSecurityManager.getSystemPrincipal(),
null
);
do_test_pending();
}

View File

@@ -1,130 +0,0 @@
"use strict";
const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");
var httpServer = null;
// Need to randomize, because apparently no one clears our cache
var randomPath = "/redirect/" + Math.random();
XPCOMUtils.defineLazyGetter(this, "randomURI", function() {
return "http://localhost:" + httpServer.identity.primaryPort + randomPath;
});
var cacheUpdateObserver = null;
function make_channel(url, callback, ctx) {
return NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true });
}
function make_uri(url) {
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
return ios.newURI(url);
}
var responseBody = "Content body";
// start the test with loading this master entry referencing the manifest
function masterEntryHandler(metadata, response) {
var masterEntryContent = "<html manifest='/manifest'></html>";
response.setHeader("Content-Type", "text/html");
response.bodyOutputStream.write(
masterEntryContent,
masterEntryContent.length
);
}
// manifest defines fallback namespace from any /redirect path to /content
function manifestHandler(metadata, response) {
var manifestContent = "CACHE MANIFEST\nFALLBACK:\nredirect /content\n";
response.setHeader("Content-Type", "text/cache-manifest");
response.bodyOutputStream.write(manifestContent, manifestContent.length);
}
// content handler correctly returns some plain text data
function contentHandler(metadata, response) {
response.setHeader("Content-Type", "text/plain");
response.bodyOutputStream.write(responseBody, responseBody.length);
}
// finally check we got fallback content
function finish_test(request, buffer) {
Assert.equal(buffer, responseBody);
httpServer.stop(do_test_finished);
}
function run_test() {
httpServer = new HttpServer();
httpServer.registerPathHandler("/masterEntry", masterEntryHandler);
httpServer.registerPathHandler("/manifest", manifestHandler);
httpServer.registerPathHandler("/content", contentHandler);
httpServer.start(-1);
var pm = Cc["@mozilla.org/permissionmanager;1"].getService(
Ci.nsIPermissionManager
);
var ssm = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(
Ci.nsIScriptSecurityManager
);
var uri = make_uri("http://localhost:" + httpServer.identity.primaryPort);
var principal = ssm.createContentPrincipal(uri, {});
if (pm.testPermissionFromPrincipal(principal, "offline-app") != 0) {
dump(
"Previous test failed to clear offline-app permission! Expect failures.\n"
);
}
pm.addFromPrincipal(
principal,
"offline-app",
Ci.nsIPermissionManager.ALLOW_ACTION
);
var ps = Cc["@mozilla.org/preferences-service;1"].getService(
Ci.nsIPrefBranch
);
dump(ps.getBoolPref("browser.cache.offline.enable"));
ps.setBoolPref("browser.cache.offline.enable", true);
ps.setBoolPref("browser.cache.offline.storage.enable", true);
ps.setComplexValue(
"browser.cache.offline.parent_directory",
Ci.nsIFile,
do_get_profile()
);
cacheUpdateObserver = {
observe() {
dump("got offline-cache-update-completed\n");
// offline cache update completed.
// In this test the randomURI doesn't exists
var chan = make_channel(randomURI);
chan.loadFlags =
Ci.nsIRequest.INHIBIT_CACHING |
Ci.nsIRequest.LOAD_FROM_CACHE |
Ci.nsICachingChannel.LOAD_ONLY_FROM_CACHE;
var chanac = chan.QueryInterface(Ci.nsIApplicationCacheChannel);
chanac.chooseApplicationCache = true;
chan.asyncOpen(new ChannelListener(finish_test));
},
};
var os = Cc["@mozilla.org/observer-service;1"].getService(
Ci.nsIObserverService
);
os.addObserver(cacheUpdateObserver, "offline-cache-update-completed");
var us = Cc["@mozilla.org/offlinecacheupdate-service;1"].getService(
Ci.nsIOfflineCacheUpdateService
);
us.scheduleUpdate(
make_uri(
"http://localhost:" + httpServer.identity.primaryPort + "/manifest"
),
make_uri(
"http://localhost:" + httpServer.identity.primaryPort + "/masterEntry"
),
Services.scriptSecurityManager.getSystemPrincipal(),
null
);
do_test_pending();
}

View File

@@ -1,133 +0,0 @@
"use strict";
const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");
var httpServer = null;
// Need to randomize, because apparently no one clears our cache
var randomPath = "/redirect/" + Math.random();
XPCOMUtils.defineLazyGetter(this, "randomURI", function() {
return "http://localhost:" + httpServer.identity.primaryPort + randomPath;
});
var cacheUpdateObserver = null;
function make_channel(url, callback, ctx) {
return NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true });
}
function make_uri(url) {
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
return ios.newURI(url);
}
const responseBody = "Content body";
// start the test with loading this master entry referencing the manifest
function masterEntryHandler(metadata, response) {
var masterEntryContent = "<html manifest='/manifest'></html>";
response.setHeader("Content-Type", "text/html");
response.bodyOutputStream.write(
masterEntryContent,
masterEntryContent.length
);
}
// manifest defines fallback namespace from any /redirect path to /content
function manifestHandler(metadata, response) {
var manifestContent = "CACHE MANIFEST\nFALLBACK:\nredirect /content\n";
response.setHeader("Content-Type", "text/cache-manifest");
response.bodyOutputStream.write(manifestContent, manifestContent.length);
}
// content handler correctly returns some plain text data
function contentHandler(metadata, response) {
response.setHeader("Content-Type", "text/plain");
response.bodyOutputStream.write(responseBody, responseBody.length);
}
// redirect handler returns redirect
function redirectHandler(metadata, response) {
response.setStatusLine(metadata.httpVersion, 301, "Moved");
response.setHeader("Location", "http://example.com/", false);
}
// finally check we got fallback content
function finish_test(request, buffer) {
Assert.equal(buffer, "");
httpServer.stop(do_test_finished);
}
function run_test() {
httpServer = new HttpServer();
httpServer.registerPathHandler("/masterEntry", masterEntryHandler);
httpServer.registerPathHandler("/manifest", manifestHandler);
httpServer.registerPathHandler("/content", contentHandler);
httpServer.registerPathHandler(randomPath, redirectHandler);
httpServer.start(-1);
var pm = Cc["@mozilla.org/permissionmanager;1"].getService(
Ci.nsIPermissionManager
);
var ssm = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(
Ci.nsIScriptSecurityManager
);
var uri = make_uri("http://localhost:" + httpServer.identity.primaryPort);
var principal = ssm.createContentPrincipal(uri, {});
if (pm.testPermissionFromPrincipal(principal, "offline-app") != 0) {
dump(
"Previous test failed to clear offline-app permission! Expect failures.\n"
);
}
pm.addFromPrincipal(
principal,
"offline-app",
Ci.nsIPermissionManager.ALLOW_ACTION
);
var ps = Cc["@mozilla.org/preferences-service;1"].getService(
Ci.nsIPrefBranch
);
dump(ps.getBoolPref("browser.cache.offline.enable"));
ps.setBoolPref("browser.cache.offline.enable", true);
ps.setBoolPref("browser.cache.offline.storage.enable", true);
ps.setComplexValue(
"browser.cache.offline.parent_directory",
Ci.nsIFile,
do_get_profile()
);
cacheUpdateObserver = {
observe() {
dump("got offline-cache-update-completed\n");
// offline cache update completed.
var chan = make_channel(randomURI);
chan.notificationCallbacks = new ChannelEventSink(ES_ABORT_REDIRECT);
var chanac = chan.QueryInterface(Ci.nsIApplicationCacheChannel);
chanac.chooseApplicationCache = true;
chan.asyncOpen(new ChannelListener(finish_test, null, CL_EXPECT_FAILURE));
},
};
var os = Cc["@mozilla.org/observer-service;1"].getService(
Ci.nsIObserverService
);
os.addObserver(cacheUpdateObserver, "offline-cache-update-completed");
var us = Cc["@mozilla.org/offlinecacheupdate-service;1"].getService(
Ci.nsIOfflineCacheUpdateService
);
us.scheduleUpdate(
make_uri(
"http://localhost:" + httpServer.identity.primaryPort + "/manifest"
),
make_uri(
"http://localhost:" + httpServer.identity.primaryPort + "/masterEntry"
),
Services.scriptSecurityManager.getSystemPrincipal(),
null
);
do_test_pending();
}

View File

@@ -1,132 +0,0 @@
"use strict";
const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");
var httpServer = null;
// Need to randomize, because apparently no one clears our cache
var randomPath = "/redirect/" + Math.random();
XPCOMUtils.defineLazyGetter(this, "randomURI", function() {
return "http://localhost:" + httpServer.identity.primaryPort + randomPath;
});
var cacheUpdateObserver = null;
function make_channel(url, callback, ctx) {
return NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true });
}
function make_uri(url) {
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
return ios.newURI(url);
}
var responseBody = "Content body";
// start the test with loading this master entry referencing the manifest
function masterEntryHandler(metadata, response) {
var masterEntryContent = "<html manifest='/manifest'></html>";
response.setHeader("Content-Type", "text/html");
response.bodyOutputStream.write(
masterEntryContent,
masterEntryContent.length
);
}
// manifest defines fallback namespace from any /redirect path to /content
function manifestHandler(metadata, response) {
var manifestContent = "CACHE MANIFEST\nFALLBACK:\nredirect /content\n";
response.setHeader("Content-Type", "text/cache-manifest");
response.bodyOutputStream.write(manifestContent, manifestContent.length);
}
// content handler correctly returns some plain text data
function contentHandler(metadata, response) {
response.setHeader("Content-Type", "text/plain");
response.bodyOutputStream.write(responseBody, responseBody.length);
}
// redirect handler returns redirect
function redirectHandler(metadata, response) {
response.setStatusLine(metadata.httpVersion, 301, "Moved");
response.setHeader("Location", "http://example.com/", false);
}
// finally check we got fallback content
function finish_test(request, buffer) {
Assert.equal(buffer, responseBody);
httpServer.stop(do_test_finished);
}
function run_test() {
httpServer = new HttpServer();
httpServer.registerPathHandler("/masterEntry", masterEntryHandler);
httpServer.registerPathHandler("/manifest", manifestHandler);
httpServer.registerPathHandler("/content", contentHandler);
httpServer.registerPathHandler(randomPath, redirectHandler);
httpServer.start(-1);
var pm = Cc["@mozilla.org/permissionmanager;1"].getService(
Ci.nsIPermissionManager
);
var ssm = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(
Ci.nsIScriptSecurityManager
);
var uri = make_uri("http://localhost:" + httpServer.identity.primaryPort);
var principal = ssm.createContentPrincipal(uri, {});
if (pm.testPermissionFromPrincipal(principal, "offline-app") != 0) {
dump(
"Previous test failed to clear offline-app permission! Expect failures.\n"
);
}
pm.addFromPrincipal(
principal,
"offline-app",
Ci.nsIPermissionManager.ALLOW_ACTION
);
var ps = Cc["@mozilla.org/preferences-service;1"].getService(
Ci.nsIPrefBranch
);
dump(ps.getBoolPref("browser.cache.offline.enable"));
ps.setBoolPref("browser.cache.offline.enable", true);
ps.setBoolPref("browser.cache.offline.storage.enable", true);
ps.setComplexValue(
"browser.cache.offline.parent_directory",
Ci.nsIFile,
do_get_profile()
);
cacheUpdateObserver = {
observe() {
dump("got offline-cache-update-completed\n");
// offline cache update completed.
var chan = make_channel(randomURI);
var chanac = chan.QueryInterface(Ci.nsIApplicationCacheChannel);
chanac.chooseApplicationCache = true;
chan.asyncOpen(new ChannelListener(finish_test));
},
};
var os = Cc["@mozilla.org/observer-service;1"].getService(
Ci.nsIObserverService
);
os.addObserver(cacheUpdateObserver, "offline-cache-update-completed");
var us = Cc["@mozilla.org/offlinecacheupdate-service;1"].getService(
Ci.nsIOfflineCacheUpdateService
);
us.scheduleUpdate(
make_uri(
"http://localhost:" + httpServer.identity.primaryPort + "/manifest"
),
make_uri(
"http://localhost:" + httpServer.identity.primaryPort + "/masterEntry"
),
Services.scriptSecurityManager.getSystemPrincipal(),
null
);
do_test_pending();
}

View File

@@ -1,140 +0,0 @@
"use strict";
const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");
var httpServer = null;
// Need to randomize, because apparently no one clears our cache
var randomPath = "/redirect/" + Math.random();
XPCOMUtils.defineLazyGetter(this, "randomURI", function() {
return "http://localhost:" + httpServer.identity.primaryPort + randomPath;
});
var cacheUpdateObserver = null;
function make_channel(url, callback, ctx) {
return NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true });
}
function make_uri(url) {
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
return ios.newURI(url);
}
var responseBody = "Content body";
// start the test with loading this master entry referencing the manifest
function masterEntryHandler(metadata, response) {
var masterEntryContent = "<html manifest='/manifest'></html>";
response.setHeader("Content-Type", "text/html");
response.bodyOutputStream.write(
masterEntryContent,
masterEntryContent.length
);
}
// manifest defines fallback namespace from any /redirect path to /content
function manifestHandler(metadata, response) {
var manifestContent = "CACHE MANIFEST\nFALLBACK:\nredirect /content\n";
response.setHeader("Content-Type", "text/cache-manifest");
response.bodyOutputStream.write(manifestContent, manifestContent.length);
}
// content handler correctly returns some plain text data
function contentHandler(metadata, response) {
response.setHeader("Content-Type", "text/plain");
response.bodyOutputStream.write(responseBody, responseBody.length);
}
// redirect handler returns redirect
function redirectHandler(metadata, response) {
response.setStatusLine(metadata.httpVersion, 301, "Moved");
response.setHeader("Location", "http://example.com/", false);
}
// finally check we got fallback content
function finish_test(request, buffer) {
Assert.equal(buffer, "");
do_test_finished();
}
function run_test() {
httpServer = new HttpServer();
httpServer.registerPathHandler("/masterEntry", masterEntryHandler);
httpServer.registerPathHandler("/manifest", manifestHandler);
httpServer.registerPathHandler("/content", contentHandler);
httpServer.start(-1);
var pm = Cc["@mozilla.org/permissionmanager;1"].getService(
Ci.nsIPermissionManager
);
var ssm = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(
Ci.nsIScriptSecurityManager
);
var uri = make_uri("http://localhost:" + httpServer.identity.primaryPort);
var principal = ssm.createContentPrincipal(uri, {});
if (pm.testPermissionFromPrincipal(principal, "offline-app") != 0) {
dump(
"Previous test failed to clear offline-app permission! Expect failures.\n"
);
}
pm.addFromPrincipal(
principal,
"offline-app",
Ci.nsIPermissionManager.ALLOW_ACTION
);
var ps = Cc["@mozilla.org/preferences-service;1"].getService(
Ci.nsIPrefBranch
);
dump(ps.getBoolPref("browser.cache.offline.enable"));
ps.setBoolPref("browser.cache.offline.enable", true);
ps.setBoolPref("browser.cache.offline.storage.enable", true);
ps.setComplexValue(
"browser.cache.offline.parent_directory",
Ci.nsIFile,
do_get_profile()
);
cacheUpdateObserver = {
observe() {
dump("got offline-cache-update-completed\n");
// offline cache update completed.
// doing this to eval the lazy getter, otherwise the make_channel call would hang
randomURI;
httpServer.stop(function() {
// Now shut the server down to have an error in onStartRequest
var chan = make_channel(randomURI);
chan.notificationCallbacks = new ChannelEventSink(ES_ABORT_REDIRECT);
var chanac = chan.QueryInterface(Ci.nsIApplicationCacheChannel);
chanac.chooseApplicationCache = true;
chan.asyncOpen(
new ChannelListener(finish_test, null, CL_EXPECT_FAILURE)
);
});
},
};
var os = Cc["@mozilla.org/observer-service;1"].getService(
Ci.nsIObserverService
);
os.addObserver(cacheUpdateObserver, "offline-cache-update-completed");
var us = Cc["@mozilla.org/offlinecacheupdate-service;1"].getService(
Ci.nsIOfflineCacheUpdateService
);
us.scheduleUpdate(
make_uri(
"http://localhost:" + httpServer.identity.primaryPort + "/manifest"
),
make_uri(
"http://localhost:" + httpServer.identity.primaryPort + "/masterEntry"
),
Services.scriptSecurityManager.getSystemPrincipal(),
null
);
do_test_pending();
}

View File

@@ -1,136 +0,0 @@
"use strict";
const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");
var httpServer = null;
// Need to randomize, because apparently no one clears our cache
var randomPath = "/redirect/" + Math.random();
XPCOMUtils.defineLazyGetter(this, "randomURI", function() {
return "http://localhost:" + httpServer.identity.primaryPort + randomPath;
});
var cacheUpdateObserver = null;
var systemPrincipal = Services.scriptSecurityManager.getSystemPrincipal();
function make_channel(url, callback, ctx) {
return NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true });
}
function make_uri(url) {
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
return ios.newURI(url);
}
var responseBody = "Content body";
// start the test with loading this master entry referencing the manifest
function masterEntryHandler(metadata, response) {
var masterEntryContent = "<html manifest='/manifest'></html>";
response.setHeader("Content-Type", "text/html");
response.bodyOutputStream.write(
masterEntryContent,
masterEntryContent.length
);
}
// manifest defines fallback namespace from any /redirect path to /content
function manifestHandler(metadata, response) {
var manifestContent = "CACHE MANIFEST\nFALLBACK:\nredirect /content\n";
response.setHeader("Content-Type", "text/cache-manifest");
response.bodyOutputStream.write(manifestContent, manifestContent.length);
}
// content handler correctly returns some plain text data
function contentHandler(metadata, response) {
response.setHeader("Content-Type", "text/plain");
response.bodyOutputStream.write(responseBody, responseBody.length);
}
// redirect handler returns redirect
function redirectHandler(metadata, response) {
response.setStatusLine(metadata.httpVersion, 301, "Moved");
response.setHeader("Location", "http://example.com/", false);
}
// finally check we got fallback content
function finish_test(request, buffer) {
Assert.equal(buffer, responseBody);
do_test_finished();
}
function run_test() {
httpServer = new HttpServer();
httpServer.registerPathHandler("/masterEntry", masterEntryHandler);
httpServer.registerPathHandler("/manifest", manifestHandler);
httpServer.registerPathHandler("/content", contentHandler);
httpServer.start(-1);
var pm = Cc["@mozilla.org/permissionmanager;1"].getService(
Ci.nsIPermissionManager
);
var ssm = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(
Ci.nsIScriptSecurityManager
);
var uri = make_uri("http://localhost:" + httpServer.identity.primaryPort);
var principal = ssm.createContentPrincipal(uri, {});
if (pm.testPermissionFromPrincipal(principal, "offline-app") != 0) {
dump(
"Previous test failed to clear offline-app permission! Expect failures.\n"
);
}
pm.addFromPrincipal(
principal,
"offline-app",
Ci.nsIPermissionManager.ALLOW_ACTION
);
var ps = Cc["@mozilla.org/preferences-service;1"].getService(
Ci.nsIPrefBranch
);
dump(ps.getBoolPref("browser.cache.offline.enable"));
ps.setBoolPref("browser.cache.offline.enable", true);
ps.setBoolPref("browser.cache.offline.storage.enable", true);
ps.setComplexValue(
"browser.cache.offline.parent_directory",
Ci.nsIFile,
do_get_profile()
);
cacheUpdateObserver = {
observe() {
dump("got offline-cache-update-completed\n");
// offline cache update completed.
randomURI; // doing this so the lazy value gets computed
httpServer.stop(function() {
// Now shut the server down to have an error in onstartrequest
var chan = make_channel(randomURI);
var chanac = chan.QueryInterface(Ci.nsIApplicationCacheChannel);
chanac.chooseApplicationCache = true;
chan.asyncOpen(new ChannelListener(finish_test));
});
},
};
var os = Cc["@mozilla.org/observer-service;1"].getService(
Ci.nsIObserverService
);
os.addObserver(cacheUpdateObserver, "offline-cache-update-completed");
var us = Cc["@mozilla.org/offlinecacheupdate-service;1"].getService(
Ci.nsIOfflineCacheUpdateService
);
us.scheduleUpdate(
make_uri(
"http://localhost:" + httpServer.identity.primaryPort + "/manifest"
),
make_uri(
"http://localhost:" + httpServer.identity.primaryPort + "/masterEntry"
),
systemPrincipal,
null
);
do_test_pending();
}

View File

@@ -1,133 +0,0 @@
"use strict";
const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");
var httpServer = null;
// Need to randomize, because apparently no one clears our cache
var randomPath = "/error/" + Math.random();
XPCOMUtils.defineLazyGetter(this, "randomURI", function() {
return "http://localhost:" + httpServer.identity.primaryPort + randomPath;
});
var cacheUpdateObserver = null;
var systemPrincipal = Services.scriptSecurityManager.getSystemPrincipal();
function make_channel(url, callback, ctx) {
return NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true });
}
function make_uri(url) {
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
return ios.newURI(url);
}
var responseBody = "Content body";
// start the test with loading this master entry referencing the manifest
function masterEntryHandler(metadata, response) {
var masterEntryContent = "<html manifest='/manifest'></html>";
response.setHeader("Content-Type", "text/html");
response.bodyOutputStream.write(
masterEntryContent,
masterEntryContent.length
);
}
// manifest defines fallback namespace from any /error path to /content
function manifestHandler(metadata, response) {
var manifestContent = "CACHE MANIFEST\nFALLBACK:\nerror /content\n";
response.setHeader("Content-Type", "text/cache-manifest");
response.bodyOutputStream.write(manifestContent, manifestContent.length);
}
// content handler correctly returns some plain text data
function contentHandler(metadata, response) {
response.setHeader("Content-Type", "text/plain");
response.bodyOutputStream.write(responseBody, responseBody.length);
}
// error handler returns error
function errorHandler(metadata, response) {
response.setStatusLine(metadata.httpVersion, 404, "Bad request");
}
// finally check we got fallback content
function finish_test(request, buffer) {
Assert.equal(buffer, "");
httpServer.stop(do_test_finished);
}
function run_test() {
httpServer = new HttpServer();
httpServer.registerPathHandler("/masterEntry", masterEntryHandler);
httpServer.registerPathHandler("/manifest", manifestHandler);
httpServer.registerPathHandler("/content", contentHandler);
httpServer.registerPathHandler(randomPath, errorHandler);
httpServer.start(-1);
var pm = Cc["@mozilla.org/permissionmanager;1"].getService(
Ci.nsIPermissionManager
);
var ssm = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(
Ci.nsIScriptSecurityManager
);
var uri = make_uri("http://localhost:" + httpServer.identity.primaryPort);
var principal = ssm.createContentPrincipal(uri, {});
if (pm.testPermissionFromPrincipal(principal, "offline-app") != 0) {
dump(
"Previous test failed to clear offline-app permission! Expect failures.\n"
);
}
pm.addFromPrincipal(
principal,
"offline-app",
Ci.nsIPermissionManager.ALLOW_ACTION
);
var ps = Cc["@mozilla.org/preferences-service;1"].getService(
Ci.nsIPrefBranch
);
dump(ps.getBoolPref("browser.cache.offline.enable"));
ps.setBoolPref("browser.cache.offline.enable", true);
ps.setBoolPref("browser.cache.offline.storage.enable", true);
ps.setComplexValue(
"browser.cache.offline.parent_directory",
Ci.nsIFile,
do_get_profile()
);
cacheUpdateObserver = {
observe() {
dump("got offline-cache-update-completed\n");
// offline cache update completed.
var chan = make_channel(randomURI);
chan.notificationCallbacks = new ChannelEventSink(ES_ABORT_REDIRECT);
var chanac = chan.QueryInterface(Ci.nsIApplicationCacheChannel);
chanac.chooseApplicationCache = true;
chan.asyncOpen(new ChannelListener(finish_test, null, CL_EXPECT_FAILURE));
},
};
var os = Cc["@mozilla.org/observer-service;1"].getService(
Ci.nsIObserverService
);
os.addObserver(cacheUpdateObserver, "offline-cache-update-completed");
var us = Cc["@mozilla.org/offlinecacheupdate-service;1"].getService(
Ci.nsIOfflineCacheUpdateService
);
us.scheduleUpdate(
make_uri(
"http://localhost:" + httpServer.identity.primaryPort + "/manifest"
),
make_uri(
"http://localhost:" + httpServer.identity.primaryPort + "/masterEntry"
),
systemPrincipal,
null
);
do_test_pending();
}

View File

@@ -1,132 +0,0 @@
"use strict";
const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");
var httpServer = null;
// Need to randomize, because apparently no one clears our cache
var randomPath = "/error/" + Math.random();
XPCOMUtils.defineLazyGetter(this, "randomURI", function() {
return "http://localhost:" + httpServer.identity.primaryPort + randomPath;
});
var cacheUpdateObserver = null;
var systemPrincipal = Services.scriptSecurityManager.getSystemPrincipal();
function make_channel(url, callback, ctx) {
return NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true });
}
function make_uri(url) {
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
return ios.newURI(url);
}
var responseBody = "Content body";
// start the test with loading this master entry referencing the manifest
function masterEntryHandler(metadata, response) {
var masterEntryContent = "<html manifest='/manifest'></html>";
response.setHeader("Content-Type", "text/html");
response.bodyOutputStream.write(
masterEntryContent,
masterEntryContent.length
);
}
// manifest defines fallback namespace from any /error path to /content
function manifestHandler(metadata, response) {
var manifestContent = "CACHE MANIFEST\nFALLBACK:\nerror /content\n";
response.setHeader("Content-Type", "text/cache-manifest");
response.bodyOutputStream.write(manifestContent, manifestContent.length);
}
// content handler correctly returns some plain text data
function contentHandler(metadata, response) {
response.setHeader("Content-Type", "text/plain");
response.bodyOutputStream.write(responseBody, responseBody.length);
}
// error handler returns error
function errorHandler(metadata, response) {
response.setStatusLine(metadata.httpVersion, 404, "Bad request");
}
// finally check we got fallback content
function finish_test(request, buffer) {
Assert.equal(buffer, responseBody);
httpServer.stop(do_test_finished);
}
function run_test() {
httpServer = new HttpServer();
httpServer.registerPathHandler("/masterEntry", masterEntryHandler);
httpServer.registerPathHandler("/manifest", manifestHandler);
httpServer.registerPathHandler("/content", contentHandler);
httpServer.registerPathHandler(randomPath, errorHandler);
httpServer.start(-1);
var pm = Cc["@mozilla.org/permissionmanager;1"].getService(
Ci.nsIPermissionManager
);
var ssm = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(
Ci.nsIScriptSecurityManager
);
var uri = make_uri("http://localhost:" + httpServer.identity.primaryPort);
var principal = ssm.createContentPrincipal(uri, {});
if (pm.testPermissionFromPrincipal(principal, "offline-app") != 0) {
dump(
"Previous test failed to clear offline-app permission! Expect failures.\n"
);
}
pm.addFromPrincipal(
principal,
"offline-app",
Ci.nsIPermissionManager.ALLOW_ACTION
);
var ps = Cc["@mozilla.org/preferences-service;1"].getService(
Ci.nsIPrefBranch
);
dump(ps.getBoolPref("browser.cache.offline.enable"));
ps.setBoolPref("browser.cache.offline.enable", true);
ps.setBoolPref("browser.cache.offline.storage.enable", true);
ps.setComplexValue(
"browser.cache.offline.parent_directory",
Ci.nsIFile,
do_get_profile()
);
cacheUpdateObserver = {
observe() {
dump("got offline-cache-update-completed\n");
// offline cache update completed.
var chan = make_channel(randomURI);
var chanac = chan.QueryInterface(Ci.nsIApplicationCacheChannel);
chanac.chooseApplicationCache = true;
chan.asyncOpen(new ChannelListener(finish_test));
},
};
var os = Cc["@mozilla.org/observer-service;1"].getService(
Ci.nsIObserverService
);
os.addObserver(cacheUpdateObserver, "offline-cache-update-completed");
var us = Cc["@mozilla.org/offlinecacheupdate-service;1"].getService(
Ci.nsIOfflineCacheUpdateService
);
us.scheduleUpdate(
make_uri(
"http://localhost:" + httpServer.identity.primaryPort + "/manifest"
),
make_uri(
"http://localhost:" + httpServer.identity.primaryPort + "/masterEntry"
),
systemPrincipal,
null
);
do_test_pending();
}

View File

@@ -1202,7 +1202,7 @@ Http2DiskCachePushListener.onStopRequest = function(request, status) {
chan.asyncOpen(listener);
};
function continue_test_http2_disk_cache_push(status, entry, appCache) {
function continue_test_http2_disk_cache_push(status, entry) {
// TODO - store stuff in cache entry, then open an h2 channel that will push
// this, once that completes, open a channel for the cache entry we made and
// ensure it came from disk cache, not the push cache.

View File

@@ -1,165 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* This test executes nsIOfflineCacheUpdateService.scheduleAppUpdate API
* 1. preloads an app with a manifest to a custom sudir in the profile (for simplicity)
* 2. observes progress and completion of the update
* 3. checks presence of index.sql and files in the expected location
*/
"use strict";
const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");
var httpServer = null;
var cacheUpdateObserver = null;
var systemPrincipal = Services.scriptSecurityManager.getSystemPrincipal();
function make_channel(url, callback, ctx) {
return NetUtil.newChannel({
uri: url,
loadUsingSystemPrincipal: true,
});
}
function make_uri(url) {
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
return ios.newURI(url);
}
// start the test with loading this master entry referencing the manifest
function masterEntryHandler(metadata, response) {
var masterEntryContent = "<html manifest='/manifest'></html>";
response.setHeader("Content-Type", "text/html");
response.bodyOutputStream.write(
masterEntryContent,
masterEntryContent.length
);
}
// manifest defines fallback namespace from any /redirect path to /content
function manifestHandler(metadata, response) {
var manifestContent = "CACHE MANIFEST\n";
response.setHeader("Content-Type", "text/cache-manifest");
response.bodyOutputStream.write(manifestContent, manifestContent.length);
}
// finally check we got fallback content
function finish_test(customDir) {
var offlineCacheDir = customDir.clone();
offlineCacheDir.append("OfflineCache");
var indexSqlFile = offlineCacheDir.clone();
indexSqlFile.append("index.sqlite");
Assert.equal(indexSqlFile.exists(), true);
var file1 = offlineCacheDir.clone();
file1.append("2");
file1.append("E");
file1.append("2C99DE6E7289A5-0");
Assert.equal(file1.exists(), true);
var file2 = offlineCacheDir.clone();
file2.append("8");
file2.append("6");
file2.append("0B457F75198B29-0");
Assert.equal(file2.exists(), true);
// This must not throw an exception. After the update has finished
// the index file can be freely removed. This way we check this process
// is no longer keeping the file open. Check like this will probably
// work only Windows systems.
// This test could potentially randomaly fail when we start closing
// the offline cache database off the main thread. Tries in a loop
// may be a solution then.
try {
indexSqlFile.remove(false);
Assert.ok(true);
} catch (ex) {
do_throw(
"Could not remove the sqlite.index file, we still keep it open \n" +
ex +
"\n"
);
}
httpServer.stop(do_test_finished);
}
function run_test() {
httpServer = new HttpServer();
httpServer.registerPathHandler("/masterEntry", masterEntryHandler);
httpServer.registerPathHandler("/manifest", manifestHandler);
httpServer.start(4444);
var profileDir = do_get_profile();
var customDir = profileDir.clone();
customDir.append("customOfflineCacheDir" + Math.random());
var pm = Cc["@mozilla.org/permissionmanager;1"].getService(
Ci.nsIPermissionManager
);
var ssm = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(
Ci.nsIScriptSecurityManager
);
var uri = make_uri("http://localhost:4444");
var principal = ssm.createContentPrincipal(uri, {});
if (pm.testPermissionFromPrincipal(principal, "offline-app") != 0) {
dump(
"Previous test failed to clear offline-app permission! Expect failures.\n"
);
}
pm.addFromPrincipal(
principal,
"offline-app",
Ci.nsIPermissionManager.ALLOW_ACTION
);
var ps = Cc["@mozilla.org/preferences-service;1"].getService(
Ci.nsIPrefBranch
);
ps.setBoolPref("browser.cache.offline.enable", true);
ps.setBoolPref("browser.cache.offline.storage.enable", true);
// Set this pref to mimic the default browser behavior.
ps.setComplexValue(
"browser.cache.offline.parent_directory",
Ci.nsIFile,
profileDir
);
var us = Cc["@mozilla.org/offlinecacheupdate-service;1"].getService(
Ci.nsIOfflineCacheUpdateService
);
var update = us.scheduleAppUpdate(
make_uri("http://localhost:4444/manifest"),
make_uri("http://localhost:4444/masterEntry"),
systemPrincipal,
customDir
);
var expectedStates = [
Ci.nsIOfflineCacheUpdateObserver.STATE_DOWNLOADING,
Ci.nsIOfflineCacheUpdateObserver.STATE_ITEMSTARTED,
Ci.nsIOfflineCacheUpdateObserver.STATE_ITEMPROGRESS,
Ci.nsIOfflineCacheUpdateObserver.STATE_ITEMCOMPLETED,
Ci.nsIOfflineCacheUpdateObserver.STATE_FINISHED,
];
update.addObserver({
updateStateChanged(update, state) {
Assert.equal(state, expectedStates.shift());
if (state == Ci.nsIOfflineCacheUpdateObserver.STATE_FINISHED) {
finish_test(customDir);
}
},
applicationCacheAvailable(appCache) {},
});
do_test_pending();
}

View File

@@ -1,302 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/*
* This testcase performs 3 requests against the offline cache. They
* are
*
* - start_cache_nonpinned_app1()
*
* - Request nsOfflineCacheService to skip pages (4) of app1 on
* the cache storage.
*
* - The offline cache storage is empty at this monent.
*
* - start_cache_nonpinned_app2_for_partial()
*
* - Request nsOfflineCacheService to skip pages of app2 on the
* cache storage.
*
* - The offline cache storage has only enough space for one more
* additional page. Only first of pages is really in the cache.
*
* - start_cache_pinned_app2_for_success()
*
* - Request nsOfflineCacheService to skip pages of app2 on the
* cache storage.
*
* - The offline cache storage has only enough space for one
* additional page. But, this is a pinned request,
* nsOfflineCacheService will make more space for this request
* by discarding app1 (non-pinned)
*
*/
"use strict";
const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
// const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
const kNS_OFFLINECACHEUPDATESERVICE_CONTRACTID =
"@mozilla.org/offlinecacheupdate-service;1";
const kManifest1 =
"CACHE MANIFEST\n" +
"/pages/foo1\n" +
"/pages/foo2\n" +
"/pages/foo3\n" +
"/pages/foo4\n";
const kManifest2 =
"CACHE MANIFEST\n" +
"/pages/foo5\n" +
"/pages/foo6\n" +
"/pages/foo7\n" +
"/pages/foo8\n";
const kDataFileSize = 1024; // file size for each content page
const kCacheSize = kDataFileSize * 5; // total space for offline cache storage
XPCOMUtils.defineLazyGetter(this, "kHttpLocation", function() {
return "http://localhost:" + httpServer.identity.primaryPort + "/";
});
XPCOMUtils.defineLazyGetter(this, "kHttpLocation_ip", function() {
return "http://127.0.0.1:" + httpServer.identity.primaryPort + "/";
});
function manifest1_handler(metadata, response) {
info("manifest1\n");
response.setHeader("content-type", "text/cache-manifest");
response.write(kManifest1);
}
function manifest2_handler(metadata, response) {
info("manifest2\n");
response.setHeader("content-type", "text/cache-manifest");
response.write(kManifest2);
}
function app_handler(metadata, response) {
info("app_handler\n");
response.setHeader("content-type", "text/html");
response.write("<html></html>");
}
function datafile_handler(metadata, response) {
info("datafile_handler\n");
let data = "";
while (data.length < kDataFileSize) {
data =
data +
Math.random()
.toString(36)
.substring(2, 15);
}
response.setHeader("content-type", "text/plain");
response.write(data.substring(0, kDataFileSize));
}
var httpServer;
function init_profile() {
var ps = Cc["@mozilla.org/preferences-service;1"].getService(
Ci.nsIPrefBranch
);
dump(ps.getBoolPref("browser.cache.offline.enable"));
ps.setBoolPref("browser.cache.offline.enable", true);
ps.setBoolPref("browser.cache.offline.storage.enable", true);
ps.setComplexValue(
"browser.cache.offline.parent_directory",
Ci.nsIFile,
do_get_profile()
);
}
function init_http_server() {
httpServer = new HttpServer();
httpServer.registerPathHandler("/app1", app_handler);
httpServer.registerPathHandler("/app2", app_handler);
httpServer.registerPathHandler("/app1.appcache", manifest1_handler);
httpServer.registerPathHandler("/app2.appcache", manifest2_handler);
for (let i = 1; i <= 8; i++) {
httpServer.registerPathHandler("/pages/foo" + i, datafile_handler);
}
httpServer.start(-1);
}
function init_cache_capacity() {
let prefs = Cc["@mozilla.org/preferences-service;1"].getService(
Ci.nsIPrefBranch
);
prefs.setIntPref("browser.cache.offline.capacity", kCacheSize / 1024);
}
function clean_app_cache() {
evict_cache_entries("appcache");
}
function do_app_cache(manifestURL, pageURL, pinned) {
let update_service = Cc[kNS_OFFLINECACHEUPDATESERVICE_CONTRACTID].getService(
Ci.nsIOfflineCacheUpdateService
);
PermissionTestUtils.add(
manifestURL,
"pin-app",
pinned
? Ci.nsIPermissionManager.ALLOW_ACTION
: Ci.nsIPermissionManager.DENY_ACTION
);
let update = update_service.scheduleUpdate(
manifestURL,
pageURL,
Services.scriptSecurityManager.getSystemPrincipal(),
null
); /* no window */
return update;
}
function watch_update(update, stateChangeHandler, cacheAvailHandler) {
let observer = {
QueryInterface: ChromeUtils.generateQI([]),
updateStateChanged: stateChangeHandler,
applicationCacheAvailable: cacheAvailHandler,
};
update.addObserver(observer);
return update;
}
function start_and_watch_app_cache(
manifestURL,
pageURL,
pinned,
stateChangeHandler,
cacheAvailHandler
) {
let ioService = Cc["@mozilla.org/network/io-service;1"].getService(
Ci.nsIIOService
);
let update = do_app_cache(
ioService.newURI(manifestURL),
ioService.newURI(pageURL),
pinned
);
watch_update(update, stateChangeHandler, cacheAvailHandler);
return update;
}
const {
STATE_FINISHED: STATE_FINISHED,
STATE_CHECKING: STATE_CHECKING,
STATE_ERROR: STATE_ERROR,
} = Ci.nsIOfflineCacheUpdateObserver;
/*
* Start caching app1 as a non-pinned app.
*/
function start_cache_nonpinned_app() {
info("Start non-pinned App1");
start_and_watch_app_cache(
kHttpLocation + "app1.appcache",
kHttpLocation + "app1",
false,
function(update, state) {
switch (state) {
case STATE_FINISHED:
start_cache_nonpinned_app2_for_partial();
break;
case STATE_ERROR:
do_throw("App1 cache state = " + state);
break;
}
},
function(appcache) {
info("app1 avail " + appcache + "\n");
}
);
}
/*
* Start caching app2 as a non-pinned app.
*
* This cache request is supposed to be saved partially in the cache
* storage for running out of the cache storage. The offline cache
* storage can hold 5 files at most. (kDataFileSize bytes for each
* file)
*/
function start_cache_nonpinned_app2_for_partial() {
info("Start non-pinned App2 for partial\n");
start_and_watch_app_cache(
kHttpLocation_ip + "app2.appcache",
kHttpLocation_ip + "app2",
false,
function(update, state) {
switch (state) {
case STATE_FINISHED:
start_cache_pinned_app2_for_success();
break;
case STATE_ERROR:
do_throw("App2 cache state = " + state);
break;
}
},
function(appcahe) {}
);
}
/*
* Start caching app2 as a pinned app.
*
* This request use IP address (127.0.0.1) as the host name instead of
* the one used by app1. Because, app1 is also pinned when app2 is
* pinned if they have the same host name (localhost).
*/
function start_cache_pinned_app2_for_success() {
let error_count = [0];
info("Start pinned App2 for success\n");
start_and_watch_app_cache(
kHttpLocation_ip + "app2.appcache",
kHttpLocation_ip + "app2",
true,
function(update, state) {
switch (state) {
case STATE_FINISHED:
Assert.ok(error_count[0] == 0, "Do not discard app1?");
httpServer.stop(do_test_finished);
break;
case STATE_ERROR:
info("STATE_ERROR\n");
error_count[0]++;
break;
}
},
function(appcache) {
info("app2 avail " + appcache + "\n");
}
);
}
function run_test() {
if (typeof _XPCSHELL_PROCESS == "undefined" || _XPCSHELL_PROCESS != "child") {
init_profile();
init_cache_capacity();
clean_app_cache();
}
init_http_server();
start_cache_nonpinned_app();
do_test_pending();
}

View File

@@ -85,7 +85,6 @@ skip-if = true
[test_partial_response_entry_size_smart_shrink.js]
[test_304_responses.js]
[test_421.js]
[test_cacheForOfflineUse_no-store.js]
[test_307_redirect.js]
[test_NetUtil.js]
[test_URIs.js]
@@ -214,14 +213,6 @@ skip-if = socketprocess_networking # Bug 1640105
[test_event_sink.js]
[test_eviction.js]
[test_extract_charset_from_content_type.js]
[test_fallback_no-cache-entry_canceled.js]
[test_fallback_no-cache-entry_passing.js]
[test_fallback_redirect-to-different-origin_canceled.js]
[test_fallback_redirect-to-different-origin_passing.js]
[test_fallback_request-error_canceled.js]
[test_fallback_request-error_passing.js]
[test_fallback_response-error_canceled.js]
[test_fallback_response-error_passing.js]
[test_file_protocol.js]
[test_gio_protocol.js]
skip-if = (toolkit != 'gtk')
@@ -324,11 +315,6 @@ run-sequentially = node server exceptions dont replay well
[test_unescapestring.js]
[test_xmlhttprequest.js]
[test_XHR_redirects.js]
[test_pinned_app_cache.js]
[test_offlinecache_custom-directory.js]
run-sequentially = Hardcoded hash value includes port 4444.
[test_bug767025.js]
run-sequentially = Hardcoded hash value includes port 4444.
[test_bug826063.js]
[test_bug812167.js]
[test_tldservice_nextsubdomain.js]