| 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..51b4ca39c534af94ac9419eae187d0d915b8ee6e
|
| --- /dev/null
|
| +++ b/chrome/browser/downgrade/user_data_downgrade_browsertest.cc
|
| @@ -0,0 +1,57 @@
|
| +// 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/version.h"
|
| +#include "chrome/common/chrome_constants.h"
|
| +#include "chrome/common/chrome_paths.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);
|
| + }
|
| +
|
| + // Verify the renamed user data directory has been deleted.
|
| + void TearDownInProcessBrowserTestFixture() override {
|
| + const base::FilePath::StringType delete_suffix =
|
| + FILE_PATH_LITERAL(" (1).CHROME_DELETE");
|
| + 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 =
|
| + base::Version(std::string(chrome::kChromeVersion) + "1").GetString();
|
| + base::WriteFile(last_chrome_version_path_, last_chrome_version.c_str(),
|
| + last_chrome_version.size());
|
| + return true;
|
| + }
|
| +
|
| + base::FilePath last_chrome_version_path_;
|
| + base::FilePath other_file_;
|
| + base::FilePath user_data_dir_;
|
| +};
|
| +
|
| +// Verify the user data directory has been renamed and created again after
|
| +// downgrade.
|
| +IN_PROC_BROWSER_TEST_F(UserDataDowngradeBrowserTest, CopyAndClean) {
|
| + std::string last_chrome_version_str;
|
| + base::ReadFileToString(last_chrome_version_path_, &last_chrome_version_str);
|
| + EXPECT_EQ(chrome::kChromeVersion, last_chrome_version_str);
|
| + ASSERT_FALSE(base::PathExists(other_file_));
|
| +}
|
|
|