summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/test/browser/browser_ext_test_mock.js
blob: de496b7631674fce1138cae6d90ecc2062e42a7d (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
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";

// This test verifies that the extension mocks behave consistently, regardless
// of test type (xpcshell vs browser test).
// See also toolkit/components/extensions/test/xpcshell/test_ext_test_mock.js

// Check the state of the extension object. This should be consistent between
// browser tests and xpcshell tests.
async function checkExtensionStartupAndUnload(ext) {
  await ext.startup();
  Assert.ok(ext.id, "Extension ID should be available");
  Assert.ok(ext.uuid, "Extension UUID should be available");
  await ext.unload();
  // Once set nothing clears the UUID.
  Assert.ok(ext.uuid, "Extension UUID exists after unload");
}

add_task(async function test_MockExtension() {
  // When "useAddonManager" is set, a MockExtension is created in the main
  // process, which does not necessarily behave identically to an Extension.
  let ext = ExtensionTestUtils.loadExtension({
    // xpcshell/test_ext_test_mock.js tests "temporary", so here we use
    // "permanent" to have even more test coverage.
    useAddonManager: "permanent",
    manifest: {
      browser_specific_settings: { gecko: { id: "@permanent-mock-extension" } },
    },
  });

  Assert.ok(!ext.id, "Extension ID is initially unavailable");
  Assert.ok(!ext.uuid, "Extension UUID is initially unavailable");
  await checkExtensionStartupAndUnload(ext);
  Assert.ok(ext.id, "Extension ID exists after unload");
});

add_task(async function test_generated_Extension() {
  let ext = ExtensionTestUtils.loadExtension({
    manifest: {},
  });

  Assert.ok(!ext.id, "Extension ID is initially unavailable");
  Assert.ok(!ext.uuid, "Extension UUID is initially unavailable");
  await checkExtensionStartupAndUnload(ext);
  Assert.ok(ext.id, "Extension ID exists after unload");
});