Skip to content

Commit

Permalink
Autofill shadow dom test page (#183)
Browse files Browse the repository at this point in the history
* Easier navigation between autofill pages

Signed-off-by: Emanuele Feliziani <feliziani.emanuele@gmail.com>

* Add autofill shadow dom test page

Signed-off-by: Emanuele Feliziani <feliziani.emanuele@gmail.com>

* Use a nested shadow tree

Signed-off-by: Emanuele Feliziani <feliziani.emanuele@gmail.com>

---------

Signed-off-by: Emanuele Feliziani <feliziani.emanuele@gmail.com>
  • Loading branch information
GioSensation authored Jan 24, 2024
1 parent f56ef13 commit 90c0e45
Show file tree
Hide file tree
Showing 15 changed files with 123 additions and 25 deletions.
6 changes: 3 additions & 3 deletions autofill/address-form-submission.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</head>

<body>
<p><a href="../index.html">[Home]</a></p>
<p><a href="../index.html#autofill">[Home]</a></p>

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

Expand Down Expand Up @@ -40,7 +40,7 @@ <h3>Address form with click handler</h3>
<label for="phone">Phone</label>
<input id="phone" type="tel">


<button type="submit">Save</button>
</fieldset>
</form>
Expand All @@ -54,4 +54,4 @@ <h3>Address form with click handler</h3>
clickForm.submit();
}, true);
</script>
</body>
</body>
2 changes: 1 addition & 1 deletion autofill/autoprompt/1-standard-login-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</head>

<body>
<p><a href="../../index.html">[Home]</a></p>
<p><a href="../../index.html#autofill">[Home]</a></p>
<nav>
<ul class="nav">
<li><a href="./1-standard-login-form.html">Form present on pageload</a></li>
Expand Down
2 changes: 1 addition & 1 deletion autofill/autoprompt/2-form-in-modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</head>

<body>
<p><a href="../../index.html">[Home]</a></p>
<p><a href="../../index.html#autofill">[Home]</a></p>
<nav>
<ul class="nav">
<li><a href="./1-standard-login-form.html">Form present on pageload</a></li>
Expand Down
2 changes: 1 addition & 1 deletion autofill/autoprompt/3-multistep-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</head>

<body>
<p><a href="../../index.html">[Home]</a></p>
<p><a href="../../index.html#autofill">[Home]</a></p>
<nav>
<ul class="nav">
<li><a href="./1-standard-login-form.html">Form present on pageload</a></li>
Expand Down
2 changes: 1 addition & 1 deletion autofill/autoprompt/4-covered-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</head>

<body>
<p><a href="../../index.html">[Home]</a></p>
<p><a href="../../index.html#autofill">[Home]</a></p>
<nav>
<ul class="nav">
<li><a href="./1-standard-login-form.html">Form present on pageload</a></li>
Expand Down
2 changes: 1 addition & 1 deletion autofill/autoprompt/5-form-with-text.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</head>

<body>
<p><a href="../../index.html">[Home]</a></p>
<p><a href="../../index.html#autofill">[Home]</a></p>
<nav>
<ul class="nav">
<li><a href="./1-standard-login-form.html">Form present on pageload</a></li>
Expand Down
6 changes: 3 additions & 3 deletions autofill/card-form-submission.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</head>

<body>
<p><a href="../index.html">[Home]</a></p>
<p><a href="../index.html#autofill">[Home]</a></p>

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

Expand All @@ -30,7 +30,7 @@ <h3>Card form with click handler</h3>

<label for="cvv">cvv</label>
<input id="cvv" type="text">

<button type="submit">Save</button>
</fieldset>
</form>
Expand All @@ -44,4 +44,4 @@ <h3>Card form with click handler</h3>
clickForm.submit();
}, true);
</script>
</body>
</body>
8 changes: 4 additions & 4 deletions autofill/form-submission.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</head>

<body>
<p><a href="../index.html">[Home]</a></p>
<p><a href="../index.html#autofill">[Home]</a></p>

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

Expand All @@ -36,9 +36,9 @@ <h3>Sign in form with click handler</h3>
clickForm.submit();
}, true);
</script>

<hr>

<form id="submit-form" novalidate action="/autofill/form-submission.html">
<h3>Sign in form with submit handler</h3>
<p>To test properly, hit enter instead of clicking Sign in.</p>
Expand Down Expand Up @@ -108,4 +108,4 @@ <h3>Sign in form where button has covering child element</h3>

</body>

</html>
</html>
6 changes: 3 additions & 3 deletions autofill/frame-form-submission-parent.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
</head>

<body>
<p><a href="../index.html">[Home]</a></p>
<p><a href="../index.html#autofill">[Home]</a></p>

<p>We should show the autofill prompts for these iframed forms (note: it does <em>not</em> work on Android)</p>

<h2>Same origin iframe</h2>
<iframe src="./frame-form-submission-child.html" id="frame-form"></iframe>

