Skip to content
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
16 changes: 16 additions & 0 deletions injected/integration-test/duck-ai-data-clearing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ import { ResultsCollector } from './page-objects/results-collector.js';
const HTML = '/duck-ai-data-clearing/index.html';
const CONFIG = './integration-test/test-pages/duck-ai-data-clearing/config/enabled.json';

test('duck-ai-data-clearing feature is ready', async ({ page }, testInfo) => {
const collector = ResultsCollector.create(page, testInfo.project.use);
collector.withUserPreferences({
messageSecret: 'ABC',
javascriptInterface: 'javascriptInterface',
messageCallback: 'messageCallback',
});
await collector.load(HTML, CONFIG);

// Wait for completion message
const messages = await collector.waitForMessage('duckAiClearDataReady', 1);

expect(messages).toHaveLength(1);
expect(messages[0].payload.method).toBe('duckAiClearDataReady');
});

test('duck-ai-data-clearing feature clears localStorage and IndexedDB', async ({ page }, testInfo) => {
const collector = ResultsCollector.create(page, testInfo.project.use);
collector.withUserPreferences({
Expand Down
14 changes: 9 additions & 5 deletions injected/src/features/duck-ai-data-clearing.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ import ContentFeature from '../content-feature.js';
export class DuckAiDataClearing extends ContentFeature {
init() {
this.messaging.subscribe('duckAiClearData', (_) => this.clearData());

this.notify('duckAiClearDataReady');
}

async clearData() {
let success = true;
let lastError = null;

const localStorageKeys = this.getFeatureSetting('chatsLocalStorageKeys');
for (const localStorageKey of localStorageKeys) {
try {
this.clearSavedAIChats(localStorageKey);
} catch (error) {
success = false;
lastError = error;
this.log.error('Error clearing saved chats:', error);
}
}
Expand All @@ -29,15 +31,17 @@ export class DuckAiDataClearing extends ContentFeature {
try {
await this.clearChatImagesStore(indexDbName, objectStoreName);
} catch (error) {
success = false;
lastError = error;
this.log.error('Error clearing saved chat images:', error);
}
}

if (success) {
if (lastError === null) {
this.notify('duckAiClearDataCompleted');
} else {
this.notify('duckAiClearDataFailed');
this.notify('duckAiClearDataFailed', {
error: lastError?.message,
});
}
}

Expand Down
Loading