Skip to content

Commit 3cfa1f6

Browse files
committed
feat: use from config
1 parent fcdaa63 commit 3cfa1f6

File tree

9 files changed

+40
-67
lines changed

9 files changed

+40
-67
lines changed

CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ injected/src/element-hiding.js @duckduckgo/content-scope-scripts-owners @jonatha
1010
injected/src/features/click-to-load.js @duckduckgo/content-scope-scripts-owners @kzar @ladamski @franfaccin @jonathanKingston @shakyShane
1111
injected/src/features/click-to-load/ @duckduckgo/content-scope-scripts-owners @kzar @ladamski @franfaccin @jonathanKingston @shakyShane
1212
injected/src/locales/click-to-load/ @duckduckgo/content-scope-scripts-owners @kzar @ladamski @franfaccin @jonathanKingston @shakyShane
13-
injected/src/features/autofill-password-import.js @duckduckgo/content-scope-scripts-owners @dbajpeyi
13+
injected/src/features/autofill-import.js @duckduckgo/content-scope-scripts-owners @dbajpeyi
1414

1515
# Broker protection
1616
injected/src/features/broker-protection.js @duckduckgo/content-scope-scripts-owners @duckduckgo/injected-broker-protection

injected/integration-test/autofill-password-import.spec.js renamed to injected/integration-test/autofill-import.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { test, expect } from '@playwright/test';
2-
import { OVERLAY_ID } from '../src/features/autofill-password-import';
2+
import { OVERLAY_ID } from '../src/features/autofill-import';
33
import { ResultsCollector } from './page-objects/results-collector.js';
44

5-
const HTML = '/autofill-password-import/index.html';
6-
const CONFIG = './integration-test/test-pages/autofill-password-import/config/config.json';
5+
const HTML = '/autofill-import/index.html';
6+
const CONFIG = './integration-test/test-pages/autofill-import/config/config.json';
77