<h2>Cross origin iframe</h2>
<iframe src="https://good.third-party.site/autofill/frame-form-submission-child.html" id="frame-form-cross-origin"></iframe>

Expand All @@ -25,4 +25,4 @@ <h2>Cross origin iframe</h2>
display:inline-block;
}
</style>
</body>
</body>
2 changes: 1 addition & 1 deletion autofill/frame-parent.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</head>

<body>
<p><a href="../index.html">[Home]</a></p>
<p><a href="../index.html#autofill">[Home]</a></p>

<p>We should show the autofill prompts for these iframed forms (note: it does <em>not</em> work on Android)</p>
<p>Note that the autofill tooltip is cut off in extensions and on Catalina. It should show correctly on macOS and iOS.</p>
Expand Down
4 changes: 2 additions & 2 deletions autofill/modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</head>

<body>
<p><a href="../index.html">[Home]</a></p>
<p><a href="../index.html#autofill">[Home]</a></p>

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

Expand Down Expand Up @@ -48,4 +48,4 @@ <h2>Sign up for our newsletter</h2>

</body>

</html>
</html>
2 changes: 1 addition & 1 deletion autofill/password-update.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<body>

<p><a href="../index.html">[Home]</a></p>
<p><a href="../index.html#autofill">[Home]</a></p>

<div class="dialog">
<form action="/change-password" id="change">
Expand Down
97 changes: 97 additions & 0 deletions autofill/shadow-dom.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Autofill: form in a nested shadow DOM</title>
<link rel="stylesheet" href="../style.css" />
</head>

<body>
<p><a href="../../index.html#autofill">[Home]</a></p>

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

<div class="">
<p>Form in shadow DOM created after click.</p>

<div class="dialog">
<shadow-component></shadow-component>
</div>
<script>
class ShadowComponent extends HTMLElement {
constructor () {
super();

// Create a shadow root
const shadowRoot = this.attachShadow({ mode: 'open' });

// Apply some styles to the shadow DOM
shadowRoot.innerHTML += `
<style>
div {
padding: 20px;
background-color: #f0f0f0;
box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.2);
}
</style>
`;

// Create a div element inside the shadow root
const div = document.createElement('div');
const initialButton = document.createElement('button');
initialButton.textContent = 'Click here to login';
initialButton.type = 'button';
div.appendChild(initialButton);
shadowRoot.appendChild(div);

initialButton.addEventListener('click', () => {
initialButton.outerHTML = '<custom-form></custom-form>';
});
}
}

// Define the custom element "shadow-component"
customElements.define('shadow-component', ShadowComponent);

class Form extends HTMLElement {
constructor () {
super();

// Create a shadow root
const shadowRoot = this.attachShadow({ mode: 'open' });

// Append the form to the shadow root
this.shadowRoot.innerHTML = `
<form id="click-form" novalidate action="./shadow-dom.html">
<h3>Sign up form</h3>
<fieldset>
<label for="email">Email</label>
<input id="email" type="email">
<label for="password">Password</label>
<input id="password" type="password" autocomplete="new-password">
<button type="submit">Sign up</button>
</fieldset>
</form>
`;
const clickForm = shadowRoot.getElementById('click-form');
const button = clickForm?.querySelector('button');
const handler = (e) => {
e.preventDefault();
e.stopImmediatePropagation();
alert('Success');
};
button?.addEventListener('click', handler, true);
clickForm?.addEventListener('submit', handler, true);
}
}

// Define the custom element
customElements.define('custom-form', Form);
</script>
</div>

</body>

</html>
4 changes: 2 additions & 2 deletions autofill/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<p><a href="../index.html">[Home]</a></p>
<p><a href="../index.html#autofill">[Home]</a></p>
<div class="">
<form action="/autofill/signup.html" id="signup">
<h2>Password generation during signup</h2>
Expand Down Expand Up @@ -44,4 +44,4 @@ <h3>Sign in form with click handler</h3>
}, true);
</script>
</body>
</html>
</html>
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ <h2>Privacy Protections Tests</h2>
<li><a href='./content-scope-scripts/runtime-checks/'>Runtime checks</a></li>
</ul>

<h2>Autofill</h2>
<h2 id="autofill">Autofill</h2>
<p><strong>Note:</strong> Autofill features currently only work on secure contexts, so no http://.</p>
<ul>
<li><a href="./autofill/address-form-submission.html">Address form submission detection and autofill</a></li>
Expand All @@ -91,6 +91,7 @@ <h2>Autofill</h2>
<li><a href="./autofill/frame-form-submission-parent.html">Form submission detection and autofill within an iframe</a></li>
<li><a href="./autofill/signup.html">Password generation during signup</a></li>
<li><a href="./autofill/password-update.html">Password update/reset forms</a></li>
<li><a href="./autofill/shadow-dom.html">Forms within shadow DOM</a></li>
<li>
Autoprompt credentials autofill when a login form is front and center
<ul>
Expand Down

0 comments on commit 90c0e45

Please sign in to comment.