Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1378)

Side by Side Diff: chrome/browser/downgrade/user_data_downgrade_browsertest.cc

Issue 2065103002: Removes downgrade browser test hack and verifies renamed user data dir. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cr Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/downgrade/user_data_downgrade.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // InProcessBrowserTest:
97 void SetUpInProcessBrowserTestFixture() override { 109 bool SetUpUserDataDirectory() override {
98 UserDataDowngradeBrowserTestBase::SetUpInProcessBrowserTestFixture(); 110 return CreateTemporaryFileInDir(user_data_dir_, &other_file_);
99 } 111 }
100
101 // InProcessBrowserTest:
102 bool SetUpUserDataDirectory() override { return true; }
103 }; 112 };
104 113
105 // Verify the user data directory has been renamed and created again after 114 // Verify the user data directory has been renamed and created again after
106 // downgrade. 115 // downgrade.
107 IN_PROC_BROWSER_TEST_F(UserDataDowngradeBrowserCopyAndCleanTest, Test) { 116 IN_PROC_BROWSER_TEST_F(UserDataDowngradeBrowserCopyAndCleanTest, Test) {
117 content::BrowserThread::GetBlockingPool()->FlushForTesting();
108 EXPECT_EQ(chrome::kChromeVersion, GetLastVersion(user_data_dir_).GetString()); 118 EXPECT_EQ(chrome::kChromeVersion, GetLastVersion(user_data_dir_).GetString());
109 ASSERT_FALSE(base::PathExists(other_file_)); 119 ASSERT_FALSE(base::PathExists(other_file_));
110 } 120 }
111 121
112 // Verify the user data directory will not be reset without downgrade. 122 // Verify the user data directory will not be reset without downgrade.
113 IN_PROC_BROWSER_TEST_F(UserDataDowngradeBrowserNoResetTest, Test) { 123 IN_PROC_BROWSER_TEST_F(UserDataDowngradeBrowserNoResetTest, Test) {
114 EXPECT_EQ(chrome::kChromeVersion, GetLastVersion(user_data_dir_).GetString()); 124 EXPECT_EQ(chrome::kChromeVersion, GetLastVersion(user_data_dir_).GetString());
115 ASSERT_TRUE(base::PathExists(other_file_)); 125 ASSERT_TRUE(base::PathExists(other_file_));
116 } 126 }
117 127
118 // Verify the "Last Version" file won't be created for non-msi install. 128 // Verify the "Last Version" file won't be created for non-msi install.
119 IN_PROC_BROWSER_TEST_F(UserDataDowngradeBrowserNoMSITest, Test) { 129 IN_PROC_BROWSER_TEST_F(UserDataDowngradeBrowserNoMSITest, Test) {
120 ASSERT_FALSE(base::PathExists(last_version_file_path_)); 130 ASSERT_FALSE(base::PathExists(last_version_file_path_));
131 ASSERT_TRUE(base::PathExists(other_file_));
121 } 132 }
122 133
123 } // namespace downgrade 134 } // namespace downgrade
OLDNEW
« no previous file with comments | « chrome/browser/downgrade/user_data_downgrade.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698