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

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

Issue 23606016: Refactor LauncherItemController and LauncherItemDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix for LauncherTest and observing LauncherModel in DelegateManager 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
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.h" 5 #include "ash/launcher/launcher.h"
6 #include "ash/launcher/launcher_button.h" 6 #include "ash/launcher/launcher_button.h"
7 #include "ash/launcher/launcher_item_delegate_manager.h"
7 #include "ash/launcher/launcher_model.h" 8 #include "ash/launcher/launcher_model.h"
8 #include "ash/launcher/launcher_view.h" 9 #include "ash/launcher/launcher_view.h"
9
10 #include "ash/shelf/shelf_widget.h" 10 #include "ash/shelf/shelf_widget.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "ash/test/ash_test_base.h" 12 #include "ash/test/ash_test_base.h"
13 #include "ash/test/launcher_view_test_api.h" 13 #include "ash/test/launcher_view_test_api.h"
14 #include "ash/test/test_launcher_item_delegate.h"
14 #include "ash/wm/window_util.h" 15 #include "ash/wm/window_util.h"
15 #include "ui/aura/root_window.h" 16 #include "ui/aura/root_window.h"
16 #include "ui/gfx/display.h" 17 #include "ui/gfx/display.h"
17 #include "ui/gfx/screen.h" 18 #include "ui/gfx/screen.h"
18 #include "ui/views/corewm/corewm_switches.h" 19 #include "ui/views/corewm/corewm_switches.h"
19 #include "ui/views/view.h" 20 #include "ui/views/view.h"
20 #include "ui/views/widget/widget.h" 21 #include "ui/views/widget/widget.h"
21 22
22 #if defined(OS_WIN) 23 #if defined(OS_WIN)
23 #include "base/win/windows_version.h" 24 #include "base/win/windows_version.h"
24 #endif 25 #endif
25 26
26 typedef ash::test::AshTestBase LauncherTest; 27 typedef ash::test::AshTestBase LauncherTest;
27 using ash::internal::LauncherView; 28 using ash::internal::LauncherView;
28 using ash::internal::LauncherButton; 29 using ash::internal::LauncherButton;
29 30
30 namespace ash { 31 namespace ash {
31 32
33 void RegisterTestLauncherItemDelegateAtIndex(LauncherModel* model, int index) {
34 ash::Shell::GetInstance()->launcher_item_delegate_manager()->
35 RegisterLauncherItemDelegate(
36 model->items()[index].id,
37 new ash::test::TestLauncherItemDelegate(NULL));
38 }
39
32 // Confirms that LauncherItem reflects the appropriated state. 40 // Confirms that LauncherItem reflects the appropriated state.
33 TEST_F(LauncherTest, StatusReflection) { 41 TEST_F(LauncherTest, StatusReflection) {
34 Launcher* launcher = Launcher::ForPrimaryDisplay(); 42 Launcher* launcher = Launcher::ForPrimaryDisplay();
35 ASSERT_TRUE(launcher); 43 ASSERT_TRUE(launcher);
36 LauncherView* launcher_view = launcher->GetLauncherViewForTest(); 44 LauncherView* launcher_view = launcher->GetLauncherViewForTest();
37 test::LauncherViewTestAPI test(launcher_view); 45 test::LauncherViewTestAPI test(launcher_view);
38 LauncherModel* model = launcher_view->model(); 46 LauncherModel* model = launcher_view->model();
39 47
40 // Initially we have the app list and chrome icon. 48 // Initially we have the app list and chrome icon.
41 int button_count = test.GetButtonCount(); 49 int button_count = test.GetButtonCount();
42 50
43 // Add running platform app. 51 // Add running platform app.
44 LauncherItem item; 52 LauncherItem item;
45 item.type = TYPE_PLATFORM_APP; 53 item.type = TYPE_PLATFORM_APP;
46 item.status = STATUS_RUNNING; 54 item.status = STATUS_RUNNING;
47 int index = model->Add(item); 55 int index = model->Add(item);
56 RegisterTestLauncherItemDelegateAtIndex(model, index);
57
48 ASSERT_EQ(++button_count, test.GetButtonCount()); 58 ASSERT_EQ(++button_count, test.GetButtonCount());
49 LauncherButton* button = test.GetButton(index); 59 LauncherButton* button = test.GetButton(index);
50 EXPECT_EQ(LauncherButton::STATE_RUNNING, button->state()); 60 EXPECT_EQ(LauncherButton::STATE_RUNNING, button->state());
51 61
52 // Remove it. 62 // Remove it.
53 model->RemoveItemAt(index); 63 model->RemoveItemAt(index);
54 ASSERT_EQ(--button_count, test.GetButtonCount()); 64 ASSERT_EQ(--button_count, test.GetButtonCount());
55 } 65 }
56 66
57 // Confirm that using the menu will clear the hover attribute. To avoid another 67 // Confirm that using the menu will clear the hover attribute. To avoid another
58 // browser test we check this here. 68 // browser test we check this here.
59 TEST_F(LauncherTest, checkHoverAfterMenu) { 69 TEST_F(LauncherTest, checkHoverAfterMenu) {
60 Launcher* launcher = Launcher::ForPrimaryDisplay(); 70 Launcher* launcher = Launcher::ForPrimaryDisplay();
61 ASSERT_TRUE(launcher); 71 ASSERT_TRUE(launcher);
62 LauncherView* launcher_view = launcher->GetLauncherViewForTest(); 72 LauncherView* launcher_view = launcher->GetLauncherViewForTest();
63 test::LauncherViewTestAPI test(launcher_view); 73 test::LauncherViewTestAPI test(launcher_view);
64 LauncherModel* model = launcher_view->model(); 74 LauncherModel* model = launcher_view->model();
65 75
66 // Initially we have the app list and chrome icon. 76 // Initially we have the app list and chrome icon.
67 int button_count = test.GetButtonCount(); 77 int button_count = test.GetButtonCount();
68 78
69 // Add running platform app. 79 // Add running platform app.
70 LauncherItem item; 80 LauncherItem item;
71 item.type = TYPE_PLATFORM_APP; 81 item.type = TYPE_PLATFORM_APP;
72 item.status = STATUS_RUNNING; 82 item.status = STATUS_RUNNING;
73 int index = model->Add(item); 83 int index = model->Add(item);
84 RegisterTestLauncherItemDelegateAtIndex(model, index);
85
74 ASSERT_EQ(++button_count, test.GetButtonCount()); 86 ASSERT_EQ(++button_count, test.GetButtonCount());
75 LauncherButton* button = test.GetButton(index); 87 LauncherButton* button = test.GetButton(index);
76 button->AddState(LauncherButton::STATE_HOVERED); 88 button->AddState(LauncherButton::STATE_HOVERED);
77 button->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); 89 button->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE);
78 EXPECT_FALSE(button->state() & LauncherButton::STATE_HOVERED); 90 EXPECT_FALSE(button->state() & LauncherButton::STATE_HOVERED);
79 91
80 // Remove it. 92 // Remove it.
81 model->RemoveItemAt(index); 93 model->RemoveItemAt(index);
82 } 94 }
83 95
84 TEST_F(LauncherTest, ShowOverflowBubble) { 96 TEST_F(LauncherTest, ShowOverflowBubble) {
85 Launcher* launcher = Launcher::ForPrimaryDisplay(); 97 Launcher* launcher = Launcher::ForPrimaryDisplay();
86 ASSERT_TRUE(launcher); 98 ASSERT_TRUE(launcher);
87 99
88 LauncherView* launcher_view = launcher->GetLauncherViewForTest(); 100 LauncherView* launcher_view = launcher->GetLauncherViewForTest();
89 test::LauncherViewTestAPI test(launcher_view); 101 test::LauncherViewTestAPI test(launcher_view);
90 102
91 LauncherModel* model = launcher_view->model(); 103 LauncherModel* model = launcher_view->model();
92 LauncherID first_item_id = model->next_id(); 104 LauncherID first_item_id = model->next_id();
93 105
94 // Add platform app button until overflow. 106 // Add platform app button until overflow.
95 int items_added = 0; 107 int items_added = 0;
108 int index = -1;
96 while (!test.IsOverflowButtonVisible()) { 109 while (!test.IsOverflowButtonVisible()) {
97 LauncherItem item; 110 LauncherItem item;
98 item.type = TYPE_PLATFORM_APP; 111 item.type = TYPE_PLATFORM_APP;
99 item.status = STATUS_RUNNING; 112 item.status = STATUS_RUNNING;
100 model->Add(item); 113 index = model->Add(item);
101 114 RegisterTestLauncherItemDelegateAtIndex(model, index);
102 ++items_added; 115 ++items_added;
103 ASSERT_LT(items_added, 10000); 116 ASSERT_LT(items_added, 10000);
104 } 117 }
105 118
106 // Shows overflow bubble. 119 // Shows overflow bubble.
107 test.ShowOverflowBubble(); 120 test.ShowOverflowBubble();
108 EXPECT_TRUE(launcher->IsShowingOverflowBubble()); 121 EXPECT_TRUE(launcher->IsShowingOverflowBubble());
109 122
110 // Removes the first item in main launcher view. 123 // Removes the first item in main launcher view.
111 model->RemoveItemAt(model->ItemIndexByID(first_item_id)); 124 model->RemoveItemAt(model->ItemIndexByID(first_item_id));
112 125
113 // Waits for all transitions to finish and there should be no crash. 126 // Waits for all transitions to finish and there should be no crash.
114 test.RunMessageLoopUntilAnimationsDone(); 127 test.RunMessageLoopUntilAnimationsDone();
115 EXPECT_FALSE(launcher->IsShowingOverflowBubble()); 128 EXPECT_FALSE(launcher->IsShowingOverflowBubble());
116 } 129 }
117 130
118 } // namespace ash 131 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698