Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <html xmlns="http://www.w3.org/1999/xhtml" manifest="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/simpleManifest.cacheManifest"> |
michael@0 | 2 | <head> |
michael@0 | 3 | <title>simple manifest test</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 | var gGotChecking = false; |
michael@0 | 12 | var gGotDownloading = false; |
michael@0 | 13 | |
michael@0 | 14 | ok(applicationCache.mozItems.length == 0, |
michael@0 | 15 | "applicationCache.mozItems should be available and empty before associating with a cache."); |
michael@0 | 16 | |
michael@0 | 17 | function addFinished() |
michael@0 | 18 | { |
michael@0 | 19 | OfflineTest.ok(applicationCache.mozLength == 1, "applicationCache should have one dynamic entry (deprecated API)"); |
michael@0 | 20 | OfflineTest.ok(applicationCache.mozItem(0) == "http://mochi.test:8888/tests/SimpleTest/EventUtils.js", |
michael@0 | 21 | "applicationCache's dynamic entry should be the one we expect (deprecated API)"); |
michael@0 | 22 | |
michael@0 | 23 | OfflineTest.ok(applicationCache.mozItems.length == 1, "applicationCache should have one dynamic entry"); |
michael@0 | 24 | OfflineTest.ok(applicationCache.mozItems[0] == "http://mochi.test:8888/tests/SimpleTest/EventUtils.js", |
michael@0 | 25 | "applicationCache's dynamic entry should be the one we expect"); |
michael@0 | 26 | |
michael@0 | 27 | OfflineTest.ok(applicationCache.mozHasItem("http://mochi.test:8888/tests/SimpleTest/EventUtils.js"), |
michael@0 | 28 | "applicationCache.mozHasItem() should see the dynamic entry"); |
michael@0 | 29 | |
michael@0 | 30 | // Check that the entry was added successfully |
michael@0 | 31 | OfflineTest.checkCache("http://mochi.test:8888/tests/SimpleTest/EventUtils.js", |
michael@0 | 32 | true, |
michael@0 | 33 | removeItem); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | function removeItem() |
michael@0 | 37 | { |
michael@0 | 38 | // Now test that removes work |
michael@0 | 39 | applicationCache.mozRemove("http://mochi.test:8888/tests/SimpleTest/EventUtils.js"); |
michael@0 | 40 | |
michael@0 | 41 | OfflineTest.ok(applicationCache.mozLength == 0, |
michael@0 | 42 | "applicationCache should have no dynamic entries (deprecated API)"); |
michael@0 | 43 | OfflineTest.ok(applicationCache.mozItems.length == 0, |
michael@0 | 44 | "applicationCache should have no dynamic entries"); |
michael@0 | 45 | OfflineTest.ok(!applicationCache.mozHasItem("http://mochi.test:8888/tests/SimpleTest/EventUtils.js"), |
michael@0 | 46 | "applicationCache.mozHasItem() should not see the removed dynamic entry"); |
michael@0 | 47 | |
michael@0 | 48 | OfflineTest.checkCache("http://mochi.test:8888/tests/SimpleTest/EventUtils.js", |
michael@0 | 49 | false, |
michael@0 | 50 | function() { |
michael@0 | 51 | // We're done |
michael@0 | 52 | OfflineTest.teardownAndFinish(); |
michael@0 | 53 | }); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | function manifestUpdated() |
michael@0 | 57 | { |
michael@0 | 58 | OfflineTest.ok(gGotChecking, "Should get a checking event"); |
michael@0 | 59 | OfflineTest.ok(gGotDownloading, "Should get a downloading event"); |
michael@0 | 60 | |
michael@0 | 61 | OfflineTest.is(applicationCache.status, 1, "Cache status should be 1 (CACHED)"); |
michael@0 | 62 | |
michael@0 | 63 | var entries = [ |
michael@0 | 64 | // The manifest itself should be in the cache |
michael@0 | 65 | ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/simpleManifest.cacheManifest", true], |
michael@0 | 66 | |
michael@0 | 67 | // The document that requested the manifest should be in the cache |
michael@0 | 68 | [window.location.href, true], |
michael@0 | 69 | |
michael@0 | 70 | // The entries from the manifest should be in the cache |
michael@0 | 71 | ["http://mochi.test:8888/tests/SimpleTest/SimpleTest.js", true], |
michael@0 | 72 | ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/offlineTests.js", true], |
michael@0 | 73 | |
michael@0 | 74 | // The bad entries from the manifest should not be in the cache |
michael@0 | 75 | ["bad:/uri/invalid", false] |
michael@0 | 76 | ]; |
michael@0 | 77 | OfflineTest.checkCacheEntries( |
michael@0 | 78 | entries, |
michael@0 | 79 | function() { |
michael@0 | 80 | try { |
michael@0 | 81 | applicationCache.swapCache(); |
michael@0 | 82 | OfflineTest.ok(false, "application.swapCache() should fail after initial update."); |
michael@0 | 83 | } catch(ex) { |
michael@0 | 84 | OfflineTest.ok(true, "application.swapCache() should fail after initial update."); |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | // XXX: make sure that the previous version went away after the swapCache(). |
michael@0 | 88 | |
michael@0 | 89 | // Now add a file using the applicationCache API |
michael@0 | 90 | applicationCache.mozAdd("http://mochi.test:8888/tests/SimpleTest/EventUtils.js"); |
michael@0 | 91 | |
michael@0 | 92 | // Wait for the add() to be downloaded |
michael@0 | 93 | OfflineTest.waitForAdd("http://mochi.test:8888/tests/SimpleTest/EventUtils.js", |
michael@0 | 94 | OfflineTest.priv(addFinished)); |
michael@0 | 95 | }); |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | if (OfflineTest.setup()) { |
michael@0 | 99 | OfflineTest.ok(applicationCache instanceof EventTarget, |
michael@0 | 100 | "applicationCache should be an event target"); |
michael@0 | 101 | |
michael@0 | 102 | applicationCache.onerror = OfflineTest.failEvent; |
michael@0 | 103 | |
michael@0 | 104 | applicationCache.addEventListener("checking", function() { |
michael@0 | 105 | // We should get the "checking" event during an initial update, |
michael@0 | 106 | // but until we are associated it will not affect applicationCache.status |
michael@0 | 107 | OfflineTest.is(applicationCache.status, applicationCache.UNCACHED, |
michael@0 | 108 | "CHECKING state during initial update"); |
michael@0 | 109 | gGotChecking = true; |
michael@0 | 110 | }, true); |
michael@0 | 111 | applicationCache.ondownloading = function() { |
michael@0 | 112 | // We should get the "downloading" event during an initial update, |
michael@0 | 113 | // but until we are associated it will not affect applicationCache.status |
michael@0 | 114 | OfflineTest.is(applicationCache.status, applicationCache.UNCACHED, |
michael@0 | 115 | "DOWNLOADING state during initial update") |
michael@0 | 116 | gGotDownloading = true; }; |
michael@0 | 117 | applicationCache.oncached = OfflineTest.priv(manifestUpdated); |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 121 | |
michael@0 | 122 | </script> |
michael@0 | 123 | |
michael@0 | 124 | </head> |
michael@0 | 125 | |
michael@0 | 126 | <body> |
michael@0 | 127 | |
michael@0 | 128 | </body> |
michael@0 | 129 | </html> |