Chromium Code Reviews| Index: chrome/browser/downgrade/user_data_downgrade_browsertest.cc |
| diff --git a/chrome/browser/downgrade/user_data_downgrade_browsertest.cc b/chrome/browser/downgrade/user_data_downgrade_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5b3dce7820401a754cd3e8fc0d1253ec9793ff6b |
| --- /dev/null |
| +++ b/chrome/browser/downgrade/user_data_downgrade_browsertest.cc |
| @@ -0,0 +1,86 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/downgrade/user_data_downgrade.h" |
| + |
| +#include "base/files/file_util.h" |
| +#include "base/path_service.h" |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "base/test/test_reg_util_win.h" |
| +#include "base/version.h" |
| +#include "base/win/registry.h" |
| +#include "chrome/common/chrome_constants.h" |
| +#include "chrome/common/chrome_paths.h" |
| +#include "chrome/installer/util/browser_distribution.h" |
| +#include "chrome/test/base/in_process_browser_test.h" |
| +#include "content/public/browser/browser_thread.h" |
| + |
| +class UserDataDowngradeBrowserTestBase : public InProcessBrowserTest { |
| + protected: |
| + // Verify the renamed user data directory has been deleted. |
|
grt (UTC plus 2)
2016/06/07 01:25:28
it's common to document the class that declares ov
zmin
2016/06/07 14:41:49
Done. Also did to SetUpInProcessBrowserTestFixture
|
| + void TearDownInProcessBrowserTestFixture() override { |
| + const base::FilePath::StringType index_suffix = FILE_PATH_LITERAL(" (1)"); |
| + ASSERT_FALSE(base::DirectoryExists( |
| + base::FilePath(user_data_dir_.value() + index_suffix) |
| + .AddExtension(g_downgrade_delete_suffix))); |
| + SimulateDowngradeForTest(false); |
| + } |
| + |
| + bool SetUpUserDataDirectory() override { |
|
grt (UTC plus 2)
2016/06/07 01:25:28
// InProcessBrowserTest:
also, please move this u
zmin
2016/06/07 14:41:49
Done.
|
| + if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_)) |
| + return false; |
| + if (!CreateTemporaryFileInDir(user_data_dir_, &other_file_)) |
| + return false; |
| + base::FilePath browser_version_file_path = |
| + user_data_dir_.Append(g_downgrade_browser_version_file); |
| + std::string last_browser_version = GetNextChromeVersion(); |
| + base::WriteFile(browser_version_file_path, last_browser_version.c_str(), |
| + last_browser_version.size()); |
| + return true; |
| + } |
| + |
| + std::string GetNextChromeVersion() { |
| + return base::Version(std::string(chrome::kChromeVersion) + "1").GetString(); |
| + } |
| + |
| + base::FilePath other_file_; |
|
grt (UTC plus 2)
2016/06/07 01:25:28
please document. maybe something like:
// The pa
zmin
2016/06/07 14:41:49
Done.
|
| + base::FilePath user_data_dir_; |
| + registry_util::RegistryOverrideManager registry_override_manager_; |
| +}; |
| + |
| +class UserDataDowngradeBrowserCopyAndCleanTest |
| + : public UserDataDowngradeBrowserTestBase { |
| + void SetUpInProcessBrowserTestFixture() override { |
| + SimulateDowngradeForTest(true); |
| + HKEY root = HKEY_CURRENT_USER; |
| + registry_override_manager_.OverrideRegistry(root); |
| + base::win::RegKey key( |
| + root, BrowserDistribution::GetDistribution()->GetStateKey().c_str(), |
| + KEY_SET_VALUE | KEY_WOW64_32KEY); |
| + key.WriteValue(L"DowngradeVersion", |
| + base::ASCIIToUTF16(GetNextChromeVersion()).c_str()); |
| + } |
| +}; |
| + |
| +class UserDataDowngradeBrowserNoResetTest |
| + : public UserDataDowngradeBrowserTestBase { |
| + void SetUpInProcessBrowserTestFixture() override { |
| + SimulateDowngradeForTest(true); |
| + } |
| +}; |
| + |
| +// Verify the user data directory has been renamed and created again after |
| +// downgrade. |
| +IN_PROC_BROWSER_TEST_F(UserDataDowngradeBrowserCopyAndCleanTest, Test) { |
| + EXPECT_EQ(chrome::kChromeVersion, |
| + GetBrowserVersion(user_data_dir_).GetString()); |
| + ASSERT_FALSE(base::PathExists(other_file_)); |
| +} |
| + |
| +// Verify the user data directory will not be reset without downgrade. |
| +IN_PROC_BROWSER_TEST_F(UserDataDowngradeBrowserNoResetTest, Test) { |
| + EXPECT_EQ(chrome::kChromeVersion, |
| + GetBrowserVersion(user_data_dir_).GetString()); |
| + ASSERT_TRUE(base::PathExists(other_file_)); |
| +} |