| Index: chrome/browser/profiles/profile_browsertest.cc
|
| diff --git a/chrome/browser/profiles/profile_browsertest.cc b/chrome/browser/profiles/profile_browsertest.cc
|
| index 0cc502f4ea4b0aa0a8587afc44ff0970963d1ab5..a4256df5aea49b7ae8414d461ee3f4f7064676d4 100644
|
| --- a/chrome/browser/profiles/profile_browsertest.cc
|
| +++ b/chrome/browser/profiles/profile_browsertest.cc
|
| @@ -7,12 +7,17 @@
|
| #include "base/command_line.h"
|
| #include "base/file_util.h"
|
| #include "base/files/scoped_temp_dir.h"
|
| +#include "base/json/json_reader.h"
|
| #include "base/prefs/pref_service.h"
|
| +#include "base/sequenced_task_runner.h"
|
| #include "base/synchronization/waitable_event.h"
|
| +#include "base/values.h"
|
| #include "base/version.h"
|
| +#include "chrome/browser/browser_process.h"
|
| #include "chrome/browser/chrome_notification_types.h"
|
| #include "chrome/browser/profiles/chrome_version_service.h"
|
| #include "chrome/browser/profiles/profile_impl.h"
|
| +#include "chrome/browser/profiles/profile_manager.h"
|
| #include "chrome/browser/profiles/startup_task_runner_service.h"
|
| #include "chrome/browser/profiles/startup_task_runner_service_factory.h"
|
| #include "chrome/common/chrome_constants.h"
|
| @@ -42,20 +47,6 @@ void CreatePrefsFileInDirectory(const base::FilePath& directory_path) {
|
| ASSERT_TRUE(base::WriteFile(pref_path, data.c_str(), data.size()));
|
| }
|
|
|
| -scoped_ptr<Profile> CreateProfile(
|
| - const base::FilePath& path,
|
| - Profile::Delegate* delegate,
|
| - Profile::CreateMode create_mode) {
|
| - scoped_ptr<Profile> profile(Profile::CreateProfile(
|
| - path, delegate, create_mode));
|
| - EXPECT_TRUE(profile.get());
|
| - // This is necessary to avoid a memleak from BookmarkModel::Load.
|
| - // Unfortunately, this also results in warnings during debug runs.
|
| - StartupTaskRunnerServiceFactory::GetForProfile(profile.get())->
|
| - StartDeferredTaskRunners();
|
| - return profile.Pass();
|
| -}
|
| -
|
| void CheckChromeVersion(Profile *profile, bool is_new) {
|
| std::string created_by_version;
|
| if (is_new) {
|
| @@ -77,6 +68,16 @@ void BlockThread(
|
| unblock->Wait();
|
| }
|
|
|
| +void FlushTaskRunner(base::SequencedTaskRunner* runner) {
|
| + ASSERT_TRUE(runner);
|
| + base::WaitableEvent unblock(false, false);
|
| +
|
| + runner->PostTask(FROM_HERE,
|
| + base::Bind(&base::WaitableEvent::Signal, base::Unretained(&unblock)));
|
| +
|
| + unblock.Wait();
|
| +}
|
| +
|
| void SpinThreads() {
|
| // Give threads a chance to do their stuff before shutting down (i.e.
|
| // deleting scoped temp dir etc).
|
| @@ -97,14 +98,32 @@ class ProfileBrowserTest : public InProcessBrowserTest {
|
| chromeos::switches::kIgnoreUserProfileMappingForTests);
|
| #endif
|
| }
|
| +
|
| + scoped_ptr<Profile> CreateProfile(
|
| + const base::FilePath& path,
|
| + Profile::Delegate* delegate,
|
| + Profile::CreateMode create_mode) {
|
| + scoped_ptr<Profile> profile(Profile::CreateProfile(
|
| + path, delegate, create_mode));
|
| + EXPECT_TRUE(profile.get());
|
| +
|
| + // Store the Profile's IO task runner so we can wind it down.
|
| + profile_io_task_runner_ = profile->GetIOTaskRunner();
|
| +
|
| + return profile.Pass();
|
| + }
|
| +
|
| + void FlushIoTaskRunnerAndSpinThreads() {
|
| + FlushTaskRunner(profile_io_task_runner_);
|
| + SpinThreads();
|
| + }
|
| +
|
| + scoped_refptr<base::SequencedTaskRunner> profile_io_task_runner_;
|
| };
|
|
|
| // Test OnProfileCreate is called with is_new_profile set to true when
|
| // creating a new profile synchronously.
|
| -//
|
| -// Flaky (sometimes timeout): http://crbug.com/141141
|
| -IN_PROC_BROWSER_TEST_F(ProfileBrowserTest,
|
| - DISABLED_CreateNewProfileSynchronous) {
|
| +IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, CreateNewProfileSynchronous) {
|
| base::ScopedTempDir temp_dir;
|
| ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
|
|
|
| @@ -117,14 +136,12 @@ IN_PROC_BROWSER_TEST_F(ProfileBrowserTest,
|
| CheckChromeVersion(profile.get(), true);
|
| }
|
|
|
| - SpinThreads();
|
| + FlushIoTaskRunnerAndSpinThreads();
|
| }
|
|
|
| // Test OnProfileCreate is called with is_new_profile set to false when
|
| // creating a profile synchronously with an existing prefs file.
|
| -// Flaky: http://crbug.com/141517
|
| -IN_PROC_BROWSER_TEST_F(ProfileBrowserTest,
|
| - DISABLED_CreateOldProfileSynchronous) {
|
| +IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, CreateOldProfileSynchronous) {
|
| base::ScopedTempDir temp_dir;
|
| ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
|
| CreatePrefsFileInDirectory(temp_dir.path());
|
| @@ -138,14 +155,12 @@ IN_PROC_BROWSER_TEST_F(ProfileBrowserTest,
|
| CheckChromeVersion(profile.get(), false);
|
| }
|
|
|
| - SpinThreads();
|
| + FlushIoTaskRunnerAndSpinThreads();
|
| }
|
|
|
| // Test OnProfileCreate is called with is_new_profile set to true when
|
| // creating a new profile asynchronously.
|
| -// This test is flaky on Linux, Win and Mac. See crbug.com/142787
|
| -IN_PROC_BROWSER_TEST_F(ProfileBrowserTest,
|
| - DISABLED_CreateNewProfileAsynchronous) {
|
| +IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, CreateNewProfileAsynchronous) {
|
| base::ScopedTempDir temp_dir;
|
| ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
|
|
|
| @@ -165,14 +180,12 @@ IN_PROC_BROWSER_TEST_F(ProfileBrowserTest,
|
| CheckChromeVersion(profile.get(), true);
|
| }
|
|
|
| - SpinThreads();
|
| + FlushIoTaskRunnerAndSpinThreads();
|
| }
|
|
|
| // Test OnProfileCreate is called with is_new_profile set to false when
|
| // creating a profile asynchronously with an existing prefs file.
|
| -// Flaky: http://crbug.com/141517
|
| -IN_PROC_BROWSER_TEST_F(ProfileBrowserTest,
|
| - DISABLED_CreateOldProfileAsynchronous) {
|
| +IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, CreateOldProfileAsynchronous) {
|
| base::ScopedTempDir temp_dir;
|
| ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
|
| CreatePrefsFileInDirectory(temp_dir.path());
|
| @@ -193,12 +206,11 @@ IN_PROC_BROWSER_TEST_F(ProfileBrowserTest,
|
| CheckChromeVersion(profile.get(), false);
|
| }
|
|
|
| - SpinThreads();
|
| + FlushIoTaskRunnerAndSpinThreads();
|
| }
|
|
|
| // Test that a README file is created for profiles that didn't have it.
|
| -// Flaky: http://crbug.com/140882
|
| -IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, DISABLED_ProfileReadmeCreated) {
|
| +IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, ProfileReadmeCreated) {
|
| base::ScopedTempDir temp_dir;
|
| ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
|
|
|
| @@ -227,7 +239,7 @@ IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, DISABLED_ProfileReadmeCreated) {
|
| temp_dir.path().Append(chrome::kReadmeFilename)));
|
| }
|
|
|
| - SpinThreads();
|
| + FlushIoTaskRunnerAndSpinThreads();
|
| }
|
|
|
| // Test that Profile can be deleted before README file is created.
|
| @@ -262,17 +274,11 @@ IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, ProfileDeletedBeforeReadmeCreated) {
|
| // task for README creation).
|
| unblock->Signal();
|
|
|
| - SpinThreads();
|
| + FlushIoTaskRunnerAndSpinThreads();
|
| }
|
|
|
| // Test that repeated setting of exit type is handled correctly.
|
| -#if defined(OS_WIN)
|
| -// Flaky on Windows: http://crbug.com/163713
|
| -#define MAYBE_ExitType DISABLED_ExitType
|
| -#else
|
| -#define MAYBE_ExitType ExitType
|
| -#endif
|
| -IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, MAYBE_ExitType) {
|
| +IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, ExitType) {
|
| base::ScopedTempDir temp_dir;
|
| ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
|
|
|
| @@ -302,5 +308,69 @@ IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, MAYBE_ExitType) {
|
| EXPECT_EQ(crash_value, final_value);
|
| }
|
|
|
| - SpinThreads();
|
| + FlushIoTaskRunnerAndSpinThreads();
|
| +}
|
| +
|
| +// The EndSession IO synchronization is only critical on Windows, but also
|
| +// happens under the USE_X11 define. See BrowserProcessImpl::EndSession.
|
| +#if defined(USE_X11) || defined(OS_WIN)
|
| +
|
| +namespace {
|
| +
|
| +std::string GetExitTypePreferenceFromDisk(Profile* profile) {
|
| + base::FilePath prefs_path =
|
| + profile->GetPath().Append(chrome::kPreferencesFilename);
|
| + std::string prefs;
|
| + if (!base::ReadFileToString(prefs_path, &prefs))
|
| + return std::string();
|
| +
|
| + scoped_ptr<base::Value> value(base::JSONReader::Read(prefs));
|
| + if (!value)
|
| + return std::string();
|
| +
|
| + base::DictionaryValue* dict = NULL;
|
| + if (!value->GetAsDictionary(&dict) || !dict)
|
| + return std::string();
|
| +
|
| + std::string exit_type;
|
| + if (!dict->GetString("profile.exit_type", &exit_type))
|
| + return std::string();
|
| +
|
| + return exit_type;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ProfileBrowserTest,
|
| + WritesProfilesSynchronouslyOnEndSession) {
|
| + base::ScopedTempDir temp_dir;
|
| + ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
|
| +
|
| + ProfileManager* profile_manager = g_browser_process->profile_manager();
|
| + ASSERT_TRUE(profile_manager);
|
| + std::vector<Profile*> loaded_profiles = profile_manager->GetLoadedProfiles();
|
| +
|
| + ASSERT_NE(loaded_profiles.size(), 0UL);
|
| + for (size_t i = 0; i < loaded_profiles.size(); ++i) {
|
| + Profile* profile = loaded_profiles[i];
|
| +
|
| + // Flush the profile data to disk for all loaded profiles.
|
| + profile->SetExitType(Profile::EXIT_CRASHED);
|
| + FlushTaskRunner(profile->GetIOTaskRunner());
|
| +
|
| + // Make sure that the prefs file was written with the expected key/value.
|
| + ASSERT_EQ(GetExitTypePreferenceFromDisk(profile), "Crashed");
|
| + }
|
| +
|
| + // This must not return until the profile data has been written to disk.
|
| + // If this test flakes, then logoff on Windows has broken again.
|
| + g_browser_process->EndSession();
|
| +
|
| + // Verify that the setting was indeed written.
|
| + for (size_t i = 0; i < loaded_profiles.size(); ++i) {
|
| + Profile* profile = loaded_profiles[i];
|
| + // Make sure that the prefs file was written with the expected key/value.
|
| + ASSERT_EQ(GetExitTypePreferenceFromDisk(profile), "SessionEnded");
|
| + }
|
| }
|
| +#endif // defined(USE_X11) || defined(OS_WIN)
|
|
|