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

const ID = "proxy1@tests.mozilla.org";

createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "42");
startupManager();

BootstrapMonitor.init();

// Ensure that a proxy file to an add-on with a valid manifest works.
add_task(function*() {
  let tempdir = gTmpD.clone();
  writeInstallRDFToDir({
    id: ID,
    version: "1.0",
    bootstrap: true,
    unpack: true,
    targetApplications: [{
          id: "xpcshell@tests.mozilla.org",
      minVersion: "1",
      maxVersion: "1"
        }],
    name: "Test Bootstrap 1 (proxy)",
  }, tempdir, ID, "bootstrap.js");

  let unpackedAddon = tempdir.clone();
  unpackedAddon.append(ID);
  do_get_file("data/test_proxy/bootstrap.js")
    .copyTo(unpackedAddon, "bootstrap.js");

  // create proxy file in profile/extensions dir
  let extensionsDir = gProfD.clone();
  extensionsDir.append("extensions");
  let proxyFile = writeProxyFileToDir(extensionsDir, unpackedAddon, ID);

  yield promiseRestartManager();

  BootstrapMonitor.checkAddonInstalled(ID, "1.0");
  BootstrapMonitor.checkAddonStarted(ID, "1.0");

  let addon = yield promiseAddonByID(ID);

  do_check_neq(addon, null);
  do_check_eq(addon.version, "1.0");
  do_check_eq(addon.name, "Test Bootstrap 1 (proxy)");
  do_check_true(addon.isCompatible);
  do_check_false(addon.appDisabled);
  do_check_true(addon.isActive);
  do_check_eq(addon.type, "extension");
  do_check_eq(addon.signedState, mozinfo.addon_signing ? AddonManager.SIGNEDSTATE_SIGNED : AddonManager.SIGNEDSTATE_NOT_REQUIRED);

  do_check_true(proxyFile.exists());

  addon.uninstall();
  unpackedAddon.remove(true);

  yield promiseRestartManager();
});


// Ensure that a proxy file to an add-on is not removed even
// if the manifest file is invalid. See bug 1195353.
add_task(function*() {
  let tempdir = gTmpD.clone();

  // use a mismatched ID to make this install.rdf invalid
  writeInstallRDFToDir({
    id: "bad-proxy1@tests.mozilla.org",
    version: "1.0",
    bootstrap: true,
    unpack: true,
    targetApplications: [{
          id: "xpcshell@tests.mozilla.org",
      minVersion: "1",
      maxVersion: "1"
        }],
    name: "Test Bootstrap 1 (proxy)",
  }, tempdir, ID, "bootstrap.js");

  let unpackedAddon = tempdir.clone();
  unpackedAddon.append(ID);
  do_get_file("data/test_proxy/bootstrap.js")
    .copyTo(unpackedAddon, "bootstrap.js");

  // create proxy file in profile/extensions dir
  let extensionsDir = gProfD.clone();
  extensionsDir.append("extensions");
  let proxyFile = writeProxyFileToDir(extensionsDir, unpackedAddon, ID);

  yield promiseRestartManager();

  BootstrapMonitor.checkAddonNotInstalled(ID, "1.0");
  BootstrapMonitor.checkAddonNotStarted(ID, "1.0");

  let addon = yield promiseAddonByID(ID);
  do_check_eq(addon, null);

  do_check_true(proxyFile.exists());

  unpackedAddon.remove(true);
  proxyFile.remove(true);

  yield promiseRestartManager();
});