Bug 1303510 - Part 2: Add browser test for doorhanger part, r?MattN draft
authorsteveck-chung <schung@mozilla.com>
Thu, 25 May 2017 11:12:52 +0800
changeset 591556 035be0582f32bdd0190a4d705bb89cc2442e9ca0
parent 591555 d03f30933a53f0f5c8b60489453129cc6f8bb2d0
child 591557 5d70396cdb999caba6532d2bfcd236278c52e415
push id63085
push userbmo:schung@mozilla.com
push dateFri, 09 Jun 2017 06:50:48 +0000
reviewersMattN
bugs1303510
milestone55.0a1
Bug 1303510 - Part 2: Add browser test for doorhanger part, r?MattN MozReview-Commit-ID: LKFuW3e5scm
browser/extensions/formautofill/test/browser/browser.ini
browser/extensions/formautofill/test/browser/browser_first_time_use_doorhanger.js
--- a/browser/extensions/formautofill/test/browser/browser.ini
+++ b/browser/extensions/formautofill/test/browser/browser.ini
@@ -1,11 +1,12 @@
 [DEFAULT]
 head = head.js
 
 support-files =
   ../fixtures/autocomplete_basic.html
 
 [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]
new file mode 100644
--- /dev/null
+++ b/browser/extensions/formautofill/test/browser/browser_first_time_use_doorhanger.js
@@ -0,0 +1,79 @@
+"use strict";
+
+const FORM_URL = "http://mochi.test:8888/browser/browser/extensions/formautofill/test/browser/autocomplete_basic.html";
+const FTU_PREF = "extensions.formautofill.firstTimeUse";
+const ENABLED_PREF = "extensions.formautofill.addresses.enabled";
+
+registerCleanupFunction(async function() {
+  let addresses = await getAddresses();
+  if (addresses.length) {
+    await removeAddresses(addresses.map(address => address.guid));
+  }
+});
+
+add_task(async function test_first_time_save() {
+  let addresses = await getAddresses();
+  is(addresses.length, 0, "No profile in storage");
+  await SpecialPowers.pushPrefEnv({
+    "set": [
+      [FTU_PREF, true],
+      [ENABLED_PREF, true],
+    ],
+  });
+
+  await BrowserTestUtils.withNewTab({gBrowser, url: FORM_URL},
+    async function(browser) {
+      let promiseShown = BrowserTestUtils.waitForEvent(PopupNotifications.panel,
+                                                       "popupshown");
+      let tabPromise = BrowserTestUtils.waitForNewTab(gBrowser, "about:preferences#privacy");
+      await ContentTask.spawn(browser, null, async function() {
+        content.document.getElementById("organization").focus();
+        content.document.getElementById("organization").value = "Sesame Street";
+        content.document.getElementById("street-address").value = "123 Sesame Street";
+        content.document.getElementById("tel").value = "1-345-345-3456";
+
+        content.document.querySelector("input[type=submit]").click();
+      });
+
+      await promiseShown;
+      let notificationElement = PopupNotifications.panel.firstChild;
+      // Open the panel via link
+      let link = notificationElement.querySelector("popupnotificationcontent label");
+      link.click();
+      let tab = await tabPromise;
+      ok(tab, "Privacy panel opened");
+      await BrowserTestUtils.removeTab(tab);
+    }
+  );
+
+  addresses = await getAddresses();
+  is(addresses.length, 1, "Profile saved");
+  let ftuPref = SpecialPowers.getBoolPref(FTU_PREF);
+  is(ftuPref, false, "First time use flag is false");
+});
+
+add_task(async function test_non_first_time_save() {
+  let addresses = await getAddresses();
+  let ftuPref = SpecialPowers.getBoolPref(FTU_PREF);
+  is(ftuPref, false, "First time use flag is false");
+  is(addresses.length, 1, "1 address in storage");
+
+  await BrowserTestUtils.withNewTab({gBrowser, url: FORM_URL},
+    async function(browser) {
+      await ContentTask.spawn(browser, null, async function() {
+        content.document.getElementById("organization").focus();
+        content.document.getElementById("organization").value = "Mozilla";
+        content.document.getElementById("street-address").value = "331 E. Evelyn Avenue";
+        content.document.getElementById("tel").value = "1-650-903-0800";
+
+        content.document.querySelector("input[type=submit]").click();
+      });
+
+      await new Promise(resolve => setTimeout(resolve, 1000));
+      is(PopupNotifications.panel.state, "closed", "Doorhanger is hidden");
+    }
+  );
+
+  addresses = await getAddresses();
+  is(addresses.length, 2, "Another address saved");
+});