browser_bug1047663.js (2310B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 "use strict"; 5 6 const EXAMPLE_URL = "https://example.com/browser/dom/workers/test/"; 7 const TAB_URL = EXAMPLE_URL + "bug1047663_tab.html"; 8 const WORKER_URL = EXAMPLE_URL + "bug1047663_worker.sjs"; 9 10 function test() { 11 waitForExplicitFinish(); 12 13 (async function () { 14 // Disable rcwn to make cache behavior deterministic. 15 await SpecialPowers.pushPrefEnv({ 16 set: [["network.http.rcwn.enabled", false]], 17 }); 18 19 let tab = await addTab(TAB_URL); 20 21 // Create a worker. Post a message to it, and check the reply. Since the 22 // server side JavaScript file returns the first source for the first 23 // request, the reply should be "one". If the reply is correct, terminate 24 // the worker. 25 await createWorkerInTab(tab, WORKER_URL); 26 let message = await postMessageToWorkerInTab(tab, WORKER_URL, "ping"); 27 is(message, "one"); 28 await terminateWorkerInTab(tab, WORKER_URL); 29 30 // Create a second worker with the same URL. Post a message to it, and check 31 // the reply. The server side JavaScript file returns the second source for 32 // all subsequent requests, but since the cache is still enabled, the reply 33 // should still be "one". If the reply is correct, terminate the worker. 34 await createWorkerInTab(tab, WORKER_URL); 35 message = await postMessageToWorkerInTab(tab, WORKER_URL, "ping"); 36 is(message, "one"); 37 await terminateWorkerInTab(tab, WORKER_URL); 38 39 // Disable the cache in this tab. This should also disable the cache for all 40 // workers in this tab. 41 await disableCacheInTab(tab); 42 43 // Create a third worker with the same URL. Post a message to it, and check 44 // the reply. Since the server side JavaScript file returns the second 45 // source for all subsequent requests, and the cache is now disabled, the 46 // reply should now be "two". If the reply is correct, terminate the worker. 47 await createWorkerInTab(tab, WORKER_URL); 48 message = await postMessageToWorkerInTab(tab, WORKER_URL, "ping"); 49 is(message, "two"); 50 await terminateWorkerInTab(tab, WORKER_URL); 51 52 removeTab(tab); 53 54 finish(); 55 })(); 56 }