This repository has been archived by the owner on Nov 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathtest.rdf.js
769 lines (680 loc) · 34.4 KB
/
test.rdf.js
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
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
/* 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/. */
"use strict";
var RDF = require("../../lib/rdf");
var DOMParser = require("xmldom").DOMParser;
var chai = require("chai");
var expect = chai.expect;
var GUIDS = require("../../lib/settings").ids;
var MIN_VERSION = require("../../lib/settings").MIN_VERSION;
var MAX_VERSION = require("../../lib/settings").MAX_VERSION;
var getData = require("../../lib/xpi/utils").getData;
describe("lib/rdf", function() {
describe("defaults", function() {
it("uses default values when none specified", function() {
var str = RDF.createRDF({ id: "myaddon@jetpack" });
var xml = parseRDF(str);
expect(getData(xml, "em:id")).to.be.equal("myaddon@jetpack");
// This should throw elsewhere
expect(getData(xml, "em:version")).to.be.equal("0.0.0");
expect(getData(xml, "em:bootstrap")).to.be.equal("true");
expect(getData(xml, "em:unpack")).to.be.equal("false");
expect(getData(xml, "em:type")).to.be.equal("2");
expect(getData(xml, "em:name")).to.be.equal("Untitled");
expect(getData(xml, "em:description")).to.be.equal(undefined);
expect(getData(xml, "em:iconURL")).to.be.equal(undefined);
expect(getData(xml, "em:icon64URL")).to.be.equal(undefined);
expect(getData(xml, "em:translator")).to.be.equal(undefined);
expect(getData(xml, "em:contributor")).to.be.equal(undefined);
expect(str.indexOf("homepageURL")).to.be.equal(-1);
["description", "creator"].forEach(function(field) {
expect(nodeEmpty(xml, "em:" + field)).to.be.equal(true);
});
expect(nodeExists(xml, "em:description")).to.be.equal(false);
expect(nodeExists(xml, "em:iconURL")).to.be.equal(false);
expect(nodeExists(xml, "em:icon64URL")).to.be.equal(false);
expect(nodeExists(xml, "em:translator")).to.be.equal(false);
expect(nodeExists(xml, "em:contributor")).to.be.equal(false);
});
});
describe("attributes", function() {
it("parses a correct ID", function() {
var xml = setupRDF({ id: "myaddon@jetpack" });
expect(getData(xml, "em:id")).to.be.equal("myaddon@jetpack");
});
it("passes in a version", function() {
var xml = setupRDF({ version: "1.4.1" });
expect(getData(xml, "em:version")).to.be.equal("1.4.1");
});
it("name uses `title` first", function() {
var xml = setupRDF({ title: "my-title", name: "my-name" });
expect(getData(xml, "em:name")).to.be.equal("my-title");
});
it("name uses `name` after `title`", function() {
var xml = setupRDF({ name: "my-name" });
expect(getData(xml, "em:name")).to.be.equal("my-name");
});
it("name is xml-escaped", function() {
var xml = RDF.createRDF({ name: "my-nam>e" });
expect(xml.indexOf("my-nam>e")).to.be.not.equal(-1);
});
it("homepage uses `homepageURL`", function() {
var xml = setupRDF({ homepage: "http://mozilla.com" });
expect(getData(xml, "em:homepageURL")).to.be.equal("http://mozilla.com");
});
it("unpack uses `unpack`", function() {
var xml = setupRDF({ unpack: true });
expect(getData(xml, "em:unpack")).to.be.equal("true");
});
it("description uses `description`", function() {
var xml = setupRDF({ description: "my-desc" });
expect(getData(xml, "em:description")).to.be.equal("my-desc");
});
it("description is xml-escaped", function() {
var xml = RDF.createRDF({ name: "my-des>c" });
expect(xml.indexOf("my-des>c")).to.be.not.equal(-1);
});
it("creator uses `author`", function() {
var xml = setupRDF({ author: "Marie Curie" });
expect(getData(xml, "em:creator")).to.be.equal("Marie Curie");
});
it("author is xml-escaped", function() {
var xml = RDF.createRDF({ name: "Marie Curie <mc@espci.fr>" });
expect(xml.indexOf("Marie Curie <mc@espci.fr>")).to.be.not.equal(-1);
});
it("iconURL uses `icon` with string", function() {
var xml = setupRDF({ id: "icon@jetpack", icon: "megaman.png" });
expect(getData(xml, "em:iconURL")).to.be.equal("resource://icon-at-jetpack/megaman.png");
});
it("iconURL uses `icon` with object no 48", function() {
var xml = setupRDF({ id: "icon@jetpack", icon: { "32": "foo32.png" } });
expect(getData(xml, "em:iconURL")).to.be.equal("resource://icon-at-jetpack/foo32.png");
});
// Use 48 because as of Fx 4 48 can be used in place of 32
it("iconURL uses `icon` with object and 48", function() {
var xml = setupRDF({ id: "icon@jetpack", icon: {
"32": "foo32.png",
"48": "foo48.png"
} });
expect(getData(xml, "em:iconURL")).to.be.equal("resource://icon-at-jetpack/foo48.png");
});
// Use 48 because as of Fx 4 48 can be used in place of 32
it("iconURL uses `icon` with object with no 32", function() {
var xml = setupRDF({ id: "icon@jetpack", icon: { "48": "foo48.png" } });
expect(getData(xml, "em:iconURL")).to.be.equal("resource://icon-at-jetpack/foo48.png");
});
it("iconURL ignores default `icon.png`", function() {
var xml = setupRDF({ id: "icon@jetpack", icon: "icon.png" });
expect(getData(xml, "em:iconURL")).to.be.equal(undefined);
expect(getData(xml, "em:icon64URL")).to.be.equal(undefined);
});
it("iconURL uses a url without modifying it", function () {
var xml1 = setupRDF({ id: "icon@jetpack", icon: "http://mozilla.org/icon.png" });
expect(getData(xml1, "em:iconURL")).to.be.equal("http://mozilla.org/icon.png");
var xml2 = setupRDF({ id: "icon@jetpack", icon: "chrome://icon-at-jetpack/icon.png" });
expect(getData(xml2, "em:iconURL")).to.be.equal("chrome://icon-at-jetpack/icon.png");
var xml3 = setupRDF({ id: "icon@jetpack", icon: "resource://icon-at-jetpack/megaman.png" });
expect(getData(xml3, "em:iconURL")).to.be.equal("resource://icon-at-jetpack/megaman.png");
});
it("icon64URL uses a url without modifying it", function () {
var xml1 = setupRDF({ id: "icon@jetpack", icon: { "64": "http://mozilla.org/icon.png" } });
expect(getData(xml1, "em:icon64URL")).to.be.equal("http://mozilla.org/icon.png");
var xml2 = setupRDF({ id: "icon@jetpack", icon: { "64": "chrome://icon-at-jetpack/icon.png" } });
expect(getData(xml2, "em:icon64URL")).to.be.equal("chrome://icon-at-jetpack/icon.png");
var xml3 = setupRDF({ id: "icon@jetpack", icon: { "64": "resource://icon-at-jetpack/megaman.png" } });
expect(getData(xml3, "em:icon64URL")).to.be.equal("resource://icon-at-jetpack/megaman.png");
});
it("icon64URL uses `icon64`", function() {
var xml = setupRDF({ id: "icon@jetpack", icon: { "64": "megaman.png" } });
expect(getData(xml, "em:icon64URL")).to.be.equal("resource://icon-at-jetpack/megaman.png");
});
it("icon64URL ignores default `icon64.png`", function() {
var xml = setupRDF({ id: "icon@jetpack", icon: { "64": "icon64.png" } });
expect(getData(xml, "em:iconURL")).to.be.equal(undefined);
expect(getData(xml, "em:icon64URL")).to.be.equal(undefined);
});
it("iconURL and icon64URL are not touched if a custom bootstrap.js provided", function() {
var xml1 = setupRDF({ id: "icon@jetpack", icon: { "32": "megaman.png" } }, false);
expect(getData(xml1, "em:iconURL")).to.be.equal("megaman.png");
var xml2 = setupRDF({ id: "icon@jetpack", icon: { "64": "megaman.png" } }, false);
expect(getData(xml2, "em:icon64URL")).to.be.equal("megaman.png");
});
it("updateURL uses `updateURL`", function() {
var url = "https://mozilla.org/update.rdf";
var xml = setupRDF({ updateURL: url });
expect(getData(xml, "em:updateURL")).to.be.equal(url);
});
it("updateURL DNE when it is undefined", function() {
var xml = RDF.createRDF({ id: "1" });
expect(xml.indexOf("updateURL")).to.be.equal(-1);
xml = RDF.createRDF({ id: "1", updateURL: undefined });
expect(xml.indexOf("updateURL")).to.be.equal(-1);
});
it("updateKey uses `updateKey`", function() {
var key = "xyz";
var xml = setupRDF({ updateKey: key });
expect(getData(xml, "em:updateKey")).to.be.equal(key);
});
it("updateKey DNE when it is undefined", function() {
var xml = RDF.createRDF({ id: "1" });
expect(xml.indexOf("updateKey")).to.be.equal(-1);
xml = RDF.createRDF({ id: "1", updateKey: undefined });
expect(xml.indexOf("updateKey")).to.be.equal(-1);
});
it("multiprocess permission", function() {
var xml = parseRDF(RDF.createRDF({ id: "1" }));
expect(nodeExists(xml, "em:multiprocessCompatible")).to.be.equal(false);
expect(getData(xml, "em:multiprocessCompatible")).to.be.equal(undefined);
xml = parseRDF(RDF.createRDF({ id: "1", permissions: { multiprocess: true } }));
expect(nodeExists(xml, "em:multiprocessCompatible")).to.be.equal(true);
expect(getData(xml, "em:multiprocessCompatible")).to.be.equal("true");
xml = parseRDF(RDF.createRDF({ id: "1", permissions: { multiprocess: false } }));
expect(nodeExists(xml, "em:multiprocessCompatible")).to.be.equal(true);
expect(getData(xml, "em:multiprocessCompatible")).to.be.equal("false");
});
it("adds `translator` fields for each translator", function() {
var xml = setupRDF({ translators: [
"Bebop", "Rocksteady"
]});
var translators = xml.getElementsByTagName("em:translator");
expect(translators.length).to.be.equal(2);
expect(translators[0].childNodes[0].data).to.be.equal("Bebop");
expect(translators[1].childNodes[0].data).to.be.equal("Rocksteady");
});
it("adds `contributor` fields for each contributor", function() {
var xml = setupRDF({ contributors: [
"Bebop", "Rocksteady"
]});
var translators = xml.getElementsByTagName("em:contributor");
expect(translators.length).to.be.equal(2);
expect(translators[0].childNodes[0].data).to.be.equal("Bebop");
expect(translators[1].childNodes[0].data).to.be.equal("Rocksteady");
});
it("hasEmbeddedWebExtension optional property", function() {
var xml = parseRDF(RDF.createRDF({ id: "1" }));
expect(nodeExists(xml, "em:hasEmbeddedWebExtension")).to.be.equal(false);
expect(getData(xml, "em:hasEmbeddedWebExtension")).to.be.equal(undefined);
xml = parseRDF(RDF.createRDF({ id: "1", hasEmbeddedWebExtension: true }));
expect(nodeExists(xml, "em:hasEmbeddedWebExtension")).to.be.equal(true);
expect(getData(xml, "em:hasEmbeddedWebExtension")).to.be.equal("true");
xml = parseRDF(RDF.createRDF({ id: "1", hasEmbeddedWebExtension: false }));
expect(nodeExists(xml, "em:hasEmbeddedWebExtension")).to.be.equal(false);
expect(getData(xml, "em:hasEmbeddedWebExtension")).to.be.equal(undefined);
});
});
describe("author", function() {
it("handles `author` fields with 'name <email@address.com>'", function() {
var xml = setupRDF({ author: "Marie Curie <mc@espci.fr>" });
expect(getData(xml, "em:creator")).to.be.equal("Marie Curie <mc@espci.fr>");
});
it("handles `author` fields with only an email address", function() {
var xml = setupRDF({ author: "mc@espci.fr" });
expect(getData(xml, "em:creator")).to.be.equal("mc@espci.fr");
});
it("handles `author` field as an object with `name` field", function() {
var xml = setupRDF({ author: { name: "Marie Curie", email: "mc@espci.fr"} });
expect(getData(xml, "em:creator")).to.be.equal("Marie Curie");
});
it("if `author` field is '' or undefined, do not ceate <em:creator/>", function() {
var xml = setupRDF({ author: "" });
expect(getData(xml, "em:creator")).to.be.equal(undefined);
xml = setupRDF({ author: undefined });
expect(getData(xml, "em:creator")).to.be.equal(undefined);
});
});
describe("engines", function() {
it("adds engine min/max from engine string for firefox", function() {
var xml = setupRDF({ engines: { firefox: ">=21.0a <32.0" }});
var apps = xml.getElementsByTagName("em:targetApplication");
var app = apps[0].childNodes[1]; // Description
expect(apps.length).to.be.equal(1);
expect(app.tagName).to.be.equal("Description");
expect(app.childNodes[1].tagName).to.be.equal("em:id");
expect(app.childNodes[1].childNodes[0].data).to.be.equal(GUIDS.FIREFOX);
expect(app.childNodes[3].tagName).to.be.equal("em:minVersion");
expect(app.childNodes[3].childNodes[0].data).to.be.equal("21.0a");
expect(app.childNodes[5].tagName).to.be.equal("em:maxVersion");
expect(app.childNodes[5].childNodes[0].data).to.be.equal("32.0.-1");
});
it("adds engine min/max from engine string for fennec", function() {
var xml = setupRDF({ engines: { fennec: ">=21.0a <32.0" }});
var apps = xml.getElementsByTagName("em:targetApplication");
var app = apps[0].childNodes[1]; // Description
expect(apps.length).to.be.equal(1);
expect(app.tagName).to.be.equal("Description");
expect(app.childNodes[1].tagName).to.be.equal("em:id");
expect(app.childNodes[1].childNodes[0].data).to.be.equal(GUIDS.FENNEC);
expect(app.childNodes[3].tagName).to.be.equal("em:minVersion");
expect(app.childNodes[3].childNodes[0].data).to.be.equal("21.0a");
expect(app.childNodes[5].tagName).to.be.equal("em:maxVersion");
expect(app.childNodes[5].childNodes[0].data).to.be.equal("32.0.-1");
});
it("handles multiple engines specified", function() {
var xml = setupRDF({ engines: {
fennec: ">=25.0a <=32.0",
firefox: ">=21.0a <=33.0",
}});
var apps = xml.getElementsByTagName("em:targetApplication");
expect(apps.length).to.be.equal(2);
var fennec = apps[0].childNodes[1]; // Description
var firefox = apps[1].childNodes[1]; // Description
expect(fennec.tagName).to.be.equal("Description");
expect(fennec.childNodes[1].tagName).to.be.equal("em:id");
expect(fennec.childNodes[1].childNodes[0].data).to.be.equal(GUIDS.FENNEC);
expect(fennec.childNodes[3].tagName).to.be.equal("em:minVersion");
expect(fennec.childNodes[3].childNodes[0].data).to.be.equal("25.0a");
expect(fennec.childNodes[5].tagName).to.be.equal("em:maxVersion");
expect(fennec.childNodes[5].childNodes[0].data).to.be.equal("32.0");
expect(firefox.tagName).to.be.equal("Description");
expect(firefox.childNodes[1].tagName).to.be.equal("em:id");
expect(firefox.childNodes[1].childNodes[0].data).to.be.equal(GUIDS.FIREFOX);
expect(firefox.childNodes[3].tagName).to.be.equal("em:minVersion");
expect(firefox.childNodes[3].childNodes[0].data).to.be.equal("21.0a");
expect(firefox.childNodes[5].tagName).to.be.equal("em:maxVersion");
expect(firefox.childNodes[5].childNodes[0].data).to.be.equal("33.0");
});
it("replaces undefined max versions with MAX_VERSION", function() {
var xml = setupRDF({ engines: {
fennec: ">=25.0"
}});
var apps = xml.getElementsByTagName("em:targetApplication");
var fennec = apps[0].childNodes[1]; // Description
expect(fennec.childNodes[3].tagName).to.be.equal("em:minVersion");
expect(fennec.childNodes[3].childNodes[0].data).to.be.equal("25.0");
expect(fennec.childNodes[5].tagName).to.be.equal("em:maxVersion");
expect(fennec.childNodes[5].childNodes[0].data).to.be.equal(MAX_VERSION);
});
it("handles wildcard versions with MIN_VERSION - *", function() {
var xml = setupRDF({ engines: {
firefox: "*"
}});
var apps = xml.getElementsByTagName("em:targetApplication");
var fennec = apps[0].childNodes[1]; // Description
expect(fennec.childNodes[3].tagName).to.be.equal("em:minVersion");
expect(fennec.childNodes[3].childNodes[0].data).to.be.equal(MIN_VERSION);
expect(fennec.childNodes[5].tagName).to.be.equal("em:maxVersion");
expect(fennec.childNodes[5].childNodes[0].data).to.be.equal(MAX_VERSION);
});
it("replaces undefined min versions with MIN_VERSION", function() {
var xml = setupRDF({ engines: {
fennec: "<30.0"
}});
var apps = xml.getElementsByTagName("em:targetApplication");
var fennec = apps[0].childNodes[1]; // Description
expect(fennec.childNodes[3].tagName).to.be.equal("em:minVersion");
expect(fennec.childNodes[3].childNodes[0].data).to.be.equal(MIN_VERSION);
expect(fennec.childNodes[5].tagName).to.be.equal("em:maxVersion");
expect(fennec.childNodes[5].childNodes[0].data).to.be.equal("30.0.-1");
});
it("creates default Firefox targetApplication if no engines defined", function() {
var xml = setupRDF({ engines: {}});
var apps = xml.getElementsByTagName("em:targetApplication");
var firefox = apps[0].childNodes[1]; // Description
expect(firefox.childNodes[3].tagName).to.be.equal("em:minVersion");
expect(firefox.childNodes[3].childNodes[0].data).to.be.equal(MIN_VERSION);
expect(firefox.childNodes[5].tagName).to.be.equal("em:maxVersion");
expect(firefox.childNodes[5].childNodes[0].data).to.be.equal(MAX_VERSION);
});
it("creates default Firefox targetApplication if no engines field", function() {
var xml = setupRDF({});
var apps = xml.getElementsByTagName("em:targetApplication");
var firefox = apps[0].childNodes[1]; // Description
expect(firefox.childNodes[3].tagName).to.be.equal("em:minVersion");
expect(firefox.childNodes[3].childNodes[0].data).to.be.equal(MIN_VERSION);
expect(firefox.childNodes[5].tagName).to.be.equal("em:maxVersion");
expect(firefox.childNodes[5].childNodes[0].data).to.be.equal(MAX_VERSION);
});
it("passes through raw GUIDs as targetApplication", function() {
var xml = setupRDF({ engines: {
"{e95a4b1e-901d-d035-4077-e95157a7a118}": "*"
}});
var apps = xml.getElementsByTagName("em:targetApplication");
var application = apps[0].childNodes[1]; // Description
expect(application.childNodes[1].tagName).to.be.equal("em:id");
expect(application.childNodes[1].childNodes[0].data).to.be.equal("{e95a4b1e-901d-d035-4077-e95157a7a118}");
});
});
describe("locales", function() {
it("add `ja` title, description, and homepage to add-on", function() {
var xml = setupRDF({ title: "my-title", description: "my-desc", homepage: "my-page",
locales: {
"ja": {
title: "名前",
description: "紹介",
homepage: "ホームページ",
}
}
});
var locales = xml.getElementsByTagName("em:localized");
var locale = locales[0].childNodes[1]; // Description
expect(locales.length).to.be.equal(1);
expect(locale.tagName).to.be.equal("Description");
expect(locale.childNodes[1].tagName).to.be.equal("em:locale");
expect(locale.childNodes[1].childNodes[0].data).to.be.equal("ja");
expect(locale.childNodes[3].tagName).to.be.equal("em:name");
expect(locale.childNodes[3].childNodes[0].data).to.be.equal("名前");
expect(locale.childNodes[5].tagName).to.be.equal("em:description");
expect(locale.childNodes[5].childNodes[0].data).to.be.equal("紹介");
expect(locale.childNodes[7].tagName).to.be.equal("em:homepageURL");
expect(locale.childNodes[7].childNodes[0].data).to.be.equal("ホームページ");
});
it("add `ja` title and homepage to add-on w/o description", function() {
var xml = setupRDF({ title: "my-title", homepage: "my-page",
locales: {
"ja": {
title: "名前",
homepage: "ホームページ",
}
}
});
var locales = xml.getElementsByTagName("em:localized");
var locale = locales[0].childNodes[1]; // Description
expect(locales.length).to.be.equal(1);
expect(locale.tagName).to.be.equal("Description");
expect(locale.childNodes[1].tagName).to.be.equal("em:locale");
expect(locale.childNodes[1].childNodes[0].data).to.be.equal("ja");
expect(locale.childNodes[3].tagName).to.be.equal("em:name");
expect(locale.childNodes[3].childNodes[0].data).to.be.equal("名前");
expect(locale.childNodes[5].tagName).to.be.equal("em:homepageURL");
expect(locale.childNodes[5].childNodes[0].data).to.be.equal("ホームページ");
});
it("add `ja` title and description to add-on w/o description", function() {
var xml = setupRDF({ title: "my-title", homepage: "my-page",
locales: {
"ja": {
title: "名前",
description: "紹介",
}
}
});
var locales = xml.getElementsByTagName("em:localized");
var locale = locales[0].childNodes[1]; // Description
expect(locales.length).to.be.equal(1);
expect(locale.tagName).to.be.equal("Description");
expect(locale.childNodes[1].tagName).to.be.equal("em:locale");
expect(locale.childNodes[1].childNodes[0].data).to.be.equal("ja");
expect(locale.childNodes[3].tagName).to.be.equal("em:name");
expect(locale.childNodes[3].childNodes[0].data).to.be.equal("名前");
expect(locale.childNodes[5].tagName).to.be.equal("em:description");
expect(locale.childNodes[5].childNodes[0].data).to.be.equal("紹介");
expect(locale.childNodes[7].tagName).to.be.equal("em:homepageURL");
expect(locale.childNodes[7].childNodes[0].data).to.be.equal("my-page");
});
it("add `ja` description and homepage to add-on w/o description", function() {
var xml = setupRDF({ title: "my-title", homepage: "my-page",
locales: {
"ja": {
description: "紹介",
homepage: "ホームページ",
}
}
});
var locales = xml.getElementsByTagName("em:localized");
var locale = locales[0].childNodes[1]; // Description
expect(locales.length).to.be.equal(1);
expect(locale.tagName).to.be.equal("Description");
expect(locale.childNodes[1].tagName).to.be.equal("em:locale");
expect(locale.childNodes[1].childNodes[0].data).to.be.equal("ja");
expect(locale.childNodes[3].tagName).to.be.equal("em:name");
expect(locale.childNodes[3].childNodes[0].data).to.be.equal("my-title");
expect(locale.childNodes[5].tagName).to.be.equal("em:description");
expect(locale.childNodes[5].childNodes[0].data).to.be.equal("紹介");
expect(locale.childNodes[7].tagName).to.be.equal("em:homepageURL");
expect(locale.childNodes[7].childNodes[0].data).to.be.equal("ホームページ");
});
it("add `ja` & `zh-CN` title, description, and homepage to add-on", function() {
var xml = setupRDF({ title: "my-title", description: "my-desc", homepage: "my-page",
locales: {
"ja": {
title: "名前",
description: "紹介",
homepage: "ホームページ",
},
"zh-CN": {
title: "扩展",
description: "说明",
homepage: "主页",
}
}
});
var locales = xml.getElementsByTagName("em:localized");
var localeJa = locales[0].childNodes[1]; // Description
var localeZhs = locales[1].childNodes[1]; // Description
expect(locales.length).to.be.equal(2);
expect(localeJa.tagName).to.be.equal("Description");
expect(localeJa.childNodes[1].tagName).to.be.equal("em:locale");
expect(localeJa.childNodes[1].childNodes[0].data).to.be.equal("ja");
expect(localeJa.childNodes[3].tagName).to.be.equal("em:name");
expect(localeJa.childNodes[3].childNodes[0].data).to.be.equal("名前");
expect(localeJa.childNodes[5].tagName).to.be.equal("em:description");
expect(localeJa.childNodes[5].childNodes[0].data).to.be.equal("紹介");
expect(localeJa.childNodes[7].tagName).to.be.equal("em:homepageURL");
expect(localeJa.childNodes[7].childNodes[0].data).to.be.equal("ホームページ");
expect(localeZhs.tagName).to.be.equal("Description");
expect(localeZhs.childNodes[1].tagName).to.be.equal("em:locale");
expect(localeZhs.childNodes[1].childNodes[0].data).to.be.equal("zh-CN");
expect(localeZhs.childNodes[3].tagName).to.be.equal("em:name");
expect(localeZhs.childNodes[3].childNodes[0].data).to.be.equal("扩展");
expect(localeZhs.childNodes[5].tagName).to.be.equal("em:description");
expect(localeZhs.childNodes[5].childNodes[0].data).to.be.equal("说明");
expect(localeZhs.childNodes[7].tagName).to.be.equal("em:homepageURL");
expect(localeZhs.childNodes[7].childNodes[0].data).to.be.equal("主页");
});
it("add `ja` title and homepage & `zh-CN` description to add-on only with homepage", function() {
var xml = setupRDF({ homepage: "my-page",
locales: {
"ja": {
title: "名前",
homepage: "ホームページ",
},
"zh-CN": {
description: "说明"
}
}
});
var locales = xml.getElementsByTagName("em:localized");
var localeJa = locales[0].childNodes[1]; // Description
var localeZhs = locales[1].childNodes[1]; // Description
expect(locales.length).to.be.equal(2);
expect(localeJa.tagName).to.be.equal("Description");
expect(localeJa.childNodes[1].tagName).to.be.equal("em:locale");
expect(localeJa.childNodes[1].childNodes[0].data).to.be.equal("ja");
expect(localeJa.childNodes[3].tagName).to.be.equal("em:name");
expect(localeJa.childNodes[3].childNodes[0].data).to.be.equal("名前");
expect(localeJa.childNodes[5].tagName).to.be.equal("em:homepageURL");
expect(localeJa.childNodes[5].childNodes[0].data).to.be.equal("ホームページ");
expect(localeZhs.tagName).to.be.equal("Description");
expect(localeZhs.childNodes[1].tagName).to.be.equal("em:locale");
expect(localeZhs.childNodes[1].childNodes[0].data).to.be.equal("zh-CN");
expect(localeZhs.childNodes[3].tagName).to.be.equal("em:name");
expect(localeZhs.childNodes[3].childNodes[0].data).to.be.equal("Untitled");
expect(localeZhs.childNodes[5].tagName).to.be.equal("em:description");
expect(localeZhs.childNodes[5].childNodes[0].data).to.be.equal("说明");
expect(localeZhs.childNodes[7].tagName).to.be.equal("em:homepageURL");
expect(localeZhs.childNodes[7].childNodes[0].data).to.be.equal("my-page");
});
});
describe("preferencesPage", function() {
it("doesn't set em:options* if no `preferences` or `preferencesURL` exist", function() {
var xml = setupRDF(
{
id: "preferences@jetpack",
version: "1.0"
}
);
// optionsURL shouldn't be set
var optURL = xml.getElementsByTagName("em:optionsURL");
expect(optURL.length).to.be.equal(0);
// optionsType shouldn't be set
var optType = xml.getElementsByTagName("em:optionsType");
expect(optType.length).to.be.equal(0);
});
it("sets em:optionsType to 2 by default if `preferences` exists", function() {
var xml = setupRDF(
{
id: "preferences@jetpack",
version: "1.0",
preferences: [
{
"name": "somePreference",
"title": "Some preference title",
"description": "Some short description for the preference",
"type": "string",
"value": "this is the default string value"
}
]
}
);
// Check if optionsURL is properly set
var optURL = xml.getElementsByTagName("em:optionsURL")[0];
expect(optURL.firstChild.data).to.be.equal("data:text/xml,<placeholder/>");
// Check if optionsType is properly set
var optType = xml.getElementsByTagName("em:optionsType")[0];
expect(optType.firstChild.data).to.be.equal("2");
});
it("sets em:optionsType to 3 if `preferencesURL` exists", function() {
var xml = setupRDF(
{
id: "preferences@jetpack",
version: "1.0",
preferencesURL: "resource://preferences-at-jetpack/data/preferences.html"
}
);
// Check if optionsURL is properly set
var optURL = xml.getElementsByTagName("em:optionsURL")[0];
expect(optURL.firstChild.data).to.be.equal("resource://preferences-at-jetpack/data/preferences.html");
// Check if optionsType is properly set
var optType = xml.getElementsByTagName("em:optionsType")[0];
expect(optType.firstChild.data).to.be.equal("3");
});
it("sets em:optionsType to 3 if both `preferences` and `preferencesURL` exist", function() {
var xml = setupRDF(
{
id: "preferences@jetpack",
version: "1.0",
preferences: [
{
"name": "somePreference",
"title": "Some preference title",
"description": "Some short description for the preference",
"type": "string",
"value": "this is the default string value"
}
],
preferencesURL: "resource://preferences-at-jetpack/data/preferences.html"
}
);
// Check if optionsURL is properly set
var optURL = xml.getElementsByTagName("em:optionsURL")[0];
expect(optURL.firstChild.data).to.be.equal("resource://preferences-at-jetpack/data/preferences.html");
// Check if optionsType is properly set
var optType = xml.getElementsByTagName("em:optionsType")[0];
expect(optType.firstChild.data).to.be.equal("3");
});
});
describe("createUpdateRDF", function() {
it("create the update.rdf file with the correct value", function() {
var str = RDF.createUpdateRDF(
{
id: "myaddon@jetpack",
updateLink: "https://mozilla.org/myaddon.xpi",
version: "1.4.1",
engines: { fennec: ">=21.0a <32.0" }
}
);
var xml = parseRDF(str);
// Check <RDF><Description about="..."/>...
var allDescriptions = xml.getElementsByTagName("Description");
var firstDesc = allDescriptions[0];
expect(firstDesc.tagName).to.be.equal("Description");
expect(firstDesc.getAttribute("about"))
.to.be.equal("urn:mozilla:extension:myaddon@jetpack");
expect(getData(xml, "em:version")).to.be.equal("1.4.1");
var apps = xml.getElementsByTagName("em:targetApplication");
// Check the <Description> nested inside <em:targetApplication>
var app = apps[0].childNodes[1];
expect(apps.length).to.be.equal(1);
expect(app.tagName).to.be.equal("Description");
expect(app.childNodes[1].tagName).to.be.equal("em:id");
expect(app.childNodes[1].childNodes[0].data).to.be.equal(GUIDS.FENNEC);
expect(app.childNodes[3].tagName).to.be.equal("em:minVersion");
expect(app.childNodes[3].childNodes[0].data).to.be.equal("21.0a");
expect(app.childNodes[5].tagName).to.be.equal("em:maxVersion");
expect(app.childNodes[5].childNodes[0].data).to.be.equal("32.0.-1");
expect(app.childNodes[7].tagName).to.be.equal("em:updateLink");
expect(app.childNodes[7].childNodes[0].data).to.be.equal("https://mozilla.org/myaddon.xpi");
});
it("create the update.rdf file with multiple engine", function() {
var str = RDF.createUpdateRDF(
{
id: "myaddon@jetpack",
updateLink: "https://mozilla.org/myaddon.xpi",
version: "1.4.1",
engines: { fennec: ">=21.0a <32.0", firefox: ">=21.0a <=33.0"}
}
);
var xml = parseRDF(str);
expect(getData(xml, "em:version")).to.be.equal("1.4.1");
var apps = xml.getElementsByTagName("em:targetApplication");
var fennec = apps[0].childNodes[1]; // Description
var firefox = apps[1].childNodes[1];
expect(apps.length).to.be.equal(2);
expect(fennec.tagName).to.be.equal("Description");
expect(fennec.childNodes[1].tagName).to.be.equal("em:id");
expect(fennec.childNodes[1].childNodes[0].data).to.be.equal(GUIDS.FENNEC);
expect(fennec.childNodes[3].tagName).to.be.equal("em:minVersion");
expect(fennec.childNodes[3].childNodes[0].data).to.be.equal("21.0a");
expect(fennec.childNodes[5].tagName).to.be.equal("em:maxVersion");
expect(fennec.childNodes[5].childNodes[0].data).to.be.equal("32.0.-1");
expect(fennec.childNodes[7].tagName).to.be.equal("em:updateLink");
expect(fennec.childNodes[7].childNodes[0].data).to.be.equal("https://mozilla.org/myaddon.xpi");
expect(firefox.tagName).to.be.equal("Description");
expect(firefox.childNodes[1].tagName).to.be.equal("em:id");
expect(firefox.childNodes[1].childNodes[0].data).to.be.equal(GUIDS.FIREFOX);
expect(firefox.childNodes[3].tagName).to.be.equal("em:minVersion");
expect(firefox.childNodes[3].childNodes[0].data).to.be.equal("21.0a");
expect(firefox.childNodes[5].tagName).to.be.equal("em:maxVersion");
expect(firefox.childNodes[5].childNodes[0].data).to.be.equal("33.0");
expect(firefox.childNodes[7].tagName).to.be.equal("em:updateLink");
expect(firefox.childNodes[7].childNodes[0].data).to.be.equal("https://mozilla.org/myaddon.xpi");
});
it("create the update.rdf file with default value", function() {
var str = RDF.createUpdateRDF(
{
id: "myaddon@jetpack",
updateLink: "https://mozilla.org/myaddon.xpi"
}
);
var xml = parseRDF(str);
expect(getData(xml, "em:version")).to.be.equal("0.0.0");
var apps = xml.getElementsByTagName("em:targetApplication");
var app = apps[0].childNodes[1]; // Description
expect(apps.length).to.be.equal(1);
expect(app.tagName).to.be.equal("Description");
expect(app.childNodes[1].tagName).to.be.equal("em:id");
expect(app.childNodes[1].childNodes[0].data).to.be.equal(GUIDS.FIREFOX);
expect(app.childNodes[3].tagName).to.be.equal("em:minVersion");
expect(app.childNodes[3].childNodes[0].data).to.be.equal(MIN_VERSION);
expect(app.childNodes[5].tagName).to.be.equal("em:maxVersion");
expect(app.childNodes[5].childNodes[0].data).to.be.equal(MAX_VERSION);
expect(app.childNodes[7].tagName).to.be.equal("em:updateLink");
expect(app.childNodes[7].childNodes[0].data).to.be.equal("https://mozilla.org/myaddon.xpi");
});
});
});
function parseRDF(rdf) {
return new DOMParser().parseFromString(rdf, "application/rdf+xml");
}
function setupRDF (manifest, needsBootstrapJS) {
if (typeof needsBootstrapJS === "undefined") {
needsBootstrapJS = true;
}
return parseRDF(RDF.createRDF(manifest, needsBootstrapJS));
}
function nodeExists (xml, tag) {
return !!xml.getElementsByTagName(tag).length;
}
function nodeEmpty (xml, tag) {
return !xml.getElementsByTagName(tag).childNodes;
}