Bug 1550093 - Add automated tests for CopyToClipboardButton. r=MattN
☠☠ backed out by 366a49e70140 ☠ ☠
authorJared Wein <jwein@mozilla.com>
Fri, 17 May 2019 21:20:54 +0000
changeset 533225 058d6d7a23a64ffc0051d2cc1ec6a78c3d050897
parent 533224 38cafbd4a35fc02e9c3b26f27338b7907878b6eb
child 533228 14f4168a80d28e5e460676491f9b9ec9c50df422
push id11276
push userrgurzau@mozilla.com
push dateMon, 20 May 2019 13:11:24 +0000
treeherdermozilla-beta@847755a7c325 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs1550093
milestone68.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 1550093 - Add automated tests for CopyToClipboardButton. r=MattN Differential Revision: https://phabricator.services.mozilla.com/D31664
browser/components/aboutlogins/tests/browser/browser.ini
browser/components/aboutlogins/tests/browser/browser_copyToClipboardButton.js
--- a/browser/components/aboutlogins/tests/browser/browser.ini
+++ b/browser/components/aboutlogins/tests/browser/browser.ini
@@ -1,8 +1,9 @@
 [DEFAULT]
 prefs =
   signon.management.page.enabled=true
 
+[browser_copyToClipboardButton.js]
 [browser_deleteLogin.js]
 [browser_loginListChanges.js]
 [browser_openSite.js]
 [browser_updateLogin.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/aboutlogins/tests/browser/browser_copyToClipboardButton.js
@@ -0,0 +1,58 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+add_task(async function test() {
+  await SpecialPowers.pushPrefEnv({"set": [["dom.events.testing.asyncClipboard", true]] });
+
+  await BrowserTestUtils.withNewTab({gBrowser, url: "about:logins"}, async function(browser) {
+    let TEST_LOGIN = {
+      guid: "70a",
+      username: "jared",
+      password: "deraj",
+      hostname: "https://www.example.com",
+    };
+
+    await ContentTask.spawn(browser, TEST_LOGIN, async function(login) {
+      let loginItem = Cu.waiveXrays(content.document.querySelector("login-item"));
+
+      // The login object needs to be cloned into the content global.
+      loginItem.setLogin(Cu.cloneInto(login, content));
+
+      // Lower the timeout for the test.
+      let copyButton = loginItem.shadowRoot.querySelector(".copy-username-button");
+      Object.defineProperty(copyButton.constructor, "BUTTON_RESET_TIMEOUT", {
+          configurable: true,
+          writable: true,
+          value: 1000,
+      });
+    });
+
+    for (let testCase of [
+      [TEST_LOGIN.username, ".copy-username-button"],
+      [TEST_LOGIN.password, ".copy-password-button"],
+    ]) {
+      let testObj = {
+        expectedValue: testCase[0],
+        copyButtonSelector: testCase[1],
+      };
+      await SimpleTest.promiseClipboardChange(testObj.expectedValue, async () => {
+        await ContentTask.spawn(browser, testObj, async function(aTestObj) {
+          let loginItem = content.document.querySelector("login-item");
+          let copyButton = loginItem.shadowRoot.querySelector(aTestObj.copyButtonSelector);
+          let innerButton = copyButton.shadowRoot.querySelector("button");
+          info("Clicking 'copy' button");
+          innerButton.click();
+        });
+      });
+      ok(true, "Username is on clipboard now");
+
+      await ContentTask.spawn(browser, testObj, async function(aTestObj) {
+        let loginItem = content.document.querySelector("login-item");
+        let copyButton = loginItem.shadowRoot.querySelector(aTestObj.copyButtonSelector);
+        ok(copyButton.hasAttribute("copied"), "Success message should be shown");
+        await ContentTaskUtils.waitForCondition(() => !copyButton.hasAttribute("copied"),
+          "'copied' attribute should be removed after a timeout");
+      });
+    }
+  });
+});