| Index: chrome/browser/profiles/profile_manager_browsertest.cc
|
| diff --git a/chrome/browser/profiles/profile_manager_browsertest.cc b/chrome/browser/profiles/profile_manager_browsertest.cc
|
| index 06f06dc2d8fa4b9e2843c2751ce1d1f706ab6001..5c397407e34c59413651f0ba232d0711f8051828 100644
|
| --- a/chrome/browser/profiles/profile_manager_browsertest.cc
|
| +++ b/chrome/browser/profiles/profile_manager_browsertest.cc
|
| @@ -36,6 +36,15 @@
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #endif
|
|
|
| +#if defined(OS_WIN)
|
| +#include <windows.h>
|
| +#include "base/files/file_util.h"
|
| +#include "base/path_service.h"
|
| +#include "base/test/test_file_util.h"
|
| +#include "chrome/common/chrome_paths.h"
|
| +#include "chrome/common/chrome_switches.h"
|
| +#endif
|
| +
|
| namespace {
|
|
|
| const ProfileManager::CreateCallback kOnProfileSwitchDoNothing;
|
| @@ -499,3 +508,152 @@ IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, IncognitoProfile) {
|
| ->GetFilePath(prefs::kSaveFileDefaultDirectory)
|
| .empty());
|
| }
|
| +
|
| +#if defined(OS_WIN)
|
| +bool RemoveCreateDirectoryPermission(const base::FilePath& path) {
|
| + return base::DenyFilePermission(path, FILE_ADD_SUBDIRECTORY);
|
| +}
|
| +
|
| +class ProfileManagerWinBrowserTest : public ProfileManagerBrowserTest {
|
| + public:
|
| + ProfileManagerWinBrowserTest() {}
|
| + // Tests may be reported as PASS even if the test has never been run. To
|
| + // mitigate the issue, a "red flag" is raised for susceptable tests. These
|
| + // tests need to call DropRedFlag() to pass the test.
|
| + void DropRedFlag() { red_flag_ = false; }
|
| +
|
| + protected:
|
| + void SetUpCommandLine(base::CommandLine* command_line) override {
|
| + command_line->AppendSwitch(switches::kRestoreLastSession);
|
| + }
|
| +
|
| + bool SetUpUserDataDirectory() override {
|
| + std::string testname(
|
| + testing::UnitTest::GetInstance()->current_test_info()->name());
|
| + if (testname == "LastOpenedProfileMissing") {
|
| + red_flag_ = true;
|
| +
|
| + base::FilePath user_data_dir;
|
| + if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir))
|
| + return false;
|
| +
|
| + base::FilePath dir_to_delete = user_data_dir.AppendASCII("Profile 1");
|
| + return base::DirectoryExists(dir_to_delete) &&
|
| + DeleteFile(dir_to_delete, true) &&
|
| + RemoveCreateDirectoryPermission(user_data_dir);
|
| + } else if (testname == "SwitchToMissingProfile") {
|
| + red_flag_ = true;
|
| +
|
| + base::FilePath user_data_dir;
|
| + if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir))
|
| + return false;
|
| +
|
| + base::FilePath dir_to_delete = user_data_dir.AppendASCII("Profile 1");
|
| + return base::DirectoryExists(dir_to_delete) &&
|
| + DeleteFile(dir_to_delete, true) &&
|
| + RemoveCreateDirectoryPermission(user_data_dir);
|
| + }
|
| + return true;
|
| + }
|
| +
|
| + void TearDown() override {
|
| + EXPECT_FALSE(red_flag_);
|
| + ProfileManagerBrowserTest::TearDown();
|
| + }
|
| +
|
| + private:
|
| + bool red_flag_ = false;
|
| + DISALLOW_COPY_AND_ASSIGN(ProfileManagerWinBrowserTest);
|
| +};
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ProfileManagerWinBrowserTest,
|
| + PRE_LastOpenedProfileMissing) {
|
| + ProfileManager* profile_manager = g_browser_process->profile_manager();
|
| + ASSERT_TRUE(profile_manager);
|
| +
|
| + std::vector<base::FilePath> profile_paths;
|
| + // Create two additional profile.
|
| + for (int i = 0; i < 2; ++i) {
|
| + base::FilePath path = profile_manager->GenerateNextProfileDirectoryPath();
|
| + profile_paths.push_back(path);
|
| +
|
| + base::RunLoop run_loop;
|
| + profile_manager->CreateProfileAsync(
|
| + path, base::Bind(&OnUnblockOnProfileCreation, &run_loop),
|
| + base::string16(), std::string(), std::string());
|
| +
|
| + // Run the message loop to allow profile creation to take place; the loop is
|
| + // terminated by OnUnblockOnProfileCreation when the profile is created.
|
| + run_loop.Run();
|
| +
|
| + profiles::SwitchToProfile(path, false, kOnProfileSwitchDoNothing,
|
| + ProfileMetrics::SWITCH_PROFILE_ICON);
|
| + }
|
| +
|
| + ASSERT_EQ(base::FilePath(FILE_PATH_LITERAL("Profile 1")),
|
| + profile_paths[0].BaseName());
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ProfileManagerWinBrowserTest,
|
| + LastOpenedProfileMissing) {
|
| + DropRedFlag();
|
| +
|
| + BrowserList* browser_list = BrowserList::GetInstance();
|
| + // Three browser windows were created in the PRE test. Since Profile 1 is
|
| + // being skipped, only two browser windows were created in the second run.
|
| + EXPECT_EQ(2u, browser_list->size());
|
| + for (const Browser* browser : *browser_list) {
|
| + EXPECT_NE(base::FilePath(FILE_PATH_LITERAL("Profile 1")),
|
| + browser->profile()->GetPath().BaseName());
|
| + }
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ProfileManagerWinBrowserTest,
|
| + PRE_SwitchToMissingProfile) {
|
| + ProfileManager* profile_manager = g_browser_process->profile_manager();
|
| + ASSERT_TRUE(profile_manager);
|
| +
|
| + std::vector<base::FilePath> profile_paths;
|
| + // Create two additional profile.
|
| + for (int i = 0; i < 2; ++i) {
|
| + base::FilePath path = profile_manager->GenerateNextProfileDirectoryPath();
|
| + profile_paths.push_back(path);
|
| +
|
| + base::RunLoop run_loop;
|
| + profile_manager->CreateProfileAsync(
|
| + path, base::Bind(&OnUnblockOnProfileCreation, &run_loop),
|
| + base::string16(), std::string(), std::string());
|
| +
|
| + // Run the message loop to allow profile creation to take place; the loop is
|
| + // terminated by OnUnblockOnProfileCreation when the profile is created.
|
| + run_loop.Run();
|
| +
|
| + profiles::SwitchToProfile(path, false, kOnProfileSwitchDoNothing,
|
| + ProfileMetrics::SWITCH_PROFILE_ICON);
|
| + }
|
| +
|
| + ASSERT_EQ(base::FilePath(FILE_PATH_LITERAL("Profile 1")),
|
| + profile_paths[0].BaseName());
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ProfileManagerWinBrowserTest,
|
| + SwitchToMissingProfile) {
|
| + DropRedFlag();
|
| +
|
| + BrowserList* browser_list = BrowserList::GetInstance();
|
| + // Three browser windows were created in the PRE test. Since Profile 1 is
|
| + // being skipped, only two browser windows were created in the second run.
|
| + EXPECT_EQ(2u, browser_list->size());
|
| + for (const Browser* browser : *browser_list) {
|
| + EXPECT_NE(base::FilePath(FILE_PATH_LITERAL("Profile 1")),
|
| + browser->profile()->GetPath().BaseName());
|
| + }
|
| +
|
| + profiles::SwitchToProfile(g_browser_process->profile_manager()
|
| + ->user_data_dir().AppendASCII("Profile 1"),
|
| + false,
|
| + kOnProfileSwitchDoNothing,
|
| + ProfileMetrics::SWITCH_PROFILE_ICON);
|
| +}
|
| +
|
| +#endif // defined(OS_WIN)
|
|
|