dom/tests/mochitest/ajax/offline/test_fallback.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_fallback.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,130 @@
     1.4 +<html xmlns="http://www.w3.org/1999/xhtml" manifest="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/fallback.cacheManifest">
     1.5 +<head>
     1.6 +<title>Fallback entry 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 class="testbody" type="text/javascript">
    1.13 +
    1.14 +/**
    1.15 + * This tests that we fall back to the correct fallback entries when loading
    1.16 + * from fallback namespaces listed in the manifest.  The test is performed twice
    1.17 + * to make sure that no cache entries are created for the nonexistent items."
    1.18 + * That would lead to a failure to fallback, as there would always be an entry
    1.19 + * in the application cache.
    1.20 + */
    1.21 +
    1.22 +var gStep = 1;
    1.23 +var gChildLoad = false;
    1.24 +var gTopWindow = null;
    1.25 +
    1.26 +function manifestUpdated()
    1.27 +{
    1.28 +  fallbackFrame.location = "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/non-existing.html";
    1.29 +  // Invokes load of fallback.html
    1.30 +}
    1.31 +
    1.32 +function onFallbackLoad(fallbackIdentification)
    1.33 +{
    1.34 +  switch (gStep)
    1.35 +  {
    1.36 +    case 001:
    1.37 +      OfflineTest.ok(!gChildLoad, "offline child not load before cache update");
    1.38 +      gChildLoad = true;
    1.39 +      // no break
    1.40 +    case 101:
    1.41 +      OfflineTest.is(fallbackIdentification, 1, "fallback for namespace1/ in step " + gStep);
    1.42 +
    1.43 +      fallbackFrame.location = "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/sub-non-existing.html";
    1.44 +      // Invokes load of fallback.html
    1.45 +      break;
    1.46 +
    1.47 +    case 002:
    1.48 +    case 102:
    1.49 +      OfflineTest.is(fallbackIdentification, 1, "fallback for namespace1/, sub namespace in name of the frame in step " + gStep);
    1.50 +
    1.51 +      fallbackFrame.location = "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/sub/non-existing.html";
    1.52 +      // Invokes load of fallback2.html
    1.53 +      break;
    1.54 +
    1.55 +    case 003:
    1.56 +    case 103:
    1.57 +      OfflineTest.is(fallbackIdentification, 2, "fallback for namespace1/sub/ in step " + gStep);
    1.58 +
    1.59 +      fallbackFrame.location = "HTTP://MOCHI.TEST:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/sub/non-existing.html";
    1.60 +      // Invokes load of fallback2.html
    1.61 +      break;
    1.62 +
    1.63 +    case 004:
    1.64 +    case 104:
    1.65 +      OfflineTest.is(fallbackIdentification, 2, "fallback for namespace1/sub/ in step " + gStep);
    1.66 +
    1.67 +      // Try opening a non-existing page as a top level document. It must
    1.68 +      // fall to fallbackTop.html that identifies it self as '100'.
    1.69 +      // Invokes load of fallbackTop.html
    1.70 +      gTopWindow = window.open("http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace2/non-existing.html");
    1.71 +
    1.72 +      break;
    1.73 +
    1.74 +    case 005:
    1.75 +      // Try all over again. This checks there are no entries for non-existing
    1.76 +      // pages created/leaked. That would prevent fallback load.
    1.77 +      gStep = 100;
    1.78 +
    1.79 +      fallbackFrame.location = "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/non-existing.html";
    1.80 +      // Invokes load of fallback1.html, again, from the start
    1.81 +      // no break
    1.82 +    case 105:
    1.83 +      OfflineTest.is(fallbackIdentification, 100, "fallback for namespace2/, invoked by a top level document " + gStep);
    1.84 +
    1.85 +      gTopWindow.close();
    1.86 +      gTopWindow = null;
    1.87 +
    1.88 +      break;
    1.89 +  }
    1.90 +
    1.91 +  if (gStep == 105) {
    1.92 +    finalize();
    1.93 +    return;
    1.94 +  }
    1.95 +
    1.96 +  ++gStep;
    1.97 +}
    1.98 +
    1.99 +
   1.100 +function finishTest()
   1.101 +{
   1.102 +  OfflineTest.teardownAndFinish();
   1.103 +}
   1.104 +
   1.105 +function finalize()
   1.106 +{
   1.107 +  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   1.108 +
   1.109 +  var entries = [
   1.110 +    ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/sub-non-existing.html", false],
   1.111 +    ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/sub/non-existing.html", false],
   1.112 +    ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace1/non-existing.html", false],
   1.113 +    ["http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/namespace2/non-existing.html", false]
   1.114 +  ];
   1.115 +  OfflineTest.checkCacheEntries(entries, finishTest);
   1.116 +}
   1.117 +
   1.118 +SimpleTest.waitForExplicitFinish();
   1.119 +
   1.120 +if (OfflineTest.setup()) {
   1.121 +  applicationCache.onerror = OfflineTest.failEvent;
   1.122 +  applicationCache.onupdateready = OfflineTest.failEvent;
   1.123 +  applicationCache.oncached = OfflineTest.priv(manifestUpdated);
   1.124 +}
   1.125 +
   1.126 +</script>
   1.127 +
   1.128 +</head>
   1.129 +
   1.130 +<body>
   1.131 +<iframe name="fallbackFrame" src=""></iframe>
   1.132 +</body>
   1.133 +</html>

mercurial