browser_target_command_detach.js (1963B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test the TargetCommand's when detaching the top target 7 // 8 // Do this with the "remote tab" codepath, which will avoid 9 // destroying the DevToolsClient when the target is destroyed. 10 // Otherwise, with "local tab", the client is closed and everything is destroy 11 // on both client and server side. 12 13 const TEST_URL = "data:text/html,test-page"; 14 15 add_task(async function () { 16 info(" ### Test detaching the top target"); 17 18 // Create a TargetCommand for a given test tab 19 const tab = await addTab(TEST_URL); 20 21 info("Create a first commands, which will destroy its top target"); 22 const commands = await CommandsFactory.forRemoteTab( 23 tab.linkedBrowser.browserId 24 ); 25 const targetCommand = commands.targetCommand; 26 27 // We have to start listening in order to ensure having a targetFront available 28 await targetCommand.startListening(); 29 30 info("Call any target front method, to ensure it works fine"); 31 await targetCommand.targetFront.focus(); 32 33 // Simulate a toolbox closing by the cleanup of TargetCommand. 34 // This will stop watching for all target types and destroy all target actors/fronts. 35 await targetCommand.stopListening(); 36 37 info( 38 "Now create a second commands after destroy, to see if we can spawn a new, functional target" 39 ); 40 const secondCommands = await CommandsFactory.forRemoteTab( 41 tab.linkedBrowser.browserId, 42 { 43 client: commands.client, 44 } 45 ); 46 const secondTargetCommand = secondCommands.targetCommand; 47 48 // We have to start listening in order to ensure having a targetFront available 49 await secondTargetCommand.startListening(); 50 51 info("Call any target front method, to ensure it works fine"); 52 await secondTargetCommand.targetFront.focus(); 53 54 BrowserTestUtils.removeTab(tab); 55 56 info("Close the two commands"); 57 await commands.destroy(); 58 await secondCommands.destroy(); 59 });