1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/mochitest/ajax/offline/test_lowDeviceStorage.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,89 @@ 1.4 +<html xmlns="http://www.w3.org/1999/xhtml"> 1.5 +<head> 1.6 +<title>Low device storage</title> 1.7 + 1.8 +<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 +<script type="text/javascript" src="/tests/dom/tests/mochitest/ajax/offline/offlineTests.js"></script> 1.10 +<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.11 + 1.12 +<script type="text/javascript"> 1.13 + 1.14 +/** 1.15 + * This test checks that an offline cache update scheduled *after* a low device 1.16 + * storage situation appears is canceled. It basically does: 1.17 + * 1.18 + * 1. Notifies to the offline cache update service about a fake 1.19 + * low device storage situation. 1.20 + * 2. Schedules an update and observes for its notifications. 1.21 + * 3. We are supposed to recieve an error event notifying about the cancelation 1.22 + * of the update because of the low storage situation. 1.23 + * 4. Notifies to the offline cache update service that we've recovered from 1.24 + * the low storage situation. 1.25 + */ 1.26 + 1.27 +var updateService = SpecialPowers.Cc['@mozilla.org/offlinecacheupdate-service;1'] 1.28 + .getService(Ci.nsIOfflineCacheUpdateService); 1.29 + 1.30 +var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"] 1.31 + .getService(SpecialPowers.Ci.nsIObserverService); 1.32 + 1.33 +var errorReceived = false; 1.34 + 1.35 +function finish() { 1.36 + obs.notifyObservers(updateService, "disk-space-watcher", "free"); 1.37 + 1.38 + OfflineTest.teardownAndFinish(); 1.39 +} 1.40 + 1.41 +if (OfflineTest.setup()) { 1.42 + obs.notifyObservers(updateService, "disk-space-watcher", "full"); 1.43 + 1.44 + var updateObserver = { 1.45 + updateStateChanged: function (aUpdate, aState) { 1.46 + switch(aState) { 1.47 + case Ci.nsIOfflineCacheUpdateObserver.STATE_ERROR: 1.48 + aUpdate.removeObserver(this); 1.49 + errorReceived = true; 1.50 + OfflineTest.ok(true, "Expected error. Update canceled"); 1.51 + break; 1.52 + case Ci.nsIOfflineCacheUpdateObserver.STATE_FINISHED: 1.53 + OfflineTest.ok(errorReceived, 1.54 + "Finished after receiving the expected error"); 1.55 + finish(); 1.56 + break; 1.57 + case Ci.nsIOfflineCacheUpdateObserver.STATE_NOUPDATE: 1.58 + aUpdate.removeObserver(this); 1.59 + OfflineTest.ok(false, "No update"); 1.60 + finish(); 1.61 + break; 1.62 + case Ci.nsIOfflineCacheUpdateObserver.STATE_DOWNLOADING: 1.63 + case Ci.nsIOfflineCacheUpdateObserver.STATE_ITEMSTARTED: 1.64 + case Ci.nsIOfflineCacheUpdateObserver.STATE_ITEMPROGRESS: 1.65 + aUpdate.removeObserver(this); 1.66 + OfflineTest.ok(false, "The update was supposed to be canceled"); 1.67 + finish(); 1.68 + break; 1.69 + } 1.70 + }, 1.71 + applicationCacheAvailable: function() {} 1.72 + }; 1.73 + 1.74 + var manifest = "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/simpleManifest.cacheManifest"; 1.75 + var ioService = Cc["@mozilla.org/network/io-service;1"] 1.76 + .getService(Ci.nsIIOService); 1.77 + var manifestURI = ioService.newURI(manifest, null, null); 1.78 + var documentURI = ioService.newURI(document.documentURI, null, null); 1.79 + var update = updateService.scheduleUpdate(manifestURI, documentURI, window); 1.80 + update.addObserver(updateObserver, false); 1.81 +} 1.82 + 1.83 +SimpleTest.waitForExplicitFinish(); 1.84 + 1.85 +</script> 1.86 + 1.87 +</head> 1.88 + 1.89 +<body> 1.90 + 1.91 +</body> 1.92 +</html>