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