summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/addons/test_symbol/bootstrap.js
blob: 4eb8b4875f9b678af941b416f70b3b3a7120c3b3 (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
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/AddonManager.jsm");

const PASS_PREF = "symboltest.instanceid.pass";
const FAIL_BOGUS_PREF = "symboltest.instanceid.fail_bogus";
const FAIL_ID_PREF = "symboltest.instanceid.fail_bogus";
const ADDON_ID = "test_symbol@tests.mozilla.org";

function install(data, reason) {}

// normally we would use BootstrapMonitor here, but we need a reference to
// the symbol inside `XPIProvider.jsm`.
function startup(data, reason) {
  Services.prefs.setBoolPref(PASS_PREF, false);
  Services.prefs.setBoolPref(FAIL_BOGUS_PREF, false);
  Services.prefs.setBoolPref(FAIL_ID_PREF, false);

  // test with the correct symbol
  if (data.hasOwnProperty("instanceID") && data.instanceID) {
    AddonManager.getAddonByInstanceID(data.instanceID)
      .then(addon => {
        if (addon.id == ADDON_ID) {
          Services.prefs.setBoolPref(PASS_PREF, true);
        }
      }).catch(err => {
        throw Error("no addon found for symbol");
      });

  }

  // test with a totally bogus symbol
  AddonManager.getAddonByInstanceID(Symbol("bad symbol"))
    .then(addon => {
      // there is no symbol by this name, so null should be returned
      if (addon == null) {
        Services.prefs.setBoolPref(FAIL_BOGUS_PREF, true);
      } else {
        throw Error("bad symbol should not match:", addon);
      }
    }).catch(err => {
      throw Error("promise should not have rejected: " + err);
    });

  // try to make a matching symbol - this should fail because it's not a
  // reference to the same symbol stored inside the addons manager.
  AddonManager.getAddonByInstanceID(Symbol(ADDON_ID))
    .then(addon => {
      // there is no symbol by this name, so null should be returned
      if (addon == null) {
        Services.prefs.setBoolPref(FAIL_ID_PREF, true);
      } else {
        throw Error("bad symbol should not match:", addon);
      }
    }).catch(err => {
      throw Error("promise should not have rejected: " + err);
    });

}

function shutdown(data, reason) {}

function uninstall(data, reason) {}