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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 // Tests AddonManager.strictCompatibility and it's related preference,
     5 // extensions.strictCompatibility, and the strictCompatibility option in
     6 // install.rdf
     9 // Always compatible
    10 var addon1 = {
    11   id: "addon1@tests.mozilla.org",
    12   version: "1.0",
    13   name: "Test 1",
    14   targetApplications: [{
    15     id: "xpcshell@tests.mozilla.org",
    16     minVersion: "1",
    17     maxVersion: "1"
    18   }]
    19 };
    21 // Incompatible in strict compatibility mode
    22 var addon2 = {
    23   id: "addon2@tests.mozilla.org",
    24   version: "1.0",
    25   name: "Test 2",
    26   targetApplications: [{
    27     id: "xpcshell@tests.mozilla.org",
    28     minVersion: "0.7",
    29     maxVersion: "0.8"
    30   }]
    31 };
    33 // Theme - always uses strict compatibility, so is always incompatible
    34 var addon3 = {
    35   id: "addon3@tests.mozilla.org",
    36   version: "1.0",
    37   name: "Test 3",
    38   internalName: "test-theme-3",
    39   targetApplications: [{
    40     id: "xpcshell@tests.mozilla.org",
    41     minVersion: "0.8",
    42     maxVersion: "0.9"
    43   }]
    44 };
    46 // Opt-in to strict compatibility - always incompatible
    47 var addon4 = {
    48   id: "addon4@tests.mozilla.org",
    49   version: "1.0",
    50   name: "Test 4",
    51   strictCompatibility: true,
    52   targetApplications: [{
    53     id: "xpcshell@tests.mozilla.org",
    54     minVersion: "0.8",
    55     maxVersion: "0.9"
    56   }]
    57 };
    59 // Addon from the future - would be marked as compatibile-by-default,
    60 // but minVersion is higher than the app version
    61 var addon5 = {
    62   id: "addon5@tests.mozilla.org",
    63   version: "1.0",
    64   name: "Test 5",
    65   targetApplications: [{
    66     id: "xpcshell@tests.mozilla.org",
    67     minVersion: "3",
    68     maxVersion: "5"
    69   }]
    70 };
    72 // Extremely old addon - maxVersion is less than the mimimum compat version
    73 // set in extensions.minCompatibleVersion
    74 var addon6 = {
    75   id: "addon6@tests.mozilla.org",
    76   version: "1.0",
    77   name: "Test 6",
    78   targetApplications: [{
    79     id: "xpcshell@tests.mozilla.org",
    80     minVersion: "0.1",
    81     maxVersion: "0.2"
    82   }]
    83 };
    85 // Dictionary - incompatible in strict compatibility mode
    86 var addon7= {
    87   id: "addon7@tests.mozilla.org",
    88   version: "1.0",
    89   name: "Test 7",
    90   type: "64",
    91   targetApplications: [{
    92     id: "xpcshell@tests.mozilla.org",
    93     minVersion: "0.8",
    94     maxVersion: "0.9"
    95   }]
    96 };
   100 const profileDir = gProfD.clone();
   101 profileDir.append("extensions");
   104 function do_check_compat_status(aStrict, aAddonCompat, aCallback) {
   105   do_check_eq(AddonManager.strictCompatibility, aStrict);
   106   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
   107                                "addon2@tests.mozilla.org",
   108                                "addon3@tests.mozilla.org",
   109                                "addon4@tests.mozilla.org",
   110                                "addon5@tests.mozilla.org",
   111                                "addon6@tests.mozilla.org",
   112                                "addon7@tests.mozilla.org"],
   113                               function([a1, a2, a3, a4, a5, a6, a7]) {
   114     do_check_neq(a1, null);
   115     do_check_eq(a1.isCompatible, aAddonCompat[0]);
   116     do_check_eq(a1.appDisabled, !aAddonCompat[0]);
   117     do_check_false(a1.strictCompatibility);
   119     do_check_neq(a2, null);
   120     do_check_eq(a2.isCompatible, aAddonCompat[1]);
   121     do_check_eq(a2.appDisabled, !aAddonCompat[1]);
   122     do_check_false(a2.strictCompatibility);
   124     do_check_neq(a3, null);
   125     do_check_eq(a3.isCompatible, aAddonCompat[2]);
   126     do_check_eq(a3.appDisabled, !aAddonCompat[2]);
   127     do_check_true(a3.strictCompatibility);
   129     do_check_neq(a4, null);
   130     do_check_eq(a4.isCompatible, aAddonCompat[3]);
   131     do_check_eq(a4.appDisabled, !aAddonCompat[3]);
   132     do_check_true(a4.strictCompatibility);
   134     do_check_neq(a5, null);
   135     do_check_eq(a5.isCompatible, aAddonCompat[4]);
   136     do_check_eq(a5.appDisabled, !aAddonCompat[4]);
   137     do_check_false(a5.strictCompatibility);
   139     do_check_neq(a6, null);
   140     do_check_eq(a6.isCompatible, aAddonCompat[5]);
   141     do_check_eq(a6.appDisabled, !aAddonCompat[5]);
   142     do_check_false(a6.strictCompatibility);
   144     do_check_neq(a7, null);
   145     do_check_eq(a7.isCompatible, aAddonCompat[6]);
   146     do_check_eq(a7.appDisabled, !aAddonCompat[6]);
   147     do_check_false(a7.strictCompatibility);
   149     do_execute_soon(aCallback);
   150   });
   151 }
   154 function run_test() {
   155   do_test_pending();
   156   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
   158   writeInstallRDFForExtension(addon1, profileDir);
   159   writeInstallRDFForExtension(addon2, profileDir);
   160   writeInstallRDFForExtension(addon3, profileDir);
   161   writeInstallRDFForExtension(addon4, profileDir);
   162   writeInstallRDFForExtension(addon5, profileDir);
   163   writeInstallRDFForExtension(addon6, profileDir);
   164   writeInstallRDFForExtension(addon7, profileDir);
   166   Services.prefs.setCharPref(PREF_EM_MIN_COMPAT_APP_VERSION, "0.1");
   168   startupManager();
   170   // Should default to enabling strict compat.
   171   do_check_compat_status(true, [true, false, false, false, false, false, false], run_test_1);
   172 }
   174 function run_test_1() {
   175   do_print("Test 1");
   176   Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false);
   177   do_check_compat_status(false, [true, true, false, false, false, true, true], run_test_2);
   178 }
   180 function run_test_2() {
   181   do_print("Test 2");
   182   restartManager();
   183   do_check_compat_status(false, [true, true, false, false, false, true, true], run_test_3);
   184 }
   186 function run_test_3() {
   187   do_print("Test 3");
   188   Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, true);
   189   do_check_compat_status(true, [true, false, false, false, false, false, false], run_test_4);
   190 }
   192 function run_test_4() {
   193   do_print("Test 4");
   194   restartManager();
   195   do_check_compat_status(true, [true, false, false, false, false, false, false], run_test_5);
   196 }
   198 function run_test_5() {
   199   do_print("Test 5");
   200   Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false);
   201   Services.prefs.setCharPref(PREF_EM_MIN_COMPAT_APP_VERSION, "0.4");
   202   do_check_compat_status(false, [true, true, false, false, false, false, true], do_test_finished);
   203 }

mercurial