toolkit/mozapps/extensions/test/xpcshell/test_update_compatmode.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/
michael@0 3 */
michael@0 4
michael@0 5 // This verifies that add-on update check correctly fills in the
michael@0 6 // %COMPATIBILITY_MODE% token in the update URL.
michael@0 7
michael@0 8
michael@0 9 // The test extension uses an insecure update url.
michael@0 10 Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false);
michael@0 11
michael@0 12 Components.utils.import("resource://testing-common/httpd.js");
michael@0 13 var testserver = new HttpServer();
michael@0 14 testserver.start(-1);
michael@0 15 gPort = testserver.identity.primaryPort;
michael@0 16 mapFile("/data/test_updatecompatmode_ignore.rdf", testserver);
michael@0 17 mapFile("/data/test_updatecompatmode_normal.rdf", testserver);
michael@0 18 mapFile("/data/test_updatecompatmode_strict.rdf", testserver);
michael@0 19 testserver.registerDirectory("/addons/", do_get_file("addons"));
michael@0 20
michael@0 21 const profileDir = gProfD.clone();
michael@0 22 profileDir.append("extensions");
michael@0 23
michael@0 24 function run_test() {
michael@0 25 do_test_pending();
michael@0 26 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
michael@0 27
michael@0 28 writeInstallRDFForExtension({
michael@0 29 id: "compatmode-normal@tests.mozilla.org",
michael@0 30 version: "1.0",
michael@0 31 updateURL: "http://localhost:" + gPort + "/data/test_updatecompatmode_%COMPATIBILITY_MODE%.rdf",
michael@0 32 targetApplications: [{
michael@0 33 id: "xpcshell@tests.mozilla.org",
michael@0 34 minVersion: "1",
michael@0 35 maxVersion: "1"
michael@0 36 }],
michael@0 37 name: "Test Addon - normal"
michael@0 38 }, profileDir);
michael@0 39
michael@0 40 writeInstallRDFForExtension({
michael@0 41 id: "compatmode-strict@tests.mozilla.org",
michael@0 42 version: "1.0",
michael@0 43 updateURL: "http://localhost:" + gPort + "/data/test_updatecompatmode_%COMPATIBILITY_MODE%.rdf",
michael@0 44 targetApplications: [{
michael@0 45 id: "xpcshell@tests.mozilla.org",
michael@0 46 minVersion: "1",
michael@0 47 maxVersion: "1"
michael@0 48 }],
michael@0 49 name: "Test Addon - strict"
michael@0 50 }, profileDir);
michael@0 51
michael@0 52 writeInstallRDFForExtension({
michael@0 53 id: "compatmode-strict-optin@tests.mozilla.org",
michael@0 54 version: "1.0",
michael@0 55 updateURL: "http://localhost:" + gPort + "/data/test_updatecompatmode_%COMPATIBILITY_MODE%.rdf",
michael@0 56 targetApplications: [{
michael@0 57 id: "xpcshell@tests.mozilla.org",
michael@0 58 minVersion: "1",
michael@0 59 maxVersion: "1"
michael@0 60 }],
michael@0 61 name: "Test Addon - strict opt-in",
michael@0 62 strictCompatibility: true
michael@0 63 }, profileDir);
michael@0 64
michael@0 65 writeInstallRDFForExtension({
michael@0 66 id: "compatmode-ignore@tests.mozilla.org",
michael@0 67 version: "1.0",
michael@0 68 updateURL: "http://localhost:" + gPort + "/data/test_updatecompatmode_%COMPATIBILITY_MODE%.rdf",
michael@0 69 targetApplications: [{
michael@0 70 id: "xpcshell@tests.mozilla.org",
michael@0 71 minVersion: "1",
michael@0 72 maxVersion: "1"
michael@0 73 }],
michael@0 74 name: "Test Addon - ignore",
michael@0 75 }, profileDir);
michael@0 76
michael@0 77 startupManager();
michael@0 78 run_test_1();
michael@0 79 }
michael@0 80
michael@0 81 function end_test() {
michael@0 82 testserver.stop(do_test_finished);
michael@0 83 }
michael@0 84
michael@0 85
michael@0 86 // Strict compatibility checking disabled.
michael@0 87 function run_test_1() {
michael@0 88 do_print("Testing with strict compatibility checking disabled");
michael@0 89 Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false);
michael@0 90 AddonManager.getAddonByID("compatmode-normal@tests.mozilla.org", function(addon) {
michael@0 91 do_check_neq(addon, null);
michael@0 92 addon.findUpdates({
michael@0 93 onCompatibilityUpdateAvailable: function() {
michael@0 94 do_throw("Should have not have seen compatibility information");
michael@0 95 },
michael@0 96
michael@0 97 onNoUpdateAvailable: function() {
michael@0 98 do_throw("Should have seen an available update");
michael@0 99 },
michael@0 100
michael@0 101 onUpdateAvailable: function(addon, install) {
michael@0 102 do_check_eq(install.version, "2.0")
michael@0 103 },
michael@0 104
michael@0 105 onUpdateFinished: function() {
michael@0 106 run_test_2();
michael@0 107 }
michael@0 108 }, AddonManager.UPDATE_WHEN_USER_REQUESTED);
michael@0 109 });
michael@0 110 }
michael@0 111
michael@0 112 // Strict compatibility checking enabled.
michael@0 113 function run_test_2() {
michael@0 114 do_print("Testing with strict compatibility checking enabled");
michael@0 115 Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, true);
michael@0 116 AddonManager.getAddonByID("compatmode-strict@tests.mozilla.org", function(addon) {
michael@0 117 do_check_neq(addon, null);
michael@0 118 addon.findUpdates({
michael@0 119 onCompatibilityUpdateAvailable: function() {
michael@0 120 do_throw("Should have not have seen compatibility information");
michael@0 121 },
michael@0 122
michael@0 123 onNoUpdateAvailable: function() {
michael@0 124 do_throw("Should have seen an available update");
michael@0 125 },
michael@0 126
michael@0 127 onUpdateAvailable: function(addon, install) {
michael@0 128 do_check_eq(install.version, "2.0")
michael@0 129 },
michael@0 130
michael@0 131 onUpdateFinished: function() {
michael@0 132 run_test_3();
michael@0 133 }
michael@0 134 }, AddonManager.UPDATE_WHEN_USER_REQUESTED);
michael@0 135 });
michael@0 136 }
michael@0 137
michael@0 138 // Strict compatibility checking opt-in.
michael@0 139 function run_test_3() {
michael@0 140 do_print("Testing with strict compatibility disabled, but addon opt-in");
michael@0 141 Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false);
michael@0 142 AddonManager.getAddonByID("compatmode-strict-optin@tests.mozilla.org", function(addon) {
michael@0 143 do_check_neq(addon, null);
michael@0 144 addon.findUpdates({
michael@0 145 onCompatibilityUpdateAvailable: function() {
michael@0 146 do_throw("Should have not have seen compatibility information");
michael@0 147 },
michael@0 148
michael@0 149 onUpdateAvailable: function(addon, install) {
michael@0 150 do_throw("Should not have seen an available update");
michael@0 151 },
michael@0 152
michael@0 153 onUpdateFinished: function() {
michael@0 154 run_test_4();
michael@0 155 }
michael@0 156 }, AddonManager.UPDATE_WHEN_USER_REQUESTED);
michael@0 157 });
michael@0 158 }
michael@0 159
michael@0 160 // Compatibility checking disabled.
michael@0 161 function run_test_4() {
michael@0 162 do_print("Testing with all compatibility checking disabled");
michael@0 163 AddonManager.checkCompatibility = false;
michael@0 164 AddonManager.getAddonByID("compatmode-ignore@tests.mozilla.org", function(addon) {
michael@0 165 do_check_neq(addon, null);
michael@0 166 addon.findUpdates({
michael@0 167 onCompatibilityUpdateAvailable: function() {
michael@0 168 do_throw("Should have not have seen compatibility information");
michael@0 169 },
michael@0 170
michael@0 171 onNoUpdateAvailable: function() {
michael@0 172 do_throw("Should have seen an available update");
michael@0 173 },
michael@0 174
michael@0 175 onUpdateAvailable: function(addon, install) {
michael@0 176 do_check_eq(install.version, "2.0")
michael@0 177 },
michael@0 178
michael@0 179 onUpdateFinished: function() {
michael@0 180 end_test();
michael@0 181 }
michael@0 182 }, AddonManager.UPDATE_WHEN_USER_REQUESTED);
michael@0 183 });
michael@0 184 }

mercurial