toolkit/mozapps/update/tests/unit_aus_update/updateRootDirMigration_win.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 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     4  */
     6 const PREF_APP_UPDATE_MIGRATE_APP_DIR = "app.update.migrated.updateDir";
     8 function clearTaskbarIDHash(exePath, appInfoName) {
     9   let registry = AUS_Cc["@mozilla.org/windows-registry-key;1"].
    10                  createInstance(AUS_Ci.nsIWindowsRegKey);
    11   try {
    12     registry.open(AUS_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
    13                   "Software\\Mozilla\\" + appInfoName + "\\TaskBarIDs",
    14                   AUS_Ci.nsIWindowsRegKey.ACCESS_ALL);
    15     registry.removeValue(exePath);
    16   } catch (e) {
    17   }
    18   finally {
    19     registry.close();
    20   }
    21 }
    23 function setTaskbarIDHash(exePath, hash, appInfoName) {
    24   let registry = AUS_Cc["@mozilla.org/windows-registry-key;1"].
    25                  createInstance(AUS_Ci.nsIWindowsRegKey);
    26   try {
    27     registry.create(AUS_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
    28                     "Software\\Mozilla\\" + appInfoName + "\\TaskBarIDs",
    29                     AUS_Ci.nsIWindowsRegKey.ACCESS_WRITE);
    30     registry.writeStringValue(exePath, hash);
    31   } catch (e) {
    32   }
    33   finally {
    34     registry.close();
    35   }
    36 };
    38 function getMigrated() {
    39   var migrated = 0;
    40   try {
    41     migrated = Services.prefs.getBoolPref(PREF_APP_UPDATE_MIGRATE_APP_DIR);
    42   } catch (e) {
    43   }
    44   return migrated;
    45 }
    47 /* General Update Manager Tests */
    49 function run_test() {
    50   setupTestCommon();
    52   standardInit();
    54   var appinfo = AUS_Cc["@mozilla.org/xre/app-info;1"].
    55                 getService(AUS_Ci.nsIXULAppInfo).
    56                 QueryInterface(AUS_Ci.nsIXULRuntime);
    58    // Obtain the old update root leaf
    59   var updateLeafName;
    60   var exeFile = FileUtils.getFile(XRE_EXECUTABLE_FILE, []);
    61   var programFiles = FileUtils.getFile("ProgF", []);
    62   if (exeFile.path.substring(0, programFiles.path.length).toLowerCase() ==
    63       programFiles.path.toLowerCase()) {
    64     updateLeafName = exeFile.parent.leafName;
    65   } else {
    66     updateLeafName = appinfo.name;
    67   }
    69   // Obtain the old update root
    70   var oldUpdateRoot;
    71   if (appinfo.vendor) {
    72     oldUpdateRoot = FileUtils.getDir("LocalAppData", [appinfo.vendor,
    73                                                       appinfo.name,
    74                                                       updateLeafName], false);
    75   } else {
    76     oldUpdateRoot = FileUtils.getDir("LocalAppData", [appinfo.name,
    77                                                       updateLeafName], false);
    78   }
    79   // Obtain the new update root
    80   var newUpdateRoot = FileUtils.getDir("UpdRootD", [], false);
    82   ///////////////////////////////////////////////////////////
    83   // Setting a taskbar ID without the old update dir existing should set the
    84   // pref so a migration isn't retried.
    86   // Remove the old and new update root directories
    87   try {
    88     oldUpdateRoot.remove(true);
    89   } catch (e) {
    90   }
    91   try {
    92     newUpdateRoot.remove(true);
    93   } catch (e) {
    94   }
    95   Services.prefs.setBoolPref(PREF_APP_UPDATE_MIGRATE_APP_DIR, false);
    96   setTaskbarIDHash(exeFile.parent.path, "AAAAAAAA", appinfo.name);
    97   initUpdateServiceStub();
    98   do_check_eq(getMigrated(), 1);
   100   ///////////////////////////////////////////////////////////
   101   // An application without a taskbar ID should bail early without a pref
   102   // being set, so that if a taskbar is set for the application, the migration
   103   // will be retried.
   105   Services.prefs.setBoolPref(PREF_APP_UPDATE_MIGRATE_APP_DIR, false);
   106   clearTaskbarIDHash(exeFile.parent.path, appinfo.name);
   107   initUpdateServiceStub();
   108   do_check_eq(getMigrated(), 0);
   110   ///////////////////////////////////////////////////////////
   111   // Migrating files should work
   113   Services.prefs.setBoolPref(PREF_APP_UPDATE_MIGRATE_APP_DIR, false);
   114   setTaskbarIDHash(exeFile.parent.path, "AAAAAAAA", appinfo.name);
   115   var oldUpdateDirs = oldUpdateRoot.clone();
   116   oldUpdateDirs.append("updates");
   117   oldUpdateDirs.append("0");
   118   oldUpdateDirs.create(AUS_Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
   120   // Get an array of all of the files we want to migrate.
   121   // We do this to create them in the old update directory.
   122   var filesToMigrate = [FILE_UPDATES_DB, FILE_UPDATE_ACTIVE,
   123                         ["updates", FILE_LAST_LOG], ["updates", FILE_BACKUP_LOG],
   124                         ["updates", "0", FILE_UPDATE_STATUS]];
   125   // Move each of those files to the new directory
   126   filesToMigrate.forEach(relPath => {
   127     let oldFile = oldUpdateRoot.clone();
   128     if (relPath instanceof Array) {
   129       relPath.forEach(relPathPart => {
   130         oldFile.append(relPathPart);
   131       });
   132     } else {
   133       oldFile.append(relPath);
   134     }
   135     oldFile.create(AUS_Ci.nsIFile.NORMAL_FILE_TYPE, PERMS_FILE);
   136   });
   137   // Do the migration
   138   initUpdateServiceStub();
   139   doTestFinish();
   140   return;
   141   // Now verify that each of the files exist in the new update directory
   142   filesToMigrate.forEach(relPath => {
   143     let newFile = newUpdateRoot.clone();
   144     let oldFile = oldUpdateRoot.clone();
   145     if (relPath instanceof Array) {
   146       relPath.forEach(relPathPart => {
   147         newFile.append(relPathPart);
   148         oldFile.append(relPathPart);
   149       });
   150     } else {
   151       newFile.append(relPath);
   152       oldFile.append(relPath);
   153     }
   154     // The file should be mimgrated, except for FILE_UPDATE_STATUS
   155     // which gets consumed by post update after it is migrated..
   156     if (newFile.leafName != FILE_UPDATE_STATUS) {
   157       do_check_true(newFile.exists());
   158     }
   159     do_check_false(oldFile.exists());
   160   });
   162   doTestFinish();
   163 }
   165 function end_test() {
   166   var appinfo = AUS_Cc["@mozilla.org/xre/app-info;1"].
   167                 getService(AUS_Ci.nsIXULAppInfo).
   168                 QueryInterface(AUS_Ci.nsIXULRuntime);
   169   var exeFile = FileUtils.getFile(XRE_EXECUTABLE_FILE, []);
   170   clearTaskbarIDHash(exeFile.parent.path, appinfo.name);
   171 }

mercurial