From eaa3ec75f75f4de9e8a3c05ecfebc6759274e560 Mon Sep 17 00:00:00 2001 From: Ray Lin Date: Tue, 13 Jun 2017 10:29:56 +0800 Subject: [PATCH] Bug 1300995 - Part 2. Add a browser chrome test for form autofill popup footer. r=MattN MozReview-Commit-ID: 7IAp0SzPzmm --HG-- extra : rebase_source : 66ed7625a69524757da4769b068e0b221a0dfaa3 --- .../formautofill/test/browser/browser.ini | 1 + .../browser/browser_autocomplete_footer.js | 60 +++++++++++++++++++ .../test/browser/browser_editProfileDialog.js | 7 --- .../browser_first_time_use_doorhanger.js | 7 --- .../browser/browser_manageProfilesDialog.js | 7 --- .../formautofill/test/browser/head.js | 16 ++++- 6 files changed, 75 insertions(+), 23 deletions(-) create mode 100644 browser/extensions/formautofill/test/browser/browser_autocomplete_footer.js diff --git a/browser/extensions/formautofill/test/browser/browser.ini b/browser/extensions/formautofill/test/browser/browser.ini index f7faa6680f2f..1fc93bb0c3f7 100644 --- a/browser/extensions/formautofill/test/browser/browser.ini +++ b/browser/extensions/formautofill/test/browser/browser.ini @@ -4,6 +4,7 @@ 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] diff --git a/browser/extensions/formautofill/test/browser/browser_autocomplete_footer.js b/browser/extensions/formautofill/test/browser/browser_autocomplete_footer.js new file mode 100644 index 000000000000..c683d6d10d83 --- /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"); + }); +}); diff --git a/browser/extensions/formautofill/test/browser/browser_editProfileDialog.js b/browser/extensions/formautofill/test/browser/browser_editProfileDialog.js index d23d6dabd337..d5bc70321b19 100644 --- a/browser/extensions/formautofill/test/browser/browser_editProfileDialog.js +++ b/browser/extensions/formautofill/test/browser/browser_editProfileDialog.js @@ -1,12 +1,5 @@ "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); diff --git a/browser/extensions/formautofill/test/browser/browser_first_time_use_doorhanger.js b/browser/extensions/formautofill/test/browser/browser_first_time_use_doorhanger.js index c44f9875a836..06fa17a618b4 100644 --- a/browser/extensions/formautofill/test/browser/browser_first_time_use_doorhanger.js +++ b/browser/extensions/formautofill/test/browser/browser_first_time_use_doorhanger.js @@ -4,13 +4,6 @@ const FORM_URL = "http://mochi.test:8888/browser/browser/extensions/formautofill 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"); diff --git a/browser/extensions/formautofill/test/browser/browser_manageProfilesDialog.js b/browser/extensions/formautofill/test/browser/browser_manageProfilesDialog.js index adaa8df17994..f9667c2d7db5 100644 --- a/browser/extensions/formautofill/test/browser/browser_manageProfilesDialog.js +++ b/browser/extensions/formautofill/test/browser/browser_manageProfilesDialog.js @@ -19,13 +19,6 @@ function waitForAddresses() { }); } -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) => { diff --git a/browser/extensions/formautofill/test/browser/head.js b/browser/extensions/formautofill/test/browser/head.js index 4c005f3f6358..855b71c86448 100644 --- a/browser/extensions/formautofill/test/browser/head.js +++ b/browser/extensions/formautofill/test/browser/head.js @@ -1,11 +1,12 @@ -/* 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", @@ -31,6 +32,10 @@ const TEST_ADDRESS_3 = { "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) { @@ -50,3 +55,10 @@ 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)); + } +});