summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/webextensions/test/xpcshell/test_provider_markSafe.js
blob: 228eb7d34f0dd0591c20482d72bd74e3723195c4 (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
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");

var startupOrder = [];

function mockAddonProvider(name) {
  let mockProvider = {
    markSafe: false,
    apiAccessed: false,

    startup() {
      if (this.markSafe)
        AddonManagerPrivate.markProviderSafe(this);

      let uri = Services.io.newURI("beard://long", null, null);
      AddonManager.isInstallEnabled("made-up-mimetype");
    },
    supportsMimetype(mimetype) {
      this.apiAccessed = true;
      return false;
    },

    get name() {
      return name;
    },
  };

  return mockProvider;
}

function run_test() {
  run_next_test();
}

add_task(function* testMarkSafe() {
  do_print("Starting with provider normally");
  let provider = mockAddonProvider("Mock1");
  AddonManagerPrivate.registerProvider(provider);
  startupManager();
  ok(!provider.apiAccessed, "Provider API should not have been accessed");
  AddonManagerPrivate.unregisterProvider(provider);
  yield promiseShutdownManager();

  do_print("Starting with provider that marks itself safe");
  provider.apiAccessed = false;
  provider.markSafe = true;
  AddonManagerPrivate.registerProvider(provider);
  startupManager();
  ok(provider.apiAccessed, "Provider API should have been accessed");
});