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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_update_compatmode.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,184 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.6 + */
     1.7 +
     1.8 +// This verifies that add-on update check correctly fills in the
     1.9 +// %COMPATIBILITY_MODE% token in the update URL.
    1.10 +
    1.11 +
    1.12 +// The test extension uses an insecure update url.
    1.13 +Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false);
    1.14 +
    1.15 +Components.utils.import("resource://testing-common/httpd.js");
    1.16 +var testserver = new HttpServer();
    1.17 +testserver.start(-1);
    1.18 +gPort = testserver.identity.primaryPort;
    1.19 +mapFile("/data/test_updatecompatmode_ignore.rdf", testserver);
    1.20 +mapFile("/data/test_updatecompatmode_normal.rdf", testserver);
    1.21 +mapFile("/data/test_updatecompatmode_strict.rdf", testserver);
    1.22 +testserver.registerDirectory("/addons/", do_get_file("addons"));
    1.23 +
    1.24 +const profileDir = gProfD.clone();
    1.25 +profileDir.append("extensions");
    1.26 +
    1.27 +function run_test() {
    1.28 +  do_test_pending();
    1.29 +  createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
    1.30 +
    1.31 +  writeInstallRDFForExtension({
    1.32 +    id: "compatmode-normal@tests.mozilla.org",
    1.33 +    version: "1.0",
    1.34 +    updateURL: "http://localhost:" + gPort + "/data/test_updatecompatmode_%COMPATIBILITY_MODE%.rdf",
    1.35 +    targetApplications: [{
    1.36 +      id: "xpcshell@tests.mozilla.org",
    1.37 +      minVersion: "1",
    1.38 +      maxVersion: "1"
    1.39 +    }],
    1.40 +    name: "Test Addon - normal"
    1.41 +  }, profileDir);
    1.42 +
    1.43 +  writeInstallRDFForExtension({
    1.44 +    id: "compatmode-strict@tests.mozilla.org",
    1.45 +    version: "1.0",
    1.46 +    updateURL: "http://localhost:" + gPort + "/data/test_updatecompatmode_%COMPATIBILITY_MODE%.rdf",
    1.47 +    targetApplications: [{
    1.48 +      id: "xpcshell@tests.mozilla.org",
    1.49 +      minVersion: "1",
    1.50 +      maxVersion: "1"
    1.51 +    }],
    1.52 +    name: "Test Addon - strict"
    1.53 +  }, profileDir);
    1.54 +
    1.55 +  writeInstallRDFForExtension({
    1.56 +    id: "compatmode-strict-optin@tests.mozilla.org",
    1.57 +    version: "1.0",
    1.58 +    updateURL: "http://localhost:" + gPort + "/data/test_updatecompatmode_%COMPATIBILITY_MODE%.rdf",
    1.59 +    targetApplications: [{
    1.60 +      id: "xpcshell@tests.mozilla.org",
    1.61 +      minVersion: "1",
    1.62 +      maxVersion: "1"
    1.63 +    }],
    1.64 +    name: "Test Addon - strict opt-in",
    1.65 +    strictCompatibility: true
    1.66 +  }, profileDir);
    1.67 +
    1.68 +  writeInstallRDFForExtension({
    1.69 +    id: "compatmode-ignore@tests.mozilla.org",
    1.70 +    version: "1.0",
    1.71 +    updateURL: "http://localhost:" + gPort + "/data/test_updatecompatmode_%COMPATIBILITY_MODE%.rdf",
    1.72 +    targetApplications: [{
    1.73 +      id: "xpcshell@tests.mozilla.org",
    1.74 +      minVersion: "1",
    1.75 +      maxVersion: "1"
    1.76 +    }],
    1.77 +    name: "Test Addon - ignore",
    1.78 +  }, profileDir);
    1.79 +
    1.80 +  startupManager();
    1.81 +  run_test_1();
    1.82 +}
    1.83 +
    1.84 +function end_test() {
    1.85 +  testserver.stop(do_test_finished);
    1.86 +}
    1.87 +
    1.88 +
    1.89 +// Strict compatibility checking disabled.
    1.90 +function run_test_1() {
    1.91 +  do_print("Testing with strict compatibility checking disabled");
    1.92 +  Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false);
    1.93 +  AddonManager.getAddonByID("compatmode-normal@tests.mozilla.org", function(addon) {
    1.94 +    do_check_neq(addon, null);
    1.95 +    addon.findUpdates({
    1.96 +      onCompatibilityUpdateAvailable: function() {
    1.97 +        do_throw("Should have not have seen compatibility information");
    1.98 +      },
    1.99 +
   1.100 +      onNoUpdateAvailable: function() {
   1.101 +        do_throw("Should have seen an available update");
   1.102 +      },
   1.103 +
   1.104 +      onUpdateAvailable: function(addon, install) {
   1.105 +        do_check_eq(install.version, "2.0")
   1.106 +      },
   1.107 +
   1.108 +      onUpdateFinished: function() {
   1.109 +        run_test_2();
   1.110 +      }
   1.111 +    }, AddonManager.UPDATE_WHEN_USER_REQUESTED);
   1.112 +  });
   1.113 +}
   1.114 +
   1.115 +// Strict compatibility checking enabled.
   1.116 +function run_test_2() {
   1.117 +  do_print("Testing with strict compatibility checking enabled");
   1.118 +  Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, true);
   1.119 +  AddonManager.getAddonByID("compatmode-strict@tests.mozilla.org", function(addon) {
   1.120 +    do_check_neq(addon, null);
   1.121 +    addon.findUpdates({
   1.122 +      onCompatibilityUpdateAvailable: function() {
   1.123 +        do_throw("Should have not have seen compatibility information");
   1.124 +      },
   1.125 +
   1.126 +      onNoUpdateAvailable: function() {
   1.127 +        do_throw("Should have seen an available update");
   1.128 +      },
   1.129 +
   1.130 +      onUpdateAvailable: function(addon, install) {
   1.131 +        do_check_eq(install.version, "2.0")
   1.132 +      },
   1.133 +
   1.134 +      onUpdateFinished: function() {
   1.135 +        run_test_3();
   1.136 +      }
   1.137 +    }, AddonManager.UPDATE_WHEN_USER_REQUESTED);
   1.138 +  });
   1.139 +}
   1.140 +
   1.141 +// Strict compatibility checking opt-in.
   1.142 +function run_test_3() {
   1.143 +  do_print("Testing with strict compatibility disabled, but addon opt-in");
   1.144 +  Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false);
   1.145 +  AddonManager.getAddonByID("compatmode-strict-optin@tests.mozilla.org", function(addon) {
   1.146 +    do_check_neq(addon, null);
   1.147 +    addon.findUpdates({
   1.148 +      onCompatibilityUpdateAvailable: function() {
   1.149 +        do_throw("Should have not have seen compatibility information");
   1.150 +      },
   1.151 +
   1.152 +      onUpdateAvailable: function(addon, install) {
   1.153 +        do_throw("Should not have seen an available update");
   1.154 +      },
   1.155 +
   1.156 +      onUpdateFinished: function() {
   1.157 +        run_test_4();
   1.158 +      }
   1.159 +    }, AddonManager.UPDATE_WHEN_USER_REQUESTED);
   1.160 +  });
   1.161 +}
   1.162 +
   1.163 +// Compatibility checking disabled.
   1.164 +function run_test_4() {
   1.165 +  do_print("Testing with all compatibility checking disabled");
   1.166 +  AddonManager.checkCompatibility = false;
   1.167 +  AddonManager.getAddonByID("compatmode-ignore@tests.mozilla.org", function(addon) {
   1.168 +    do_check_neq(addon, null);
   1.169 +    addon.findUpdates({
   1.170 +      onCompatibilityUpdateAvailable: function() {
   1.171 +        do_throw("Should have not have seen compatibility information");
   1.172 +      },
   1.173 +
   1.174 +      onNoUpdateAvailable: function() {
   1.175 +        do_throw("Should have seen an available update");
   1.176 +      },
   1.177 +
   1.178 +      onUpdateAvailable: function(addon, install) {
   1.179 +        do_check_eq(install.version, "2.0")
   1.180 +      },
   1.181 +
   1.182 +      onUpdateFinished: function() {
   1.183 +        end_test();
   1.184 +      }
   1.185 +    }, AddonManager.UPDATE_WHEN_USER_REQUESTED);
   1.186 +  });
   1.187 +}

mercurial