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

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/version.h"
10 #include "chrome/common/chrome_constants.h"
11 #include "chrome/common/chrome_paths.h"
12 #include "chrome/test/base/in_process_browser_test.h"
13 #include "content/public/browser/browser_thread.h"
14
15 class UserDataDowngradeBrowserTest : public InProcessBrowserTest {
16 protected:
17 void SetUpInProcessBrowserTestFixture() override {
18 SimulateDowngradeForTest(true);
19 }
20
21 // Verify the renamed user data directory has been deleted.
22 void TearDownInProcessBrowserTestFixture() override {
23 const base::FilePath::StringType delete_suffix =
24 FILE_PATH_LITERAL(" (1).CHROME_DELETE");
25 ASSERT_FALSE(base::DirectoryExists(
26 base::FilePath(user_data_dir_.value() + delete_suffix)));
27 SimulateDowngradeForTest(false);
28 }
29
30 bool SetUpUserDataDirectory() override {
31 const base::FilePath::StringType last_chrome_version_file =
32 FILE_PATH_LITERAL("Last Chrome Version");
33 if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_))
34 return false;
35 if (!CreateTemporaryFileInDir(user_data_dir_, &other_file_))
36 return false;
37 last_chrome_version_path_ = user_data_dir_.Append(last_chrome_version_file);
38 std::string last_chrome_version =
39 base::Version(std::string(chrome::kChromeVersion) + "1").GetString();
40 base::WriteFile(last_chrome_version_path_, last_chrome_version.c_str(),
41 last_chrome_version.size());
42 return true;
43 }
44
45 base::FilePath last_chrome_version_path_;
46 base::FilePath other_file_;
47 base::FilePath user_data_dir_;
48 };
49
50 // Verify the user data directory has been renamed and created again after
51 // downgrade.
52 IN_PROC_BROWSER_TEST_F(UserDataDowngradeBrowserTest, CopyAndClean) {
53 std::string last_chrome_version_str;
54 base::ReadFileToString(last_chrome_version_path_, &last_chrome_version_str);
55 EXPECT_EQ(chrome::kChromeVersion, last_chrome_version_str);
56 ASSERT_FALSE(base::PathExists(other_file_));
57 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698