summaryrefslogtreecommitdiffstats
path: root/toolkit/components/downloads/test/unit/test_DownloadList.js
blob: f7d03900af5661d2fefcc02fe7ae966f1ef8f459 (plain)
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
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Tests the DownloadList object.
 */

"use strict";

// Globals

const { TelemetryTestUtils } = ChromeUtils.importESModule(
  "resource://testing-common/TelemetryTestUtils.sys.mjs"
);

Services.prefs.setBoolPref(
  "toolkit.telemetry.testing.overrideProductsCheck",
  true
);

/**
 * Returns a Date in the past usable to add expirable visits.
 *
 * @note Expiration ignores any visit added in the last 7 days, but it's
 *       better be safe against DST issues, by going back one day more.
 */
function getExpirableDate() {
  let dateObj = new Date();
  // Normalize to midnight
  dateObj.setHours(0);
  dateObj.setMinutes(0);
  dateObj.setSeconds(0);
  dateObj.setMilliseconds(0);
  return new Date(dateObj.getTime() - 8 * 86400000);
}

/**
 * Adds an expirable history visit for a download.
 *
 * @param aSourceUrl
 *        String containing the URI for the download source, or null to use
 *        httpUrl("source.txt").
 *
 * @return {Promise}
 * @rejects JavaScript exception.
 */
function promiseExpirableDownloadVisit(aSourceUrl) {
  return PlacesUtils.history.insert({
    url: aSourceUrl || httpUrl("source.txt"),
    visits: [
      {
        transition: PlacesUtils.history.TRANSITIONS.DOWNLOAD,
        date: getExpirableDate(),
      },
    ],
  });
}

// Tests

/**
 * Checks the testing mechanism used to build different download lists.
 */
add_task(async function test_construction() {
  let downloadListOne = await promiseNewList();
  let downloadListTwo = await promiseNewList();
  let privateDownloadListOne = await promiseNewList(true);
  let privateDownloadListTwo = await promiseNewList(true);

  Assert.notEqual(downloadListOne, downloadListTwo);
  Assert.notEqual(privateDownloadListOne, privateDownloadListTwo);
  Assert.notEqual(downloadListOne, privateDownloadListOne);
});

/**
 * Checks the methods to add and retrieve items from the list.
 */
add_task(async function test_add_getAll() {
  let list = await promiseNewList();

  let downloadOne = await promiseNewDownload();
  await list.add(downloadOne);

  let itemsOne = await list.getAll();
  Assert.equal(itemsOne.length, 1);
  Assert.equal(itemsOne[0], downloadOne);

  let downloadTwo = await promiseNewDownload();
  await list.add(downloadTwo);

  let itemsTwo = await list.getAll();
  Assert.equal(itemsTwo.length, 2);
  Assert.equal(itemsTwo[0], downloadOne);
  Assert.equal(itemsTwo[1], downloadTwo);

  // The first snapshot should not have been modified.
  Assert.equal(itemsOne.length, 1);
});

/**
 * Checks the method to remove items from the list.
 */
add_task(async function test_remove() {
  let list = await promiseNewList();

  await list.add(await promiseNewDownload());
  await list.add(await promiseNewDownload());

  let items = await list.getAll();
  await list.remove(items[0]);

  // Removing an item that was never added should not raise an error.
  await list.remove(await promiseNewDownload());

  items = await list.getAll();
  Assert.equal(items.length, 1);
});

/**
 * Tests that the "add", "remove", and "getAll" methods on the global
 * DownloadCombinedList object combine the contents of the global DownloadList
 * objects for public and private downloads.
 */
add_task(async function test_DownloadCombinedList_add_remove_getAll() {
  let publicList = await promiseNewList();
  let privateList = await Downloads.getList(Downloads.PRIVATE);
  let combinedList = await Downloads.getList(Downloads.ALL);

  let publicDownload = await promiseNewDownload();
  let privateDownload = await Downloads.createDownload({
    source: { url: httpUrl("source.txt"), isPrivate: true },
    target: getTempFile(TEST_TARGET_FILE_NAME).path,
  });

  await publicList.add(publicDownload);
  await privateList.add(privateDownload);

  Assert.equal((await combinedList.getAll()).length, 2);

  await combinedList.remove(publicDownload);
  await combinedList.remove(privateDownload);

  Assert.equal((await combinedList.getAll()).length, 0);

  await combinedList.add(publicDownload);
  await combinedList.add(privateDownload);

  Assert.equal((await publicList.getAll()).length, 1);
  Assert.equal((await privateList.getAll()).length, 1);
  Assert.equal((await combinedList.getAll()).length, 2);

  await publicList.remove(publicDownload);
  await privateList.remove(privateDownload);

  Assert.equal((await combinedList.getAll()).length, 0);
});

