15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
58bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "ash/shelf/shelf_view.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <algorithm>
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
107dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "ash/ash_switches.h"
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/root_window_controller.h"
121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "ash/shelf/app_list_button.h"
13f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ash/shelf/overflow_bubble.h"
14f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ash/shelf/overflow_bubble_view.h"
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/shelf/shelf.h"
16f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ash/shelf/shelf_button.h"
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/shelf/shelf_constants.h"
181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ash/shelf/shelf_icon_observer.h"
19a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ash/shelf/shelf_item_delegate_manager.h"
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/shelf/shelf_layout_manager.h"
21f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ash/shelf/shelf_model.h"
224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ash/shelf/shelf_tooltip_manager.h"
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/shelf/shelf_widget.h"
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell.h"
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/shell_window_ids.h"
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/test/ash_test_base.h"
27f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ash/test/overflow_bubble_view_test_api.h"
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/test/shelf_test_api.h"
298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "ash/test/shelf_view_test_api.h"
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/test/shell_test_api.h"
31a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ash/test/test_shelf_delegate.h"
32a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ash/test/test_shelf_item_delegate.h"
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
347dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "base/command_line.h"
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h"
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
37a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "base/strings/string_number_conversions.h"
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/test/aura_test_base.h"
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/window.h"
40a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/aura/window_event_dispatcher.h"
41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ui/base/l10n/l10n_util.h"
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer.h"
43d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/events/event.h"
44d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/events/event_constants.h"
455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "ui/events/test/event_generator.h"
46868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ui/views/view_model.h"
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/widget.h"
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/widget_delegate.h"
496e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "ui/wm/core/coordinate_conversion.h"
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ash {
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace test {
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)////////////////////////////////////////////////////////////////////////////////
551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// ShelfIconObserver tests.
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TestShelfIconObserver : public ShelfIconObserver {
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  explicit TestShelfIconObserver(Shelf* shelf)
605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      : shelf_(shelf),
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        change_notified_(false) {
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    if (shelf_)
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      shelf_->AddIconObserver(this);
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual ~TestShelfIconObserver() {
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    if (shelf_)
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      shelf_->RemoveIconObserver(this);
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // ShelfIconObserver implementation.
721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void OnShelfIconPositionsChanged() OVERRIDE {
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    change_notified_ = true;
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int change_notified() const { return change_notified_; }
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void Reset() { change_notified_ = false; }
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Shelf* shelf_;
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool change_notified_;
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TestShelfIconObserver);
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
86a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class ShelfViewIconObserverTest : public AshTestBase {
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
888bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  ShelfViewIconObserverTest() {}
898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual ~ShelfViewIconObserverTest() {}
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SetUp() OVERRIDE {
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    AshTestBase::SetUp();
935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    Shelf* shelf = Shelf::ForPrimaryDisplay();
945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    observer_.reset(new TestShelfIconObserver(shelf));
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    shelf_view_test_.reset(
975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        new ShelfViewTestAPI(ShelfTestAPI(shelf).shelf_view()));
988bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    shelf_view_test_->SetAnimationDuration(1);
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void TearDown() OVERRIDE {
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    observer_.reset();
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    AshTestBase::TearDown();
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TestShelfIconObserver* observer() { return observer_.get(); }
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  ShelfViewTestAPI* shelf_view_test() {
1098bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    return shelf_view_test_.get();
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Shelf* ShelfForSecondaryDisplay() {
1135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return Shelf::ForWindow(Shell::GetAllRootWindows()[1]);
1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
1171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  scoped_ptr<TestShelfIconObserver> observer_;
1188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  scoped_ptr<ShelfViewTestAPI> shelf_view_test_;
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(ShelfViewIconObserverTest);
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
123f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// TestShelfItemDelegate which tracks whether it gets selected.
124f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)class ShelfItemSelectionTracker : public TestShelfItemDelegate {
125f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) public:
126f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  ShelfItemSelectionTracker() : TestShelfItemDelegate(NULL), selected_(false) {
127f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  }
128f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
129f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual ~ShelfItemSelectionTracker() {
130f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  }
131f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Resets to the initial state.
1331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void Reset() { selected_ = false; }
1341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
135f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Returns true if the delegate was selected.
136f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  bool WasSelected() {
137f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    return selected_;
138f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  }
139f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
140f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // TestShelfItemDelegate:
141f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual bool ItemSelected(const ui::Event& event) OVERRIDE {
142f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    selected_ = true;
143f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    return false;
144f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  }
145f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
146f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) private:
147f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  bool selected_;
148f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
149f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(ShelfItemSelectionTracker);
150f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)};
151f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(ShelfViewIconObserverTest, AddRemove) {
153a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  TestShelfDelegate* shelf_delegate = TestShelfDelegate::instance();
154a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  ASSERT_TRUE(shelf_delegate);
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  params.bounds = gfx::Rect(0, 0, 200, 200);
1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  params.context = CurrentContext();
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<views::Widget> widget(new views::Widget());
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  widget->Init(params);
1635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  shelf_delegate->AddShelfItem(widget->GetNativeWindow());
1648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  shelf_view_test()->RunMessageLoopUntilAnimationsDone();
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(observer()->change_notified());
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  observer()->Reset();
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  widget->Show();
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  widget->GetNativeWindow()->parent()->RemoveChild(widget->GetNativeWindow());
1708bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  shelf_view_test()->RunMessageLoopUntilAnimationsDone();
1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(observer()->change_notified());
1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  observer()->Reset();
1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Sometimes fails on trybots on win7_aura. http://crbug.com/177135
1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN)
1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define MAYBE_AddRemoveWithMultipleDisplays \
1782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DISABLED_AddRemoveWithMultipleDisplays
1792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#else
1802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define MAYBE_AddRemoveWithMultipleDisplays \
1812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    AddRemoveWithMultipleDisplays
1822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Make sure creating/deleting an window on one displays notifies a
1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// shelf on external display as well as one on primary.
1858bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(ShelfViewIconObserverTest, MAYBE_AddRemoveWithMultipleDisplays) {
1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  UpdateDisplay("400x400,400x400");
1875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  TestShelfIconObserver second_observer(ShelfForSecondaryDisplay());
1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
189a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  TestShelfDelegate* shelf_delegate = TestShelfDelegate::instance();
190a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  ASSERT_TRUE(shelf_delegate);
1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  params.bounds = gfx::Rect(0, 0, 200, 200);
1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  params.context = CurrentContext();
1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<views::Widget> widget(new views::Widget());
1982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  widget->Init(params);
1995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  shelf_delegate->AddShelfItem(widget->GetNativeWindow());
2008bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  shelf_view_test()->RunMessageLoopUntilAnimationsDone();
2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(observer()->change_notified());
2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(second_observer.change_notified());
2032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  observer()->Reset();
2042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  second_observer.Reset();
2052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  widget->GetNativeWindow()->parent()->RemoveChild(widget->GetNativeWindow());
2078bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  shelf_view_test()->RunMessageLoopUntilAnimationsDone();
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(observer()->change_notified());
2092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(second_observer.change_notified());
2102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  observer()->Reset();
2122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  second_observer.Reset();
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(ShelfViewIconObserverTest, BoundsChanged) {
2165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfWidget* widget = Shell::GetPrimaryRootWindowController()->shelf();
2175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Shelf* shelf = Shelf::ForPrimaryDisplay();
2185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gfx::Size shelf_size = widget->GetWindowBoundsInScreen().size();
2192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  shelf_size.set_width(shelf_size.width() / 2);
2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_GT(shelf_size.width(), 0);
2215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  shelf->SetShelfViewBounds(gfx::Rect(shelf_size));
2228bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // No animation happens for ShelfView bounds change.
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(observer()->change_notified());
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  observer()->Reset();
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)////////////////////////////////////////////////////////////////////////////////
2288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// ShelfView tests.
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
230a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Simple ShelfDelegate implmentation for ShelfViewTest.OverflowBubbleSize
231a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// and CheckDragAndDropFromOverflowBubbleToShelf
232a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class TestShelfDelegateForShelfView : public ShelfDelegate {
233f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) public:
234a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  explicit TestShelfDelegateForShelfView(ShelfModel* model)
235a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      : model_(model) {}
236a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual ~TestShelfDelegateForShelfView() {}
237a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
238a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // ShelfDelegate overrides:
2395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void OnShelfCreated(Shelf* shelf) OVERRIDE {}
240a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
2415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void OnShelfDestroyed(Shelf* shelf) OVERRIDE {}
242a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
2435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual ShelfID GetShelfIDForAppID(const std::string& app_id) OVERRIDE {
2445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ShelfID id = 0;
245a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    EXPECT_TRUE(base::StringToInt(app_id, &id));
246a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return id;
247a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
248a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
2495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual const std::string& GetAppIDForShelfID(ShelfID id) OVERRIDE {
250a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    // Use |app_id_| member variable because returning a reference to local
251a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    // variable is not allowed.
252a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    app_id_ = base::IntToString(id);
253a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return app_id_;
254a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
255a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
256a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual void PinAppWithID(const std::string& app_id) OVERRIDE {
257a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
258f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
259f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual bool IsAppPinned(const std::string& app_id) OVERRIDE {
260f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    // Returns true for ShelfViewTest.OverflowBubbleSize. To test ripping off in
261f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    // that test, an item is already pinned state.
262f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    return true;
263f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
264f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
265a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual bool CanPin() const OVERRIDE {
266a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return true;
267a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
268a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
269a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual void UnpinAppWithID(const std::string& app_id) OVERRIDE {
2705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ShelfID id = 0;
271a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    EXPECT_TRUE(base::StringToInt(app_id, &id));
272a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    ASSERT_GT(id, 0);
273a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    int index = model_->ItemIndexByID(id);
274a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    ASSERT_GE(index, 0);
275a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
276a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    model_->RemoveItemAt(index);
277a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
278a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
279f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) private:
280a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  ShelfModel* model_;
281a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
282a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Temp member variable for returning a value. See the comment in the
2835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // GetAppIDForShelfID().
284a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  std::string app_id_;
285a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
286a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TestShelfDelegateForShelfView);
287f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)};
288f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
2898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)class ShelfViewTest : public AshTestBase {
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
2911320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  ShelfViewTest()
2921320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      : model_(NULL),
2931320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci        shelf_view_(NULL),
2941320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci        browser_index_(1),
2951320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci        item_manager_(NULL) {}
2968bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual ~ShelfViewTest() {}
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SetUp() OVERRIDE {
2991320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    CommandLine::ForCurrentProcess()->AppendSwitch(
3001320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci        switches::kAshEnableTouchViewTouchFeedback);
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    AshTestBase::SetUp();
3022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    test::ShellTestApi test_api(Shell::GetInstance());
303f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    model_ = test_api.shelf_model();
3045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    Shelf* shelf = Shelf::ForPrimaryDisplay();
3055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    shelf_view_ = ShelfTestAPI(shelf).shelf_view();
3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // The bounds should be big enough for 4 buttons + overflow chevron.
308a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    shelf_view_->SetBounds(0, 0, 500, kShelfSize);
3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    test_api_.reset(new ShelfViewTestAPI(shelf_view_));
3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    test_api_->SetAnimationDuration(1);  // Speeds up animation for test.
31290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
313a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    item_manager_ = Shell::GetInstance()->shelf_item_delegate_manager();
3144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    DCHECK(item_manager_);
3154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
3165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Add browser shortcut shelf item at index 0 for test.
31790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    AddBrowserShortcut();
31858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  }
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void TearDown() OVERRIDE {
3212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    test_api_.reset();
3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    AshTestBase::TearDown();
3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
3265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void CreateAndSetShelfItemDelegateForID(ShelfID id) {
327a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    scoped_ptr<ShelfItemDelegate> delegate(new TestShelfItemDelegate(NULL));
328a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    item_manager_->SetShelfItemDelegate(id, delegate.Pass());
3294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
3304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
3315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID AddBrowserShortcut() {
3325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ShelfItem browser_shortcut;
33390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    browser_shortcut.type = TYPE_BROWSER_SHORTCUT;
33490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
3355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ShelfID id = model_->next_id();
33658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    model_->AddAt(browser_index_, browser_shortcut);
337a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    CreateAndSetShelfItemDelegateForID(id);
33890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    test_api_->RunMessageLoopUntilAnimationsDone();
33990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    return id;
34090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
34190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
3425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID AddAppShortcut() {
3435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ShelfItem item;
3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    item.type = TYPE_APP_SHORTCUT;
3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    item.status = STATUS_CLOSED;
3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ShelfID id = model_->next_id();
3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    model_->Add(item);
349a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    CreateAndSetShelfItemDelegateForID(id);
3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    test_api_->RunMessageLoopUntilAnimationsDone();
3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return id;
3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID AddPanel() {
3555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ShelfID id = AddPanelNoWait();
3562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    test_api_->RunMessageLoopUntilAnimationsDone();
3572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return id;
3582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID AddPlatformAppNoWait() {
3615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ShelfItem item;
3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    item.type = TYPE_PLATFORM_APP;
3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    item.status = STATUS_RUNNING;
3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ShelfID id = model_->next_id();
3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    model_->Add(item);
367a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    CreateAndSetShelfItemDelegateForID(id);
3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return id;
3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID AddPanelNoWait() {
3725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ShelfItem item;
3732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    item.type = TYPE_APP_PANEL;
3742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    item.status = STATUS_RUNNING;
3752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ShelfID id = model_->next_id();
3772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    model_->Add(item);
378a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    CreateAndSetShelfItemDelegateForID(id);
3792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return id;
3802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID AddPlatformApp() {
3835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ShelfID id = AddPlatformAppNoWait();
3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    test_api_->RunMessageLoopUntilAnimationsDone();
3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return id;
3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void RemoveByID(ShelfID id) {
3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    model_->RemoveItemAt(model_->ItemIndexByID(id));
3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    test_api_->RunMessageLoopUntilAnimationsDone();
3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
393c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfButton* GetButtonByID(ShelfID id) {
3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    int index = model_->ItemIndexByID(id);
3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return test_api_->GetButton(index);
3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfItem GetItemByID(ShelfID id) {
3995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ShelfItems::const_iterator items = model_->ItemByID(id);
4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return *items;
4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void CheckModelIDs(
4045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const std::vector<std::pair<ShelfID, views::View*> >& id_map) {
4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    size_t map_index = 0;
4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    for (size_t model_index = 0;
4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         model_index < model_->items().size();
4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         ++model_index) {
4095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ShelfItem item = model_->items()[model_index];
4105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ShelfID id = item.id;
4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      EXPECT_EQ(id_map[map_index].first, id);
4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      EXPECT_EQ(id_map[map_index].second, GetButtonByID(id));
4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      ++map_index;
4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ASSERT_EQ(map_index, id_map.size());
4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void VerifyShelfItemBoundsAreValid() {
4191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    for (int i = 0; i <= test_api_->GetLastVisibleIndex(); ++i) {
4202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      if (test_api_->GetButton(i)) {
4218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        gfx::Rect shelf_view_bounds = shelf_view_->GetLocalBounds();
4222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        gfx::Rect item_bounds = test_api_->GetBoundsByIndex(i);
4235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        EXPECT_GE(item_bounds.x(), 0);
4245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        EXPECT_GE(item_bounds.y(), 0);
4255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        EXPECT_LE(item_bounds.right(), shelf_view_bounds.width());
4265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        EXPECT_LE(item_bounds.bottom(), shelf_view_bounds.height());
4272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      }
4282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
4292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
4302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  ShelfButton* SimulateButtonPressed(ShelfButtonHost::Pointer pointer,
432c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch                                     int button_index) {
433c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    ShelfButtonHost* button_host = shelf_view_;
4341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    ShelfButton* button = test_api_->GetButton(button_index);
4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ui::MouseEvent click_event(ui::ET_MOUSE_PRESSED,
436f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                               gfx::Point(),
4375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                               button->GetBoundsInScreen().origin(), 0, 0);
4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    button_host->PointerPressedOnButton(button, pointer, click_event);
439ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    return button;
440ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  }
441ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
4421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Simulates a single mouse click.
4431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void SimulateClick(int button_index) {
444c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    ShelfButtonHost* button_host = shelf_view_;
4451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    ShelfButton* button =
4461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci        SimulateButtonPressed(ShelfButtonHost::MOUSE, button_index);
4471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED,
4481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                 gfx::Point(),
4491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                 button->GetBoundsInScreen().origin(),
4501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                 0,
4511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                 0);
4521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    test_api_->ButtonPressed(button, release_event);
4531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    button_host->PointerReleasedOnButton(button, ShelfButtonHost::MOUSE, false);
4541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  }
4551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
4561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Simulates the second click of a double click.
4571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void SimulateDoubleClick(int button_index) {
4581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    ShelfButtonHost* button_host = shelf_view_;
4591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    ShelfButton* button =
4601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci        SimulateButtonPressed(ShelfButtonHost::MOUSE, button_index);
4611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED,
4621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                 gfx::Point(),
4631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                 button->GetBoundsInScreen().origin(),
4641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                 ui::EF_IS_DOUBLE_CLICK,
4651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                 0);
4661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    test_api_->ButtonPressed(button, release_event);
467c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    button_host->PointerReleasedOnButton(button, ShelfButtonHost::MOUSE, false);
468ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  }
469ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
470c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  views::View* SimulateDrag(ShelfButtonHost::Pointer pointer,
471ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch                            int button_index,
472ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch                            int destination_index) {
473c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    ShelfButtonHost* button_host = shelf_view_;
474ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    views::View* button = SimulateButtonPressed(pointer, button_index);
4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Drag.
47790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    views::View* destination = test_api_->GetButton(destination_index);
4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED,
479f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                              gfx::Point(destination->x() - button->x(),
480f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                                         destination->y() - button->y()),
4815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                              destination->GetBoundsInScreen().origin(), 0, 0);
4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    button_host->PointerDraggedOnButton(button, pointer, drag_event);
4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return button;
4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetupForDragTest(
4875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      std::vector<std::pair<ShelfID, views::View*> >* id_map) {
4885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Initialize |id_map| with the automatically-created shelf buttons.
4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    for (size_t i = 0; i < model_->items().size(); ++i) {
490c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      ShelfButton* button = test_api_->GetButton(i);
4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      id_map->push_back(std::make_pair(model_->items()[i].id, button));
4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map));
4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Add 5 app shelf buttons for testing.
4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    for (int i = 0; i < 5; ++i) {
4975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ShelfID id = AddAppShortcut();
49858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      // App Icon is located at index 0, and browser shortcut is located at
49958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      // index 1. So we should start to add app shortcut at index 2.
50058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      id_map->insert(id_map->begin() + (i + browser_index_ + 1),
5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                     std::make_pair(id, GetButtonByID(id)));
5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map));
5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  views::View* GetTooltipAnchorView() {
5078bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    return shelf_view_->tooltip_manager()->anchor_;
5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
510a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void AddButtonsUntilOverflow() {
511a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    int items_added = 0;
512a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    while (!test_api_->IsOverflowButtonVisible()) {
513a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      AddAppShortcut();
514a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      ++items_added;
515a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      ASSERT_LT(items_added, 10000);
516a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    }
517a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
518a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ShowTooltip() {
5208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    shelf_view_->tooltip_manager()->ShowInternal();
5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
523a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void TestDraggingAnItemFromOverflowToShelf(bool cancel) {
524a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    test_api_->ShowOverflowBubble();
525a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    ASSERT_TRUE(test_api_->overflow_bubble() &&
526a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                test_api_->overflow_bubble()->IsShowing());
527a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
528a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    ash::test::ShelfViewTestAPI test_api_for_overflow(
529a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      test_api_->overflow_bubble()->shelf_view());
530a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
531a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    int total_item_count = model_->item_count();
532a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
533a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    int last_visible_item_id_in_shelf =
5345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        GetItemId(test_api_->GetLastVisibleIndex());
535a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    int second_last_visible_item_id_in_shelf =
5365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        GetItemId(test_api_->GetLastVisibleIndex() - 1);
537a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    int first_visible_item_id_in_overflow =
5385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        GetItemId(test_api_for_overflow.GetFirstVisibleIndex());
539a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    int second_last_visible_item_id_in_overflow =
5405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        GetItemId(test_api_for_overflow.GetLastVisibleIndex() - 1);
541a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
542a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    int drag_item_index =
543a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)        test_api_for_overflow.GetLastVisibleIndex();
5445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ShelfID drag_item_id = GetItemId(drag_item_index);
545c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    ShelfButton* drag_button = test_api_for_overflow.GetButton(drag_item_index);
546a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    gfx::Point center_point_of_drag_item =
547a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)        drag_button->GetBoundsInScreen().CenterPoint();
548a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
5495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    ui::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow(),
5505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                       center_point_of_drag_item);
551a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    // Rip an item off to OverflowBubble.
552a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    generator.PressLeftButton();
553a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    gfx::Point rip_off_point(center_point_of_drag_item.x(), 0);
554a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    generator.MoveMouseTo(rip_off_point);
555a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    test_api_for_overflow.RunMessageLoopUntilAnimationsDone();
5565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ASSERT_TRUE(test_api_for_overflow.IsRippedOffFromShelf());
557a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    ASSERT_FALSE(test_api_for_overflow.DraggedItemFromOverflowToShelf());
558a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
559a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    // Move a dragged item into Shelf at |drop_index|.
560a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    int drop_index = 1;
561a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    gfx::Point drop_point =
562a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)        test_api_->GetButton(drop_index)->GetBoundsInScreen().CenterPoint();
563a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    int item_width = test_api_for_overflow.GetButtonSize();
564a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    // To insert at |drop_index|, more smaller x-axis value of |drop_point|
565a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    // should be used.
566a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    gfx::Point modified_drop_point(drop_point.x() - item_width / 4,
567a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                   drop_point.y());
568a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    generator.MoveMouseTo(modified_drop_point);
569a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    test_api_for_overflow.RunMessageLoopUntilAnimationsDone();
570a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    test_api_->RunMessageLoopUntilAnimationsDone();
5715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ASSERT_TRUE(test_api_for_overflow.IsRippedOffFromShelf());
572a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    ASSERT_TRUE(test_api_for_overflow.DraggedItemFromOverflowToShelf());
573a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
574a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    if (cancel)
575a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      drag_button->OnMouseCaptureLost();
576a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    else
577a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      generator.ReleaseLeftButton();
578a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
579a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    test_api_for_overflow.RunMessageLoopUntilAnimationsDone();
580a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    test_api_->RunMessageLoopUntilAnimationsDone();
5815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ASSERT_FALSE(test_api_for_overflow.IsRippedOffFromShelf());
582a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    ASSERT_FALSE(test_api_for_overflow.DraggedItemFromOverflowToShelf());
583a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
584a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    // Compare pre-stored items' id with newly positioned items' after dragging
585a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    // is canceled or finished.
586a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    if (cancel) {
5875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      EXPECT_EQ(last_visible_item_id_in_shelf,
5885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                GetItemId(test_api_->GetLastVisibleIndex()));
5895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      EXPECT_EQ(second_last_visible_item_id_in_shelf,
5905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                GetItemId(test_api_->GetLastVisibleIndex() - 1));
5915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      EXPECT_EQ(first_visible_item_id_in_overflow,
5925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                GetItemId(test_api_for_overflow.GetFirstVisibleIndex()));
5935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      EXPECT_EQ(second_last_visible_item_id_in_overflow,
5945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                GetItemId(test_api_for_overflow.GetLastVisibleIndex() - 1));
595a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    } else {
5965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      EXPECT_EQ(drag_item_id, GetItemId(drop_index));
5975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      EXPECT_EQ(total_item_count, model_->item_count());
5985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      EXPECT_EQ(last_visible_item_id_in_shelf,
5995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                GetItemId(test_api_for_overflow.GetFirstVisibleIndex()));
6005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      EXPECT_EQ(second_last_visible_item_id_in_shelf,
6015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                GetItemId(test_api_->GetLastVisibleIndex()));
6025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      EXPECT_EQ(first_visible_item_id_in_overflow,
6035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                GetItemId(test_api_for_overflow.GetFirstVisibleIndex() + 1));
6045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      EXPECT_EQ(second_last_visible_item_id_in_overflow,
6055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                GetItemId(test_api_for_overflow.GetLastVisibleIndex()));
606a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    }
607a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
608a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
6095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Returns the item's ShelfID at |index|.
6105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID GetItemId(int index) {
6115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    DCHECK_GE(index, 0);
6125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return model_->items()[index].id;
6135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
6145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void ReplaceShelfDelegateForRipOffTest() {
6165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Replace ShelfDelegate.
6175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    test::ShellTestApi test_api(Shell::GetInstance());
6185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    test_api.SetShelfDelegate(NULL);
6195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ShelfDelegate* delegate = new TestShelfDelegateForShelfView(model_);
6205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    test_api.SetShelfDelegate(delegate);
6215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    test::ShelfTestAPI(Shelf::ForPrimaryDisplay()).SetShelfDelegate(delegate);
6225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    test_api_->SetShelfDelegate(delegate);
6235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
6245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
625f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ShelfModel* model_;
626c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfView* shelf_view_;
62758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  int browser_index_;
628a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  ShelfItemDelegateManager* item_manager_;
6292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  scoped_ptr<ShelfViewTestAPI> test_api_;
6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
6338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(ShelfViewTest);
6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)class ScopedTextDirectionChange {
6374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) public:
6381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  explicit ScopedTextDirectionChange(bool is_rtl) : is_rtl_(is_rtl) {
6394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    original_locale_ = l10n_util::GetApplicationLocale(std::string());
6404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    if (is_rtl_)
6414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      base::i18n::SetICUDefaultLocale("he");
6424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    CheckTextDirectionIsCorrect();
6434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
6444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
6454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ~ScopedTextDirectionChange() {
6464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    if (is_rtl_)
6474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      base::i18n::SetICUDefaultLocale(original_locale_);
6484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
6494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
6504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) private:
6514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void CheckTextDirectionIsCorrect() {
6524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    ASSERT_EQ(is_rtl_, base::i18n::IsRTL());
6534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
6544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
6554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  bool is_rtl_;
6564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  std::string original_locale_;
6574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)};
6584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
6598bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)class ShelfViewTextDirectionTest
6608bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    : public ShelfViewTest,
661868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      public testing::WithParamInterface<bool> {
662868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public:
6638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  ShelfViewTextDirectionTest() : text_direction_change_(GetParam()) {}
6648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual ~ShelfViewTextDirectionTest() {}
665868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
666868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void SetUp() OVERRIDE {
6678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    ShelfViewTest::SetUp();
668868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  }
669868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
670868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void TearDown() OVERRIDE {
6718bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    ShelfViewTest::TearDown();
672868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  }
673868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
674868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) private:
6754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ScopedTextDirectionChange text_direction_change_;
676868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
6778bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(ShelfViewTextDirectionTest);
678868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
679868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
680868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Checks that the ideal item icon bounds match the view's bounds in the screen
681868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// in both LTR and RTL.
6828bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_P(ShelfViewTextDirectionTest, IdealBoundsOfItemIcon) {
6835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID id = AddPlatformApp();
684c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfButton* button = GetButtonByID(id);
685868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  gfx::Rect item_bounds = button->GetBoundsInScreen();
686868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  gfx::Point icon_offset = button->GetIconBounds().origin();
687868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  item_bounds.Offset(icon_offset.OffsetFromOrigin());
6888bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  gfx::Rect ideal_bounds = shelf_view_->GetIdealBoundsOfItemIcon(id);
689868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  gfx::Point screen_origin;
6908bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  views::View::ConvertPointToScreen(shelf_view_, &screen_origin);
691868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ideal_bounds.Offset(screen_origin.x(), screen_origin.y());
692868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(item_bounds.x(), ideal_bounds.x());
693868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(item_bounds.y(), ideal_bounds.y());
694868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
695868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
696cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Check that items in the overflow area are returning the overflow button as
697cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// ideal bounds.
698cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)TEST_F(ShelfViewTest, OverflowButtonBounds) {
699cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  ShelfID first_id = AddPlatformApp();
700cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  ShelfID overflow_id = AddPlatformApp();
701cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  int items_added = 0;
702cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  while (!test_api_->IsOverflowButtonVisible()) {
703cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    // Added button is visible after animation while in this loop.
704cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    EXPECT_TRUE(GetButtonByID(overflow_id)->visible());
705cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    overflow_id = AddPlatformApp();
706cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    ++items_added;
707cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    ASSERT_LT(items_added, 10000);
708cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
709cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  ShelfID last_id = AddPlatformApp();
710cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
711cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  gfx::Rect first_bounds = shelf_view_->GetIdealBoundsOfItemIcon(first_id);
712cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  gfx::Rect overflow_bounds =
713cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      shelf_view_->GetIdealBoundsOfItemIcon(overflow_id);
714cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  gfx::Rect last_bounds = shelf_view_->GetIdealBoundsOfItemIcon(last_id);
715cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
716cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Check that all items have the same size and that the overflow items are
717cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // identical whereas the first one does not match either of them.
718cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ(first_bounds.size().ToString(), last_bounds.size().ToString());
719cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_NE(first_bounds.ToString(), last_bounds.ToString());
720cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ(overflow_bounds.ToString(), last_bounds.ToString());
721cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
722cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
7238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Checks that shelf view contents are considered in the correct drag group.
7248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(ShelfViewTest, EnforceDragType) {
725ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_TRUE(test_api_->SameDragType(TYPE_PLATFORM_APP, TYPE_PLATFORM_APP));
726ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_FALSE(test_api_->SameDragType(TYPE_PLATFORM_APP, TYPE_APP_SHORTCUT));
727ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_FALSE(test_api_->SameDragType(TYPE_PLATFORM_APP,
728ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch                                       TYPE_BROWSER_SHORTCUT));
729ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_FALSE(test_api_->SameDragType(TYPE_PLATFORM_APP, TYPE_WINDOWED_APP));
730ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_FALSE(test_api_->SameDragType(TYPE_PLATFORM_APP, TYPE_APP_LIST));
731ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_FALSE(test_api_->SameDragType(TYPE_PLATFORM_APP, TYPE_APP_PANEL));
732ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
733ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_TRUE(test_api_->SameDragType(TYPE_APP_SHORTCUT, TYPE_APP_SHORTCUT));
734ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_TRUE(test_api_->SameDragType(TYPE_APP_SHORTCUT,
735ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch                                      TYPE_BROWSER_SHORTCUT));
736ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_FALSE(test_api_->SameDragType(TYPE_APP_SHORTCUT,
737ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch                                       TYPE_WINDOWED_APP));
738ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_FALSE(test_api_->SameDragType(TYPE_APP_SHORTCUT, TYPE_APP_LIST));
739ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_FALSE(test_api_->SameDragType(TYPE_APP_SHORTCUT, TYPE_APP_PANEL));
740ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
741ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_TRUE(test_api_->SameDragType(TYPE_BROWSER_SHORTCUT,
742ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch                                      TYPE_BROWSER_SHORTCUT));
743ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_FALSE(test_api_->SameDragType(TYPE_BROWSER_SHORTCUT,
744ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch                                       TYPE_WINDOWED_APP));
745ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_FALSE(test_api_->SameDragType(TYPE_BROWSER_SHORTCUT, TYPE_APP_LIST));
746ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_FALSE(test_api_->SameDragType(TYPE_BROWSER_SHORTCUT, TYPE_APP_PANEL));
747ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
748ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_TRUE(test_api_->SameDragType(TYPE_WINDOWED_APP, TYPE_WINDOWED_APP));
749ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_FALSE(test_api_->SameDragType(TYPE_WINDOWED_APP, TYPE_APP_LIST));
750ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_FALSE(test_api_->SameDragType(TYPE_WINDOWED_APP, TYPE_APP_PANEL));
751ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
752ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_TRUE(test_api_->SameDragType(TYPE_APP_LIST, TYPE_APP_LIST));
753ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_FALSE(test_api_->SameDragType(TYPE_APP_LIST, TYPE_APP_PANEL));
754ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
755ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_TRUE(test_api_->SameDragType(TYPE_APP_PANEL, TYPE_APP_PANEL));
756ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch}
757ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
758424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// Adds platform app button until overflow and verifies that the last added
759424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// platform app button is hidden.
7608bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(ShelfViewTest, AddBrowserUntilOverflow) {
7615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // All buttons should be visible.
7625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_EQ(test_api_->GetButtonCount(),
7635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            test_api_->GetLastVisibleIndex() + 1);
7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
765424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Add platform app button until overflow.
7662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int items_added = 0;
7675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID last_added = AddPlatformApp();
7685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  while (!test_api_->IsOverflowButtonVisible()) {
7695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Added button is visible after animation while in this loop.
7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_TRUE(GetButtonByID(last_added)->visible());
7715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
772424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    last_added = AddPlatformApp();
7732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ++items_added;
7742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ASSERT_LT(items_added, 10000);
7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The last added button should be invisible.
7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_FALSE(GetButtonByID(last_added)->visible());
7795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
781424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// Adds one platform app button then adds app shortcut until overflow. Verifies
782424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// that the browser button gets hidden on overflow and last added app shortcut
783424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// is still visible.
7848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(ShelfViewTest, AddAppShortcutWithBrowserButtonUntilOverflow) {
7855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // All buttons should be visible.
7865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_EQ(test_api_->GetButtonCount(),
7875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            test_api_->GetLastVisibleIndex() + 1);
7885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID browser_button_id = AddPlatformApp();
7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Add app shortcut until overflow.
7922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int items_added = 0;
7935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID last_added = AddAppShortcut();
7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  while (!test_api_->IsOverflowButtonVisible()) {
7955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Added button is visible after animation while in this loop.
7965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_TRUE(GetButtonByID(last_added)->visible());
7975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    last_added = AddAppShortcut();
7992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ++items_added;
8002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ASSERT_LT(items_added, 10000);
8015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
80358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // And the platform app button is invisible.
80458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_FALSE(GetButtonByID(browser_button_id)->visible());
80558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)}
80658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
8078bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(ShelfViewTest, AddPanelHidesPlatformAppButton) {
8085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // All buttons should be visible.
8095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_EQ(test_api_->GetButtonCount(),
8105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            test_api_->GetLastVisibleIndex() + 1);
8112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
812424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Add platform app button until overflow, remember last visible platform app
813424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // button.
8142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int items_added = 0;
8155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID first_added = AddPlatformApp();
8162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(GetButtonByID(first_added)->visible());
81758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  while (true) {
8185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ShelfID added = AddPlatformApp();
81958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    if (test_api_->IsOverflowButtonVisible()) {
82058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      EXPECT_FALSE(GetButtonByID(added)->visible());
82158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      RemoveByID(added);
82258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      break;
82358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    }
82458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    ++items_added;
82558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    ASSERT_LT(items_added, 10000);
82658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  }
82758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
8285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID panel = AddPanel();
82958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_TRUE(test_api_->IsOverflowButtonVisible());
83058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
83158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  RemoveByID(panel);
83258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_FALSE(test_api_->IsOverflowButtonVisible());
83358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)}
83458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
835424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// When there are more panels then platform app buttons we should hide panels
836424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// rather than platform apps.
8378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(ShelfViewTest, PlatformAppHidesExcessPanels) {
8385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // All buttons should be visible.
8395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_EQ(test_api_->GetButtonCount(),
8405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            test_api_->GetLastVisibleIndex() + 1);
8412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
842424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Add platform app button.
8435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID platform_app = AddPlatformApp();
8445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID first_panel = AddPanel();
8452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
846424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  EXPECT_TRUE(GetButtonByID(platform_app)->visible());
8472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(GetButtonByID(first_panel)->visible());
8482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Add panels until there is an overflow.
8505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID last_panel = first_panel;
8512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int items_added = 0;
8522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  while (!test_api_->IsOverflowButtonVisible()) {
8532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    last_panel = AddPanel();
8542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ++items_added;
8552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ASSERT_LT(items_added, 10000);
8562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
8572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
858424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // The first panel should now be hidden by the new platform apps needing
859424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // space.
8602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_FALSE(GetButtonByID(first_panel)->visible());
8612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(GetButtonByID(last_panel)->visible());
862424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  EXPECT_TRUE(GetButtonByID(platform_app)->visible());
8632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
864424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Adding platform apps should eventually begin to hide platform apps. We will
865424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // add platform apps until either the last panel or platform app is hidden.
8662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  items_added = 0;
867424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  while (GetButtonByID(platform_app)->visible() &&
8682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)         GetButtonByID(last_panel)->visible()) {
869424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    platform_app = AddPlatformApp();
8702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ++items_added;
8712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ASSERT_LT(items_added, 10000);
8722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
8732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(GetButtonByID(last_panel)->visible());
874424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  EXPECT_FALSE(GetButtonByID(platform_app)->visible());
8752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
8762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Adds button until overflow then removes first added one. Verifies that
8785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the last added one changes from invisible to visible and overflow
8795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// chevron is gone.
8808bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(ShelfViewTest, RemoveButtonRevealsOverflowed) {
8815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // All buttons should be visible.
8825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_EQ(test_api_->GetButtonCount(),
8835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            test_api_->GetLastVisibleIndex() + 1);
8845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
885424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Add platform app buttons until overflow.
8862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int items_added = 0;
8875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID first_added = AddPlatformApp();
8885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID last_added = first_added;
8892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  while (!test_api_->IsOverflowButtonVisible()) {
890424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    last_added = AddPlatformApp();
8912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ++items_added;
8922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ASSERT_LT(items_added, 10000);
8932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
8945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Expect add more than 1 button. First added is visible and last is not.
8965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_NE(first_added, last_added);
8975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(GetButtonByID(first_added)->visible());
8985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_FALSE(GetButtonByID(last_added)->visible());
8995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Remove first added.
9015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RemoveByID(first_added);
9025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Last added button becomes visible and overflow chevron is gone.
9045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(GetButtonByID(last_added)->visible());
9055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(1.0f, GetButtonByID(last_added)->layer()->opacity());
9065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_FALSE(test_api_->IsOverflowButtonVisible());
9075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Verifies that remove last overflowed button should hide overflow chevron.
9108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(ShelfViewTest, RemoveLastOverflowed) {
9115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // All buttons should be visible.
9125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_EQ(test_api_->GetButtonCount(),
9135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            test_api_->GetLastVisibleIndex() + 1);
9145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
915424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Add platform app button until overflow.
9162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int items_added = 0;
9175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID last_added = AddPlatformApp();
9182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  while (!test_api_->IsOverflowButtonVisible()) {
919424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    last_added = AddPlatformApp();
9202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ++items_added;
9212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ASSERT_LT(items_added, 10000);
9222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
9235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RemoveByID(last_added);
9255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_FALSE(test_api_->IsOverflowButtonVisible());
9265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
928424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// Adds platform app button without waiting for animation to finish and verifies
9295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// that all added buttons are visible.
9308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(ShelfViewTest, AddButtonQuickly) {
9315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // All buttons should be visible.
9325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_EQ(test_api_->GetButtonCount(),
9335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            test_api_->GetLastVisibleIndex() + 1);
9345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
935424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Add a few platform buttons quickly without wait for animation.
9365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int added_count = 0;
9375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  while (!test_api_->IsOverflowButtonVisible()) {
938424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    AddPlatformAppNoWait();
9395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ++added_count;
9402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ASSERT_LT(added_count, 10000);
9415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
9425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9438bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // ShelfView should be big enough to hold at least 3 new buttons.
9445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_GE(added_count, 3);
9455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Wait for the last animation to finish.
9475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  test_api_->RunMessageLoopUntilAnimationsDone();
9485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Verifies non-overflow buttons are visible.
9505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (int i = 0; i <= test_api_->GetLastVisibleIndex(); ++i) {
951c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    ShelfButton* button = test_api_->GetButton(i);
9525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (button) {
9535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      EXPECT_TRUE(button->visible()) << "button index=" << i;
9545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      EXPECT_EQ(1.0f, button->layer()->opacity()) << "button index=" << i;
9555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
9565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
9575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Check that model changes are handled correctly while a shelf icon is being
9605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// dragged.
9618bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(ShelfViewTest, ModelChangesWhileDragging) {
962c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfButtonHost* button_host = shelf_view_;
9635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::vector<std::pair<ShelfID, views::View*> > id_map;
9655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SetupForDragTest(&id_map);
9665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
96758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Dragging browser shortcut at index 1.
96858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT);
969c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  views::View* dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 1, 3);
97058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  std::rotate(id_map.begin() + 1,
97158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)              id_map.begin() + 2,
97258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)              id_map.begin() + 4);
97358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
974c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  button_host->PointerReleasedOnButton(
975c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      dragged_button, ShelfButtonHost::MOUSE, false);
97658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT);
97758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
97858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Dragging changes model order.
979c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 1, 3);
98058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  std::rotate(id_map.begin() + 1,
98158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)              id_map.begin() + 2,
98258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)              id_map.begin() + 4);
98358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
98458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
98558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Cancelling the drag operation restores previous order.
986c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  button_host->PointerReleasedOnButton(
987c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      dragged_button, ShelfButtonHost::MOUSE, true);
98858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  std::rotate(id_map.begin() + 1,
98958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)              id_map.begin() + 3,
99058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)              id_map.begin() + 4);
99158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
99258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
99358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Deleting an item keeps the remaining intact.
994c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 1, 3);
99558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  model_->RemoveItemAt(1);
99658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  id_map.erase(id_map.begin() + 1);
99758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
998c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  button_host->PointerReleasedOnButton(
999c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      dragged_button, ShelfButtonHost::MOUSE, false);
100058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
10015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Adding a shelf item cancels the drag and respects the order.
1002c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 1, 3);
10035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID new_id = AddAppShortcut();
100458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  id_map.insert(id_map.begin() + 6,
100558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                std::make_pair(new_id, GetButtonByID(new_id)));
100658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1007c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  button_host->PointerReleasedOnButton(
1008c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      dragged_button, ShelfButtonHost::MOUSE, false);
100958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
10105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Adding a shelf item at the end (i.e. a panel)  canels drag and respects
101158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // the order.
1012c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 1, 3);
101358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  new_id = AddPanel();
101458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  id_map.insert(id_map.begin() + 7,
101558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                std::make_pair(new_id, GetButtonByID(new_id)));
101658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1017c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  button_host->PointerReleasedOnButton(
1018c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      dragged_button, ShelfButtonHost::MOUSE, false);
101958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)}
102058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
10215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Check that 2nd drag from the other pointer would be ignored.
10228bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(ShelfViewTest, SimultaneousDrag) {
1023c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfButtonHost* button_host = shelf_view_;
10245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::vector<std::pair<ShelfID, views::View*> > id_map;
10265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SetupForDragTest(&id_map);
10275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Start a mouse drag.
1029c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  views::View* dragged_button_mouse =
1030c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      SimulateDrag(ShelfButtonHost::MOUSE, 1, 3);
103158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  std::rotate(id_map.begin() + 1,
103258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)              id_map.begin() + 2,
103358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)              id_map.begin() + 4);
10345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
10355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Attempt a touch drag before the mouse drag finishes.
1036c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  views::View* dragged_button_touch =
1037c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      SimulateDrag(ShelfButtonHost::TOUCH, 4, 2);
10385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Nothing changes since 2nd drag is ignored.
10405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
10415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Finish the mouse drag.
1043c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  button_host->PointerReleasedOnButton(
1044c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      dragged_button_mouse, ShelfButtonHost::MOUSE, false);
10455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
10465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Now start a touch drag.
1048c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  dragged_button_touch = SimulateDrag(ShelfButtonHost::TOUCH, 4, 2);
104958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  std::rotate(id_map.begin() + 3,
105058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)              id_map.begin() + 4,
105158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)              id_map.begin() + 5);
10525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
10535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // And attempt a mouse drag before the touch drag finishes.
1055c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  dragged_button_mouse = SimulateDrag(ShelfButtonHost::MOUSE, 1, 2);
10565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Nothing changes since 2nd drag is ignored.
10585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
10595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1060c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  button_host->PointerReleasedOnButton(
1061c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      dragged_button_touch, ShelfButtonHost::TOUCH, false);
10625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
10635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
10645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1065ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch// Check that clicking first on one item and then dragging another works as
1066ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch// expected.
10678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(ShelfViewTest, ClickOneDragAnother) {
1068c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfButtonHost* button_host = shelf_view_;
1069ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
10705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::vector<std::pair<ShelfID, views::View*> > id_map;
1071ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  SetupForDragTest(&id_map);
1072ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
1073ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // A click on item 1 is simulated.
10741320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  SimulateClick(1);
1075ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
1076ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // Dragging browser index at 0 should change the model order correctly.
107758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT);
1078c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  views::View* dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 1, 3);
107958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  std::rotate(id_map.begin() + 1,
108058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)              id_map.begin() + 2,
108158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)              id_map.begin() + 4);
1082ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1083c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  button_host->PointerReleasedOnButton(
1084c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      dragged_button, ShelfButtonHost::MOUSE, false);
108558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT);
1086ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch}
1087ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
10881320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Tests that double-clicking an item does not activate it twice.
10891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciTEST_F(ShelfViewTest, ClickingTwiceActivatesOnce) {
10901320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Watch for selection of the browser shortcut.
10911320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  ShelfID browser_shelf_id = model_->items()[browser_index_].id;
10921320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker;
10931320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  item_manager_->SetShelfItemDelegate(
10941320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      browser_shelf_id,
10951320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      scoped_ptr<ShelfItemDelegate>(selection_tracker).Pass());
10961320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
10971320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // A single click selects the item.
10981320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  SimulateClick(browser_index_);
10991320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_TRUE(selection_tracker->WasSelected());
11001320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
11011320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // A double-click does not select the item.
11021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  selection_tracker->Reset();
11031320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  SimulateDoubleClick(browser_index_);
11041320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_FALSE(selection_tracker->WasSelected());
11051320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
11061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1107f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// Check that clicking an item and jittering the mouse a bit still selects the
1108f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// item.
1109f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)TEST_F(ShelfViewTest, ClickAndMoveSlightly) {
1110f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  std::vector<std::pair<ShelfID, views::View*> > id_map;
1111f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  SetupForDragTest(&id_map);
1112f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1113f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  ShelfID shelf_id = (id_map.begin() + 1)->first;
1114f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  views::View* button = (id_map.begin() + 1)->second;
1115f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1116f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Replace the ShelfItemDelegate for |shelf_id| with one which tracks whether
1117f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // the shelf item gets selected.
1118f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker;
1119f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  item_manager_->SetShelfItemDelegate(
1120f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      shelf_id,
1121f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      scoped_ptr<ShelfItemDelegate>(selection_tracker).Pass());
1122f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1123f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  gfx::Vector2d press_offset(5, 30);
1124f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  gfx::Point press_location = gfx::Point() + press_offset;
1125f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  gfx::Point press_location_in_screen =
1126f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      button->GetBoundsInScreen().origin() + press_offset;
1127f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1128f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  ui::MouseEvent click_event(ui::ET_MOUSE_PRESSED,
1129f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                             press_location,
1130f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                             press_location_in_screen,
1131f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                             ui::EF_LEFT_MOUSE_BUTTON, 0);
1132f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  button->OnMousePressed(click_event);
1133f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1134f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  ui::MouseEvent drag_event1(ui::ET_MOUSE_DRAGGED,
1135f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                             press_location + gfx::Vector2d(0, 1),
1136f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                             press_location_in_screen + gfx::Vector2d(0, 1),
1137f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                             ui::EF_LEFT_MOUSE_BUTTON, 0);
1138f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  button->OnMouseDragged(drag_event1);
1139f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1140f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  ui::MouseEvent drag_event2(ui::ET_MOUSE_DRAGGED,
1141f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                             press_location + gfx::Vector2d(-1, 0),
1142f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                             press_location_in_screen + gfx::Vector2d(-1, 0),
1143f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                             ui::EF_LEFT_MOUSE_BUTTON, 0);
1144f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  button->OnMouseDragged(drag_event2);
1145f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1146f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED,
1147f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                               press_location + gfx::Vector2d(-1, 0),
1148f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                               press_location_in_screen + gfx::Vector2d(-1, 0),
1149f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                               ui::EF_LEFT_MOUSE_BUTTON, 0);
1150f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  button->OnMouseReleased(release_event);
1151f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1152f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_TRUE(selection_tracker->WasSelected());
1153f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)}
1154f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
11555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Confirm that item status changes are reflected in the buttons.
11565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(ShelfViewTest, ShelfItemStatus) {
11575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // All buttons should be visible.
11585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_EQ(test_api_->GetButtonCount(),
11595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            test_api_->GetLastVisibleIndex() + 1);
11605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1161424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Add platform app button.
11625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID last_added = AddPlatformApp();
11635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfItem item = GetItemByID(last_added);
11645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int index = model_->ItemIndexByID(last_added);
1165c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfButton* button = GetButtonByID(last_added);
1166c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ASSERT_EQ(ShelfButton::STATE_RUNNING, button->state());
1167a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  item.status = STATUS_ACTIVE;
11685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  model_->Set(index, item);
1169c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ASSERT_EQ(ShelfButton::STATE_ACTIVE, button->state());
1170a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  item.status = STATUS_ATTENTION;
11715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  model_->Set(index, item);
1172c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ASSERT_EQ(ShelfButton::STATE_ATTENTION, button->state());
11735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
11745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Confirm that item status changes are reflected in the buttons
11765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// for platform apps.
11775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(ShelfViewTest, ShelfItemStatusPlatformApp) {
11785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // All buttons should be visible.
11795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_EQ(test_api_->GetButtonCount(),
11805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            test_api_->GetLastVisibleIndex() + 1);
11815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1182424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Add platform app button.
11835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID last_added = AddPlatformApp();
11845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfItem item = GetItemByID(last_added);
11855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int index = model_->ItemIndexByID(last_added);
1186c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfButton* button = GetButtonByID(last_added);
1187c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ASSERT_EQ(ShelfButton::STATE_RUNNING, button->state());
1188a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  item.status = STATUS_ACTIVE;
11895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  model_->Set(index, item);
1190c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ASSERT_EQ(ShelfButton::STATE_ACTIVE, button->state());
1191a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  item.status = STATUS_ATTENTION;
11925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  model_->Set(index, item);
1193c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ASSERT_EQ(ShelfButton::STATE_ATTENTION, button->state());
11945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
11955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Confirm that shelf item bounds are correctly updated on shelf changes.
11975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(ShelfViewTest, ShelfItemBoundsCheck) {
11985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  VerifyShelfItemBoundsAreValid();
11991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  shelf_view_->shelf_layout_manager()->SetAutoHideBehavior(
12001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
12012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  test_api_->RunMessageLoopUntilAnimationsDone();
12025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  VerifyShelfItemBoundsAreValid();
12031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  shelf_view_->shelf_layout_manager()->SetAutoHideBehavior(
12041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
12052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  test_api_->RunMessageLoopUntilAnimationsDone();
12065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  VerifyShelfItemBoundsAreValid();
12072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
12082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
12098bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(ShelfViewTest, ShelfTooltipTest) {
12105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
12115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            test_api_->GetButtonCount());
12125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Prepare some items to the shelf.
12145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID app_button_id = AddAppShortcut();
12155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID platform_button_id = AddPlatformApp();
12165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1217c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfButton* app_button = GetButtonByID(app_button_id);
1218c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfButton* platform_button = GetButtonByID(platform_button_id);
12195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1220c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfButtonHost* button_host = shelf_view_;
1221c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfTooltipManager* tooltip_manager = shelf_view_->tooltip_manager();
12225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  button_host->MouseEnteredButton(app_button);
12245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // There's a delay to show the tooltip, so it's not visible yet.
12255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_FALSE(tooltip_manager->IsVisible());
12265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(app_button, GetTooltipAnchorView());
12275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ShowTooltip();
12295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(tooltip_manager->IsVisible());
12305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Once it's visible, it keeps visibility and is pointing to the same
12325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // item.
12335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  button_host->MouseExitedButton(app_button);
12345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(tooltip_manager->IsVisible());
12355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(app_button, GetTooltipAnchorView());
12365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // When entered to another item, it switches to the new item.  There is no
12385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // delay for the visibility.
1239424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  button_host->MouseEnteredButton(platform_button);
12405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(tooltip_manager->IsVisible());
1241424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  EXPECT_EQ(platform_button, GetTooltipAnchorView());
12425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1243424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  button_host->MouseExitedButton(platform_button);
12445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tooltip_manager->Close();
12455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Next time: enter app_button -> move immediately to tab_button.
12475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  button_host->MouseEnteredButton(app_button);
12485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  button_host->MouseExitedButton(app_button);
1249424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  button_host->MouseEnteredButton(platform_button);
12505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_FALSE(tooltip_manager->IsVisible());
1251424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  EXPECT_EQ(platform_button, GetTooltipAnchorView());
12525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
12535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Verify a fix for crash caused by a tooltip update for a deletedshelf
1255d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// button, see crbug.com/288838.
12568bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(ShelfViewTest, RemovingItemClosesTooltip) {
1257c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfButtonHost* button_host = shelf_view_;
1258c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfTooltipManager* tooltip_manager = shelf_view_->tooltip_manager();
1259d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
12605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Add an item to the shelf.
12615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID app_button_id = AddAppShortcut();
1262c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfButton* app_button = GetButtonByID(app_button_id);
1263d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
1264d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Spawn a tooltip on that item.
1265d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  button_host->MouseEnteredButton(app_button);
1266d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  ShowTooltip();
1267d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_TRUE(tooltip_manager->IsVisible());
1268d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
1269d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Remove the app shortcut while the tooltip is open. The tooltip should be
1270d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // closed.
1271d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  RemoveByID(app_button_id);
1272d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_FALSE(tooltip_manager->IsVisible());
1273d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
1274d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Change the shelf layout. This should not crash.
1275a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT,
1276a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                          Shell::GetPrimaryRootWindow());
1277d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
1278d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
1279d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Changing the shelf alignment closes any open tooltip.
12808bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(ShelfViewTest, ShelfAlignmentClosesTooltip) {
1281c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfButtonHost* button_host = shelf_view_;
1282c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfTooltipManager* tooltip_manager = shelf_view_->tooltip_manager();
1283d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
12845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Add an item to the shelf.
12855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID app_button_id = AddAppShortcut();
1286c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfButton* app_button = GetButtonByID(app_button_id);
1287d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
1288d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Spawn a tooltip on the item.
1289d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  button_host->MouseEnteredButton(app_button);
1290d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  ShowTooltip();
1291d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_TRUE(tooltip_manager->IsVisible());
1292d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
1293d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Changing shelf alignment hides the tooltip.
1294a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT,
1295a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                          Shell::GetPrimaryRootWindow());
1296d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_FALSE(tooltip_manager->IsVisible());
1297d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
1298d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
12998bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(ShelfViewTest, ShouldHideTooltipTest) {
13005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID app_button_id = AddAppShortcut();
13015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfID platform_button_id = AddPlatformApp();
13025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The tooltip shouldn't hide if the mouse is on normal buttons.
13045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (int i = 0; i < test_api_->GetButtonCount(); i++) {
1305c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    ShelfButton* button = test_api_->GetButton(i);
13065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (!button)
13075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      continue;
13085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13098bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    EXPECT_FALSE(shelf_view_->ShouldHideTooltip(
13105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        button->GetMirroredBounds().CenterPoint()))
13118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        << "ShelfView tries to hide on button " << i;
13125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
13135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The tooltip should not hide on the app-list button.
13158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  views::View* app_list_button = shelf_view_->GetAppListButtonView();
13168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_FALSE(shelf_view_->ShouldHideTooltip(
13175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      app_list_button->GetMirroredBounds().CenterPoint()));
13185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The tooltip shouldn't hide if the mouse is in the gap between two buttons.
13205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::Rect app_button_rect = GetButtonByID(app_button_id)->GetMirroredBounds();
1321424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  gfx::Rect platform_button_rect =
1322424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      GetButtonByID(platform_button_id)->GetMirroredBounds();
1323424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  ASSERT_FALSE(app_button_rect.Intersects(platform_button_rect));
13248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_FALSE(shelf_view_->ShouldHideTooltip(
1325424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      gfx::UnionRects(app_button_rect, platform_button_rect).CenterPoint()));
13265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The tooltip should hide if it's outside of all buttons.
13285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::Rect all_area;
13295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (int i = 0; i < test_api_->GetButtonCount(); i++) {
1330c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    ShelfButton* button = test_api_->GetButton(i);
13315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (!button)
13325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      continue;
13335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    all_area.Union(button->GetMirroredBounds());
13355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
13368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  all_area.Union(shelf_view_->GetAppListButtonView()->GetMirroredBounds());
13378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_FALSE(shelf_view_->ShouldHideTooltip(all_area.origin()));
13388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_FALSE(shelf_view_->ShouldHideTooltip(
13395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      gfx::Point(all_area.right() - 1, all_area.bottom() - 1)));
13408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_TRUE(shelf_view_->ShouldHideTooltip(
13415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      gfx::Point(all_area.right(), all_area.y())));
13428bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_TRUE(shelf_view_->ShouldHideTooltip(
13435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      gfx::Point(all_area.x() - 1, all_area.y())));
13448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_TRUE(shelf_view_->ShouldHideTooltip(
13455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      gfx::Point(all_area.x(), all_area.y() - 1)));
13468bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_TRUE(shelf_view_->ShouldHideTooltip(
13475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      gfx::Point(all_area.x(), all_area.bottom())));
13485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
13495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(ShelfViewTest, ShouldHideTooltipWithAppListWindowTest) {
13516e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  Shell::GetInstance()->ShowAppList(NULL);
13525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_TRUE(Shell::GetInstance()->GetAppListWindow());
13535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The tooltip shouldn't hide if the mouse is on normal buttons.
13555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (int i = 1; i < test_api_->GetButtonCount(); i++) {
1356c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    ShelfButton* button = test_api_->GetButton(i);
13575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (!button)
13585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      continue;
13595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13608bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    EXPECT_FALSE(shelf_view_->ShouldHideTooltip(
13615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        button->GetMirroredBounds().CenterPoint()))
13628bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        << "ShelfView tries to hide on button " << i;
13635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
13645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The tooltip should hide on the app-list button.
13668bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  views::View* app_list_button = shelf_view_->GetAppListButtonView();
13678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_TRUE(shelf_view_->ShouldHideTooltip(
13685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      app_list_button->GetMirroredBounds().CenterPoint()));
13695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
13705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Test that by moving the mouse cursor off the button onto the bubble it closes
13727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// the bubble.
13738bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(ShelfViewTest, ShouldHideTooltipWhenHoveringOnTooltip) {
1374c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfTooltipManager* tooltip_manager = shelf_view_->tooltip_manager();
13757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  tooltip_manager->CreateZeroDelayTimerForTest();
13765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
13777d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
13787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Move the mouse off any item and check that no tooltip is shown.
13797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  generator.MoveMouseTo(gfx::Point(0, 0));
13807d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  EXPECT_FALSE(tooltip_manager->IsVisible());
13817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
13827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Move the mouse over the button and check that it is visible.
13838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  views::View* app_list_button = shelf_view_->GetAppListButtonView();
13847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  gfx::Rect bounds = app_list_button->GetBoundsInScreen();
13857d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  generator.MoveMouseTo(bounds.CenterPoint());
13867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Wait for the timer to go off.
13877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  RunAllPendingInMessageLoop();
13887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  EXPECT_TRUE(tooltip_manager->IsVisible());
13897d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
13907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Move the mouse cursor slightly to the right of the item. The tooltip should
13917d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // stay open.
139258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  generator.MoveMouseBy(bounds.width() / 2 + 5, 0);
13937d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Make sure there is no delayed close.
13947d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  RunAllPendingInMessageLoop();
13957d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  EXPECT_TRUE(tooltip_manager->IsVisible());
13967d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
13977d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Move back - it should still stay open.
139858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  generator.MoveMouseBy(-(bounds.width() / 2 + 5), 0);
13997d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Make sure there is no delayed close.
14007d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  RunAllPendingInMessageLoop();
14017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  EXPECT_TRUE(tooltip_manager->IsVisible());
14027d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
14037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Now move the mouse cursor slightly above the item - so that it is over the
14047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // tooltip bubble. Now it should disappear.
14057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  generator.MoveMouseBy(0, -(bounds.height() / 2 + 5));
14067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Wait until the delayed close kicked in.
14077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  RunAllPendingInMessageLoop();
14087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  EXPECT_FALSE(tooltip_manager->IsVisible());
14097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
14107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
14118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Resizing shelf view while an add animation without fade-in is running,
14125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// which happens when overflow happens. App list button should end up in its
14135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// new ideal bounds.
14148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(ShelfViewTest, ResizeDuringOverflowAddAnimation) {
14155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // All buttons should be visible.
14165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_EQ(test_api_->GetButtonCount(),
14175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            test_api_->GetLastVisibleIndex() + 1);
14185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
14195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Add buttons until overflow. Let the non-overflow add animations finish but
14205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // leave the last running.
14212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int items_added = 0;
1422424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  AddPlatformAppNoWait();
14235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  while (!test_api_->IsOverflowButtonVisible()) {
14245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    test_api_->RunMessageLoopUntilAnimationsDone();
1425424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    AddPlatformAppNoWait();
14262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ++items_added;
14272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ASSERT_LT(items_added, 10000);
14285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
14295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
14308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // Resize shelf view with that animation running and stay overflown.
14318bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  gfx::Rect bounds = shelf_view_->bounds();
1432a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  bounds.set_width(bounds.width() - kShelfSize);
14338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  shelf_view_->SetBoundsRect(bounds);
14345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_TRUE(test_api_->IsOverflowButtonVisible());
14355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
14365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Finish the animation.
14375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  test_api_->RunMessageLoopUntilAnimationsDone();
14385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
14395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // App list button should ends up in its new ideal bounds.
14405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const int app_list_button_index = test_api_->GetButtonCount() - 1;
14415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const gfx::Rect& app_list_ideal_bounds =
14425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      test_api_->GetIdealBoundsByIndex(app_list_button_index);
14435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const gfx::Rect& app_list_bounds =
14445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      test_api_->GetBoundsByIndex(app_list_button_index);
14455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(app_list_ideal_bounds, app_list_bounds);
14465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
14475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1448f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Checks the overflow bubble size when an item is ripped off and re-inserted.
1449f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)TEST_F(ShelfViewTest, OverflowBubbleSize) {
14505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Replace current ShelfDelegate with TestShelfDelegateForShelfView.
14515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ReplaceShelfDelegateForRipOffTest();
1452f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1453a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  AddButtonsUntilOverflow();
1454f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1455f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Show overflow bubble.
1456f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  test_api_->ShowOverflowBubble();
1457f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ASSERT_TRUE(test_api_->overflow_bubble() &&
1458f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              test_api_->overflow_bubble()->IsShowing());
1459f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1460a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  ShelfViewTestAPI test_for_overflow_view(
1461f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      test_api_->overflow_bubble()->shelf_view());
1462f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1463f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  int ripped_index = test_for_overflow_view.GetLastVisibleIndex();
1464f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  gfx::Size bubble_size = test_for_overflow_view.GetPreferredSize();
1465f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  int item_width = test_for_overflow_view.GetButtonSize() +
1466f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      test_for_overflow_view.GetButtonSpacing();
1467f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
14685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
14695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                     gfx::Point());
1470c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfButton* button = test_for_overflow_view.GetButton(ripped_index);
1471f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Rip off the last visible item.
1472f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  gfx::Point start_point = button->GetBoundsInScreen().CenterPoint();
1473f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  gfx::Point rip_off_point(start_point.x(), 0);
1474f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  generator.MoveMouseTo(start_point.x(), start_point.y());
1475f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  base::MessageLoop::current()->RunUntilIdle();
1476f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  generator.PressLeftButton();
1477f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  base::MessageLoop::current()->RunUntilIdle();
1478f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  generator.MoveMouseTo(rip_off_point.x(), rip_off_point.y());
1479f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  base::MessageLoop::current()->RunUntilIdle();
1480f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  test_for_overflow_view.RunMessageLoopUntilAnimationsDone();
1481f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1482f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Check the overflow bubble size when an item is ripped off.
1483f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(bubble_size.width() - item_width,
1484f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)            test_for_overflow_view.GetPreferredSize().width());
1485f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ASSERT_TRUE(test_api_->overflow_bubble() &&
1486f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              test_api_->overflow_bubble()->IsShowing());
1487f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1488f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Re-insert an item into the overflow bubble.
1489f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  int first_index = test_for_overflow_view.GetFirstVisibleIndex();
1490f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  button = test_for_overflow_view.GetButton(first_index);
1491f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1492f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Check the bubble size after an item is re-inserted.
1493f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  generator.MoveMouseTo(button->GetBoundsInScreen().CenterPoint());
1494f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  test_for_overflow_view.RunMessageLoopUntilAnimationsDone();
1495f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(bubble_size.width(),
1496f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)            test_for_overflow_view.GetPreferredSize().width());
1497f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1498f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  generator.ReleaseLeftButton();
1499f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  test_for_overflow_view.RunMessageLoopUntilAnimationsDone();
1500f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(bubble_size.width(),
1501f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)            test_for_overflow_view.GetPreferredSize().width());
1502f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
1503f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1504f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Check the drag insertion bounds of scrolled overflow bubble.
1505f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)TEST_F(ShelfViewTest, CheckDragInsertBoundsOfScrolledOverflowBubble) {
1506f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  UpdateDisplay("400x300");
1507f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1508f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(2, model_->item_count());
1509f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1510a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  AddButtonsUntilOverflow();
1511f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1512f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Show overflow bubble.
1513f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  test_api_->ShowOverflowBubble();
1514f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ASSERT_TRUE(test_api_->overflow_bubble() &&
1515f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              test_api_->overflow_bubble()->IsShowing());
1516f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1517f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  int item_width = test_api_->GetButtonSize() +
1518f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      test_api_->GetButtonSpacing();
1519c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  OverflowBubbleView* bubble_view = test_api_->overflow_bubble()->bubble_view();
1520f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  test::OverflowBubbleViewTestAPI bubble_view_api(bubble_view);
1521f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1522f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Add more buttons until OverflowBubble is scrollable and it has 3 invisible
1523f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // items.
1524f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  while (bubble_view_api.GetContentsSize().width() <
1525f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)         (bubble_view->GetContentsBounds().width() + 3 * item_width))
1526f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    AddAppShortcut();
1527f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1528f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ASSERT_TRUE(test_api_->overflow_bubble() &&
1529f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              test_api_->overflow_bubble()->IsShowing());
1530f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1531a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  ShelfViewTestAPI test_for_overflow_view(
1532f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      test_api_->overflow_bubble()->shelf_view());
1533f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  int first_index = test_for_overflow_view.GetFirstVisibleIndex();
1534f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  int last_index = test_for_overflow_view.GetLastVisibleIndex();
1535f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1536c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfButton* first_button = test_for_overflow_view.GetButton(first_index);
1537c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfButton* last_button = test_for_overflow_view.GetButton(last_index);
1538f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  gfx::Point first_point = first_button->GetBoundsInScreen().CenterPoint();
1539f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  gfx::Point last_point = last_button->GetBoundsInScreen().CenterPoint();
1540f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  gfx::Rect drag_reinsert_bounds =
1541f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      test_for_overflow_view.GetBoundsForDragInsertInScreen();
1542f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_TRUE(drag_reinsert_bounds.Contains(first_point));
1543f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_FALSE(drag_reinsert_bounds.Contains(last_point));
1544f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1545f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Scrolls sufficiently to show last item.
1546f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  bubble_view_api.ScrollByXOffset(3 * item_width);
1547f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  drag_reinsert_bounds =
1548f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      test_for_overflow_view.GetBoundsForDragInsertInScreen();
1549f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  first_point = first_button->GetBoundsInScreen().CenterPoint();
1550f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  last_point = last_button->GetBoundsInScreen().CenterPoint();
1551f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_FALSE(drag_reinsert_bounds.Contains(first_point));
1552f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_TRUE(drag_reinsert_bounds.Contains(last_point));
1553f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
1554f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1555f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Check the drag insertion bounds of shelf view in multi monitor environment.
1556f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)TEST_F(ShelfViewTest, CheckDragInsertBoundsWithMultiMonitor) {
1557f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // win8-aura doesn't support multiple display.
1558f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (!SupportsMultipleDisplays())
1559f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    return;
1560f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1561f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  UpdateDisplay("800x600,800x600");
15625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Shelf* secondary_shelf = Shelf::ForWindow(Shell::GetAllRootWindows()[1]);
1563c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfView* shelf_view_for_secondary =
15645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ShelfTestAPI(secondary_shelf).shelf_view();
1565f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1566f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // The bounds should be big enough for 4 buttons + overflow chevron.
1567a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  shelf_view_for_secondary->SetBounds(0, 0, 500, kShelfSize);
1568f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1569f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ShelfViewTestAPI test_api_for_secondary(shelf_view_for_secondary);
1570f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Speeds up animation for test.
1571f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  test_api_for_secondary.SetAnimationDuration(1);
1572f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1573a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  AddButtonsUntilOverflow();
1574f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1575f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Test #1: Test drag insertion bounds of primary shelf.
1576f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Show overflow bubble.
1577f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  test_api_->ShowOverflowBubble();
1578f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ASSERT_TRUE(test_api_->overflow_bubble() &&
1579f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              test_api_->overflow_bubble()->IsShowing());
1580f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1581a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  ShelfViewTestAPI test_api_for_overflow_view(
1582f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      test_api_->overflow_bubble()->shelf_view());
1583f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1584c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfButton* button = test_api_for_overflow_view.GetButton(
1585f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      test_api_for_overflow_view.GetLastVisibleIndex());
1586f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1587f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Checks that a point in shelf is contained in drag insert bounds.
1588f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  gfx::Point point_in_shelf_view = button->GetBoundsInScreen().CenterPoint();
1589f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  gfx::Rect drag_reinsert_bounds =
1590f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      test_api_for_overflow_view.GetBoundsForDragInsertInScreen();
1591f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_TRUE(drag_reinsert_bounds.Contains(point_in_shelf_view));
1592f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Checks that a point out of shelf is not contained in drag insert bounds.
1593f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_FALSE(drag_reinsert_bounds.Contains(
1594f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      gfx::Point(point_in_shelf_view.x(), 0)));
1595f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1596f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Test #2: Test drag insertion bounds of secondary shelf.
1597f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Show overflow bubble.
1598f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  test_api_for_secondary.ShowOverflowBubble();
1599f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ASSERT_TRUE(test_api_for_secondary.overflow_bubble() &&
1600f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              test_api_for_secondary.overflow_bubble()->IsShowing());
1601f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1602a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  ShelfViewTestAPI test_api_for_overflow_view_of_secondary(
1603f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      test_api_for_secondary.overflow_bubble()->shelf_view());
1604f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1605c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfButton* button_in_secondary =
1606f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      test_api_for_overflow_view_of_secondary.GetButton(
1607f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)          test_api_for_overflow_view_of_secondary.GetLastVisibleIndex());
1608f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1609f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Checks that a point in shelf is contained in drag insert bounds.
1610f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  gfx::Point point_in_secondary_shelf_view =
1611f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      button_in_secondary->GetBoundsInScreen().CenterPoint();
1612f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  gfx::Rect drag_reinsert_bounds_in_secondary =
1613f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      test_api_for_overflow_view_of_secondary.GetBoundsForDragInsertInScreen();
1614f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_TRUE(drag_reinsert_bounds_in_secondary.Contains(
1615f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      point_in_secondary_shelf_view));
1616f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Checks that a point out of shelf is not contained in drag insert bounds.
1617f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_FALSE(drag_reinsert_bounds_in_secondary.Contains(
1618f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      gfx::Point(point_in_secondary_shelf_view.x(), 0)));
1619f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Checks that a point of overflow bubble in primary shelf should not be
1620f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // contained by insert bounds of secondary shelf.
1621f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_FALSE(drag_reinsert_bounds_in_secondary.Contains(point_in_shelf_view));
1622f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
1623f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
16245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Checks the rip an item off from left aligned shelf in secondary monitor.
16255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(ShelfViewTest, CheckRipOffFromLeftShelfAlignmentWithMultiMonitor) {
16265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // win8-aura doesn't support multiple display.
16275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!SupportsMultipleDisplays())
16285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
16295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
16305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateDisplay("800x600,800x600");
16315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_EQ(2U, Shell::GetAllRootWindows().size());
16325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
16335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  aura::Window* second_root = Shell::GetAllRootWindows()[1];
16345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
16355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, second_root);
16365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_EQ(SHELF_ALIGNMENT_LEFT,
16375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            Shell::GetInstance()->GetShelfAlignment(second_root));
16385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
16395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Initially, app list and browser shortcut are added.
16405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(2, model_->item_count());
16415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int browser_index = model_->GetItemIndexForType(TYPE_BROWSER_SHORTCUT);
16425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_GT(browser_index, 0);
16435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
16445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Shelf* secondary_shelf = Shelf::ForWindow(second_root);
1645c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfView* shelf_view_for_secondary =
16465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ShelfTestAPI(secondary_shelf).shelf_view();
16475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
16485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfViewTestAPI test_api_for_secondary_shelf_view(shelf_view_for_secondary);
1649c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ShelfButton* button =
1650c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      test_api_for_secondary_shelf_view.GetButton(browser_index);
16515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
16525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Fetch the start point of dragging.
16535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gfx::Point start_point = button->GetBoundsInScreen().CenterPoint();
16546e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  ::wm::ConvertPointFromScreen(second_root, &start_point);
16555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
16565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  ui::test::EventGenerator generator(second_root, start_point);
16575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
16585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Rip off the browser item.
16595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  generator.PressLeftButton();
16605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  generator.MoveMouseTo(start_point.x() + 400, start_point.y());
16615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  test_api_for_secondary_shelf_view.RunMessageLoopUntilAnimationsDone();
16625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(test_api_for_secondary_shelf_view.IsRippedOffFromShelf());
16635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
16645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1665a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Checks various drag and drop operations from OverflowBubble to Shelf.
1666a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)TEST_F(ShelfViewTest, CheckDragAndDropFromOverflowBubbleToShelf) {
16675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Replace current ShelfDelegate with TestShelfDelegateForShelfView.
16685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ReplaceShelfDelegateForRipOffTest();
1669a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1670a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  AddButtonsUntilOverflow();
1671a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1672a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  TestDraggingAnItemFromOverflowToShelf(false);
1673a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  TestDraggingAnItemFromOverflowToShelf(true);
1674a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
1675a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
16761320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Tests that the AppListButton renders as active in response to touches.
16771320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciTEST_F(ShelfViewTest, AppListButtonTouchFeedback) {
16781320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  AppListButton* app_list_button =
16791320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      static_cast<AppListButton*>(shelf_view_->GetAppListButtonView());
16801320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_FALSE(app_list_button->draw_background_as_active());
16811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
16821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
16831320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  generator.set_current_location(app_list_button->
16841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      GetBoundsInScreen().CenterPoint());
16851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  generator.PressTouch();
16861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  RunAllPendingInMessageLoop();
16871320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_TRUE(app_list_button->draw_background_as_active());
16881320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
16891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  generator.ReleaseTouch();
16901320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  RunAllPendingInMessageLoop();
16911320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_FALSE(app_list_button->draw_background_as_active());
16921320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
16931320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
16941320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
16951320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Tests that a touch that slides out of the bounds of the AppListButton leads
16961320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// to the end of rendering an active state.
16971320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciTEST_F(ShelfViewTest, AppListButtonTouchFeedbackCancellation) {
16981320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  AppListButton* app_list_button =
16991320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      static_cast<AppListButton*>(shelf_view_->GetAppListButtonView());
17001320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_FALSE(app_list_button->draw_background_as_active());
17011320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
17021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
17031320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  generator.set_current_location(app_list_button->
17041320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      GetBoundsInScreen().CenterPoint());
17051320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  generator.PressTouch();
17061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  RunAllPendingInMessageLoop();
17071320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_TRUE(app_list_button->draw_background_as_active());
17081320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
17091320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  gfx::Point moved_point(app_list_button->GetBoundsInScreen().right() + 1,
17101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                         app_list_button->
17111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                             GetBoundsInScreen().CenterPoint().y());
17121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  generator.MoveTouch(moved_point);
17131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  RunAllPendingInMessageLoop();
17141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_FALSE(app_list_button->draw_background_as_active());
17151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
17161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  generator.set_current_location(moved_point);
17171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  generator.ReleaseTouch();
17181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  RunAllPendingInMessageLoop();
17191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_FALSE(app_list_button->draw_background_as_active());
17201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility());
17211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
17221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
17238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)class ShelfViewVisibleBoundsTest : public ShelfViewTest,
1724f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                   public testing::WithParamInterface<bool> {
17254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) public:
17268bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  ShelfViewVisibleBoundsTest() : text_direction_change_(GetParam()) {}
17274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
17284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void CheckAllItemsAreInBounds() {
17298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    gfx::Rect visible_bounds = shelf_view_->GetVisibleItemsBoundsInScreen();
17305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    gfx::Rect shelf_bounds = shelf_view_->GetBoundsInScreen();
17315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    EXPECT_TRUE(shelf_bounds.Contains(visible_bounds));
17324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    for (int i = 0; i < test_api_->GetButtonCount(); ++i)
1733c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      if (ShelfButton* button = test_api_->GetButton(i))
17344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)        EXPECT_TRUE(visible_bounds.Contains(button->GetBoundsInScreen()));
17354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    CheckAppListButtonIsInBounds();
17364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
17374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
17384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void CheckAppListButtonIsInBounds() {
17398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    gfx::Rect visible_bounds = shelf_view_->GetVisibleItemsBoundsInScreen();
17408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    gfx::Rect app_list_button_bounds = shelf_view_->GetAppListButtonView()->
17414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)       GetBoundsInScreen();
17424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    EXPECT_TRUE(visible_bounds.Contains(app_list_button_bounds));
17434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
17444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
17454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) private:
17464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ScopedTextDirectionChange text_direction_change_;
17474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
17488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(ShelfViewVisibleBoundsTest);
17494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)};
17504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
17518bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_P(ShelfViewVisibleBoundsTest, ItemsAreInBounds) {
17524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Adding elements leaving some empty space.
17534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  for (int i = 0; i < 3; i++) {
17544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    AddAppShortcut();
17554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
17564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  test_api_->RunMessageLoopUntilAnimationsDone();
17574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_FALSE(test_api_->IsOverflowButtonVisible());
17584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  CheckAllItemsAreInBounds();
17594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Same for overflow case.
17604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  while (!test_api_->IsOverflowButtonVisible()) {
17614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    AddAppShortcut();
17624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
17634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  test_api_->RunMessageLoopUntilAnimationsDone();
17644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  CheckAllItemsAreInBounds();
17654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
17664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
17678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool());
17688bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest,
17694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    testing::Bool());
1770868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
17715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace test
17725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace ash
1773