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

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

Issue 1986823002: Reset user data directory and disk cache directory after downgrade. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
OLDNEW
(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 namespace downgrade {
21
22 class UserDataDowngradeBrowserTestBase : public InProcessBrowserTest {
23 protected:
24 // content::BrowserTestBase:
25 void SetUpInProcessBrowserTestFixture() override {
26 SetSimulateDowngradeForTest(true);
27 HKEY root = HKEY_CURRENT_USER;
28 registry_override_manager_.OverrideRegistry(root);
29 key_.Create(root,
30 BrowserDistribution::GetDistribution()->GetStateKey().c_str(),
31 KEY_SET_VALUE | KEY_WOW64_32KEY);
32 }
33
34 // InProcessBrowserTest:
35 bool SetUpUserDataDirectory() override {
36 if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_))
37 return false;
38 if (!CreateTemporaryFileInDir(user_data_dir_, &other_file_))
39 return false;
40 last_version_file_path_ = user_data_dir_.Append(kDowngradeLastVersionFile);
41 std::string last_version = GetNextChromeVersion();
42 base::WriteFile(last_version_file_path_, last_version.c_str(),
43 last_version.size());
44 return true;
45 }
46
47 // content::BrowserTestBase:
48 // Verify the renamed user data directory has been deleted.
49 void TearDownInProcessBrowserTestFixture() override {
50 const base::FilePath::StringType index_suffix = FILE_PATH_LITERAL(" (1)");
51 ASSERT_FALSE(base::DirectoryExists(
52 base::FilePath(user_data_dir_.value() + index_suffix)
53 .AddExtension(kDowngradeDeleteSuffix)));
54 SetSimulateDowngradeForTest(false);
55 key_.Close();
56 }
57
58 std::string GetNextChromeVersion() {
59 return base::Version(std::string(chrome::kChromeVersion) + "1").GetString();
60 }
61
62 base::FilePath last_version_file_path_;
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.
65 base::FilePath other_file_;
66 base::FilePath user_data_dir_;
67 base::win::RegKey key_;
68 registry_util::RegistryOverrideManager registry_override_manager_;
69 };
70
71 class UserDataDowngradeBrowserCopyAndCleanTest
72 : public UserDataDowngradeBrowserTestBase {
73 protected:
74 // content::BrowserTestBase:
75 void SetUpInProcessBrowserTestFixture() override {
76 UserDataDowngradeBrowserTestBase::SetUpInProcessBrowserTestFixture();
77 key_.WriteValue(L"DowngradeVersion",
78 base::ASCIIToUTF16(GetNextChromeVersion()).c_str());
79 key_.WriteValue(google_update::kRegMSIField, 1);
80 }
81 };
82
83 class UserDataDowngradeBrowserNoResetTest
84 : public UserDataDowngradeBrowserTestBase {
85 protected:
86 // content::BrowserTestBase:
87 void SetUpInProcessBrowserTestFixture() override {
88 UserDataDowngradeBrowserTestBase::SetUpInProcessBrowserTestFixture();
89 key_.WriteValue(google_update::kRegMSIField, 1);
90 }
91 };
92
93 class UserDataDowngradeBrowserNoMSITest
94 : public UserDataDowngradeBrowserTestBase {
95 protected:
96 // content::BrowserTestBase:
97 void SetUpInProcessBrowserTestFixture() override {
98 UserDataDowngradeBrowserTestBase::SetUpInProcessBrowserTestFixture();
99 }
100
101 // InProcessBrowserTest:
102 bool SetUpUserDataDirectory() override { return true; }
103 };
104
105 // Verify the user data directory has been renamed and created again after
106 // downgrade.
107 IN_PROC_BROWSER_TEST_F(UserDataDowngradeBrowserCopyAndCleanTest, Test) {
108 EXPECT_EQ(chrome::kChromeVersion, GetLastVersion(user_data_dir_).GetString());
109 ASSERT_FALSE(base::PathExists(other_file_));
110 }
111
112 // Verify the user data directory will not be reset without downgrade.
113 IN_PROC_BROWSER_TEST_F(UserDataDowngradeBrowserNoResetTest, Test) {
114 EXPECT_EQ(chrome::kChromeVersion, GetLastVersion(user_data_dir_).GetString());
115 ASSERT_TRUE(base::PathExists(other_file_));
116 }
117
118 // Verify the "Last Version" file won't be created for non-msi install.
119 IN_PROC_BROWSER_TEST_F(UserDataDowngradeBrowserNoMSITest, Test) {
120 ASSERT_FALSE(base::PathExists(last_version_file_path_));
121 }
122
123 } // namespace downgrade
OLDNEW
« no previous file with comments | « chrome/browser/downgrade/user_data_downgrade.cc ('k') | chrome/browser/policy/policy_path_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698