browser_toolbox_window_title_changes.js (3644B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 requestLongerTimeout(5); 5 6 var { Toolbox } = require("resource://devtools/client/framework/toolbox.js"); 7 8 const NAME_1 = ""; 9 const NAME_2 = "Toolbox test for title update"; 10 const NAME_3 = NAME_2; 11 const NAME_4 = "Toolbox test for another title update"; 12 13 const IFRAME_URL = "data:text/html,<title>iframe title</title>"; 14 const URL_1 = `data:text/html;charset=UTF-8,abcde <iframe src="${IFRAME_URL}"></iframe>`; 15 const URL_2 = 16 URL_ROOT_ORG_SSL + "browser_toolbox_window_title_changes_page.html"; 17 const URL_3 = 18 URL_ROOT_COM_SSL + "browser_toolbox_window_title_changes_page.html"; 19 const URL_4 = `https://example.com/document-builder.sjs?html=<head><title>${NAME_4}</title></head><h1>Hello`; 20 21 add_task(async function test() { 22 await addTab(URL_1); 23 24 const tab = gBrowser.selectedTab; 25 let toolbox = await gDevTools.showToolboxForTab(tab, { 26 hostType: Toolbox.HostType.BOTTOM, 27 }); 28 await toolbox.selectTool("webconsole"); 29 30 info("Undock toolbox and check title"); 31 // We have to first switch the host in order to spawn the new top level window 32 // on which we are going to listen from title change event 33 await toolbox.switchHost(Toolbox.HostType.WINDOW); 34 await checkTitle(NAME_1, URL_1, "toolbox undocked"); 35 36 info("switch to different tool and check title again"); 37 await toolbox.selectTool("jsdebugger"); 38 await checkTitle(NAME_1, URL_1, "tool changed"); 39 40 const { targetCommand } = toolbox.commands; 41 const iframeTarget = targetCommand 42 .getAllTargets([targetCommand.TYPES.FRAME]) 43 .find(target => { 44 return target.url == IFRAME_URL; 45 }); 46 ok(iframeTarget, "Found the iframe target"); 47 info("Selecting the iframe target"); 48 await toolbox.commands.targetCommand.selectTarget(iframeTarget); 49 await checkTitle("iframe title", IFRAME_URL, "selected iframe target"); 50 51 info("navigate to different local url and check title"); 52 53 await navigateTo(URL_2); 54 info("wait for title change"); 55 await checkTitle(NAME_2, URL_2, "url changed"); 56 57 info("navigate to a real url and check title"); 58 await navigateTo(URL_3); 59 60 info("wait for title change"); 61 await checkTitle(NAME_3, URL_3, "url changed"); 62 63 info("navigate to another page on the same domain"); 64 await navigateTo(URL_4); 65 await checkTitle(NAME_4, URL_4, "title changed"); 66 67 info( 68 "destroy toolbox, create new one hosted in a window (with a different tool id), and check title" 69 ); 70 // Give the tools a chance to handle the navigation event before 71 // destroying the toolbox. 72 await new Promise(resolve => executeSoon(resolve)); 73 await toolbox.destroy(); 74 75 // After destroying the toolbox, open a new one. 76 toolbox = await gDevTools.showToolboxForTab(tab, { 77 hostType: Toolbox.HostType.WINDOW, 78 }); 79 toolbox.selectTool("webconsole"); 80 await checkTitle(NAME_4, URL_4, "toolbox destroyed and recreated"); 81 82 info("clean up"); 83 await toolbox.destroy(); 84 gBrowser.removeCurrentTab(); 85 }); 86 87 function getExpectedTitle(name, url) { 88 if (name) { 89 return `Developer Tools — ${name} — ${url}`; 90 } 91 return `Developer Tools — ${url}`; 92 } 93 94 async function checkTitle(name, url, context) { 95 info("Check title - " + context); 96 await waitFor( 97 () => getToolboxWindowTitle() === getExpectedTitle(name, url), 98 `Didn't get the expected title ("${getExpectedTitle(name, url)}"`, 99 200, 100 50 101 ); 102 const expectedTitle = getExpectedTitle(name, url); 103 is(getToolboxWindowTitle(), expectedTitle, context); 104 } 105 106 function getToolboxWindowTitle() { 107 return Services.wm.getMostRecentWindow("devtools:toolbox").document.title; 108 }