Chromium Code Reviews| 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/test/base/in_process_browser_test.h" | |
| 17 #include "content/public/browser/browser_thread.h" | |
| 18 | |
| 19 class UserDataDowngradeBrowserTestBase : public InProcessBrowserTest { | |
| 20 protected: | |
| 21 // InProcessBroiwserTest: | |
| 22 bool SetUpUserDataDirectory() override { | |
| 23 if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_)) | |
| 24 return false; | |
| 25 if (!CreateTemporaryFileInDir(user_data_dir_, &other_file_)) | |
| 26 return false; | |
| 27 base::FilePath browser_version_file_path = | |
| 28 user_data_dir_.Append(kDowngradeBrowserVersionFile); | |
| 29 std::string last_browser_version = GetNextChromeVersion(); | |
| 30 base::WriteFile(browser_version_file_path, last_browser_version.c_str(), | |
| 31 last_browser_version.size()); | |
| 32 return true; | |
| 33 } | |
| 34 | |
| 35 // Verify the renamed user data directory has been deleted. | |
|
grt (UTC plus 2)
2016/06/07 15:40:43
swap these two comments. the first tells the reade
| |
| 36 // content::BrowserTestBase: | |
| 37 void TearDownInProcessBrowserTestFixture() override { | |
| 38 const base::FilePath::StringType index_suffix = FILE_PATH_LITERAL(" (1)"); | |
| 39 ASSERT_FALSE(base::DirectoryExists( | |
| 40 base::FilePath(user_data_dir_.value() + index_suffix) | |
| 41 .AddExtension(kDowngradeDeleteSuffix))); | |
| 42 SimulateDowngradeForTest(false); | |
| 43 } | |
| 44 | |
| 45 std::string GetNextChromeVersion() { | |
| 46 return base::Version(std::string(chrome::kChromeVersion) + "1").GetString(); | |
| 47 } | |
| 48 | |
| 49 // The path to an arbitrary file in the user data dir that will be present | |
| 50 // only when a reset does not take place. | |
| 51 base::FilePath other_file_; | |
| 52 base::FilePath user_data_dir_; | |
| 53 registry_util::RegistryOverrideManager registry_override_manager_; | |
| 54 }; | |
| 55 | |
| 56 class UserDataDowngradeBrowserCopyAndCleanTest | |
| 57 : public UserDataDowngradeBrowserTestBase { | |
| 58 protected: | |
| 59 // content::BrowserTestBase: | |
| 60 void SetUpInProcessBrowserTestFixture() override { | |
| 61 SimulateDowngradeForTest(true); | |
| 62 HKEY root = HKEY_CURRENT_USER; | |
| 63 registry_override_manager_.OverrideRegistry(root); | |
| 64 base::win::RegKey key( | |
| 65 root, BrowserDistribution::GetDistribution()->GetStateKey().c_str(), | |
| 66 KEY_SET_VALUE | KEY_WOW64_32KEY); | |
| 67 key.WriteValue(L"DowngradeVersion", | |
| 68 base::ASCIIToUTF16(GetNextChromeVersion()).c_str()); | |
| 69 } | |
| 70 }; | |
| 71 | |
| 72 class UserDataDowngradeBrowserNoResetTest | |
| 73 : public UserDataDowngradeBrowserTestBase { | |
| 74 protected: | |
| 75 // content::BrowserTestBase: | |
| 76 void SetUpInProcessBrowserTestFixture() override { | |
| 77 SimulateDowngradeForTest(true); | |
| 78 } | |
| 79 }; | |
| 80 | |
| 81 // Verify the user data directory has been renamed and created again after | |
| 82 // downgrade. | |
| 83 IN_PROC_BROWSER_TEST_F(UserDataDowngradeBrowserCopyAndCleanTest, Test) { | |
| 84 EXPECT_EQ(chrome::kChromeVersion, | |
| 85 GetBrowserVersion(user_data_dir_).GetString()); | |
| 86 ASSERT_FALSE(base::PathExists(other_file_)); | |
| 87 } | |
| 88 | |
| 89 // Verify the user data directory will not be reset without downgrade. | |
| 90 IN_PROC_BROWSER_TEST_F(UserDataDowngradeBrowserNoResetTest, Test) { | |
| 91 EXPECT_EQ(chrome::kChromeVersion, | |
| 92 GetBrowserVersion(user_data_dir_).GetString()); | |
| 93 ASSERT_TRUE(base::PathExists(other_file_)); | |
| 94 } | |
| OLD | NEW |