Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: os == 'android'
- Manifest: toolkit/components/passwordmgr/test/mochitest/mochitest.toml
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test autofill on username-form</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="pwmgr_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
Test autofill on username-form
<script>
add_setup(async () => {
await setStoredLoginsAsync(
);
});
add_task(async function test_autofill_username_only_form() {
await loadRecipes({
siteRecipes: [{
hosts: ["mochi.test:8888"],
notUsernameSelector: "input[name='shouldnotfill']",
}],
});
let win = window.open("about:blank");
SimpleTest.registerCleanupFunction(() => win.close());
// 6 out of the 10 forms should be autofilled
await loadFormIntoWindow(window.location.origin, `
<input type='text' name='uname' autocomplete='username' value=''>
<button type='submit'>Submit</button>
<button type='reset'> Reset </button>
</form>
<!-- no password field, 1 username field, with a value set -->
<input type='text' name='uname' autocomplete='username' value='someuser'>
<button type='submit'>Submit</button>
<button type='reset'> Reset </button>
</form>
<!-- no password field, 2 username fields, should be ignored -->
<input type='text' name='uname1' autocomplete='username' value=''>
<input type='text' name='uname2' autocomplete='username' value=''>
<button type='submit'>Submit</button>
<button type='reset'> Reset </button>
</form>
<!-- no password field, 1 username field, too small for the username login -->
<input type='text' name='uname' value='' maxlength="4" autocomplete='username'>
<button type='submit'>Submit</button>
<button type='reset'> Reset </button>
</form>
<!-- no password field, 1 username field, too small for the username login -->
<input type='text' name='uname' value='' maxlength="0" autocomplete='username'>
<button type='submit'>Submit</button>
<button type='reset'> Reset </button>
</form>
<!-- no password field, 1 text input field (not a username-only form), should be ignored -->
<input type='text' name='uname' value=''>
<button type='submit'>Submit</button>
<button type='reset'> Reset </button>
</form>
<!-- no password field, 1 username field that matches notUsernameSelector recipe -->
<input type='text' name='shouldnotfill' autocomplete='username' value=''>
<button type='submit'>Submit</button>
<button type='reset'> Reset </button>
</form>
<!-- no form, one text input field (without autocomplete == 'username'), should be ignored -->
<div id="form8"> 8
<input id='un1' name='shouldnotfill' placeholder=username value= ''>
</div>
<!-- no password field, 1 username field without autocomplete-->
<input type="text" id="username" name='uname' value=''>
</form>
<!-- no form, two text input fields with autcomplete == 'username', should be ignored -->
<div id='form10'> 10
<input name='shouldnotfill' autocomplete=username value = ''>
<input name='shouldnotfill' autocomplete=username value = ''>
</div>`, win, 6);
await checkLoginFormInFrameWithElementValues(win, 1, "user1");
await checkLoginFormInFrameWithElementValues(win, 2, "someuser");
await checkUnmodifiedFormInFrame(win, 3);
await checkUnmodifiedFormInFrame(win, 4);
await checkUnmodifiedFormInFrame(win, 5);
await checkUnmodifiedFormInFrame(win, 6);
await checkUnmodifiedFormInFrame(win, 7);
await checkUnmodifiedFormInFrame(win, 8);
await checkLoginFormInFrameWithElementValues(win, 9, "user1");
await checkUnmodifiedFormInFrame(win, 10);
// We must close and reopen the window since multiple formless inputs in one document are grouped together,
// which won't trigger autofill.
win.close()
win = window.open("about:blank");
await loadFormIntoWindow(window.location.origin, `
<!-- no form, 1 username field with autocomplete, without a value set -->
<div id='form1'> 1
<input type='text' name='uname' autocomplete='username' value=''>
</div>`, win, 1);
await checkLoginFormInFrameWithElementValues(win, 1, "user2");
await resetRecipes();
});
</script>
<p id="display"></p>
<div id="content"></div>
<pre id="test"></pre>
</pre>
</body>
</html>