/**
 * Checks that views receive the download add and remove notifications, and that
 * adding and removing views works as expected, both for a normal and a combined
 * list.
 */
add_task(async function test_notifications_add_remove() {
  for (let isCombined of [false, true]) {
    // Force creating a new list for both the public and combined cases.
    let list = await promiseNewList();
    if (isCombined) {
      list = await Downloads.getList(Downloads.ALL);
    }

    let downloadOne = await promiseNewDownload();
    let downloadTwo = await Downloads.createDownload({
      source: { url: httpUrl("source.txt"), isPrivate: true },
      target: getTempFile(TEST_TARGET_FILE_NAME).path,
    });
    await list.add(downloadOne);
    await list.add(downloadTwo);

    // Check that we receive add notifications for existing elements.
    let addNotifications = 0;
    let viewOne = {
      onDownloadAdded(aDownload) {
        // The first download to be notified should be the first that was added.
        if (addNotifications == 0) {
          Assert.equal(aDownload, downloadOne);
        } else if (addNotifications == 1) {
          Assert.equal(aDownload, downloadTwo);
        }
        addNotifications++;
      },
    };
    await list.addView(viewOne);
    Assert.equal(addNotifications, 2);

    // Check that we receive add notifications for new elements.
    await list.add(await promiseNewDownload());
    Assert.equal(addNotifications, 3);

    // Check that we receive remove notifications.
    let removeNotifications = 0;
    let viewTwo = {
      onDownloadRemoved(aDownload) {
        Assert.equal(aDownload, downloadOne);
        removeNotifications++;
      },
    };
    await list.addView(viewTwo);
    await list.remove(downloadOne);
    Assert.equal(removeNotifications, 1);

    // We should not receive remove notifications after the view is removed.
    await list.removeView(viewTwo);
    await list.remove(downloadTwo);
    Assert.equal(removeNotifications, 1);

    // We should not receive add notifications after the view is removed.
    await list.removeView(viewOne);
    await list.add(await promiseNewDownload());
    Assert.equal(addNotifications, 3);
  }
});

/**
 * Checks that views receive the download change notifications, both for a
 * normal and a combined list.
 */
add_task(async function test_notifications_change() {
  for (let isCombined of [false, true]) {
    // Force creating a new list for both the public and combined cases.
    let list = await promiseNewList();
    if (isCombined) {
      list = await Downloads.getList(Downloads.ALL);
    }

    let downloadOne = await promiseNewDownload();
    let downloadTwo = await Downloads.createDownload({
      source: { url: httpUrl("source.txt"), isPrivate: true },
      target: getTempFile(TEST_TARGET_FILE_NAME).path,
    });
    await list.add(downloadOne);
    await list.add(downloadTwo);

    // Check that we receive change notifications.
    let receivedOnDownloadChanged = false;
    await list.addView({
      onDownloadChanged(aDownload) {
        Assert.equal(aDownload, downloadOne);
        receivedOnDownloadChanged = true;
      },
    });
    await downloadOne.start();
    Assert.ok(receivedOnDownloadChanged);

    // We should not receive change notifications after a download is removed.
    receivedOnDownloadChanged = false;
    await list.remove(downloadTwo);
    await downloadTwo.start();
    Assert.ok(!receivedOnDownloadChanged);
  }
});

/**
 * Checks that the reference to "this" is correct in the view callbacks.
 */
add_task(async function test_notifications_this() {
  let list = await promiseNewList();

  // Check that we receive change notifications.
  let receivedOnDownloadAdded = false;
  let receivedOnDownloadChanged = false;
  let receivedOnDownloadRemoved = false;
  let view = {
    onDownloadAdded() {
      Assert.equal(this, view);
      receivedOnDownloadAdded = true;
    },
    onDownloadChanged() {
      // Only do this check once.
      if (!receivedOnDownloadChanged) {
        Assert.equal(this, view);
        receivedOnDownloadChanged = true;
      }
    },
    onDownloadRemoved() {
      Assert.equal(this, view);
      receivedOnDownloadRemoved = true;
    },
  };
  await list.addView(view);

  let download = await promiseNewDownload();
  await list.add(download);
  await download.start();
  await list.remove(download);

  // Verify that we executed the checks.
  Assert.ok(receivedOnDownloadAdded);
  Assert.ok(receivedOnDownloadChanged);
  Assert.ok(receivedOnDownloadRemoved);
});

