Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <!-- |
michael@0 | 2 | Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 4 | --> |
michael@0 | 5 | <!DOCTYPE HTML> |
michael@0 | 6 | <html> |
michael@0 | 7 | <head> |
michael@0 | 8 | <title>Test for SharedWorker</title> |
michael@0 | 9 | <script src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 10 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"> |
michael@0 | 11 | <script class="testbody" type="text/javascript;version=1.7"> |
michael@0 | 12 | "use strict"; |
michael@0 | 13 | |
michael@0 | 14 | const swPref = "dom.workers.sharedWorkers.enabled"; |
michael@0 | 15 | const scrollbarPref = "layout.testing.overlay-scrollbars.always-visible"; |
michael@0 | 16 | const bfCacheEnabledPref = "browser.sessionhistory.cache_subframes"; |
michael@0 | 17 | const bfCacheDepthPref = "browser.sessionhistory.max_total_viewers"; |
michael@0 | 18 | const bfCacheDepth = 10; |
michael@0 | 19 | |
michael@0 | 20 | const frameRelativeURL = "multi_sharedWorker_frame.html"; |
michael@0 | 21 | const storedData = "0123456789abcdefghijklmnopqrstuvwxyz"; |
michael@0 | 22 | |
michael@0 | 23 | let testGenerator = (function() { |
michael@0 | 24 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 25 | |
michael@0 | 26 | if (!SpecialPowers.getBoolPref(swPref)) { |
michael@0 | 27 | ok(!("SharedWorker" in window), "No SharedWorker without pref set"); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | // Enable SharedWorkers and force scrollbar to always be shown. The |
michael@0 | 31 | // scrollbar setting is necessary to avoid the fade-in/fade-out from |
michael@0 | 32 | // evicting our document from the BF cache below. If bug 1049277 |
michael@0 | 33 | // is fixed, then we can stop setting the scrollbar pref here. |
michael@0 | 34 | SpecialPowers.pushPrefEnv({ set: [[swPref, true], |
michael@0 | 35 | [scrollbarPref, true]] }, |
michael@0 | 36 | sendToGenerator); |
michael@0 | 37 | yield undefined; |
michael@0 | 38 | |
michael@0 | 39 | window.addEventListener("message", function(event) { |
michael@0 | 40 | if (typeof(event.data) == "string") { |
michael@0 | 41 | info(event.data); |
michael@0 | 42 | } else { |
michael@0 | 43 | sendToGenerator(event); |
michael@0 | 44 | } |
michael@0 | 45 | }); |
michael@0 | 46 | |
michael@0 | 47 | let frame = document.getElementById("frame"); |
michael@0 | 48 | frame.src = frameRelativeURL; |
michael@0 | 49 | frame.onload = sendToGenerator; |
michael@0 | 50 | |
michael@0 | 51 | yield undefined; |
michael@0 | 52 | |
michael@0 | 53 | frame = frame.contentWindow; |
michael@0 | 54 | frame.postMessage({ command: "retrieve" }, "*"); |
michael@0 | 55 | |
michael@0 | 56 | let event = yield undefined; |
michael@0 | 57 | ok(event instanceof MessageEvent, "Got a MessageEvent"); |
michael@0 | 58 | is(event.source, frame, "Correct window got the event"); |
michael@0 | 59 | is(event.data.type, "result", "Got a result message"); |
michael@0 | 60 | is(event.data.data, undefined, "No data stored yet"); |
michael@0 | 61 | |
michael@0 | 62 | frame.postMessage({ command: "store", data: storedData }, "*"); |
michael@0 | 63 | frame.postMessage({ command: "retrieve" }, "*"); |
michael@0 | 64 | |
michael@0 | 65 | event = yield undefined; |
michael@0 | 66 | ok(event instanceof MessageEvent, "Got a MessageEvent"); |
michael@0 | 67 | is(event.source, frame, "Correct window got the event"); |
michael@0 | 68 | is(event.data.type, "result", "Got a result message"); |
michael@0 | 69 | is(event.data.data, storedData, "Got stored data"); |
michael@0 | 70 | |
michael@0 | 71 | // Navigate when the bfcache is disabled. |
michael@0 | 72 | info("Navigating to about:blank"); |
michael@0 | 73 | let frame = document.getElementById("frame"); |
michael@0 | 74 | frame.onload = sendToGenerator; |
michael@0 | 75 | frame.src = "about:blank"; |
michael@0 | 76 | frame.contentWindow.document.body.offsetTop; |
michael@0 | 77 | |
michael@0 | 78 | yield undefined; |
michael@0 | 79 | |
michael@0 | 80 | info("Navigating to " + frameRelativeURL); |
michael@0 | 81 | frame.src = frameRelativeURL; |
michael@0 | 82 | frame.contentWindow.document.body.offsetTop; |
michael@0 | 83 | |
michael@0 | 84 | yield undefined; |
michael@0 | 85 | |
michael@0 | 86 | frame = frame.contentWindow; |
michael@0 | 87 | frame.postMessage({ command: "retrieve" }, "*"); |
michael@0 | 88 | |
michael@0 | 89 | let event = yield undefined; |
michael@0 | 90 | ok(event instanceof MessageEvent, "Got a MessageEvent"); |
michael@0 | 91 | is(event.source, frame, "Correct window got the event"); |
michael@0 | 92 | is(event.data.type, "result", "Got a result message"); |
michael@0 | 93 | is(event.data.data, undefined, "No data stored"); |
michael@0 | 94 | |
michael@0 | 95 | frame.postMessage({ command: "store", data: storedData }, "*"); |
michael@0 | 96 | frame.postMessage({ command: "retrieve" }, "*"); |
michael@0 | 97 | |
michael@0 | 98 | event = yield undefined; |
michael@0 | 99 | ok(event instanceof MessageEvent, "Got a MessageEvent"); |
michael@0 | 100 | is(event.source, frame, "Correct window got the event"); |
michael@0 | 101 | is(event.data.type, "result", "Got a result message"); |
michael@0 | 102 | is(event.data.data, storedData, "Got stored data"); |
michael@0 | 103 | |
michael@0 | 104 | info("Enabling '" + bfCacheEnabledPref + "' pref"); |
michael@0 | 105 | SpecialPowers.pushPrefEnv({ set: [[bfCacheEnabledPref, true], |
michael@0 | 106 | [bfCacheDepthPref, bfCacheDepth]] }, |
michael@0 | 107 | sendToGenerator); |
michael@0 | 108 | yield undefined; |
michael@0 | 109 | |
michael@0 | 110 | // Navigate when the bfcache is enabled. |
michael@0 | 111 | let frame = document.getElementById("frame"); |
michael@0 | 112 | frame.onload = sendToGenerator; |
michael@0 | 113 | |
michael@0 | 114 | info("Navigating to about:blank"); |
michael@0 | 115 | frame.src = "about:blank"; |
michael@0 | 116 | frame.contentWindow.document.body.offsetTop; |
michael@0 | 117 | |
michael@0 | 118 | yield undefined; |
michael@0 | 119 | |
michael@0 | 120 | for (let i = 0; i < 3; i++) { |
michael@0 | 121 | info("Running GC"); |
michael@0 | 122 | SpecialPowers.exactGC(window, sendToGenerator); |
michael@0 | 123 | yield undefined; |
michael@0 | 124 | |
michael@0 | 125 | info("Waiting the event queue to clear"); |
michael@0 | 126 | SpecialPowers.executeSoon(sendToGenerator); |
michael@0 | 127 | yield undefined; |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | info("Navigating to " + frameRelativeURL); |
michael@0 | 131 | frame.src = frameRelativeURL; |
michael@0 | 132 | frame.contentWindow.document.body.offsetTop; |
michael@0 | 133 | |
michael@0 | 134 | yield undefined; |
michael@0 | 135 | |
michael@0 | 136 | frame = frame.contentWindow; |
michael@0 | 137 | frame.postMessage({ command: "retrieve" }, "*"); |
michael@0 | 138 | |
michael@0 | 139 | let event = yield undefined; |
michael@0 | 140 | ok(event instanceof MessageEvent, "Got a MessageEvent"); |
michael@0 | 141 | is(event.source, frame, "Correct window got the event"); |
michael@0 | 142 | is(event.data.type, "result", "Got a result message"); |
michael@0 | 143 | is(event.data.data, storedData, "Still have data stored"); |
michael@0 | 144 | |
michael@0 | 145 | info("Resetting '" + bfCacheEnabledPref + "' pref"); |
michael@0 | 146 | SpecialPowers.popPrefEnv(sendToGenerator); |
michael@0 | 147 | yield undefined; |
michael@0 | 148 | |
michael@0 | 149 | window.removeEventListener("message", sendToGenerator); |
michael@0 | 150 | |
michael@0 | 151 | SimpleTest.finish(); |
michael@0 | 152 | yield undefined; |
michael@0 | 153 | })(); |
michael@0 | 154 | |
michael@0 | 155 | let sendToGenerator = testGenerator.send.bind(testGenerator); |
michael@0 | 156 | |
michael@0 | 157 | </script> |
michael@0 | 158 | </head> |
michael@0 | 159 | <body onload="testGenerator.next();"> |
michael@0 | 160 | <iframe id="frame"></iframe> |
michael@0 | 161 | </body> |
michael@0 | 162 | </html> |