Bug 936026 - Test autofilling logins in documents restored from bfcache. r=jaws
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Wed, 20 Mar 2019 14:21:59 +0000
changeset 465225 48cd73fc089340f641dab57d6563e66b6738d731
parent 465224 4ce441f87fdf4abc6443ff83d610b2adff4d3885
child 465226 29cd1266e85e48a17bd027b13d87817fc9c1c849
push id112496
push usershindli@mozilla.com
push dateThu, 21 Mar 2019 04:37:39 +0000
treeherdermozilla-inbound@29476d3ca61d [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_bfcache.html
--- a/toolkit/components/passwordmgr/test/mochitest/mochitest.ini
+++ b/toolkit/components/passwordmgr/test/mochitest/mochitest.ini
@@ -30,16 +30,19 @@ 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_bfcache.html]
+scheme = https
+skip-if = toolkit == 'android' # bug 1527403
 [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_bfcache.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>