/**
 * Checks that download is removed on history expiration.
 */
add_task(async function test_history_expiration() {
  mustInterruptResponses();

  function cleanup() {
    Services.prefs.clearUserPref("places.history.expiration.max_pages");
  }
  registerCleanupFunction(cleanup);

  // Set max pages to 0 to make the download expire.
  Services.prefs.setIntPref("places.history.expiration.max_pages", 0);

  let list = await promiseNewList();
  let downloadOne = await promiseNewDownload();
  let downloadTwo = await promiseNewDownload(httpUrl("interruptible.txt"));

  let deferred = Promise.withResolvers();
  let removeNotifications = 0;
  let downloadView = {
    onDownloadRemoved(aDownload) {
      if (++removeNotifications == 2) {
        deferred.resolve();
      }
    },
  };
  await list.addView(downloadView);

  // Work with one finished download and one canceled download.
  await downloadOne.start();
  downloadTwo.start().catch(() => {});
  await downloadTwo.cancel();

  // We must replace the visits added while executing the downloads with visits
  // that are older than 7 days, otherwise they will not be expired.
  await PlacesUtils.history.clear();
  await promiseExpirableDownloadVisit();
  await promiseExpirableDownloadVisit(httpUrl("interruptible.txt"));

  // After clearing history, we can add the downloads to be removed to the list.
  await list.add(downloadOne);
  await list.add(downloadTwo);

  // Force a history expiration.
  Cc["@mozilla.org/places/expiration;1"]
    .getService(Ci.nsIObserver)
    .observe(null, "places-debug-start-expiration", -1);

  // Wait for both downloads to be removed.
  await deferred.promise;

  cleanup();
});

/**
 * Checks all downloads are removed after clearing history.
 */
add_task(async function test_history_clear() {
  let list = await promiseNewList();
  let downloadOne = await promiseNewDownload();
  let downloadTwo = await promiseNewDownload();
  await list.add(downloadOne);
  await list.add(downloadTwo);

  let deferred = Promise.withResolvers();
  let removeNotifications = 0;
  let downloadView = {
    onDownloadRemoved(aDownload) {
      if (++removeNotifications == 2) {
        deferred.resolve();
      }
    },
  };
  await list.addView(downloadView);

  await downloadOne.start();
  await downloadTwo.start();

  await PlacesUtils.history.clear();

  // Wait for the removal notifications that may still be pending.
  await deferred.promise;
});

/**
 * Tests the removeFinished method to ensure that it only removes
 * finished downloads.
 */
add_task(async function test_removeFinished() {
  let list = await promiseNewList();
  let downloadOne = await promiseNewDownload();
  let downloadTwo = await promiseNewDownload();
  let downloadThree = await promiseNewDownload();
  let downloadFour = await promiseNewDownload();
  await list.add(downloadOne);
  await list.add(downloadTwo);
  await list.add(downloadThree);
  await list.add(downloadFour);

  let deferred = Promise.withResolvers();
  let removeNotifications = 0;
  let downloadView = {
    onDownloadRemoved(aDownload) {
      Assert.ok(
        aDownload == downloadOne ||
          aDownload == downloadTwo ||
          aDownload == downloadThree
      );
      Assert.ok(removeNotifications < 3);
      if (++removeNotifications == 3) {
        deferred.resolve();
      }
    },
  };
  await list.addView(downloadView);

  // Start three of the downloads, but don't start downloadTwo, then set
  // downloadFour to have partial data. All downloads except downloadFour
  // should be removed.
  await downloadOne.start();
  await downloadThree.start();
  await downloadFour.start();
  downloadFour.hasPartialData = true;

  list.removeFinished();
  await deferred.promise;

  let downloads = await list.getAll();
  Assert.equal(downloads.length, 1);
});

/**
 * Tests that removeFinished method keeps the file that is currently downloading,
 * even if it needs to remove failed download of the same file.
 */
