summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/xpcshell/test_shutdown.js
blob: d6fe08266605c7efe0486178af923ed0c7863705 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

// Verify that API functions fail if the Add-ons Manager isn't initialised.

const IGNORE = [
  "getPreferredIconURL",
  "escapeAddonURI",
  "shouldAutoUpdate",
  "getStartupChanges",
  "addAddonListener",
  "removeAddonListener",
  "addInstallListener",
  "removeInstallListener",
  "addManagerListener",
  "removeManagerListener",
  "addExternalExtensionLoader",
  "beforeShutdown",
  "init",
  "stateToString",
  "errorToString",
  "getUpgradeListener",
  "addUpgradeListener",
  "removeUpgradeListener",
  "getInstallSourceFromHost",
  "stageLangpacksForAppUpdate",
];

const IGNORE_PRIVATE = [
  "AddonAuthor",
  "AddonScreenshot",
  "startup",
  "shutdown",
  "addonIsActive",
  "registerProvider",
  "unregisterProvider",
  "addStartupChange",
  "removeStartupChange",
  "getNewSideloads",
  "finalShutdown",
  "recordTimestamp",
  "recordSimpleMeasure",
  "recordException",
  "getSimpleMeasures",
  "simpleTimer",
  "setTelemetryDetails",
  "getTelemetryDetails",
  "callNoUpdateListeners",
  "backgroundUpdateTimerHandler",
  "hasUpgradeListener",
  "getUpgradeListener",
  "isDBLoaded",
  "recordTiming",
  "BOOTSTRAP_REASONS",
  "notifyAddonChanged",
  "overrideAddonRepository",
  "overrideAsyncShutdown",
];

async function test_functions() {
  for (let prop in AddonManager) {
    if (IGNORE.includes(prop)) {
      continue;
    }
    if (typeof AddonManager[prop] != "function") {
      continue;
    }

    let args = [];

    // Getter functions need a callback and in some cases not having one will
    // throw before checking if the add-ons manager is initialized so pass in
    // an empty one.
    if (prop.startsWith("get")) {
      // For now all getter functions with more than one argument take the
      // callback in the second argument.
      if (AddonManager[prop].length > 1) {
        args.push(undefined, () => {});
      } else {
        args.push(() => {});
      }
    }

    // Clean this up in bug 1365720
    if (prop == "getActiveAddons") {
      args = [];
    }

    try {
      info("AddonManager." + prop);
      await AddonManager[prop](...args);
      do_throw(prop + " did not throw an exception");
    } catch (e) {
      if (e.result != Cr.NS_ERROR_NOT_INITIALIZED) {
        do_throw(prop + " threw an unexpected exception: " + e);
      }
    }
  }

  for (let prop in AddonManagerPrivate) {
    if (IGNORE_PRIVATE.includes(prop)) {
      continue;
    }
    if (typeof AddonManagerPrivate[prop] != "function") {
      continue;
    }

    try {
      info("AddonManagerPrivate." + prop);
      AddonManagerPrivate[prop]();
      do_throw(prop + " did not throw an exception");
    } catch (e) {
      if (e.result != Cr.NS_ERROR_NOT_INITIALIZED) {
        do_throw(prop + " threw an unexpected exception: " + e);
      }
    }
  }
}

add_task(async function () {
  await test_functions();
  await promiseStartupManager();
  await promiseShutdownManager();
  await test_functions();
});

function run_test() {
  createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
  run_next_test();
}