diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/tests/mochitest/ajax/offline/test_lowDeviceStorage.html | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | uxp-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/tests/mochitest/ajax/offline/test_lowDeviceStorage.html')
-rw-r--r-- | dom/tests/mochitest/ajax/offline/test_lowDeviceStorage.html | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/dom/tests/mochitest/ajax/offline/test_lowDeviceStorage.html b/dom/tests/mochitest/ajax/offline/test_lowDeviceStorage.html new file mode 100644 index 0000000000..d03ef5a12f --- /dev/null +++ b/dom/tests/mochitest/ajax/offline/test_lowDeviceStorage.html @@ -0,0 +1,91 @@ +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<title>Low device storage</title> + +<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> +<script type="text/javascript" src="/tests/dom/tests/mochitest/ajax/offline/offlineTests.js"></script> +<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> + +<script type="text/javascript"> + +/** + * This test checks that an offline cache update scheduled *after* a low device + * storage situation appears is canceled. It basically does: + * + * 1. Notifies to the offline cache update service about a fake + * low device storage situation. + * 2. Schedules an update and observes for its notifications. + * 3. We are supposed to receive an error event notifying about the cancelation + * of the update because of the low storage situation. + * 4. Notifies to the offline cache update service that we've recovered from + * the low storage situation. + */ + +var updateService = SpecialPowers.Cc['@mozilla.org/offlinecacheupdate-service;1'] + .getService(Ci.nsIOfflineCacheUpdateService); + +var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"] + .getService(SpecialPowers.Ci.nsIObserverService); + +var errorReceived = false; + +var systemPrincipal = SpecialPowers.Services.scriptSecurityManager.getSystemPrincipal(); + +function finish() { + obs.notifyObservers(updateService, "disk-space-watcher", "free"); + + OfflineTest.teardownAndFinish(); +} + +if (OfflineTest.setup()) { + obs.notifyObservers(updateService, "disk-space-watcher", "full"); + + var updateObserver = { + updateStateChanged: function (aUpdate, aState) { + switch(aState) { + case Ci.nsIOfflineCacheUpdateObserver.STATE_ERROR: + errorReceived = true; + OfflineTest.ok(true, "Expected error. Update canceled"); + break; + case Ci.nsIOfflineCacheUpdateObserver.STATE_FINISHED: + aUpdate.removeObserver(this); + OfflineTest.ok(errorReceived, + "Finished after receiving the expected error"); + finish(); + break; + case Ci.nsIOfflineCacheUpdateObserver.STATE_NOUPDATE: + aUpdate.removeObserver(this); + OfflineTest.ok(false, "No update"); + finish(); + break; + case Ci.nsIOfflineCacheUpdateObserver.STATE_DOWNLOADING: + case Ci.nsIOfflineCacheUpdateObserver.STATE_ITEMSTARTED: + case Ci.nsIOfflineCacheUpdateObserver.STATE_ITEMPROGRESS: + aUpdate.removeObserver(this); + OfflineTest.ok(false, "The update was supposed to be canceled"); + finish(); + break; + } + }, + applicationCacheAvailable: function() {} + }; + + var manifest = "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/simpleManifest.cacheManifest"; + var ioService = Cc["@mozilla.org/network/io-service;1"] + .getService(Ci.nsIIOService); + var manifestURI = ioService.newURI(manifest, null, null); + var documentURI = ioService.newURI(document.documentURI, null, null); + var update = updateService.scheduleUpdate(manifestURI, documentURI, systemPrincipal, window); + update.addObserver(updateObserver, false); +} + +SimpleTest.waitForExplicitFinish(); + +</script> + +</head> + +<body> + +</body> +</html> |