browser_markup_links_04.js (4686B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Tests that the contextual menu shows the right items when clicking on a link 7 // in an attribute. Run the action to copy the link and check the clipboard. 8 9 const TEST_URL = URL_ROOT + "doc_markup_links.html"; 10 11 const TOOLBOX_L10N = new LocalizationHelper( 12 "devtools/client/locales/toolbox.properties" 13 ); 14 15 // The test case array contains objects with the following properties: 16 // - selector: css selector for the node to select in the inspector 17 // - attributeName: name of the attribute to test 18 // - popupNodeSelector: css selector for the element inside the attribute 19 // element to use as the contextual menu anchor 20 // - isLinkFollowItemVisible: is the follow-link item expected to be displayed 21 // - isLinkCopyItemVisible: is the copy-link item expected to be displayed 22 // - linkFollowItemLabel: the expected label of the follow-link item 23 // - linkCopyItemLabel: the expected label of the copy-link item 24 const TEST_DATA = [ 25 { 26 selector: "link", 27 attributeName: "href", 28 popupNodeSelector: ".link", 29 isLinkFollowItemVisible: true, 30 isLinkCopyItemVisible: true, 31 linkFollowItemLabel: TOOLBOX_L10N.getStr( 32 "toolbox.viewCssSourceInStyleEditor.label" 33 ), 34 linkCopyItemLabel: INSPECTOR_L10N.getStr( 35 "inspector.menu.copyUrlToClipboard.label" 36 ), 37 }, 38 { 39 selector: "link[rel=icon]", 40 attributeName: "href", 41 popupNodeSelector: ".link", 42 isLinkFollowItemVisible: true, 43 isLinkCopyItemVisible: true, 44 linkFollowItemLabel: INSPECTOR_L10N.getStr( 45 "inspector.menu.openUrlInNewTab.label" 46 ), 47 linkCopyItemLabel: INSPECTOR_L10N.getStr( 48 "inspector.menu.copyUrlToClipboard.label" 49 ), 50 }, 51 { 52 selector: "link", 53 attributeName: "rel", 54 popupNodeSelector: ".attr-value", 55 isLinkFollowItemVisible: false, 56 isLinkCopyItemVisible: false, 57 }, 58 { 59 selector: "output", 60 attributeName: "for", 61 popupNodeSelector: ".link", 62 isLinkFollowItemVisible: true, 63 isLinkCopyItemVisible: false, 64 linkFollowItemLabel: INSPECTOR_L10N.getFormatStr( 65 "inspector.menu.selectElement.label", 66 "name" 67 ), 68 }, 69 { 70 selector: "script", 71 attributeName: "src", 72 popupNodeSelector: ".link", 73 isLinkFollowItemVisible: true, 74 isLinkCopyItemVisible: true, 75 linkFollowItemLabel: TOOLBOX_L10N.getStr( 76 "toolbox.viewJsSourceInDebugger.label" 77 ), 78 linkCopyItemLabel: INSPECTOR_L10N.getStr( 79 "inspector.menu.copyUrlToClipboard.label" 80 ), 81 }, 82 { 83 selector: "p[for]", 84 attributeName: "for", 85 popupNodeSelector: ".attr-value", 86 isLinkFollowItemVisible: false, 87 isLinkCopyItemVisible: false, 88 }, 89 ]; 90 91 add_task(async function () { 92 const { inspector } = await openInspectorForURL(TEST_URL); 93 94 for (const test of TEST_DATA) { 95 info("Selecting test node " + test.selector); 96 await selectNode(test.selector, inspector); 97 const nodeFront = inspector.selection.nodeFront; 98 99 info("Finding the popupNode to anchor the context-menu to"); 100 const { editor } = await getContainerForSelector(test.selector, inspector); 101 const popupNode = editor.attrElements 102 .get(test.attributeName) 103 .querySelector(test.popupNodeSelector); 104 ok(popupNode, "Found the popupNode in attribute " + test.attributeName); 105 106 info("Simulating a context click on the popupNode"); 107 const allMenuItems = openContextMenuAndGetAllItems(inspector, { 108 target: popupNode, 109 }); 110 111 const linkFollow = allMenuItems.find(i => i.id === "node-menu-link-follow"); 112 const linkCopy = allMenuItems.find(i => i.id === "node-menu-link-copy"); 113 114 is( 115 linkFollow.visible, 116 test.isLinkFollowItemVisible, 117 "The follow-link item display is correct" 118 ); 119 is( 120 linkCopy.visible, 121 test.isLinkCopyItemVisible, 122 "The copy-link item display is correct" 123 ); 124 125 if (test.isLinkFollowItemVisible) { 126 is( 127 linkFollow.label, 128 test.linkFollowItemLabel, 129 "the follow-link label is correct" 130 ); 131 } 132 if (test.isLinkCopyItemVisible) { 133 is( 134 linkCopy.label, 135 test.linkCopyItemLabel, 136 "the copy-link label is correct" 137 ); 138 139 info("Get link from node attribute"); 140 const link = await nodeFront.getAttribute(test.attributeName); 141 info("Resolve link to absolue URL"); 142 const expected = await inspector.inspectorFront.resolveRelativeURL( 143 link, 144 nodeFront 145 ); 146 info("Check the clipboard to see if the correct URL was copied"); 147 await waitForClipboardPromise(() => linkCopy.click(), expected); 148 } 149 } 150 });