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

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: 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
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/test/base/in_process_browser_test.h"
17 #include "content/public/browser/browser_thread.h"
18
19 class UserDataDowngradeBrowserTestBase : public InProcessBrowserTest {
20 protected:
21 // 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
22 void TearDownInProcessBrowserTestFixture() override {
23 const base::FilePath::StringType index_suffix = FILE_PATH_LITERAL(" (1)");
24 ASSERT_FALSE(base::DirectoryExists(
25 base::FilePath(user_data_dir_.value() + index_suffix)
26 .AddExtension(g_downgrade_delete_suffix)));
27 SimulateDowngradeForTest(false);
28 }
29
30 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.
31 if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_))
32 return false;
33 if (!CreateTemporaryFileInDir(user_data_dir_, &other_file_))
34 return false;
35 base::FilePath browser_version_file_path =
36 user_data_dir_.Append(g_downgrade_browser_version_file);
37 std::string last_browser_version = GetNextChromeVersion();
38 base::WriteFile(browser_version_file_path, last_browser_version.c_str(),
39 last_browser_version.size());
40 return true;
41 }
42
43 std::string GetNextChromeVersion() {
44 return base::Version(std::string(chrome::kChromeVersion) + "1").GetString();
45 }
46
47 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.
48 base::FilePath user_data_dir_;
49 registry_util::RegistryOverrideManager registry_override_manager_;
50 };
51
52 class UserDataDowngradeBrowserCopyAndCleanTest
53 : public UserDataDowngradeBrowserTestBase {
54 void SetUpInProcessBrowserTestFixture() override {
55 SimulateDowngradeForTest(true);
56 HKEY root = HKEY_CURRENT_USER;
57 registry_override_manager_.OverrideRegistry(root);
58 base::win::RegKey key(
59 root, BrowserDistribution::GetDistribution()->GetStateKey().c_str(),
60 KEY_SET_VALUE | KEY_WOW64_32KEY);
61 key.WriteValue(L"DowngradeVersion",
62 base::ASCIIToUTF16(GetNextChromeVersion()).c_str());
63 }
64 };
65
66 class UserDataDowngradeBrowserNoResetTest
67 : public UserDataDowngradeBrowserTestBase {
68 void SetUpInProcessBrowserTestFixture() override {
69 SimulateDowngradeForTest(true);
70 }
71 };
72
73 // Verify the user data directory has been renamed and created again after
74 // downgrade.
75 IN_PROC_BROWSER_TEST_F(UserDataDowngradeBrowserCopyAndCleanTest, Test) {
76 EXPECT_EQ(chrome::kChromeVersion,
77 GetBrowserVersion(user_data_dir_).GetString());
78 ASSERT_FALSE(base::PathExists(other_file_));
79 }
80
81 // Verify the user data directory will not be reset without downgrade.
82 IN_PROC_BROWSER_TEST_F(UserDataDowngradeBrowserNoResetTest, Test) {
83 EXPECT_EQ(chrome::kChromeVersion,
84 GetBrowserVersion(user_data_dir_).GetString());
85 ASSERT_TRUE(base::PathExists(other_file_));
86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698