Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/files/scoped_temp_dir.h" | 6 #include "base/file_util.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/extensions/extension_browsertest.h" | 13 #include "chrome/browser/extensions/extension_browsertest.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | 16 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 // Browser Test for AppListController that runs on all platforms supporting | 35 // Browser Test for AppListController that runs on all platforms supporting |
| 36 // app_list. | 36 // app_list. |
| 37 class AppListControllerBrowserTest : public InProcessBrowserTest { | 37 class AppListControllerBrowserTest : public InProcessBrowserTest { |
| 38 public: | 38 public: |
| 39 AppListControllerBrowserTest() | 39 AppListControllerBrowserTest() |
| 40 : profile2_(NULL) {} | 40 : profile2_(NULL) {} |
| 41 | 41 |
| 42 void InitSecondProfile() { | |
| 43 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
| 44 base::FilePath temp_profile_dir = | |
| 45 profile_manager->user_data_dir().AppendASCII("Profile 1"); | |
| 46 profile_manager->CreateProfileAsync( | |
|
tapted
2013/09/16 20:46:44
Will the path created by this call get deleted whe
calamity
2013/09/17 00:09:26
user_data_dir is a scoped_temp_dir and those are d
| |
| 47 temp_profile_dir, | |
| 48 base::Bind(&AppListControllerBrowserTest::OnProfileCreated, | |
| 49 this), | |
| 50 string16(), string16(), std::string()); | |
| 51 content::RunMessageLoop(); // Will stop in OnProfileCreated(). | |
| 52 } | |
| 53 | |
| 42 void OnProfileCreated(Profile* profile, Profile::CreateStatus status) { | 54 void OnProfileCreated(Profile* profile, Profile::CreateStatus status) { |
| 43 if (status == Profile::CREATE_STATUS_INITIALIZED) { | 55 if (status == Profile::CREATE_STATUS_INITIALIZED) { |
| 44 profile2_ = profile; | 56 profile2_ = profile; |
| 45 base::MessageLoop::current()->Quit(); | 57 base::MessageLoop::current()->Quit(); |
| 46 } | 58 } |
| 47 } | 59 } |
| 48 | 60 |
| 49 protected: | 61 protected: |
| 50 base::ScopedTempDir temp_profile_dir_; | |
| 51 Profile* profile2_; | 62 Profile* profile2_; |
| 52 | 63 |
| 53 private: | 64 private: |
| 54 DISALLOW_COPY_AND_ASSIGN(AppListControllerBrowserTest); | 65 DISALLOW_COPY_AND_ASSIGN(AppListControllerBrowserTest); |
| 55 }; | 66 }; |
| 56 | 67 |
| 57 // Test the CreateNewWindow function of the controller delegate. | 68 // Test the CreateNewWindow function of the controller delegate. |
| 58 IN_PROC_BROWSER_TEST_F(AppListControllerBrowserTest, CreateNewWindow) { | 69 IN_PROC_BROWSER_TEST_F(AppListControllerBrowserTest, CreateNewWindow) { |
| 59 const chrome::HostDesktopType desktop = chrome::GetActiveDesktop(); | 70 const chrome::HostDesktopType desktop = chrome::GetActiveDesktop(); |
| 60 AppListService* service = AppListService::Get(); | 71 AppListService* service = AppListService::Get(); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 79 IN_PROC_BROWSER_TEST_F(AppListControllerBrowserTest, ShowAndDismiss) { | 90 IN_PROC_BROWSER_TEST_F(AppListControllerBrowserTest, ShowAndDismiss) { |
| 80 AppListService* service = AppListService::Get(); | 91 AppListService* service = AppListService::Get(); |
| 81 ASSERT_FALSE(service->IsAppListVisible()); | 92 ASSERT_FALSE(service->IsAppListVisible()); |
| 82 service->ShowForProfile(browser()->profile()); | 93 service->ShowForProfile(browser()->profile()); |
| 83 ASSERT_TRUE(service->IsAppListVisible()); | 94 ASSERT_TRUE(service->IsAppListVisible()); |
| 84 service->DismissAppList(); | 95 service->DismissAppList(); |
| 85 ASSERT_FALSE(service->IsAppListVisible()); | 96 ASSERT_FALSE(service->IsAppListVisible()); |
| 86 } | 97 } |
| 87 | 98 |
| 88 IN_PROC_BROWSER_TEST_F(AppListControllerBrowserTest, SwitchAppListProfiles) { | 99 IN_PROC_BROWSER_TEST_F(AppListControllerBrowserTest, SwitchAppListProfiles) { |
| 89 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 100 InitSecondProfile(); |
| 90 ASSERT_TRUE(temp_profile_dir_.CreateUniqueTempDir()); | |
| 91 profile_manager->CreateProfileAsync( | |
| 92 temp_profile_dir_.path(), | |
| 93 base::Bind(&AppListControllerBrowserTest::OnProfileCreated, | |
| 94 this), | |
| 95 string16(), string16(), std::string()); | |
| 96 content::RunMessageLoop(); // Will stop in OnProfileCreated(). | |
| 97 | 101 |
| 98 AppListService* service = AppListService::Get(); | 102 AppListService* service = AppListService::Get(); |
| 103 scoped_ptr<test::AppListServiceTestApi> test_api( | |
| 104 test::AppListServiceTestApi::Create(chrome::HOST_DESKTOP_TYPE_NATIVE)); | |
| 105 ASSERT_TRUE(service); | |
| 106 ASSERT_TRUE(test_api); | |
| 107 | |
| 108 scoped_ptr<AppListControllerDelegate> controller( | |
| 109 service->CreateControllerDelegate()); | |
| 110 ASSERT_TRUE(controller); | |
| 111 | |
| 112 // Open the app list with the browser's profile. | |
| 99 ASSERT_FALSE(service->IsAppListVisible()); | 113 ASSERT_FALSE(service->IsAppListVisible()); |
| 100 service->ShowForProfile(browser()->profile()); | 114 controller->ShowForProfileByPath(browser()->profile()->GetPath()); |
| 115 app_list::AppListModel* model = test_api->GetAppListModel(); | |
| 116 ASSERT_TRUE(model); | |
| 117 model->SetSignedIn(true); | |
| 118 base::RunLoop().RunUntilIdle(); | |
| 119 | |
| 101 ASSERT_TRUE(service->IsAppListVisible()); | 120 ASSERT_TRUE(service->IsAppListVisible()); |
| 102 ASSERT_EQ(browser()->profile(), service->GetCurrentAppListProfile()); | 121 ASSERT_EQ(browser()->profile(), service->GetCurrentAppListProfile()); |
| 103 service->ShowForProfile(profile2_); | 122 |
| 123 // Open the app list with the second profile. | |
| 124 controller->ShowForProfileByPath(profile2_->GetPath()); | |
| 125 model = test_api->GetAppListModel(); | |
| 126 ASSERT_TRUE(model); | |
| 127 model->SetSignedIn(true); | |
| 128 base::RunLoop().RunUntilIdle(); | |
| 129 | |
| 104 ASSERT_TRUE(service->IsAppListVisible()); | 130 ASSERT_TRUE(service->IsAppListVisible()); |
| 105 ASSERT_EQ(profile2_, service->GetCurrentAppListProfile()); | 131 ASSERT_EQ(profile2_, service->GetCurrentAppListProfile()); |
| 106 service->DismissAppList(); | 132 |
| 133 controller->DismissView(); | |
| 134 } | |
| 135 | |
| 136 IN_PROC_BROWSER_TEST_F(AppListControllerBrowserTest, | |
| 137 SwitchAppListProfilesDuringSearch) { | |
|
tapted
2013/09/16 20:46:44
This shouldn't be appearing anew in the diff - you
| |
| 138 InitSecondProfile(); | |
| 139 | |
| 140 AppListService* service = AppListService::Get(); | |
| 141 scoped_ptr<test::AppListServiceTestApi> test_api( | |
| 142 test::AppListServiceTestApi::Create(chrome::HOST_DESKTOP_TYPE_NATIVE)); | |
| 143 ASSERT_TRUE(service); | |
| 144 ASSERT_TRUE(test_api); | |
| 145 | |
| 146 scoped_ptr<AppListControllerDelegate> controller( | |
| 147 service->CreateControllerDelegate()); | |
| 148 ASSERT_TRUE(controller); | |
| 149 | |
| 150 // Set a search with original profile. | |
| 151 controller->ShowForProfileByPath(browser()->profile()->GetPath()); | |
| 152 app_list::AppListModel* model = test_api->GetAppListModel(); | |
| 153 ASSERT_TRUE(model); | |
| 154 model->SetSignedIn(true); | |
| 155 model->search_box()->SetText(ASCIIToUTF16("minimal")); | |
| 156 base::RunLoop().RunUntilIdle(); | |
| 157 | |
| 158 // Switch to the second profile. | |
| 159 controller->ShowForProfileByPath(profile2_->GetPath()); | |
| 160 model = test_api->GetAppListModel(); | |
| 161 ASSERT_TRUE(model); | |
| 162 model->SetSignedIn(true); | |
| 163 base::RunLoop().RunUntilIdle(); | |
| 164 | |
| 165 // Ensure the search box is empty. | |
| 166 ASSERT_TRUE(model->search_box()->text().empty()); | |
| 167 ASSERT_EQ(profile2_, service->GetCurrentAppListProfile()); | |
| 168 | |
| 169 controller->DismissView(); | |
| 107 ASSERT_FALSE(service->IsAppListVisible()); | 170 ASSERT_FALSE(service->IsAppListVisible()); |
| 108 } | 171 } |
| 109 | 172 |
| 110 class ShowAppListBrowserTest : public InProcessBrowserTest { | 173 class ShowAppListBrowserTest : public InProcessBrowserTest { |
| 111 public: | 174 public: |
| 112 ShowAppListBrowserTest() {} | 175 ShowAppListBrowserTest() {} |
| 113 | 176 |
| 114 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 177 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 115 command_line->AppendSwitch(switches::kShowAppList); | 178 command_line->AppendSwitch(switches::kShowAppList); |
| 116 } | 179 } |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 // Results should not be immediately refreshed. When they are, the item should | 313 // Results should not be immediately refreshed. When they are, the item should |
| 251 // be removed from the model. | 314 // be removed from the model. |
| 252 EXPECT_TRUE(observed_result_); | 315 EXPECT_TRUE(observed_result_); |
| 253 base::RunLoop().RunUntilIdle(); | 316 base::RunLoop().RunUntilIdle(); |
| 254 EXPECT_FALSE(observed_result_); | 317 EXPECT_FALSE(observed_result_); |
| 255 StopWatchingResults(); | 318 StopWatchingResults(); |
| 256 service->DismissAppList(); | 319 service->DismissAppList(); |
| 257 } | 320 } |
| 258 | 321 |
| 259 } // namespace | 322 } // namespace |
| OLD | NEW |