summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/update/tests/unit_aus_update/updateManagerXML.js
blob: f15e51827ea0e6647da76c999d82ba25d2a237d7 (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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
/* 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/.
 */

function run_test() {
  setupTestCommon();

  debugDump(
    "testing addition of a successful update to " +
      FILE_UPDATES_XML +
      " and verification of update properties including the format " +
      "prior to bug 530872"
  );

  setUpdateChannel("test_channel");

  let patchProps = {
    type: "partial",
    url: "http://partial/",
    size: "86",
    selected: "true",
    state: STATE_PENDING,
    custom1: 'custom1_attr="custom1 patch value"',
    custom2: 'custom2_attr="custom2 patch value"',
  };
  let patches = getLocalPatchString(patchProps);
  let updateProps = {
    type: "major",
    name: "New",
    displayVersion: "version 4",
    appVersion: "4.0",
    buildID: "20070811053724",
    detailsURL: "http://details1/",
    serviceURL: "http://service1/",
    installDate: "1238441300314",
    statusText: "test status text",
    isCompleteUpdate: "false",
    channel: "test_channel",
    foregroundDownload: "true",
    promptWaitTime: "345600",
    previousAppVersion: "3.0",
    custom1: 'custom1_attr="custom1 value"',
    custom2: 'custom2_attr="custom2 value"',
  };
  let updates = getLocalUpdateString(updateProps, patches);
  writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true);
  writeStatusFile(STATE_SUCCEEDED);

  patchProps = {
    type: "complete",
    url: "http://complete/",
    size: "75",
    selected: "true",
    state: STATE_FAILED,
    custom1: 'custom3_attr="custom3 patch value"',
    custom2: 'custom4_attr="custom4 patch value"',
  };
  patches = getLocalPatchString(patchProps);
  updateProps = {
    type: "minor",
    name: "Existing",
    appVersion: "3.0",
    detailsURL: "http://details2/",
    serviceURL: "http://service2/",
    statusText: getString("patchApplyFailure"),
    isCompleteUpdate: "true",
    channel: "test_channel",
    foregroundDownload: "false",
    promptWaitTime: "691200",
    custom1: 'custom3_attr="custom3 value"',
    custom2: 'custom4_attr="custom4 value"',
  };
  updates = getLocalUpdateString(updateProps, patches);
  writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), false);

  standardInit();

  Assert.ok(
    !gUpdateManager.downloadingUpdate,
    "there should not be a downloading update"
  );
  Assert.ok(!gUpdateManager.readyUpdate, "there should not be a ready update");
  Assert.equal(
    gUpdateManager.getUpdateCount(),
    2,
    "the update manager updateCount attribute" + MSG_SHOULD_EQUAL
  );

  debugDump("checking the first update properties");
  let update = gUpdateManager
    .getUpdateAt(0)
    .QueryInterface(Ci.nsIWritablePropertyBag);
  Assert.equal(
    update.state,
    STATE_SUCCEEDED,
    "the update state attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    update.type,
    "major",
    "the update type attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    update.name,
    "New",
    "the update name attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    update.displayVersion,
    "version 4",
    "the update displayVersion attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    update.appVersion,
    "4.0",
    "the update appVersion attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    update.buildID,
    "20070811053724",
    "the update buildID attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    update.detailsURL,
    "http://details1/",
    "the update detailsURL attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    update.serviceURL,
    "http://service1/",
    "the update serviceURL attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    update.installDate,
    "1238441300314",
    "the update installDate attribute" + MSG_SHOULD_EQUAL
  );
  // statusText is updated
  Assert.equal(
    update.statusText,
    getString("installSuccess"),
    "the update statusText attribute" + MSG_SHOULD_EQUAL
  );
  Assert.ok(
    !update.isCompleteUpdate,
    "the update isCompleteUpdate attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    update.channel,
    "test_channel",
    "the update channel attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    update.promptWaitTime,
    "345600",
    "the update promptWaitTime attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    update.previousAppVersion,
    "3.0",
    "the update previousAppVersion attribute" + MSG_SHOULD_EQUAL
  );
  // Custom attributes
  Assert.equal(
    update.getProperty("custom1_attr"),
    "custom1 value",
    "the update custom1_attr property" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    update.getProperty("custom2_attr"),
    "custom2 value",
    "the update custom2_attr property" + MSG_SHOULD_EQUAL
  );
  // nsIPropertyBag enumerator
  debugDump("checking the first update enumerator");
  Assert.ok(
    update.enumerator instanceof Ci.nsISimpleEnumerator,
    "update enumerator should be an instance of nsISimpleEnumerator"
  );
  let results = Array.from(update.enumerator);
  Assert.equal(
    results.length,
    3,
    "the length of the array created from the update enumerator" +
      MSG_SHOULD_EQUAL
  );
  Assert.ok(
    results.every(prop => prop instanceof Ci.nsIProperty),
    "the objects in the array created from the update enumerator " +
      "should all be an instance of nsIProperty"
  );
  Assert.equal(
    results[0].name,
    "custom1_attr",
    "the first property name" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    results[0].value,
    "custom1 value",
    "the first property value" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    results[1].name,
    "custom2_attr",
    "the second property name" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    results[1].value,
    "custom2 value",
    "the second property value" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    results[2].name,
    "foregroundDownload",
    "the second property name" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    results[2].value,
    "true",
    "the third property value" + MSG_SHOULD_EQUAL
  );

  debugDump("checking the first update patch properties");
  let patch = update.selectedPatch.QueryInterface(Ci.nsIWritablePropertyBag);
  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,
    "86",
    "the update patch size attribute" + MSG_SHOULD_EQUAL
  );
  Assert.ok(
    !!patch.selected,
    "the update patch selected attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    patch.state,
    STATE_SUCCEEDED,
    "the update patch state attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    patch.getProperty("custom1_attr"),
    "custom1 patch value",
    "the update patch custom1_attr property" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    patch.getProperty("custom2_attr"),
    "custom2 patch value",
    "the update patch custom2_attr property" + MSG_SHOULD_EQUAL
  );
  // nsIPropertyBag enumerator
  debugDump("checking the first update patch enumerator");
  Assert.ok(
    patch.enumerator instanceof Ci.nsISimpleEnumerator,
    "patch enumerator should be an instance of nsISimpleEnumerator"
  );
  results = Array.from(patch.enumerator);
  Assert.equal(
    results.length,
    2,
    "the length of the array created from the patch enumerator" +
      MSG_SHOULD_EQUAL
  );
  Assert.ok(
    results.every(prop => prop instanceof Ci.nsIProperty),
    "the objects in the array created from the patch enumerator " +
      "should all be an instance of nsIProperty"
  );
  Assert.equal(
    results[0].name,
    "custom1_attr",
    "the first property name" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    results[0].value,
    "custom1 patch value",
    "the first property value" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    results[1].name,
    "custom2_attr",
    "the second property name" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    results[1].value,
    "custom2 patch value",
    "the second property value" + MSG_SHOULD_EQUAL
  );

  debugDump("checking the second update properties");
  update = gUpdateManager
    .getUpdateAt(1)
    .QueryInterface(Ci.nsIWritablePropertyBag);
  Assert.equal(
    update.state,
    STATE_FAILED,
    "the update state attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    update.name,
    "Existing",
    "the update name attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    update.type,
    "minor",
    "the update type attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    update.displayVersion,
    "3.0",
    "the update displayVersion attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    update.appVersion,
    "3.0",
    "the update appVersion attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    update.detailsURL,
    "http://details2/",
    "the update detailsURL attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    update.serviceURL,
    "http://service2/",
    "the update serviceURL attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    update.installDate,
    "1238441400314",
    "the update installDate attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    update.statusText,
    getString("patchApplyFailure"),
    "the update statusText attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    update.buildID,
    "20080811053724",
    "the update buildID attribute" + MSG_SHOULD_EQUAL
  );
  Assert.ok(
    !!update.isCompleteUpdate,
    "the update isCompleteUpdate attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    update.channel,
    "test_channel",
    "the update channel attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    update.promptWaitTime,
    "691200",
    "the update promptWaitTime attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    update.previousAppVersion,
    "1.0",
    "the update previousAppVersion attribute" + MSG_SHOULD_EQUAL
  );
  // Custom attributes
  Assert.equal(
    update.getProperty("custom3_attr"),
    "custom3 value",
    "the update custom3_attr property" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    update.getProperty("custom4_attr"),
    "custom4 value",
    "the update custom4_attr property" + MSG_SHOULD_EQUAL
  );
  // nsIPropertyBag enumerator
  debugDump("checking the second update enumerator");
  Assert.ok(
    update.enumerator instanceof Ci.nsISimpleEnumerator,
    "update enumerator should be an instance of nsISimpleEnumerator"
  );
  results = Array.from(update.enumerator);
  Assert.equal(
    results.length,
    3,
    "the length of the array created from the update enumerator" +
      MSG_SHOULD_EQUAL
  );
  Assert.ok(
    results.every(prop => prop instanceof Ci.nsIProperty),
    "the objects in the array created from the update enumerator " +
      "should all be an instance of nsIProperty"
  );
  Assert.equal(
    results[0].name,
    "custom3_attr",
    "the first property name" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    results[0].value,
    "custom3 value",
    "the first property value" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    results[1].name,
    "custom4_attr",
    "the second property name" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    results[1].value,
    "custom4 value",
    "the second property value" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    results[2].name,
    "foregroundDownload",
    "the third property name" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    results[2].value,
    "false",
    "the third property value" + MSG_SHOULD_EQUAL
  );

  debugDump("checking the second update patch properties");
  patch = update.selectedPatch.QueryInterface(Ci.nsIWritablePropertyBag);
  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,
    "75",
    "the update patch size attribute" + MSG_SHOULD_EQUAL
  );
  Assert.ok(
    !!patch.selected,
    "the update patch selected attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    patch.state,
    STATE_FAILED,
    "the update patch state attribute" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    patch.getProperty("custom3_attr"),
    "custom3 patch value",
    "the update patch custom3_attr property" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    patch.getProperty("custom4_attr"),
    "custom4 patch value",
    "the update patch custom4_attr property" + MSG_SHOULD_EQUAL
  );
  // nsIPropertyBag enumerator
  debugDump("checking the second update patch enumerator");
  Assert.ok(
    patch.enumerator instanceof Ci.nsISimpleEnumerator,
    "patch enumerator should be an instance of nsISimpleEnumerator"
  );
  results = Array.from(patch.enumerator);
  Assert.equal(
    results.length,
    2,
    "the length of the array created from the patch enumerator" +
      MSG_SHOULD_EQUAL
  );
  Assert.ok(
    results.every(prop => prop instanceof Ci.nsIProperty),
    "the objects in the array created from the patch enumerator " +
      "should all be an instance of nsIProperty"
  );
  Assert.equal(
    results[0].name,
    "custom3_attr",
    "the first property name" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    results[0].value,
    "custom3 patch value",
    "the first property value" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    results[1].name,
    "custom4_attr",
    "the second property name" + MSG_SHOULD_EQUAL
  );
  Assert.equal(
    results[1].value,
    "custom4 patch value",
    "the second property value" + MSG_SHOULD_EQUAL
  );

  let attrNames = [
    "appVersion",
    "buildID",
    "channel",
    "detailsURL",
    "displayVersion",
    "elevationFailure",
    "errorCode",
    "installDate",
    "isCompleteUpdate",
    "name",
    "previousAppVersion",
    "promptWaitTime",
    "serviceURL",
    "state",
    "statusText",
    "type",
    "unsupported",
  ];
  checkIllegalProperties(update, attrNames);

  attrNames = [
    "errorCode",
    "finalURL",
    "selected",
    "size",
    "state",
    "type",
    "URL",
  ];
  checkIllegalProperties(patch, attrNames);

  executeSoon(doTestFinish);
}