add_task(async function test_removeFinished_keepsDownloadingFile() {
  let targetFile = getTempFile(TEST_TARGET_FILE_NAME);

  let oneDownload = await Downloads.createDownload({
    source: httpUrl("empty.txt"),
    target: targetFile.path,
  });

  let otherDownload = await Downloads.createDownload({
    source: httpUrl("empty.txt"),
    target: targetFile.path,
  });

  let list = await promiseNewList();
  await list.add(oneDownload);
  await list.add(otherDownload);

  let deferred = Promise.withResolvers();
  let downloadView = {
    async onDownloadRemoved(aDownload) {
      Assert.equal(aDownload, oneDownload);
      await TestUtils.waitForCondition(() => oneDownload._finalizeExecuted);
      deferred.resolve();
    },
  };
  await list.addView(downloadView);

  await oneDownload.start();
  await otherDownload.start();

  oneDownload.hasPartialData = otherDownload.hasPartialData = true;
  oneDownload.error = "Download failed";

  list.removeFinished();
  await deferred.promise;

  let downloads = await list.getAll();
  Assert.equal(
    downloads.length,
    1,
    "Failed download should be removed, active download should be kept"
  );

  Assert.ok(
    await IOUtils.exists(otherDownload.target.path),
    "The file should not have been deleted."
  );
});

/**
 * Tests the global DownloadSummary objects for the public, private, and
 * combined download lists.
 */
add_task(async function test_DownloadSummary() {
  mustInterruptResponses();

  let publicList = await promiseNewList();
  let privateList = await Downloads.getList(Downloads.PRIVATE);

  let publicSummary = await Downloads.getSummary(Downloads.PUBLIC);
  let privateSummary = await Downloads.getSummary(Downloads.PRIVATE);
  let combinedSummary = await Downloads.getSummary(Downloads.ALL);

  // Add a public download that has succeeded.
  let succeededPublicDownload = await promiseNewDownload();
  await succeededPublicDownload.start();
  await publicList.add(succeededPublicDownload);

  // Add a public download that has been canceled midway.
  let canceledPublicDownload = await promiseNewDownload(
    httpUrl("interruptible.txt")
  );
  canceledPublicDownload.start().catch(() => {});
  await promiseDownloadMidway(canceledPublicDownload);
  await canceledPublicDownload.cancel();
  await publicList.add(canceledPublicDownload);

  // Add a public download that is in progress.
  let inProgressPublicDownload = await promiseNewDownload(
    httpUrl("interruptible.txt")
  );
  inProgressPublicDownload.start().catch(() => {});
  await promiseDownloadMidway(inProgressPublicDownload);
  await publicList.add(inProgressPublicDownload);

  // Add a public download of unknown size that is in progress.
  let inProgressSizelessPublicDownload = await promiseNewDownload(
    httpUrl("interruptible_nosize.txt")
  );
  inProgressSizelessPublicDownload.start().catch(() => {});
  await promiseDownloadStarted(inProgressSizelessPublicDownload);
  await publicList.add(inProgressSizelessPublicDownload);

  // Add a private download that is in progress.
  let inProgressPrivateDownload = await Downloads.createDownload({
    source: { url: httpUrl("interruptible.txt"), isPrivate: true },
    target: getTempFile(TEST_TARGET_FILE_NAME).path,
  });
  inProgressPrivateDownload.start().catch(() => {});
  await promiseDownloadMidway(inProgressPrivateDownload);
  await privateList.add(inProgressPrivateDownload);

  // Verify that the summary includes the total number of bytes and the
  // currently transferred bytes only for the downloads that are not stopped.
  // For simplicity, we assume that after a download is added to the list, its
  // current state is immediately propagated to the summary object, which is
  // true in the current implementation, though it is not guaranteed as all the
  // download operations may happen asynchronously.
  Assert.ok(!publicSummary.allHaveStopped);
  Assert.ok(!publicSummary.allUnknownSize);
  Assert.equal(publicSummary.progressTotalBytes, TEST_DATA_SHORT.length * 3);
  Assert.equal(publicSummary.progressCurrentBytes, TEST_DATA_SHORT.length * 2);

  Assert.ok(!privateSummary.allHaveStopped);
  Assert.ok(!privateSummary.allUnknownSize);
  Assert.equal(privateSummary.progressTotalBytes, TEST_DATA_SHORT.length * 2);
  Assert.equal(privateSummary.progressCurrentBytes, TEST_DATA_SHORT.length);

  Assert.ok(!combinedSummary.allHaveStopped);
  Assert.ok(!combinedSummary.allUnknownSize);
  Assert.equal(combinedSummary.progressTotalBytes, TEST_DATA_SHORT.length * 5);
  Assert.equal(
    combinedSummary.progressCurrentBytes,
    TEST_DATA_SHORT.length * 3
  );

  await inProgressPublicDownload.cancel();

  // Stopping the download should have excluded it from the summary, but we
  // should still have one public download (with unknown size) and also one
  // private download remaining.
  Assert.ok(!publicSummary.allHaveStopped);
  Assert.ok(publicSummary.allUnknownSize);
  Assert.equal(publicSummary.progressTotalBytes, TEST_DATA_SHORT.length);
  Assert.equal(publicSummary.progressCurrentBytes, TEST_DATA_SHORT.length);

  Assert.ok(!privateSummary.allHaveStopped);
  Assert.ok(!privateSummary.allUnknownSize);
  Assert.equal(privateSummary.progressTotalBytes, TEST_DATA_SHORT.length * 2);
  Assert.equal(privateSummary.progressCurrentBytes, TEST_DATA_SHORT.length);

  Assert.ok(!combinedSummary.allHaveStopped);
  Assert.ok(!combinedSummary.allUnknownSize);
  Assert.equal(combinedSummary.progressTotalBytes, TEST_DATA_SHORT.length * 3);
  Assert.equal(
    combinedSummary.progressCurrentBytes,
    TEST_DATA_SHORT.length * 2
  );

  await inProgressPrivateDownload.cancel();

  // Stopping the private download should have excluded it from the summary, so
  // now only the unknown size public download should remain.
  Assert.ok(!publicSummary.allHaveStopped);
  Assert.ok(publicSummary.allUnknownSize);
  Assert.equal(publicSummary.progressTotalBytes, TEST_DATA_SHORT.length);
  Assert.equal(publicSummary.progressCurrentBytes, TEST_DATA_SHORT.length);

  Assert.ok(privateSummary.allHaveStopped);
  Assert.ok(privateSummary.allUnknownSize);
  Assert.equal(privateSummary.progressTotalBytes, 0);
  Assert.equal(privateSummary.progressCurrentBytes, 0);

  Assert.ok(!combinedSummary.allHaveStopped);
  Assert.ok(combinedSummary.allUnknownSize);
  Assert.equal(combinedSummary.progressTotalBytes, TEST_DATA_SHORT.length);
  Assert.equal(combinedSummary.progressCurrentBytes, TEST_DATA_SHORT.length);

  await inProgressSizelessPublicDownload.cancel();

  // All the downloads should be stopped now.
  Assert.ok(publicSummary.allHaveStopped);
  Assert.ok(publicSummary.allUnknownSize);
  Assert.equal(publicSummary.progressTotalBytes, 0);
  Assert.equal(publicSummary.progressCurrentBytes, 0);

  Assert.ok(privateSummary.allHaveStopped);
  Assert.ok(privateSummary.allUnknownSize);
  Assert.equal(privateSummary.progressTotalBytes, 0);
  Assert.equal(privateSummary.progressCurrentBytes, 0);

  Assert.ok(combinedSummary.allHaveStopped);
  Assert.ok(combinedSummary.allUnknownSize);
  Assert.equal(combinedSummary.progressTotalBytes, 0);
  Assert.equal(combinedSummary.progressCurrentBytes, 0);
});

