head.js (2129B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 /** 5 * Provide infrastructure for JSProcessActor tests. 6 */ 7 8 const URL = "about:blank"; 9 const TEST_URL = "http://test2.example.org/"; 10 let processActorOptions = { 11 parent: { 12 esModuleURI: "resource://testing-common/TestProcessActorParent.sys.mjs", 13 }, 14 child: { 15 esModuleURI: "resource://testing-common/TestProcessActorChild.sys.mjs", 16 observers: ["test-js-content-actor-child-observer"], 17 }, 18 }; 19 20 function promiseNotification(aNotification) { 21 let notificationResolve; 22 let notificationObserver = function observer() { 23 notificationResolve(); 24 Services.obs.removeObserver(notificationObserver, aNotification); 25 }; 26 return new Promise(resolve => { 27 notificationResolve = resolve; 28 Services.obs.addObserver(notificationObserver, aNotification); 29 }); 30 } 31 32 function declTest(name, cfg) { 33 let { 34 url = "about:blank", 35 includeParent = false, 36 remoteTypes, 37 loadInDevToolsLoader = false, 38 test, 39 } = cfg; 40 41 // Build the actor options object which will be used to register & unregister 42 // our process actor. 43 let actorOptions = { 44 parent: Object.assign({}, processActorOptions.parent), 45 child: Object.assign({}, processActorOptions.child), 46 }; 47 actorOptions.includeParent = includeParent; 48 if (remoteTypes !== undefined) { 49 actorOptions.remoteTypes = remoteTypes; 50 } 51 if (loadInDevToolsLoader) { 52 actorOptions.loadInDevToolsLoader = true; 53 } 54 55 // Add a new task for the actor test declared here. 56 add_task(async function () { 57 info("Entering test: " + name); 58 59 // Register our actor, and load a new tab with the provided URL 60 ChromeUtils.registerProcessActor("TestProcessActor", actorOptions); 61 try { 62 await BrowserTestUtils.withNewTab(url, async browser => { 63 info("browser ready"); 64 await Promise.resolve(test(browser, window)); 65 }); 66 } finally { 67 // Unregister the actor after the test is complete. 68 ChromeUtils.unregisterProcessActor("TestProcessActor"); 69 info("Exiting test: " + name); 70 } 71 }); 72 }