dom/tests/mochitest/ajax/offline/test_changingManifest.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_changingManifest.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,115 @@
     1.4 +<html xmlns="http://www.w3.org/1999/xhtml" manifest="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/changingManifest.sjs">
     1.5 +<head>
     1.6 +<title>changing 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 +var g1SecUrl =  "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/changing1Sec.sjs";
    1.18 +var g1HourUrl = "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/changing1Hour.sjs";
    1.19 +
    1.20 +var gCacheContents = null;
    1.21 +
    1.22 +function finish()
    1.23 +{
    1.24 +  OfflineTest.teardownAndFinish();
    1.25 +}
    1.26 +
    1.27 +function manifestUpdatedAgain()
    1.28 +{
    1.29 +  OfflineTest.ok(gGotChecking, "Should get a checking event on the second update");
    1.30 +  OfflineTest.ok(gGotDownloading, "Should get a downloading event on the second update");
    1.31 +
    1.32 +  // The second manifest has no NETWORK entry, but we are still
    1.33 +  // associated with the first version of the manifest, so we should
    1.34 +  // be able to access the whitelisted entry.
    1.35 +  try {
    1.36 +    var xhr = new XMLHttpRequest();
    1.37 +    xhr.open("GET", "onwhitelist.html", false);
    1.38 +    xhr.send();
    1.39 +    OfflineTest.ok(true, "Fetched from the initial cache's whitelist.");
    1.40 +  } catch (e) {
    1.41 +    OfflineTest.ok(false, "Failed to fetch from the initial cache's whitelist.");
    1.42 +  }
    1.43 +
    1.44 +  // Get the initial contents of the first two files.
    1.45 +  fetcher = new OfflineCacheContents([g1SecUrl, g1HourUrl]);
    1.46 +  fetcher.fetch(function(contents) {
    1.47 +    // Make sure the contents of the 1-second-expiration file have changed,
    1.48 +    // but that the 1-hour-expiration has not.
    1.49 +    OfflineTest.isnot(gCacheContents[g1SecUrl], contents[g1SecUrl], "1-second expiration should have changed");
    1.50 +    OfflineTest.is(gCacheContents[g1HourUrl], contents[g1HourUrl], "1-hour expiration should not have changed");
    1.51 +
    1.52 +    finish();
    1.53 +  });
    1.54 +}
    1.55 +
    1.56 +function failAndFinish(e) {
    1.57 +  OfflineTest.ok(false, "Unexpected event: " + e.type);
    1.58 +  finish();
    1.59 +}
    1.60 +
    1.61 +function manifestUpdated()
    1.62 +{
    1.63 +  OfflineTest.ok(gGotChecking, "Should get a checking event");
    1.64 +  OfflineTest.ok(gGotDownloading, "Should get a downloading event");
    1.65 +
    1.66 +  // Replace this manifest with a new one.
    1.67 +  OfflineTest.setSJSState("changingManifest.sjs", "2");
    1.68 +
    1.69 +  // Get the initial contents of the first two files.
    1.70 +  fetcher = new OfflineCacheContents([g1SecUrl, g1HourUrl]);
    1.71 +  fetcher.fetch(function(contents) {
    1.72 +    gCacheContents = contents;
    1.73 +
    1.74 +    // Now make sure applicationCache.update() does what we expect.
    1.75 +    applicationCache.onchecking = function() {
    1.76 +      OfflineTest.is(applicationCache.status, applicationCache.CHECKING,
    1.77 +                     "CHECKING state during update");
    1.78 +      gGotChecking = true;
    1.79 +    };
    1.80 +    applicationCache.ondownloading = function() {
    1.81 +      OfflineTest.is(applicationCache.status, applicationCache.DOWNLOADING,
    1.82 +                     "DOWNLOADING state during update");
    1.83 +      gGotDownloading = true;
    1.84 +    };
    1.85 +
    1.86 +    applicationCache.onupdateready = OfflineTest.priv(manifestUpdatedAgain);
    1.87 +    applicationCache.onnoupdate = failAndFinish;
    1.88 +    applicationCache.oncached = failAndFinish;
    1.89 +
    1.90 +    gGotChecking = false;
    1.91 +    gGotDownloading = false;
    1.92 +
    1.93 +    // The changing versions give out a new version each second,
    1.94 +    // make sure it has time to grab a new version, and for the
    1.95 +    // 1-second cache timeout to pass.
    1.96 +    window.setTimeout("applicationCache.update()", 5000);
    1.97 +  });
    1.98 +}
    1.99 +
   1.100 +if (OfflineTest.setup()) {
   1.101 +  applicationCache.onerror = failAndFinish;
   1.102 +  applicationCache.onnoupdate = failAndFinish;
   1.103 +
   1.104 +  applicationCache.onchecking = function() { gGotChecking = true; };
   1.105 +  applicationCache.ondownloading = function() { gGotDownloading = true; };
   1.106 +  applicationCache.oncached = OfflineTest.priv(manifestUpdated);
   1.107 +}
   1.108 +
   1.109 +SimpleTest.waitForExplicitFinish();
   1.110 +
   1.111 +</script>
   1.112 +
   1.113 +</head>
   1.114 +
   1.115 +<body>
   1.116 +
   1.117 +</body>
   1.118 +</html>

mercurial