Tue, 06 Jan 2015 21:39:09 +0100
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 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=479863 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 479863</title> |
michael@0 | 8 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 10 | </head> |
michael@0 | 11 | <body> |
michael@0 | 12 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=479863">Mozilla Bug 479863</a> |
michael@0 | 13 | <p id="display"></p> |
michael@0 | 14 | <div id="content" style="display: none"> |
michael@0 | 15 | |
michael@0 | 16 | </div> |
michael@0 | 17 | |
michael@0 | 18 | <video id='v1'></video> |
michael@0 | 19 | <video id='v2' preload="auto"></video> |
michael@0 | 20 | <video id='v3' autoplay></video> |
michael@0 | 21 | <video id='v4'></video> |
michael@0 | 22 | <video id='v5'></video> |
michael@0 | 23 | <video id='v6'></video> |
michael@0 | 24 | |
michael@0 | 25 | <pre id="test"> |
michael@0 | 26 | <script type="application/javascript"> |
michael@0 | 27 | function is() {} |
michael@0 | 28 | |
michael@0 | 29 | var suspendCount = {}; |
michael@0 | 30 | var expectedSuspendCount = {v1:2, v2:1, v3:1, v4:2, v5:2, v6:2}; |
michael@0 | 31 | var totalSuspendCount = 0; |
michael@0 | 32 | for (var i = 0; i < expectedSuspendCount.length; ++i) { |
michael@0 | 33 | totalSuspendCount += expectedSuspendCount[i]; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | function suspended(event) { |
michael@0 | 37 | // If the element suspends the download, it should not then be able to |
michael@0 | 38 | // complete it, so we should be stuck in NETWORK_IDLE even though this |
michael@0 | 39 | // event handler could run a long time after the actual suspend. |
michael@0 | 40 | var expectedState = event.type == "load" ? event.target.NETWORK_LOADED |
michael@0 | 41 | : event.target.NETWORK_IDLE; |
michael@0 | 42 | |
michael@0 | 43 | is(event.target.networkState, expectedState, |
michael@0 | 44 | event.target.id + " suspended networkState"); |
michael@0 | 45 | suspendCount[event.target.id]++; |
michael@0 | 46 | |
michael@0 | 47 | --totalSuspendCount; |
michael@0 | 48 | if (totalSuspendCount == 0) { |
michael@0 | 49 | // We're done. |
michael@0 | 50 | for (var i = 1; i <= 6; ++i) { |
michael@0 | 51 | var id = "v" + i; |
michael@0 | 52 | is(suspendCount[id], expectedSuspendCount[id], "Suspend count for " + id); |
michael@0 | 53 | } |
michael@0 | 54 | SimpleTest.finish(); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | if (suspendCount[event.target.id] > 1) |
michael@0 | 58 | return; |
michael@0 | 59 | |
michael@0 | 60 | if (event.target.id == "v1") { |
michael@0 | 61 | event.target.preload = "auto"; |
michael@0 | 62 | } else if (event.target.id == "v4") { |
michael@0 | 63 | event.target.play(); |
michael@0 | 64 | } else if (event.target.id == "v5") { |
michael@0 | 65 | event.target.currentTime = 0.1; |
michael@0 | 66 | } else if (event.target.id == "v6") { |
michael@0 | 67 | event.target.autoplay = true; |
michael@0 | 68 | } |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | var key = Math.random(); |
michael@0 | 72 | |
michael@0 | 73 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 74 | SpecialPowers.pushPrefEnv({"set": [["media.cache_size", 40000]]}, beginTest); |
michael@0 | 75 | function beginTest() { |
michael@0 | 76 | for (var i = 1; i <= 6; ++i) { |
michael@0 | 77 | var id = "v" + i; |
michael@0 | 78 | var v = document.getElementById(id); |
michael@0 | 79 | suspendCount[id] = 0; |
michael@0 | 80 | v.addEventListener("suspend", suspended, false); |
michael@0 | 81 | // Treat "load" as "suspend" for now, it means the same thing: we |
michael@0 | 82 | // stopped the download. |
michael@0 | 83 | v.addEventListener("load", suspended, false); |
michael@0 | 84 | v.src = "seek.ogv?key=" + key + "&id=" + id; |
michael@0 | 85 | } |
michael@0 | 86 | } |
michael@0 | 87 | </script> |
michael@0 | 88 | </pre> |
michael@0 | 89 | </body> |
michael@0 | 90 | </html> |