dom/tests/mochitest/ajax/offline/foreign2.html
author Honza Bambas <honzab.moz@firemni.cz>
Tue, 31 Jul 2012 02:36:00 -0400
changeset 114335 293dee8a857a56ea4650835ac067e91787694373
parent 114206 1f7c4fae49c0d80075e7b0380c4b841a5ed30ab0
child 155552 e9139204213762205ba80699940b7dd4f98c9122
permissions -rw-r--r--
Bug 756717 - Implement 'appcache jar' for apps, r=tlee+jduell

<html xmlns="http://www.w3.org/1999/xhtml" manifest="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/foreign2.cacheManifest">
<head>
<title>Foreign page 2</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">

function manifestUpdated()
{
  var appCacheService = SpecialPowers.Components.classes["@mozilla.org/network/application-cache-service;1"]
    .getService(SpecialPowers.Ci.nsIApplicationCacheService);

  var foreign2cache = appCacheService.chooseApplicationCache(
    "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/foreign2.html", OfflineTest.loadContext());

  OfflineTest.ok(foreign2cache, "Foreign 2 cache present, chosen for foreign2.html");
  OfflineTest.is(foreign2cache.manifestURI.asciiSpec, "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/foreign2.cacheManifest")

  var foreign1cache = OfflineTest.getActiveCache(
    "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/foreign1.cacheManifest");
  OfflineTest.ok(foreign1cache, "Foreign 1 cache loaded");
  foreign1cache.discard();

  OfflineTest.teardown();
  OfflineTest.finish();
}

function onLoaded()
{
  var appCacheService = SpecialPowers.Components.classes["@mozilla.org/network/application-cache-service;1"]
    .getService(SpecialPowers.Ci.nsIApplicationCacheService);

  var foreign1cache = OfflineTest.getActiveCache(
    "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/foreign1.cacheManifest");
  OfflineTest.ok(foreign1cache, "Foreign 1 cache loaded");

  var foreign2cache = OfflineTest.getActiveCache(
    "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/foreign2.cacheManifest");
  OfflineTest.ok(!foreign2cache, "Foreign 2 cache not present");

  foreign1cache = appCacheService.chooseApplicationCache(
    "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/foreign2.html", OfflineTest.loadContext());
  OfflineTest.ok(!foreign1cache, "foreign2.html not chosen from foreign1 cache");

  try
  {
    OfflineTest.ok(applicationCache.status == SpecialPowers.Ci.nsIDOMOfflineResourceList.UNCACHED,
        "there is no associated application cache");
  }
  catch (ex)
  {
    OfflineTest.ok(false, "applicationCache.status must not throw an exception");
  }
}

if (OfflineTest.setup())
{
  applicationCache.onerror = OfflineTest.failEvent;
  applicationCache.onupdateready = OfflineTest.failEvent;
  applicationCache.onnoupdate = OfflineTest.failEvent;
  applicationCache.oncached = OfflineTest.priv(manifestUpdated);
}

</script>

</head>

<body onload="OfflineTest.priv(onLoaded)();">
</body>
</html>