@@ -21,8 +21,11 @@ import product from 'vs/platform/product/common/product';
21
21
import { IProductService } from 'vs/platform/product/common/productService' ;
22
22
import { resolveMarketplaceHeaders } from 'vs/platform/externalServices/common/marketplace' ;
23
23
import { InMemoryStorageService , IStorageService } from 'vs/platform/storage/common/storage' ;
24
- import { TelemetryConfiguration , TELEMETRY_SETTING_ID } from 'vs/platform/telemetry/common/telemetry' ;
24
+ import { ITelemetryInfo , ITelemetryService , TelemetryConfiguration , TelemetryLevel , TELEMETRY_SETTING_ID } from 'vs/platform/telemetry/common/telemetry' ;
25
25
import { TargetPlatform } from 'vs/platform/extensions/common/extensions' ;
26
+ import { ClassifiedEvent , GDPRClassification , StrictPropertyCheck } from 'vs/platform/telemetry/common/gdprTypings' ;
27
+ import { staticObservableValue } from 'vs/base/common/observableValue' ;
28
+ import { Emitter , Event } from 'vs/base/common/event' ;
26
29
27
30
class EnvironmentServiceMock extends mock < IEnvironmentService > ( ) {
28
31
override readonly serviceMachineIdResource : URI ;
@@ -36,6 +39,7 @@ class EnvironmentServiceMock extends mock<IEnvironmentService>() {
36
39
suite ( 'Extension Gallery Service' , ( ) => {
37
40
const disposables : DisposableStore = new DisposableStore ( ) ;
38
41
let fileService : IFileService , environmentService : IEnvironmentService , storageService : IStorageService , productService : IProductService , configurationService : IConfigurationService ;
42
+ let telemetryService : ITelemetryService ;
39
43
40
44
setup ( ( ) => {
41
45
const serviceMachineIdResource = joinPath ( URI . file ( 'tests' ) . with ( { scheme : 'vscode-tests' } ) , 'machineid' ) ;
@@ -47,14 +51,15 @@ suite('Extension Gallery Service', () => {
47
51
configurationService = new TestConfigurationService ( { [ TELEMETRY_SETTING_ID ] : TelemetryConfiguration . ON } ) ;
48
52
configurationService . updateValue ( TELEMETRY_SETTING_ID , TelemetryConfiguration . ON ) ;
49
53
productService = { _serviceBrand : undefined , ...product , enableTelemetry : true } ;
54
+ telemetryService = new MockTelemetryService ( ) ;
50
55
} ) ;
51
56
52
57
teardown ( ( ) => disposables . clear ( ) ) ;
53
58
54
59
test ( 'marketplace machine id' , async ( ) => {
55
- const headers = await resolveMarketplaceHeaders ( product . version , productService , environmentService , configurationService , fileService , storageService ) ;
60
+ const headers = await resolveMarketplaceHeaders ( product . version , productService , environmentService , configurationService , fileService , storageService , telemetryService ) ;
56
61
assert . ok ( isUUID ( headers [ 'X-Market-User-Id' ] ) ) ;
57
- const headers2 = await resolveMarketplaceHeaders ( product . version , productService , environmentService , configurationService , fileService , storageService ) ;
62
+ const headers2 = await resolveMarketplaceHeaders ( product . version , productService , environmentService , configurationService , fileService , storageService , telemetryService ) ;
58
63
assert . strictEqual ( headers [ 'X-Market-User-Id' ] , headers2 [ 'X-Market-User-Id' ] ) ;
59
64
} ) ;
60
65
@@ -153,3 +158,51 @@ suite('Extension Gallery Service', () => {
153
158
return { version, targetPlatform } as IRawGalleryExtensionVersion ;
154
159
}
155
160
} ) ;
161
+
162
+ class MockTelemetryService implements ITelemetryService {
163
+ public _serviceBrand : undefined ;
164
+ public telemetryLevel = staticObservableValue ( TelemetryLevel . USAGE ) ;
165
+ public sendErrorTelemetry = true ;
166
+
167
+ public events : any [ ] = [ ] ;
168
+
169
+ private readonly emitter = new Emitter < any > ( ) ;
170
+
171
+ public get eventLogged ( ) : Event < any > {
172
+ return this . emitter . event ;
173
+ }
174
+
175
+ public setEnabled ( value : boolean ) : void {
176
+ }
177
+
178
+ public setExperimentProperty ( name : string , value : string ) : void {
179
+ }
180
+
181
+ public publicLog ( eventName : string , data ?: any ) : Promise < void > {
182
+ const event = { name : eventName , data : data } ;
183
+ this . events . push ( event ) ;
184
+ this . emitter . fire ( event ) ;
185
+ return Promise . resolve ( ) ;
186
+ }
187
+
188
+ public publicLog2 < E extends ClassifiedEvent < T > = never , T extends GDPRClassification < T > = never > ( eventName : string , data ?: StrictPropertyCheck < T , E > ) {
189
+ return this . publicLog ( eventName , data as any ) ;
190
+ }
191
+
192
+ public publicLogError ( eventName : string , data ?: any ) : Promise < void > {
193
+ return this . publicLog ( eventName , data ) ;
194
+ }
195
+
196
+ public publicLogError2 < E extends ClassifiedEvent < T > = never , T extends GDPRClassification < T > = never > ( eventName : string , data ?: StrictPropertyCheck < T , E > ) {
197
+ return this . publicLogError ( eventName , data as any ) ;
198
+ }
199
+
200
+ public getTelemetryInfo ( ) : Promise < ITelemetryInfo > {
201
+ return Promise . resolve ( {
202
+ instanceId : 'someValue.instanceId' ,
203
+ sessionId : 'someValue.sessionId' ,
204
+ machineId : 'someValue.machineId' ,
205
+ firstSessionDate : 'someValue.firstSessionDate'
206
+ } ) ;
207
+ }
208
+ }
0 commit comments