dom/tests/mochitest/ajax/offline/test_lowDeviceStorage.html

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

michael@0 1 <html xmlns="http://www.w3.org/1999/xhtml">
michael@0 2 <head>
michael@0 3 <title>Low device storage</title>
michael@0 4
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <script type="text/javascript" src="/tests/dom/tests/mochitest/ajax/offline/offlineTests.js"></script>
michael@0 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 8
michael@0 9 <script type="text/javascript">
michael@0 10
michael@0 11 /**
michael@0 12 * This test checks that an offline cache update scheduled *after* a low device
michael@0 13 * storage situation appears is canceled. It basically does:
michael@0 14 *
michael@0 15 * 1. Notifies to the offline cache update service about a fake
michael@0 16 * low device storage situation.
michael@0 17 * 2. Schedules an update and observes for its notifications.
michael@0 18 * 3. We are supposed to recieve an error event notifying about the cancelation
michael@0 19 * of the update because of the low storage situation.
michael@0 20 * 4. Notifies to the offline cache update service that we've recovered from
michael@0 21 * the low storage situation.
michael@0 22 */
michael@0 23
michael@0 24 var updateService = SpecialPowers.Cc['@mozilla.org/offlinecacheupdate-service;1']
michael@0 25 .getService(Ci.nsIOfflineCacheUpdateService);
michael@0 26
michael@0 27 var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
michael@0 28 .getService(SpecialPowers.Ci.nsIObserverService);
michael@0 29
michael@0 30 var errorReceived = false;
michael@0 31
michael@0 32 function finish() {
michael@0 33 obs.notifyObservers(updateService, "disk-space-watcher", "free");
michael@0 34
michael@0 35 OfflineTest.teardownAndFinish();
michael@0 36 }
michael@0 37
michael@0 38 if (OfflineTest.setup()) {
michael@0 39 obs.notifyObservers(updateService, "disk-space-watcher", "full");
michael@0 40
michael@0 41 var updateObserver = {
michael@0 42 updateStateChanged: function (aUpdate, aState) {
michael@0 43 switch(aState) {
michael@0 44 case Ci.nsIOfflineCacheUpdateObserver.STATE_ERROR:
michael@0 45 aUpdate.removeObserver(this);
michael@0 46 errorReceived = true;
michael@0 47 OfflineTest.ok(true, "Expected error. Update canceled");
michael@0 48 break;
michael@0 49 case Ci.nsIOfflineCacheUpdateObserver.STATE_FINISHED:
michael@0 50 OfflineTest.ok(errorReceived,
michael@0 51 "Finished after receiving the expected error");
michael@0 52 finish();
michael@0 53 break;
michael@0 54 case Ci.nsIOfflineCacheUpdateObserver.STATE_NOUPDATE:
michael@0 55 aUpdate.removeObserver(this);
michael@0 56 OfflineTest.ok(false, "No update");
michael@0 57 finish();
michael@0 58 break;
michael@0 59 case Ci.nsIOfflineCacheUpdateObserver.STATE_DOWNLOADING:
michael@0 60 case Ci.nsIOfflineCacheUpdateObserver.STATE_ITEMSTARTED:
michael@0 61 case Ci.nsIOfflineCacheUpdateObserver.STATE_ITEMPROGRESS:
michael@0 62 aUpdate.removeObserver(this);
michael@0 63 OfflineTest.ok(false, "The update was supposed to be canceled");
michael@0 64 finish();
michael@0 65 break;
michael@0 66 }
michael@0 67 },
michael@0 68 applicationCacheAvailable: function() {}
michael@0 69 };
michael@0 70
michael@0 71 var manifest = "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/simpleManifest.cacheManifest";
michael@0 72 var ioService = Cc["@mozilla.org/network/io-service;1"]
michael@0 73 .getService(Ci.nsIIOService);
michael@0 74 var manifestURI = ioService.newURI(manifest, null, null);
michael@0 75 var documentURI = ioService.newURI(document.documentURI, null, null);
michael@0 76 var update = updateService.scheduleUpdate(manifestURI, documentURI, window);
michael@0 77 update.addObserver(updateObserver, false);
michael@0 78 }
michael@0 79
michael@0 80 SimpleTest.waitForExplicitFinish();
michael@0 81
michael@0 82 </script>
michael@0 83
michael@0 84 </head>
michael@0 85
michael@0 86 <body>
michael@0 87
michael@0 88 </body>
michael@0 89 </html>

mercurial