Bug 936026 - Test autofilling logins in documents restored from bfcache. r=jaws
☠☠ backed out by 77453788170e ☠ ☠
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Mon, 18 Mar 2019 19:43:47 +0000
changeset 465157 d06cbdecb3890be89b7f514ba0612650dc929065
parent 465156 e4044386c8ae00a2ac888b73458ccae53a51b172
child 465158 cfa2c6443a6d085a9c1ff5869c1d145c3f99a2f2
push id35732
push useropoprus@mozilla.com
push dateWed, 20 Mar 2019 10:52:37 +0000
treeherdermozilla-central@708979f9c3f3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs936026
milestone68.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 936026 - Test autofilling logins in documents restored from bfcache. r=jaws Differential Revision: https://phabricator.services.mozilla.com/D22213
toolkit/components/passwordmgr/test/mochitest/mochitest.ini
toolkit/components/passwordmgr/test/mochitest/test_autofill_from_bfache.html
--- a/toolkit/components/passwordmgr/test/mochitest/mochitest.ini
+++ b/toolkit/components/passwordmgr/test/mochitest/mochitest.ini
@@ -30,16 +30,18 @@ skip-if = toolkit == 'android' # autocom
 [test_autocomplete_https_upgrade.html]
 skip-if = toolkit == 'android' # autocomplete
 [test_autocomplete_sandboxed.html]
 scheme = https
 skip-if = toolkit == 'android' # autocomplete
 [test_autofill_autocomplete_types.html]
 scheme = https
 skip-if = toolkit == 'android' # bug 1533965
+[test_autofill_from_bfache.html]
+scheme = https
 [test_autofill_highlight.html]
 scheme = https
 skip-if = toolkit == 'android' # Bug 1531185
 [test_autofill_https_upgrade.html]
 skip-if = toolkit == 'android' # Bug 1259768
 [test_autofill_sandboxed.html]
 scheme = https
 skip-if = toolkit == 'android'
new file mode 100644
--- /dev/null
+++ b/toolkit/components/passwordmgr/test/mochitest/test_autofill_from_bfache.html
@@ -0,0 +1,69 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>Test autofilling documents restored from the back/forward cache (bfcache)</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/AddTask.js"></script>
+  <script type="text/javascript" src="pwmgr_common.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<script>
+runChecksAfterCommonInit();
+
+runInParent(function initLogins() {
+  const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
+
+  let login1 = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance(Ci.nsILoginInfo);
+  login1.init("https://example.com", "", null, "autofilled", "pass1", "", "");
+  Services.logins.addLogin(login1);
+});
+
+</script>
+<p id="display"></p>
+
+<div id="content">
+  <a id="next" href="https://example.org/" target="loginWin">Next</a>
+</div>
+
+<pre id="test">
+<script class="testbody" type="text/javascript">
+let win;
+// Check for expected username/password in form.
+function checkACForm(expectedUsername, expectedPassword) {
+  let doc = win.document;
+  let uname = doc.getElementById("form-basic-username");
+  let pword = doc.getElementById("form-basic-password");
+  let formID = uname.parentNode.id;
+  is(uname.value, expectedUsername, "Checking " + formID + " username");
+  is(pword.value, expectedPassword, "Checking " + formID + " password");
+}
+
+add_task(async function test_crossOriginBfcacheRestore() {
+  let processedPromise = promiseFormsProcessed();
+  win = window.open("form_basic.html", "loginWin");
+  await processedPromise;
+  checkACForm("autofilled", "pass1");
+
+  let pageHidePromise = new Promise(resolve => {
+    win.addEventListener("pagehide", resolve, {once: true});
+  });
+  info("Navigate to another page on a different origin");
+  document.getElementById("next").click();
+  let pageHideEvent = await pageHidePromise;
+  await SimpleTest.promiseFocus(win);
+  ok(pageHideEvent.persisted, "First document should have been persisted in bfcache");
+
+  info("go back to the first page (login form)");
+  processedPromise = promiseFormsProcessed();
+  SpecialPowers.wrap(win).history.back();
+  await processedPromise;
+  checkACForm("autofilled", "pass1");
+  win.close();
+});
+</script>
+</pre>
+</body>
+</html>