Bug 1300995 - Part 2. Add a browser chrome test for form autofill popup footer. r=MattN
☠☠ backed out by f881b39e669d ☠ ☠
authorRay Lin <ralin@mozilla.com>
Tue, 13 Jun 2017 10:29:56 +0800
changeset 415310 cc5161b809a01203bb5dce841c963824b6f451ca
parent 415309 c104436d1937cf3695b972238eab7b8ae3452df9
child 415311 610b983f605ea76b6bf5358da438ae6087abbff9
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs1300995
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 1300995 - Part 2. Add a browser chrome test for form autofill popup footer. r=MattN MozReview-Commit-ID: 7IAp0SzPzmm
browser/extensions/formautofill/test/browser/browser.ini
browser/extensions/formautofill/test/browser/browser_autocomplete_footer.js
browser/extensions/formautofill/test/browser/browser_editProfileDialog.js
browser/extensions/formautofill/test/browser/browser_first_time_use_doorhanger.js
browser/extensions/formautofill/test/browser/browser_manageProfilesDialog.js
browser/extensions/formautofill/test/browser/head.js
--- a/browser/extensions/formautofill/test/browser/browser.ini
+++ b/browser/extensions/formautofill/test/browser/browser.ini
@@ -1,12 +1,13 @@
 [DEFAULT]
 head = head.js
 
 support-files =
   ../fixtures/autocomplete_basic.html
 
+[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]
new file mode 100644
--- /dev/null
+++ b/browser/extensions/formautofill/test/browser/browser_autocomplete_footer.js
@@ -0,0 +1,60 @@
+"use strict";
+
+const URL = BASE_URL + "autocomplete_basic.html";
+const PRIVACY_PREF_URL = "about:preferences#privacy";
+
+add_task(async function setup_storage() {
+  await saveAddress(TEST_ADDRESS_1);
+  await saveAddress(TEST_ADDRESS_2);
+  await saveAddress(TEST_ADDRESS_3);
+});
+
+add_task(async function test_click_on_footer() {
+  await BrowserTestUtils.withNewTab({gBrowser, url: URL}, async function(browser) {
+    const {autoCompletePopup, autoCompletePopup: {richlistbox: itemsBox}} = browser;
+
+    await ContentTask.spawn(browser, {}, async function() {
+      content.document.getElementById("organization").focus();
+    });
+    await sleep(2000);
+    await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
+    await BrowserTestUtils.waitForCondition(() => autoCompletePopup.popupOpen);
+
+    // Click on the footer
+    const listItemElems = itemsBox.querySelectorAll(".autocomplete-richlistitem");
+    const prefTabPromise = BrowserTestUtils.waitForNewTab(gBrowser, PRIVACY_PREF_URL);
+    await EventUtils.synthesizeMouseAtCenter(listItemElems[listItemElems.length - 1], {});
+    await BrowserTestUtils.removeTab(await prefTabPromise);
+    ok(true, "Tab: preferences#privacy was successfully opened by clicking on the footer");
+
+    // Ensure the popup is closed before entering the next test.
+    await ContentTask.spawn(browser, {}, async function() {
+      content.document.getElementById("organization").blur();
+    });
+    await BrowserTestUtils.waitForCondition(() => !autoCompletePopup.popupOpen);
+  });
+});
+
+add_task(async function test_press_enter_on_footer() {
+  await BrowserTestUtils.withNewTab({gBrowser, url: URL}, async function(browser) {
+    const {autoCompletePopup, autoCompletePopup: {richlistbox: itemsBox}} = browser;
+
+    await ContentTask.spawn(browser, {}, async function() {
+      const input = content.document.getElementById("organization");
+      input.focus();
+    });
+    await sleep(2000);
+    await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
+    await BrowserTestUtils.waitForCondition(() => autoCompletePopup.popupOpen);
+
+    // Navigate to the footer and press enter.
+    const listItemElems = itemsBox.querySelectorAll(".autocomplete-richlistitem");
+    const prefTabPromise = BrowserTestUtils.waitForNewTab(gBrowser, PRIVACY_PREF_URL);
+    for (let i = 0; i < listItemElems.length; i++) {
+      await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
+    }
+    await BrowserTestUtils.synthesizeKey("VK_RETURN", {}, browser);
+    await BrowserTestUtils.removeTab(await prefTabPromise);
+    ok(true, "Tab: preferences#privacy was successfully opened by pressing enter on the footer");
+  });
+});
--- a/browser/extensions/formautofill/test/browser/browser_editProfileDialog.js
+++ b/browser/extensions/formautofill/test/browser/browser_editProfileDialog.js
@@ -1,17 +1,10 @@
 "use strict";
 
