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

Side by Side Diff: ash/launcher/launcher_view_unittest.cc

Issue 25823002: Refactor LauncherItemController and LauncherItemDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 2 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ash/launcher/launcher_view.h" 5 #include "ash/launcher/launcher_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/ash_switches.h" 10 #include "ash/ash_switches.h"
11 #include "ash/launcher/launcher.h" 11 #include "ash/launcher/launcher.h"
12 #include "ash/launcher/launcher_button.h" 12 #include "ash/launcher/launcher_button.h"
13 #include "ash/launcher/launcher_icon_observer.h" 13 #include "ash/launcher/launcher_icon_observer.h"
14 #include "ash/launcher/launcher_item_delegate_manager.h"
14 #include "ash/launcher/launcher_model.h" 15 #include "ash/launcher/launcher_model.h"
15 #include "ash/launcher/launcher_types.h" 16 #include "ash/launcher/launcher_types.h"
16 #include "ash/root_window_controller.h" 17 #include "ash/root_window_controller.h"
17 #include "ash/shelf/shelf_layout_manager.h" 18 #include "ash/shelf/shelf_layout_manager.h"
18 #include "ash/shelf/shelf_tooltip_manager.h" 19 #include "ash/shelf/shelf_tooltip_manager.h"
19 #include "ash/shelf/shelf_widget.h" 20 #include "ash/shelf/shelf_widget.h"
20 #include "ash/shell.h" 21 #include "ash/shell.h"
21 #include "ash/shell_window_ids.h" 22 #include "ash/shell_window_ids.h"
22 #include "ash/test/ash_test_base.h" 23 #include "ash/test/ash_test_base.h"
23 #include "ash/test/launcher_test_api.h" 24 #include "ash/test/launcher_test_api.h"
24 #include "ash/test/launcher_view_test_api.h" 25 #include "ash/test/launcher_view_test_api.h"
25 #include "ash/test/shell_test_api.h" 26 #include "ash/test/shell_test_api.h"
26 #include "ash/test/test_launcher_delegate.h" 27 #include "ash/test/test_launcher_delegate.h"
28 #include "ash/test/test_launcher_item_delegate.h"
27 #include "base/basictypes.h" 29 #include "base/basictypes.h"
28 #include "base/command_line.h" 30 #include "base/command_line.h"
29 #include "base/compiler_specific.h" 31 #include "base/compiler_specific.h"
30 #include "base/memory/scoped_ptr.h" 32 #include "base/memory/scoped_ptr.h"
31 #include "grit/ash_resources.h" 33 #include "grit/ash_resources.h"
32 #include "ui/aura/root_window.h" 34 #include "ui/aura/root_window.h"
33 #include "ui/aura/test/aura_test_base.h" 35 #include "ui/aura/test/aura_test_base.h"
34 #include "ui/aura/test/event_generator.h" 36 #include "ui/aura/test/event_generator.h"
35 #include "ui/aura/window.h" 37 #include "ui/aura/window.h"
36 #include "ui/base/l10n/l10n_util.h" 38 #include "ui/base/l10n/l10n_util.h"
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 Launcher* launcher = Launcher::ForPrimaryDisplay(); 208 Launcher* launcher = Launcher::ForPrimaryDisplay();
207 launcher_view_ = test::LauncherTestAPI(launcher).launcher_view(); 209 launcher_view_ = test::LauncherTestAPI(launcher).launcher_view();
208 210
209 // The bounds should be big enough for 4 buttons + overflow chevron. 211 // The bounds should be big enough for 4 buttons + overflow chevron.
210 launcher_view_->SetBounds(0, 0, 500, 212 launcher_view_->SetBounds(0, 0, 500,
211 internal::ShelfLayoutManager::GetPreferredShelfSize()); 213 internal::ShelfLayoutManager::GetPreferredShelfSize());
212 214
213 test_api_.reset(new LauncherViewTestAPI(launcher_view_)); 215 test_api_.reset(new LauncherViewTestAPI(launcher_view_));
214 test_api_->SetAnimationDuration(1); // Speeds up animation for test. 216 test_api_->SetAnimationDuration(1); // Speeds up animation for test.
215 217
218 item_manager_ =
219 ash::Shell::GetInstance()->launcher_item_delegate_manager();
220 DCHECK(item_manager_);
221
216 // Add browser shortcut launcher item at index 0 for test. 222 // Add browser shortcut launcher item at index 0 for test.
217 AddBrowserShortcut(); 223 AddBrowserShortcut();
218 } 224 }
219 225
220 virtual void TearDown() OVERRIDE { 226 virtual void TearDown() OVERRIDE {
221 test_api_.reset(); 227 test_api_.reset();
222 AshTestBase::TearDown(); 228 AshTestBase::TearDown();
223 } 229 }
224 230
225 protected: 231 protected:
232 void CreateAndSetLauncherItemDelegateForID(LauncherID id) {
233 scoped_ptr<LauncherItemDelegate> delegate(
234 new ash::test::TestLauncherItemDelegate(NULL));
235 item_manager_->SetLauncherItemDelegate(id, delegate.Pass());
236 }
237
226 LauncherID AddBrowserShortcut() { 238 LauncherID AddBrowserShortcut() {
227 LauncherItem browser_shortcut; 239 LauncherItem browser_shortcut;
228 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; 240 browser_shortcut.type = TYPE_BROWSER_SHORTCUT;
229 241
230 LauncherID id = model_->next_id(); 242 LauncherID id = model_->next_id();
231 model_->AddAt(browser_index_, browser_shortcut); 243 model_->AddAt(browser_index_, browser_shortcut);
244 CreateAndSetLauncherItemDelegateForID(id);
232 test_api_->RunMessageLoopUntilAnimationsDone(); 245 test_api_->RunMessageLoopUntilAnimationsDone();
233 return id; 246 return id;
234 } 247 }
235 248
236 LauncherID AddAppShortcut() { 249 LauncherID AddAppShortcut() {
237 LauncherItem item; 250 LauncherItem item;
238 item.type = TYPE_APP_SHORTCUT; 251 item.type = TYPE_APP_SHORTCUT;
239 item.status = STATUS_CLOSED; 252 item.status = STATUS_CLOSED;
240 253
241 LauncherID id = model_->next_id(); 254 LauncherID id = model_->next_id();
242 model_->Add(item); 255 model_->Add(item);
256 CreateAndSetLauncherItemDelegateForID(id);
243 test_api_->RunMessageLoopUntilAnimationsDone(); 257 test_api_->RunMessageLoopUntilAnimationsDone();
244 return id; 258 return id;
245 } 259 }
246 260
247 LauncherID AddPanel() { 261 LauncherID AddPanel() {
248 LauncherID id = AddPanelNoWait(); 262 LauncherID id = AddPanelNoWait();
249 test_api_->RunMessageLoopUntilAnimationsDone(); 263 test_api_->RunMessageLoopUntilAnimationsDone();
250 return id; 264 return id;
251 } 265 }
252 266
253 LauncherID AddPlatformAppNoWait() { 267 LauncherID AddPlatformAppNoWait() {
254 LauncherItem item; 268 LauncherItem item;
255 item.type = TYPE_PLATFORM_APP; 269 item.type = TYPE_PLATFORM_APP;
256 item.status = STATUS_RUNNING; 270 item.status = STATUS_RUNNING;
257 271
258 LauncherID id = model_->next_id(); 272 LauncherID id = model_->next_id();
259 model_->Add(item); 273 model_->Add(item);
274 CreateAndSetLauncherItemDelegateForID(id);
260 return id; 275 return id;
261 } 276 }
262 277
263 LauncherID AddPanelNoWait() { 278 LauncherID AddPanelNoWait() {
264 LauncherItem item; 279 LauncherItem item;
265 item.type = TYPE_APP_PANEL; 280 item.type = TYPE_APP_PANEL;
266 item.status = STATUS_RUNNING; 281 item.status = STATUS_RUNNING;
267 282
268 LauncherID id = model_->next_id(); 283 LauncherID id = model_->next_id();
269 model_->Add(item); 284 model_->Add(item);
285 CreateAndSetLauncherItemDelegateForID(id);
270 return id; 286 return id;
271 } 287 }
272 288
273 LauncherID AddPlatformApp() { 289 LauncherID AddPlatformApp() {
274 LauncherID id = AddPlatformAppNoWait(); 290 LauncherID id = AddPlatformAppNoWait();
275 test_api_->RunMessageLoopUntilAnimationsDone(); 291 test_api_->RunMessageLoopUntilAnimationsDone();
276 return id; 292 return id;
277 } 293 }
278 294
279 void RemoveByID(LauncherID id) { 295 void RemoveByID(LauncherID id) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 return launcher_view_->tooltip_manager()->anchor_; 396 return launcher_view_->tooltip_manager()->anchor_;
381 } 397 }
382 398
383 void ShowTooltip() { 399 void ShowTooltip() {
384 launcher_view_->tooltip_manager()->ShowInternal(); 400 launcher_view_->tooltip_manager()->ShowInternal();
385 } 401 }
386 402
387 LauncherModel* model_; 403 LauncherModel* model_;
388 internal::LauncherView* launcher_view_; 404 internal::LauncherView* launcher_view_;
389 int browser_index_; 405 int browser_index_;
406 LauncherItemDelegateManager* item_manager_;
390 407
391 scoped_ptr<LauncherViewTestAPI> test_api_; 408 scoped_ptr<LauncherViewTestAPI> test_api_;
392 409
393 private: 410 private:
394 DISALLOW_COPY_AND_ASSIGN(LauncherViewTest); 411 DISALLOW_COPY_AND_ASSIGN(LauncherViewTest);
395 }; 412 };
396 413
397 class LauncherViewLegacyShelfLayoutTest : public LauncherViewTest { 414 class LauncherViewLegacyShelfLayoutTest : public LauncherViewTest {
398 public: 415 public:
399 LauncherViewLegacyShelfLayoutTest() : LauncherViewTest() { 416 LauncherViewLegacyShelfLayoutTest() : LauncherViewTest() {
(...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 test_api_->RunMessageLoopUntilAnimationsDone(); 1372 test_api_->RunMessageLoopUntilAnimationsDone();
1356 CheckAllItemsAreInBounds(); 1373 CheckAllItemsAreInBounds();
1357 } 1374 }
1358 1375
1359 INSTANTIATE_TEST_CASE_P(LtrRtl, LauncherViewTextDirectionTest, testing::Bool()); 1376 INSTANTIATE_TEST_CASE_P(LtrRtl, LauncherViewTextDirectionTest, testing::Bool());
1360 INSTANTIATE_TEST_CASE_P(VisibleBounds, LauncherViewVisibleBoundsTest, 1377 INSTANTIATE_TEST_CASE_P(VisibleBounds, LauncherViewVisibleBoundsTest,
1361 testing::Bool()); 1378 testing::Bool());
1362 1379
1363 } // namespace test 1380 } // namespace test
1364 } // namespace ash 1381 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698