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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/downgrade/user_data_downgrade_browsertest.cc
diff --git a/chrome/browser/downgrade/user_data_downgrade_browsertest.cc b/chrome/browser/downgrade/user_data_downgrade_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7e0e17427dbd858cd4f594dfc45bed5d267c158c
--- /dev/null
+++ b/chrome/browser/downgrade/user_data_downgrade_browsertest.cc
@@ -0,0 +1,72 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/downgrade/user_data_downgrade.h"
+
+#include "base/files/file_util.h"
+#include "base/path_service.h"
+#include "base/strings/utf_string_conversions.h"
+#include "base/test/test_reg_util_win.h"
+#include "base/version.h"
+#include "base/win/registry.h"
+#include "chrome/common/chrome_constants.h"
+#include "chrome/common/chrome_paths.h"
+#include "chrome/installer/util/browser_distribution.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "content/public/browser/browser_thread.h"
+
+class UserDataDowngradeBrowserTest : public InProcessBrowserTest {
+ protected:
+ void SetUpInProcessBrowserTestFixture() override {
+ SimulateDowngradeForTest(true);
+ HKEY root = HKEY_CURRENT_USER;
+ registry_override_manager_.OverrideRegistry(root);
+ base::win::RegKey key(
+ root, BrowserDistribution::GetDistribution()->GetStateKey().c_str(),
+ KEY_SET_VALUE | KEY_WOW64_32KEY);
+ key.WriteValue(L"DowngradeVersion",
+ base::ASCIIToUTF16(GetNextChromeVersion()).c_str());
+ }
+
+ // Verify the renamed user data directory has been deleted.
+ void TearDownInProcessBrowserTestFixture() override {
+ const base::FilePath::StringType delete_suffix =
+ 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
+ ASSERT_FALSE(base::DirectoryExists(
+ base::FilePath(user_data_dir_.value() + delete_suffix)));
+ SimulateDowngradeForTest(false);
+ }
+
+ bool SetUpUserDataDirectory() override {
+ const base::FilePath::StringType last_chrome_version_file =
+ FILE_PATH_LITERAL("Last Chrome Version");
+ if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_))
+ return false;
+ if (!CreateTemporaryFileInDir(user_data_dir_, &other_file_))
+ return false;
+ last_chrome_version_path_ = user_data_dir_.Append(last_chrome_version_file);
+ std::string last_chrome_version = GetNextChromeVersion();
+ base::WriteFile(last_chrome_version_path_, last_chrome_version.c_str(),
+ last_chrome_version.size());
+ return true;
+ }
+
+ std::string GetNextChromeVersion() {
+ return base::Version(std::string(chrome::kChromeVersion) + "1").GetString();
+ }
+
+ base::FilePath last_chrome_version_path_;
+ base::FilePath other_file_;
+ base::FilePath user_data_dir_;
+ registry_util::RegistryOverrideManager registry_override_manager_;
+};
+
+// Verify the user data directory has been renamed and created again after
+// downgrade.
+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.
+ std::string last_chrome_version_str;
+ 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.
+ EXPECT_EQ(chrome::kChromeVersion, last_chrome_version_str);
+ ASSERT_FALSE(base::PathExists(other_file_));
+}

Powered by Google App Engine
This is Rietveld 408576698