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/files/scoped_temp_dir.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/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/strings/utf_string_conversions.h" | |
10 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/extensions/extension_browsertest.h" | |
11 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
13 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | 16 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
14 #include "chrome/browser/ui/app_list/app_list_service.h" | 17 #include "chrome/browser/ui/app_list/app_list_service.h" |
18 #include "chrome/browser/ui/app_list/test/app_list_service_test_api.h" | |
15 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/browser_finder.h" | 20 #include "chrome/browser/ui/browser_finder.h" |
17 #include "chrome/browser/ui/host_desktop.h" | 21 #include "chrome/browser/ui/host_desktop.h" |
22 #include "chrome/common/chrome_paths.h" | |
18 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
20 #include "chrome/test/base/in_process_browser_test.h" | 25 #include "chrome/test/base/in_process_browser_test.h" |
21 #include "chrome/test/base/ui_test_utils.h" | 26 #include "chrome/test/base/ui_test_utils.h" |
27 #include "ui/app_list/app_list_model.h" | |
28 #include "ui/app_list/search_box_model.h" | |
29 #include "ui/app_list/search_result.h" | |
30 #include "ui/app_list/search_result_observer.h" | |
31 #include "ui/base/models/list_model_observer.h" | |
32 | |
33 namespace { | |
22 | 34 |
23 // Browser Test for AppListController that runs on all platforms supporting | 35 // Browser Test for AppListController that runs on all platforms supporting |
24 // app_list. | 36 // app_list. |
25 class AppListControllerBrowserTest : public InProcessBrowserTest { | 37 class AppListControllerBrowserTest : public InProcessBrowserTest { |
26 public: | 38 public: |
27 AppListControllerBrowserTest() | 39 AppListControllerBrowserTest() |
28 : profile2_(NULL) {} | 40 : profile2_(NULL) {} |
29 | 41 |
30 void OnProfileCreated(Profile* profile, Profile::CreateStatus status) { | 42 void OnProfileCreated(Profile* profile, Profile::CreateStatus status) { |
31 if (status == Profile::CREATE_STATUS_INITIALIZED) { | 43 if (status == Profile::CREATE_STATUS_INITIALIZED) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 // switches::kShowAppList. | 125 // switches::kShowAppList. |
114 ASSERT_TRUE(service->IsAppListVisible()); | 126 ASSERT_TRUE(service->IsAppListVisible()); |
115 | 127 |
116 // Create a browser to prevent shutdown when we dismiss the app list. We | 128 // Create a browser to prevent shutdown when we dismiss the app list. We |
117 // need to do this because switches::kShowAppList suppresses the creation of | 129 // need to do this because switches::kShowAppList suppresses the creation of |
118 // any browsers. | 130 // any browsers. |
119 CreateBrowser(service->GetCurrentAppListProfile()); | 131 CreateBrowser(service->GetCurrentAppListProfile()); |
120 service->DismissAppList(); | 132 service->DismissAppList(); |
121 } | 133 } |
122 #endif // !defined(OS_CHROMEOS) | 134 #endif // !defined(OS_CHROMEOS) |
135 | |
136 // Browser Test for AppListController that observes search result changes. | |
137 class AppListControllerSearchResultsBrowserTest | |
138 : public ExtensionBrowserTest, | |
139 public app_list::SearchResultObserver, | |
140 public ui::ListModelObserver { | |
141 public: | |
142 AppListControllerSearchResultsBrowserTest() | |
143 : observed_result_(NULL), | |
144 item_uninstall_count_(0), | |
145 observed_results_list_(NULL) {} | |
146 | |
147 void WatchResultsLookingForItem( | |
148 app_list::AppListModel::SearchResults* search_results, | |
149 const std::string& extension_name) { | |
150 EXPECT_FALSE(observed_results_list_); | |
151 observed_results_list_ = search_results; | |
152 observed_results_list_->AddObserver(this); | |
153 item_to_observe_ = ASCIIToUTF16(extension_name); | |
154 } | |
155 | |
156 void StopWatchingResults() { | |
157 EXPECT_TRUE(observed_results_list_); | |
158 observed_results_list_->RemoveObserver(this); | |
159 } | |
160 | |
161 protected: | |
162 void Update() { | |
163 if (observed_result_) { | |
164 observed_result_->RemoveObserver(this); | |
165 observed_result_ = NULL; | |
166 } | |
167 | |
168 for (size_t i = 0; i < observed_results_list_->item_count(); ++i) { | |
169 if (observed_results_list_->GetItemAt(i)->title() != item_to_observe_) | |
170 continue; | |
171 | |
172 // Ensure there is at most one. | |
173 EXPECT_FALSE(observed_result_); | |
174 observed_result_ = observed_results_list_->GetItemAt(i); | |
175 } | |
176 | |
177 if (observed_result_) | |
178 observed_result_->AddObserver(this); | |
179 } | |
180 | |
181 // Overridden from SearchResultObserver: | |
182 virtual void OnIconChanged() OVERRIDE {} | |
183 virtual void OnActionsChanged() OVERRIDE {} | |
184 virtual void OnIsInstallingChanged() OVERRIDE {} | |
185 virtual void OnPercentDownloadedChanged() OVERRIDE {} | |
186 virtual void OnItemInstalled() OVERRIDE {} | |
187 virtual void OnItemUninstalled() OVERRIDE { | |
188 ++item_uninstall_count_; | |
189 EXPECT_TRUE(observed_result_); | |
190 } | |
191 | |
192 // Overridden from ui::ListModelObserver: | |
193 virtual void ListItemsAdded(size_t start, size_t count) OVERRIDE { Update(); } | |
koz (OOO until 15th September)
2013/08/30 00:12:42
nit: Update() -> AttemptToLocateItem()
tapted
2013/08/30 00:54:40
Done.
| |
194 virtual void ListItemsRemoved(size_t start, size_t count) OVERRIDE { | |
195 Update(); | |
196 } | |
197 virtual void ListItemMoved(size_t index, size_t target_index) OVERRIDE {} | |
198 virtual void ListItemsChanged(size_t start, size_t count) OVERRIDE {} | |
199 | |
200 app_list::SearchResult* observed_result_; | |
201 int item_uninstall_count_; | |
202 | |
203 private: | |
204 base::string16 item_to_observe_; | |
205 app_list::AppListModel::SearchResults* observed_results_list_; | |
206 | |
207 DISALLOW_COPY_AND_ASSIGN(AppListControllerSearchResultsBrowserTest); | |
208 }; | |
209 | |
210 // Test showing search results, and uninstalling one of them while displayed. | |
211 IN_PROC_BROWSER_TEST_F(AppListControllerSearchResultsBrowserTest, | |
212 UninstallSearchResult) { | |
213 base::FilePath test_extension_path; | |
214 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_extension_path)); | |
215 test_extension_path = test_extension_path.AppendASCII("extensions") | |
216 .AppendASCII("platform_apps") | |
217 .AppendASCII("minimal"); | |
218 const extensions::Extension* extension = | |
219 InstallExtension(test_extension_path, | |
220 1 /* expected_change: new install */); | |
221 ASSERT_TRUE(extension); | |
222 | |
223 AppListService* service = AppListService::Get(); | |
224 scoped_ptr<test::AppListServiceTestApi> test_api( | |
225 test::AppListServiceTestApi::Create(chrome::HOST_DESKTOP_TYPE_NATIVE)); | |
226 ASSERT_TRUE(service); | |
227 ASSERT_TRUE(test_api); | |
228 service->ShowForProfile(browser()->profile()); | |
229 | |
230 app_list::AppListModel* model = test_api->GetAppListModel(); | |
231 ASSERT_TRUE(model); | |
232 model->SetSignedIn(true); | |
233 WatchResultsLookingForItem(model->results(), extension->name()); | |
234 | |
235 // Ensure a search finds the extension. | |
236 EXPECT_FALSE(observed_result_); | |
237 model->search_box()->SetText(ASCIIToUTF16("minimal")); | |
238 EXPECT_TRUE(observed_result_); | |
239 | |
240 // Ensure the UI is updated. This is via PostTask in views. | |
241 base::RunLoop().RunUntilIdle(); | |
242 | |
243 // Now uninstall and ensure this browser test observes it. | |
244 EXPECT_EQ(0, item_uninstall_count_); | |
245 UninstallExtension(extension->id()); | |
246 | |
247 // TODO(tapted): This should only see one notification. Currently it sees two. | |
248 // See http://crbug.com/277897 . | |
249 EXPECT_EQ(2, item_uninstall_count_); | |
250 | |
251 // Results should not be immediately refreshed. When they are, the item should | |
252 // be removed from the model. | |
253 EXPECT_TRUE(observed_result_); | |
254 base::RunLoop().RunUntilIdle(); | |
255 EXPECT_FALSE(observed_result_); | |
256 StopWatchingResults(); | |
257 service->DismissAppList(); | |
258 } | |
259 | |
260 } // namespace | |
OLD | NEW |