This source file includes following definitions.
- InitSecondProfile
- OnProfileCreated
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- SetUpCommandLine
- IN_PROC_BROWSER_TEST_F
- SetUpUserDataDirectory
- IN_PROC_BROWSER_TEST_F
#include "chrome/browser/ui/app_list/app_list_service.h"
#include "base/command_line.h"
#include "base/json/json_file_value_serializer.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
#include "chrome/browser/ui/app_list/test/chrome_app_list_test_support.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.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 "ui/app_list/app_list_model.h"
#include "ui/app_list/search_box_model.h"
class AppListServiceInteractiveTest : public InProcessBrowserTest {
public:
AppListServiceInteractiveTest()
: profile2_(NULL) {}
void InitSecondProfile() {
ProfileManager* profile_manager = g_browser_process->profile_manager();
base::FilePath temp_profile_dir =
profile_manager->user_data_dir().AppendASCII("Profile 1");
profile_manager->CreateProfileAsync(
temp_profile_dir,
base::Bind(&AppListServiceInteractiveTest::OnProfileCreated,
this),
base::string16(), base::string16(), std::string());
content::RunMessageLoop();
}
void OnProfileCreated(Profile* profile, Profile::CreateStatus status) {
if (status == Profile::CREATE_STATUS_INITIALIZED) {
profile2_ = profile;
base::MessageLoop::current()->Quit();
}
}
protected:
Profile* profile2_;
private:
DISALLOW_COPY_AND_ASSIGN(AppListServiceInteractiveTest);
};
#if defined(OS_CHROMEOS)
#define MAYBE_ShowAndDismiss DISABLED_ShowAndDismiss
#define MAYBE_SwitchAppListProfiles DISABLED_SwitchAppListProfiles
#define MAYBE_SwitchAppListProfilesDuringSearch \
DISABLED_SwitchAppListProfilesDuringSearch
#define MAYBE_ShowAppListNonDefaultProfile \
DISABLED_ShowAppListNonDefaultProfile
#else
#define MAYBE_ShowAndDismiss ShowAndDismiss
#define MAYBE_SwitchAppListProfiles SwitchAppListProfiles
#define MAYBE_SwitchAppListProfilesDuringSearch \
SwitchAppListProfilesDuringSearch
#define MAYBE_ShowAppListNonDefaultProfile ShowAppListNonDefaultProfile
#endif
IN_PROC_BROWSER_TEST_F(AppListServiceInteractiveTest, MAYBE_ShowAndDismiss) {
AppListService* service = test::GetAppListService();
ASSERT_FALSE(service->IsAppListVisible());
service->ShowForProfile(browser()->profile());
ASSERT_TRUE(service->IsAppListVisible());
service->DismissAppList();
ASSERT_FALSE(service->IsAppListVisible());
}
IN_PROC_BROWSER_TEST_F(AppListServiceInteractiveTest,
MAYBE_SwitchAppListProfiles) {
InitSecondProfile();
test::SigninProfile(browser()->profile());
test::SigninProfile(profile2_);
AppListService* service = test::GetAppListService();
ASSERT_TRUE(service);
AppListControllerDelegate* controller(service->GetControllerDelegate());
ASSERT_TRUE(controller);
ASSERT_FALSE(service->IsAppListVisible());
controller->ShowForProfileByPath(browser()->profile()->GetPath());
app_list::AppListModel* model = test::GetAppListModel(service);
ASSERT_TRUE(model);
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(service->IsAppListVisible());
ASSERT_EQ(browser()->profile(), service->GetCurrentAppListProfile());
controller->ShowForProfileByPath(profile2_->GetPath());
model = test::GetAppListModel(service);
ASSERT_TRUE(model);
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(service->IsAppListVisible());
ASSERT_EQ(profile2_, service->GetCurrentAppListProfile());
controller->DismissView();
}
IN_PROC_BROWSER_TEST_F(AppListServiceInteractiveTest,
MAYBE_SwitchAppListProfilesDuringSearch) {
InitSecondProfile();
test::SigninProfile(browser()->profile());
test::SigninProfile(profile2_);
AppListService* service = test::GetAppListService();
ASSERT_TRUE(service);
AppListControllerDelegate* controller(service->GetControllerDelegate());
ASSERT_TRUE(controller);
controller->ShowForProfileByPath(browser()->profile()->GetPath());
app_list::AppListModel* model = test::GetAppListModel(service);
ASSERT_TRUE(model);
model->search_box()->SetText(base::ASCIIToUTF16("minimal"));
base::RunLoop().RunUntilIdle();
controller->ShowForProfileByPath(profile2_->GetPath());
model = test::GetAppListModel(service);
ASSERT_TRUE(model);
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(model->search_box()->text().empty());
ASSERT_EQ(profile2_, service->GetCurrentAppListProfile());
controller->DismissView();
ASSERT_FALSE(service->IsAppListVisible());
}
class ShowAppListInteractiveTest : public InProcessBrowserTest {
public:
ShowAppListInteractiveTest() {}
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
command_line->AppendSwitch(switches::kShowAppList);
}
private:
DISALLOW_COPY_AND_ASSIGN(ShowAppListInteractiveTest);
};
IN_PROC_BROWSER_TEST_F(ShowAppListInteractiveTest, ShowAppListFlag) {
AppListService* service = test::GetAppListService();
ASSERT_TRUE(service->IsAppListVisible());
CreateBrowser(service->GetCurrentAppListProfile());
service->DismissAppList();
}
class ShowAppListNonDefaultInteractiveTest : public ShowAppListInteractiveTest {
public:
ShowAppListNonDefaultInteractiveTest()
: second_profile_name_(FILE_PATH_LITERAL("Profile 1")) {
}
virtual bool SetUpUserDataDirectory() OVERRIDE {
base::FilePath user_data_dir;
CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir));
base::FilePath profile_path = user_data_dir.Append(second_profile_name_);
CHECK(second_profile_temp_dir_.Set(profile_path));
base::FilePath local_pref_path =
user_data_dir.Append(chrome::kLocalStateFilename);
base::DictionaryValue dict;
dict.SetString(prefs::kAppListProfile,
second_profile_name_.MaybeAsASCII());
CHECK(JSONFileValueSerializer(local_pref_path).Serialize(dict));
return InProcessBrowserTest::SetUpUserDataDirectory();
}
protected:
const base::FilePath second_profile_name_;
base::ScopedTempDir second_profile_temp_dir_;
private:
DISALLOW_COPY_AND_ASSIGN(ShowAppListNonDefaultInteractiveTest);
};
IN_PROC_BROWSER_TEST_F(ShowAppListNonDefaultInteractiveTest,
MAYBE_ShowAppListNonDefaultProfile) {
AppListService* service = test::GetAppListService();
EXPECT_TRUE(service->IsAppListVisible());
EXPECT_EQ(second_profile_name_.value(),
service->GetCurrentAppListProfile()->GetPath().BaseName().value());
ProfileManager* profile_manager = g_browser_process->profile_manager();
EXPECT_EQ(1u, profile_manager->GetNumberOfProfiles());
CreateBrowser(profile_manager->GetLastUsedProfile());
EXPECT_EQ(2u, profile_manager->GetNumberOfProfiles());
service->DismissAppList();
}