dom/tests/mochitest/ajax/offline/test_refetchManifest.html

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 <html xmlns="http://www.w3.org/1999/xhtml" manifest="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/changingManifest.sjs">
     2 <head>
     3 <title>refetch manifest test</title>
     5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     6 <script type="text/javascript" src="/tests/dom/tests/mochitest/ajax/offline/offlineTests.js"></script>
     8 <script type="text/javascript">
    10 function finish()
    11 {
    12   OfflineTest.teardownAndFinish();
    13 }
    15 function failAndFinish(e)
    16 {
    17   OfflineTest.ok(false, "Unexpected event: " + e.type);
    18   finish();
    19 }
    21 function manifestUpdated()
    22 {
    23   // Replace this manifest with a new one.
    25   // XXX: After this put, we will no longer have Cache-Control:
    26   // no-cache on the manifest, so future updates will just use the
    27   // cached manifest.
    29   // Get the initial contents of the first two files.
    30   fetcher = new OfflineCacheContents([g1SecUrl, g1HourUrl]);
    31   fetcher.fetch(function(contents) {
    32     gCacheContents = contents;
    34     // Now make sure applicationCache.update() does what we expect.
    35     applicationCache.onupdateready = OfflineTest.priv(manifestUpdatedAgain);
    36     applicationCache.onnoupdate = failAndFinish;
    37     applicationCache.oncached = failAndFinish;
    39     gGotChecking = false;
    40     gGotDownloading = false;
    42     // The changing versions give out a new version each second,
    43     // make sure it has time to grab a new version, and for the
    44     // 1-second cache timeout to pass.
    45     window.setTimeout("applicationCache.update()", 5000);
    46   });
    47 }
    49 function replaceManifest()
    50 {
    51   // If we replace the manifest after a downloading event, the update
    52   // should fail when it revalidates the manifest at the end of the update.
    53   OfflineTest.setSJSState("changingManifest.sjs", "2");
    54 }
    56 function cached()
    57 {
    58   OfflineTest.ok(true, "Got the expected cached event.");
    59   finish();
    60 }
    62 function gotError()
    63 {
    64   OfflineTest.ok(true, "Got the expected error event.");
    66   // Now this update will be rescheduled, and it should succeed.
    67   applicationCache.onerror = failAndFinish;
    68   applicationCache.oncached = cached;
    69 }
    71 if (OfflineTest.setup()) {
    72   applicationCache.onerror = gotError;
    73   applicationCache.onnoupdate = failAndFinish;
    75   applicationCache.ondownloading = replaceManifest;
    76   applicationCache.oncached = failAndFinish;
    77 }
    79 SimpleTest.waitForExplicitFinish();
    81 </script>
    83 </head>
    85 <body>
    87 </body>
    88 </html>

mercurial