This source file includes following definitions.
- CreatePrefsFileInDirectory
- CheckChromeVersion
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "chrome/browser/profiles/profile.h"
#include "base/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/prefs/pref_service.h"
#include "base/version.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/startup_task_runner_service.h"
#include "chrome/browser/profiles/startup_task_runner_service_factory.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
class MockProfileDelegate : public Profile::Delegate {
public:
MOCK_METHOD1(OnPrefsLoaded, void(Profile*));
MOCK_METHOD3(OnProfileCreated, void(Profile*, bool, bool));
};
void CreatePrefsFileInDirectory(const base::FilePath& directory_path) {
base::FilePath pref_path(directory_path.Append(chrome::kPreferencesFilename));
std::string data("{}");
ASSERT_TRUE(base::WriteFile(pref_path, data.c_str(), data.size()));
}
void CheckChromeVersion(Profile *profile, bool is_new) {
std::string created_by_version;
if (is_new) {
chrome::VersionInfo version_info;
created_by_version = version_info.Version();
} else {
created_by_version = "1.0.0.0";
}
std::string pref_version =
ChromeVersionService::GetVersion(profile->GetPrefs());
EXPECT_EQ(created_by_version, pref_version);
}
}
typedef InProcessBrowserTest ProfileBrowserTest;
IN_PROC_BROWSER_TEST_F(ProfileBrowserTest,
DISABLED_CreateNewProfileSynchronous) {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
MockProfileDelegate delegate;
EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true));
scoped_ptr<Profile> profile(Profile::CreateProfile(
temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS));
ASSERT_TRUE(profile.get());
CheckChromeVersion(profile.get(), true);
StartupTaskRunnerServiceFactory::GetForProfile(profile.get())->
StartDeferredTaskRunners();
}
IN_PROC_BROWSER_TEST_F(ProfileBrowserTest,
DISABLED_CreateOldProfileSynchronous) {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
CreatePrefsFileInDirectory(temp_dir.path());
MockProfileDelegate delegate;
EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, false));
scoped_ptr<Profile> profile(Profile::CreateProfile(
temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS));
ASSERT_TRUE(profile.get());
CheckChromeVersion(profile.get(), false);
StartupTaskRunnerServiceFactory::GetForProfile(profile.get())->
StartDeferredTaskRunners();
}
IN_PROC_BROWSER_TEST_F(ProfileBrowserTest,
DISABLED_CreateNewProfileAsynchronous) {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
MockProfileDelegate delegate;
EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true));
scoped_ptr<Profile> profile(Profile::CreateProfile(
temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS));
ASSERT_TRUE(profile.get());
StartupTaskRunnerServiceFactory::GetForProfile(profile.get())->
StartDeferredTaskRunners();
content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_PROFILE_CREATED,
content::Source<Profile>(profile.get()));
observer.Wait();
CheckChromeVersion(profile.get(), true);
}
IN_PROC_BROWSER_TEST_F(ProfileBrowserTest,
DISABLED_CreateOldProfileAsynchronous) {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
CreatePrefsFileInDirectory(temp_dir.path());
MockProfileDelegate delegate;
EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, false));
scoped_ptr<Profile> profile(Profile::CreateProfile(
temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS));
ASSERT_TRUE(profile.get());
StartupTaskRunnerServiceFactory::GetForProfile(profile.get())->
StartDeferredTaskRunners();
content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_PROFILE_CREATED,
content::Source<Profile>(profile.get()));
observer.Wait();
CheckChromeVersion(profile.get(), false);
}
IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, DISABLED_ProfileReadmeCreated) {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
MockProfileDelegate delegate;
EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true));
ProfileImpl::create_readme_delay_ms = 0;
scoped_ptr<Profile> profile(Profile::CreateProfile(
temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS));
ASSERT_TRUE(profile.get());
StartupTaskRunnerServiceFactory::GetForProfile(profile.get())->
StartDeferredTaskRunners();
content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_PROFILE_CREATED,
content::Source<Profile>(profile.get()));
observer.Wait();
content::RunAllPendingInMessageLoop(content::BrowserThread::FILE);
EXPECT_TRUE(base::PathExists(
temp_dir.path().Append(chrome::kReadmeFilename)));
}
IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, ProfileDeletedBeforeReadmeCreated) {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
MockProfileDelegate delegate;
EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true));
ProfileImpl::create_readme_delay_ms = 0;
scoped_ptr<Profile> profile(Profile::CreateProfile(
temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS));
ASSERT_TRUE(profile.get());
StartupTaskRunnerServiceFactory::GetForProfile(profile.get())->
StartDeferredTaskRunners();
profile.reset();
content::RunAllPendingInMessageLoop();
content::RunAllPendingInMessageLoop(content::BrowserThread::DB);
content::RunAllPendingInMessageLoop(content::BrowserThread::FILE);
}
#if defined(OS_WIN)
#define MAYBE_ExitType DISABLED_ExitType
#else
#define MAYBE_ExitType ExitType
#endif
IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, MAYBE_ExitType) {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
MockProfileDelegate delegate;
EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true));
scoped_ptr<Profile> profile(Profile::CreateProfile(
temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS));
ASSERT_TRUE(profile.get());
StartupTaskRunnerServiceFactory::GetForProfile(profile.get())->
StartDeferredTaskRunners();
PrefService* prefs = profile->GetPrefs();
std::string crash_value(prefs->GetString(prefs::kSessionExitType));
profile->SetExitType(Profile::EXIT_SESSION_ENDED);
std::string first_call_value(prefs->GetString(prefs::kSessionExitType));
EXPECT_NE(crash_value, first_call_value);
profile->SetExitType(Profile::EXIT_NORMAL);
std::string second_call_value(prefs->GetString(prefs::kSessionExitType));
EXPECT_EQ(first_call_value, second_call_value);
profile->SetExitType(Profile::EXIT_CRASHED);
std::string final_value(prefs->GetString(prefs::kSessionExitType));
EXPECT_EQ(crash_value, final_value);
profile.reset();
content::RunAllPendingInMessageLoop();
content::RunAllPendingInMessageLoop(content::BrowserThread::DB);
}