summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/update/tests/unit_aus_update/remoteUpdateXML.js
blob: 94081a01a56163fb2fee0345d772bfe1d6312b4f (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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

async function run_test() {
  setupTestCommon();
  debugDump("testing remote update xml attributes");
  start_httpserver();
  setUpdateURL(gURLData + gHTTPHandlerPath);
  setUpdateChannel("test_channel");

  debugDump("testing update xml not available");
  await waitForUpdateCheck(false).then(aArgs => {
    Assert.equal(
      aArgs.updates[0].errorCode,
      1500,
      "the update errorCode" + MSG_SHOULD_EQUAL
    );
  });

  debugDump(
    "testing one update available, the update's property values and " +
      "the property values of the update's patches"
  );
  let patchProps = {
    type: "complete",
    url: "http://complete/",
    size: "9856459",
  };
  let patches = getRemotePatchString(patchProps);
  patchProps = { type: "partial", url: "http://partial/", size: "1316138" };
  patches += getRemotePatchString(patchProps);
  let updateProps = {
    type: "minor",
    name: "Minor Test",
    displayVersion: "version 2.1a1pre",
    appVersion: "2.1a1pre",
    buildID: "20080811053724",
    detailsURL: "http://details/",
    promptWaitTime: "345600",
    custom1: 'custom1_attr="custom1 value"',
    custom2: 'custom2_attr="custom2 value"',
  };
  let updates = getRemoteUpdateString(updateProps, patches);
  gResponseBody = getRemoteUpdatesXMLString(updates);
  await waitForUpdateCheck(true, { updateCount: 1 }).then(aArgs => {
    // XXXrstrong - not specifying a detailsURL will cause a leak due to
    // bug 470244 and until this is fixed this will not test the value for
    // detailsURL when it isn't specified in the update xml.

    let bestUpdate = gAUS
      .selectUpdate(aArgs.updates)
      .QueryInterface(Ci.nsIWritablePropertyBag);
    Assert.equal(
      bestUpdate.type,
      "minor",
      "the update type attribute" + MSG_SHOULD_EQUAL
    );
    Assert.equal(
      bestUpdate.name,
      "Minor Test",
      "the update name attribute" + MSG_SHOULD_EQUAL
    );
    Assert.equal(
      bestUpdate.displayVersion,
      "version 2.1a1pre",
      "the update displayVersion attribute" + MSG_SHOULD_EQUAL
    );
    Assert.equal(
      bestUpdate.appVersion,
      "2.1a1pre",
      "the update appVersion attribute" + MSG_SHOULD_EQUAL
    );
    Assert.equal(
      bestUpdate.buildID,
      "20080811053724",
      "the update buildID attribute" + MSG_SHOULD_EQUAL
    );
    Assert.equal(
      bestUpdate.detailsURL,
      "http://details/",
      "the update detailsURL attribute" + MSG_SHOULD_EQUAL
    );
    Assert.equal(
      bestUpdate.promptWaitTime,
      "345600",
      "the update promptWaitTime attribute" + MSG_SHOULD_EQUAL
    );
    Assert.equal(
      bestUpdate.serviceURL,
      gURLData + gHTTPHandlerPath + "?force=1",
      "the update serviceURL attribute" + MSG_SHOULD_EQUAL
    );
    Assert.equal(
      bestUpdate.channel,
      "test_channel",
      "the update channel attribute" + MSG_SHOULD_EQUAL
    );
    Assert.ok(
      !bestUpdate.isCompleteUpdate,
      "the update isCompleteUpdate attribute" + MSG_SHOULD_EQUAL
    );
    Assert.ok(
      !bestUpdate.isSecurityUpdate,
      "the update isSecurityUpdate attribute" + MSG_SHOULD_EQUAL
    );
    // Check that installDate is within 10 seconds of the current date.
    Assert.ok(
      Date.now() - bestUpdate.installDate < 10000,
      "the update installDate attribute should be within 10 seconds " +
        "of the current time"
    );
    Assert.ok(
      !bestUpdate.statusText,
      "the update statusText attribute" + MSG_SHOULD_EQUAL
    );
    // nsIUpdate:state returns an empty string when no action has been performed
    // on an available update
    Assert.equal(
      bestUpdate.state,
      "",
      "the update state attribute" + MSG_SHOULD_EQUAL
    );
    Assert.equal(
      bestUpdate.errorCode,
      0,
      "the update errorCode attribute" + MSG_SHOULD_EQUAL
    );
    Assert.equal(
      bestUpdate.patchCount,
      2,
      "the update patchCount attribute" + MSG_SHOULD_EQUAL
    );
    // XXX TODO - test nsIUpdate:serialize

    Assert.equal(
      bestUpdate.getProperty("custom1_attr"),
      "custom1 value",
      "the update custom1_attr property" + MSG_SHOULD_EQUAL
    );
    Assert.equal(
      bestUpdate.getProperty("custom2_attr"),
      "custom2 value",
      "the update custom2_attr property" + MSG_SHOULD_EQUAL
    );

    let patch = bestUpdate.getPatchAt(0);
    Assert.equal(
      patch.type,
      "complete",
      "the update patch type attribute" + MSG_SHOULD_EQUAL
    );
    Assert.equal(
      patch.URL,
      "http://complete/",
      "the update patch URL attribute" + MSG_SHOULD_EQUAL
    );
    Assert.equal(
      patch.size,
      9856459,
      "the update patch size attribute" + MSG_SHOULD_EQUAL
    );
    // The value for patch.state can be the string 'null' as a valid value. This
    // is confusing if it returns null which is an invalid value since the test
    // failure output will show a failure for null == null. To lessen the
    // confusion first check that the typeof for patch.state is string.
    Assert.equal(
      typeof patch.state,
      "string",
      "the update patch state typeof value should equal |string|"
    );
    Assert.equal(
      patch.state,
      STATE_NONE,
      "the update patch state attribute" + MSG_SHOULD_EQUAL
    );
    Assert.ok(
      !patch.selected,
      "the update patch selected attribute" + MSG_SHOULD_EQUAL
    );
    // XXX TODO - test nsIUpdatePatch:serialize

    patch = bestUpdate.getPatchAt(1);
    Assert.equal(
      patch.type,
      "partial",
      "the update patch type attribute" + MSG_SHOULD_EQUAL
    );
    Assert.equal(
      patch.URL,
      "http://partial/",
      "the update patch URL attribute" + MSG_SHOULD_EQUAL
    );
    Assert.equal(
      patch.size,
      1316138,
      "the update patch size attribute" + MSG_SHOULD_EQUAL
    );
    Assert.equal(
      patch.state,
      STATE_NONE,
      "the update patch state attribute" + MSG_SHOULD_EQUAL
    );
    Assert.ok(
      !patch.selected,
      "the update patch selected attribute" + MSG_SHOULD_EQUAL
    );
    // XXX TODO - test nsIUpdatePatch:serialize
  });

  debugDump(
    "testing an empty update xml that returns a root node name of " +
      "parsererror"
  );
  gResponseBody = "<parsererror/>";
  await waitForUpdateCheck(false).then(aArgs => {
    Assert.equal(
      aArgs.updates[0].errorCode,
      1200,
      "the update errorCode" + MSG_SHOULD_EQUAL
    );
  });

  debugDump("testing no updates available");
  gResponseBody = getRemoteUpdatesXMLString("");
  await waitForUpdateCheck(true, { updateCount: 0 });

  debugDump("testing one update available with two patches");
  patches = getRemotePatchString({});
  patchProps = { type: "partial" };
  patches += getRemotePatchString(patchProps);
  updates = getRemoteUpdateString({}, patches);
  gResponseBody = getRemoteUpdatesXMLString(updates);
  await waitForUpdateCheck(true, { updateCount: 1 });

  debugDump("testing three updates available each with two patches");
  patches = getRemotePatchString({});
  patchProps = { type: "partial" };
  patches += getRemotePatchString(patchProps);
  updates = getRemoteUpdateString({}, patches);
  updates += updates + updates;
  gResponseBody = getRemoteUpdatesXMLString(updates);
  await waitForUpdateCheck(true, { updateCount: 3 });

  debugDump(
    "testing one update with complete and partial patches with size " +
      "0 specified in the update xml"
  );
  patchProps = { size: "0" };
  patches = getRemotePatchString(patchProps);
  patchProps = { type: "partial", size: "0" };
  patches += getRemotePatchString(patchProps);
  updates = getRemoteUpdateString({}, patches);
  gResponseBody = getRemoteUpdatesXMLString(updates);
  await waitForUpdateCheck(true).then(aArgs => {
    Assert.equal(
      aArgs.updates.length,
      0,
      "the update count" + MSG_SHOULD_EQUAL
    );
  });

  debugDump(
    "testing one update with complete patch with size 0 specified in " +
      "the update xml"
  );
  patchProps = { size: "0" };
  patches = getRemotePatchString(patchProps);
  updates = getRemoteUpdateString({}, patches);
  gResponseBody = getRemoteUpdatesXMLString(updates);
  await waitForUpdateCheck(true, { updateCount: 0 });

  debugDump(
    "testing one update with partial patch with size 0 specified in " +
      "the update xml"
  );
  patchProps = { type: "partial", size: "0" };
  patches = getRemotePatchString(patchProps);
  updates = getRemoteUpdateString({}, patches);
  gResponseBody = getRemoteUpdatesXMLString(updates);
  await waitForUpdateCheck(true, { updateCount: 0 });

  debugDump(
    "testing that updates for older versions of the application " +
      "aren't selected"
  );
  patches = getRemotePatchString({});
  patchProps = { type: "partial" };
  patches += getRemotePatchString(patchProps);
  updateProps = { appVersion: "1.0pre" };
  updates = getRemoteUpdateString(updateProps, patches);
  updateProps = { appVersion: "1.0a" };
  updates += getRemoteUpdateString(updateProps, patches);
  gResponseBody = getRemoteUpdatesXMLString(updates);
  await waitForUpdateCheck(true, { updateCount: 2 }).then(aArgs => {
    let bestUpdate = gAUS.selectUpdate(aArgs.updates);
    Assert.ok(!bestUpdate, "there shouldn't be an update available");
  });

  debugDump(
    "testing that updates for the current version of the application " +
      "are selected"
  );
  patches = getRemotePatchString({});
  patchProps = { type: "partial" };
  patches += getRemotePatchString(patchProps);
  updateProps = { appVersion: "1.0" };
  updates = getRemoteUpdateString(updateProps, patches);
  gResponseBody = getRemoteUpdatesXMLString(updates);
  await waitForUpdateCheck(true, { updateCount: 1 }).then(aArgs => {
    let bestUpdate = gAUS.selectUpdate(aArgs.updates);
    Assert.ok(!!bestUpdate, "there should be one update available");
    Assert.equal(
      bestUpdate.appVersion,
      "1.0",
      "the update appVersion attribute" + MSG_SHOULD_EQUAL
    );
    Assert.equal(
      bestUpdate.displayVersion,
      "1.0",
      "the update displayVersion attribute" + MSG_SHOULD_EQUAL
    );
  });

  stop_httpserver(doTestFinish);
}