Bug 1378754 - Test that autofill and login fields remain marked after a persisted pagehide. r=steveck
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Fri, 21 Jul 2017 23:00:10 -0700
changeset 419656 d9fa2317c55a6480e534f6264a92042fea9cc2df
parent 419655 b5a0702e2572a8d87541903a11dabd2b238c412e
child 419657 6a64e20610de04a40803749b446e48c2f39f79bd
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssteveck
bugs1378754
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 1378754 - Test that autofill and login fields remain marked after a persisted pagehide. r=steveck MozReview-Commit-ID: 5FTGiu8Lb9Q
browser/extensions/formautofill/test/browser/browser.ini
browser/extensions/formautofill/test/browser/browser_autocomplete_marked_back_forward.js
browser/extensions/formautofill/test/browser/browser_autocomplete_marked_detached_tab.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,14 +1,16 @@
 [DEFAULT]
 head = head.js
 
 support-files =
   ../fixtures/autocomplete_basic.html
 
 [browser_autocomplete_footer.js]
+[browser_autocomplete_marked_back_forward.js]
+[browser_autocomplete_marked_detached_tab.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_autocomplete_marked_back_forward.js
@@ -0,0 +1,61 @@
+/**
+ * Test that autofill autocomplete works after back/forward navigation
+ */
+
+"use strict";
+
+const URL = BASE_URL + "autocomplete_basic.html";
+
+function checkPopup(autoCompletePopup) {
+  let first = autoCompletePopup.view.results[0];
+  const {primary, secondary} = JSON.parse(first.label);
+  ok(primary.startsWith(TEST_ADDRESS_1["street-address"].split("\n")[0]),
+     "Check primary label is street address");
+  is(secondary, TEST_ADDRESS_1["address-level2"], "Check secondary label is address-level2");
+}
+
+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_back_forward() {
+  await BrowserTestUtils.withNewTab({gBrowser, url: URL}, async function(browser) {
+    const {autoCompletePopup} = browser;
+
+    // Check the page after the initial load
+    await openPopupOn(browser, "#street-address");
+    checkPopup(autoCompletePopup);
+
+    // Now navigate forward and make sure autofill autocomplete results are still attached
+    let loadPromise = BrowserTestUtils.browserLoaded(browser);
+    await BrowserTestUtils.loadURI(browser, `${URL}?load=2`);
+    await loadPromise;
+
+    // Check the second page
+    await openPopupOn(browser, "#street-address");
+    checkPopup(autoCompletePopup);
+
+    // Check after hitting back to the first page
+    let stoppedPromise = BrowserTestUtils.browserStopped(browser);
+    browser.goBack();
+    await stoppedPromise;
+    await openPopupOn(browser, "#street-address");
+    checkPopup(autoCompletePopup);
+
+    // Check after hitting forward to the second page
+    stoppedPromise = BrowserTestUtils.browserStopped(browser);
+    browser.goForward();
+    await stoppedPromise;
+    await openPopupOn(browser, "#street-address");
+    checkPopup(autoCompletePopup);
+
+    // 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,
+                                            "popup should have closed");
+  });
+});
new file mode 100644
--- /dev/null
+++ b/browser/extensions/formautofill/test/browser/browser_autocomplete_marked_detached_tab.js
@@ -0,0 +1,54 @@
+/**
+ * Test that autofill autocomplete works after detaching a tab
+ */
+
+"use strict";
+
+const URL = BASE_URL + "autocomplete_basic.html";
+
+function checkPopup(autoCompletePopup) {
+  let first = autoCompletePopup.view.results[0];
+  const {primary, secondary} = JSON.parse(first.label);
+  ok(primary.startsWith(TEST_ADDRESS_1["street-address"].split("\n")[0]),
+     "Check primary label is street address");
+  is(secondary, TEST_ADDRESS_1["address-level2"], "Check secondary label is address-level2");
+}
+
+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_detach_tab_marked() {
+  await BrowserTestUtils.withNewTab({gBrowser, url: URL}, async function(browser) {
+    const {autoCompletePopup} = browser;
+
+    // Check the page after the initial load
+    await openPopupOn(browser, "#street-address");
+    checkPopup(autoCompletePopup);
+
+    // Detach the tab to a new window
+    let newWin = gBrowser.replaceTabWithWindow(gBrowser.getTabForBrowser(browser));
+    await TestUtils.topicObserved("browser-delayed-startup-finished", subject => {
+      return subject == newWin;
+    });
+
+    info("tab was detached");
+    let newBrowser = newWin.gBrowser.selectedBrowser;
+    ok(newBrowser, "Found new <browser>");
+    let newAutoCompletePopup = newBrowser.autoCompletePopup;
+    ok(newAutoCompletePopup, "Found new autocomplete popup");
+
+    await openPopupOn(newBrowser, "#street-address");
+    checkPopup(newAutoCompletePopup);
+
+    // Ensure the popup is closed before entering the next test.
+    await ContentTask.spawn(newBrowser, {}, async function() {
+      content.document.getElementById("street-address").blur();
+    });
+    await BrowserTestUtils.waitForCondition(() => !newAutoCompletePopup.popupOpen,
+                                           "popup should have closed");
+    await BrowserTestUtils.closeWindow(newWin);
+  });
+});
--- a/browser/extensions/formautofill/test/browser/head.js
+++ b/browser/extensions/formautofill/test/browser/head.js
@@ -39,27 +39,29 @@ const SECONDARY_BUTTON_INDEX = 1;
 async function sleep(ms = 500) {
   await new Promise(resolve => setTimeout(resolve, ms));
 }
 
 async function expectPopupOpen(browser) {
   const {autoCompletePopup, autoCompletePopup: {richlistbox: itemsBox}} = browser;
   const listItemElems = itemsBox.querySelectorAll(".autocomplete-richlistitem");
 
-  await BrowserTestUtils.waitForCondition(() => autoCompletePopup.popupOpen);
+  await BrowserTestUtils.waitForCondition(() => autoCompletePopup.popupOpen,
+                                         "popup should be open");
   await BrowserTestUtils.waitForCondition(() => {
     return [...listItemElems].every(item => {
       return (item.getAttribute("originaltype") == "autofill-profile" ||
              item.getAttribute("originaltype") == "autofill-footer") &&
              item.hasAttribute("formautofillattached");
     });
-  });
+  }, "The popup should be a form autofill one");
 }
 
 async function openPopupOn(browser, selector) {
+  await SimpleTest.promiseFocus(browser);
   /* 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);
 }