function checkIllegalProperties(object, propertyNames) {
  let objectName =
    object instanceof Ci.nsIUpdate ? "nsIUpdate" : "nsIUpdatePatch";
  propertyNames.forEach(function (name) {
    // Check that calling getProperty, setProperty, and deleteProperty on an
    // nsIUpdate attribute throws NS_ERROR_ILLEGAL_VALUE
    let result = 0;
    try {
      object.getProperty(name);
    } catch (e) {
      result = e.result;
    }
    Assert.equal(
      result,
      Cr.NS_ERROR_ILLEGAL_VALUE,
      "calling getProperty using an " +
        objectName +
        " attribute " +
        "name should throw NS_ERROR_ILLEGAL_VALUE"
    );

    result = 0;
    try {
      object.setProperty(name, "value");
    } catch (e) {
      result = e.result;
    }
    Assert.equal(
      result,
      Cr.NS_ERROR_ILLEGAL_VALUE,
      "calling setProperty using an " +
        objectName +
        " attribute " +
        "name should throw NS_ERROR_ILLEGAL_VALUE"
    );

    result = 0;
    try {
      object.deleteProperty(name);
    } catch (e) {
      result = e.result;
    }
    Assert.equal(
      result,
      Cr.NS_ERROR_ILLEGAL_VALUE,
      "calling deleteProperty using an " +
        objectName +
        " attribute " +
        "name should throw NS_ERROR_ILLEGAL_VALUE"
    );
  });
}