File tree Expand file tree Collapse file tree 4 files changed +45
-0
lines changed
Extension/src/background/api Expand file tree Collapse file tree 4 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -89,4 +89,11 @@ export class DocumentBlockApi {
89
89
90
90
DocumentBlockApi . storeTrustedDomain ( hostname ) ;
91
91
}
92
+
93
+ /**
94
+ * Resets trusted domains to empty array.
95
+ */
96
+ public static async reset ( ) : Promise < void > {
97
+ await trustedDomainsStorage . setData ( [ ] ) ;
98
+ }
92
99
}
Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ import {
73
73
GPC_SCRIPT_OUTPUT ,
74
74
HIDE_DOCUMENT_REFERRER_OUTPUT ,
75
75
} from '../../../../../constants' ;
76
+ import { DocumentBlockApi } from '../document-block' ;
76
77
import { filteringLogApi } from '../filtering-log' ;
77
78
import { network } from '../network' ;
78
79
import { CommonFilterUtils } from '../../../common/common-filter-utils' ;
@@ -216,6 +217,9 @@ export class SettingsApi {
216
217
// On import should enable only groups from imported file.
217
218
await CommonFilterApi . initDefaultFilters ( enableUntouchedGroups ) ;
218
219
220
+ // reset trusted domains list
221
+ await DocumentBlockApi . reset ( ) ;
222
+
219
223
// reset list of consented filter ids on reset settings
220
224
await annoyancesConsent . reset ( ) ;
221
225
}
Original file line number Diff line number Diff line change @@ -80,4 +80,31 @@ describe('document block api', () => {
80
80
} ) ,
81
81
) . toBe ( true ) ;
82
82
} ) ;
83
+
84
+ it ( 'Resets trusted domains' , async ( ) => {
85
+ const url = 'https://example.org/test' ;
86
+
87
+ await DocumentBlockApi . init ( ) ;
88
+
89
+ vi . spyOn ( Date , 'now' ) . mockImplementation ( ( ) => 0 ) ;
90
+
91
+ await DocumentBlockApi . setTrustedDomain ( url ) ;
92
+
93
+ expect (
94
+ browser . storage . local . set . calledWith ( {
95
+ [ TRUSTED_DOCUMENTS_CACHE_KEY ] : JSON . stringify ( [ {
96
+ domain : 'example.org' ,
97
+ expires : DocumentBlockApi . TRUSTED_TTL_MS ,
98
+ } ] ) ,
99
+ } ) ,
100
+ ) . toBe ( true ) ;
101
+
102
+ await DocumentBlockApi . reset ( ) ;
103
+
104
+ expect (
105
+ browser . storage . local . set . calledWith ( {
106
+ [ TRUSTED_DOCUMENTS_CACHE_KEY ] : JSON . stringify ( [ ] ) ,
107
+ } ) ,
108
+ ) . toBe ( true ) ;
109
+ } ) ;
83
110
} ) ;
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import {
16
16
HIDE_DOCUMENT_REFERRER_OUTPUT ,
17
17
} from '../../../../constants' ;
18
18
import {
19
+ DocumentBlockApi ,
19
20
Network ,
20
21
SettingsApi ,
21
22
type SettingsData ,
@@ -222,10 +223,16 @@ describe('Settings Api', () => {
222
223
223
224
it ( 'Reset default settings' , async ( ) => {
224
225
await SettingsApi . setSetting ( SettingOption . AllowlistEnabled , false ) ;
226
+ expect ( SettingsApi . getSetting ( SettingOption . AllowlistEnabled ) ) . toBe ( false ) ;
227
+
228
+ // test trusted domains list as well since it is temporary and not stores as a part of settings
229
+ await DocumentBlockApi . setTrustedDomain ( 'https://example.com/test' ) ;
230
+ expect ( await DocumentBlockApi . getTrustedDomains ( ) ) . toStrictEqual ( [ 'example.com' ] ) ;
225
231
226
232
await SettingsApi . reset ( true ) ;
227
233
228
234
expect ( SettingsApi . getSetting ( SettingOption . AllowlistEnabled ) ) . toBe ( true ) ;
235
+ expect ( await DocumentBlockApi . getTrustedDomains ( ) ) . toStrictEqual ( [ ] ) ;
229
236
} , EXTENDED_TIMEOUT_MS ) ;
230
237
} ) ;
231
238
} ) ;
You can’t perform that action at this time.
0 commit comments