Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Side by Side Diff: chrome/browser/ui/app_list/app_list_controller_browsertest.cc

Issue 23072036: Adds an integration test for uninstalling app list search results. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/wm/app_list_controller.h ('k') | chrome/browser/ui/app_list/app_list_service_mac.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 AttemptToLocateItem() {
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 {
194 AttemptToLocateItem();
195 }
196 virtual void ListItemsRemoved(size_t start, size_t count) OVERRIDE {
197 AttemptToLocateItem();
198 }
199 virtual void ListItemMoved(size_t index, size_t target_index) OVERRIDE {}
200 virtual void ListItemsChanged(size_t start, size_t count) OVERRIDE {}
201
202 app_list::SearchResult* observed_result_;
203 int item_uninstall_count_;
204
205 private:
206 base::string16 item_to_observe_;
207 app_list::AppListModel::SearchResults* observed_results_list_;
208
209 DISALLOW_COPY_AND_ASSIGN(AppListControllerSearchResultsBrowserTest);
210 };
211
212 // Test showing search results, and uninstalling one of them while displayed.
213 IN_PROC_BROWSER_TEST_F(AppListControllerSearchResultsBrowserTest,
214 UninstallSearchResult) {
215 base::FilePath test_extension_path;
216 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_extension_path));
217 test_extension_path = test_extension_path.AppendASCII("extensions")
218 .AppendASCII("platform_apps")
219 .AppendASCII("minimal");
220 const extensions::Extension* extension =
221 InstallExtension(test_extension_path,
222 1 /* expected_change: new install */);
223 ASSERT_TRUE(extension);
224
225 AppListService* service = AppListService::Get();
226 scoped_ptr<test::AppListServiceTestApi> test_api(
227 test::AppListServiceTestApi::Create(chrome::HOST_DESKTOP_TYPE_NATIVE));
228 ASSERT_TRUE(service);
229 ASSERT_TRUE(test_api);
230 service->ShowForProfile(browser()->profile());
231
232 app_list::AppListModel* model = test_api->GetAppListModel();
233 ASSERT_TRUE(model);
234 model->SetSignedIn(true);
235 WatchResultsLookingForItem(model->results(), extension->name());
236
237 // Ensure a search finds the extension.
238 EXPECT_FALSE(observed_result_);
239 model->search_box()->SetText(ASCIIToUTF16("minimal"));
240 EXPECT_TRUE(observed_result_);
241
242 // Ensure the UI is updated. This is via PostTask in views.
243 base::RunLoop().RunUntilIdle();
244
245 // Now uninstall and ensure this browser test observes it.
246 EXPECT_EQ(0, item_uninstall_count_);
247 UninstallExtension(extension->id());
248 EXPECT_EQ(1, item_uninstall_count_);
249
250 // Results should not be immediately refreshed. When they are, the item should
251 // be removed from the model.
252 EXPECT_TRUE(observed_result_);
253 base::RunLoop().RunUntilIdle();
254 EXPECT_FALSE(observed_result_);
255 StopWatchingResults();
256 service->DismissAppList();
257 }
258
259 } // namespace
OLDNEW
« no previous file with comments | « ash/wm/app_list_controller.h ('k') | chrome/browser/ui/app_list/app_list_service_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698