summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/xpcshell/test_upgrade_incompatible.js
blob: b9eb0f31e10946f1af05c200b5e35c86a3670905 (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
// Tests that when an extension manifest that was previously valid becomes
// unparseable after an application update, the extension becomes
// disabled.  (See bug 1439600 for a concrete example of a situation where
// this happened).
add_task(async function test_upgrade_incompatible() {
  const ID = "incompatible-upgrade@tests.mozilla.org";

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

  await promiseStartupManager();

  let file = createTempWebExtensionFile({
    manifest: {
      browser_specific_settings: { gecko: { id: ID } },
    },
  });

  let { addon } = await promiseInstallFile(file);

  notEqual(addon, null);
  equal(addon.appDisabled, false);

  await promiseShutdownManager();

  // Create a new, incompatible extension
  let newfile = createTempWebExtensionFile({
    manifest: {
      browser_specific_settings: { gecko: { id: ID } },
      manifest_version: 1,
    },
  });

  // swap the incompatible extension in for the original
  let path = PathUtils.join(gProfD.path, "extensions", `${ID}.xpi`);
  let fileInfo = await IOUtils.stat(path);
  let timestamp = fileInfo.lastModified;

  await IOUtils.move(newfile.path, path);
  await promiseSetExtensionModifiedTime(path, timestamp);
  Services.obs.notifyObservers(new FileUtils.File(path), "flush-cache-entry");

  // Restart.  With the change to the DB schema we recompute compatibility.
  // With an unparseable manifest the addon should become disabled.
  Services.prefs.setIntPref("extensions.databaseSchema", 0);
  await promiseStartupManager();

  addon = await promiseAddonByID(ID);
  notEqual(addon, null);
  equal(addon.appDisabled, true);

  await promiseShutdownManager();

  file = createTempWebExtensionFile({
    manifest: {
      browser_specific_settings: { gecko: { id: ID } },
    },
  });

  // swap the old extension back in and check that we don't persist the disabled state forever.
  await IOUtils.move(file.path, path);
  await promiseSetExtensionModifiedTime(path, timestamp);
  Services.obs.notifyObservers(new FileUtils.File(path), "flush-cache-entry");

  // Restart.  With the change to the DB schema we recompute compatibility.
  Services.prefs.setIntPref("extensions.databaseSchema", 0);
  await promiseStartupManager();

  addon = await promiseAddonByID(ID);
  notEqual(addon, null);
  equal(addon.appDisabled, false);

  await promiseShutdownManager();
});