summaryrefslogtreecommitdiffstats
path: root/toolkit/components/thumbnails/test/browser_thumbnails_bg_destroy_browser.js
blob: 609d3449729c1377f2fa98347b33f1ab0c97b9b6 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

add_task(async function thumbnails_bg_destroy_browser() {
  await SpecialPowers.pushPrefEnv({
    set: [["dom.ipc.processCount", 1]],
  });

  let url1 = "https://example.com/1";
  ok(!thumbnailExists(url1), "First file should not exist yet.");

  let url2 = "https://example.com/2";
  ok(!thumbnailExists(url2), "Second file should not exist yet.");

  let defaultTimeout = BackgroundPageThumbs._destroyBrowserTimeout;
  BackgroundPageThumbs._destroyBrowserTimeout = 1000;

  await bgCapture(url1);
  ok(thumbnailExists(url1), "First file should exist after capture.");
  removeThumbnail(url1);

  // arbitrary wait - intermittent failures noted after 2 seconds
  await TestUtils.waitForCondition(
    () => {
      return BackgroundPageThumbs._thumbBrowser === undefined;
    },
    "BackgroundPageThumbs._thumbBrowser should eventually be discarded.",
    1000,
    5
  );

  is(
    BackgroundPageThumbs._thumbBrowser,
    undefined,
    "Thumb browser should be destroyed after timeout."
  );
  BackgroundPageThumbs._destroyBrowserTimeout = defaultTimeout;

  await bgCapture(url2);
  ok(thumbnailExists(url2), "Second file should exist after capture.");
  removeThumbnail(url2);

  isnot(
    BackgroundPageThumbs._thumbBrowser,
    undefined,
    "Thumb browser should exist immediately after capture."
  );
});