summaryrefslogtreecommitdiff
path: root/dom/tests/mochitest/ajax/offline/test_bug460353.html
blob: 683d53d6ac108aaf41e9c78bf3f0214d4b32b6fa (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
<html xmlns="http://www.w3.org/1999/xhtml" manifest="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/simpleManifest.cacheManifest">
<head>
<title>Bug 460353</title>

<!--
  This test checks that each iframe creates its own
  scope. Actually, we just check that it loads and updates
  its associated cache. There is no check that the cache is the
  expected one, there is no API to gain that information.
-->

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

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

var result = new Array();
var expectedUpdates = 3; // 2 iframes and our self

applicationCache.oncached = onUpdatePassed;
applicationCache.onnoupdate = onUpdatePassed;

SpecialPowers.pushPermissions([{'type': 'offline-app', 'allow': true, 'context': document}], init);

function onUpdatePassed()
{
  if (!(--expectedUpdates))
    SimpleTest.executeSoon(finish);
}

function init()
{
  var iframes = document.getElementsByTagName('iframe');
  iframes[0].src = "460353_iframe_nomanifest.html";
  iframes[1].src = "460353_iframe_ownmanifest.html";
  iframes[2].src = "460353_iframe_samemanifest.html";
}

function frameOnLoad(frameid, status)
{
  var obj = new Object();
  result[frameid] = obj;

  result[frameid].load = true;
  result[frameid].cacheStatus = status;
}

function frameOnUpdate(frameid, ok, status)
{
  result[frameid].update = true;
  result[frameid].updateOK = ok;
  result[frameid].cacheStatus = status;

  onUpdatePassed();
}

function finish()
{
  SimpleTest.ok(result["same"].load || false, "Frame with the same manifest loads");
  SimpleTest.ok(result["same"].update || false, "Frame with the same manifest cache update notification");
  SimpleTest.ok(result["same"].updateOK || false, "Frame with the same manifest cache update passed OK");
  SimpleTest.is(result["same"].cacheStatus || -1, 1, "Frame with the same manifest cache status was IDLE");

  SimpleTest.ok(result["diff"].load || false, "Frame with different manifest loads");
  SimpleTest.ok(result["diff"].update || false, "Frame with different manifest cache update notification");
  SimpleTest.ok(result["diff"].updateOK || false, "Frame with different manifest cache update passed OK");
  SimpleTest.is(result["diff"].cacheStatus || -1, 1, "Frame with different manifest cache status was IDLE");

  SimpleTest.ok(result["noman"].load || false, "Frame with no manifest loads");
  SimpleTest.ok(result["noman"].update == undefined, "Frame with no manifest cache update didn't notify");
  SimpleTest.ok(result["noman"].updateOK == undefined, "Frame with no manifest cache update didn't pass");
  SimpleTest.is(result["noman"].cacheStatus || -1, -1, "Frame with no manifest cache status was undefined");

  OfflineTest.waitForUpdates(function() {
    cleanCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/simpleManifest.cacheManifest");
    cleanCache("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/updatingManifest.sjs");

    SimpleTest.finish();
  });
}

function cleanCache(manifestURL)
{
  var cache = OfflineTest.getActiveCache(manifestURL);
  dump("Discarding cache for " + manifestURL + " cache=" + cache + "\n");
  if (cache)
    cache.discard();
}

SimpleTest.waitForExplicitFinish();

</script>

<body>
  <iframe></iframe>
  <iframe></iframe>
  <iframe></iframe>
</body>
</html>