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

Ema/fix mutating forms #358

Merged
merged 8 commits into from
Jul 21, 2023
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
141 changes: 116 additions & 25 deletions dist/autofill-debug.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/autofill.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

141 changes: 116 additions & 25 deletions dist/autofill.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions integration-test/helpers/mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const constants = {
'emailAtTopLeft': 'pages/email-at-top-left.html',
'iframeContainer': 'pages/iframe-container.html',
'signup': 'pages/signup.html',
'mutatingForm': 'pages/mutating-form.html',
'login': 'pages/login.html',
'loginWithPoorForm': 'pages/login-poor-form.html',
'loginWithText': 'pages/login-with-text.html',
Expand Down
44 changes: 38 additions & 6 deletions integration-test/helpers/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@
return new IncontextSignupPage()
}

export function mutatingFormPage (page) {
class MutatingFormPage {
async navigate () {
await page.goto(constants.pages['mutatingForm'])
}
async toggleLoginOrSignup () {
const toggleBtn = page.locator('#toggle-login-signup')
await toggleBtn.click()
}
passwordFieldShowsKey () {
return loginPage(page).passwordFieldShowsKey()
}
assertPasswordHasNoIcon () {
return signupPage(page).assertPasswordHasNoIcon()
}
}

return new MutatingFormPage()
}

