addon-sdk/source/test/test-xul-app.js

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial