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