browser_dbg_listtabs-01.js (2627B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /** 7 * Make sure the listTabs request works as specified. 8 */ 9 10 var { 11 DevToolsServer, 12 } = require("resource://devtools/server/devtools-server.js"); 13 var { 14 DevToolsClient, 15 } = require("resource://devtools/client/devtools-client.js"); 16 17 const TAB1_URL = EXAMPLE_URL + "doc_empty-tab-01.html"; 18 const TAB2_URL = EXAMPLE_URL + "doc_empty-tab-02.html"; 19 20 add_task(async function test() { 21 DevToolsServer.init(); 22 DevToolsServer.registerAllActors(); 23 24 const transport = DevToolsServer.connectPipe(); 25 const client = new DevToolsClient(transport); 26 const [aType] = await client.connect(); 27 is(aType, "browser", "Root actor should identify itself as a browser."); 28 29 const firstTab = await testFirstTab(client); 30 const secondTab = await testSecondTab(client, firstTab.front); 31 await testRemoveTab(client, firstTab.tab); 32 await testAttachRemovedTab(secondTab.tab, secondTab.front); 33 await client.close(); 34 }); 35 36 async function testFirstTab(client) { 37 const tab = await addTab(TAB1_URL); 38 39 const front = await getDescriptorActorForUrl(client, TAB1_URL); 40 ok(front, "Should find a target actor for the first tab."); 41 return { tab, front }; 42 } 43 44 async function testSecondTab(client, firstTabFront) { 45 const tab = await addTab(TAB2_URL); 46 47 const firstFront = await getDescriptorActorForUrl(client, TAB1_URL); 48 const secondFront = await getDescriptorActorForUrl(client, TAB2_URL); 49 is(firstFront, firstTabFront, "First tab's actor shouldn't have changed."); 50 ok(secondFront, "Should find a target actor for the second tab."); 51 return { tab, front: secondFront }; 52 } 53 54 async function testRemoveTab(client, firstTab) { 55 await removeTab(firstTab); 56 const front = await getDescriptorActorForUrl(client, TAB1_URL); 57 ok(!front, "Shouldn't find a target actor for the first tab anymore."); 58 } 59 60 async function testAttachRemovedTab(secondTab, secondTabFront) { 61 await removeTab(secondTab); 62 63 const { actorID } = secondTabFront; 64 try { 65 await secondTabFront.getFavicon({}); 66 ok( 67 false, 68 "any request made to the descriptor for a closed tab should have failed" 69 ); 70 } catch (error) { 71 ok( 72 error.message.includes( 73 `Connection closed, pending request to ${actorID}, type getFavicon failed` 74 ), 75 "Actor is gone since the tab was removed." 76 ); 77 } 78 } 79 80 async function getDescriptorActorForUrl(client, url) { 81 const tabDescriptors = await client.mainRoot.listTabs(); 82 const tabDescriptor = tabDescriptors.find(front => front.url == url); 83 return tabDescriptor; 84 }