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

"use strict";

/**
 * This file tests scenarios where the cache is disabled due to user
 * configuration.
 */

registerCleanupFunction(async () => {
  // When the test completes, make sure we cleanup with a populated cache,
  // since this is the default starting state for these tests.
  await withFullyLoadedAboutHome(async browser => {
    await simulateRestart(browser);
  });
});

/**
 * Tests the case where the cache is disabled via the pref.
 */
add_task(async function test_cache_disabled() {
  await withFullyLoadedAboutHome(async browser => {
    await SpecialPowers.pushPrefEnv({
      set: [["browser.startup.homepage.abouthome_cache.enabled", false]],
    });

    await simulateRestart(browser);

    await ensureDynamicAboutHome(
      browser,
      AboutHomeStartupCache.CACHE_RESULT_SCALARS.DISABLED
    );

    await SpecialPowers.popPrefEnv();
  });
});

/**
 * Tests the case where the cache is disabled because the home page is
 * not set at about:home.
 */
add_task(async function test_cache_custom_homepage() {
  await withFullyLoadedAboutHome(async browser => {
    await HomePage.set("https://example.com");
    await simulateRestart(browser);

    await ensureDynamicAboutHome(
      browser,
      AboutHomeStartupCache.CACHE_RESULT_SCALARS.NOT_LOADING_ABOUTHOME
    );

    HomePage.reset();
  });
});

/**
 * Tests the case where the cache is disabled because the session is
 * configured to automatically be restored.
 */
add_task(async function test_cache_restore_session() {
  await withFullyLoadedAboutHome(async browser => {
    await SpecialPowers.pushPrefEnv({
      set: [["browser.startup.page", 3]],
    });

    await simulateRestart(browser);

    await ensureDynamicAboutHome(
      browser,
      AboutHomeStartupCache.CACHE_RESULT_SCALARS.NOT_LOADING_ABOUTHOME
    );

    await SpecialPowers.popPrefEnv();
  });
});

/**
 * Tests the case where the cache is disabled because about:newtab
 * preloading is disabled.
 */
add_task(async function test_cache_no_preloading() {
  await withFullyLoadedAboutHome(async browser => {
    await SpecialPowers.pushPrefEnv({
      set: [["browser.newtab.preload", false]],
    });

    await simulateRestart(browser);

    await ensureDynamicAboutHome(
      browser,
      AboutHomeStartupCache.CACHE_RESULT_SCALARS.PRELOADING_DISABLED
    );

    await SpecialPowers.popPrefEnv();
  });
});