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

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

Issue 23449033: [ash] Remove Launcher::GetLauncherViewForTest() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing class keyword 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_model.h" 7 #include "ash/launcher/launcher_model.h"
8 #include "ash/launcher/launcher_view.h" 8 #include "ash/launcher/launcher_view.h"
9 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_test_api.h"
13 #include "ash/test/launcher_view_test_api.h" 14 #include "ash/test/launcher_view_test_api.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 class LauncherTest : public ash::test::AshTestBase {
34 public:
35 LauncherTest() : launcher_(NULL),
36 launcher_view_(NULL),
37 launcher_model_(NULL) {
38 }
39
40 virtual ~LauncherTest() {}
41
42 virtual void SetUp() {
43 test::AshTestBase::SetUp();
44
45 launcher_ = Launcher::ForPrimaryDisplay();
46 ASSERT_TRUE(launcher_);
47
48 ash::test::LauncherTestAPI test(launcher_);
49 launcher_view_ = test.launcher_view();
50 launcher_model_ = launcher_view_->model();
51
52 test_.reset(new ash::test::LauncherViewTestAPI(launcher_view_));
53 }
54
55 virtual void TearDown() OVERRIDE {
56 test::AshTestBase::TearDown();
57 }
58
59 Launcher* launcher() {
60 return launcher_;
61 }
62
63 LauncherView* launcher_view() {
64 return launcher_view_;
65 }
66
67 LauncherModel* launcher_model() {
68 return launcher_model_;
69 }
70
71 ash::test::LauncherViewTestAPI* test_api() {
72 return test_.get();
73 }
74
75 private:
76 Launcher* launcher_;
77 LauncherView* launcher_view_;
78 LauncherModel* launcher_model_;
79 scoped_ptr<ash::test::LauncherViewTestAPI> test_;
80
81 DISALLOW_COPY_AND_ASSIGN(LauncherTest);
82 };
83
32 // Confirms that LauncherItem reflects the appropriated state. 84 // Confirms that LauncherItem reflects the appropriated state.
33 TEST_F(LauncherTest, StatusReflection) { 85 TEST_F(LauncherTest, StatusReflection) {
34 Launcher* launcher = Launcher::ForPrimaryDisplay(); 86 // Initially we have the app list.
35 ASSERT_TRUE(launcher); 87 int button_count = test_api()->GetButtonCount();
36 LauncherView* launcher_view = launcher->GetLauncherViewForTest();
37 test::LauncherViewTestAPI test(launcher_view);
38 LauncherModel* model = launcher_view->model();
39
40 // Initially we have the app list and chrome icon.
41 int button_count = test.GetButtonCount();
42 88
43 // Add running platform app. 89 // Add running platform app.
44 LauncherItem item; 90 LauncherItem item;
45 item.type = TYPE_PLATFORM_APP; 91 item.type = TYPE_PLATFORM_APP;
46 item.status = STATUS_RUNNING; 92 item.status = STATUS_RUNNING;
47 int index = model->Add(item); 93 int index = launcher_model()->Add(item);
48 ASSERT_EQ(++button_count, test.GetButtonCount()); 94 ASSERT_EQ(++button_count, test_api()->GetButtonCount());
49 LauncherButton* button = test.GetButton(index); 95 LauncherButton* button = test_api()->GetButton(index);
50 EXPECT_EQ(LauncherButton::STATE_RUNNING, button->state()); 96 EXPECT_EQ(LauncherButton::STATE_RUNNING, button->state());
51 97
52 // Remove it. 98 // Remove it.
53 model->RemoveItemAt(index); 99 launcher_model()->RemoveItemAt(index);
54 ASSERT_EQ(--button_count, test.GetButtonCount()); 100 ASSERT_EQ(--button_count, test_api()->GetButtonCount());
55 } 101 }
56 102
57 // Confirm that using the menu will clear the hover attribute. To avoid another 103 // Confirm that using the menu will clear the hover attribute. To avoid another
58 // browser test we check this here. 104 // browser test we check this here.
59 TEST_F(LauncherTest, checkHoverAfterMenu) { 105 TEST_F(LauncherTest, checkHoverAfterMenu) {
60 Launcher* launcher = Launcher::ForPrimaryDisplay(); 106 // Initially we have the app list.
61 ASSERT_TRUE(launcher); 107 int button_count = test_api()->GetButtonCount();
62 LauncherView* launcher_view = launcher->GetLauncherViewForTest();
63 test::LauncherViewTestAPI test(launcher_view);
64 LauncherModel* model = launcher_view->model();
65
66 // Initially we have the app list and chrome icon.
67 int button_count = test.GetButtonCount();
68 108
69 // Add running platform app. 109 // Add running platform app.
70 LauncherItem item; 110 LauncherItem item;
71 item.type = TYPE_PLATFORM_APP; 111 item.type = TYPE_PLATFORM_APP;
72 item.status = STATUS_RUNNING; 112 item.status = STATUS_RUNNING;
73 int index = model->Add(item); 113 int index = launcher_model()->Add(item);
74 ASSERT_EQ(++button_count, test.GetButtonCount()); 114 ASSERT_EQ(++button_count, test_api()->GetButtonCount());
75 LauncherButton* button = test.GetButton(index); 115 LauncherButton* button = test_api()->GetButton(index);
76 button->AddState(LauncherButton::STATE_HOVERED); 116 button->AddState(LauncherButton::STATE_HOVERED);
77 button->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); 117 button->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE);
78 EXPECT_FALSE(button->state() & LauncherButton::STATE_HOVERED); 118 EXPECT_FALSE(button->state() & LauncherButton::STATE_HOVERED);
79 119
80 // Remove it. 120 // Remove it.
81 model->RemoveItemAt(index); 121 launcher_model()->RemoveItemAt(index);
82 } 122 }
83 123
84 TEST_F(LauncherTest, ShowOverflowBubble) { 124 TEST_F(LauncherTest, ShowOverflowBubble) {
85 Launcher* launcher = Launcher::ForPrimaryDisplay(); 125 LauncherID first_item_id = launcher_model()->next_id();
86 ASSERT_TRUE(launcher);
87
88 LauncherView* launcher_view = launcher->GetLauncherViewForTest();
89 test::LauncherViewTestAPI test(launcher_view);
90
91 LauncherModel* model = launcher_view->model();
92 LauncherID first_item_id = model->next_id();
93 126
94 // Add platform app button until overflow. 127 // Add platform app button until overflow.
95 int items_added = 0; 128 int items_added = 0;
96 while (!test.IsOverflowButtonVisible()) { 129 while (!test_api()->IsOverflowButtonVisible()) {
97 LauncherItem item; 130 LauncherItem item;
98 item.type = TYPE_PLATFORM_APP; 131 item.type = TYPE_PLATFORM_APP;
99 item.status = STATUS_RUNNING; 132 item.status = STATUS_RUNNING;
100 model->Add(item); 133 launcher_model()->Add(item);
101 134
102 ++items_added; 135 ++items_added;
103 ASSERT_LT(items_added, 10000); 136 ASSERT_LT(items_added, 10000);
104 } 137 }
105 138
106 // Shows overflow bubble. 139 // Shows overflow bubble.
107 test.ShowOverflowBubble(); 140 test_api()->ShowOverflowBubble();
108 EXPECT_TRUE(launcher->IsShowingOverflowBubble()); 141 EXPECT_TRUE(launcher()->IsShowingOverflowBubble());
109 142
110 // Removes the first item in main launcher view. 143 // Removes the first item in main launcher view.
111 model->RemoveItemAt(model->ItemIndexByID(first_item_id)); 144 launcher_model()->RemoveItemAt(
145 launcher_model()->ItemIndexByID(first_item_id));
112 146
113 // Waits for all transitions to finish and there should be no crash. 147 // Waits for all transitions to finish and there should be no crash.
114 test.RunMessageLoopUntilAnimationsDone(); 148 test_api()->RunMessageLoopUntilAnimationsDone();
115 EXPECT_FALSE(launcher->IsShowingOverflowBubble()); 149 EXPECT_FALSE(launcher()->IsShowingOverflowBubble());
116 } 150 }
117 151
118 } // namespace ash 152 } // namespace ash
OLDNEW
« no previous file with comments | « ash/launcher/launcher_tooltip_manager_unittest.cc ('k') | ash/launcher/launcher_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698