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

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: reorder accessor, fix destructor in browser_test -- runs too late for win 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
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"
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
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_result_(NULL),
143 item_uninstall_count_(0),
144 observed_results_list_(NULL) {}
145
146 void WatchResultsLookingForItem(
147 app_list::AppListModel::SearchResults* search_results,
148 const std::string& extension_name) {
149 EXPECT_FALSE(observed_results_list_);
150 observed_results_list_ = search_results;
151 observed_results_list_->AddObserver(this);
152 item_to_observe_ = ASCIIToUTF16(extension_name);
153 }
154
155 void StopWatchingResults() {
tapted 2013/08/28 07:23:14 note: moved this from the destructor and it's call
156 EXPECT_TRUE(observed_results_list_);
157 observed_results_list_->RemoveObserver(this);
158 }
159
160 protected:
161 void Update() {
162 if (observed_result_) {
163 observed_result_->RemoveObserver(this);
164 observed_result_ = NULL;
165 }
166
167 for (size_t i = 0; i < observed_results_list_->item_count(); ++i) {
168 if (observed_results_list_->GetItemAt(i)->title() != item_to_observe_)
169 continue;
170
171 // Ensure there is at most one.
172 EXPECT_FALSE(observed_result_);
173 observed_result_ = observed_results_list_->GetItemAt(i);
174 }
175
176 if (observed_result_)
177 observed_result_->AddObserver(this);
178 }
179
180 // Overridden from SearchResultObserver:
181 virtual void OnIconChanged() OVERRIDE {}
182 virtual void OnActionsChanged() OVERRIDE {}
183 virtual void OnIsInstallingChanged() OVERRIDE {}
184 virtual void OnPercentDownloadedChanged() OVERRIDE {}
185 virtual void OnItemInstalled() OVERRIDE {}
186 virtual void OnItemUninstalled() OVERRIDE {
187 ++item_uninstall_count_;
188 EXPECT_TRUE(observed_result_);
189 }
190
191 // Overridden from ui::ListModelObserver:
192 virtual void ListItemsAdded(size_t start, size_t count) OVERRIDE { Update(); }
193 virtual void ListItemsRemoved(size_t start, size_t count) OVERRIDE {
194 Update();
195 }
196 virtual void ListItemMoved(size_t index, size_t target_index) OVERRIDE {}
197 virtual void ListItemsChanged(size_t start, size_t count) OVERRIDE {}
198
199 app_list::SearchResult* observed_result_;
200 int item_uninstall_count_;
201
202 private:
203 base::string16 item_to_observe_;
204 app_list::AppListModel::SearchResults* observed_results_list_;
205
206 DISALLOW_COPY_AND_ASSIGN(AppListControllerSearchResultsBrowserTest);
207 };
208
209 // Test showing search results, and uninstalling one of them while displayed.
210 IN_PROC_BROWSER_TEST_F(AppListControllerSearchResultsBrowserTest,
211 UninstallSearchResult) {
212 base::FilePath test_extension_path;
213 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_extension_path));
214 test_extension_path = test_extension_path.AppendASCII("extensions")
215 .AppendASCII("platform_apps")
216 .AppendASCII("minimal");
217 const extensions::Extension* extension =
218 InstallExtension(test_extension_path,
219 1 /* expected_change: new install */);
220 ASSERT_TRUE(extension);
221
222 AppListService* service = AppListService::Get();
223 ASSERT_TRUE(service);
224 service->ShowForProfile(browser()->profile());
225
226 app_list::AppListModel* model = service->GetAppListModelForTesting();
227 ASSERT_TRUE(model);
228 model->SetSignedIn(true);
229 WatchResultsLookingForItem(model->results(), extension->name());
230
231 // Ensure a search finds the extension.
232 EXPECT_FALSE(observed_result_);
233 model->search_box()->SetText(ASCIIToUTF16("minimal"));
234 EXPECT_TRUE(observed_result_);
235
236 // Ensure the UI is updated. This is via PostTask in views.
237 base::RunLoop().RunUntilIdle();
238
239 // Now uninstall and ensure this browser test observes it.
240 EXPECT_EQ(0, item_uninstall_count_);
241 UninstallExtension(extension->id());
242
243 // TODO(tapted): This should only see one notification. Currently it sees two.
244 // See http://crbug.com/277897 .
245 EXPECT_EQ(2, item_uninstall_count_);
246
247 // Results should not be immediately refreshed. When they are, the item should
248 // be removed from the model.
249 EXPECT_TRUE(observed_result_);
250 base::RunLoop().RunUntilIdle();
251 EXPECT_FALSE(observed_result_);
252 StopWatchingResults();
253 service->DismissAppList();
254 }
255
256 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698