88
test('Password import feature', async ({ page }, testInfo) => {
99
const collector = ResultsCollector.create(page, testInfo.project.use);
1010
await collector.load(HTML, CONFIG);
1111

12-
const passwordImportFeature = new AutofillPasswordImportSpec(page);
12+
const passwordImportFeature = new AutofillImportSpec(page);
1313
await passwordImportFeature.clickOnElement('Home page');
1414
await passwordImportFeature.waitForAnimation();
1515

@@ -25,7 +25,7 @@ test('Password import feature', async ({ page }, testInfo) => {
2525
await expect(overlay).not.toBeVisible();
2626
});
2727

28-
class AutofillPasswordImportSpec {
28+
class AutofillImportSpec {
2929
/**
3030
* @param {import("@playwright/test").Page} page
3131
*/

injected/integration-test/type-helpers.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class Build {
6161
android: () => '../build/android/contentScope.js',
6262
apple: () => '../build/apple/contentScope.js',
6363
'apple-isolated': () => '../build/apple/contentScopeIsolated.js',
64-
'android-autofill-import': () => '../build/android/autofillPasswordImport.js',
64+
'android-autofill-import': () => '../build/android/autofillImport.js',
6565
'android-broker-protection': () => '../build/android/brokerProtection.js',
6666
});
6767
return readFileSync(path, 'utf8');

injected/playwright.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default defineConfig({
5656
},
5757
{
5858
name: 'android-autofill-import',
59-
testMatch: ['integration-test/autofill-password-import.spec.js'],
59+
testMatch: ['integration-test/autofill-import.spec.js'],
6060
use: { injectName: 'android-autofill-import', platform: 'android', ...devices['Galaxy S5'] },
6161
},
6262
{

injected/scripts/entry-points.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const builds = {
3333
},
3434
'android-autofill-import': {
3535
input: 'entry-points/android.js',
36-
output: ['../build/android/autofillPasswordImport.js'],
36+
output: ['../build/android/autofillImport.js'],
3737
},
3838
'android-adsjs': {
3939
input: 'entry-points/android-adsjs.js',

injected/src/features.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const otherFeatures = /** @type {const} */ ([
2828
'brokerProtection',
2929
'performanceMetrics',
3030
'breakageReporting',
31-
'autofillPasswordImport',
31+
'autofillImport',
3232
'favicon',
3333
'webTelemetry',
3434
'pageContext',
@@ -50,7 +50,7 @@ export const platformSupport = {
5050
],
5151
android: [...baseFeatures, 'webCompat', 'breakageReporting', 'duckPlayer', 'messageBridge'],
5252
'android-broker-protection': ['brokerProtection'],
53-
'android-autofill-import': ['autofillPasswordImport'],
53+
'android-autofill-import': ['autofillImport'],
5454
'android-adsjs': [
5555
'apiManipulation',
5656
'webCompat',

injected/src/features/autofill-bookmark-steps-selectors.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

injected/src/features/autofill-password-import.js renamed to injected/src/features/autofill-import.js

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import ContentFeature from '../content-feature';
22
import { isBeingFramed, withExponentialBackoff } from '../utils';
33
import { execute } from './broker-protection/execute';
4-
import { Steps } from './autofill-bookmark-steps';
54
import { DEFAULT_RETRY_CONFIG, retry } from '../timer-utils';
65

76
export const ANIMATION_DURATION_MS = 1000;
@@ -10,7 +9,6 @@ export const BACKGROUND_COLOR_START = 'rgba(85, 127, 243, 0.10)';
109
export const BACKGROUND_COLOR_END = 'rgba(85, 127, 243, 0.25)';
1110
export const OVERLAY_ID = 'ddg-password-import-overlay';
1211
export const DELAY_BEFORE_ANIMATION = 300;
13-
const BOOKMARK_IMPORT_DOMAIN = 'takeout.google.com';
1412
const TAKEOUT_DOWNLOAD_URL_BASE = '/takeout/download';
1513

1614
/**
@@ -65,7 +63,8 @@ export default class AutofillImport extends ContentFeature {
6563
/** @type {WeakSet<Element>} */
6664
#tappedElements = new WeakSet();
6765

68-
// #bookmarkImportActions;
66+
#bookmarkImportActions;
67+
#bookmarkImportSelectors;
6968

7069
/**
7170
* @returns {ButtonAnimationStyle}
@@ -425,7 +424,7 @@ export default class AutofillImport extends ContentFeature {
425424
}
426425

427426
async handlePasswordManagerPath(pathname) {
428-
console.log('DEEP DEBUG autofill-password-import: handlePasswordManagerPath', pathname);
427+
console.log('DEEP DEBUG autofill-import: handlePasswordManagerPath', pathname);
429428
this.removeOverlayIfNeeded();
430429
if (this.isSupportedPath(pathname)) {
431430
try {
@@ -447,15 +446,18 @@ export default class AutofillImport extends ContentFeature {
447446
*
448447
*/
449448
async handleLocation(location) {
450-
const { pathname, hostname } = location;
451-
if (hostname === BOOKMARK_IMPORT_DOMAIN) {
449+
const { pathname } = location;
450+
if (this.getFeatureSettingEnabled('canImportFromGoogleTakeout')) {
452451
if (this.#processingBookmark) {
453452
return;
454453
}
455454
this.#processingBookmark = true;
456455
this.handleBookmarkImportPath(pathname);
457-
} else {
456+
} else if (this.getFeatureSettingEnabled('canImportFromGooglePasswordManager')) {
458457
await this.handlePasswordManagerPath(pathname);
458+
} else {
459+
// Unknown feature, we bail out
460+
return;
459461
}
460462
}
461463

@@ -524,15 +526,10 @@ export default class AutofillImport extends ContentFeature {
524526
}
525527

526528
/** Bookmark import code */
527-
528-
get userIdSelector() {
529-
return 'a[href*="&user="]';
530-
}
531-
532529
async downloadData() {
533-
const userId = document.querySelector(this.userIdSelector)?.getAttribute('href')?.split('&user=')[1];
534-
console.log('DEEP DEBUG autofill-password-import: userId', userId);
535-
await this.runWithRetry(() => document.querySelector(`a[href="./manage/archive/${this.#exportId}"]`), 8);
530+
const userId = document.querySelector(this.#bookmarkImportSelectors.userIdLink)?.getAttribute('href')?.split('&user=')[1];
531+
console.log('DEEP DEBUG autofill-import: userId', userId);
532+
await this.runWithRetry(() => document.querySelector(`${this.#bookmarkImportSelectors.downloadLink}/${this.#exportId}`), 8);
536533
const downloadURL = `${TAKEOUT_DOWNLOAD_URL_BASE}?j=${this.#exportId}&i=0&user=${userId}`;
537534
window.location.href = downloadURL;
538535
}
@@ -548,13 +545,12 @@ export default class AutofillImport extends ContentFeature {
548545
}
549546

550547
async handleBookmarkImportPath(pathname) {
551-
console.log('DEEP DEBUG autofill-password-import: handleBookmarkImportPath', pathname);
548+
console.log('DEEP DEBUG autofill-import: handleBookmarkImportPath', pathname);
552549
if (pathname === '/' && !this.#isBookmarkModalVisible) {
553-
const bookmarkSteps = new Steps();
554-
for (const action of bookmarkSteps.actions) {
550+
for (const action of this.#bookmarkImportActions) {
555551
if (action.id === 'chrome-data-button-click') {
556552
await this.runWithRetry(() => {
557-
const element = document.querySelector(this.chromeDataButtonSelector);
553+
const element = document.querySelector(this.#bookmarkImportSelectors.chromeDataButton);
558554
return element?.checkVisibility();
559555
});
560556
}
@@ -571,50 +567,43 @@ export default class AutofillImport extends ContentFeature {
571567
}
572568
}
573569

574-
setButtonSettings() {
570+
setPasswordImportSettings() {
575571
this.#exportButtonSettings = this.getFeatureSetting('exportButton');
576572
this.#signInButtonSettings = this.getFeatureSetting('signInButton');
577573
this.#settingsButtonSettings = this.getFeatureSetting('settingsButton');
578574
}
579575

580-
setDBPActions() {
581-
// this.#bookmarkImportActions = actions;
582-
}
583-
584-
get tabPanelSelector() {
585-
return 'div[role="tabpanel"]';
586-
}
587-
588-
get chromeDataButtonSelector() {
589-
return `${this.tabPanelSelector} div:nth-child(10) > div:nth-child(2) > div:nth-child(2) button`;
576+
setBookmarkImportSettings() {
577+
this.#bookmarkImportActions = this.getFeatureSetting('actions');
578+
this.#bookmarkImportSelectors = this.getFeatureSetting('selectors');
590579
}
591580

592581
async findExportId() {
593-
const panels = document.querySelectorAll(this.tabPanelSelector);
582+
const panels = document.querySelectorAll(this.#bookmarkImportSelectors.tabPanel);
594583
const exportPanel = panels[panels.length - 1];
595584
return await this.runWithRetry(() => exportPanel.querySelector('div[data-archive-id]')?.getAttribute('data-archive-id'), 8, 100);
596585
}
597586

598587
async storeExportId() {
599588
this.#exportId = await this.findExportId();
600-
console.log('DEEP DEBUG autofill-password-import: stored export id', this.#exportId);
589+
console.log('DEEP DEBUG autofill-import: stored export id', this.#exportId);
601590
}
602591

603592
urlChanged(navigationType) {
604-
console.log('DEEP DEBUG autofill-password-import: urlChanged', window.location.pathname, navigationType);
593+
console.log('DEEP DEBUG autofill-import: urlChanged', window.location.pathname, navigationType);
605594
this.handleLocation(window.location);
606595
}
607596

608597
init() {
609-
console.log('DEEP DEBUG autofill-password-import: init');
598+
console.log('DEEP DEBUG autofill-import: init');
610599
if (isBeingFramed()) {
611600
return;
612601
}
613602

614603
if (this.getFeatureSettingEnabled('canImportFromGoogleTakeout')) {
615-
// this.setDBPActions(this.getFeatureSetting('bookmarkImport'));
604+
this.setBookmarkImportSettings();
616605
} else if (this.getFeatureSettingEnabled('canImportFromGooglePasswordManager')) {
617-
this.setButtonSettings();
606+
this.setPasswordImportSettings();
618607
} else {
619608
// bail out
620609
return;

injected/src/features/autofill-bookmark-steps-actions.json renamed to injected/src/features/bookmark-import-config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
2+
"selectors": {
3+
"tabPanalSelector": "div[role=\"tabpanel\"]",
4+
"chromeDataButtonSelector": "div[role=\"tabpanel\"] div:nth-child(10) > div:nth-child(2) > div:nth-child(2) button"
5+
},
26
"actions": [
37
{
48
"id": "deselect-all-button-click",

0 commit comments

Comments
 (0)