| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/downgrade/user_data_downgrade.h" |
| 6 |
| 7 #include "base/files/file_util.h" |
| 8 #include "base/path_service.h" |
| 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/test/test_reg_util_win.h" |
| 11 #include "base/version.h" |
| 12 #include "base/win/registry.h" |
| 13 #include "chrome/common/chrome_constants.h" |
| 14 #include "chrome/common/chrome_paths.h" |
| 15 #include "chrome/installer/util/browser_distribution.h" |
| 16 #include "chrome/installer/util/google_update_constants.h" |
| 17 #include "chrome/test/base/in_process_browser_test.h" |
| 18 #include "content/public/browser/browser_thread.h" |
| 19 |
| 20 class UserDataDowngradeBrowserTestBase : public InProcessBrowserTest { |
| 21 protected: |
| 22 // content::BrowserTestBase: |
| 23 void SetUpInProcessBrowserTestFixture() override { |
| 24 SimulateDowngradeForTest(true); |
| 25 HKEY root = HKEY_CURRENT_USER; |
| 26 registry_override_manager_.OverrideRegistry(root); |
| 27 key_.Create(root, |
| 28 BrowserDistribution::GetDistribution()->GetStateKey().c_str(), |
| 29 KEY_SET_VALUE | KEY_WOW64_32KEY); |
| 30 } |
| 31 |
| 32 // InProcessBrowserTest: |
| 33 bool SetUpUserDataDirectory() override { |
| 34 if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_)) |
| 35 return false; |
| 36 if (!CreateTemporaryFileInDir(user_data_dir_, &other_file_)) |
| 37 return false; |
| 38 last_version_file_path_ = user_data_dir_.Append(kDowngradeLastVersionFile); |
| 39 std::string last_version = GetNextChromeVersion(); |
| 40 base::WriteFile(last_version_file_path_, last_version.c_str(), |
| 41 last_version.size()); |
| 42 return true; |
| 43 } |
| 44 |
| 45 // content::BrowserTestBase: |
| 46 // Verify the renamed user data directory has been deleted. |
| 47 void TearDownInProcessBrowserTestFixture() override { |
| 48 const base::FilePath::StringType index_suffix = FILE_PATH_LITERAL(" (1)"); |
| 49 ASSERT_FALSE(base::DirectoryExists( |
| 50 base::FilePath(user_data_dir_.value() + index_suffix) |
| 51 .AddExtension(kDowngradeDeleteSuffix))); |
| 52 SimulateDowngradeForTest(false); |
| 53 key_.Close(); |
| 54 } |
| 55 |
| 56 std::string GetNextChromeVersion() { |
| 57 return base::Version(std::string(chrome::kChromeVersion) + "1").GetString(); |
| 58 } |
| 59 |
| 60 base::FilePath last_version_file_path_; |
| 61 // The path to an arbitrary file in the user data dir that will be present |
| 62 // only when a reset does not take place. |
| 63 base::FilePath other_file_; |
| 64 base::FilePath user_data_dir_; |
| 65 base::win::RegKey key_; |
| 66 registry_util::RegistryOverrideManager registry_override_manager_; |
| 67 }; |
| 68 |
| 69 class UserDataDowngradeBrowserCopyAndCleanTest |
| 70 : public UserDataDowngradeBrowserTestBase { |
| 71 protected: |
| 72 // content::BrowserTestBase: |
| 73 void SetUpInProcessBrowserTestFixture() override { |
| 74 UserDataDowngradeBrowserTestBase::SetUpInProcessBrowserTestFixture(); |
| 75 key_.WriteValue(L"DowngradeVersion", |
| 76 base::ASCIIToUTF16(GetNextChromeVersion()).c_str()); |
| 77 key_.WriteValue(google_update::kRegMSIField, 1); |
| 78 } |
| 79 }; |
| 80 |
| 81 class UserDataDowngradeBrowserNoResetTest |
| 82 : public UserDataDowngradeBrowserTestBase { |
| 83 protected: |
| 84 // content::BrowserTestBase: |
| 85 void SetUpInProcessBrowserTestFixture() override { |
| 86 UserDataDowngradeBrowserTestBase::SetUpInProcessBrowserTestFixture(); |
| 87 key_.WriteValue(google_update::kRegMSIField, 1); |
| 88 } |
| 89 }; |
| 90 |
| 91 class UserDataDowngradeBrowserNoMSITest |
| 92 : public UserDataDowngradeBrowserTestBase { |
| 93 protected: |
| 94 // content::BrowserTestBase: |
| 95 void SetUpInProcessBrowserTestFixture() override { |
| 96 UserDataDowngradeBrowserTestBase::SetUpInProcessBrowserTestFixture(); |
| 97 } |
| 98 |
| 99 // InProcessBrowserTest: |
| 100 bool SetUpUserDataDirectory() override { return true; } |
| 101 }; |
| 102 |
| 103 // Verify the user data directory has been renamed and created again after |
| 104 // downgrade. |
| 105 IN_PROC_BROWSER_TEST_F(UserDataDowngradeBrowserCopyAndCleanTest, Test) { |
| 106 EXPECT_EQ(chrome::kChromeVersion, GetLastVersion(user_data_dir_).GetString()); |
| 107 ASSERT_FALSE(base::PathExists(other_file_)); |
| 108 } |
| 109 |
| 110 // Verify the user data directory will not be reset without downgrade. |
| 111 IN_PROC_BROWSER_TEST_F(UserDataDowngradeBrowserNoResetTest, Test) { |
| 112 EXPECT_EQ(chrome::kChromeVersion, GetLastVersion(user_data_dir_).GetString()); |
| 113 ASSERT_TRUE(base::PathExists(other_file_)); |
| 114 } |
| 115 |
| 116 // Verify the "Last Version" file won't be created for non-msi install. |
| 117 IN_PROC_BROWSER_TEST_F(UserDataDowngradeBrowserNoMSITest, Test) { |
| 118 ASSERT_FALSE(base::PathExists(last_version_file_path_)); |
| 119 } |
| OLD | NEW |