/**
 * Checks that views receive the summary change notification.  This is tested on
 * the combined summary when adding a public download, as we assume that if we
 * pass the test in this case we will also pass it in the others.
 */
add_task(async function test_DownloadSummary_notifications() {
  let list = await promiseNewList();
  let summary = await Downloads.getSummary(Downloads.ALL);

  let download = await promiseNewDownload();
  await list.add(download);

  // Check that we receive change notifications.
  let receivedOnSummaryChanged = false;
  await summary.addView({
    onSummaryChanged() {
      receivedOnSummaryChanged = true;
    },
  });
  await download.start();
  Assert.ok(receivedOnSummaryChanged);
});

/**
 * Tests that if a new download is added, telemetry records the event and type of the file.
 */
add_task(async function test_downloadAddedTelemetry() {
  Services.telemetry.clearEvents();
  Services.telemetry.setEventRecordingEnabled("downloads", true);

  let targetFile = getTempFile(TEST_TARGET_FILE_NAME);

  let download = await Downloads.createDownload({
    source: httpUrl("empty.txt"),
    target: targetFile.path,
  });

  let list = await Downloads.getList(Downloads.ALL);
  await list.add(download);
  download.start();
  await promiseDownloadFinished(download);

  TelemetryTestUtils.assertEvents([
    {
      category: "downloads",
      method: "added",
      object: "fileExtension",
      value: "txt",
    },
  ]);
});