Bug 1348791 - Add a test for autocomplete master password timeout. r=MattN draft
authorJohann Hofmann <jhofmann@mozilla.com>
Mon, 08 May 2017 06:20:45 -0400
changeset 574093 9c7aa29301e06816a7d9fcf91a7511d46418bb1f
parent 574092 6f4d2c59360963f53972b812d999756637434415
child 627485 f99ec1ab1e259754227c2c0773064e441acb2231
push id57587
push userbmo:jhofmann@mozilla.com
push dateMon, 08 May 2017 10:32:42 +0000
reviewersMattN
bugs1348791
milestone55.0a1
Bug 1348791 - Add a test for autocomplete master password timeout. r=MattN MozReview-Commit-ID: GTZQhI4VUv8
toolkit/components/passwordmgr/test/browser/browser.ini
toolkit/components/passwordmgr/test/browser/browser_master_password_autocomplete.js
--- a/toolkit/components/passwordmgr/test/browser/browser.ini
+++ b/toolkit/components/passwordmgr/test/browser/browser.ini
@@ -49,16 +49,17 @@ support-files =
 [browser_exceptions_dialog.js]
 [browser_formless_submit_chrome.js]
 [browser_hasInsecureLoginForms.js]
 [browser_hasInsecureLoginForms_streamConverter.js]
 [browser_http_autofill.js]
 [browser_insecurePasswordConsoleWarning.js]
 support-files =
   form_cross_origin_insecure_action.html
+[browser_master_password_autocomplete.js]
 [browser_notifications.js]
 [browser_notifications_username.js]
 [browser_notifications_password.js]
 [browser_notifications_2.js]
 skip-if = os == "linux" # Bug 1272849 Main action button disabled state intermittent
 [browser_passwordmgr_editing.js]
 skip-if = os == "linux"
 [browser_context_menu.js]
new file mode 100644
--- /dev/null
+++ b/toolkit/components/passwordmgr/test/browser/browser_master_password_autocomplete.js
@@ -0,0 +1,59 @@
+const HOST = "https://example.com";
+const URL = HOST + "/browser/toolkit/components/passwordmgr/test/browser/form_basic.html";
+const TIMEOUT_PREF = "signon.masterPasswordReprompt.timeout_ms";
+
+// Waits for the master password prompt and cancels it.
+function waitForDialog() {
+  let dialogShown = TestUtils.topicObserved("common-dialog-loaded");
+  return dialogShown.then(function([subject]) {
+    let dialog = subject.Dialog;
+    is(dialog.args.title, "Password Required");
+    dialog.ui.button1.click();
+  });
+}
+
+// Test that autocomplete does not trigger a master password prompt
+// for a certain time after it was cancelled.
+add_task(function* test_mpAutocompleteTimeout() {
+  let login = LoginTestUtils.testData.formLogin({
+    hostname: "https://example.com",
+    formSubmitURL: "https://example.com",
+    username: "username",
+    password: "password",
+  });
+  Services.logins.addLogin(login);
+  LoginTestUtils.masterPassword.enable();
+
+  registerCleanupFunction(function() {
+    LoginTestUtils.masterPassword.disable();
+    Services.logins.removeAllLogins();
+  });
+
+  // Set master password prompt timeout to 3s.
+  // If this test goes intermittent, you likely have to increase this value.
+  yield SpecialPowers.pushPrefEnv({set: [[TIMEOUT_PREF, 3000]]});
+
+  // Wait for initial master password dialog after opening the tab.
+  let dialogShown = waitForDialog();
+
+  yield BrowserTestUtils.withNewTab(URL, function*(browser) {
+    yield dialogShown;
+
+    yield ContentTask.spawn(browser, null, function*() {
+      // Focus the password field to trigger autocompletion.
+      content.document.getElementById("form-basic-password").focus();
+    });
+
+    // Wait 4s, dialog should not have been shown
+    // (otherwise the code below will not work).
+    yield new Promise((c) => setTimeout(c, 4000));
+
+    dialogShown = waitForDialog();
+    yield ContentTask.spawn(browser, null, function*() {
+      // Re-focus the password field to trigger autocompletion.
+      content.document.getElementById("form-basic-username").focus();
+      content.document.getElementById("form-basic-password").focus();
+    });
+    yield dialogShown;
+  });
+});