|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 var xulApp = require("sdk/system/xul-app"); |
|
6 |
|
7 exports["test xulapp"] = function(assert) { |
|
8 assert.equal(typeof(xulApp.ID), "string", |
|
9 "ID is a string"); |
|
10 assert.equal(typeof(xulApp.name), "string", |
|
11 "name is a string"); |
|
12 assert.equal(typeof(xulApp.version), "string", |
|
13 "version is a string"); |
|
14 assert.equal(typeof(xulApp.platformVersion), "string", |
|
15 "platformVersion is a string"); |
|
16 |
|
17 assert.throws(function() { xulApp.is("blargy"); }, |
|
18 /Unkown Mozilla Application: blargy/, |
|
19 "is() throws error on bad app name"); |
|
20 assert.throws(function() { xulApp.isOneOf(["blargy"]); }, |
|
21 /Unkown Mozilla Application: blargy/, |
|
22 "isOneOf() throws error on bad app name"); |
|
23 |
|
24 function testSupport(name) { |
|
25 var item = xulApp.is(name); |
|
26 assert.ok(item === true || item === false, |
|
27 "is('" + name + "') is true or false."); |
|
28 } |
|
29 |
|
30 var apps = ["Firefox", "Mozilla", "Sunbird", "SeaMonkey", |
|
31 "Fennec", "Thunderbird"]; |
|
32 |
|
33 apps.forEach(testSupport); |
|
34 |
|
35 assert.ok(xulApp.isOneOf(apps) == true || |
|
36 xulApp.isOneOf(apps) == false, |
|
37 "isOneOf() returns true or false."); |
|
38 |
|
39 assert.equal(xulApp.versionInRange(xulApp.platformVersion, "1.9", "*"), |
|
40 true, "platformVersion in range [1.9, *)"); |
|
41 assert.equal(xulApp.versionInRange("3.6.4", "3.6.4", "3.6.*"), |
|
42 true, "3.6.4 in [3.6.4, 3.6.*)"); |
|
43 assert.equal(xulApp.versionInRange("1.9.3", "1.9.2", "1.9.3"), |
|
44 false, "1.9.3 not in [1.9.2, 1.9.3)"); |
|
45 }; |
|
46 |
|
47 exports["test satisfies version range"] = function (assert) { |
|
48 [ ["1.0.0 - 2.0.0", "1.2.3"], |
|
49 ["1.0.0", "1.0.0"], |
|
50 [">=*", "0.2.4"], |
|
51 ["", "1.0.0"], |
|
52 ["*", "1.2.3"], |
|
53 [">=1.0.0", "1.0.0"], |
|
54 [">=1.0.0", "1.0.1"], |
|
55 [">=1.0.0", "1.1.0"], |
|
56 [">1.0.0", "1.0.1"], |
|
57 [">1.0.0", "1.1.0"], |
|
58 ["<=2.0.0", "2.0.0"], |
|
59 ["<=2.0.0", "1.9999.9999"], |
|
60 ["<=2.0.0", "0.2.9"], |
|
61 ["<2.0.0", "1.9999.9999"], |
|
62 ["<2.0.0", "0.2.9"], |
|
63 [">= 1.0.0", "1.0.0"], |
|
64 [">= 1.0.0", "1.0.1"], |
|
65 [">= 1.0.0", "1.1.0"], |
|
66 ["> 1.0.0", "1.0.1"], |
|
67 ["> 1.0.0", "1.1.0"], |
|
68 ["<1", "1.0.0beta"], |
|
69 ["< 1", "1.0.0beta"], |
|
70 ["<= 2.0.0", "2.0.0"], |
|
71 ["<= 2.0.0", "1.9999.9999"], |
|
72 ["<= 2.0.0", "0.2.9"], |
|
73 ["< 2.0.0", "1.9999.9999"], |
|
74 ["<\t2.0.0", "0.2.9"], |
|
75 [">=0.1.97", "0.1.97"], |
|
76 ["0.1.20 || 1.2.4", "1.2.4"], |
|
77 [">=0.2.3 || <0.0.1", "0.0.0"], |
|
78 [">=0.2.3 || <0.0.1", "0.2.3"], |
|
79 [">=0.2.3 || <0.0.1", "0.2.4"], |
|
80 ["||", "1.3.4"], |
|
81 ["2.x.x", "2.1.3"], |
|
82 ["1.2.x", "1.2.3"], |
|
83 ["1.2.x || 2.x", "2.1.3"], |
|
84 ["1.2.x || 2.x", "1.2.3"], |
|
85 ["x", "1.2.3"], |
|
86 ["2.*.*", "2.1.3"], |
|
87 ["1.2.*", "1.2.3"], |
|
88 ["1.2.* || 2.*", "2.1.3"], |
|
89 ["1.2.* || 2.*", "1.2.3"], |
|
90 ["*", "1.2.3"], |
|
91 ["2.*", "2.1.2"], |
|
92 [">=1", "1.0.0"], |
|
93 [">= 1", "1.0.0"], |
|
94 ["<1.2", "1.1.1"], |
|
95 ["< 1.2", "1.1.1"], |
|
96 ["=0.7.x", "0.7.2"], |
|
97 [">=0.7.x", "0.7.2"], |
|
98 ["<=0.7.x", "0.6.2"], |
|
99 ["<=0.7.x", "0.7.2"] |
|
100 ].forEach(function (v) { |
|
101 assert.ok(xulApp.satisfiesVersion(v[1], v[0]), v[0] + " satisfied by " + v[1]); |
|
102 }); |
|
103 } |
|
104 exports["test not satisfies version range"] = function (assert) { |
|
105 [ ["1.0.0 - 2.0.0", "2.2.3"], |
|
106 ["1.0.0", "1.0.1"], |
|
107 [">=1.0.0", "0.0.0"], |
|
108 [">=1.0.0", "0.0.1"], |
|
109 [">=1.0.0", "0.1.0"], |
|
110 [">1.0.0", "0.0.1"], |
|
111 [">1.0.0", "0.1.0"], |
|
112 ["<=2.0.0", "3.0.0"], |
|
113 ["<=2.0.0", "2.9999.9999"], |
|
114 ["<=2.0.0", "2.2.9"], |
|
115 ["<2.0.0", "2.9999.9999"], |
|
116 ["<2.0.0", "2.2.9"], |
|
117 [">=0.1.97", "v0.1.93"], |
|
118 [">=0.1.97", "0.1.93"], |
|
119 ["0.1.20 || 1.2.4", "1.2.3"], |
|
120 [">=0.2.3 || <0.0.1", "0.0.3"], |
|
121 [">=0.2.3 || <0.0.1", "0.2.2"], |
|
122 ["2.x.x", "1.1.3"], |
|
123 ["2.x.x", "3.1.3"], |
|
124 ["1.2.x", "1.3.3"], |
|
125 ["1.2.x || 2.x", "3.1.3"], |
|
126 ["1.2.x || 2.x", "1.1.3"], |
|
127 ["2.*.*", "1.1.3"], |
|
128 ["2.*.*", "3.1.3"], |
|
129 ["1.2.*", "1.3.3"], |
|
130 ["1.2.* || 2.*", "3.1.3"], |
|
131 ["1.2.* || 2.*", "1.1.3"], |
|
132 ["2", "1.1.2"], |
|
133 ["2.3", "2.3.1"], |
|
134 ["2.3", "2.4.1"], |
|
135 ["<1", "1.0.0"], |
|
136 [">=1.2", "1.1.1"], |
|
137 ["1", "2.0.0beta"], |
|
138 ["=0.7.x", "0.8.2"], |
|
139 [">=0.7.x", "0.6.2"], |
|
140 ].forEach(function (v) { |
|
141 assert.ok(!xulApp.satisfiesVersion(v[1], v[0]), v[0] + " not satisfied by " + v[1]); |
|
142 }); |
|
143 } |
|
144 |
|
145 require("test").run(exports); |