Bug 1329628 - Part 2. Add a browser chrome test for phishing warning text. r=MattN
MozReview-Commit-ID: CkOxp2SKEI8
--- a/browser/extensions/formautofill/test/browser/browser_autocomplete_footer.js
+++ b/browser/extensions/formautofill/test/browser/browser_autocomplete_footer.js
@@ -1,60 +1,87 @@
"use strict";
const URL = BASE_URL + "autocomplete_basic.html";
const PRIVACY_PREF_URL = "about:preferences#privacy";
+async function expectWarningText(browser, expectedText) {
+ const {autoCompletePopup: {richlistbox: itemsBox}} = browser;
+ const warningBox = itemsBox.querySelector(".autocomplete-richlistitem:last-child")._warningTextBox;
+
+ await BrowserTestUtils.waitForCondition(() => {
+ return warningBox.textContent == expectedText;
+ }, `Waiting for expected warning text: ${expectedText}, Got ${warningBox.textContent}`);
+ ok(true, `Got expected warning text: ${expectedText}`);
+}
+
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 expectPopupOpen(browser);
-
+ await openPopupOn(browser, "#organization");
// Click on the footer
- const listItemElems = itemsBox.querySelectorAll(".autocomplete-richlistitem");
+ const optionButton = itemsBox.querySelector(".autocomplete-richlistitem:last-child")._optionButton;
const prefTabPromise = BrowserTestUtils.waitForNewTab(gBrowser, PRIVACY_PREF_URL);
- await EventUtils.synthesizeMouseAtCenter(listItemElems[listItemElems.length - 1], {});
+ await EventUtils.synthesizeMouseAtCenter(optionButton, {});
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: {richlistbox: itemsBox}} = 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 expectPopupOpen(browser);
-
+ await openPopupOn(browser, "#organization");
// 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");
+
+ // 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_phishing_warning() {
+ await BrowserTestUtils.withNewTab({gBrowser, url: URL}, async function(browser) {
+ const {autoCompletePopup, autoCompletePopup: {richlistbox: itemsBox}} = browser;
+
+ await openPopupOn(browser, "#street-address");
+ const warningBox = itemsBox.querySelector(".autocomplete-richlistitem:last-child")._warningTextBox;
+ ok(warningBox, "Got phishing warning box");
+ await expectWarningText(browser, "Also fill company, address, phone, email");
+ await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
+ await expectWarningText(browser, "Also fill company, phone, email");
+ await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
+ await expectWarningText(browser, "Fill address");
+ await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
+ await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
+ await expectWarningText(browser, "Also fill company, address, phone, email");
+
+ // Ensure the popup is closed before entering the next test.
+ await ContentTask.spawn(browser, {}, async function() {
+ content.document.getElementById("street-address").blur();
+ });
+ await BrowserTestUtils.waitForCondition(() => !autoCompletePopup.popupOpen);
+ });
+});
--- 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, BASE_URL,
TEST_ADDRESS_1, TEST_ADDRESS_2, TEST_ADDRESS_3,
- sleep, expectPopupOpen, getAddresses, saveAddress, removeAddresses */
+ sleep, expectPopupOpen, openPopupOn,
+ 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 = {
@@ -45,16 +46,26 @@ async function expectPopupOpen(browser)
return [...listItemElems].every(item => {
return (item.getAttribute("originaltype") == "autofill-profile" ||
item.getAttribute("originaltype") == "autofill-footer") &&
item.hasAttribute("formautofillattached");
});
});
}
+async function openPopupOn(browser, selector) {
+ /* eslint no-shadow: ["error", { "allow": ["selector"] }] */
+ await ContentTask.spawn(browser, {selector}, async function({selector}) {
+ content.document.querySelector(selector).focus();
+ });
+ await sleep(2000);
+ await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
+ await expectPopupOpen(browser);
+}
+
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", {});
});