Bug 1552275 - Fix Copy Link context menu in DevTools Inspector markup view. r=gl a=jcristau
authorRazvan Caliman <rcaliman@mozilla.com>
Mon, 20 May 2019 16:03:00 +0000
changeset 533382 baf9be06329bcfa0777295b41b55b23debafb195
parent 533381 1d17556df566802d63e1239d7c42e44772c9a734
child 533383 a5352b191e5a39803a6ed74a48279529277aa6e6
push id11307
push usernbeleuzu@mozilla.com
push dateFri, 24 May 2019 18:27:55 +0000
treeherdermozilla-beta@b7c117554a7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgl, jcristau
bugs1552275, 1529364
milestone68.0
Bug 1552275 - Fix Copy Link context menu in DevTools Inspector markup view. r=gl a=jcristau - Fixes the references to the correct event handler & InspectorFront after a previous mass refactoring in Bug 1529364. - Augments a test to ensure the clipboard content is correct executing the context menu action to copy a link. Differential Revision: https://phabricator.services.mozilla.com/D31765
devtools/client/inspector/markup/markup-context-menu.js
devtools/client/inspector/markup/test/browser_markup_links_04.js
--- a/devtools/client/inspector/markup/markup-context-menu.js
+++ b/devtools/client/inspector/markup/markup-context-menu.js
@@ -62,19 +62,21 @@ class MarkupContextMenu {
       target: event.target,
     });
   }
 
   /**
    * This method is here for the benefit of copying links.
    */
   _copyAttributeLink(link) {
-    this.inspector.resolveRelativeURL(link, this.selection.nodeFront).then(url => {
-      clipboardHelper.copyString(url);
-    }, console.error);
+    this.inspector.inspector
+      .resolveRelativeURL(link, this.selection.nodeFront)
+      .then(url => {
+        clipboardHelper.copyString(url);
+      }, console.error);
   }
 
   /**
    * Copy the full CSS Path of the selected Node to the clipboard.
    */
   _copyCssPath() {
     if (!this.selection.isNode()) {
       return;
@@ -207,17 +209,17 @@ class MarkupContextMenu {
     clipboardHelper.copyString(this.nodeMenuTriggerInfo.value);
   }
 
   /**
    * This method is here for the benefit of the node-menu-link-copy menu item
    * in the inspector contextual-menu.
    */
   _onCopyLink() {
-    this.copyAttributeLink(this.contextMenuTarget.dataset.link);
+    this._copyAttributeLink(this.contextMenuTarget.dataset.link);
   }
 
   /**
    * Edit attribute for node.
    * Used for node context menu and shouldn't be called directly.
    */
   _onEditAttribute() {
     const container = this.markup.getContainer(this.selection.nodeFront);
--- a/devtools/client/inspector/markup/test/browser_markup_links_04.js
+++ b/devtools/client/inspector/markup/test/browser_markup_links_04.js
@@ -1,16 +1,16 @@
 /* vim: set ts=2 et sw=2 tw=80: */
 /* Any copyright is dedicated to the Public Domain.
  http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 // Tests that the contextual menu shows the right items when clicking on a link
-// in an attribute.
+// in an attribute. Run the action to copy the link and check the clipboard.
 
 const TEST_URL = URL_ROOT + "doc_markup_links.html";
 
 const TOOLBOX_L10N = new LocalizationHelper("devtools/client/locales/toolbox.properties");
 
 // The test case array contains objects with the following properties:
 // - selector: css selector for the node to select in the inspector
 // - attributeName: name of the attribute to test
@@ -73,16 +73,17 @@ const TEST_DATA = [{
 }];
 
 add_task(async function() {
   const {inspector} = await openInspectorForURL(TEST_URL);
 
   for (const test of TEST_DATA) {
     info("Selecting test node " + test.selector);
     await selectNode(test.selector, inspector);
+    const nodeFront = inspector.selection.nodeFront;
 
     info("Finding the popupNode to anchor the context-menu to");
     const {editor} = await getContainerForSelector(test.selector, inspector);
     const popupNode = editor.attrElements.get(test.attributeName)
                     .querySelector(test.popupNodeSelector);
     ok(popupNode, "Found the popupNode in attribute " + test.attributeName);
 
     info("Simulating a context click on the popupNode");
@@ -100,11 +101,19 @@ add_task(async function() {
 
     if (test.isLinkFollowItemVisible) {
       is(linkFollow.label, test.linkFollowItemLabel,
         "the follow-link label is correct");
     }
     if (test.isLinkCopyItemVisible) {
       is(linkCopy.label, test.linkCopyItemLabel,
         "the copy-link label is correct");
+
+      info("Get link from node attribute");
+      const link = await nodeFront.getAttribute(test.attributeName);
+      info("Resolve link to absolue URL");
+      const expected = await inspector.inspector
+        .resolveRelativeURL(link, nodeFront);
+      info("Check the clipboard to see if the correct URL was copied");
+      await waitForClipboardPromise(() => linkCopy.click(), expected);
     }
   }
 });