dom/tests/mochitest/ajax/offline/test_changingManifest.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.

michael@0 1 <html xmlns="http://www.w3.org/1999/xhtml" manifest="http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/changingManifest.sjs">
michael@0 2 <head>
michael@0 3 <title>changing manifest test</title>
michael@0 4
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <script type="text/javascript" src="/tests/dom/tests/mochitest/ajax/offline/offlineTests.js"></script>
michael@0 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 8
michael@0 9 <script type="text/javascript">
michael@0 10
michael@0 11 var gGotChecking = false;
michael@0 12 var gGotDownloading = false;
michael@0 13
michael@0 14 var g1SecUrl = "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/changing1Sec.sjs";
michael@0 15 var g1HourUrl = "http://mochi.test:8888/tests/dom/tests/mochitest/ajax/offline/changing1Hour.sjs";
michael@0 16
michael@0 17 var gCacheContents = null;
michael@0 18
michael@0 19 function finish()
michael@0 20 {
michael@0 21 OfflineTest.teardownAndFinish();
michael@0 22 }
michael@0 23
michael@0 24 function manifestUpdatedAgain()
michael@0 25 {
michael@0 26 OfflineTest.ok(gGotChecking, "Should get a checking event on the second update");
michael@0 27 OfflineTest.ok(gGotDownloading, "Should get a downloading event on the second update");
michael@0 28
michael@0 29 // The second manifest has no NETWORK entry, but we are still
michael@0 30 // associated with the first version of the manifest, so we should
michael@0 31 // be able to access the whitelisted entry.
michael@0 32 try {
michael@0 33 var xhr = new XMLHttpRequest();
michael@0 34 xhr.open("GET", "onwhitelist.html", false);
michael@0 35 xhr.send();
michael@0 36 OfflineTest.ok(true, "Fetched from the initial cache's whitelist.");
michael@0 37 } catch (e) {
michael@0 38 OfflineTest.ok(false, "Failed to fetch from the initial cache's whitelist.");
michael@0 39 }
michael@0 40
michael@0 41 // Get the initial contents of the first two files.
michael@0 42 fetcher = new OfflineCacheContents([g1SecUrl, g1HourUrl]);
michael@0 43 fetcher.fetch(function(contents) {
michael@0 44 // Make sure the contents of the 1-second-expiration file have changed,
michael@0 45 // but that the 1-hour-expiration has not.
michael@0 46 OfflineTest.isnot(gCacheContents[g1SecUrl], contents[g1SecUrl], "1-second expiration should have changed");
michael@0 47 OfflineTest.is(gCacheContents[g1HourUrl], contents[g1HourUrl], "1-hour expiration should not have changed");
michael@0 48
michael@0 49 finish();
michael@0 50 });
michael@0 51 }
michael@0 52
michael@0 53 function failAndFinish(e) {
michael@0 54 OfflineTest.ok(false, "Unexpected event: " + e.type);
michael@0 55 finish();
michael@0 56 }
michael@0 57
michael@0 58 function manifestUpdated()
michael@0 59 {
michael@0 60 OfflineTest.ok(gGotChecking, "Should get a checking event");
michael@0 61 OfflineTest.ok(gGotDownloading, "Should get a downloading event");
michael@0 62
michael@0 63 // Replace this manifest with a new one.
michael@0 64 OfflineTest.setSJSState("changingManifest.sjs", "2");
michael@0 65
michael@0 66 // Get the initial contents of the first two files.
michael@0 67 fetcher = new OfflineCacheContents([g1SecUrl, g1HourUrl]);
michael@0 68 fetcher.fetch(function(contents) {
michael@0 69 gCacheContents = contents;
michael@0 70
michael@0 71 // Now make sure applicationCache.update() does what we expect.
michael@0 72 applicationCache.onchecking = function() {
michael@0 73 OfflineTest.is(applicationCache.status, applicationCache.CHECKING,
michael@0 74 "CHECKING state during update");
michael@0 75 gGotChecking = true;
michael@0 76 };
michael@0 77 applicationCache.ondownloading = function() {
michael@0 78 OfflineTest.is(applicationCache.status, applicationCache.DOWNLOADING,
michael@0 79 "DOWNLOADING state during update");
michael@0 80 gGotDownloading = true;
michael@0 81 };
michael@0 82
michael@0 83 applicationCache.onupdateready = OfflineTest.priv(manifestUpdatedAgain);
michael@0 84 applicationCache.onnoupdate = failAndFinish;
michael@0 85 applicationCache.oncached = failAndFinish;
michael@0 86
michael@0 87 gGotChecking = false;
michael@0 88 gGotDownloading = false;
michael@0 89
michael@0 90 // The changing versions give out a new version each second,
michael@0 91 // make sure it has time to grab a new version, and for the
michael@0 92 // 1-second cache timeout to pass.
michael@0 93 window.setTimeout("applicationCache.update()", 5000);
michael@0 94 });
michael@0 95 }
michael@0 96
michael@0 97 if (OfflineTest.setup()) {
michael@0 98 applicationCache.onerror = failAndFinish;
michael@0 99 applicationCache.onnoupdate = failAndFinish;
michael@0 100
michael@0 101 applicationCache.onchecking = function() { gGotChecking = true; };
michael@0 102 applicationCache.ondownloading = function() { gGotDownloading = true; };
michael@0 103 applicationCache.oncached = OfflineTest.priv(manifestUpdated);
michael@0 104 }
michael@0 105
michael@0 106 SimpleTest.waitForExplicitFinish();
michael@0 107
michael@0 108 </script>
michael@0 109
michael@0 110 </head>
michael@0 111
michael@0 112 <body>
michael@0 113
michael@0 114 </body>
michael@0 115 </html>

mercurial