|
1 <html xmlns="http://www.w3.org/1999/xhtml"> |
|
2 <head> |
|
3 <title>Low device storage</title> |
|
4 |
|
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" /> |
|
8 |
|
9 <script type="text/javascript"> |
|
10 |
|
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 */ |
|
23 |
|
24 var updateService = SpecialPowers.Cc['@mozilla.org/offlinecacheupdate-service;1'] |
|
25 .getService(Ci.nsIOfflineCacheUpdateService); |
|
26 |
|
27 var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"] |
|
28 .getService(SpecialPowers.Ci.nsIObserverService); |
|
29 |
|
30 var errorReceived = false; |
|
31 |
|
32 function finish() { |
|
33 obs.notifyObservers(updateService, "disk-space-watcher", "free"); |
|
34 |
|
35 OfflineTest.teardownAndFinish(); |
|
36 } |
|
37 |
|
38 if (OfflineTest.setup()) { |
|
39 obs.notifyObservers(updateService, "disk-space-watcher", "full"); |
|
40 |
|
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 }; |
|
70 |
|
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 } |
|
79 |
|
80 SimpleTest.waitForExplicitFinish(); |
|
81 |
|
82 </script> |
|
83 |
|
84 </head> |
|
85 |
|
86 <body> |
|
87 |
|
88 </body> |
|
89 </html> |