test_front_destroy.js (1382B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 /** 5 * Test that fronts throw errors if they are called after being destroyed. 6 */ 7 8 "use strict"; 9 10 // HACK: ServiceWorkerManager requires the "profile-change-teardown" to cleanly 11 // shutdown, and setting _profileInitialized to `true` will trigger those 12 // notifications (see /testing/xpcshell/head.js). 13 // eslint-disable-next-line no-undef 14 _profileInitialized = true; 15 16 add_task(async function test() { 17 DevToolsServer.init(); 18 DevToolsServer.registerAllActors(); 19 20 info("Create and connect the DevToolsClient"); 21 const transport = DevToolsServer.connectPipe(); 22 const client = new DevToolsClient(transport); 23 await client.connect(); 24 25 info("Get the device front and check calling getDescription() on it"); 26 const front = await client.mainRoot.getFront("device"); 27 const description = await front.getDescription(); 28 ok( 29 !!description, 30 "Check that the getDescription() method returns a valid response." 31 ); 32 33 info("Destroy the device front and try calling getDescription again"); 34 front.destroy(); 35 Assert.throws( 36 () => front.getDescription(), 37 /Can not send request 'getDescription' because front 'device' is already destroyed\./, 38 "Check device front throws when getDescription() is called after destroy()" 39 ); 40 41 await client.close(); 42 });