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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial