Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a bunch of test cases for autofill autoprompt #89

Merged
merged 2 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions autofill/autoprompt/case-1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Autofill autoprompt for signin forms</title>
<link rel="stylesheet" href="../style.css" />
</head>

<body>
<p><a href="../index.html">[Home]</a></p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't work because we are two levels deep (autofill/autoprompt/). Same for all test case pages.

<nav>
<ul class="nav">
<li><a href="./case-1.html">Case 1</a></li>
<li><a href="./case-2.html">Case 2</a></li>
<li><a href="./case-3.html">Case 3</a></li>
<li><a href="./case-4.html">Case 4</a></li>
<li><a href="./case-5.html">Case 5</a></li>
</ul>
</nav>

<p id="demo"></p>

<div class="">
<p>Sign in form present on pageload (<b>should prompt automatically</b>).</p>

<div class="dialog">
<form id="click-form" novalidate>
<h3>Sign in form</h3>
<fieldset>
<label for="email">Email</label>
<input id="email" type="email">
<label for="password">Password</label>
<input id="password" type="password">
<button type="submit">Sign in</button>
</fieldset>
</form>
</div>
<script>
const clickForm = document.getElementById('click-form');
const button = clickForm?.querySelector('button');
const handler = (e) => {
e.preventDefault();
e.stopImmediatePropagation();
clickForm.outerHTML = '<h1>Submitted!</h1>';
}
button?.addEventListener('click', handler, true);
</script>
</div>

</body>

</html>
59 changes: 59 additions & 0 deletions autofill/autoprompt/case-2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Autofill autoprompt for signin forms</title>
<link rel="stylesheet" href="../style.css" />
</head>

<body>
<p><a href="../index.html">[Home]</a></p>
<nav>
<ul class="nav">
<li><a href="./case-1.html">Case 1</a></li>
<li><a href="./case-2.html">Case 2</a></li>
<li><a href="./case-3.html">Case 3</a></li>
<li><a href="./case-4.html">Case 4</a></li>
<li><a href="./case-5.html">Case 5</a></li>
</ul>
</nav>

<p id="demo"></p>

<div class="">
<p>Form created in modal after click (<b>should not prompt automatically</b>).</p>

<div class="dialog">
<p><button type="button">Click here to login</button></p>
</div>
<script>
const initialButton = document.querySelector('button');
initialButton.addEventListener('click', () => {
const formEl = `<form id="click-form" novalidate action="./case-3.html">
<h3>Sign in form dia</h3>
<fieldset>
<label for="email">Email</label>
<input id="email" type="email">
<label for="password">Password</label>
<input id="password" type="password">
<button type="submit">Sign in</button>
</fieldset>
</form>`
initialButton.outerHTML = formEl;
const clickForm = document.getElementById('click-form');
const button = clickForm?.querySelector('button');
const handler = (e) => {
e.preventDefault();
e.stopImmediatePropagation();
window.location.href = './case-3.html'
}
button?.addEventListener('click', handler, true);
})
</script>
</div>

</body>

</html>
67 changes: 67 additions & 0 deletions autofill/autoprompt/case-3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Autofill autoprompt for signin forms</title>
<link rel="stylesheet" href="../style.css" />
</head>

<body>
<p><a href="../index.html">[Home]</a></p>
<nav>
<ul class="nav">
<li><a href="./case-1.html">Case 1</a></li>
<li><a href="./case-2.html">Case 2</a></li>
<li><a href="./case-3.html">Case 3</a></li>
<li><a href="./case-4.html">Case 4</a></li>
<li><a href="./case-5.html">Case 5</a></li>
</ul>
</nav>

<p id="demo"></p>

<div class="dialog">
<p>Login form with a multistep flow. It should prompt automatically on first load, then the second field triggers the prompt on tap/click.</p>
<form action="/login" id="login">
<h2>Log in</h2>
<fieldset>
<label for="email">Email</label>
<input id="email" type="email" required>
<button type="button">Continue</button>
</fieldset>
<fieldset class="password-container" hidden>
<label for="password">Password</label>
<input id="password" type="password" required>
<button type="submit">Log in</button>
</fieldset>
</form>
</div>

<script type="module">
const continueButton = document.querySelector('button[type=button]');
const submitButton = document.querySelector('button[type=submit]');
const passwordContainer = document.querySelector('.password-container');

continueButton.addEventListener('click', () => {
if (form.email.validity.valid) {
passwordContainer.removeAttribute('hidden');
continueButton.setAttribute('hidden', '');
}
});

const form = document.forms.login;
form.addEventListener('submit', (e) => {
e.preventDefault();
if (form.checkValidity()) {
setTimeout(() => {
form.outerHTML = '<h1>Submitted!</h1>';
}, 100);
}
});
</script>

</body>

</html>
65 changes: 65 additions & 0 deletions autofill/autoprompt/case-4.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Autofill autoprompt for signin forms</title>
<link rel="stylesheet" href="../style.css" />
</head>

<body>
<p><a href="../index.html">[Home]</a></p>
<nav>
<ul class="nav">
<li><a href="./case-1.html">Case 1</a></li>
<li><a href="./case-2.html">Case 2</a></li>
<li><a href="./case-3.html">Case 3</a></li>
<li><a href="./case-4.html">Case 4</a></li>
<li><a href="./case-5.html">Case 5</a></li>
</ul>
</nav>

<p id="demo">The cookie dialog will prevent autoprompt. You should not see an autoprompt on this page. Once dismissing the cookie dialog, you can use the form as usual.</p>

<div class="dialog">
<form action="/login" id="login">
<h2>Log in</h2>
<fieldset>
<label for="email">Email</label>
<input id="email" type="email">
<label for="password">Password</label>
<input id="password" type="password">
<button type="submit">Log in</button>
</fieldset>
</form>
</div>

<div class="dialog dialog--cookie-dialog" hidden>
<h2>Annoying cookie prompt</h2>
<h3>This cookie prompt will appear with a slight delay after page load. It will cover our beloved login form thus preventing autoprompt.</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. </p>
<p><button type="button" class="close-cookie-dialog">Accept all cookies, you have no choice</button></p>
</div>
<script type="module">
const cookieDialog = document.querySelector('.dialog--cookie-dialog');
const closeCookieDialogBtn = document.querySelector('.close-cookie-dialog');
closeCookieDialogBtn.addEventListener('click', () => cookieDialog.setAttribute('hidden', ''));

// show the cookie prompt after page load
setTimeout(() => cookieDialog.removeAttribute('hidden'), 100);

const form = document.forms.login;
form.addEventListener('submit', (e) => {
e.preventDefault();
if (form.checkValidity()) {
setTimeout(() => {
form.outerHTML = '<h1>Submitted!</h1>';
}, 100);
}
});
</script>

</body>

</html>
62 changes: 62 additions & 0 deletions autofill/autoprompt/case-5.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Autofill autoprompt for signin forms</title>
<link rel="stylesheet" href="../style.css" />
</head>

<body>
<p><a href="../index.html">[Home]</a></p>
<nav>
<ul class="nav">
<li><a href="./case-1.html">Case 1</a></li>
<li><a href="./case-2.html">Case 2</a></li>
<li><a href="./case-3.html">Case 3</a></li>
<li><a href="./case-4.html">Case 4</a></li>
<li><a href="./case-5.html">Case 5</a></li>
</ul>
</nav>

<p id="demo"></p>
<p>Sign in form present below the fold on mobile, but in a sidebar on larger screens (<strong>should prompt automatically only when visible, i.e. on desktop</strong>).</p>

<div class="container">
<div class="main">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. </p>

<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. </p>
</div>

<div class="sidebar">
<form id="click-form" novalidate>
<h3>Sign in form</h3>
<fieldset>
<label for="email">Email</label>
<input id="email" type="email">
<label for="password">Password</label>
<input id="password" type="password">
<button type="submit">Sign in</button>
</fieldset>
</form>
</div>

<script>
const clickForm = document.getElementById('click-form');
const button = clickForm?.querySelector('button');
const handler = (e) => {
e.preventDefault();
e.stopImmediatePropagation();
clickForm.outerHTML = '<h1>Submitted!</h1>';
}
button?.addEventListener('click', handler, true);
</script>
</div>

</body>

</html>
Loading