/**
* A wrapper around interactions for `integration-test/pages/signup.html`
*
Expand All @@ -68,6 +88,7 @@
const decoratedFirstInputSelector = '#email' + constants.fields.email.selectors.identity
const decoratedSecondInputSelector = '#email-2' + constants.fields.email.selectors.identity
const emailStyleAttr = () => page.locator('#email').first().getAttribute('style')
const passwordStyleAttr = () => page.locator('#password' + constants.fields.password.selectors.credential).getAttribute('style')

class SignupPage {
/**
Expand Down Expand Up @@ -149,7 +170,7 @@
const [, generatedPassword] = passwordButtonText.split('\n')

if (!generatedPassword.trim()) {
throw new Error('unreachable - password must not be empty')

Check failure on line 173 in integration-test/helpers/pages.js

View workflow job for this annotation

GitHub Actions / test

[macos] › email-autofill.macos.spec.js:196:9 › macos › auto filling a signup form › with an identity + Email Protection

1) [macos] › email-autofill.macos.spec.js:196:9 › macos › auto filling a signup form › with an identity + Email Protection, autofill using duck address in identity Error: unreachable - password must not be empty at ../helpers/pages.js:173 171 | 172 | if (!generatedPassword.trim()) { > 173 | throw new Error('unreachable - password must not be empty') | ^ 174 | } 175 | 176 | await passwordBtn.click({ force: true }) at SignupPage.selectGeneratedPassword (/home/runner/work/duckduckgo-autofill/duckduckgo-autofill/integration-test/helpers/pages.js:173:23) at /home/runner/work/duckduckgo-autofill/duckduckgo-autofill/integration-test/tests/email-autofill.macos.spec.js:210:13

Check failure on line 173 in integration-test/helpers/pages.js

View workflow job for this annotation

GitHub Actions / test

[macos] › email-autofill.macos.spec.js:239:9 › macos › auto filling a signup form › with no input types

2) [macos] › email-autofill.macos.spec.js:239:9 › macos › auto filling a signup form › with no input types Error: unreachable - password must not be empty at ../helpers/pages.js:173 171 | 172 | if (!generatedPassword.trim()) { > 173 | throw new Error('unreachable - password must not be empty') | ^ 174 | } 175 | 176 | await passwordBtn.click({ force: true }) at SignupPage.selectGeneratedPassword (/home/runner/work/duckduckgo-autofill/duckduckgo-autofill/integration-test/helpers/pages.js:173:23) at /home/runner/work/duckduckgo-autofill/duckduckgo-autofill/integration-test/tests/email-autofill.macos.spec.js:247:13
}

await passwordBtn.click({ force: true })
Expand Down Expand Up @@ -282,7 +303,10 @@
await expect(input).toHaveValue('')
}
async assertEmailHasNoDaxIcon () {
expect(await emailStyleAttr()).toBeNull()
expect(await emailStyleAttr()).toBeFalsy()
}
async assertPasswordHasNoIcon () {
expect(await passwordStyleAttr()).toBeFalsy()

Check failure on line 309 in integration-test/helpers/pages.js

View workflow job for this annotation

GitHub Actions / test

[macos] › mutating-form.macos.spec.js:19:5 › Mutating form page › works fine on macOS

3) [macos] › mutating-form.macos.spec.js:19:5 › Mutating form page › works fine on macOS ───────── Error: expect(received).toBeFalsy() Received: "background-size: auto 100% !important; background-position: right !important; background-repeat: no-repeat !important; background-origin: content-box !important; background-image: url(\"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB3aWR0aD0iMjRweCIgaGVpZ2h0PSIyNHB4IiB2aWV3Qm94PSIwIDAgMjQgMjQiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+CiAgICA8dGl0bGU+ZGRnLXBhc3N3b3JkLWljb24tYmFzZTwvdGl0bGU+CiAgICA8ZyBpZD0iZGRnLXBhc3N3b3JkLWljb24tYmFzZSIgc3Ryb2tlPSJub25lIiBzdHJva2Utd2lkdGg9IjEiIGZpbGw9Im5vbmUiIGZpbGwtcnVsZT0iZXZlbm9kZCI+CiAgICAgICAgPGcgaWQ9IlVuaW9uIiB0cmFuc2Zvcm09InRyYW5zbGF0ZSg0LjAwMDAwMCwgNC4wMDAwMDApIiBmaWxsPSIjMDAwMDAwIj4KICAgICAgICAgICAgPHBhdGggZD0iTTExLjMzMzMsMi42NjY2NyBDMTAuMjI4OCwyLjY2NjY3IDkuMzMzMzMsMy41NjIxIDkuMzMzMzMsNC42NjY2NyBDOS4zMzMzMyw1Ljc3MTI0IDEwLjIyODgsNi42NjY2NyAxMS4zMzMzLDYuNjY2NjcgQzEyLjQzNzksNi42NjY2NyAxMy4zMzMzLDUuNzcxMjQgMTMuMzMzMyw0LjY2NjY3IEMxMy4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IuMzg3ODEgMTMuNjEyMiwwIDEwLjY2NjcsMCBaIE02LjY2NjY3LDUuMzMzMzMgQzYuNjY2NjcsMy4xMjQxOSA4LjQ1NzUzLDEuMzMzMzMgMTAuNjY2NywxLjMzMzMzIEMxMi44NzU4LDEuMzMzMzMgMTQuNjY2NywzLjEyNDE5IDE0LjY2NjcsNS4zMzMzMyBDMTQuNjY2Nyw3LjU0MjQ3IDEyLjg3NTgsOS4zMzMzMyAxMC42NjY3LDkuMzMzMzMgQzEwLjE1NTgsOS4zMzMzMyA5LjY2ODg2LDkuMjM3OSA5LjIyMTUyLDkuMDY0NSBDOC45NzUyOCw4Ljk2OTA1IDguNjk1OTEsOS4wMjc5NSA4LjUwOTE2LDkuMjE0NjkgTDcuNzIzODYsMTAgTDYsMTAgQzUuNjMxODEsMTAgNS4zMzMzMywxMC4yOTg1IDUuMzMzMzMsMTAuNjY2NyBMNS4zMzMzMywxMi42NjY3IEw0LDEyLjY2NjcgQzMuNjMxODEsMTIuNjY2NyAzLjMzMzMzLDEyLjk2NTEgMy4zMzMzMywxMy4zMzMzIEwzLjMzMzMzLDE0LjY2NjcgTDEuMzMzMzMsMTQuNjY2NyBMMS4zMzMzMywxMi42MDk1IEw2LjY5Nzg3LDcuMjQ0OTQgQzYuODc1MDIsNy4wNjc3OSA2LjkzNzksNi44MDYyOSA2Ljg2MDY1LDYuNTY3OTggQzYuNzM0ODksNi4xNzk5NyA2LjY2NjY3LDUuNzY1MjcgNi42NjY2Nyw1LjMzMzMzIFoiIGlkPSJTaGFwZSI+PC9wYXRoPgogICAgICAgIDwvZz4KICAgIDwvZz4KPC9zdmc+\") !important; transition: background !important;" at ../helpers/pages.js:309 307 | } 308 | async assertPasswordHasNoIcon () { > 309 | expect(await passwordStyleAttr()).toBeFalsy() | ^ 310 | } 311 | } 312 | at SignupPage.assertPasswordHasNoIcon (/home/runner/work/duckduckgo-autofill/duckduckgo-autofill/integration-test/helpers/pages.js:309:47) at /home/runner/work/duckduckgo-autofill/duckduckgo-autofill/integration-test/tests/mutating-form.macos.spec.js:34:9
}
}

Expand Down Expand Up @@ -343,16 +367,24 @@
const emailStyle = await page.locator('#email').getAttribute('style')
expect(emailStyle).toContain(constants.iconMatchers.dax)
}
async emailHasDaxPasswordNoIcon () {
await this.emailFieldShowsDax()
async passwordFieldShowsKey () {
// don't make assertions until the element is both found + has a none-empty 'style' attribute
await page.waitForFunction(() => Boolean(document.querySelector('#password')?.getAttribute('style')))
const emailStyle = await page.locator('#password').getAttribute('style')
expect(emailStyle).toContain(constants.iconMatchers.key)
}
async passwordHasNoIcon () {
const passwordStyle = await page.locator('#password').getAttribute('style')
expect(passwordStyle || '').not.toContain('data:image/svg+xml;base64,')
}
async emailHasDaxPasswordNoIcon () {
await this.emailFieldShowsDax()
await this.passwordHasNoIcon()
}
async onlyPasswordFieldHasIcon () {
const styles1 = await page.locator('#email').getAttribute('style')
const styles2 = await page.locator('#password').getAttribute('style')
expect(styles1 || '').not.toContain('data:image/svg+xml;base64,')
expect(styles2 || '').toContain(constants.iconMatchers.key)
await this.passwordFieldShowsKey()
}
/**
* @param {string} username
Expand Down Expand Up @@ -646,7 +678,7 @@
expect(input).toHaveAttribute(ATTR_AUTOFILL, 'true')
}
async assertDaxIconIsHidden ({ checking = 'autofill' } = {}) {
const input = await page.locator(selectors.identity)
const input = await page.getByLabel('Email')
if (checking === 'style') {
const style = await input.getAttribute('style')
expect(style).toBeFalsy()
Expand Down
161 changes: 161 additions & 0 deletions integration-test/pages/mutating-form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Mutating form</title>
<!-- <link rel="stylesheet" href="./style.css" />-->
<style>
body {
font-family: "Lucida Sans", "Lucida Sans Regular", "Lucida Grande",
"Lucida Sans Unicode", Geneva, Verdana, sans-serif;
padding: 1em;
}

.dialog {
max-width: 500px;
height: auto;
padding: 30px;
background-color: #fefefe;
border-radius: 4px;
border: 0.5px solid #999;
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
text-align: center;
}

hr {
margin: 2em auto;
}

fieldset {
display: grid;
grid-template-columns: max-content 1fr;
grid-gap: 1em;
max-width: 410px;
padding: 0;
border: none;
margin: auto;
}

label {
align-self: center;
text-align: right;
}

input,
button,
.button {
font-family: inherit;
font-size: 16px;
line-height: 24px;
}

input {
grid-column: span 2;
margin: auto;
}

button,
.button {
grid-column: span 2;
display: block;
margin: auto;
padding: 5px 20px;
background-color: black;
color: white;
font-weight: bold;
border-radius: 3px;
border: none;
appearance: none;
box-shadow: none;
}

.button-with-child {
position: relative;
width: 250px;
height: 40px;
}

.button-with-child i {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
}

button[type="button"] {
display: inline-block;
padding: 0;
background: none;
color: black;
}
</style>
</head>

<body>
<main>

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

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

<div class="dialog">
<form action="/signup" id="signup-login">
<h2>Sign up for our services</h2>
<fieldset>
<input id="email" type="email" placeholder="Email">
<input id="firstname" type="text" placeholder="First name">
<input id="lastname" type="text" placeholder="Last name">
<input id="password" type="password" passwordrules="minlength: 5; maxlength: 10" placeholder="Password">
<input id="password-2" type="password" passwordrules="minlength: 5; maxlength: 10" placeholder="Repeat password">
<button type="submit">Sign up</button>
</fieldset>
<p><button id="toggle-login-signup" type="button">Login instead</button></p>
</form>
</div>
</main>
<script type="module">
const form = document.forms['signup-login'];
form.addEventListener("submit", (e) => {
e.preventDefault();
})
</script>
<script>
const form = document.forms['signup-login'];
const toggle = document.getElementById('toggle-login-signup')
const submit = document.querySelector('button[type=submit]')
const title = document.querySelector('h2')
toggle.addEventListener('click', () => {
if (form.action.includes('signup')) {
setLogin()
} else {
setSignup()
}
})
let elsToRemove
function setLogin () {
title.textContent = 'Login now!'
submit.textContent = 'Login'
toggle.textContent = 'Signup here'
elsToRemove = document.querySelectorAll('#firstname, #lastname, #password-2')
elsToRemove.forEach(el => el.remove())

form.action = '/login'
}
function setSignup () {
title.textContent = 'Sign up for our services'
submit.textContent = 'Signup'
toggle.textContent = 'Login instead'
form.append(...elsToRemove)
form.action = '/signup'
}
</script>
</body>

</html>
36 changes: 36 additions & 0 deletions integration-test/tests/mutating-form.macos.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {createAutofillScript, forwardConsoleMessages} from '../helpers/harness.js'
import {createWebkitMocks, macosContentScopeReplacements} from '../helpers/mocks.webkit.js'
import {mutatingFormPage} from '../helpers/pages.js'
import {test as base} from '@playwright/test'

/**
* Tests for various auto-fill scenarios on macos
*/
const test = base.extend({})

test.describe('Mutating form page', () => {
async function applyScript (page) {
await createAutofillScript()
.replaceAll(macosContentScopeReplacements())
.platform('macos')
.applyTo(page)
}

test('works fine on macOS', async ({page}) => {
// enable in-terminal exceptions
await forwardConsoleMessages(page)
await createWebkitMocks().applyTo(page)

// Load the autofill.js script with replacements
await await applyScript(page)

const mutatingForm = mutatingFormPage(page)
await mutatingForm.navigate()

await mutatingForm.passwordFieldShowsKey()

await mutatingForm.toggleLoginOrSignup()

await mutatingForm.assertPasswordHasNoIcon()
})
})
Loading
Loading