browser_watcher_actor_getter_caching.js (2551B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test that watcher front/actor APIs do not lead to create duplicate actors. 7 8 const TEST_URL = "data:text/html;charset=utf-8,Actor caching test"; 9 10 add_task(async function () { 11 info("Setup the test page with workers of all types"); 12 const tab = await addTab(TEST_URL); 13 14 info("Create a target list for a tab target"); 15 const commands = await CommandsFactory.forTab(tab); 16 const targetCommand = commands.targetCommand; 17 await targetCommand.startListening(); 18 19 const { watcherFront } = targetCommand; 20 ok(watcherFront, "A watcherFront is available on targetCommand"); 21 22 info("Check that getNetworkParentActor does not create duplicate actors"); 23 testActorGetter( 24 watcherFront, 25 () => watcherFront.getNetworkParentActor(), 26 "networkParent" 27 ); 28 29 info("Check that getBreakpointListActor does not create duplicate actors"); 30 testActorGetter( 31 watcherFront, 32 () => watcherFront.getBreakpointListActor(), 33 "breakpoint-list" 34 ); 35 36 info( 37 "Check that getTargetConfigurationActor does not create duplicate actors" 38 ); 39 testActorGetter( 40 watcherFront, 41 () => watcherFront.getTargetConfigurationActor(), 42 "target-configuration" 43 ); 44 45 info( 46 "Check that getThreadConfigurationActor does not create duplicate actors" 47 ); 48 testActorGetter( 49 watcherFront, 50 () => watcherFront.getThreadConfigurationActor(), 51 "thread-configuration" 52 ); 53 54 targetCommand.destroy(); 55 await commands.waitForRequestsToSettle(); 56 await commands.destroy(); 57 }); 58 59 /** 60 * Check that calling an actor getter method on the watcher front leads to the 61 * creation of at most 1 actor. 62 */ 63 async function testActorGetter(watcherFront, actorGetterFn, typeName) { 64 checkPoolChildrenSize(watcherFront, typeName, 0); 65 66 const actor = await actorGetterFn(); 67 checkPoolChildrenSize(watcherFront, typeName, 1); 68 69 const otherActor = await actorGetterFn(); 70 is(actor, otherActor, "Returned the same actor for " + typeName); 71 72 checkPoolChildrenSize(watcherFront, typeName, 1); 73 } 74 75 /** 76 * Assert that a given parent pool has the expected number of children for 77 * a given typeName. 78 */ 79 function checkPoolChildrenSize(parentPool, typeName, expected) { 80 const children = [...parentPool.poolChildren()]; 81 const childrenByType = children.filter(pool => pool.typeName === typeName); 82 is( 83 childrenByType.length, 84 expected, 85 `${parentPool.actorID} should have ${expected} children of type ${typeName}` 86 ); 87 }