-registerCleanupFunction(async function() {
-  let addresses = await getAddresses();
-  if (addresses.length) {
-    await removeAddresses(addresses.map(address => address.guid));
-  }
-});
-
 add_task(async function test_cancelEditProfileDialog() {
   await new Promise(resolve => {
     let win = window.openDialog(EDIT_PROFILE_DIALOG_URL, null, null, null);
     win.addEventListener("load", () => {
       win.addEventListener("unload", () => {
         ok(true, "Edit profile dialog is closed");
         resolve();
       }, {once: true});
--- a/browser/extensions/formautofill/test/browser/browser_first_time_use_doorhanger.js
+++ b/browser/extensions/formautofill/test/browser/browser_first_time_use_doorhanger.js
@@ -1,21 +1,14 @@
 "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],
     ],
--- a/browser/extensions/formautofill/test/browser/browser_manageProfilesDialog.js
+++ b/browser/extensions/formautofill/test/browser/browser_manageProfilesDialog.js
@@ -14,23 +14,16 @@ function waitForAddresses() {
     Services.cpmm.addMessageListener("FormAutofill:Addresses", function getResult(result) {
       Services.cpmm.removeMessageListener("FormAutofill:Addresses", getResult);
       // Wait for the next tick for elements to get rendered.
       SimpleTest.executeSoon(resolve.bind(null, result.data));
     });
   });
 }
 
-registerCleanupFunction(async function() {
-  let addresses = await getAddresses();
-  if (addresses.length) {
-    await removeAddresses(addresses.map(address => address.guid));
-  }
-});
-
 add_task(async function test_manageProfilesInitialState() {
   await BrowserTestUtils.withNewTab({gBrowser, url: MANAGE_PROFILES_DIALOG_URL}, async function(browser) {
     await ContentTask.spawn(browser, TEST_SELECTORS, (args) => {
       let selAddresses = content.document.querySelector(args.selAddresses);
       let btnRemove = content.document.querySelector(args.btnRemove);
       let btnEdit = content.document.querySelector(args.btnEdit);
       let btnAdd = content.document.querySelector(args.btnAdd);
 
--- a/browser/extensions/formautofill/test/browser/head.js
+++ b/browser/extensions/formautofill/test/browser/head.js
@@ -1,16 +1,17 @@
-/* exported MANAGE_PROFILES_DIALOG_URL, EDIT_PROFILE_DIALOG_URL,
+/* exported MANAGE_PROFILES_DIALOG_URL, EDIT_PROFILE_DIALOG_URL, BASE_URL,
             TEST_ADDRESS_1, TEST_ADDRESS_2, TEST_ADDRESS_3,
-            getAddresses, saveAddress, removeAddresses */
+            sleep, getAddresses, saveAddress, removeAddresses */
 
 "use strict";
 
 const MANAGE_PROFILES_DIALOG_URL = "chrome://formautofill/content/manageProfiles.xhtml";
 const EDIT_PROFILE_DIALOG_URL = "chrome://formautofill/content/editProfile.xhtml";
+const BASE_URL = "http://mochi.test:8888/browser/browser/extensions/formautofill/test/browser/";
 
 const TEST_ADDRESS_1 = {
   "given-name": "John",
   "additional-name": "R.",
   "family-name": "Smith",
   organization: "World Wide Web Consortium",
   "street-address": "32 Vassar Street\nMIT Room 32-G524",
   "address-level2": "Cambridge",
@@ -26,16 +27,20 @@ const TEST_ADDRESS_2 = {
   country: "US",
 };
 
 const TEST_ADDRESS_3 = {
   "street-address": "Other Address",
   "postal-code": "12345",
 };
 
+async function sleep(ms = 500) {
+  await new Promise(resolve => setTimeout(resolve, ms));
+}
+
 function getAddresses() {
   return new Promise(resolve => {
     Services.cpmm.addMessageListener("FormAutofill:Addresses", function getResult(result) {
       Services.cpmm.removeMessageListener("FormAutofill:Addresses", getResult);
       resolve(result.data);
     });
     Services.cpmm.sendAsyncMessage("FormAutofill:GetAddresses", {});
   });
@@ -45,8 +50,15 @@ function saveAddress(address) {
   Services.cpmm.sendAsyncMessage("FormAutofill:SaveAddress", {address});
   return TestUtils.topicObserved("formautofill-storage-changed");
 }
 
 function removeAddresses(guids) {
   Services.cpmm.sendAsyncMessage("FormAutofill:RemoveAddresses", {guids});
   return TestUtils.topicObserved("formautofill-storage-changed");
 }
+
+registerCleanupFunction(async function() {
+  let addresses = await getAddresses();
+  if (addresses.length) {
+    await removeAddresses(addresses.map(address => address.guid));
+  }
+});