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

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/test/base/in_process_browser_test.h"
17 #include "content/public/browser/browser_thread.h"
18
19 class UserDataDowngradeBrowserTest : public InProcessBrowserTest {
20 protected:
21 void SetUpInProcessBrowserTestFixture() override {
22 SimulateDowngradeForTest(true);
23 HKEY root = HKEY_CURRENT_USER;
24 registry_override_manager_.OverrideRegistry(root);
25 base::win::RegKey key(
26 root, BrowserDistribution::GetDistribution()->GetStateKey().c_str(),
27 KEY_SET_VALUE | KEY_WOW64_32KEY);
28 key.WriteValue(L"DowngradeVersion",
29 base::ASCIIToUTF16(GetNextChromeVersion()).c_str());
30 }
31
32 // Verify the renamed user data directory has been deleted.
33 void TearDownInProcessBrowserTestFixture() override {
34 const base::FilePath::StringType delete_suffix =
35 FILE_PATH_LITERAL(" (1).CHROME_DELETE");
sky 2016/06/03 00:04:24 Make a constant for this. In fact you should also
zmin 2016/06/03 15:46:52 The moved profile may be deleted very quickly duri
sky 2016/06/03 18:18:03 You need some way to verify all this is working. A
36 ASSERT_FALSE(base::DirectoryExists(
37 base::FilePath(user_data_dir_.value() + delete_suffix)));
38 SimulateDowngradeForTest(false);
39 }
40
41 bool SetUpUserDataDirectory() override {
42 const base::FilePath::StringType last_chrome_version_file =
43 FILE_PATH_LITERAL("Last Chrome Version");
44 if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_))
45 return false;
46 if (!CreateTemporaryFileInDir(user_data_dir_, &other_file_))
47 return false;
48 last_chrome_version_path_ = user_data_dir_.Append(last_chrome_version_file);
49 std::string last_chrome_version = GetNextChromeVersion();
50 base::WriteFile(last_chrome_version_path_, last_chrome_version.c_str(),
51 last_chrome_version.size());
52 return true;
53 }
54
55 std::string GetNextChromeVersion() {
56 return base::Version(std::string(chrome::kChromeVersion) + "1").GetString();
57 }
58
59 base::FilePath last_chrome_version_path_;
60 base::FilePath other_file_;
61 base::FilePath user_data_dir_;
62 registry_util::RegistryOverrideManager registry_override_manager_;
63 };
64
65 // Verify the user data directory has been renamed and created again after
66 // downgrade.
67 IN_PROC_BROWSER_TEST_F(UserDataDowngradeBrowserTest, CopyAndClean) {
sky 2016/06/03 00:04:24 Can you also add a test that the directory is not
zmin 2016/06/03 15:46:52 Sure.
68 std::string last_chrome_version_str;
69 base::ReadFileToString(last_chrome_version_path_, &last_chrome_version_str);
sky 2016/06/03 00:04:24 It would be good if user_data_downgrade.h had a sp
zmin 2016/06/03 15:46:52 Done.
70 EXPECT_EQ(chrome::kChromeVersion, last_chrome_version_str);
71 ASSERT_FALSE(base::PathExists(other_file_));
72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698