summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/ajax/offline/obsolete.html
blob: 5f0106d3af2a4703a97fd5b73151323873b0315c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<html manifest="obsoletingManifest.sjs">
<head>
<title>obsolete test</title>
<script type="text/javascript">

function obsolete(evt)
{
  window.opener.ok(true, "Got an 'obsolete' event");

  // The cache status is switched immediately AFTER sending the event,
  // make sure that it isn't OBSOLETE yet...
  window.opener.isnot(applicationCache.status, 5,
                      "Status should not yet be 5 (obsolete)");

  // But check that it is after the event is fired.
  setTimeout(function(){
    window.opener.is(applicationCache.status, 5,
                     "Status should be 5 (obsolete)");

    // Now swapCache(), and our new status should be UNCACHED.
    applicationCache.swapCache();
    window.opener.is(applicationCache.status, 0,
                     "Status should be 0 (UNCACHED)");
    window.opener.finish();
  }, 0);
}

function fail(evt)
{
  window.opener.ok(false, "Got an unexpected event: " + evt.type)
  window.opener.finish();
}

applicationCache.oncached = function() {
  // ok, we've successfully loaded from the initial cache.
  try {
    applicationCache.swapCache();
    window.opener.todo(false, "We shouldn't have to swapCache in the oncached handler (bug 443023)");
  } catch(e) {
  }

  // Now delete the manifest and refresh, we should get an "obsolete" message.
  applicationCache.oncached = fail;
  applicationCache.onupdateready = fail;
  applicationCache.onnoupdate = fail;
  applicationCache.onerror = fail;
  applicationCache.onobsolete = obsolete;

  // Make the obsoleting.sjs return 404 NOT FOUND code
  var req = new XMLHttpRequest();
  req.open("GET", "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/obsoletingManifest.sjs?state=");
  var channel = SpecialPowers.wrap(req).channel
    .QueryInterface(SpecialPowers.Ci.nsIApplicationCacheChannel);
  channel.chooseApplicationCache = false;
  channel.inheritApplicationCache = false;
  req.send("");
  req.onreadystatechange = function() {
    if (req.readyState == 4) {
      applicationCache.update();
    }
  }
}

</script>
</head>

<body>
<h1></h1>
</body> </html>