summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/xpcshell/test_bug655254.js
blob: 45274b734fed83668f8732de7f734ee0f69436b5 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

// This verifies that moving an extension in the filesystem without any other
// change still keeps updated compatibility information

// The test extension uses an insecure update url.
Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false);
// Enable loading extensions from the user and system scopes
Services.prefs.setIntPref("extensions.enabledScopes",
                          AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_USER);

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

Components.utils.import("resource://testing-common/httpd.js");
var testserver = new HttpServer();
testserver.start(-1);
gPort = testserver.identity.primaryPort;
mapFile("/data/test_bug655254.rdf", testserver);

var userDir = gProfD.clone();
userDir.append("extensions2");
userDir.append(gAppInfo.ID);

var dirProvider = {
  getFile: function(aProp, aPersistent) {
    aPersistent.value = false;
    if (aProp == "XREUSysExt")
      return userDir.parent;
    return null;
  },

  QueryInterface: XPCOMUtils.generateQI([AM_Ci.nsIDirectoryServiceProvider,
                                         AM_Ci.nsISupports])
};
Services.dirsvc.registerProvider(dirProvider);

var addon1 = {
  id: "addon1@tests.mozilla.org",
  version: "1.0",
  name: "Test 1",
  updateURL: "http://localhost:" + gPort + "/data/test_bug655254.rdf",
  targetApplications: [{
    id: "xpcshell@tests.mozilla.org",
    minVersion: "1",
    maxVersion: "1"
  }]
};

// Set up the profile
function run_test() {
  do_test_pending();
  run_test_1();
}

function end_test() {
  testserver.stop(do_test_finished);
}

function run_test_1() {
  var time = Date.now();
  var dir = writeInstallRDFForExtension(addon1, userDir);
  setExtensionModifiedTime(dir, time);

  manuallyInstall(do_get_addon("test_bug655254_2"), userDir, "addon2@tests.mozilla.org");

  startupManager();

  AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                               "addon2@tests.mozilla.org"], function([a1, a2]) {
    do_check_neq(a1, null);
    do_check_true(a1.appDisabled);
    do_check_false(a1.isActive);
    do_check_false(isExtensionInAddonsList(userDir, a1.id));

    do_check_neq(a2, null);
    do_check_false(a2.appDisabled);
    do_check_true(a2.isActive);
    do_check_false(isExtensionInAddonsList(userDir, a2.id));
    do_check_eq(Services.prefs.getIntPref("bootstraptest.active_version"), 1);

    a1.findUpdates({
      onUpdateFinished: function() {
        restartManager();

        AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) {
          do_check_neq(a1, null);
          do_check_false(a1.appDisabled);
          do_check_true(a1.isActive);
          do_check_true(isExtensionInAddonsList(userDir, a1.id));

          shutdownManager();

          do_check_eq(Services.prefs.getIntPref("bootstraptest.active_version"), 0);

          userDir.parent.moveTo(gProfD, "extensions3");
          userDir = gProfD.clone();
          userDir.append("extensions3");
          userDir.append(gAppInfo.ID);
          do_check_true(userDir.exists());

          startupManager(false);

          AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                       "addon2@tests.mozilla.org"], function([a1, a2]) {
            do_check_neq(a1, null);
            do_check_false(a1.appDisabled);
            do_check_true(a1.isActive);
            do_check_true(isExtensionInAddonsList(userDir, a1.id));

            do_check_neq(a2, null);
            do_check_false(a2.appDisabled);
            do_check_true(a2.isActive);
            do_check_false(isExtensionInAddonsList(userDir, a2.id));
            do_check_eq(Services.prefs.getIntPref("bootstraptest.active_version"), 1);

            do_execute_soon(run_test_2);
          });
        }));
      }
    }, AddonManager.UPDATE_WHEN_USER_REQUESTED);
  });
}

//Set up the profile
function run_test_2() {
  AddonManager.getAddonByID("addon2@tests.mozilla.org", callback_soon(function(a2) {
   do_check_neq(a2, null);
   do_check_false(a2.appDisabled);
   do_check_true(a2.isActive);
   do_check_false(isExtensionInAddonsList(userDir, a2.id));
   do_check_eq(Services.prefs.getIntPref("bootstraptest.active_version"), 1);

   a2.userDisabled = true;
   do_check_eq(Services.prefs.getIntPref("bootstraptest.active_version"), 0);

   shutdownManager();

   userDir.parent.moveTo(gProfD, "extensions4");
   userDir = gProfD.clone();
   userDir.append("extensions4");
   userDir.append(gAppInfo.ID);
   do_check_true(userDir.exists());

   startupManager(false);

   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
                                "addon2@tests.mozilla.org"], function([a1, a2]) {
     do_check_neq(a1, null);
     do_check_false(a1.appDisabled);
     do_check_true(a1.isActive);
     do_check_true(isExtensionInAddonsList(userDir, a1.id));

     do_check_neq(a2, null);
     do_check_true(a2.userDisabled);
     do_check_false(a2.isActive);
     do_check_false(isExtensionInAddonsList(userDir, a2.id));
     do_check_eq(Services.prefs.getIntPref("bootstraptest.active_version"), 0);

     end_test();
   });
  }));
}