browser_dbg_target-scoped-actor-02.js (1622B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /** 7 * Check target-scoped actor lifetimes. 8 */ 9 10 const ACTORS_URL = EXAMPLE_URL + "testactors.js"; 11 const TAB_URL = TEST_URI_ROOT + "doc_empty-tab-01.html"; 12 13 add_task(async function () { 14 const tab = await addTab(TAB_URL); 15 16 await registerActorInContentProcess(ACTORS_URL, { 17 prefix: "testOne", 18 constructor: "TestActor1", 19 type: { target: true }, 20 }); 21 22 const target = await createAndAttachTargetForTab(tab); 23 const { client } = target; 24 const form = target.targetForm; 25 26 await testTargetScopedActor(client, form); 27 await closeTab(client, form); 28 await target.destroy(); 29 }); 30 31 async function testTargetScopedActor(client, form) { 32 ok(form.testOneActor, "Found the test target-scoped actor."); 33 ok( 34 form.testOneActor.includes("testOne"), 35 "testOneActor's typeName should be used." 36 ); 37 38 const response = await client.request({ 39 to: form.testOneActor, 40 type: "ping", 41 }); 42 is(response.pong, "pong", "Actor should respond to requests."); 43 } 44 45 async function closeTab(client, form) { 46 // We need to start listening for the rejection before removing the tab 47 /* eslint-disable-next-line mozilla/rejects-requires-await*/ 48 const onReject = Assert.rejects( 49 client.request({ to: form.testOneActor, type: "ping" }), 50 err => 51 err.message === 52 `'ping' active request packet to '${form.testOneActor}' ` + 53 `can't be sent as the connection just closed.`, 54 "testOneActor went away." 55 ); 56 await removeTab(gBrowser.selectedTab); 57 await onReject; 58 }