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

Side by Side Diff: ash/shelf/shelf_view_unittest.cc

Issue 115113006: Rename Launcher to Shelf. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ShelfTestAPI Created 7 years 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 (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/shelf/shelf_view.h" 5 #include "ash/shelf/shelf_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"
12 #include "ash/launcher/launcher_types.h" 11 #include "ash/launcher/launcher_types.h"
13 #include "ash/root_window_controller.h" 12 #include "ash/root_window_controller.h"
14 #include "ash/shelf/overflow_bubble.h" 13 #include "ash/shelf/overflow_bubble.h"
15 #include "ash/shelf/overflow_bubble_view.h" 14 #include "ash/shelf/overflow_bubble_view.h"
15 #include "ash/shelf/shelf.h"
16 #include "ash/shelf/shelf_button.h" 16 #include "ash/shelf/shelf_button.h"
17 #include "ash/shelf/shelf_icon_observer.h" 17 #include "ash/shelf/shelf_icon_observer.h"
18 #include "ash/shelf/shelf_item_delegate_manager.h" 18 #include "ash/shelf/shelf_item_delegate_manager.h"
19 #include "ash/shelf/shelf_layout_manager.h" 19 #include "ash/shelf/shelf_layout_manager.h"
20 #include "ash/shelf/shelf_model.h" 20 #include "ash/shelf/shelf_model.h"
21 #include "ash/shelf/shelf_tooltip_manager.h" 21 #include "ash/shelf/shelf_tooltip_manager.h"
22 #include "ash/shelf/shelf_widget.h" 22 #include "ash/shelf/shelf_widget.h"
23 #include "ash/shell.h" 23 #include "ash/shell.h"
24 #include "ash/shell_window_ids.h" 24 #include "ash/shell_window_ids.h"
25 #include "ash/test/ash_test_base.h" 25 #include "ash/test/ash_test_base.h"
26 #include "ash/test/launcher_test_api.h"
27 #include "ash/test/overflow_bubble_view_test_api.h" 26 #include "ash/test/overflow_bubble_view_test_api.h"
27 #include "ash/test/shelf_test_api.h"
28 #include "ash/test/shelf_view_test_api.h" 28 #include "ash/test/shelf_view_test_api.h"
29 #include "ash/test/shell_test_api.h" 29 #include "ash/test/shell_test_api.h"
30 #include "ash/test/test_shelf_delegate.h" 30 #include "ash/test/test_shelf_delegate.h"
31 #include "ash/test/test_shelf_item_delegate.h" 31 #include "ash/test/test_shelf_item_delegate.h"
32 #include "ash/wm/coordinate_conversion.h" 32 #include "ash/wm/coordinate_conversion.h"
33 #include "base/basictypes.h" 33 #include "base/basictypes.h"
34 #include "base/command_line.h" 34 #include "base/command_line.h"
35 #include "base/compiler_specific.h" 35 #include "base/compiler_specific.h"
36 #include "base/memory/scoped_ptr.h" 36 #include "base/memory/scoped_ptr.h"
37 #include "base/strings/string_number_conversions.h" 37 #include "base/strings/string_number_conversions.h"
(...skipping 11 matching lines...) Expand all
49 #include "ui/views/widget/widget_delegate.h" 49 #include "ui/views/widget/widget_delegate.h"
50 50
51 namespace ash { 51 namespace ash {
52 namespace test { 52 namespace test {
53 53
54 //////////////////////////////////////////////////////////////////////////////// 54 ////////////////////////////////////////////////////////////////////////////////
55 // ShelfIconObserver tests. 55 // ShelfIconObserver tests.
56 56
57 class TestShelfIconObserver : public ShelfIconObserver { 57 class TestShelfIconObserver : public ShelfIconObserver {
58 public: 58 public:
59 explicit TestShelfIconObserver(Launcher* launcher) 59 explicit TestShelfIconObserver(Shelf* shelf)
60 : launcher_(launcher), 60 : shelf_(shelf),
61 change_notified_(false) { 61 change_notified_(false) {
62 if (launcher_) 62 if (shelf_)
63 launcher_->AddIconObserver(this); 63 shelf_->AddIconObserver(this);
64 } 64 }
65 65
66 virtual ~TestShelfIconObserver() { 66 virtual ~TestShelfIconObserver() {
67 if (launcher_) 67 if (shelf_)
68 launcher_->RemoveIconObserver(this); 68 shelf_->RemoveIconObserver(this);
69 } 69 }
70 70
71 // ShelfIconObserver implementation. 71 // ShelfIconObserver implementation.
72 virtual void OnShelfIconPositionsChanged() OVERRIDE { 72 virtual void OnShelfIconPositionsChanged() OVERRIDE {
73 change_notified_ = true; 73 change_notified_ = true;
74 } 74 }
75 75
76 int change_notified() const { return change_notified_; } 76 int change_notified() const { return change_notified_; }
77 void Reset() { change_notified_ = false; } 77 void Reset() { change_notified_ = false; }
78 78
79 private: 79 private:
80 Launcher* launcher_; 80 Shelf* shelf_;
81 bool change_notified_; 81 bool change_notified_;
82 82
83 DISALLOW_COPY_AND_ASSIGN(TestShelfIconObserver); 83 DISALLOW_COPY_AND_ASSIGN(TestShelfIconObserver);
84 }; 84 };
85 85
86 class ShelfViewIconObserverTest : public AshTestBase { 86 class ShelfViewIconObserverTest : public AshTestBase {
87 public: 87 public:
88 ShelfViewIconObserverTest() {} 88 ShelfViewIconObserverTest() {}
89 virtual ~ShelfViewIconObserverTest() {} 89 virtual ~ShelfViewIconObserverTest() {}
90 90
91 virtual void SetUp() OVERRIDE { 91 virtual void SetUp() OVERRIDE {
92 AshTestBase::SetUp(); 92 AshTestBase::SetUp();
93 Launcher* launcher = Launcher::ForPrimaryDisplay(); 93 Shelf* shelf = Shelf::ForPrimaryDisplay();
94 observer_.reset(new TestShelfIconObserver(launcher)); 94 observer_.reset(new TestShelfIconObserver(shelf));
95 95
96 shelf_view_test_.reset(new ShelfViewTestAPI( 96 shelf_view_test_.reset(
97 LauncherTestAPI(launcher).shelf_view())); 97 new ShelfViewTestAPI(ShelfTestAPI(shelf).shelf_view()));
98 shelf_view_test_->SetAnimationDuration(1); 98 shelf_view_test_->SetAnimationDuration(1);
99 } 99 }
100 100
101 virtual void TearDown() OVERRIDE { 101 virtual void TearDown() OVERRIDE {
102 observer_.reset(); 102 observer_.reset();
103 AshTestBase::TearDown(); 103 AshTestBase::TearDown();
104 } 104 }
105 105
106 TestShelfIconObserver* observer() { return observer_.get(); } 106 TestShelfIconObserver* observer() { return observer_.get(); }
107 107
108 ShelfViewTestAPI* shelf_view_test() { 108 ShelfViewTestAPI* shelf_view_test() {
109 return shelf_view_test_.get(); 109 return shelf_view_test_.get();
110 } 110 }
111 111
112 Launcher* LauncherForSecondaryDisplay() { 112 Shelf* ShelfForSecondaryDisplay() {
113 return Launcher::ForWindow(Shell::GetAllRootWindows()[1]); 113 return Shelf::ForWindow(Shell::GetAllRootWindows()[1]);
114 } 114 }
115 115
116 private: 116 private:
117 scoped_ptr<TestShelfIconObserver> observer_; 117 scoped_ptr<TestShelfIconObserver> observer_;
118 scoped_ptr<ShelfViewTestAPI> shelf_view_test_; 118 scoped_ptr<ShelfViewTestAPI> shelf_view_test_;
119 119
120 DISALLOW_COPY_AND_ASSIGN(ShelfViewIconObserverTest); 120 DISALLOW_COPY_AND_ASSIGN(ShelfViewIconObserverTest);
121 }; 121 };
122 122
123 TEST_F(ShelfViewIconObserverTest, AddRemove) { 123 TEST_F(ShelfViewIconObserverTest, AddRemove) {
(...skipping 21 matching lines...) Expand all
145 145
146 // Sometimes fails on trybots on win7_aura. http://crbug.com/177135 146 // Sometimes fails on trybots on win7_aura. http://crbug.com/177135
147 #if defined(OS_WIN) 147 #if defined(OS_WIN)
148 #define MAYBE_AddRemoveWithMultipleDisplays \ 148 #define MAYBE_AddRemoveWithMultipleDisplays \
149 DISABLED_AddRemoveWithMultipleDisplays 149 DISABLED_AddRemoveWithMultipleDisplays
150 #else 150 #else
151 #define MAYBE_AddRemoveWithMultipleDisplays \ 151 #define MAYBE_AddRemoveWithMultipleDisplays \
152 AddRemoveWithMultipleDisplays 152 AddRemoveWithMultipleDisplays
153 #endif 153 #endif
154 // Make sure creating/deleting an window on one displays notifies a 154 // Make sure creating/deleting an window on one displays notifies a
155 // launcher on external display as well as one on primary. 155 // shelf on external display as well as one on primary.
156 TEST_F(ShelfViewIconObserverTest, MAYBE_AddRemoveWithMultipleDisplays) { 156 TEST_F(ShelfViewIconObserverTest, MAYBE_AddRemoveWithMultipleDisplays) {
157 UpdateDisplay("400x400,400x400"); 157 UpdateDisplay("400x400,400x400");
158 TestShelfIconObserver second_observer(LauncherForSecondaryDisplay()); 158 TestShelfIconObserver second_observer(ShelfForSecondaryDisplay());
159 159
160 TestShelfDelegate* shelf_delegate = TestShelfDelegate::instance(); 160 TestShelfDelegate* shelf_delegate = TestShelfDelegate::instance();
161 ASSERT_TRUE(shelf_delegate); 161 ASSERT_TRUE(shelf_delegate);
162 162
163 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 163 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
164 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 164 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
165 params.bounds = gfx::Rect(0, 0, 200, 200); 165 params.bounds = gfx::Rect(0, 0, 200, 200);
166 params.context = CurrentContext(); 166 params.context = CurrentContext();
167 167
168 scoped_ptr<views::Widget> widget(new views::Widget()); 168 scoped_ptr<views::Widget> widget(new views::Widget());
169 widget->Init(params); 169 widget->Init(params);
170 shelf_delegate->AddLauncherItem(widget->GetNativeWindow()); 170 shelf_delegate->AddLauncherItem(widget->GetNativeWindow());
171 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); 171 shelf_view_test()->RunMessageLoopUntilAnimationsDone();
172 EXPECT_TRUE(observer()->change_notified()); 172 EXPECT_TRUE(observer()->change_notified());
173 EXPECT_TRUE(second_observer.change_notified()); 173 EXPECT_TRUE(second_observer.change_notified());
174 observer()->Reset(); 174 observer()->Reset();
175 second_observer.Reset(); 175 second_observer.Reset();
176 176
177 widget->GetNativeWindow()->parent()->RemoveChild(widget->GetNativeWindow()); 177 widget->GetNativeWindow()->parent()->RemoveChild(widget->GetNativeWindow());
178 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); 178 shelf_view_test()->RunMessageLoopUntilAnimationsDone();
179 EXPECT_TRUE(observer()->change_notified()); 179 EXPECT_TRUE(observer()->change_notified());
180 EXPECT_TRUE(second_observer.change_notified()); 180 EXPECT_TRUE(second_observer.change_notified());
181 181
182 observer()->Reset(); 182 observer()->Reset();
183 second_observer.Reset(); 183 second_observer.Reset();
184 } 184 }
185 185
186 TEST_F(ShelfViewIconObserverTest, BoundsChanged) { 186 TEST_F(ShelfViewIconObserverTest, BoundsChanged) {
187 ShelfWidget* shelf = Shell::GetPrimaryRootWindowController()->shelf(); 187 ShelfWidget* widget = Shell::GetPrimaryRootWindowController()->shelf();
188 Launcher* launcher = Launcher::ForPrimaryDisplay(); 188 Shelf* shelf = Shelf::ForPrimaryDisplay();
189 gfx::Size shelf_size = 189 gfx::Size shelf_size = widget->GetWindowBoundsInScreen().size();
190 shelf->GetWindowBoundsInScreen().size();
191 shelf_size.set_width(shelf_size.width() / 2); 190 shelf_size.set_width(shelf_size.width() / 2);
192 ASSERT_GT(shelf_size.width(), 0); 191 ASSERT_GT(shelf_size.width(), 0);
193 launcher->SetShelfViewBounds(gfx::Rect(shelf_size)); 192 shelf->SetShelfViewBounds(gfx::Rect(shelf_size));
194 // No animation happens for ShelfView bounds change. 193 // No animation happens for ShelfView bounds change.
195 EXPECT_TRUE(observer()->change_notified()); 194 EXPECT_TRUE(observer()->change_notified());
196 observer()->Reset(); 195 observer()->Reset();
197 } 196 }
198 197
199 //////////////////////////////////////////////////////////////////////////////// 198 ////////////////////////////////////////////////////////////////////////////////
200 // ShelfView tests. 199 // ShelfView tests.
201 200
202 // Simple ShelfDelegate implmentation for ShelfViewTest.OverflowBubbleSize 201 // Simple ShelfDelegate implmentation for ShelfViewTest.OverflowBubbleSize
203 // and CheckDragAndDropFromOverflowBubbleToShelf 202 // and CheckDragAndDropFromOverflowBubbleToShelf
204 class TestShelfDelegateForShelfView : public ShelfDelegate { 203 class TestShelfDelegateForShelfView : public ShelfDelegate {
205 public: 204 public:
206 explicit TestShelfDelegateForShelfView(ShelfModel* model) 205 explicit TestShelfDelegateForShelfView(ShelfModel* model)
207 : model_(model) {} 206 : model_(model) {}
208 virtual ~TestShelfDelegateForShelfView() {} 207 virtual ~TestShelfDelegateForShelfView() {}
209 208
210 // ShelfDelegate overrides: 209 // ShelfDelegate overrides:
211 virtual void OnLauncherCreated(Launcher* launcher) OVERRIDE {} 210 virtual void OnShelfCreated(Shelf* shelf) OVERRIDE {}
212 211
213 virtual void OnLauncherDestroyed(Launcher* launcher) OVERRIDE {} 212 virtual void OnShelfDestroyed(Shelf* shelf) OVERRIDE {}
214 213
215 virtual LauncherID GetLauncherIDForAppID(const std::string& app_id) OVERRIDE { 214 virtual LauncherID GetLauncherIDForAppID(const std::string& app_id) OVERRIDE {
216 LauncherID id = 0; 215 LauncherID id = 0;
217 EXPECT_TRUE(base::StringToInt(app_id, &id)); 216 EXPECT_TRUE(base::StringToInt(app_id, &id));
218 return id; 217 return id;
219 } 218 }
220 219
221 virtual const std::string& GetAppIDForLauncherID(LauncherID id) OVERRIDE { 220 virtual const std::string& GetAppIDForLauncherID(LauncherID id) OVERRIDE {
222 // Use |app_id_| member variable because returning a reference to local 221 // Use |app_id_| member variable because returning a reference to local
223 // variable is not allowed. 222 // variable is not allowed.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 259
261 class ShelfViewTest : public AshTestBase { 260 class ShelfViewTest : public AshTestBase {
262 public: 261 public:
263 ShelfViewTest() : model_(NULL), shelf_view_(NULL), browser_index_(1) {} 262 ShelfViewTest() : model_(NULL), shelf_view_(NULL), browser_index_(1) {}
264 virtual ~ShelfViewTest() {} 263 virtual ~ShelfViewTest() {}
265 264
266 virtual void SetUp() OVERRIDE { 265 virtual void SetUp() OVERRIDE {
267 AshTestBase::SetUp(); 266 AshTestBase::SetUp();
268 test::ShellTestApi test_api(Shell::GetInstance()); 267 test::ShellTestApi test_api(Shell::GetInstance());
269 model_ = test_api.shelf_model(); 268 model_ = test_api.shelf_model();
270 Launcher* launcher = Launcher::ForPrimaryDisplay(); 269 Shelf* shelf = Shelf::ForPrimaryDisplay();
271 shelf_view_ = test::LauncherTestAPI(launcher).shelf_view(); 270 shelf_view_ = ShelfTestAPI(shelf).shelf_view();
272 271
273 // The bounds should be big enough for 4 buttons + overflow chevron. 272 // The bounds should be big enough for 4 buttons + overflow chevron.
274 shelf_view_->SetBounds(0, 0, 500, 273 shelf_view_->SetBounds(0, 0, 500,
275 internal::ShelfLayoutManager::GetPreferredShelfSize()); 274 internal::ShelfLayoutManager::GetPreferredShelfSize());
276 275
277 test_api_.reset(new ShelfViewTestAPI(shelf_view_)); 276 test_api_.reset(new ShelfViewTestAPI(shelf_view_));
278 test_api_->SetAnimationDuration(1); // Speeds up animation for test. 277 test_api_->SetAnimationDuration(1); // Speeds up animation for test.
279 278
280 item_manager_ = Shell::GetInstance()->shelf_item_delegate_manager(); 279 item_manager_ = Shell::GetInstance()->shelf_item_delegate_manager();
281 DCHECK(item_manager_); 280 DCHECK(item_manager_);
282 281
283 // Add browser shortcut launcher item at index 0 for test. 282 // Add browser shortcut shelf item at index 0 for test.
284 AddBrowserShortcut(); 283 AddBrowserShortcut();
285 } 284 }
286 285
287 virtual void TearDown() OVERRIDE { 286 virtual void TearDown() OVERRIDE {
288 test_api_.reset(); 287 test_api_.reset();
289 AshTestBase::TearDown(); 288 AshTestBase::TearDown();
290 } 289 }
291 290
292 protected: 291 protected:
293 void CreateAndSetShelfItemDelegateForID(LauncherID id) { 292 void CreateAndSetShelfItemDelegateForID(LauncherID id) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 ++model_index) { 374 ++model_index) {
376 LauncherItem item = model_->items()[model_index]; 375 LauncherItem item = model_->items()[model_index];
377 LauncherID id = item.id; 376 LauncherID id = item.id;
378 EXPECT_EQ(id_map[map_index].first, id); 377 EXPECT_EQ(id_map[map_index].first, id);
379 EXPECT_EQ(id_map[map_index].second, GetButtonByID(id)); 378 EXPECT_EQ(id_map[map_index].second, GetButtonByID(id));
380 ++map_index; 379 ++map_index;
381 } 380 }
382 ASSERT_EQ(map_index, id_map.size()); 381 ASSERT_EQ(map_index, id_map.size());
383 } 382 }
384 383
385 void VerifyLauncherItemBoundsAreValid() { 384 void VerifyShelfItemBoundsAreValid() {
386 for (int i=0;i <= test_api_->GetLastVisibleIndex(); ++i) { 385 for (int i=0;i <= test_api_->GetLastVisibleIndex(); ++i) {
387 if (test_api_->GetButton(i)) { 386 if (test_api_->GetButton(i)) {
388 gfx::Rect shelf_view_bounds = shelf_view_->GetLocalBounds(); 387 gfx::Rect shelf_view_bounds = shelf_view_->GetLocalBounds();
389 gfx::Rect item_bounds = test_api_->GetBoundsByIndex(i); 388 gfx::Rect item_bounds = test_api_->GetBoundsByIndex(i);
390 EXPECT_TRUE(item_bounds.x() >= 0); 389 EXPECT_TRUE(item_bounds.x() >= 0);
391 EXPECT_TRUE(item_bounds.y() >= 0); 390 EXPECT_TRUE(item_bounds.y() >= 0);
392 EXPECT_TRUE(item_bounds.right() <= shelf_view_bounds.width()); 391 EXPECT_TRUE(item_bounds.right() <= shelf_view_bounds.width());
393 EXPECT_TRUE(item_bounds.bottom() <= shelf_view_bounds.height()); 392 EXPECT_TRUE(item_bounds.bottom() <= shelf_view_bounds.height());
394 } 393 }
395 } 394 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 views::View* destination = test_api_->GetButton(destination_index); 426 views::View* destination = test_api_->GetButton(destination_index);
428 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, 427 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED,
429 destination->bounds().origin(), 428 destination->bounds().origin(),
430 destination->GetBoundsInScreen().origin(), 0); 429 destination->GetBoundsInScreen().origin(), 0);
431 button_host->PointerDraggedOnButton(button, pointer, drag_event); 430 button_host->PointerDraggedOnButton(button, pointer, drag_event);
432 return button; 431 return button;
433 } 432 }
434 433
435 void SetupForDragTest( 434 void SetupForDragTest(
436 std::vector<std::pair<LauncherID, views::View*> >* id_map) { 435 std::vector<std::pair<LauncherID, views::View*> >* id_map) {
437 // Initialize |id_map| with the automatically-created launcher buttons. 436 // Initialize |id_map| with the automatically-created shelf buttons.
438 for (size_t i = 0; i < model_->items().size(); ++i) { 437 for (size_t i = 0; i < model_->items().size(); ++i) {
439 internal::ShelfButton* button = test_api_->GetButton(i); 438 internal::ShelfButton* button = test_api_->GetButton(i);
440 id_map->push_back(std::make_pair(model_->items()[i].id, button)); 439 id_map->push_back(std::make_pair(model_->items()[i].id, button));
441 } 440 }
442 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map)); 441 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map));
443 442
444 // Add 5 app launcher buttons for testing. 443 // Add 5 app shelf buttons for testing.
445 for (int i = 0; i < 5; ++i) { 444 for (int i = 0; i < 5; ++i) {
446 LauncherID id = AddAppShortcut(); 445 LauncherID id = AddAppShortcut();
447 // App Icon is located at index 0, and browser shortcut is located at 446 // App Icon is located at index 0, and browser shortcut is located at
448 // index 1. So we should start to add app shortcut at index 2. 447 // index 1. So we should start to add app shortcut at index 2.
449 id_map->insert(id_map->begin() + (i + browser_index_ + 1), 448 id_map->insert(id_map->begin() + (i + browser_index_ + 1),
450 std::make_pair(id, GetButtonByID(id))); 449 std::make_pair(id, GetButtonByID(id)));
451 } 450 }
452 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map)); 451 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map));
453 } 452 }
454 453
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 // Verifies non-overflow buttons are visible. 932 // Verifies non-overflow buttons are visible.
934 for (int i = 0; i <= test_api_->GetLastVisibleIndex(); ++i) { 933 for (int i = 0; i <= test_api_->GetLastVisibleIndex(); ++i) {
935 internal::ShelfButton* button = test_api_->GetButton(i); 934 internal::ShelfButton* button = test_api_->GetButton(i);
936 if (button) { 935 if (button) {
937 EXPECT_TRUE(button->visible()) << "button index=" << i; 936 EXPECT_TRUE(button->visible()) << "button index=" << i;
938 EXPECT_EQ(1.0f, button->layer()->opacity()) << "button index=" << i; 937 EXPECT_EQ(1.0f, button->layer()->opacity()) << "button index=" << i;
939 } 938 }
940 } 939 }
941 } 940 }
942 941
943 // Check that model changes are handled correctly while a launcher icon is being 942 // Check that model changes are handled correctly while a shelf icon is being
944 // dragged. 943 // dragged.
945 TEST_F(ShelfViewTest, ModelChangesWhileDragging) { 944 TEST_F(ShelfViewTest, ModelChangesWhileDragging) {
946 internal::ShelfButtonHost* button_host = shelf_view_; 945 internal::ShelfButtonHost* button_host = shelf_view_;
947 946
948 std::vector<std::pair<LauncherID, views::View*> > id_map; 947 std::vector<std::pair<LauncherID, views::View*> > id_map;
949 SetupForDragTest(&id_map); 948 SetupForDragTest(&id_map);
950 949
951 // Dragging browser shortcut at index 1. 950 // Dragging browser shortcut at index 1.
952 EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT); 951 EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT);
953 views::View* dragged_button = SimulateDrag( 952 views::View* dragged_button = SimulateDrag(
(...skipping 25 matching lines...) Expand all
979 978
980 // Deleting an item keeps the remaining intact. 979 // Deleting an item keeps the remaining intact.
981 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 1, 3); 980 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 1, 3);
982 model_->RemoveItemAt(1); 981 model_->RemoveItemAt(1);
983 id_map.erase(id_map.begin() + 1); 982 id_map.erase(id_map.begin() + 1);
984 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 983 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
985 button_host->PointerReleasedOnButton(dragged_button, 984 button_host->PointerReleasedOnButton(dragged_button,
986 internal::ShelfButtonHost::MOUSE, 985 internal::ShelfButtonHost::MOUSE,
987 false); 986 false);
988 987
989 // Adding a launcher item cancels the drag and respects the order. 988 // Adding a shelf item cancels the drag and respects the order.
990 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 1, 3); 989 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 1, 3);
991 LauncherID new_id = AddAppShortcut(); 990 LauncherID new_id = AddAppShortcut();
992 id_map.insert(id_map.begin() + 6, 991 id_map.insert(id_map.begin() + 6,
993 std::make_pair(new_id, GetButtonByID(new_id))); 992 std::make_pair(new_id, GetButtonByID(new_id)));
994 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 993 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
995 button_host->PointerReleasedOnButton(dragged_button, 994 button_host->PointerReleasedOnButton(dragged_button,
996 internal::ShelfButtonHost::MOUSE, 995 internal::ShelfButtonHost::MOUSE,
997 false); 996 false);
998 997
999 // Adding a launcher item at the end (i.e. a panel) canels drag and respects 998 // Adding a shelf item at the end (i.e. a panel) canels drag and respects
1000 // the order. 999 // the order.
1001 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 1, 3); 1000 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 1, 3);
1002 new_id = AddPanel(); 1001 new_id = AddPanel();
1003 id_map.insert(id_map.begin() + 7, 1002 id_map.insert(id_map.begin() + 7,
1004 std::make_pair(new_id, GetButtonByID(new_id))); 1003 std::make_pair(new_id, GetButtonByID(new_id)));
1005 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1004 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1006 button_host->PointerReleasedOnButton(dragged_button, 1005 button_host->PointerReleasedOnButton(dragged_button,
1007 internal::ShelfButtonHost::MOUSE, 1006 internal::ShelfButtonHost::MOUSE,
1008 false); 1007 false);
1009 } 1008 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 1044
1046 // Deleting an item keeps the remaining intact. 1045 // Deleting an item keeps the remaining intact.
1047 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2); 1046 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2);
1048 model_->RemoveItemAt(1); 1047 model_->RemoveItemAt(1);
1049 id_map.erase(id_map.begin() + 1); 1048 id_map.erase(id_map.begin() + 1);
1050 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1049 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1051 button_host->PointerReleasedOnButton(dragged_button, 1050 button_host->PointerReleasedOnButton(dragged_button,
1052 internal::ShelfButtonHost::MOUSE, 1051 internal::ShelfButtonHost::MOUSE,
1053 false); 1052 false);
1054 1053
1055 // Adding a launcher item cancels the drag and respects the order. 1054 // Adding a shelf item cancels the drag and respects the order.
1056 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2); 1055 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2);
1057 LauncherID new_id = AddAppShortcut(); 1056 LauncherID new_id = AddAppShortcut();
1058 id_map.insert(id_map.begin() + 5, 1057 id_map.insert(id_map.begin() + 5,
1059 std::make_pair(new_id, GetButtonByID(new_id))); 1058 std::make_pair(new_id, GetButtonByID(new_id)));
1060 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1059 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1061 button_host->PointerReleasedOnButton(dragged_button, 1060 button_host->PointerReleasedOnButton(dragged_button,
1062 internal::ShelfButtonHost::MOUSE, 1061 internal::ShelfButtonHost::MOUSE,
1063 false); 1062 false);
1064 1063
1065 // Adding a launcher item at the end (i.e. a panel) canels drag and respects 1064 // Adding a shelf item at the end (i.e. a panel) canels drag and respects
1066 // the order. 1065 // the order.
1067 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2); 1066 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2);
1068 new_id = AddPanel(); 1067 new_id = AddPanel();
1069 id_map.insert(id_map.begin() + 7, 1068 id_map.insert(id_map.begin() + 7,
1070 std::make_pair(new_id, GetButtonByID(new_id))); 1069 std::make_pair(new_id, GetButtonByID(new_id)));
1071 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1070 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1072 button_host->PointerReleasedOnButton(dragged_button, 1071 button_host->PointerReleasedOnButton(dragged_button,
1073 internal::ShelfButtonHost::MOUSE, 1072 internal::ShelfButtonHost::MOUSE,
1074 false); 1073 false);
1075 } 1074 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 id_map.begin() + 2, 1138 id_map.begin() + 2,
1140 id_map.begin() + 4); 1139 id_map.begin() + 4);
1141 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1140 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1142 button_host->PointerReleasedOnButton(dragged_button, 1141 button_host->PointerReleasedOnButton(dragged_button,
1143 internal::ShelfButtonHost::MOUSE, 1142 internal::ShelfButtonHost::MOUSE,
1144 false); 1143 false);
1145 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT); 1144 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT);
1146 } 1145 }
1147 1146
1148 // Confirm that item status changes are reflected in the buttons. 1147 // Confirm that item status changes are reflected in the buttons.
1149 TEST_F(ShelfViewTest, LauncherItemStatus) { 1148 TEST_F(ShelfViewTest, ShelfItemStatus) {
1150 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, 1149 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
1151 test_api_->GetButtonCount()); 1150 test_api_->GetButtonCount());
1152 1151
1153 // Add platform app button. 1152 // Add platform app button.
1154 LauncherID last_added = AddPlatformApp(); 1153 LauncherID last_added = AddPlatformApp();
1155 LauncherItem item = GetItemByID(last_added); 1154 LauncherItem item = GetItemByID(last_added);
1156 int index = model_->ItemIndexByID(last_added); 1155 int index = model_->ItemIndexByID(last_added);
1157 internal::ShelfButton* button = GetButtonByID(last_added); 1156 internal::ShelfButton* button = GetButtonByID(last_added);
1158 ASSERT_EQ(internal::ShelfButton::STATE_RUNNING, button->state()); 1157 ASSERT_EQ(internal::ShelfButton::STATE_RUNNING, button->state());
1159 item.status = STATUS_ACTIVE; 1158 item.status = STATUS_ACTIVE;
1160 model_->Set(index, item); 1159 model_->Set(index, item);
1161 ASSERT_EQ(internal::ShelfButton::STATE_ACTIVE, button->state()); 1160 ASSERT_EQ(internal::ShelfButton::STATE_ACTIVE, button->state());
1162 item.status = STATUS_ATTENTION; 1161 item.status = STATUS_ATTENTION;
1163 model_->Set(index, item); 1162 model_->Set(index, item);
1164 ASSERT_EQ(internal::ShelfButton::STATE_ATTENTION, button->state()); 1163 ASSERT_EQ(internal::ShelfButton::STATE_ATTENTION, button->state());
1165 } 1164 }
1166 1165
1167 TEST_F(ShelfViewLegacyShelfLayoutTest, 1166 TEST_F(ShelfViewLegacyShelfLayoutTest,
1168 LauncherItemPositionReflectedOnStateChanged) { 1167 ShelfItemPositionReflectedOnStateChanged) {
1169 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, 1168 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
1170 test_api_->GetButtonCount()); 1169 test_api_->GetButtonCount());
1171 1170
1172 // Add 2 items to the launcher. 1171 // Add 2 items to the shelf.
1173 LauncherID item1_id = AddPlatformApp(); 1172 LauncherID item1_id = AddPlatformApp();
1174 LauncherID item2_id = AddPlatformAppNoWait(); 1173 LauncherID item2_id = AddPlatformAppNoWait();
1175 internal::ShelfButton* item1_button = GetButtonByID(item1_id); 1174 internal::ShelfButton* item1_button = GetButtonByID(item1_id);
1176 internal::ShelfButton* item2_button = GetButtonByID(item2_id); 1175 internal::ShelfButton* item2_button = GetButtonByID(item2_id);
1177 1176
1178 internal::ShelfButton::State state_mask = 1177 internal::ShelfButton::State state_mask =
1179 static_cast<internal::ShelfButton::State>( 1178 static_cast<internal::ShelfButton::State>(
1180 internal::ShelfButton::STATE_NORMAL | 1179 internal::ShelfButton::STATE_NORMAL |
1181 internal::ShelfButton::STATE_HOVERED | 1180 internal::ShelfButton::STATE_HOVERED |
1182 internal::ShelfButton::STATE_RUNNING | 1181 internal::ShelfButton::STATE_RUNNING |
1183 internal::ShelfButton::STATE_ACTIVE | 1182 internal::ShelfButton::STATE_ACTIVE |
1184 internal::ShelfButton::STATE_ATTENTION | 1183 internal::ShelfButton::STATE_ATTENTION |
1185 internal::ShelfButton::STATE_FOCUSED); 1184 internal::ShelfButton::STATE_FOCUSED);
1186 1185
1187 // Clear the button states. 1186 // Clear the button states.
1188 item1_button->ClearState(state_mask); 1187 item1_button->ClearState(state_mask);
1189 item2_button->ClearState(state_mask); 1188 item2_button->ClearState(state_mask);
1190 1189
1191 // Since default alignment in tests is bottom, state is reflected in y-axis. 1190 // Since default alignment in tests is bottom, state is reflected in y-axis.
1192 ASSERT_EQ(item1_button->GetIconBounds().y(), 1191 ASSERT_EQ(item1_button->GetIconBounds().y(),
1193 item2_button->GetIconBounds().y()); 1192 item2_button->GetIconBounds().y());
1194 item1_button->AddState(internal::ShelfButton::STATE_HOVERED); 1193 item1_button->AddState(internal::ShelfButton::STATE_HOVERED);
1195 ASSERT_NE(item1_button->GetIconBounds().y(), 1194 ASSERT_NE(item1_button->GetIconBounds().y(),
1196 item2_button->GetIconBounds().y()); 1195 item2_button->GetIconBounds().y());
1197 item1_button->ClearState(internal::ShelfButton::STATE_HOVERED); 1196 item1_button->ClearState(internal::ShelfButton::STATE_HOVERED);
1198 } 1197 }
1199 1198
1200 // Confirm that item status changes are reflected in the buttons 1199 // Confirm that item status changes are reflected in the buttons
1201 // for platform apps. 1200 // for platform apps.
1202 TEST_F(ShelfViewTest, LauncherItemStatusPlatformApp) { 1201 TEST_F(ShelfViewTest, ShelfItemStatusPlatformApp) {
1203 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, 1202 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
1204 test_api_->GetButtonCount()); 1203 test_api_->GetButtonCount());
1205 1204
1206 // Add platform app button. 1205 // Add platform app button.
1207 LauncherID last_added = AddPlatformApp(); 1206 LauncherID last_added = AddPlatformApp();
1208 LauncherItem item = GetItemByID(last_added); 1207 LauncherItem item = GetItemByID(last_added);
1209 int index = model_->ItemIndexByID(last_added); 1208 int index = model_->ItemIndexByID(last_added);
1210 internal::ShelfButton* button = GetButtonByID(last_added); 1209 internal::ShelfButton* button = GetButtonByID(last_added);
1211 ASSERT_EQ(internal::ShelfButton::STATE_RUNNING, button->state()); 1210 ASSERT_EQ(internal::ShelfButton::STATE_RUNNING, button->state());
1212 item.status = STATUS_ACTIVE; 1211 item.status = STATUS_ACTIVE;
1213 model_->Set(index, item); 1212 model_->Set(index, item);
1214 ASSERT_EQ(internal::ShelfButton::STATE_ACTIVE, button->state()); 1213 ASSERT_EQ(internal::ShelfButton::STATE_ACTIVE, button->state());
1215 item.status = STATUS_ATTENTION; 1214 item.status = STATUS_ATTENTION;
1216 model_->Set(index, item); 1215 model_->Set(index, item);
1217 ASSERT_EQ(internal::ShelfButton::STATE_ATTENTION, button->state()); 1216 ASSERT_EQ(internal::ShelfButton::STATE_ATTENTION, button->state());
1218 } 1217 }
1219 1218
1220 // Confirm that launcher item bounds are correctly updated on shelf changes. 1219 // Confirm that shelf item bounds are correctly updated on shelf changes.
1221 TEST_F(ShelfViewTest, LauncherItemBoundsCheck) { 1220 TEST_F(ShelfViewTest, ShelfItemBoundsCheck) {
1222 VerifyLauncherItemBoundsAreValid(); 1221 VerifyShelfItemBoundsAreValid();
1223 shelf_view_->shelf_layout_manager()->SetAutoHideBehavior( 1222 shelf_view_->shelf_layout_manager()->SetAutoHideBehavior(
1224 SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 1223 SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1225 test_api_->RunMessageLoopUntilAnimationsDone(); 1224 test_api_->RunMessageLoopUntilAnimationsDone();
1226 VerifyLauncherItemBoundsAreValid(); 1225 VerifyShelfItemBoundsAreValid();
1227 shelf_view_->shelf_layout_manager()->SetAutoHideBehavior( 1226 shelf_view_->shelf_layout_manager()->SetAutoHideBehavior(
1228 SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 1227 SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1229 test_api_->RunMessageLoopUntilAnimationsDone(); 1228 test_api_->RunMessageLoopUntilAnimationsDone();
1230 VerifyLauncherItemBoundsAreValid(); 1229 VerifyShelfItemBoundsAreValid();
1231 } 1230 }
1232 1231
1233 TEST_F(ShelfViewTest, ShelfTooltipTest) { 1232 TEST_F(ShelfViewTest, ShelfTooltipTest) {
1234 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, 1233 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
1235 test_api_->GetButtonCount()); 1234 test_api_->GetButtonCount());
1236 1235
1237 // Prepare some items to the launcher. 1236 // Prepare some items to the shelf.
1238 LauncherID app_button_id = AddAppShortcut(); 1237 LauncherID app_button_id = AddAppShortcut();
1239 LauncherID platform_button_id = AddPlatformApp(); 1238 LauncherID platform_button_id = AddPlatformApp();
1240 1239
1241 internal::ShelfButton* app_button = GetButtonByID(app_button_id); 1240 internal::ShelfButton* app_button = GetButtonByID(app_button_id);
1242 internal::ShelfButton* platform_button = GetButtonByID(platform_button_id); 1241 internal::ShelfButton* platform_button = GetButtonByID(platform_button_id);
1243 1242
1244 internal::ShelfButtonHost* button_host = shelf_view_; 1243 internal::ShelfButtonHost* button_host = shelf_view_;
1245 internal::ShelfTooltipManager* tooltip_manager = 1244 internal::ShelfTooltipManager* tooltip_manager =
1246 shelf_view_->tooltip_manager(); 1245 shelf_view_->tooltip_manager();
1247 1246
(...skipping 21 matching lines...) Expand all
1269 tooltip_manager->Close(); 1268 tooltip_manager->Close();
1270 1269
1271 // Next time: enter app_button -> move immediately to tab_button. 1270 // Next time: enter app_button -> move immediately to tab_button.
1272 button_host->MouseEnteredButton(app_button); 1271 button_host->MouseEnteredButton(app_button);
1273 button_host->MouseExitedButton(app_button); 1272 button_host->MouseExitedButton(app_button);
1274 button_host->MouseEnteredButton(platform_button); 1273 button_host->MouseEnteredButton(platform_button);
1275 EXPECT_FALSE(tooltip_manager->IsVisible()); 1274 EXPECT_FALSE(tooltip_manager->IsVisible());
1276 EXPECT_EQ(platform_button, GetTooltipAnchorView()); 1275 EXPECT_EQ(platform_button, GetTooltipAnchorView());
1277 } 1276 }
1278 1277
1279 // Verify a fix for crash caused by a tooltip update for a deleted launcher 1278 // Verify a fix for crash caused by a tooltip update for a deletedshelf
1280 // button, see crbug.com/288838. 1279 // button, see crbug.com/288838.
1281 TEST_F(ShelfViewTest, RemovingItemClosesTooltip) { 1280 TEST_F(ShelfViewTest, RemovingItemClosesTooltip) {
1282 internal::ShelfButtonHost* button_host = shelf_view_; 1281 internal::ShelfButtonHost* button_host = shelf_view_;
1283 internal::ShelfTooltipManager* tooltip_manager = 1282 internal::ShelfTooltipManager* tooltip_manager =
1284 shelf_view_->tooltip_manager(); 1283 shelf_view_->tooltip_manager();
1285 1284
1286 // Add an item to the launcher. 1285 // Add an item to the shelf.
1287 LauncherID app_button_id = AddAppShortcut(); 1286 LauncherID app_button_id = AddAppShortcut();
1288 internal::ShelfButton* app_button = GetButtonByID(app_button_id); 1287 internal::ShelfButton* app_button = GetButtonByID(app_button_id);
1289 1288
1290 // Spawn a tooltip on that item. 1289 // Spawn a tooltip on that item.
1291 button_host->MouseEnteredButton(app_button); 1290 button_host->MouseEnteredButton(app_button);
1292 ShowTooltip(); 1291 ShowTooltip();
1293 EXPECT_TRUE(tooltip_manager->IsVisible()); 1292 EXPECT_TRUE(tooltip_manager->IsVisible());
1294 1293
1295 // Remove the app shortcut while the tooltip is open. The tooltip should be 1294 // Remove the app shortcut while the tooltip is open. The tooltip should be
1296 // closed. 1295 // closed.
1297 RemoveByID(app_button_id); 1296 RemoveByID(app_button_id);
1298 EXPECT_FALSE(tooltip_manager->IsVisible()); 1297 EXPECT_FALSE(tooltip_manager->IsVisible());
1299 1298
1300 // Change the shelf layout. This should not crash. 1299 // Change the shelf layout. This should not crash.
1301 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, 1300 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT,
1302 Shell::GetPrimaryRootWindow()); 1301 Shell::GetPrimaryRootWindow());
1303 } 1302 }
1304 1303
1305 // Changing the shelf alignment closes any open tooltip. 1304 // Changing the shelf alignment closes any open tooltip.
1306 TEST_F(ShelfViewTest, ShelfAlignmentClosesTooltip) { 1305 TEST_F(ShelfViewTest, ShelfAlignmentClosesTooltip) {
1307 internal::ShelfButtonHost* button_host = shelf_view_; 1306 internal::ShelfButtonHost* button_host = shelf_view_;
1308 internal::ShelfTooltipManager* tooltip_manager = 1307 internal::ShelfTooltipManager* tooltip_manager =
1309 shelf_view_->tooltip_manager(); 1308 shelf_view_->tooltip_manager();
1310 1309
1311 // Add an item to the launcher. 1310 // Add an item to the shelf.
1312 LauncherID app_button_id = AddAppShortcut(); 1311 LauncherID app_button_id = AddAppShortcut();
1313 internal::ShelfButton* app_button = GetButtonByID(app_button_id); 1312 internal::ShelfButton* app_button = GetButtonByID(app_button_id);
1314 1313
1315 // Spawn a tooltip on the item. 1314 // Spawn a tooltip on the item.
1316 button_host->MouseEnteredButton(app_button); 1315 button_host->MouseEnteredButton(app_button);
1317 ShowTooltip(); 1316 ShowTooltip();
1318 EXPECT_TRUE(tooltip_manager->IsVisible()); 1317 EXPECT_TRUE(tooltip_manager->IsVisible());
1319 1318
1320 // Changing shelf alignment hides the tooltip. 1319 // Changing shelf alignment hides the tooltip.
1321 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, 1320 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT,
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 const gfx::Rect& app_list_ideal_bounds = 1468 const gfx::Rect& app_list_ideal_bounds =
1470 test_api_->GetIdealBoundsByIndex(app_list_button_index); 1469 test_api_->GetIdealBoundsByIndex(app_list_button_index);
1471 const gfx::Rect& app_list_bounds = 1470 const gfx::Rect& app_list_bounds =
1472 test_api_->GetBoundsByIndex(app_list_button_index); 1471 test_api_->GetBoundsByIndex(app_list_button_index);
1473 EXPECT_EQ(app_list_bounds, app_list_ideal_bounds); 1472 EXPECT_EQ(app_list_bounds, app_list_ideal_bounds);
1474 } 1473 }
1475 1474
1476 // Checks the overflow bubble size when an item is ripped off and re-inserted. 1475 // Checks the overflow bubble size when an item is ripped off and re-inserted.
1477 TEST_F(ShelfViewTest, OverflowBubbleSize) { 1476 TEST_F(ShelfViewTest, OverflowBubbleSize) {
1478 // Replace ShelfDelegate. 1477 // Replace ShelfDelegate.
1479 test::ShellTestApi test_api(Shell::GetInstance()); 1478 ShellTestApi test_api(Shell::GetInstance());
1480 test_api.SetShelfDelegate(NULL); 1479 test_api.SetShelfDelegate(NULL);
1481 ShelfDelegate *delegate = new TestShelfDelegateForShelfView(model_); 1480 ShelfDelegate *delegate = new TestShelfDelegateForShelfView(model_);
1482 test_api.SetShelfDelegate(delegate); 1481 test_api.SetShelfDelegate(delegate);
1483 test::LauncherTestAPI( 1482 ShelfTestAPI(Shelf::ForPrimaryDisplay()).SetShelfDelegate(delegate);
1484 Launcher::ForPrimaryDisplay()).SetShelfDelegate(delegate);
1485 test_api_->SetShelfDelegate(delegate); 1483 test_api_->SetShelfDelegate(delegate);
1486 1484
1487 AddButtonsUntilOverflow(); 1485 AddButtonsUntilOverflow();
1488 1486
1489 // Show overflow bubble. 1487 // Show overflow bubble.
1490 test_api_->ShowOverflowBubble(); 1488 test_api_->ShowOverflowBubble();
1491 ASSERT_TRUE(test_api_->overflow_bubble() && 1489 ASSERT_TRUE(test_api_->overflow_bubble() &&
1492 test_api_->overflow_bubble()->IsShowing()); 1490 test_api_->overflow_bubble()->IsShowing());
1493 1491
1494 ShelfViewTestAPI test_for_overflow_view( 1492 ShelfViewTestAPI test_for_overflow_view(
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1601 EXPECT_TRUE(drag_reinsert_bounds.Contains(last_point)); 1599 EXPECT_TRUE(drag_reinsert_bounds.Contains(last_point));
1602 } 1600 }
1603 1601
1604 // Check the drag insertion bounds of shelf view in multi monitor environment. 1602 // Check the drag insertion bounds of shelf view in multi monitor environment.
1605 TEST_F(ShelfViewTest, CheckDragInsertBoundsWithMultiMonitor) { 1603 TEST_F(ShelfViewTest, CheckDragInsertBoundsWithMultiMonitor) {
1606 // win8-aura doesn't support multiple display. 1604 // win8-aura doesn't support multiple display.
1607 if (!SupportsMultipleDisplays()) 1605 if (!SupportsMultipleDisplays())
1608 return; 1606 return;
1609 1607
1610 UpdateDisplay("800x600,800x600"); 1608 UpdateDisplay("800x600,800x600");
1611 Launcher* secondary_launcher = 1609 Shelf* secondary_shelf = Shelf::ForWindow(Shell::GetAllRootWindows()[1]);
1612 Launcher::ForWindow(Shell::GetAllRootWindows()[1]);
1613 internal::ShelfView* shelf_view_for_secondary = 1610 internal::ShelfView* shelf_view_for_secondary =
1614 test::LauncherTestAPI(secondary_launcher).shelf_view(); 1611 ShelfTestAPI(secondary_shelf).shelf_view();
1615 1612
1616 // The bounds should be big enough for 4 buttons + overflow chevron. 1613 // The bounds should be big enough for 4 buttons + overflow chevron.
1617 shelf_view_for_secondary->SetBounds(0, 0, 500, 1614 shelf_view_for_secondary->SetBounds(0, 0, 500,
1618 internal::ShelfLayoutManager::GetPreferredShelfSize()); 1615 internal::ShelfLayoutManager::GetPreferredShelfSize());
1619 1616
1620 ShelfViewTestAPI test_api_for_secondary(shelf_view_for_secondary); 1617 ShelfViewTestAPI test_api_for_secondary(shelf_view_for_secondary);
1621 // Speeds up animation for test. 1618 // Speeds up animation for test.
1622 test_api_for_secondary.SetAnimationDuration(1); 1619 test_api_for_secondary.SetAnimationDuration(1);
1623 1620
1624 AddButtonsUntilOverflow(); 1621 AddButtonsUntilOverflow();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1685 1682
1686 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, second_root); 1683 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, second_root);
1687 ASSERT_EQ(SHELF_ALIGNMENT_LEFT, 1684 ASSERT_EQ(SHELF_ALIGNMENT_LEFT,
1688 Shell::GetInstance()->GetShelfAlignment(second_root)); 1685 Shell::GetInstance()->GetShelfAlignment(second_root));
1689 1686
1690 // Initially, app list and browser shortcut are added. 1687 // Initially, app list and browser shortcut are added.
1691 EXPECT_EQ(2, model_->item_count()); 1688 EXPECT_EQ(2, model_->item_count());
1692 int browser_index = model_->GetItemIndexForType(TYPE_BROWSER_SHORTCUT); 1689 int browser_index = model_->GetItemIndexForType(TYPE_BROWSER_SHORTCUT);
1693 EXPECT_GT(browser_index, 0); 1690 EXPECT_GT(browser_index, 0);
1694 1691
1695 Launcher* secondary_launcher = Launcher::ForWindow(second_root); 1692 Shelf* secondary_shelf = Shelf::ForWindow(second_root);
1696 internal::ShelfView* shelf_view_for_secondary = 1693 internal::ShelfView* shelf_view_for_secondary =
1697 test::LauncherTestAPI(secondary_launcher).shelf_view(); 1694 ShelfTestAPI(secondary_shelf).shelf_view();
1698 1695
1699 ShelfViewTestAPI test_api_for_secondary_shelf_view(shelf_view_for_secondary); 1696 ShelfViewTestAPI test_api_for_secondary_shelf_view(shelf_view_for_secondary);
1700 internal::ShelfButton* button = 1697 internal::ShelfButton* button =
1701 test_api_for_secondary_shelf_view.GetButton(browser_index); 1698 test_api_for_secondary_shelf_view.GetButton(browser_index);
1702 1699
1703 // Fetch the start point of dragging. 1700 // Fetch the start point of dragging.
1704 gfx::Point start_point = button->GetBoundsInScreen().CenterPoint(); 1701 gfx::Point start_point = button->GetBoundsInScreen().CenterPoint();
1705 wm::ConvertPointFromScreen(second_root, &start_point); 1702 wm::ConvertPointFromScreen(second_root, &start_point);
1706 1703
1707 aura::test::EventGenerator generator(second_root, start_point); 1704 aura::test::EventGenerator generator(second_root, start_point);
1708 1705
1709 // Rip off the browser item. 1706 // Rip off the browser item.
1710 generator.PressLeftButton(); 1707 generator.PressLeftButton();
1711 generator.MoveMouseTo(start_point.x() + 400, start_point.y()); 1708 generator.MoveMouseTo(start_point.x() + 400, start_point.y());
1712 test_api_for_secondary_shelf_view.RunMessageLoopUntilAnimationsDone(); 1709 test_api_for_secondary_shelf_view.RunMessageLoopUntilAnimationsDone();
1713 EXPECT_TRUE(test_api_for_secondary_shelf_view.IsRippedOffFromShelf()); 1710 EXPECT_TRUE(test_api_for_secondary_shelf_view.IsRippedOffFromShelf());
1714 } 1711 }
1715 1712
1716 // Checks various drag and drop operations from OverflowBubble to Shelf. 1713 // Checks various drag and drop operations from OverflowBubble to Shelf.
1717 TEST_F(ShelfViewTest, CheckDragAndDropFromOverflowBubbleToShelf) { 1714 TEST_F(ShelfViewTest, CheckDragAndDropFromOverflowBubbleToShelf) {
1718 // Replace LauncherDelegate. 1715 // Replace ShelfDelegate.
1719 test::ShellTestApi test_api(Shell::GetInstance()); 1716 ShellTestApi test_api(Shell::GetInstance());
1720 test_api.SetShelfDelegate(NULL); 1717 test_api.SetShelfDelegate(NULL);
1721 ShelfDelegate *delegate = new TestShelfDelegateForShelfView(model_); 1718 ShelfDelegate *delegate = new TestShelfDelegateForShelfView(model_);
1722 test_api.SetShelfDelegate(delegate); 1719 test_api.SetShelfDelegate(delegate);
1723 test::LauncherTestAPI( 1720 ShelfTestAPI(Shelf::ForPrimaryDisplay()).SetShelfDelegate(delegate);
1724 Launcher::ForPrimaryDisplay()).SetShelfDelegate(delegate);
1725 test_api_->SetShelfDelegate(delegate); 1721 test_api_->SetShelfDelegate(delegate);
1726 1722
1727 AddButtonsUntilOverflow(); 1723 AddButtonsUntilOverflow();
1728 1724
1729 TestDraggingAnItemFromOverflowToShelf(false); 1725 TestDraggingAnItemFromOverflowToShelf(false);
1730 TestDraggingAnItemFromOverflowToShelf(true); 1726 TestDraggingAnItemFromOverflowToShelf(true);
1731 } 1727 }
1732 1728
1733 class ShelfViewVisibleBoundsTest : public ShelfViewTest, 1729 class ShelfViewVisibleBoundsTest : public ShelfViewTest,
1734 public testing::WithParamInterface<bool> { 1730 public testing::WithParamInterface<bool> {
1735 public: 1731 public:
1736 ShelfViewVisibleBoundsTest() : text_direction_change_(GetParam()) {} 1732 ShelfViewVisibleBoundsTest() : text_direction_change_(GetParam()) {}
1737 1733
1738 void CheckAllItemsAreInBounds() { 1734 void CheckAllItemsAreInBounds() {
1739 gfx::Rect visible_bounds = shelf_view_->GetVisibleItemsBoundsInScreen(); 1735 gfx::Rect visible_bounds = shelf_view_->GetVisibleItemsBoundsInScreen();
1740 gfx::Rect launcher_bounds = shelf_view_->GetBoundsInScreen(); 1736 gfx::Rect shelf_bounds = shelf_view_->GetBoundsInScreen();
1741 EXPECT_TRUE(launcher_bounds.Contains(visible_bounds)); 1737 EXPECT_TRUE(shelf_bounds.Contains(visible_bounds));
1742 for (int i = 0; i < test_api_->GetButtonCount(); ++i) 1738 for (int i = 0; i < test_api_->GetButtonCount(); ++i)
1743 if (internal::ShelfButton* button = test_api_->GetButton(i)) 1739 if (internal::ShelfButton* button = test_api_->GetButton(i))
1744 EXPECT_TRUE(visible_bounds.Contains(button->GetBoundsInScreen())); 1740 EXPECT_TRUE(visible_bounds.Contains(button->GetBoundsInScreen()));
1745 CheckAppListButtonIsInBounds(); 1741 CheckAppListButtonIsInBounds();
1746 } 1742 }
1747 1743
1748 void CheckAppListButtonIsInBounds() { 1744 void CheckAppListButtonIsInBounds() {
1749 gfx::Rect visible_bounds = shelf_view_->GetVisibleItemsBoundsInScreen(); 1745 gfx::Rect visible_bounds = shelf_view_->GetVisibleItemsBoundsInScreen();
1750 gfx::Rect app_list_button_bounds = shelf_view_->GetAppListButtonView()-> 1746 gfx::Rect app_list_button_bounds = shelf_view_->GetAppListButtonView()->
1751 GetBoundsInScreen(); 1747 GetBoundsInScreen();
(...skipping 21 matching lines...) Expand all
1773 test_api_->RunMessageLoopUntilAnimationsDone(); 1769 test_api_->RunMessageLoopUntilAnimationsDone();
1774 CheckAllItemsAreInBounds(); 1770 CheckAllItemsAreInBounds();
1775 } 1771 }
1776 1772
1777 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool()); 1773 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool());
1778 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest, 1774 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest,
1779 testing::Bool()); 1775 testing::Bool());
1780 1776
1781 } // namespace test 1777 } // namespace test
1782 } // namespace ash 1778 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698