toolkit/mozapps/extensions/test/xpcshell/test_migrate1.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/
     3  */
     5 // Checks that we migrate data from the old rdf style database
     7 var addon1 = {
     8   id: "addon1@tests.mozilla.org",
     9   version: "1.0",
    10   name: "Test 1",
    11   targetApplications: [{
    12     id: "xpcshell@tests.mozilla.org",
    13     minVersion: "1",
    14     maxVersion: "1"
    15   }]
    16 };
    18 var addon2 = {
    19   id: "addon2@tests.mozilla.org",
    20   version: "2.0",
    21   name: "Test 2",
    22   targetApplications: [{
    23     id: "toolkit@mozilla.org",
    24     minVersion: "1",
    25     maxVersion: "1"
    26   }]
    27 };
    29 var addon3 = {
    30   id: "addon3@tests.mozilla.org",
    31   version: "2.0",
    32   name: "Test 3",
    33   targetApplications: [{
    34     id: "xpcshell@tests.mozilla.org",
    35     minVersion: "1",
    36     maxVersion: "1"
    37   }]
    38 };
    40 var addon4 = {
    41   id: "addon4@tests.mozilla.org",
    42   version: "2.0",
    43   name: "Test 4",
    44   targetApplications: [{
    45     id: "toolkit@mozilla.org",
    46     minVersion: "1",
    47     maxVersion: "1"
    48   }]
    49 };
    51 var addon5 = {
    52   id: "addon5@tests.mozilla.org",
    53   version: "2.0",
    54   name: "Test 5",
    55   targetApplications: [{
    56     id: "toolkit@mozilla.org",
    57     minVersion: "1",
    58     maxVersion: "1"
    59   }]
    60 };
    62 var theme1 = {
    63   id: "theme1@tests.mozilla.org",
    64   version: "1.0",
    65   name: "Theme 1",
    66   type: 4,
    67   internalName: "theme1/1.0",
    68   targetApplications: [{
    69     id: "xpcshell@tests.mozilla.org",
    70     minVersion: "1",
    71     maxVersion: "2"
    72   }]
    73 };
    75 var theme2 = {
    76   id: "theme2@tests.mozilla.org",
    77   version: "1.0",
    78   name: "Theme 2",
    79   type: 4,
    80   internalName: "theme2/1.0",
    81   targetApplications: [{
    82     id: "xpcshell@tests.mozilla.org",
    83     minVersion: "1",
    84     maxVersion: "2"
    85   }]
    86 };
    88 const profileDir = gProfD.clone();
    89 profileDir.append("extensions");
    91 function run_test() {
    92   do_test_pending();
    93   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "2");
    95   writeInstallRDFForExtension(addon1, profileDir);
    96   writeInstallRDFForExtension(addon2, profileDir);
    97   writeInstallRDFForExtension(addon3, profileDir);
    98   writeInstallRDFForExtension(addon4, profileDir);
    99   writeInstallRDFForExtension(addon5, profileDir);
   100   writeInstallRDFForExtension(theme1, profileDir);
   101   writeInstallRDFForExtension(theme2, profileDir);
   103   let stagedXPIs = profileDir.clone();
   104   stagedXPIs.append("staged-xpis");
   105   stagedXPIs.append("addon6@tests.mozilla.org");
   106   stagedXPIs.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755);
   108   let addon6 = do_get_addon("test_migrate6");
   109   addon6.copyTo(stagedXPIs, "tmp.xpi");
   110   stagedXPIs = stagedXPIs.parent;
   112   stagedXPIs.append("addon7@tests.mozilla.org");
   113   stagedXPIs.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755);
   115   let addon7 = do_get_addon("test_migrate7");
   116   addon7.copyTo(stagedXPIs, "tmp.xpi");
   117   stagedXPIs = stagedXPIs.parent;
   119   stagedXPIs.append("addon8@tests.mozilla.org");
   120   stagedXPIs.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755);
   122   let addon7 = do_get_addon("test_migrate8");
   123   addon7.copyTo(stagedXPIs, "tmp.xpi");
   124   stagedXPIs = stagedXPIs.parent;
   126   let old = do_get_file("data/test_migrate.rdf");
   127   old.copyTo(gProfD, "extensions.rdf");
   129   let oldCache = gProfD.clone();
   130   oldCache.append("extensions.cache");
   131   oldCache.create(AM_Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
   133   // Theme state is determined by the selected theme pref
   134   Services.prefs.setCharPref("general.skins.selectedSkin", "theme1/1.0");
   136   Services.prefs.setCharPref("extensions.lastAppVersion", "1");
   138   startupManager();
   139   check_startup_changes("installed", []);
   140   check_startup_changes("updated", []);
   141   check_startup_changes("uninstalled", []);
   142   check_startup_changes("disabled", []);
   143   check_startup_changes("enabled", []);
   145   do_check_false(oldCache.exists());
   147   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
   148                                "addon2@tests.mozilla.org",
   149                                "addon3@tests.mozilla.org",
   150                                "addon4@tests.mozilla.org",
   151                                "addon5@tests.mozilla.org",
   152                                "addon6@tests.mozilla.org",
   153                                "addon7@tests.mozilla.org",
   154                                "addon8@tests.mozilla.org",
   155                                "theme1@tests.mozilla.org",
   156                                "theme2@tests.mozilla.org"], function([a1, a2, a3,
   157                                                                       a4, a5, a6,
   158                                                                       a7, a8, t1,
   159                                                                       t2]) {
   160     // addon1 was user and app enabled in the old extensions.rdf
   161     do_check_neq(a1, null);
   162     do_check_false(a1.userDisabled);
   163     do_check_false(a1.appDisabled);
   164     do_check_true(a1.isActive);
   165     do_check_true(isExtensionInAddonsList(profileDir, a1.id));
   166     do_check_false(a1.hasBinaryComponents);
   168     // addon2 was user disabled and app enabled in the old extensions.rdf
   169     do_check_neq(a2, null);
   170     do_check_true(a2.userDisabled);
   171     do_check_false(a2.appDisabled);
   172     do_check_false(a2.isActive);
   173     do_check_false(isExtensionInAddonsList(profileDir, a2.id));
   174     do_check_false(a2.hasBinaryComponents);
   176     // addon3 was pending user disable and app disabled in the old extensions.rdf
   177     do_check_neq(a3, null);
   178     do_check_true(a3.userDisabled);
   179     do_check_true(a3.appDisabled);
   180     do_check_false(a3.isActive);
   181     do_check_false(isExtensionInAddonsList(profileDir, a3.id));
   182     do_check_false(a3.hasBinaryComponents);
   184     // addon4 was pending user enable and app disabled in the old extensions.rdf
   185     do_check_neq(a4, null);
   186     do_check_false(a4.userDisabled);
   187     do_check_true(a4.appDisabled);
   188     do_check_false(a4.isActive);
   189     do_check_false(isExtensionInAddonsList(profileDir, a4.id));
   190     do_check_false(a4.hasBinaryComponents);
   192     // addon5 was disabled and compatible but a new version has been installed
   193     // since, it should still be disabled but should be incompatible
   194     do_check_neq(a5, null);
   195     do_check_true(a5.userDisabled);
   196     do_check_true(a5.appDisabled);
   197     do_check_false(a5.isActive);
   198     do_check_false(isExtensionInAddonsList(profileDir, a5.id));
   199     do_check_false(a5.hasBinaryComponents);
   201     // addon6 should be installed and compatible and packed unless unpacking is
   202     // forced
   203     do_check_neq(a6, null);
   204     do_check_false(a6.userDisabled);
   205     do_check_false(a6.appDisabled);
   206     do_check_true(a6.isActive);
   207     do_check_true(isExtensionInAddonsList(profileDir, a6.id));
   208     if (Services.prefs.getBoolPref("extensions.alwaysUnpack"))
   209       do_check_eq(a6.getResourceURI("install.rdf").scheme, "file");
   210     else
   211       do_check_eq(a6.getResourceURI("install.rdf").scheme, "jar");
   212     do_check_false(a6.hasBinaryComponents);
   214     // addon7 should be installed and compatible and unpacked
   215     do_check_neq(a7, null);
   216     do_check_false(a7.userDisabled);
   217     do_check_false(a7.appDisabled);
   218     do_check_true(a7.isActive);
   219     do_check_true(isExtensionInAddonsList(profileDir, a7.id));
   220     do_check_eq(a7.getResourceURI("install.rdf").scheme, "file");
   221     do_check_false(a7.hasBinaryComponents);
   223     // addon8 should be installed and compatible and have binary components
   224     do_check_neq(a8, null);
   225     do_check_false(a8.userDisabled);
   226     do_check_false(a8.appDisabled);
   227     do_check_true(a8.isActive);
   228     do_check_true(isExtensionInAddonsList(profileDir, a8.id));
   229     do_check_true(a8.hasBinaryComponents);
   231     // Theme 1 was previously enabled
   232     do_check_neq(t1, null);
   233     do_check_false(t1.userDisabled);
   234     do_check_false(t1.appDisabled);
   235     do_check_true(t1.isActive);
   236     do_check_true(isThemeInAddonsList(profileDir, t1.id));
   237     do_check_false(hasFlag(t1.permissions, AddonManager.PERM_CAN_ENABLE));
   239     // Theme 2 was previously disabled
   240     do_check_neq(t1, null);
   241     do_check_true(t2.userDisabled);
   242     do_check_false(t2.appDisabled);
   243     do_check_false(t2.isActive);
   244     do_check_false(isThemeInAddonsList(profileDir, t2.id));
   245     do_check_true(hasFlag(t2.permissions, AddonManager.PERM_CAN_ENABLE));
   247     do_check_false(stagedXPIs.exists());
   249     do_execute_soon(do_test_finished);
   250   });
   251 }

mercurial