summaryrefslogtreecommitdiffstats
path: root/browser/components/newtab/test/browser/abouthomecache/browser_shutdown_timeout.js
blob: 52be79338eb6ff55c1015c915707008708fbe9e9 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Tests that if there's a substantial delay in getting the cache
 * streams from the privileged about content process for any reason
 * during shutdown, that we timeout and let the AsyncShutdown proceed,
 * rather than letting it block until AsyncShutdown causes a shutdown
 * hang crash.
 */
add_task(async function test_shutdown_timeout() {
  await withFullyLoadedAboutHome(async browser => {
    // First, make sure the cache is populated so that later on, after
    // the timeout, simulateRestart doesn't complain about not finding
    // a pre-existing cache. This complaining only happens if this test
    // is run in isolation.
    await clearCache();
    await simulateRestart(browser);

    // Next, manually shutdown the AboutHomeStartupCacheChild so that
    // it doesn't respond to requests to the cache streams.
    await SpecialPowers.spawn(browser, [], async () => {
      let { AboutHomeStartupCacheChild } = ChromeUtils.import(
        "resource:///modules/AboutNewTabService.jsm"
      );
      AboutHomeStartupCacheChild.uninit();
    });

    // Then, manually dirty the cache state so that we attempt to write
    // on shutdown.
    AboutHomeStartupCache.onPreloadedNewTabMessage();

    await simulateRestart(browser, { expectTimeout: true });

    Assert.ok(
      true,
      "We reached here, which means shutdown didn't block forever."
    );

    // Clear the cache so that we're not in a half-persisted state.
    await clearCache();
  });
});