Bug 1303515 - Part 2: Add browser test for autofill update doorhanger. r=lchang
authorsteveck-chung <schung@mozilla.com>
Wed, 14 Jun 2017 18:53:06 +0800
changeset 366938 2854c4f6e026f6b30a68c2efc004a9c3f1ebfd6e
parent 366937 571481e5562ae2321b24ff6d50c35fe7092d1941
child 366939 bf0d8b3a56b77a3e908d545eba10dcb8abf3de74
push id45768
push userryanvm@gmail.com
push dateFri, 30 Jun 2017 13:49:49 +0000
treeherderautoland@bf0d8b3a56b7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslchang
bugs1303515
milestone56.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 1303515 - Part 2: Add browser test for autofill update doorhanger. r=lchang MozReview-Commit-ID: 7FYmaF4QarT
browser/extensions/formautofill/test/browser/browser.ini
browser/extensions/formautofill/test/browser/browser_update_doorhanger.js
--- a/browser/extensions/formautofill/test/browser/browser.ini
+++ b/browser/extensions/formautofill/test/browser/browser.ini
@@ -6,8 +6,9 @@ support-files =
 
 [browser_autocomplete_footer.js]
 [browser_check_installed.js]
 [browser_editProfileDialog.js]
 [browser_first_time_use_doorhanger.js]
 [browser_privacyPreferences.js]
 [browser_manageProfilesDialog.js]
 [browser_submission_in_private_mode.js]
+[browser_update_doorhanger.js]
new file mode 100644
--- /dev/null
+++ b/browser/extensions/formautofill/test/browser/browser_update_doorhanger.js
@@ -0,0 +1,120 @@
+"use strict";
+
+const FORM_URL = "http://mochi.test:8888/browser/browser/extensions/formautofill/test/browser/autocomplete_basic.html";
+
+add_task(async function test_update_address() {
+  await saveAddress(TEST_ADDRESS_1);
+  let addresses = await getAddresses();
+  is(addresses.length, 1, "1 address in storage");
+
+  await BrowserTestUtils.withNewTab({gBrowser, url: FORM_URL},
+    async function(browser) {
+      let promiseShown = BrowserTestUtils.waitForEvent(PopupNotifications.panel,
+                                                       "popupshown");
+      await ContentTask.spawn(browser, null, async function() {
+        content.document.querySelector("form #organization").focus();
+      });
+
+      await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
+      await expectPopupOpen(browser);
+      await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
+      await BrowserTestUtils.synthesizeKey("VK_RETURN", {}, browser);
+
+      await ContentTask.spawn(browser, null, async function() {
+        let form = content.document.getElementById("form");
+        let org = form.querySelector("#organization");
+        await new Promise(resolve => setTimeout(resolve, 1000));
+        org.value = "Mozilla";
+
+        // Wait 1000ms before submission to make sure the input value applied
+        await new Promise(resolve => setTimeout(resolve, 1000));
+        form.querySelector("input[type=submit]").click();
+      });
+
+      await promiseShown;
+      let notificationElement = PopupNotifications.panel.firstChild;
+      notificationElement.button.click();
+    }
+  );
+
+  addresses = await getAddresses();
+  is(addresses.length, 1, "Still 1 address in storage");
+  is(addresses[0].organization, "Mozilla", "Verify the organization field");
+});
+
+add_task(async function test_create_new_address() {
+  let addresses = await getAddresses();
+  is(addresses.length, 1, "1 address in storage");
+
+  await BrowserTestUtils.withNewTab({gBrowser, url: FORM_URL},
+    async function(browser) {
+      let promiseShown = BrowserTestUtils.waitForEvent(PopupNotifications.panel,
+                                                       "popupshown");
+      await ContentTask.spawn(browser, null, async function() {
+        content.document.querySelector("form #tel").focus();
+      });
+
+      await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
+      await expectPopupOpen(browser);
+      await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
+      await BrowserTestUtils.synthesizeKey("VK_RETURN", {}, browser);
+
+      await ContentTask.spawn(browser, null, async function() {
+        let form = content.document.getElementById("form");
+        let tel = form.querySelector("#tel");
+        await new Promise(resolve => setTimeout(resolve, 1000));
+        tel.value = "+1-234-567-890";
+
+        // Wait 1000ms before submission to make sure the input value applied
+        await new Promise(resolve => setTimeout(resolve, 1000));
+        form.querySelector("input[type=submit]").click();
+      });
+
+      await promiseShown;
+      let notificationElement = PopupNotifications.panel.firstChild;
+      notificationElement.secondaryButton.click();
+    }
+  );
+
+  addresses = await getAddresses();
+  is(addresses.length, 2, "2 addresses in storage");
+  is(addresses[1].tel, "+1-234-567-890", "Verify the tel field");
+});
+
+add_task(async function test_create_new_address_merge() {
+  let addresses = await getAddresses();
+  is(addresses.length, 2, "2 address in storage");
+
+  await BrowserTestUtils.withNewTab({gBrowser, url: FORM_URL},
+    async function(browser) {
+      let promiseShown = BrowserTestUtils.waitForEvent(PopupNotifications.panel,
+                                                       "popupshown");
+      await ContentTask.spawn(browser, null, async function() {
+        content.document.querySelector("form #tel").focus();
+      });
+
+      await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
+      await expectPopupOpen(browser);
+      await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
+      await BrowserTestUtils.synthesizeKey("VK_RETURN", {}, browser);
+
+      // Choose the latest address and revert to the original phone number
+      await ContentTask.spawn(browser, null, async function() {
+        let form = content.document.getElementById("form");
+        let tel = form.querySelector("#tel");
+        tel.value = "+1 617 253 5702";
+
+        // Wait 1000ms before submission to make sure the input value applied
+        await new Promise(resolve => setTimeout(resolve, 1000));
+        form.querySelector("input[type=submit]").click();
+      });
+
+      await promiseShown;
+      let notificationElement = PopupNotifications.panel.firstChild;
+      notificationElement.secondaryButton.click();
+    }
+  );
+
+  addresses = await getAddresses();
+  is(addresses.length, 2, "Still 2 addresses in storage");
+});