1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const { AppConstants } = ChromeUtils.importESModule(
"resource://gre/modules/AppConstants.sys.mjs"
);
const { setTimeout } = ChromeUtils.importESModule(
"resource://gre/modules/Timer.sys.mjs"
);
function sleep(ms) {
/* eslint-disable mozilla/no-arbitrary-setTimeout */
return new Promise(resolve => setTimeout(resolve, ms));
}
add_task(
/* on Android FOG is set up through head.js */
{ skip_if: () => AppConstants.platform == "android" },
function test_setup() {
// FOG needs a profile directory to put its data in.
do_get_profile();
// We need to initialize it once, otherwise operations will be stuck in the pre-init queue.
Services.fog.initializeFOG();
}
);
add_task(function test_jog_counter_works() {
Services.fog.testRegisterRuntimeMetric(
"counter",
"jog_cat",
"jog_counter",
["test-only"],
`"ping"`,
false
);
Glean.jogCat.jogCounter.add(53);
Assert.equal(53, Glean.jogCat.jogCounter.testGetValue());
});
add_task(async function test_jog_string_works() {
const value = "an active string!";
Services.fog.testRegisterRuntimeMetric(
"string",
"jog_cat",
"jog_string",
["test-only"],
`"ping"`,
false
);
Glean.jogCat.jogString.set(value);
Assert.equal(value, Glean.jogCat.jogString.testGetValue());
});
add_task(async function test_jog_string_list_works() {
const value = "an active string!";
const value2 = "a more active string!";
const value3 = "the most active of strings.";
Services.fog.testRegisterRuntimeMetric(
"string_list",
"jog_cat",
"jog_string_list",
["test-only"],
`"ping"`,
false
);
const jogList = [value, value2];
Glean.jogCat.jogStringList.set(jogList);
let val = Glean.jogCat.jogStringList.testGetValue();
// Note: This is incredibly fragile and will break if we ever rearrange items
// in the string list.
Assert.deepEqual(jogList, val);
Glean.jogCat.jogStringList.add(value3);
Assert.ok(Glean.jogCat.jogStringList.testGetValue().includes(value3));
});
add_task(async function test_jog_timespan_works() {
Services.fog.testRegisterRuntimeMetric(
"timespan",
"jog_cat",
"jog_timespan",
["test-only"],
`"ping"`,
false,
JSON.stringify({ time_unit: "millisecond" })
);
Glean.jogCat.jogTimespan.start();
Glean.jogCat.jogTimespan.cancel();
Assert.equal(undefined, Glean.jogCat.jogTimespan.testGetValue());
// We start, briefly sleep and then stop.
// That guarantees some time to measure.
Glean.jogCat.jogTimespan.start();
await sleep(10);
Glean.jogCat.jogTimespan.stop();
Assert.ok(Glean.jogCat.jogTimespan.testGetValue() > 0);
});
add_task(async function test_jog_uuid_works() {
const kTestUuid = "decafdec-afde-cafd-ecaf-decafdecafde";
Services.fog.testRegisterRuntimeMetric(
"uuid",
"jog_cat",
"jog_uuid",
["test-only"],
`"ping"`,
false
);
Glean.jogCat.jogUuid.set(kTestUuid);
Assert.equal(kTestUuid, Glean.jogCat.jogUuid.testGetValue());
Glean.jogCat.jogUuid.generateAndSet();
// Since we generate v4 UUIDs, and the first character of the third group
// isn't 4, this won't ever collide with kTestUuid.
Assert.notEqual(kTestUuid, Glean.jogCat.jogUuid.testGetValue());
});
add_task(function test_jog_datetime_works() {
const value = new Date("2020-06-11T12:00:00");
Services.fog.testRegisterRuntimeMetric(
"datetime",
"jog_cat",
"jog_datetime",
["test-only"],
`"ping"`,
false,
JSON.stringify({ time_unit: "nanosecond" })
);
Glean.jogCat.jogDatetime.set(value.getTime() * 1000);
const received = Glean.jogCat.jogDatetime.testGetValue();
Assert.equal(received.getTime(), value.getTime());
});
add_task(function test_jog_boolean_works() {
Services.fog.testRegisterRuntimeMetric(
"boolean",
"jog_cat",
"jog_bool",
["test-only"],
`"ping"`,
false
);
Glean.jogCat.jogBool.set(false);
Assert.equal(false, Glean.jogCat.jogBool.testGetValue());
});
add_task(async function test_jog_event_works() {
Services.fog.testRegisterRuntimeMetric(
"event",
"jog_cat",
"jog_event_no_extra",
["test-only"],
`"ping"`,
false
);
Glean.jogCat.jogEventNoExtra.record();
var events = Glean.jogCat.jogEventNoExtra.testGetValue();
Assert.equal(1, events.length);
Assert.equal("jog_cat", events[0].category);
Assert.equal("jog_event_no_extra", events[0].name);
Services.fog.testRegisterRuntimeMetric(
"event",
"jog_cat",
"jog_event",
["test-only"],
`"ping"`,
false,
JSON.stringify({ allowed_extra_keys: ["extra1", "extra2"] })
);
let extra = { extra1: "can set extras", extra2: "passing more data" };
Glean.jogCat.jogEvent.record(extra);
events = Glean.jogCat.jogEvent.testGetValue();
Assert.equal(1, events.length);
Assert.equal("jog_cat", events[0].category);
Assert.equal("jog_event", events[0].name);
Assert.deepEqual(extra, events[0].extra);
Services.fog.testRegisterRuntimeMetric(
"event",
"jog_cat",
"jog_event_with_extra",
["test-only"],
`"ping"`,
false,
JSON.stringify({
allowed_extra_keys: ["extra1", "extra2", "extra3_longer_name"],
})
);
let extra2 = {
extra1: "can set extras",
extra2: 37,
extra3_longer_name: false,
};
Glean.jogCat.jogEventWithExtra.record(extra2);
events = Glean.jogCat.jogEventWithExtra.testGetValue();
Assert.equal(1, events.length);
Assert.equal("jog_cat", events[0].category);
Assert.equal("jog_event_with_extra", events[0].name);
let expectedExtra = {
extra1: "can set extras",
extra2: "37",
extra3_longer_name: "false",
};
Assert.deepEqual(expectedExtra, events[0].extra);
// Quantities need to be non-negative.
let extra4 = {
extra2: -1,
};
Glean.jogCat.jogEventWithExtra.record(extra4);
events = Glean.jogCat.jogEventWithExtra.testGetValue();
Assert.equal(1, events.length, "Recorded one event too many.");
// Invalid extra keys don't crash, the event is not recorded.
let extra3 = {
extra1_nonexistent_extra: "this does not crash",
};
Glean.jogCat.jogEventWithExtra.record(extra3);
// And test methods throw appropriately
Assert.throws(
() => Glean.jogCat.jogEventWithExtra.testGetValue(),
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/
);
});
add_task(async function test_jog_memory_distribution_works() {
Services.fog.testRegisterRuntimeMetric(
"memory_distribution",
"jog_cat",
"jog_memory_dist",
["test-only"],
`"ping"`,
false,
JSON.stringify({ memory_unit: "megabyte" })
);
Glean.jogCat.jogMemoryDist.accumulate(7);
Glean.jogCat.jogMemoryDist.accumulate(17);
let data = Glean.jogCat.jogMemoryDist.testGetValue();
// `data.sum` is in bytes, but the metric is in MB.
Assert.equal(24 * 1024 * 1024, data.sum, "Sum's correct");
for (let [bucket, count] of Object.entries(data.values)) {
Assert.ok(
count == 0 || (count == 1 && (bucket == 17520006 || bucket == 7053950)),
"Only two buckets have a sample"
);
}
});
add_task(async function test_jog_custom_distribution_works() {
Services.fog.testRegisterRuntimeMetric(
"custom_distribution",
"jog_cat",
"jog_custom_dist",
["test-only"],
`"ping"`,
false,
JSON.stringify({
range_min: 1,
range_max: 2147483646,
bucket_count: 10,
histogram_type: "linear",
})
);
Glean.jogCat.jogCustomDist.accumulateSamples([7, 268435458]);
let data = Glean.jogCat.jogCustomDist.testGetValue();
Assert.equal(7 + 268435458, data.sum, "Sum's correct");
for (let [bucket, count] of Object.entries(data.values)) {
Assert.ok(
count == 0 || (count == 1 && (bucket == 1 || bucket == 268435456)),
`Only two buckets have a sample ${bucket} ${count}`
);
}
// Negative values will not be recorded, instead an error is recorded.
Glean.jogCat.jogCustomDist.accumulateSamples([-7]);
Assert.throws(
() => Glean.jogCat.jogCustomDist.testGetValue(),
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/
);
});
add_task(async function test_jog_custom_pings() {
Services.fog.testRegisterRuntimeMetric(
"boolean",
"jog_cat",
"jog_ping_bool",
["jog-ping"],
`"ping"`,
false
);
Services.fog.testRegisterRuntimePing("jog-ping", true, true, []);
Assert.ok("jogPing" in GleanPings);
let submitted = false;
Glean.jogCat.jogPingBool.set(false);
GleanPings.jogPing.testBeforeNextSubmit(reason => {
submitted = true;
Assert.equal(false, Glean.jogCat.jogPingBool.testGetValue());
});
GleanPings.jogPing.submit();
Assert.ok(submitted, "Ping was submitted, callback was called.");
// ping-lifetime value was cleared.
Assert.equal(undefined, Glean.jogCat.jogPingBool.testGetValue());
});
add_task(async function test_jog_timing_distribution_works() {
Services.fog.testRegisterRuntimeMetric(
"timing_distribution",
"jog_cat",
"jog_timing_dist",
["test-only"],
`"ping"`,
false,
JSON.stringify({ time_unit: "microsecond" })
);
let t1 = Glean.jogCat.jogTimingDist.start();
let t2 = Glean.jogCat.jogTimingDist.start();
await sleep(5);
let t3 = Glean.jogCat.jogTimingDist.start();
Glean.jogCat.jogTimingDist.cancel(t1);
await sleep(5);
Glean.jogCat.jogTimingDist.stopAndAccumulate(t2); // 10ms
Glean.jogCat.jogTimingDist.stopAndAccumulate(t3); // 5ms
let data = Glean.jogCat.jogTimingDist.testGetValue();
const NANOS_IN_MILLIS = 1e6;
// bug 1701949 - Sleep gets close, but sometimes doesn't wait long enough.
const EPSILON = 40000;
// Variance in timing makes getting the sum impossible to know.
Assert.greater(data.sum, 15 * NANOS_IN_MILLIS - EPSILON);
// No guarantees from timers means no guarantees on buckets.
// But we can guarantee it's only two samples.
Assert.equal(
2,
Object.entries(data.values).reduce(
(acc, [bucket, count]) => acc + count,
0
),
"Only two buckets with samples"
);
});
add_task(async function test_jog_labeled_boolean_works() {
Services.fog.testRegisterRuntimeMetric(
"labeled_boolean",
"jog_cat",
"jog_labeled_bool",
["test-only"],
`"ping"`,
false
);
Assert.equal(
undefined,
Glean.jogCat.jogLabeledBool.label_1.testGetValue(),
"New labels with no values should return undefined"
);
Glean.jogCat.jogLabeledBool.label_1.set(true);
Glean.jogCat.jogLabeledBool.label_2.set(false);
Assert.equal(true, Glean.jogCat.jogLabeledBool.label_1.testGetValue());
Assert.equal(false, Glean.jogCat.jogLabeledBool.label_2.testGetValue());
// What about invalid/__other__?
Assert.equal(undefined, Glean.jogCat.jogLabeledBool.__other__.testGetValue());
Glean.jogCat.jogLabeledBool.NowValidLabel.set(true);
Assert.ok(Glean.jogCat.jogLabeledBool.NowValidLabel.testGetValue());
Glean.jogCat.jogLabeledBool["1".repeat(72)].set(true);
Assert.throws(
() => Glean.jogCat.jogLabeledBool.__other__.testGetValue(),
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
"Should throw because of a recording error."
);
});
add_task(async function test_jog_labeled_boolean_with_static_labels_works() {
Services.fog.testRegisterRuntimeMetric(
"labeled_boolean",
"jog_cat",
"jog_labeled_bool_with_labels",
["test-only"],
`"ping"`,
false,
JSON.stringify({ ordered_labels: ["label_1", "label_2"] })
);
Assert.equal(
undefined,
Glean.jogCat.jogLabeledBoolWithLabels.label_1.testGetValue(),
"New labels with no values should return undefined"
);
Glean.jogCat.jogLabeledBoolWithLabels.label_1.set(true);
Glean.jogCat.jogLabeledBoolWithLabels.label_2.set(false);
Assert.equal(
true,
Glean.jogCat.jogLabeledBoolWithLabels.label_1.testGetValue()
);
Assert.equal(
false,
Glean.jogCat.jogLabeledBoolWithLabels.label_2.testGetValue()
);
// What about invalid/__other__?
Assert.equal(
undefined,
Glean.jogCat.jogLabeledBoolWithLabels.__other__.testGetValue()
);
Glean.jogCat.jogLabeledBoolWithLabels.label_3.set(true);
Assert.equal(
true,
Glean.jogCat.jogLabeledBoolWithLabels.__other__.testGetValue()
);
// TODO: Test that we have the right number and type of errors (bug 1683171)
});
add_task(async function test_jog_labeled_counter_works() {
Services.fog.testRegisterRuntimeMetric(
"labeled_counter",
"jog_cat",
"jog_labeled_counter",
["test-only"],
`"ping"`,
false
);
Assert.equal(
undefined,
Glean.jogCat.jogLabeledCounter.label_1.testGetValue(),
"New labels with no values should return undefined"
);
Glean.jogCat.jogLabeledCounter.label_1.add(1);
Glean.jogCat.jogLabeledCounter.label_2.add(2);
Assert.equal(1, Glean.jogCat.jogLabeledCounter.label_1.testGetValue());
Assert.equal(2, Glean.jogCat.jogLabeledCounter.label_2.testGetValue());
// What about invalid/__other__?
Assert.equal(
undefined,
Glean.jogCat.jogLabeledCounter.__other__.testGetValue()
);
Glean.jogCat.jogLabeledCounter["1".repeat(72)].add(1);
Assert.throws(
() => Glean.jogCat.jogLabeledCounter.__other__.testGetValue(),
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
"Should throw because of a recording error."
);
});
add_task(async function test_jog_labeled_counter_with_static_labels_works() {
Services.fog.testRegisterRuntimeMetric(
"labeled_counter",
"jog_cat",
"jog_labeled_counter_with_labels",
["test-only"],
`"ping"`,
false,
JSON.stringify({ ordered_labels: ["label_1", "label_2"] })
);
Assert.equal(
undefined,
Glean.jogCat.jogLabeledCounterWithLabels.label_1.testGetValue(),
"New labels with no values should return undefined"
);
Glean.jogCat.jogLabeledCounterWithLabels.label_1.add(1);
Glean.jogCat.jogLabeledCounterWithLabels.label_2.add(2);
Assert.equal(
1,
Glean.jogCat.jogLabeledCounterWithLabels.label_1.testGetValue()
);
Assert.equal(
2,
Glean.jogCat.jogLabeledCounterWithLabels.label_2.testGetValue()
);
// What about invalid/__other__?
Assert.equal(
undefined,
Glean.jogCat.jogLabeledCounterWithLabels.__other__.testGetValue()
);
Glean.jogCat.jogLabeledCounterWithLabels["1".repeat(72)].add(1);
// TODO:(bug 1766515) - This should throw.
/*Assert.throws(
() => Glean.jogCat.jogLabeledCounterWithLabels.__other__.testGetValue(),
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
"Should throw because of a recording error."
);*/
Assert.equal(
1,
Glean.jogCat.jogLabeledCounterWithLabels.__other__.testGetValue()
);
});
add_task(async function test_jog_labeled_string_works() {
Services.fog.testRegisterRuntimeMetric(
"labeled_string",
"jog_cat",
"jog_labeled_string",
["test-only"],
`"ping"`,
false
);
Assert.equal(
undefined,
Glean.jogCat.jogLabeledString.label_1.testGetValue(),
"New labels with no values should return undefined"
);
Glean.jogCat.jogLabeledString.label_1.set("crimson");
Glean.jogCat.jogLabeledString.label_2.set("various");
Assert.equal("crimson", Glean.jogCat.jogLabeledString.label_1.testGetValue());
Assert.equal("various", Glean.jogCat.jogLabeledString.label_2.testGetValue());
// What about invalid/__other__?
Assert.equal(
undefined,
Glean.jogCat.jogLabeledString.__other__.testGetValue()
);
Glean.jogCat.jogLabeledString["1".repeat(72)].set("valid");
Assert.throws(
() => Glean.jogCat.jogLabeledString.__other__.testGetValue(),
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/
);
});
add_task(async function test_jog_labeled_string_with_labels_works() {
Services.fog.testRegisterRuntimeMetric(
"labeled_string",
"jog_cat",
"jog_labeled_string_with_labels",
["test-only"],
`"ping"`,
false,
JSON.stringify({ ordered_labels: ["label_1", "label_2"] })
);
Assert.equal(
undefined,
Glean.jogCat.jogLabeledStringWithLabels.label_1.testGetValue(),
"New labels with no values should return undefined"
);
Glean.jogCat.jogLabeledStringWithLabels.label_1.set("crimson");
Glean.jogCat.jogLabeledStringWithLabels.label_2.set("various");
Assert.equal(
"crimson",
Glean.jogCat.jogLabeledStringWithLabels.label_1.testGetValue()
);
Assert.equal(
"various",
Glean.jogCat.jogLabeledStringWithLabels.label_2.testGetValue()
);
// What about invalid/__other__?
Assert.equal(
undefined,
Glean.jogCat.jogLabeledStringWithLabels.__other__.testGetValue()
);
Glean.jogCat.jogLabeledStringWithLabels["1".repeat(72)].set("valid");
// TODO:(bug 1766515) - This should throw.
/*Assert.throws(
() => Glean.jogCat.jogLabeledStringWithLabels.__other__.testGetValue(),
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/
);*/
Assert.equal(
"valid",
Glean.jogCat.jogLabeledStringWithLabels.__other__.testGetValue()
);
});
add_task(function test_jog_quantity_works() {
Services.fog.testRegisterRuntimeMetric(
"quantity",
"jog_cat",
"jog_quantity",
["test-only"],
`"ping"`,
false
);
Glean.jogCat.jogQuantity.set(42);
Assert.equal(42, Glean.jogCat.jogQuantity.testGetValue());
});
add_task(function test_jog_rate_works() {
Services.fog.testRegisterRuntimeMetric(
"rate",
"jog_cat",
"jog_rate",
["test-only"],
`"ping"`,
false
);
// 1) Standard rate with internal denominator
Glean.jogCat.jogRate.addToNumerator(22);
Glean.jogCat.jogRate.addToDenominator(7);
Assert.deepEqual(
{ numerator: 22, denominator: 7 },
Glean.jogCat.jogRate.testGetValue()
);
Services.fog.testRegisterRuntimeMetric(
"denominator",
"jog_cat",
"jog_denominator",
["test-only"],
`"ping"`,
false,
JSON.stringify({
numerators: [
{
name: "jog_rate_ext",
category: "jog_cat",
send_in_pings: ["test-only"],
lifetime: "ping",
disabled: false,
},
],
})
);
Services.fog.testRegisterRuntimeMetric(
"rate",
"jog_cat",
"jog_rate_ext",
["test-only"],
`"ping"`,
false
);
// 2) Rate with external denominator
Glean.jogCat.jogDenominator.add(11);
Glean.jogCat.jogRateExt.addToNumerator(121);
Assert.equal(11, Glean.jogCat.jogDenominator.testGetValue());
Assert.deepEqual(
{ numerator: 121, denominator: 11 },
Glean.jogCat.jogRateExt.testGetValue()
);
});
add_task(function test_jog_dotted_categories_work() {
Services.fog.testRegisterRuntimeMetric(
"counter",
"jog_cat.dotted",
"jog_counter",
["test-only"],
`"ping"`,
false
);
Glean.jogCatDotted.jogCounter.add(314);
Assert.equal(314, Glean.jogCatDotted.jogCounter.testGetValue());
});
add_task(async function test_jog_ping_works() {
const kReason = "reason-1";
Services.fog.testRegisterRuntimePing("my-ping", true, true, [kReason]);
let submitted = false;
GleanPings.myPing.testBeforeNextSubmit(reason => {
submitted = true;
Assert.equal(kReason, reason);
});
GleanPings.myPing.submit("reason-1");
Assert.ok(submitted, "Ping must have been submitted");
});
add_task(function test_jog_name_collision() {
Assert.ok("aCounter" in Glean.testOnlyJog);
Assert.equal(undefined, Glean.testOnlyJog.aCounter.testGetValue());
const kValue = 42;
Glean.testOnlyJog.aCounter.add(kValue);
Assert.equal(kValue, Glean.testOnlyJog.aCounter.testGetValue());
// Let's overwrite the test_only.jog.a_counter counter.
Services.fog.testRegisterRuntimeMetric(
"counter",
"test_only.jog",
"a_counter",
["store1"],
`"ping"`,
true // changing the metric to disabled.
);
Assert.ok("aCounter" in Glean.testOnlyJog);
Assert.equal(kValue, Glean.testOnlyJog.aCounter.testGetValue());
Glean.testOnlyJog.aCounter.add(kValue);
Assert.equal(
kValue,
Glean.testOnlyJog.aCounter.testGetValue(),
"value of now-disabled metric remains unchanged."
);
// Now let's mess with events:
Assert.ok("anEvent" in Glean.testOnlyJog);
Assert.equal(undefined, Glean.testOnlyJog.anEvent.testGetValue());
const extra12 = {
extra1: "a value",
extra2: "another value",
};
Glean.testOnlyJog.anEvent.record(extra12);
Assert.deepEqual(extra12, Glean.testOnlyJog.anEvent.testGetValue()[0].extra);
Services.fog.testRegisterRuntimeMetric(
"event",
"test_only.jog",
"an_event",
["store1"],
`"ping"`,
false,
JSON.stringify({ allowed_extra_keys: ["extra1", "extra2", "extra3"] }) // New extra key just dropped
);
const extra123 = {
extra1: "different value",
extra2: "another different value",
extra3: 42,
};
Glean.testOnlyJog.anEvent.record(extra123);
Assert.deepEqual(extra123, Glean.testOnlyJog.anEvent.testGetValue()[1].extra);
});
add_task(function test_enumerable_names() {
Assert.ok(Object.keys(Glean).includes("testOnlyJog"));
Assert.ok(Object.keys(Glean.testOnlyJog).includes("aCounter"));
Assert.ok(Object.keys(GleanPings).includes("testPing"));
});
add_task(async function test_jog_text_works() {
const kValue =
"In the heart of the Opéra district in Paris, the Cédric Grolet Opéra bakery-pastry shop is a veritable temple of gourmet delights.";
Services.fog.testRegisterRuntimeMetric(
"text",
"test_only.jog",
"a_text",
["test-only"],
`"ping"`,
false
);
Glean.testOnlyJog.aText.set(kValue);
Assert.equal(kValue, Glean.testOnlyJog.aText.testGetValue());
});
|