browser_webconsole_clickable_urls.js (3244B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // When strings containing URLs are entered into the webconsole, 5 // ensure that the output can be clicked to open those URLs. 6 // This test only check that clicking on a link works as expected, 7 // as the output is already tested in Reps (in Github). 8 9 "use strict"; 10 11 const TEST_URI = "data:text/html;charset=utf8,<!DOCTYPE html>Clickable URLS"; 12 13 add_task(async function () { 14 const hud = await openNewTabAndConsole(TEST_URI); 15 const currentTab = gBrowser.selectedTab; 16 17 const firstURL = "http://example.com/"; 18 const secondURL = "http://example.com/?id=secondURL"; 19 SpecialPowers.spawn( 20 gBrowser.selectedBrowser, 21 [[firstURL, secondURL]], 22 urls => { 23 content.wrappedJSObject.console.log("Visit ", urls[0], " and ", urls[1]); 24 } 25 ); 26 27 const node = await waitFor(() => findConsoleAPIMessage(hud, firstURL)); 28 const [urlEl1, urlEl2] = Array.from(node.querySelectorAll("a.url")); 29 30 let onTabLoaded = BrowserTestUtils.waitForNewTab(gBrowser, firstURL, true); 31 32 info("Clicking on the first link"); 33 urlEl1.click(); 34 35 let newTab = await onTabLoaded; 36 // We only need to check that newTab is truthy since 37 // BrowserTestUtils.waitForNewTab checks the URL. 38 ok(newTab, "The expected tab was opened."); 39 40 info("Select the first tab again"); 41 gBrowser.selectedTab = currentTab; 42 43 info("Ctrl/Cmd + Click on the second link"); 44 onTabLoaded = BrowserTestUtils.waitForNewTab(gBrowser, secondURL, true); 45 46 const isMacOS = Services.appinfo.OS === "Darwin"; 47 EventUtils.sendMouseEvent( 48 { 49 type: "click", 50 [isMacOS ? "metaKey" : "ctrlKey"]: true, 51 }, 52 urlEl2, 53 hud.ui.window 54 ); 55 56 newTab = await onTabLoaded; 57 58 ok(newTab, "The expected tab was opened."); 59 is( 60 newTab._tPos, 61 currentTab._tPos + 1, 62 "The new tab was opened in the position to the right of the current tab" 63 ); 64 is(gBrowser.selectedTab, currentTab, "The tab was opened in the background"); 65 66 info( 67 "Test that Ctrl/Cmd + Click on a link in an array doesn't open the sidebar" 68 ); 69 const onMessage = waitForMessageByType(hud, "Visit", ".console-api"); 70 SpecialPowers.spawn(gBrowser.selectedBrowser, [firstURL], url => { 71 content.wrappedJSObject.console.log([`Visit ${url}`]); 72 }); 73 const message = await onMessage; 74 const urlEl3 = message.node.querySelector("a.url"); 75 76 onTabLoaded = BrowserTestUtils.waitForNewTab(gBrowser, firstURL, true); 77 78 AccessibilityUtils.setEnv({ 79 // Focusable element is put back in focus order when its container row is in 80 // focused/active state. 81 nonNegativeTabIndexRule: false, 82 }); 83 EventUtils.sendMouseEvent( 84 { 85 type: "click", 86 [isMacOS ? "metaKey" : "ctrlKey"]: true, 87 }, 88 urlEl3, 89 hud.ui.window 90 ); 91 AccessibilityUtils.resetEnv(); 92 await onTabLoaded; 93 94 info("Log a message and wait for it to appear so we know the UI was updated"); 95 const onSmokeMessage = waitForMessageByType(hud, "smoke", ".console-api"); 96 SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => { 97 content.wrappedJSObject.console.log("smoke"); 98 }); 99 await onSmokeMessage; 100 ok(!hud.ui.document.querySelector(".sidebar"), "Sidebar wasn't closed"); 101 });