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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/ajax/offline/test_simpleManifest.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,129 @@
     1.4 +<html xmlns="http://www.w3.org/1999/xhtml" manifest="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/simpleManifest.cacheManifest">
     1.5 +<head>
     1.6 +<title>simple manifest test</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 +var gGotChecking = false;
    1.15 +var gGotDownloading = false;
    1.16 +
    1.17 +ok(applicationCache.mozItems.length == 0,
    1.18 +   "applicationCache.mozItems should be available and empty before associating with a cache.");
    1.19 +
    1.20 +function addFinished()
    1.21 +{
    1.22 +  OfflineTest.ok(applicationCache.mozLength == 1, "applicationCache should have one dynamic entry (deprecated API)");
    1.23 +  OfflineTest.ok(applicationCache.mozItem(0) == "http://mochi.test:8888/tests/SimpleTest/EventUtils.js",
    1.24 +    "applicationCache's dynamic entry should be the one we expect (deprecated API)");
    1.25 +
    1.26 +  OfflineTest.ok(applicationCache.mozItems.length == 1, "applicationCache should have one dynamic entry");
    1.27 +  OfflineTest.ok(applicationCache.mozItems[0] == "http://mochi.test:8888/tests/SimpleTest/EventUtils.js",
    1.28 +    "applicationCache's dynamic entry should be the one we expect");
    1.29 +
    1.30 +  OfflineTest.ok(applicationCache.mozHasItem("http://mochi.test:8888/tests/SimpleTest/EventUtils.js"),
    1.31 +                 "applicationCache.mozHasItem() should see the dynamic entry");
    1.32 +
    1.33 +  // Check that the entry was added successfully
    1.34 +  OfflineTest.checkCache("http://mochi.test:8888/tests/SimpleTest/EventUtils.js",
    1.35 +                         true,
    1.36 +                         removeItem);
    1.37 +}
    1.38 +
    1.39 +function removeItem()
    1.40 +{
    1.41 +  // Now test that removes work
    1.42 +  applicationCache.mozRemove("http://mochi.test:8888/tests/SimpleTest/EventUtils.js");
    1.43 +
    1.44 +  OfflineTest.ok(applicationCache.mozLength == 0,
    1.45 +                 "applicationCache should have no dynamic entries (deprecated API)");
    1.46 +  OfflineTest.ok(applicationCache.mozItems.length == 0,
    1.47 +                 "applicationCache should have no dynamic entries");
    1.48 +  OfflineTest.ok(!applicationCache.mozHasItem("http://mochi.test:8888/tests/SimpleTest/EventUtils.js"),
    1.49 +                 "applicationCache.mozHasItem() should not see the removed dynamic entry");
    1.50 +
    1.51 +  OfflineTest.checkCache("http://mochi.test:8888/tests/SimpleTest/EventUtils.js",
    1.52 +                         false,
    1.53 +                         function() {
    1.54 +                           // We're done
    1.55 +                           OfflineTest.teardownAndFinish();
    1.56 +                         });
    1.57 +}
    1.58 +
    1.59 +function manifestUpdated()
    1.60 +{
    1.61 +  OfflineTest.ok(gGotChecking, "Should get a checking event");
    1.62 +  OfflineTest.ok(gGotDownloading, "Should get a downloading event");
    1.63 +
    1.64 +  OfflineTest.is(applicationCache.status, 1, "Cache status should be 1 (CACHED)");
    1.65 +
    1.66 +  var entries = [
    1.67 +    // The manifest itself should be in the cache
    1.68 +    ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/simpleManifest.cacheManifest", true],
    1.69 +
    1.70 +    // The document that requested the manifest should be in the cache
    1.71 +    [window.location.href, true],
    1.72 +
    1.73 +    // The entries from the manifest should be in the cache
    1.74 +    ["http://mochi.test:8888/tests/SimpleTest/SimpleTest.js", true],
    1.75 +    ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/offlineTests.js", true],
    1.76 +
    1.77 +    // The bad entries from the manifest should not be in the cache
    1.78 +    ["bad:/uri/invalid", false]
    1.79 +  ];
    1.80 +  OfflineTest.checkCacheEntries(
    1.81 +    entries,
    1.82 +    function() {
    1.83 +      try {
    1.84 +        applicationCache.swapCache();
    1.85 +        OfflineTest.ok(false, "application.swapCache() should fail after initial update.");
    1.86 +      } catch(ex) {
    1.87 +        OfflineTest.ok(true, "application.swapCache() should fail after initial update.");
    1.88 +      }
    1.89 +
    1.90 +      // XXX: make sure that the previous version went away after the swapCache().
    1.91 +
    1.92 +      // Now add a file using the applicationCache API
    1.93 +      applicationCache.mozAdd("http://mochi.test:8888/tests/SimpleTest/EventUtils.js");
    1.94 +
    1.95 +      // Wait for the add() to be downloaded
    1.96 +      OfflineTest.waitForAdd("http://mochi.test:8888/tests/SimpleTest/EventUtils.js",
    1.97 +                             OfflineTest.priv(addFinished));
    1.98 +    });
    1.99 +}
   1.100 +
   1.101 +if (OfflineTest.setup()) {
   1.102 +  OfflineTest.ok(applicationCache instanceof EventTarget,
   1.103 +                 "applicationCache should be an event target");
   1.104 +
   1.105 +  applicationCache.onerror = OfflineTest.failEvent;
   1.106 +
   1.107 +  applicationCache.addEventListener("checking", function() {
   1.108 +    // We should get the "checking" event during an initial update,
   1.109 +    // but until we are associated it will not affect applicationCache.status
   1.110 +    OfflineTest.is(applicationCache.status, applicationCache.UNCACHED,
   1.111 +                   "CHECKING state during initial update");
   1.112 +    gGotChecking = true;
   1.113 +    }, true);
   1.114 +  applicationCache.ondownloading = function() {
   1.115 +    // We should get the "downloading" event during an initial update,
   1.116 +    // but until we are associated it will not affect applicationCache.status
   1.117 +    OfflineTest.is(applicationCache.status, applicationCache.UNCACHED,
   1.118 +                   "DOWNLOADING state during initial update")
   1.119 +    gGotDownloading = true; };
   1.120 +  applicationCache.oncached = OfflineTest.priv(manifestUpdated);
   1.121 +}
   1.122 +
   1.123 +SimpleTest.waitForExplicitFinish();
   1.124 +
   1.125 +</script>
   1.126 +
   1.127 +</head>
   1.128 +
   1.129 +<body>
   1.130 +
   1.131 +</body>
   1.132 +</html>

mercurial