Skip to content

Commit c057232

Browse files
committed
test: add test for formBoundary settings
1 parent 758cae0 commit c057232

File tree

10 files changed

+236
-67
lines changed

10 files changed

+236
-67
lines changed

dist/autofill-debug.js

Lines changed: 10 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/autofill.js

Lines changed: 10 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration-test/helpers/mocks.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const constants = {
2727
selectInput: `${localPagesPrefix}/select-input.html`,
2828
shadowInputsLogin: `${localPagesPrefix}/shadow-inputs-login.html`,
2929
unknownUsernameLogin: `${localPagesPrefix}/unknown-username-login.html`,
30+
singleStepForm: `${localPagesPrefix}/single-step-form.html`,
3031
},
3132
forms: {
3233
'www_ulisboa_pt_login.html': `${testFormsPrefix}/www_ulisboa_pt_login.html`,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { constants } from '../mocks.js';
2+
import { genericPage } from './genericPage.js';
3+
4+
export function singleStepFormPage(page) {
5+
class SingleStepFormPage {
6+
async navigate() {
7+
await page.goto(constants.pages.singleStepForm);
8+
}
9+
10+
async assertUsernameFieldHasDaxIcon(selector) {
11+
await genericPage(page).usernameFieldShowsDaxIcon(selector);
12+
}
13+
14+
async assertUsernameFieldHasFillKey(selector) {
15+
await genericPage(page).usernameFieldShowsFillKey(selector);
16+
}
17+
}
18+
19+
return new SingleStepFormPage();
20+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Join us!</title>
5+
<style>
6+
body {
7+
display: flex;
8+
justify-content: center;
9+
align-items: center;
10+
min-height: 100vh;
11+
margin: 0;
12+
}
13+
.social-login {
14+
text-align: center;
15+
}
16+
.social-login p {
17+
margin: 0 0 20px 0;
18+
color: #666;
19+
}
20+
.social-buttons {
21+
display: flex;
22+
gap: 10px;
23+
margin-bottom: 20px;
24+
}
25+
.social-button {
26+
padding: 8px 16px;
27+
border: 1px solid #ddd;
28+
border-radius: 4px;
29+
background: white;
30+
cursor: pointer;
31+
display: flex;
32+
align-items: center;
33+
gap: 8px;
34+
}
35+
form {
36+
display: flex;
37+
gap: 8px;
38+
}
39+
input {
40+
padding: 8px;
41+
width: 200px;
42+
}
43+
button {
44+
padding: 8px 16px;
45+
}
46+
</style>
47+
</head>
48+
<body>
49+
<div class="social-login">
50+
<p>Login with</p>
51+
<div class="social-buttons">
52+
<button class="social-button">Google</button>
53+
<button class="social-button">Facebook</button>
54+
</div>
55+
<p>or</p>
56+
<form>
57+
<input type="text" id="email">
58+
<button>Continue</button>
59+
</form>
60+
</div>
61+
62+
</body>
63+
</html>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"features": {
3+
"siteSpecificFixes": {
4+
"state": "enabled",
5+
"anyOtherSettingForNative": "anyValue",
6+
"settings": {
7+
"javascriptConfig": {
8+
"domains": [
9+
{
10+
"domain": [
11+
"localhost"
12+
],
13+
"patchSettings": [
14+
{
15+
"path": "",
16+
"op": "add",
17+
"value": {
18+
"formTypeSettings": [],
19+
"formBoundarySettings": [
20+
{
21+
"formSelector": ".social-login",
22+
"inputsSelectors": []
23+
}
24+
]
25+
}
26+
}
27+
]
28+
}
29+
]
30+
}
31+
}
32+
}
33+
}
34+
}

integration-test/tests/site-specific-feature/site-specific-feature.macos.spec.js

Lines changed: 87 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,66 +6,106 @@ import { loginPage } from '../../helpers/pages/loginPage.js';
66
import { readFileSync } from 'fs';
77
import { genericPage } from '../../helpers/pages/genericPage.js';
88
import { signupPage } from '../../helpers/pages/signupPage.js';
9+
import { singleStepFormPage } from '../../helpers/pages/singleStepFormPage.js';
910

1011
/**
1112
* Tests for email autofill on ios tooltipHandler
1213
*/
1314
const test = testContext(base);
14-
const BASE_CONFIG_PATH = 'integration-test/tests/site-specific-feature/config-feature/';
15+
const BASE_CONFIG_PATH = 'integration-test/tests/site-specific-feature/config-feature';
1516

1617
function loginToSignupConfig() {
17-
return JSON.parse(readFileSync(`${BASE_CONFIG_PATH}login-to-signup.json`, 'utf8'));
18+
return JSON.parse(readFileSync(`${BASE_CONFIG_PATH}/login-to-signup.json`, 'utf8'));
1819
}
1920

2021
function signupToLoginConfig() {
21-
return JSON.parse(readFileSync(`${BASE_CONFIG_PATH}signup-to-login.json`, 'utf8'));
22+
return JSON.parse(readFileSync(`${BASE_CONFIG_PATH}/signup-to-login.json`, 'utf8'));
2223
}
2324

24-
test.describe('site-specific-fixes on login form', () => {
25-
test('login form can be forced to be a signup form', async ({ page }) => {
26-
// enable in-terminal exceptions
27-
await forwardConsoleMessages(page);
28-
29-
await createWebkitMocks('macos')
30-
.withAvailableInputTypes({ email: true })
31-
.withPersonalEmail('0')
32-
.withPrivateEmail('0')
33-
.withContentScopeFeatures(loginToSignupConfig().features)
34-
.applyTo(page);
35-
36-
// Load the autofill.js script
37-
await createAutofillScript().replaceAll(macosContentScopeReplacements()).platform('macos').applyTo(page);
38-
await page.pause();
39-
const login = loginPage(page);
40-
await login.navigate();
41-
await genericPage(page).passwordFieldShowsGenKey();
42-
await genericPage(page).usernameFieldShowsDaxIcon('#email');
25+
function formBoundaryConfig() {
26+
return JSON.parse(readFileSync(`${BASE_CONFIG_PATH}/form-boundary.json`, 'utf8'));
27+
}
28+
29+
test.describe('site-specific-fixes', () => {
30+
test.describe('formTypeSettings', () => {
31+
test('login form can be forced to be a signup form', async ({ page }) => {
32+
// enable in-terminal exceptions
33+
await forwardConsoleMessages(page);
34+
35+
await createWebkitMocks('macos')
36+
.withAvailableInputTypes({ email: true })
37+
.withPersonalEmail('0')
38+
.withPrivateEmail('0')
39+
.withContentScopeFeatures(loginToSignupConfig().features)
40+
.applyTo(page);
41+
42+
// Load the autofill.js script
43+
await createAutofillScript().replaceAll(macosContentScopeReplacements()).platform('macos').applyTo(page);
44+
const login = loginPage(page);
45+
await login.navigate();
46+
await genericPage(page).passwordFieldShowsGenKey();
47+
await genericPage(page).usernameFieldShowsDaxIcon('#email');
48+
});
49+
50+
test('signup form can be forced to be a login form', async ({ page }) => {
51+
await forwardConsoleMessages(page);
52+
53+
await createWebkitMocks('macos')
54+
.withCredentials({
55+
id: 'test',
56+
username: '[email protected]',
57+
password: 'password',
58+
})
59+
.withAvailableInputTypes({
60+
credentials: {
61+
username: true,
62+
password: true,
63+
},
64+
})
65+
.withContentScopeFeatures(signupToLoginConfig().features)
66+
.applyTo(page);
67+
68+
// Load the autofill.js script
69+
await createAutofillScript().replaceAll(macosContentScopeReplacements()).platform('macos').applyTo(page);
70+
const signup = signupPage(page);
71+
await signup.navigate();
72+
await genericPage(page).passwordFieldShowsFillKey('#password');
73+
await genericPage(page).usernameFieldShowsFillKey('#email');
74+
});
4375
});
4476

45-
test('signup form can be forced to be a login form', async ({ page }) => {
46-
await forwardConsoleMessages(page);
47-
48-
await createWebkitMocks('macos')
49-
.withCredentials({
50-
id: 'test',
51-
username: '[email protected]',
52-
password: 'password',
53-
})
54-
.withAvailableInputTypes({
55-
credentials: {
56-
username: true,
57-
password: true,
58-
},
59-
})
60-
.withContentScopeFeatures(signupToLoginConfig().features)
61-
.applyTo(page);
62-
63-
// Load the autofill.js script
64-
await createAutofillScript().replaceAll(macosContentScopeReplacements()).platform('macos').applyTo(page);
65-
await page.pause();
66-
const signup = signupPage(page);
67-
await signup.navigate();
68-
await genericPage(page).passwordFieldShowsFillKey('#password');
69-
await genericPage(page).usernameFieldShowsFillKey('#email');
77+
test.describe('formBoundarySettings', () => {
78+
test('forcing form boundary for a single step form scores the field as a username field', async ({ page }) => {
79+
// enable in-terminal exceptions
80+
await forwardConsoleMessages(page);
81+
82+
await createWebkitMocks('macos')
83+
.withPersonalEmail('0')
84+
.withAvailableInputTypes({ email: true, credentials: { username: true, password: true } })
85+
.withContentScopeFeatures(formBoundaryConfig().features)
86+
.applyTo(page);
87+
88+
// Load the autofill.js script
89+
await createAutofillScript().replaceAll(macosContentScopeReplacements()).platform('macos').applyTo(page);
90+
const singleStepForm = singleStepFormPage(page);
91+
await singleStepForm.navigate();
92+
await singleStepForm.assertUsernameFieldHasFillKey('#email');
93+
});
94+
95+
test('single step form scores the field as an email field', async ({ page }) => {
96+
// enable in-terminal exceptions
97+
await forwardConsoleMessages(page);
98+
99+
await createWebkitMocks('macos')
100+
.withPersonalEmail('0')
101+
.withAvailableInputTypes({ email: true, credentials: { username: true, password: true } })
102+
.applyTo(page);
103+
104+
// Load the autofill.js script
105+
await createAutofillScript().replaceAll(macosContentScopeReplacements()).platform('macos').applyTo(page);
106+
const singleStepForm = singleStepFormPage(page);
107+
await singleStepForm.navigate();
108+
await singleStepForm.assertUsernameFieldHasDaxIcon('#email');
109+
});
70110
});
71111
});

src/Form/FormAnalyzer.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ class FormAnalyzer {
3333
this.form = form;
3434
this.siteSpecificFeature = siteSpecificFeature;
3535
this.matching = matching || new Matching(matchingConfiguration);
36-
console.log('DEEP siteSpecificFeature', siteSpecificFeature?.isEnabled());
37-
if (this.siteSpecificFeature?.isEnabled()) {
38-
this.siteSpecificFeature.setForcedFormInputTypes(form, this.matching);
36+
if (this.siteSpecificFeature?.isEnabled() && this.siteSpecificFeature.attemptForceFormInputTypes(form, this.matching)) {
3937
return this;
4038
}
4139
/**

0 commit comments

Comments
 (0)