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
3 // found in the LICENSE file.
5 #include "ash/shelf/shelf_view.h"
10 #include "ash/root_window_controller.h"
11 #include "ash/shelf/app_list_button.h"
12 #include "ash/shelf/overflow_bubble.h"
13 #include "ash/shelf/overflow_bubble_view.h"
14 #include "ash/shelf/shelf.h"
15 #include "ash/shelf/shelf_button.h"
16 #include "ash/shelf/shelf_constants.h"
17 #include "ash/shelf/shelf_icon_observer.h"
18 #include "ash/shelf/shelf_item_delegate_manager.h"
19 #include "ash/shelf/shelf_layout_manager.h"
20 #include "ash/shelf/shelf_model.h"
21 #include "ash/shelf/shelf_tooltip_manager.h"
22 #include "ash/shelf/shelf_widget.h"
23 #include "ash/shell.h"
24 #include "ash/shell_window_ids.h"
25 #include "ash/test/ash_test_base.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"
29 #include "ash/test/shell_test_api.h"
30 #include "ash/test/test_shelf_delegate.h"
31 #include "ash/test/test_shelf_item_delegate.h"
32 #include "base/basictypes.h"
33 #include "base/compiler_specific.h"
34 #include "base/memory/scoped_ptr.h"
35 #include "base/strings/string_number_conversions.h"
36 #include "ui/aura/test/aura_test_base.h"
37 #include "ui/aura/window.h"
38 #include "ui/aura/window_event_dispatcher.h"
39 #include "ui/base/l10n/l10n_util.h"
40 #include "ui/compositor/layer.h"
41 #include "ui/events/event.h"
42 #include "ui/events/event_constants.h"
43 #include "ui/events/event_utils.h"
44 #include "ui/events/test/event_generator.h"
45 #include "ui/views/view_model.h"
46 #include "ui/views/widget/widget.h"
47 #include "ui/views/widget/widget_delegate.h"
48 #include "ui/wm/core/coordinate_conversion.h"
53 ////////////////////////////////////////////////////////////////////////////////
54 // ShelfIconObserver tests.
56 class TestShelfIconObserver
: public ShelfIconObserver
{
58 explicit TestShelfIconObserver(Shelf
* shelf
)
60 change_notified_(false) {
62 shelf_
->AddIconObserver(this);
65 ~TestShelfIconObserver() override
{
67 shelf_
->RemoveIconObserver(this);
70 // ShelfIconObserver implementation.
71 void OnShelfIconPositionsChanged() override
{ change_notified_
= true; }
73 int change_notified() const { return change_notified_
; }
74 void Reset() { change_notified_
= false; }
78 bool change_notified_
;
80 DISALLOW_COPY_AND_ASSIGN(TestShelfIconObserver
);
83 class ShelfViewIconObserverTest
: public AshTestBase
{
85 ShelfViewIconObserverTest() {}
86 ~ShelfViewIconObserverTest() override
{}
88 void SetUp() override
{
90 Shelf
* shelf
= Shelf::ForPrimaryDisplay();
91 observer_
.reset(new TestShelfIconObserver(shelf
));
93 shelf_view_test_
.reset(
94 new ShelfViewTestAPI(ShelfTestAPI(shelf
).shelf_view()));
95 shelf_view_test_
->SetAnimationDuration(1);
98 void TearDown() override
{
100 AshTestBase::TearDown();
103 TestShelfIconObserver
* observer() { return observer_
.get(); }
105 ShelfViewTestAPI
* shelf_view_test() {
106 return shelf_view_test_
.get();
109 Shelf
* ShelfForSecondaryDisplay() {
110 return Shelf::ForWindow(Shell::GetAllRootWindows()[1]);
114 scoped_ptr
<TestShelfIconObserver
> observer_
;
115 scoped_ptr
<ShelfViewTestAPI
> shelf_view_test_
;
117 DISALLOW_COPY_AND_ASSIGN(ShelfViewIconObserverTest
);
120 // TestShelfItemDelegate which tracks whether it gets selected.
121 class ShelfItemSelectionTracker
: public TestShelfItemDelegate
{
123 ShelfItemSelectionTracker() : TestShelfItemDelegate(NULL
), selected_(false) {
126 ~ShelfItemSelectionTracker() override
{}
128 // Resets to the initial state.
129 void Reset() { selected_
= false; }
131 // Returns true if the delegate was selected.
136 // TestShelfItemDelegate:
137 bool ItemSelected(const ui::Event
& event
) override
{
145 DISALLOW_COPY_AND_ASSIGN(ShelfItemSelectionTracker
);
148 TEST_F(ShelfViewIconObserverTest
, AddRemove
) {
149 TestShelfDelegate
* shelf_delegate
= TestShelfDelegate::instance();
150 ASSERT_TRUE(shelf_delegate
);
152 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
153 params
.ownership
= views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET
;
154 params
.bounds
= gfx::Rect(0, 0, 200, 200);
155 params
.context
= CurrentContext();
157 scoped_ptr
<views::Widget
> widget(new views::Widget());
158 widget
->Init(params
);
159 shelf_delegate
->AddShelfItem(widget
->GetNativeWindow());
160 shelf_view_test()->RunMessageLoopUntilAnimationsDone();
161 EXPECT_TRUE(observer()->change_notified());
165 widget
->GetNativeWindow()->parent()->RemoveChild(widget
->GetNativeWindow());
166 shelf_view_test()->RunMessageLoopUntilAnimationsDone();
167 EXPECT_TRUE(observer()->change_notified());
171 // Sometimes fails on trybots on win7_aura. http://crbug.com/177135
173 #define MAYBE_AddRemoveWithMultipleDisplays \
174 DISABLED_AddRemoveWithMultipleDisplays
176 #define MAYBE_AddRemoveWithMultipleDisplays \
177 AddRemoveWithMultipleDisplays
179 // Make sure creating/deleting an window on one displays notifies a
180 // shelf on external display as well as one on primary.
181 TEST_F(ShelfViewIconObserverTest
, MAYBE_AddRemoveWithMultipleDisplays
) {
182 UpdateDisplay("400x400,400x400");
183 TestShelfIconObserver
second_observer(ShelfForSecondaryDisplay());
185 TestShelfDelegate
* shelf_delegate
= TestShelfDelegate::instance();
186 ASSERT_TRUE(shelf_delegate
);
188 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
189 params
.ownership
= views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET
;
190 params
.bounds
= gfx::Rect(0, 0, 200, 200);
191 params
.context
= CurrentContext();
193 scoped_ptr
<views::Widget
> widget(new views::Widget());
194 widget
->Init(params
);
195 shelf_delegate
->AddShelfItem(widget
->GetNativeWindow());
196 shelf_view_test()->RunMessageLoopUntilAnimationsDone();
197 EXPECT_TRUE(observer()->change_notified());
198 EXPECT_TRUE(second_observer
.change_notified());
200 second_observer
.Reset();
202 widget
->GetNativeWindow()->parent()->RemoveChild(widget
->GetNativeWindow());
203 shelf_view_test()->RunMessageLoopUntilAnimationsDone();
204 EXPECT_TRUE(observer()->change_notified());
205 EXPECT_TRUE(second_observer
.change_notified());
208 second_observer
.Reset();
211 TEST_F(ShelfViewIconObserverTest
, BoundsChanged
) {
212 ShelfWidget
* widget
= Shell::GetPrimaryRootWindowController()->shelf();
213 Shelf
* shelf
= Shelf::ForPrimaryDisplay();
214 gfx::Size shelf_size
= widget
->GetWindowBoundsInScreen().size();
215 shelf_size
.set_width(shelf_size
.width() / 2);
216 ASSERT_GT(shelf_size
.width(), 0);
217 shelf
->SetShelfViewBounds(gfx::Rect(shelf_size
));
218 // No animation happens for ShelfView bounds change.
219 EXPECT_TRUE(observer()->change_notified());
223 ////////////////////////////////////////////////////////////////////////////////
226 // Simple ShelfDelegate implmentation for ShelfViewTest.OverflowBubbleSize
227 // and CheckDragAndDropFromOverflowBubbleToShelf
228 class TestShelfDelegateForShelfView
: public ShelfDelegate
{
230 explicit TestShelfDelegateForShelfView(ShelfModel
* model
)
232 ~TestShelfDelegateForShelfView() override
{}
234 // ShelfDelegate overrides:
235 void OnShelfCreated(Shelf
* shelf
) override
{}
237 void OnShelfDestroyed(Shelf
* shelf
) override
{}
239 ShelfID
GetShelfIDForAppID(const std::string
& app_id
) override
{
241 EXPECT_TRUE(base::StringToInt(app_id
, &id
));
245 const std::string
& GetAppIDForShelfID(ShelfID id
) override
{
246 // Use |app_id_| member variable because returning a reference to local
247 // variable is not allowed.
248 app_id_
= base::IntToString(id
);
252 void PinAppWithID(const std::string
& app_id
) override
{}
254 bool IsAppPinned(const std::string
& app_id
) override
{
255 // Returns true for ShelfViewTest.OverflowBubbleSize. To test ripping off in
256 // that test, an item is already pinned state.
260 bool CanPin() const override
{ return true; }
262 void UnpinAppWithID(const std::string
& app_id
) override
{
264 EXPECT_TRUE(base::StringToInt(app_id
, &id
));
266 int index
= model_
->ItemIndexByID(id
);
269 model_
->RemoveItemAt(index
);
275 // Temp member variable for returning a value. See the comment in the
276 // GetAppIDForShelfID().
279 DISALLOW_COPY_AND_ASSIGN(TestShelfDelegateForShelfView
);
282 class ShelfViewTest
: public AshTestBase
{
288 item_manager_(NULL
) {}
289 ~ShelfViewTest() override
{}
291 void SetUp() override
{
292 AshTestBase::SetUp();
293 test::ShellTestApi
test_api(Shell::GetInstance());
294 model_
= test_api
.shelf_model();
295 Shelf
* shelf
= Shelf::ForPrimaryDisplay();
296 shelf_view_
= ShelfTestAPI(shelf
).shelf_view();
298 // The bounds should be big enough for 4 buttons + overflow chevron.
299 shelf_view_
->SetBounds(0, 0, 500, kShelfSize
);
301 test_api_
.reset(new ShelfViewTestAPI(shelf_view_
));
302 test_api_
->SetAnimationDuration(1); // Speeds up animation for test.
304 item_manager_
= Shell::GetInstance()->shelf_item_delegate_manager();
305 DCHECK(item_manager_
);
307 // Add browser shortcut shelf item at index 0 for test.
308 AddBrowserShortcut();
311 void TearDown() override
{
313 AshTestBase::TearDown();
317 void CreateAndSetShelfItemDelegateForID(ShelfID id
) {
318 scoped_ptr
<ShelfItemDelegate
> delegate(new TestShelfItemDelegate(NULL
));
319 item_manager_
->SetShelfItemDelegate(id
, delegate
.Pass());
322 ShelfID
AddBrowserShortcut() {
323 ShelfItem browser_shortcut
;
324 browser_shortcut
.type
= TYPE_BROWSER_SHORTCUT
;
326 ShelfID id
= model_
->next_id();
327 model_
->AddAt(browser_index_
, browser_shortcut
);
328 CreateAndSetShelfItemDelegateForID(id
);
329 test_api_
->RunMessageLoopUntilAnimationsDone();
333 ShelfID
AddAppShortcut() {
335 item
.type
= TYPE_APP_SHORTCUT
;
336 item
.status
= STATUS_CLOSED
;
338 ShelfID id
= model_
->next_id();
340 CreateAndSetShelfItemDelegateForID(id
);
341 test_api_
->RunMessageLoopUntilAnimationsDone();
346 ShelfID id
= AddPanelNoWait();
347 test_api_
->RunMessageLoopUntilAnimationsDone();
351 ShelfID
AddPlatformAppNoWait() {
353 item
.type
= TYPE_PLATFORM_APP
;
354 item
.status
= STATUS_RUNNING
;
356 ShelfID id
= model_
->next_id();
358 CreateAndSetShelfItemDelegateForID(id
);
362 ShelfID
AddPanelNoWait() {
364 item
.type
= TYPE_APP_PANEL
;
365 item
.status
= STATUS_RUNNING
;
367 ShelfID id
= model_
->next_id();
369 CreateAndSetShelfItemDelegateForID(id
);
373 ShelfID
AddPlatformApp() {
374 ShelfID id
= AddPlatformAppNoWait();
375 test_api_
->RunMessageLoopUntilAnimationsDone();
379 void RemoveByID(ShelfID id
) {
380 model_
->RemoveItemAt(model_
->ItemIndexByID(id
));
381 test_api_
->RunMessageLoopUntilAnimationsDone();
384 ShelfButton
* GetButtonByID(ShelfID id
) {
385 int index
= model_
->ItemIndexByID(id
);
386 return test_api_
->GetButton(index
);
389 ShelfItem
GetItemByID(ShelfID id
) {
390 ShelfItems::const_iterator items
= model_
->ItemByID(id
);
395 const std::vector
<std::pair
<ShelfID
, views::View
*> >& id_map
) {
396 size_t map_index
= 0;
397 for (size_t model_index
= 0;
398 model_index
< model_
->items().size();
400 ShelfItem item
= model_
->items()[model_index
];
401 ShelfID id
= item
.id
;
402 EXPECT_EQ(id_map
[map_index
].first
, id
);
403 EXPECT_EQ(id_map
[map_index
].second
, GetButtonByID(id
));
406 ASSERT_EQ(map_index
, id_map
.size());
409 void VerifyShelfItemBoundsAreValid() {
410 for (int i
= 0; i
<= test_api_
->GetLastVisibleIndex(); ++i
) {
411 if (test_api_
->GetButton(i
)) {
412 gfx::Rect shelf_view_bounds
= shelf_view_
->GetLocalBounds();
413 gfx::Rect item_bounds
= test_api_
->GetBoundsByIndex(i
);
414 EXPECT_GE(item_bounds
.x(), 0);
415 EXPECT_GE(item_bounds
.y(), 0);
416 EXPECT_LE(item_bounds
.right(), shelf_view_bounds
.width());
417 EXPECT_LE(item_bounds
.bottom(), shelf_view_bounds
.height());
422 ShelfButton
* SimulateButtonPressed(ShelfButtonHost::Pointer pointer
,
424 ShelfButtonHost
* button_host
= shelf_view_
;
425 ShelfButton
* button
= test_api_
->GetButton(button_index
);
426 ui::MouseEvent
click_event(ui::ET_MOUSE_PRESSED
, gfx::Point(),
427 button
->GetBoundsInScreen().origin(),
428 ui::EventTimeForNow(), 0, 0);
429 button_host
->PointerPressedOnButton(button
, pointer
, click_event
);
433 // Simulates a single mouse click.
434 void SimulateClick(int button_index
) {
435 ShelfButtonHost
* button_host
= shelf_view_
;
436 ShelfButton
* button
=
437 SimulateButtonPressed(ShelfButtonHost::MOUSE
, button_index
);
438 ui::MouseEvent
release_event(ui::ET_MOUSE_RELEASED
, gfx::Point(),
439 button
->GetBoundsInScreen().origin(),
440 ui::EventTimeForNow(), 0, 0);
441 test_api_
->ButtonPressed(button
, release_event
);
442 button_host
->PointerReleasedOnButton(button
, ShelfButtonHost::MOUSE
, false);
445 // Simulates the second click of a double click.
446 void SimulateDoubleClick(int button_index
) {
447 ShelfButtonHost
* button_host
= shelf_view_
;
448 ShelfButton
* button
=
449 SimulateButtonPressed(ShelfButtonHost::MOUSE
, button_index
);
450 ui::MouseEvent
release_event(ui::ET_MOUSE_RELEASED
, gfx::Point(),
451 button
->GetBoundsInScreen().origin(),
452 ui::EventTimeForNow(), ui::EF_IS_DOUBLE_CLICK
,
454 test_api_
->ButtonPressed(button
, release_event
);
455 button_host
->PointerReleasedOnButton(button
, ShelfButtonHost::MOUSE
, false);
458 views::View
* SimulateDrag(ShelfButtonHost::Pointer pointer
,
460 int destination_index
) {
461 ShelfButtonHost
* button_host
= shelf_view_
;
462 views::View
* button
= SimulateButtonPressed(pointer
, button_index
);
465 views::View
* destination
= test_api_
->GetButton(destination_index
);
466 ui::MouseEvent
drag_event(
467 ui::ET_MOUSE_DRAGGED
, gfx::Point(destination
->x() - button
->x(),
468 destination
->y() - button
->y()),
469 destination
->GetBoundsInScreen().origin(), ui::EventTimeForNow(), 0, 0);
470 button_host
->PointerDraggedOnButton(button
, pointer
, drag_event
);
474 void SetupForDragTest(
475 std::vector
<std::pair
<ShelfID
, views::View
*> >* id_map
) {
476 // Initialize |id_map| with the automatically-created shelf buttons.
477 for (size_t i
= 0; i
< model_
->items().size(); ++i
) {
478 ShelfButton
* button
= test_api_
->GetButton(i
);
479 id_map
->push_back(std::make_pair(model_
->items()[i
].id
, button
));
481 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map
));
483 // Add 5 app shelf buttons for testing.
484 for (int i
= 0; i
< 5; ++i
) {
485 ShelfID id
= AddAppShortcut();
486 // App Icon is located at index 0, and browser shortcut is located at
487 // index 1. So we should start to add app shortcut at index 2.
488 id_map
->insert(id_map
->begin() + (i
+ browser_index_
+ 1),
489 std::make_pair(id
, GetButtonByID(id
)));
491 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map
));
494 views::View
* GetTooltipAnchorView() {
495 return shelf_view_
->tooltip_manager()->anchor_
;
498 void AddButtonsUntilOverflow() {
500 while (!test_api_
->IsOverflowButtonVisible()) {
503 ASSERT_LT(items_added
, 10000);
508 shelf_view_
->tooltip_manager()->ShowInternal();
511 void TestDraggingAnItemFromOverflowToShelf(bool cancel
) {
512 test_api_
->ShowOverflowBubble();
513 ASSERT_TRUE(test_api_
->overflow_bubble() &&
514 test_api_
->overflow_bubble()->IsShowing());
516 ash::test::ShelfViewTestAPI
test_api_for_overflow(
517 test_api_
->overflow_bubble()->shelf_view());
519 int total_item_count
= model_
->item_count();
521 int last_visible_item_id_in_shelf
=
522 GetItemId(test_api_
->GetLastVisibleIndex());
523 int second_last_visible_item_id_in_shelf
=
524 GetItemId(test_api_
->GetLastVisibleIndex() - 1);
525 int first_visible_item_id_in_overflow
=
526 GetItemId(test_api_for_overflow
.GetFirstVisibleIndex());
527 int second_last_visible_item_id_in_overflow
=
528 GetItemId(test_api_for_overflow
.GetLastVisibleIndex() - 1);
530 int drag_item_index
=
531 test_api_for_overflow
.GetLastVisibleIndex();
532 ShelfID drag_item_id
= GetItemId(drag_item_index
);
533 ShelfButton
* drag_button
= test_api_for_overflow
.GetButton(drag_item_index
);
534 gfx::Point center_point_of_drag_item
=
535 drag_button
->GetBoundsInScreen().CenterPoint();
537 ui::test::EventGenerator
generator(ash::Shell::GetPrimaryRootWindow(),
538 center_point_of_drag_item
);
539 // Rip an item off to OverflowBubble.
540 generator
.PressLeftButton();
541 gfx::Point
rip_off_point(center_point_of_drag_item
.x(), 0);
542 generator
.MoveMouseTo(rip_off_point
);
543 test_api_for_overflow
.RunMessageLoopUntilAnimationsDone();
544 ASSERT_TRUE(test_api_for_overflow
.IsRippedOffFromShelf());
545 ASSERT_FALSE(test_api_for_overflow
.DraggedItemFromOverflowToShelf());
547 // Move a dragged item into Shelf at |drop_index|.
549 gfx::Point drop_point
=
550 test_api_
->GetButton(drop_index
)->GetBoundsInScreen().CenterPoint();
551 int item_width
= test_api_for_overflow
.GetButtonSize();
552 // To insert at |drop_index|, more smaller x-axis value of |drop_point|
554 gfx::Point
modified_drop_point(drop_point
.x() - item_width
/ 4,
556 generator
.MoveMouseTo(modified_drop_point
);
557 test_api_for_overflow
.RunMessageLoopUntilAnimationsDone();
558 test_api_
->RunMessageLoopUntilAnimationsDone();
559 ASSERT_TRUE(test_api_for_overflow
.IsRippedOffFromShelf());
560 ASSERT_TRUE(test_api_for_overflow
.DraggedItemFromOverflowToShelf());
563 drag_button
->OnMouseCaptureLost();
565 generator
.ReleaseLeftButton();
567 test_api_for_overflow
.RunMessageLoopUntilAnimationsDone();
568 test_api_
->RunMessageLoopUntilAnimationsDone();
569 ASSERT_FALSE(test_api_for_overflow
.IsRippedOffFromShelf());
570 ASSERT_FALSE(test_api_for_overflow
.DraggedItemFromOverflowToShelf());
572 // Compare pre-stored items' id with newly positioned items' after dragging
573 // is canceled or finished.
575 EXPECT_EQ(last_visible_item_id_in_shelf
,
576 GetItemId(test_api_
->GetLastVisibleIndex()));
577 EXPECT_EQ(second_last_visible_item_id_in_shelf
,
578 GetItemId(test_api_
->GetLastVisibleIndex() - 1));
579 EXPECT_EQ(first_visible_item_id_in_overflow
,
580 GetItemId(test_api_for_overflow
.GetFirstVisibleIndex()));
581 EXPECT_EQ(second_last_visible_item_id_in_overflow
,
582 GetItemId(test_api_for_overflow
.GetLastVisibleIndex() - 1));
584 EXPECT_EQ(drag_item_id
, GetItemId(drop_index
));
585 EXPECT_EQ(total_item_count
, model_
->item_count());
586 EXPECT_EQ(last_visible_item_id_in_shelf
,
587 GetItemId(test_api_for_overflow
.GetFirstVisibleIndex()));
588 EXPECT_EQ(second_last_visible_item_id_in_shelf
,
589 GetItemId(test_api_
->GetLastVisibleIndex()));
590 EXPECT_EQ(first_visible_item_id_in_overflow
,
591 GetItemId(test_api_for_overflow
.GetFirstVisibleIndex() + 1));
592 EXPECT_EQ(second_last_visible_item_id_in_overflow
,
593 GetItemId(test_api_for_overflow
.GetLastVisibleIndex()));
597 // Returns the item's ShelfID at |index|.
598 ShelfID
GetItemId(int index
) {
600 return model_
->items()[index
].id
;
603 void ReplaceShelfDelegateForRipOffTest() {
604 // Replace ShelfDelegate.
605 test::ShellTestApi
test_api(Shell::GetInstance());
606 test_api
.SetShelfDelegate(NULL
);
607 ShelfDelegate
* delegate
= new TestShelfDelegateForShelfView(model_
);
608 test_api
.SetShelfDelegate(delegate
);
609 test::ShelfTestAPI(Shelf::ForPrimaryDisplay()).SetShelfDelegate(delegate
);
610 test_api_
->SetShelfDelegate(delegate
);
614 ShelfView
* shelf_view_
;
616 ShelfItemDelegateManager
* item_manager_
;
618 scoped_ptr
<ShelfViewTestAPI
> test_api_
;
621 DISALLOW_COPY_AND_ASSIGN(ShelfViewTest
);
624 class ScopedTextDirectionChange
{
626 explicit ScopedTextDirectionChange(bool is_rtl
) : is_rtl_(is_rtl
) {
627 original_locale_
= l10n_util::GetApplicationLocale(std::string());
629 base::i18n::SetICUDefaultLocale("he");
630 CheckTextDirectionIsCorrect();
633 ~ScopedTextDirectionChange() {
635 base::i18n::SetICUDefaultLocale(original_locale_
);
639 void CheckTextDirectionIsCorrect() {
640 ASSERT_EQ(is_rtl_
, base::i18n::IsRTL());
644 std::string original_locale_
;
647 class ShelfViewTextDirectionTest
648 : public ShelfViewTest
,
649 public testing::WithParamInterface
<bool> {
651 ShelfViewTextDirectionTest() : text_direction_change_(GetParam()) {}
652 virtual ~ShelfViewTextDirectionTest() {}
654 void SetUp() override
{ ShelfViewTest::SetUp(); }
656 void TearDown() override
{ ShelfViewTest::TearDown(); }
659 ScopedTextDirectionChange text_direction_change_
;
661 DISALLOW_COPY_AND_ASSIGN(ShelfViewTextDirectionTest
);
664 // Checks that the ideal item icon bounds match the view's bounds in the screen
665 // in both LTR and RTL.
666 TEST_P(ShelfViewTextDirectionTest
, IdealBoundsOfItemIcon
) {
667 ShelfID id
= AddPlatformApp();
668 ShelfButton
* button
= GetButtonByID(id
);
669 gfx::Rect item_bounds
= button
->GetBoundsInScreen();
670 gfx::Point icon_offset
= button
->GetIconBounds().origin();
671 item_bounds
.Offset(icon_offset
.OffsetFromOrigin());
672 gfx::Rect ideal_bounds
= shelf_view_
->GetIdealBoundsOfItemIcon(id
);
673 gfx::Point screen_origin
;
674 views::View::ConvertPointToScreen(shelf_view_
, &screen_origin
);
675 ideal_bounds
.Offset(screen_origin
.x(), screen_origin
.y());
676 EXPECT_EQ(item_bounds
.x(), ideal_bounds
.x());
677 EXPECT_EQ(item_bounds
.y(), ideal_bounds
.y());
680 // Check that items in the overflow area are returning the overflow button as
682 TEST_F(ShelfViewTest
, OverflowButtonBounds
) {
683 ShelfID first_id
= AddPlatformApp();
684 ShelfID overflow_id
= AddPlatformApp();
686 while (!test_api_
->IsOverflowButtonVisible()) {
687 // Added button is visible after animation while in this loop.
688 EXPECT_TRUE(GetButtonByID(overflow_id
)->visible());
689 overflow_id
= AddPlatformApp();
691 ASSERT_LT(items_added
, 10000);
693 ShelfID last_id
= AddPlatformApp();
695 gfx::Rect first_bounds
= shelf_view_
->GetIdealBoundsOfItemIcon(first_id
);
696 gfx::Rect overflow_bounds
=
697 shelf_view_
->GetIdealBoundsOfItemIcon(overflow_id
);
698 gfx::Rect last_bounds
= shelf_view_
->GetIdealBoundsOfItemIcon(last_id
);
700 // Check that all items have the same size and that the overflow items are
701 // identical whereas the first one does not match either of them.
702 EXPECT_EQ(first_bounds
.size().ToString(), last_bounds
.size().ToString());
703 EXPECT_NE(first_bounds
.ToString(), last_bounds
.ToString());
704 EXPECT_EQ(overflow_bounds
.ToString(), last_bounds
.ToString());
707 // Checks that shelf view contents are considered in the correct drag group.
708 TEST_F(ShelfViewTest
, EnforceDragType
) {
709 EXPECT_TRUE(test_api_
->SameDragType(TYPE_PLATFORM_APP
, TYPE_PLATFORM_APP
));
710 EXPECT_FALSE(test_api_
->SameDragType(TYPE_PLATFORM_APP
, TYPE_APP_SHORTCUT
));
711 EXPECT_FALSE(test_api_
->SameDragType(TYPE_PLATFORM_APP
,
712 TYPE_BROWSER_SHORTCUT
));
713 EXPECT_FALSE(test_api_
->SameDragType(TYPE_PLATFORM_APP
, TYPE_WINDOWED_APP
));
714 EXPECT_FALSE(test_api_
->SameDragType(TYPE_PLATFORM_APP
, TYPE_APP_LIST
));
715 EXPECT_FALSE(test_api_
->SameDragType(TYPE_PLATFORM_APP
, TYPE_APP_PANEL
));
717 EXPECT_TRUE(test_api_
->SameDragType(TYPE_APP_SHORTCUT
, TYPE_APP_SHORTCUT
));
718 EXPECT_TRUE(test_api_
->SameDragType(TYPE_APP_SHORTCUT
,
719 TYPE_BROWSER_SHORTCUT
));
720 EXPECT_FALSE(test_api_
->SameDragType(TYPE_APP_SHORTCUT
,
722 EXPECT_FALSE(test_api_
->SameDragType(TYPE_APP_SHORTCUT
, TYPE_APP_LIST
));
723 EXPECT_FALSE(test_api_
->SameDragType(TYPE_APP_SHORTCUT
, TYPE_APP_PANEL
));
725 EXPECT_TRUE(test_api_
->SameDragType(TYPE_BROWSER_SHORTCUT
,
726 TYPE_BROWSER_SHORTCUT
));
727 EXPECT_FALSE(test_api_
->SameDragType(TYPE_BROWSER_SHORTCUT
,
729 EXPECT_FALSE(test_api_
->SameDragType(TYPE_BROWSER_SHORTCUT
, TYPE_APP_LIST
));
730 EXPECT_FALSE(test_api_
->SameDragType(TYPE_BROWSER_SHORTCUT
, TYPE_APP_PANEL
));
732 EXPECT_TRUE(test_api_
->SameDragType(TYPE_WINDOWED_APP
, TYPE_WINDOWED_APP
));
733 EXPECT_FALSE(test_api_
->SameDragType(TYPE_WINDOWED_APP
, TYPE_APP_LIST
));
734 EXPECT_FALSE(test_api_
->SameDragType(TYPE_WINDOWED_APP
, TYPE_APP_PANEL
));
736 EXPECT_TRUE(test_api_
->SameDragType(TYPE_APP_LIST
, TYPE_APP_LIST
));
737 EXPECT_FALSE(test_api_
->SameDragType(TYPE_APP_LIST
, TYPE_APP_PANEL
));
739 EXPECT_TRUE(test_api_
->SameDragType(TYPE_APP_PANEL
, TYPE_APP_PANEL
));
742 // Adds platform app button until overflow and verifies that the last added
743 // platform app button is hidden.
744 TEST_F(ShelfViewTest
, AddBrowserUntilOverflow
) {
745 // All buttons should be visible.
746 ASSERT_EQ(test_api_
->GetButtonCount(),
747 test_api_
->GetLastVisibleIndex() + 1);
749 // Add platform app button until overflow.
751 ShelfID last_added
= AddPlatformApp();
752 while (!test_api_
->IsOverflowButtonVisible()) {
753 // Added button is visible after animation while in this loop.
754 EXPECT_TRUE(GetButtonByID(last_added
)->visible());
756 last_added
= AddPlatformApp();
758 ASSERT_LT(items_added
, 10000);
761 // The last added button should be invisible.
762 EXPECT_FALSE(GetButtonByID(last_added
)->visible());
765 // Adds one platform app button then adds app shortcut until overflow. Verifies
766 // that the browser button gets hidden on overflow and last added app shortcut
768 TEST_F(ShelfViewTest
, AddAppShortcutWithBrowserButtonUntilOverflow
) {
769 // All buttons should be visible.
770 ASSERT_EQ(test_api_
->GetButtonCount(),
771 test_api_
->GetLastVisibleIndex() + 1);
773 ShelfID browser_button_id
= AddPlatformApp();
775 // Add app shortcut until overflow.
777 ShelfID last_added
= AddAppShortcut();
778 while (!test_api_
->IsOverflowButtonVisible()) {
779 // Added button is visible after animation while in this loop.
780 EXPECT_TRUE(GetButtonByID(last_added
)->visible());
782 last_added
= AddAppShortcut();
784 ASSERT_LT(items_added
, 10000);
787 // And the platform app button is invisible.
788 EXPECT_FALSE(GetButtonByID(browser_button_id
)->visible());
791 TEST_F(ShelfViewTest
, AddPanelHidesPlatformAppButton
) {
792 // All buttons should be visible.
793 ASSERT_EQ(test_api_
->GetButtonCount(),
794 test_api_
->GetLastVisibleIndex() + 1);
796 // Add platform app button until overflow, remember last visible platform app
799 ShelfID first_added
= AddPlatformApp();
800 EXPECT_TRUE(GetButtonByID(first_added
)->visible());
802 ShelfID added
= AddPlatformApp();
803 if (test_api_
->IsOverflowButtonVisible()) {
804 EXPECT_FALSE(GetButtonByID(added
)->visible());
809 ASSERT_LT(items_added
, 10000);
812 ShelfID panel
= AddPanel();
813 EXPECT_TRUE(test_api_
->IsOverflowButtonVisible());
816 EXPECT_FALSE(test_api_
->IsOverflowButtonVisible());
819 // When there are more panels then platform app buttons we should hide panels
820 // rather than platform apps.
821 TEST_F(ShelfViewTest
, PlatformAppHidesExcessPanels
) {
822 // All buttons should be visible.
823 ASSERT_EQ(test_api_
->GetButtonCount(),
824 test_api_
->GetLastVisibleIndex() + 1);
826 // Add platform app button.
827 ShelfID platform_app
= AddPlatformApp();
828 ShelfID first_panel
= AddPanel();
830 EXPECT_TRUE(GetButtonByID(platform_app
)->visible());
831 EXPECT_TRUE(GetButtonByID(first_panel
)->visible());
833 // Add panels until there is an overflow.
834 ShelfID last_panel
= first_panel
;
836 while (!test_api_
->IsOverflowButtonVisible()) {
837 last_panel
= AddPanel();
839 ASSERT_LT(items_added
, 10000);
842 // The first panel should now be hidden by the new platform apps needing
844 EXPECT_FALSE(GetButtonByID(first_panel
)->visible());
845 EXPECT_TRUE(GetButtonByID(last_panel
)->visible());
846 EXPECT_TRUE(GetButtonByID(platform_app
)->visible());
848 // Adding platform apps should eventually begin to hide platform apps. We will
849 // add platform apps until either the last panel or platform app is hidden.
851 while (GetButtonByID(platform_app
)->visible() &&
852 GetButtonByID(last_panel
)->visible()) {
853 platform_app
= AddPlatformApp();
855 ASSERT_LT(items_added
, 10000);
857 EXPECT_TRUE(GetButtonByID(last_panel
)->visible());
858 EXPECT_FALSE(GetButtonByID(platform_app
)->visible());
861 // Adds button until overflow then removes first added one. Verifies that
862 // the last added one changes from invisible to visible and overflow
864 TEST_F(ShelfViewTest
, RemoveButtonRevealsOverflowed
) {
865 // All buttons should be visible.
866 ASSERT_EQ(test_api_
->GetButtonCount(),
867 test_api_
->GetLastVisibleIndex() + 1);
869 // Add platform app buttons until overflow.
871 ShelfID first_added
= AddPlatformApp();
872 ShelfID last_added
= first_added
;
873 while (!test_api_
->IsOverflowButtonVisible()) {
874 last_added
= AddPlatformApp();
876 ASSERT_LT(items_added
, 10000);
879 // Expect add more than 1 button. First added is visible and last is not.
880 EXPECT_NE(first_added
, last_added
);
881 EXPECT_TRUE(GetButtonByID(first_added
)->visible());
882 EXPECT_FALSE(GetButtonByID(last_added
)->visible());
884 // Remove first added.
885 RemoveByID(first_added
);
887 // Last added button becomes visible and overflow chevron is gone.
888 EXPECT_TRUE(GetButtonByID(last_added
)->visible());
889 EXPECT_EQ(1.0f
, GetButtonByID(last_added
)->layer()->opacity());
890 EXPECT_FALSE(test_api_
->IsOverflowButtonVisible());
893 // Verifies that remove last overflowed button should hide overflow chevron.
894 TEST_F(ShelfViewTest
, RemoveLastOverflowed
) {
895 // All buttons should be visible.
896 ASSERT_EQ(test_api_
->GetButtonCount(),
897 test_api_
->GetLastVisibleIndex() + 1);
899 // Add platform app button until overflow.
901 ShelfID last_added
= AddPlatformApp();
902 while (!test_api_
->IsOverflowButtonVisible()) {
903 last_added
= AddPlatformApp();
905 ASSERT_LT(items_added
, 10000);
908 RemoveByID(last_added
);
909 EXPECT_FALSE(test_api_
->IsOverflowButtonVisible());
912 // Adds platform app button without waiting for animation to finish and verifies
913 // that all added buttons are visible.
914 TEST_F(ShelfViewTest
, AddButtonQuickly
) {
915 // All buttons should be visible.
916 ASSERT_EQ(test_api_
->GetButtonCount(),
917 test_api_
->GetLastVisibleIndex() + 1);
919 // Add a few platform buttons quickly without wait for animation.
921 while (!test_api_
->IsOverflowButtonVisible()) {
922 AddPlatformAppNoWait();
924 ASSERT_LT(added_count
, 10000);
927 // ShelfView should be big enough to hold at least 3 new buttons.
928 ASSERT_GE(added_count
, 3);
930 // Wait for the last animation to finish.
931 test_api_
->RunMessageLoopUntilAnimationsDone();
933 // Verifies non-overflow buttons are visible.
934 for (int i
= 0; i
<= test_api_
->GetLastVisibleIndex(); ++i
) {
935 ShelfButton
* button
= test_api_
->GetButton(i
);
937 EXPECT_TRUE(button
->visible()) << "button index=" << i
;
938 EXPECT_EQ(1.0f
, button
->layer()->opacity()) << "button index=" << i
;
943 // Check that model changes are handled correctly while a shelf icon is being
945 TEST_F(ShelfViewTest
, ModelChangesWhileDragging
) {
946 ShelfButtonHost
* button_host
= shelf_view_
;
948 std::vector
<std::pair
<ShelfID
, views::View
*> > id_map
;
949 SetupForDragTest(&id_map
);
951 // Dragging browser shortcut at index 1.
952 EXPECT_TRUE(model_
->items()[1].type
== TYPE_BROWSER_SHORTCUT
);
953 views::View
* dragged_button
= SimulateDrag(ShelfButtonHost::MOUSE
, 1, 3);
954 std::rotate(id_map
.begin() + 1,
957 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map
));
958 button_host
->PointerReleasedOnButton(
959 dragged_button
, ShelfButtonHost::MOUSE
, false);
960 EXPECT_TRUE(model_
->items()[3].type
== TYPE_BROWSER_SHORTCUT
);
962 // Dragging changes model order.
963 dragged_button
= SimulateDrag(ShelfButtonHost::MOUSE
, 1, 3);
964 std::rotate(id_map
.begin() + 1,
967 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map
));
969 // Cancelling the drag operation restores previous order.
970 button_host
->PointerReleasedOnButton(
971 dragged_button
, ShelfButtonHost::MOUSE
, true);
972 std::rotate(id_map
.begin() + 1,
975 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map
));
977 // Deleting an item keeps the remaining intact.
978 dragged_button
= SimulateDrag(ShelfButtonHost::MOUSE
, 1, 3);
979 model_
->RemoveItemAt(1);
980 id_map
.erase(id_map
.begin() + 1);
981 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map
));
982 button_host
->PointerReleasedOnButton(
983 dragged_button
, ShelfButtonHost::MOUSE
, false);
985 // Adding a shelf item cancels the drag and respects the order.
986 dragged_button
= SimulateDrag(ShelfButtonHost::MOUSE
, 1, 3);
987 ShelfID new_id
= AddAppShortcut();
988 id_map
.insert(id_map
.begin() + 6,
989 std::make_pair(new_id
, GetButtonByID(new_id
)));
990 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map
));
991 button_host
->PointerReleasedOnButton(
992 dragged_button
, ShelfButtonHost::MOUSE
, false);
994 // Adding a shelf item at the end (i.e. a panel) canels drag and respects
996 dragged_button
= SimulateDrag(ShelfButtonHost::MOUSE
, 1, 3);
998 id_map
.insert(id_map
.begin() + 7,
999 std::make_pair(new_id
, GetButtonByID(new_id
)));
1000 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map
));
1001 button_host
->PointerReleasedOnButton(
1002 dragged_button
, ShelfButtonHost::MOUSE
, false);
1005 // Check that 2nd drag from the other pointer would be ignored.
1006 TEST_F(ShelfViewTest
, SimultaneousDrag
) {
1007 ShelfButtonHost
* button_host
= shelf_view_
;
1009 std::vector
<std::pair
<ShelfID
, views::View
*> > id_map
;
1010 SetupForDragTest(&id_map
);
1012 // Start a mouse drag.
1013 views::View
* dragged_button_mouse
=
1014 SimulateDrag(ShelfButtonHost::MOUSE
, 1, 3);
1015 std::rotate(id_map
.begin() + 1,
1017 id_map
.begin() + 4);
1018 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map
));
1019 // Attempt a touch drag before the mouse drag finishes.
1020 views::View
* dragged_button_touch
=
1021 SimulateDrag(ShelfButtonHost::TOUCH
, 4, 2);
1023 // Nothing changes since 2nd drag is ignored.
1024 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map
));
1026 // Finish the mouse drag.
1027 button_host
->PointerReleasedOnButton(
1028 dragged_button_mouse
, ShelfButtonHost::MOUSE
, false);
1029 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map
));
1031 // Now start a touch drag.
1032 dragged_button_touch
= SimulateDrag(ShelfButtonHost::TOUCH
, 4, 2);
1033 std::rotate(id_map
.begin() + 3,
1035 id_map
.begin() + 5);
1036 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map
));
1038 // And attempt a mouse drag before the touch drag finishes.
1039 dragged_button_mouse
= SimulateDrag(ShelfButtonHost::MOUSE
, 1, 2);
1041 // Nothing changes since 2nd drag is ignored.
1042 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map
));
1044 button_host
->PointerReleasedOnButton(
1045 dragged_button_touch
, ShelfButtonHost::TOUCH
, false);
1046 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map
));
1049 // Check that clicking first on one item and then dragging another works as
1051 TEST_F(ShelfViewTest
, ClickOneDragAnother
) {
1052 ShelfButtonHost
* button_host
= shelf_view_
;
1054 std::vector
<std::pair
<ShelfID
, views::View
*> > id_map
;
1055 SetupForDragTest(&id_map
);
1057 // A click on item 1 is simulated.
1060 // Dragging browser index at 0 should change the model order correctly.
1061 EXPECT_TRUE(model_
->items()[1].type
== TYPE_BROWSER_SHORTCUT
);
1062 views::View
* dragged_button
= SimulateDrag(ShelfButtonHost::MOUSE
, 1, 3);
1063 std::rotate(id_map
.begin() + 1,
1065 id_map
.begin() + 4);
1066 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map
));
1067 button_host
->PointerReleasedOnButton(
1068 dragged_button
, ShelfButtonHost::MOUSE
, false);
1069 EXPECT_TRUE(model_
->items()[3].type
== TYPE_BROWSER_SHORTCUT
);
1072 // Tests that double-clicking an item does not activate it twice.
1073 TEST_F(ShelfViewTest
, ClickingTwiceActivatesOnce
) {
1074 // Watch for selection of the browser shortcut.
1075 ShelfID browser_shelf_id
= model_
->items()[browser_index_
].id
;
1076 ShelfItemSelectionTracker
* selection_tracker
= new ShelfItemSelectionTracker
;
1077 item_manager_
->SetShelfItemDelegate(
1079 scoped_ptr
<ShelfItemDelegate
>(selection_tracker
).Pass());
1081 // A single click selects the item.
1082 SimulateClick(browser_index_
);
1083 EXPECT_TRUE(selection_tracker
->WasSelected());
1085 // A double-click does not select the item.
1086 selection_tracker
->Reset();
1087 SimulateDoubleClick(browser_index_
);
1088 EXPECT_FALSE(selection_tracker
->WasSelected());
1091 // Check that clicking an item and jittering the mouse a bit still selects the
1093 TEST_F(ShelfViewTest
, ClickAndMoveSlightly
) {
1094 std::vector
<std::pair
<ShelfID
, views::View
*> > id_map
;
1095 SetupForDragTest(&id_map
);
1097 ShelfID shelf_id
= (id_map
.begin() + 1)->first
;
1098 views::View
* button
= (id_map
.begin() + 1)->second
;
1100 // Replace the ShelfItemDelegate for |shelf_id| with one which tracks whether
1101 // the shelf item gets selected.
1102 ShelfItemSelectionTracker
* selection_tracker
= new ShelfItemSelectionTracker
;
1103 item_manager_
->SetShelfItemDelegate(
1105 scoped_ptr
<ShelfItemDelegate
>(selection_tracker
).Pass());
1107 gfx::Vector2d
press_offset(5, 30);
1108 gfx::Point press_location
= gfx::Point() + press_offset
;
1109 gfx::Point press_location_in_screen
=
1110 button
->GetBoundsInScreen().origin() + press_offset
;
1112 ui::MouseEvent
click_event(ui::ET_MOUSE_PRESSED
, press_location
,
1113 press_location_in_screen
, ui::EventTimeForNow(),
1114 ui::EF_LEFT_MOUSE_BUTTON
, 0);
1115 button
->OnMousePressed(click_event
);
1117 ui::MouseEvent
drag_event1(
1118 ui::ET_MOUSE_DRAGGED
, press_location
+ gfx::Vector2d(0, 1),
1119 press_location_in_screen
+ gfx::Vector2d(0, 1), ui::EventTimeForNow(),
1120 ui::EF_LEFT_MOUSE_BUTTON
, 0);
1121 button
->OnMouseDragged(drag_event1
);
1123 ui::MouseEvent
drag_event2(
1124 ui::ET_MOUSE_DRAGGED
, press_location
+ gfx::Vector2d(-1, 0),
1125 press_location_in_screen
+ gfx::Vector2d(-1, 0), ui::EventTimeForNow(),
1126 ui::EF_LEFT_MOUSE_BUTTON
, 0);
1127 button
->OnMouseDragged(drag_event2
);
1129 ui::MouseEvent
release_event(
1130 ui::ET_MOUSE_RELEASED
, press_location
+ gfx::Vector2d(-1, 0),
1131 press_location_in_screen
+ gfx::Vector2d(-1, 0), ui::EventTimeForNow(),
1132 ui::EF_LEFT_MOUSE_BUTTON
, 0);
1133 button
->OnMouseReleased(release_event
);
1135 EXPECT_TRUE(selection_tracker
->WasSelected());
1138 // Confirm that item status changes are reflected in the buttons.
1139 TEST_F(ShelfViewTest
, ShelfItemStatus
) {
1140 // All buttons should be visible.
1141 ASSERT_EQ(test_api_
->GetButtonCount(),
1142 test_api_
->GetLastVisibleIndex() + 1);
1144 // Add platform app button.
1145 ShelfID last_added
= AddPlatformApp();
1146 ShelfItem item
= GetItemByID(last_added
);
1147 int index
= model_
->ItemIndexByID(last_added
);
1148 ShelfButton
* button
= GetButtonByID(last_added
);
1149 ASSERT_EQ(ShelfButton::STATE_RUNNING
, button
->state());
1150 item
.status
= STATUS_ACTIVE
;
1151 model_
->Set(index
, item
);
1152 ASSERT_EQ(ShelfButton::STATE_ACTIVE
, button
->state());
1153 item
.status
= STATUS_ATTENTION
;
1154 model_
->Set(index
, item
);
1155 ASSERT_EQ(ShelfButton::STATE_ATTENTION
, button
->state());
1158 // Confirm that item status changes are reflected in the buttons
1159 // for platform apps.
1160 TEST_F(ShelfViewTest
, ShelfItemStatusPlatformApp
) {
1161 // All buttons should be visible.
1162 ASSERT_EQ(test_api_
->GetButtonCount(),
1163 test_api_
->GetLastVisibleIndex() + 1);
1165 // Add platform app button.
1166 ShelfID last_added
= AddPlatformApp();
1167 ShelfItem item
= GetItemByID(last_added
);
1168 int index
= model_
->ItemIndexByID(last_added
);
1169 ShelfButton
* button
= GetButtonByID(last_added
);
1170 ASSERT_EQ(ShelfButton::STATE_RUNNING
, button
->state());
1171 item
.status
= STATUS_ACTIVE
;
1172 model_
->Set(index
, item
);
1173 ASSERT_EQ(ShelfButton::STATE_ACTIVE
, button
->state());
1174 item
.status
= STATUS_ATTENTION
;
1175 model_
->Set(index
, item
);
1176 ASSERT_EQ(ShelfButton::STATE_ATTENTION
, button
->state());
1179 // Confirm that shelf item bounds are correctly updated on shelf changes.
1180 TEST_F(ShelfViewTest
, ShelfItemBoundsCheck
) {
1181 VerifyShelfItemBoundsAreValid();
1182 shelf_view_
->shelf_layout_manager()->SetAutoHideBehavior(
1183 SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1184 test_api_
->RunMessageLoopUntilAnimationsDone();
1185 VerifyShelfItemBoundsAreValid();
1186 shelf_view_
->shelf_layout_manager()->SetAutoHideBehavior(
1187 SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
1188 test_api_
->RunMessageLoopUntilAnimationsDone();
1189 VerifyShelfItemBoundsAreValid();
1192 TEST_F(ShelfViewTest
, ShelfTooltipTest
) {
1193 ASSERT_EQ(test_api_
->GetLastVisibleIndex() + 1,
1194 test_api_
->GetButtonCount());
1196 // Prepare some items to the shelf.
1197 ShelfID app_button_id
= AddAppShortcut();
1198 ShelfID platform_button_id
= AddPlatformApp();
1200 ShelfButton
* app_button
= GetButtonByID(app_button_id
);
1201 ShelfButton
* platform_button
= GetButtonByID(platform_button_id
);
1203 ShelfButtonHost
* button_host
= shelf_view_
;
1204 ShelfTooltipManager
* tooltip_manager
= shelf_view_
->tooltip_manager();
1206 button_host
->MouseEnteredButton(app_button
);
1207 // There's a delay to show the tooltip, so it's not visible yet.
1208 EXPECT_FALSE(tooltip_manager
->IsVisible());
1209 EXPECT_EQ(app_button
, GetTooltipAnchorView());
1212 EXPECT_TRUE(tooltip_manager
->IsVisible());
1214 // Once it's visible, it keeps visibility and is pointing to the same
1216 button_host
->MouseExitedButton(app_button
);
1217 EXPECT_TRUE(tooltip_manager
->IsVisible());
1218 EXPECT_EQ(app_button
, GetTooltipAnchorView());
1220 // When entered to another item, it switches to the new item. There is no
1221 // delay for the visibility.
1222 button_host
->MouseEnteredButton(platform_button
);
1223 EXPECT_TRUE(tooltip_manager
->IsVisible());
1224 EXPECT_EQ(platform_button
, GetTooltipAnchorView());
1226 button_host
->MouseExitedButton(platform_button
);
1227 tooltip_manager
->Close();
1229 // Next time: enter app_button -> move immediately to tab_button.
1230 button_host
->MouseEnteredButton(app_button
);
1231 button_host
->MouseExitedButton(app_button
);
1232 button_host
->MouseEnteredButton(platform_button
);
1233 EXPECT_FALSE(tooltip_manager
->IsVisible());
1234 EXPECT_EQ(platform_button
, GetTooltipAnchorView());
1237 // Verify a fix for crash caused by a tooltip update for a deletedshelf
1238 // button, see crbug.com/288838.
1239 TEST_F(ShelfViewTest
, RemovingItemClosesTooltip
) {
1240 ShelfButtonHost
* button_host
= shelf_view_
;
1241 ShelfTooltipManager
* tooltip_manager
= shelf_view_
->tooltip_manager();
1243 // Add an item to the shelf.
1244 ShelfID app_button_id
= AddAppShortcut();
1245 ShelfButton
* app_button
= GetButtonByID(app_button_id
);
1247 // Spawn a tooltip on that item.
1248 button_host
->MouseEnteredButton(app_button
);
1250 EXPECT_TRUE(tooltip_manager
->IsVisible());
1252 // Remove the app shortcut while the tooltip is open. The tooltip should be
1254 RemoveByID(app_button_id
);
1255 EXPECT_FALSE(tooltip_manager
->IsVisible());
1257 // Change the shelf layout. This should not crash.
1258 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT
,
1259 Shell::GetPrimaryRootWindow());
1262 // Changing the shelf alignment closes any open tooltip.
1263 TEST_F(ShelfViewTest
, ShelfAlignmentClosesTooltip
) {
1264 ShelfButtonHost
* button_host
= shelf_view_
;
1265 ShelfTooltipManager
* tooltip_manager
= shelf_view_
->tooltip_manager();
1267 // Add an item to the shelf.
1268 ShelfID app_button_id
= AddAppShortcut();
1269 ShelfButton
* app_button
= GetButtonByID(app_button_id
);
1271 // Spawn a tooltip on the item.
1272 button_host
->MouseEnteredButton(app_button
);
1274 EXPECT_TRUE(tooltip_manager
->IsVisible());
1276 // Changing shelf alignment hides the tooltip.
1277 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT
,
1278 Shell::GetPrimaryRootWindow());
1279 EXPECT_FALSE(tooltip_manager
->IsVisible());
1282 TEST_F(ShelfViewTest
, ShouldHideTooltipTest
) {
1283 ShelfID app_button_id
= AddAppShortcut();
1284 ShelfID platform_button_id
= AddPlatformApp();
1286 // The tooltip shouldn't hide if the mouse is on normal buttons.
1287 for (int i
= 0; i
< test_api_
->GetButtonCount(); i
++) {
1288 ShelfButton
* button
= test_api_
->GetButton(i
);
1292 EXPECT_FALSE(shelf_view_
->ShouldHideTooltip(
1293 button
->GetMirroredBounds().CenterPoint()))
1294 << "ShelfView tries to hide on button " << i
;
1297 // The tooltip should not hide on the app-list button.
1298 views::View
* app_list_button
= shelf_view_
->GetAppListButtonView();
1299 EXPECT_FALSE(shelf_view_
->ShouldHideTooltip(
1300 app_list_button
->GetMirroredBounds().CenterPoint()));
1302 // The tooltip shouldn't hide if the mouse is in the gap between two buttons.
1303 gfx::Rect app_button_rect
= GetButtonByID(app_button_id
)->GetMirroredBounds();
1304 gfx::Rect platform_button_rect
=
1305 GetButtonByID(platform_button_id
)->GetMirroredBounds();
1306 ASSERT_FALSE(app_button_rect
.Intersects(platform_button_rect
));
1307 EXPECT_FALSE(shelf_view_
->ShouldHideTooltip(
1308 gfx::UnionRects(app_button_rect
, platform_button_rect
).CenterPoint()));
1310 // The tooltip should hide if it's outside of all buttons.
1312 for (int i
= 0; i
< test_api_
->GetButtonCount(); i
++) {
1313 ShelfButton
* button
= test_api_
->GetButton(i
);
1317 all_area
.Union(button
->GetMirroredBounds());
1319 all_area
.Union(shelf_view_
->GetAppListButtonView()->GetMirroredBounds());
1320 EXPECT_FALSE(shelf_view_
->ShouldHideTooltip(all_area
.origin()));
1321 EXPECT_FALSE(shelf_view_
->ShouldHideTooltip(
1322 gfx::Point(all_area
.right() - 1, all_area
.bottom() - 1)));
1323 EXPECT_TRUE(shelf_view_
->ShouldHideTooltip(
1324 gfx::Point(all_area
.right(), all_area
.y())));
1325 EXPECT_TRUE(shelf_view_
->ShouldHideTooltip(
1326 gfx::Point(all_area
.x() - 1, all_area
.y())));
1327 EXPECT_TRUE(shelf_view_
->ShouldHideTooltip(
1328 gfx::Point(all_area
.x(), all_area
.y() - 1)));
1329 EXPECT_TRUE(shelf_view_
->ShouldHideTooltip(
1330 gfx::Point(all_area
.x(), all_area
.bottom())));
1333 TEST_F(ShelfViewTest
, ShouldHideTooltipWithAppListWindowTest
) {
1334 Shell::GetInstance()->ShowAppList(NULL
);
1335 ASSERT_TRUE(Shell::GetInstance()->GetAppListWindow());
1337 // The tooltip shouldn't hide if the mouse is on normal buttons.
1338 for (int i
= 1; i
< test_api_
->GetButtonCount(); i
++) {
1339 ShelfButton
* button
= test_api_
->GetButton(i
);
1343 EXPECT_FALSE(shelf_view_
->ShouldHideTooltip(
1344 button
->GetMirroredBounds().CenterPoint()))
1345 << "ShelfView tries to hide on button " << i
;
1348 // The tooltip should hide on the app-list button.
1349 views::View
* app_list_button
= shelf_view_
->GetAppListButtonView();
1350 EXPECT_TRUE(shelf_view_
->ShouldHideTooltip(
1351 app_list_button
->GetMirroredBounds().CenterPoint()));
1354 // Test that by moving the mouse cursor off the button onto the bubble it closes
1356 TEST_F(ShelfViewTest
, ShouldHideTooltipWhenHoveringOnTooltip
) {
1357 ShelfTooltipManager
* tooltip_manager
= shelf_view_
->tooltip_manager();
1358 tooltip_manager
->CreateZeroDelayTimerForTest();
1359 ui::test::EventGenerator
generator(Shell::GetPrimaryRootWindow());
1361 // Move the mouse off any item and check that no tooltip is shown.
1362 generator
.MoveMouseTo(gfx::Point(0, 0));
1363 EXPECT_FALSE(tooltip_manager
->IsVisible());
1365 // Move the mouse over the button and check that it is visible.
1366 views::View
* app_list_button
= shelf_view_
->GetAppListButtonView();
1367 gfx::Rect bounds
= app_list_button
->GetBoundsInScreen();
1368 generator
.MoveMouseTo(bounds
.CenterPoint());
1369 // Wait for the timer to go off.
1370 RunAllPendingInMessageLoop();
1371 EXPECT_TRUE(tooltip_manager
->IsVisible());
1373 // Move the mouse cursor slightly to the right of the item. The tooltip should
1375 generator
.MoveMouseBy(bounds
.width() / 2 + 5, 0);
1376 // Make sure there is no delayed close.
1377 RunAllPendingInMessageLoop();
1378 EXPECT_TRUE(tooltip_manager
->IsVisible());
1380 // Move back - it should still stay open.
1381 generator
.MoveMouseBy(-(bounds
.width() / 2 + 5), 0);
1382 // Make sure there is no delayed close.
1383 RunAllPendingInMessageLoop();
1384 EXPECT_TRUE(tooltip_manager
->IsVisible());
1386 // Now move the mouse cursor slightly above the item - so that it is over the
1387 // tooltip bubble. Now it should disappear.
1388 generator
.MoveMouseBy(0, -(bounds
.height() / 2 + 5));
1389 // Wait until the delayed close kicked in.
1390 RunAllPendingInMessageLoop();
1391 EXPECT_FALSE(tooltip_manager
->IsVisible());
1394 // Resizing shelf view while an add animation without fade-in is running,
1395 // which happens when overflow happens. App list button should end up in its
1396 // new ideal bounds.
1397 TEST_F(ShelfViewTest
, ResizeDuringOverflowAddAnimation
) {
1398 // All buttons should be visible.
1399 ASSERT_EQ(test_api_
->GetButtonCount(),
1400 test_api_
->GetLastVisibleIndex() + 1);
1402 // Add buttons until overflow. Let the non-overflow add animations finish but
1403 // leave the last running.
1404 int items_added
= 0;
1405 AddPlatformAppNoWait();
1406 while (!test_api_
->IsOverflowButtonVisible()) {
1407 test_api_
->RunMessageLoopUntilAnimationsDone();
1408 AddPlatformAppNoWait();
1410 ASSERT_LT(items_added
, 10000);
1413 // Resize shelf view with that animation running and stay overflown.
1414 gfx::Rect bounds
= shelf_view_
->bounds();
1415 bounds
.set_width(bounds
.width() - kShelfSize
);
1416 shelf_view_
->SetBoundsRect(bounds
);
1417 ASSERT_TRUE(test_api_
->IsOverflowButtonVisible());
1419 // Finish the animation.
1420 test_api_
->RunMessageLoopUntilAnimationsDone();
1422 // App list button should ends up in its new ideal bounds.
1423 const int app_list_button_index
= test_api_
->GetButtonCount() - 1;
1424 const gfx::Rect
& app_list_ideal_bounds
=
1425 test_api_
->GetIdealBoundsByIndex(app_list_button_index
);
1426 const gfx::Rect
& app_list_bounds
=
1427 test_api_
->GetBoundsByIndex(app_list_button_index
);
1428 EXPECT_EQ(app_list_ideal_bounds
, app_list_bounds
);
1431 // Checks the overflow bubble size when an item is ripped off and re-inserted.
1432 TEST_F(ShelfViewTest
, OverflowBubbleSize
) {
1433 // Replace current ShelfDelegate with TestShelfDelegateForShelfView.
1434 ReplaceShelfDelegateForRipOffTest();
1436 AddButtonsUntilOverflow();
1437 // Add one more button to prevent the overflow bubble to disappear upon
1438 // dragging an item out on windows (flakiness, see crbug.com/436131).
1441 // Show overflow bubble.
1442 test_api_
->ShowOverflowBubble();
1443 ASSERT_TRUE(test_api_
->overflow_bubble() &&
1444 test_api_
->overflow_bubble()->IsShowing());
1446 ShelfViewTestAPI
test_for_overflow_view(
1447 test_api_
->overflow_bubble()->shelf_view());
1449 int ripped_index
= test_for_overflow_view
.GetLastVisibleIndex();
1450 gfx::Size bubble_size
= test_for_overflow_view
.GetPreferredSize();
1451 int item_width
= test_for_overflow_view
.GetButtonSize() +
1452 test_for_overflow_view
.GetButtonSpacing();
1454 ui::test::EventGenerator
generator(Shell::GetPrimaryRootWindow(),
1456 ShelfButton
* button
= test_for_overflow_view
.GetButton(ripped_index
);
1457 // Rip off the last visible item.
1458 gfx::Point start_point
= button
->GetBoundsInScreen().CenterPoint();
1459 gfx::Point
rip_off_point(start_point
.x(), 0);
1460 generator
.MoveMouseTo(start_point
.x(), start_point
.y());
1461 base::MessageLoop::current()->RunUntilIdle();
1462 generator
.PressLeftButton();
1463 base::MessageLoop::current()->RunUntilIdle();
1464 generator
.MoveMouseTo(rip_off_point
.x(), rip_off_point
.y());
1465 base::MessageLoop::current()->RunUntilIdle();
1466 test_for_overflow_view
.RunMessageLoopUntilAnimationsDone();
1468 // Check the overflow bubble size when an item is ripped off.
1469 EXPECT_EQ(bubble_size
.width() - item_width
,
1470 test_for_overflow_view
.GetPreferredSize().width());
1471 ASSERT_TRUE(test_api_
->overflow_bubble() &&
1472 test_api_
->overflow_bubble()->IsShowing());
1474 // Re-insert an item into the overflow bubble.
1475 int first_index
= test_for_overflow_view
.GetFirstVisibleIndex();
1476 button
= test_for_overflow_view
.GetButton(first_index
);
1478 // Check the bubble size after an item is re-inserted.
1479 generator
.MoveMouseTo(button
->GetBoundsInScreen().CenterPoint());
1480 test_for_overflow_view
.RunMessageLoopUntilAnimationsDone();
1481 EXPECT_EQ(bubble_size
.width(),
1482 test_for_overflow_view
.GetPreferredSize().width());
1484 generator
.ReleaseLeftButton();
1485 test_for_overflow_view
.RunMessageLoopUntilAnimationsDone();
1486 EXPECT_EQ(bubble_size
.width(),
1487 test_for_overflow_view
.GetPreferredSize().width());
1490 // Check the drag insertion bounds of scrolled overflow bubble.
1491 TEST_F(ShelfViewTest
, CheckDragInsertBoundsOfScrolledOverflowBubble
) {
1492 UpdateDisplay("400x300");
1494 EXPECT_EQ(2, model_
->item_count());
1496 AddButtonsUntilOverflow();
1498 // Show overflow bubble.
1499 test_api_
->ShowOverflowBubble();
1500 ASSERT_TRUE(test_api_
->overflow_bubble() &&
1501 test_api_
->overflow_bubble()->IsShowing());
1503 int item_width
= test_api_
->GetButtonSize() +
1504 test_api_
->GetButtonSpacing();
1505 OverflowBubbleView
* bubble_view
= test_api_
->overflow_bubble()->bubble_view();
1506 test::OverflowBubbleViewTestAPI
bubble_view_api(bubble_view
);
1508 // Add more buttons until OverflowBubble is scrollable and it has 3 invisible
1510 while (bubble_view_api
.GetContentsSize().width() <
1511 (bubble_view
->GetContentsBounds().width() + 3 * item_width
))
1514 ASSERT_TRUE(test_api_
->overflow_bubble() &&
1515 test_api_
->overflow_bubble()->IsShowing());
1517 ShelfViewTestAPI
test_for_overflow_view(
1518 test_api_
->overflow_bubble()->shelf_view());
1519 int first_index
= test_for_overflow_view
.GetFirstVisibleIndex();
1520 int last_index
= test_for_overflow_view
.GetLastVisibleIndex();
1522 ShelfButton
* first_button
= test_for_overflow_view
.GetButton(first_index
);
1523 ShelfButton
* last_button
= test_for_overflow_view
.GetButton(last_index
);
1524 gfx::Point first_point
= first_button
->GetBoundsInScreen().CenterPoint();
1525 gfx::Point last_point
= last_button
->GetBoundsInScreen().CenterPoint();
1526 gfx::Rect drag_reinsert_bounds
=
1527 test_for_overflow_view
.GetBoundsForDragInsertInScreen();
1528 EXPECT_TRUE(drag_reinsert_bounds
.Contains(first_point
));
1529 EXPECT_FALSE(drag_reinsert_bounds
.Contains(last_point
));
1531 // Scrolls sufficiently to show last item.
1532 bubble_view_api
.ScrollByXOffset(3 * item_width
);
1533 drag_reinsert_bounds
=
1534 test_for_overflow_view
.GetBoundsForDragInsertInScreen();
1535 first_point
= first_button
->GetBoundsInScreen().CenterPoint();
1536 last_point
= last_button
->GetBoundsInScreen().CenterPoint();
1537 EXPECT_FALSE(drag_reinsert_bounds
.Contains(first_point
));
1538 EXPECT_TRUE(drag_reinsert_bounds
.Contains(last_point
));
1541 // Check the drag insertion bounds of shelf view in multi monitor environment.
1542 TEST_F(ShelfViewTest
, CheckDragInsertBoundsWithMultiMonitor
) {
1543 // win8-aura doesn't support multiple display.
1544 if (!SupportsMultipleDisplays())
1547 UpdateDisplay("800x600,800x600");
1548 Shelf
* secondary_shelf
= Shelf::ForWindow(Shell::GetAllRootWindows()[1]);
1549 ShelfView
* shelf_view_for_secondary
=
1550 ShelfTestAPI(secondary_shelf
).shelf_view();
1552 // The bounds should be big enough for 4 buttons + overflow chevron.
1553 shelf_view_for_secondary
->SetBounds(0, 0, 500, kShelfSize
);
1555 ShelfViewTestAPI
test_api_for_secondary(shelf_view_for_secondary
);
1556 // Speeds up animation for test.
1557 test_api_for_secondary
.SetAnimationDuration(1);
1559 AddButtonsUntilOverflow();
1561 // Test #1: Test drag insertion bounds of primary shelf.
1562 // Show overflow bubble.
1563 test_api_
->ShowOverflowBubble();
1564 ASSERT_TRUE(test_api_
->overflow_bubble() &&
1565 test_api_
->overflow_bubble()->IsShowing());
1567 ShelfViewTestAPI
test_api_for_overflow_view(
1568 test_api_
->overflow_bubble()->shelf_view());
1570 ShelfButton
* button
= test_api_for_overflow_view
.GetButton(
1571 test_api_for_overflow_view
.GetLastVisibleIndex());
1573 // Checks that a point in shelf is contained in drag insert bounds.
1574 gfx::Point point_in_shelf_view
= button
->GetBoundsInScreen().CenterPoint();
1575 gfx::Rect drag_reinsert_bounds
=
1576 test_api_for_overflow_view
.GetBoundsForDragInsertInScreen();
1577 EXPECT_TRUE(drag_reinsert_bounds
.Contains(point_in_shelf_view
));
1578 // Checks that a point out of shelf is not contained in drag insert bounds.
1579 EXPECT_FALSE(drag_reinsert_bounds
.Contains(
1580 gfx::Point(point_in_shelf_view
.x(), 0)));
1582 // Test #2: Test drag insertion bounds of secondary shelf.
1583 // Show overflow bubble.
1584 test_api_for_secondary
.ShowOverflowBubble();
1585 ASSERT_TRUE(test_api_for_secondary
.overflow_bubble() &&
1586 test_api_for_secondary
.overflow_bubble()->IsShowing());
1588 ShelfViewTestAPI
test_api_for_overflow_view_of_secondary(
1589 test_api_for_secondary
.overflow_bubble()->shelf_view());
1591 ShelfButton
* button_in_secondary
=
1592 test_api_for_overflow_view_of_secondary
.GetButton(
1593 test_api_for_overflow_view_of_secondary
.GetLastVisibleIndex());
1595 // Checks that a point in shelf is contained in drag insert bounds.
1596 gfx::Point point_in_secondary_shelf_view
=
1597 button_in_secondary
->GetBoundsInScreen().CenterPoint();
1598 gfx::Rect drag_reinsert_bounds_in_secondary
=
1599 test_api_for_overflow_view_of_secondary
.GetBoundsForDragInsertInScreen();
1600 EXPECT_TRUE(drag_reinsert_bounds_in_secondary
.Contains(
1601 point_in_secondary_shelf_view
));
1602 // Checks that a point out of shelf is not contained in drag insert bounds.
1603 EXPECT_FALSE(drag_reinsert_bounds_in_secondary
.Contains(
1604 gfx::Point(point_in_secondary_shelf_view
.x(), 0)));
1605 // Checks that a point of overflow bubble in primary shelf should not be
1606 // contained by insert bounds of secondary shelf.
1607 EXPECT_FALSE(drag_reinsert_bounds_in_secondary
.Contains(point_in_shelf_view
));
1610 // Checks the rip an item off from left aligned shelf in secondary monitor.
1611 TEST_F(ShelfViewTest
, CheckRipOffFromLeftShelfAlignmentWithMultiMonitor
) {
1612 // win8-aura doesn't support multiple display.
1613 if (!SupportsMultipleDisplays())
1616 UpdateDisplay("800x600,800x600");
1617 ASSERT_EQ(2U, Shell::GetAllRootWindows().size());
1619 aura::Window
* second_root
= Shell::GetAllRootWindows()[1];
1621 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT
, second_root
);
1622 ASSERT_EQ(SHELF_ALIGNMENT_LEFT
,
1623 Shell::GetInstance()->GetShelfAlignment(second_root
));
1625 // Initially, app list and browser shortcut are added.
1626 EXPECT_EQ(2, model_
->item_count());
1627 int browser_index
= model_
->GetItemIndexForType(TYPE_BROWSER_SHORTCUT
);
1628 EXPECT_GT(browser_index
, 0);
1630 Shelf
* secondary_shelf
= Shelf::ForWindow(second_root
);
1631 ShelfView
* shelf_view_for_secondary
=
1632 ShelfTestAPI(secondary_shelf
).shelf_view();
1634 ShelfViewTestAPI
test_api_for_secondary_shelf_view(shelf_view_for_secondary
);
1635 ShelfButton
* button
=
1636 test_api_for_secondary_shelf_view
.GetButton(browser_index
);
1638 // Fetch the start point of dragging.
1639 gfx::Point start_point
= button
->GetBoundsInScreen().CenterPoint();
1640 ::wm::ConvertPointFromScreen(second_root
, &start_point
);
1642 ui::test::EventGenerator
generator(second_root
, start_point
);
1644 // Rip off the browser item.
1645 generator
.PressLeftButton();
1646 generator
.MoveMouseTo(start_point
.x() + 400, start_point
.y());
1647 test_api_for_secondary_shelf_view
.RunMessageLoopUntilAnimationsDone();
1648 EXPECT_TRUE(test_api_for_secondary_shelf_view
.IsRippedOffFromShelf());
1651 // Checks various drag and drop operations from OverflowBubble to Shelf.
1652 TEST_F(ShelfViewTest
, CheckDragAndDropFromOverflowBubbleToShelf
) {
1653 // Replace current ShelfDelegate with TestShelfDelegateForShelfView.
1654 ReplaceShelfDelegateForRipOffTest();
1656 AddButtonsUntilOverflow();
1657 // Add one more button to prevent the overflow bubble to disappear upon
1658 // dragging an item out on windows (flakiness, see crbug.com/425097).
1661 TestDraggingAnItemFromOverflowToShelf(false);
1662 TestDraggingAnItemFromOverflowToShelf(true);
1665 // Tests that the AppListButton renders as active in response to touches.
1666 TEST_F(ShelfViewTest
, DISABLED_AppListButtonTouchFeedback
) {
1667 AppListButton
* app_list_button
=
1668 static_cast<AppListButton
*>(shelf_view_
->GetAppListButtonView());
1669 EXPECT_FALSE(app_list_button
->draw_background_as_active());
1671 ui::test::EventGenerator
generator(Shell::GetPrimaryRootWindow());
1672 generator
.set_current_location(app_list_button
->
1673 GetBoundsInScreen().CenterPoint());
1674 generator
.PressTouch();
1675 RunAllPendingInMessageLoop();
1676 EXPECT_TRUE(app_list_button
->draw_background_as_active());
1678 generator
.ReleaseTouch();
1679 RunAllPendingInMessageLoop();
1680 EXPECT_FALSE(app_list_button
->draw_background_as_active());
1681 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
1684 // Tests that a touch that slides out of the bounds of the AppListButton leads
1685 // to the end of rendering an active state.
1686 TEST_F(ShelfViewTest
, DISABLED_AppListButtonTouchFeedbackCancellation
) {
1687 AppListButton
* app_list_button
=
1688 static_cast<AppListButton
*>(shelf_view_
->GetAppListButtonView());
1689 EXPECT_FALSE(app_list_button
->draw_background_as_active());
1691 ui::test::EventGenerator
generator(Shell::GetPrimaryRootWindow());
1692 generator
.set_current_location(app_list_button
->
1693 GetBoundsInScreen().CenterPoint());
1694 generator
.PressTouch();
1695 RunAllPendingInMessageLoop();
1696 EXPECT_TRUE(app_list_button
->draw_background_as_active());
1698 gfx::Point
moved_point(app_list_button
->GetBoundsInScreen().right() + 1,
1700 GetBoundsInScreen().CenterPoint().y());
1701 generator
.MoveTouch(moved_point
);
1702 RunAllPendingInMessageLoop();
1703 EXPECT_FALSE(app_list_button
->draw_background_as_active());
1705 generator
.set_current_location(moved_point
);
1706 generator
.ReleaseTouch();
1707 RunAllPendingInMessageLoop();
1708 EXPECT_FALSE(app_list_button
->draw_background_as_active());
1709 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility());
1712 class ShelfViewVisibleBoundsTest
: public ShelfViewTest
,
1713 public testing::WithParamInterface
<bool> {
1715 ShelfViewVisibleBoundsTest() : text_direction_change_(GetParam()) {}
1717 void CheckAllItemsAreInBounds() {
1718 gfx::Rect visible_bounds
= shelf_view_
->GetVisibleItemsBoundsInScreen();
1719 gfx::Rect shelf_bounds
= shelf_view_
->GetBoundsInScreen();
1720 EXPECT_TRUE(shelf_bounds
.Contains(visible_bounds
));
1721 for (int i
= 0; i
< test_api_
->GetButtonCount(); ++i
)
1722 if (ShelfButton
* button
= test_api_
->GetButton(i
))
1723 EXPECT_TRUE(visible_bounds
.Contains(button
->GetBoundsInScreen()));
1724 CheckAppListButtonIsInBounds();
1727 void CheckAppListButtonIsInBounds() {
1728 gfx::Rect visible_bounds
= shelf_view_
->GetVisibleItemsBoundsInScreen();
1729 gfx::Rect app_list_button_bounds
= shelf_view_
->GetAppListButtonView()->
1730 GetBoundsInScreen();
1731 EXPECT_TRUE(visible_bounds
.Contains(app_list_button_bounds
));
1735 ScopedTextDirectionChange text_direction_change_
;
1737 DISALLOW_COPY_AND_ASSIGN(ShelfViewVisibleBoundsTest
);
1740 TEST_P(ShelfViewVisibleBoundsTest
, ItemsAreInBounds
) {
1741 // Adding elements leaving some empty space.
1742 for (int i
= 0; i
< 3; i
++) {
1745 test_api_
->RunMessageLoopUntilAnimationsDone();
1746 EXPECT_FALSE(test_api_
->IsOverflowButtonVisible());
1747 CheckAllItemsAreInBounds();
1748 // Same for overflow case.
1749 while (!test_api_
->IsOverflowButtonVisible()) {
1752 test_api_
->RunMessageLoopUntilAnimationsDone();
1753 CheckAllItemsAreInBounds();
1756 INSTANTIATE_TEST_CASE_P(LtrRtl
, ShelfViewTextDirectionTest
, testing::Bool());
1757 INSTANTIATE_TEST_CASE_P(VisibleBounds
, ShelfViewVisibleBoundsTest
,