Bug 1579260 - Clear 'copy' state of button when the other Copy button is clicked. r=MattN
authorJared Wein <jwein@mozilla.com>
Tue, 10 Sep 2019 05:31:56 +0000
changeset 492520 d07909564f855bbe5723fdde5438b99b51123315
parent 492519 cc4a002262292311a9f92a89bbd22775ac084c25
child 492521 155794d2768106b07f5d021db8ad916fb49fdee7
push id94960
push userjwein@mozilla.com
push dateTue, 10 Sep 2019 15:23:59 +0000
treeherderautoland@d07909564f85 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs1579260
milestone71.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1579260 - Clear 'copy' state of button when the other Copy button is clicked. r=MattN Differential Revision: https://phabricator.services.mozilla.com/D45272
browser/components/aboutlogins/content/components/login-item.js
browser/components/aboutlogins/tests/browser/browser_copyToClipboardButton.js
--- a/browser/components/aboutlogins/content/components/login-item.js
+++ b/browser/components/aboutlogins/content/components/login-item.js
@@ -289,16 +289,20 @@ export default class LoginItem extends H
           }
           return;
         }
         if (
           classList.contains("copy-password-button") ||
           classList.contains("copy-username-button")
         ) {
           let copyButton = event.currentTarget;
+          let otherCopyButton =
+            copyButton == this._copyPasswordButton
+              ? this._copyUsernameButton
+              : this._copyPasswordButton;
           if (copyButton.dataset.copyLoginProperty == "password") {
             let masterPasswordAuth = await new Promise(resolve => {
               window.AboutLoginsUtils.promptForMasterPassword(resolve);
             });
             if (!masterPasswordAuth) {
               return;
             }
           }
@@ -309,16 +313,20 @@ export default class LoginItem extends H
             copyButton.dataset.copyLoginProperty
           ];
           document.dispatchEvent(
             new CustomEvent("AboutLoginsCopyLoginDetail", {
               bubbles: true,
               detail: propertyToCopy,
             })
           );
+          otherCopyButton.disabled = false;
+          delete otherCopyButton.dataset.copied;
+          clearTimeout(this._copyUsernameTimeoutId);
+          clearTimeout(this._copyPasswordTimeoutId);
           let timeoutId = setTimeout(() => {
             copyButton.disabled = false;
             delete copyButton.dataset.copied;
           }, LoginItem.COPY_BUTTON_RESET_TIMEOUT);
           if (copyButton.dataset.copyLoginProperty == "password") {
             this._copyPasswordTimeoutId = timeoutId;
           } else {
             this._copyUsernameTimeoutId = timeoutId;
--- a/browser/components/aboutlogins/tests/browser/browser_copyToClipboardButton.js
+++ b/browser/components/aboutlogins/tests/browser/browser_copyToClipboardButton.js
@@ -58,22 +58,42 @@ add_task(async function test() {
               info("Clicking 'copy' button");
               copyButton.click();
             });
           }
         );
         ok(true, testObj.expectedValue + " is on clipboard now");
 
         await ContentTask.spawn(browser, testObj, async function(aTestObj) {
-          let loginItem = content.document.querySelector("login-item");
+          let loginItem = Cu.waiveXrays(
+            content.document.querySelector("login-item")
+          );
           let copyButton = loginItem.shadowRoot.querySelector(
             aTestObj.copyButtonSelector
           );
+          let otherCopyButton =
+            copyButton == loginItem._copyUsernameButton
+              ? loginItem._copyPasswordButton
+              : loginItem._copyUsernameButton;
+          ok(
+            !otherCopyButton.dataset.copied,
+            "The other copy button should have the 'copied' state removed"
+          );
           ok(copyButton.dataset.copied, "Success message should be shown");
-          await ContentTaskUtils.waitForCondition(
-            () => !copyButton.dataset.copied,
-            "'copied' attribute should be removed after a timeout"
-          );
         });
       }
+
+      // Wait for the 'copied' attribute to get removed from the copyPassword
+      // button, which is the last button that is clicked in the above testcase.
+      // Since another Copy button isn't clicked, the state won't get cleared
+      // instantly. This test covers the built-in timeout of the visual display.
+      await ContentTask.spawn(browser, null, async () => {
+        let copyButton = Cu.waiveXrays(
+          content.document.querySelector("login-item")
+        )._copyPasswordButton;
+        await ContentTaskUtils.waitForCondition(
+          () => !copyButton.dataset.copied,
+          "'copied' attribute should be removed after a timeout"
+        );
+      });
     }
   );
 });