summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/ajax/offline/test_redirectUpdateItem.html
blob: a646b33e438f652f4f9600edd0c985bd3e64154c (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<html xmlns="http://www.w3.org/1999/xhtml" manifest="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/redirects.sjs">
<head>
<title>Entries redirection handling during update test</title>

<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/dom/tests/mochitest/ajax/offline/offlineTests.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />

<script class="testbody" type="text/javascript">

var gCurrentManifestVersion = 1;

function manifestCached()
{
  var entries = [
    ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/dynamicRedirect.sjs", false],
    ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/explicitRedirect.sjs", true],
  ];
  OfflineTest.checkCacheEntries(entries, manifestCachedContinue);
}

function manifestCachedContinue()
{
  OfflineTest.is(gCurrentManifestVersion, 1, "Cached event for manifest version one");

  // Now add one dynamic entry (now with content overriden redirect sjs)
  applicationCache.mozAdd(
    "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/dynamicRedirect.sjs");

  // Wait for the dynamic entry be added to the cache...
  OfflineTest.waitForAdd(
    "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/dynamicRedirect.sjs",
    function() {
      // ...check it is there...
      OfflineTest.checkCache(
        "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/dynamicRedirect.sjs",
        true,
        function() {
          // ...revert state of the dynamic entry on the server, now we get the redirect...
          OfflineTest.setSJSState(
            "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/dynamicRedirect.sjs",
            "");

          // ...update manifest to the new version on the server...
          OfflineTest.setSJSState(
            "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/redirects.sjs",
            "second");
          gCurrentManifestVersion = 2;

          // ...and finally invoke the cache update.
          applicationCache.update();
        });
    });
}

function manifestUpdated()
{
  switch (gCurrentManifestVersion)
  {
    case 2:
      // Check the dynamic entry was removed from the cache (because of the redirect)...
      OfflineTest.checkCache(
        "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/dynamicRedirect.sjs",
        false,
        function () {
          // ...return back redirect for the explicit entry...
          OfflineTest.setSJSState(
            "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/explicitRedirect.sjs",
            "");

          // ...update the manifest to the third version...
          OfflineTest.setSJSState(
            "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/redirects.sjs",
            "third");
          gCurrentManifestVersion = 3;

          // ...and invoke the cache update, now we must get error.
          applicationCache.update();
        });

      break;

    case 3:
      OfflineTest.ok(false, "Update didn't fail for third version of the manifest");
      finish();
      break;
  }
}

function manifestError()
{
  switch (gCurrentManifestVersion)
  {
    case 1:
      OfflineTest.ok(false, "Error not expected when caching the first version of the manifest");
      finish();
      break;
    case 2:
      OfflineTest.ok(false, "Error not expected when updating to second version of the manifest");
      finish();
      break;
    case 3:
      OfflineTest.ok(true, "Error expected when updating to third version of the manifest");
      finish();
      break;
  }
}

function finish()
{
  OfflineTest.teardownAndFinish();
}

SimpleTest.waitForExplicitFinish();
SimpleTest.requestFlakyTimeout("untriaged");

if (OfflineTest.setup()) {
  applicationCache.onerror = OfflineTest.priv(manifestError);
  applicationCache.onupdateready = OfflineTest.priv(manifestUpdated);
  applicationCache.oncached = OfflineTest.priv(manifestCached);

  // Override sjs redirects on the server, it will now return 200 OK and the content
  OfflineTest.setSJSState(
      "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/explicitRedirect.sjs",
      "on");
  OfflineTest.setSJSState(
      "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/dynamicRedirect.sjs",
      "on");
}

</script>

</head>

<body>
</body>
</html>