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