This source file includes following definitions.
- change_notified_
- OnShelfIconPositionsChanged
- change_notified
- Reset
- SetUp
- TearDown
- observer
- shelf_view_test
- ShelfForSecondaryDisplay
- TEST_F
- TEST_F
- TEST_F
- OnShelfCreated
- OnShelfDestroyed
- GetShelfIDForAppID
- GetAppIDForShelfID
- PinAppWithID
- IsAppPinned
- CanPin
- UnpinAppWithID
- browser_index_
- SetUp
- TearDown
- CreateAndSetShelfItemDelegateForID
- AddBrowserShortcut
- AddAppShortcut
- AddPanel
- AddPlatformAppNoWait
- AddPanelNoWait
- AddPlatformApp
- RemoveByID
- GetButtonByID
- GetItemByID
- CheckModelIDs
- VerifyShelfItemBoundsAreValid
- SimulateButtonPressed
- SimulateClick
- SimulateDrag
- SetupForDragTest
- GetTooltipAnchorView
- AddButtonsUntilOverflow
- ShowTooltip
- TestDraggingAnItemFromOverflowToShelf
- GetItemId
- ReplaceShelfDelegateForRipOffTest
- SetUp
- CheckTextDirectionIsCorrect
- SetUp
- TearDown
- TEST_P
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- CheckAllItemsAreInBounds
- CheckAppListButtonIsInBounds
- TEST_P
#include "ash/shelf/shelf_view.h"
#include <algorithm>
#include <vector>
#include "ash/ash_switches.h"
#include "ash/root_window_controller.h"
#include "ash/shelf/overflow_bubble.h"
#include "ash/shelf/overflow_bubble_view.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_button.h"
#include "ash/shelf/shelf_constants.h"
#include "ash/shelf/shelf_icon_observer.h"
#include "ash/shelf/shelf_item_delegate_manager.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shelf/shelf_model.h"
#include "ash/shelf/shelf_tooltip_manager.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/overflow_bubble_view_test_api.h"
#include "ash/test/shelf_test_api.h"
#include "ash/test/shelf_view_test_api.h"
#include "ash/test/shell_test_api.h"
#include "ash/test/test_shelf_delegate.h"
#include "ash/test/test_shelf_item_delegate.h"
#include "ash/wm/coordinate_conversion.h"
#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string_number_conversions.h"
#include "grit/ash_resources.h"
#include "ui/aura/test/aura_test_base.h"
#include "ui/aura/test/event_generator.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/compositor/layer.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
#include "ui/views/view_model.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
namespace ash {
namespace test {
class TestShelfIconObserver : public ShelfIconObserver {
public:
explicit TestShelfIconObserver(Shelf* shelf)
: shelf_(shelf),
change_notified_(false) {
if (shelf_)
shelf_->AddIconObserver(this);
}
virtual ~TestShelfIconObserver() {
if (shelf_)
shelf_->RemoveIconObserver(this);
}
virtual void OnShelfIconPositionsChanged() OVERRIDE {
change_notified_ = true;
}
int change_notified() const { return change_notified_; }
void Reset() { change_notified_ = false; }
private:
Shelf* shelf_;
bool change_notified_;
DISALLOW_COPY_AND_ASSIGN(TestShelfIconObserver);
};
class ShelfViewIconObserverTest : public AshTestBase {
public:
ShelfViewIconObserverTest() {}
virtual ~ShelfViewIconObserverTest() {}
virtual void SetUp() OVERRIDE {
AshTestBase::SetUp();
Shelf* shelf = Shelf::ForPrimaryDisplay();
observer_.reset(new TestShelfIconObserver(shelf));
shelf_view_test_.reset(
new ShelfViewTestAPI(ShelfTestAPI(shelf).shelf_view()));
shelf_view_test_->SetAnimationDuration(1);
}
virtual void TearDown() OVERRIDE {
observer_.reset();
AshTestBase::TearDown();
}
TestShelfIconObserver* observer() { return observer_.get(); }
ShelfViewTestAPI* shelf_view_test() {
return shelf_view_test_.get();
}
Shelf* ShelfForSecondaryDisplay() {
return Shelf::ForWindow(Shell::GetAllRootWindows()[1]);
}
private:
scoped_ptr<TestShelfIconObserver> observer_;
scoped_ptr<ShelfViewTestAPI> shelf_view_test_;
DISALLOW_COPY_AND_ASSIGN(ShelfViewIconObserverTest);
};
TEST_F(ShelfViewIconObserverTest, AddRemove) {
TestShelfDelegate* shelf_delegate = TestShelfDelegate::instance();
ASSERT_TRUE(shelf_delegate);
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.bounds = gfx::Rect(0, 0, 200, 200);
params.context = CurrentContext();
scoped_ptr<views::Widget> widget(new views::Widget());
widget->Init(params);
shelf_delegate->AddShelfItem(widget->GetNativeWindow());
shelf_view_test()->RunMessageLoopUntilAnimationsDone();
EXPECT_TRUE(observer()->change_notified());
observer()->Reset();
widget->Show();
widget->GetNativeWindow()->parent()->RemoveChild(widget->GetNativeWindow());
shelf_view_test()->RunMessageLoopUntilAnimationsDone();
EXPECT_TRUE(observer()->change_notified());
observer()->Reset();
}
#if defined(OS_WIN)
#define MAYBE_AddRemoveWithMultipleDisplays \
DISABLED_AddRemoveWithMultipleDisplays
#else
#define MAYBE_AddRemoveWithMultipleDisplays \
AddRemoveWithMultipleDisplays
#endif
TEST_F(ShelfViewIconObserverTest, MAYBE_AddRemoveWithMultipleDisplays) {
UpdateDisplay("400x400,400x400");
TestShelfIconObserver second_observer(ShelfForSecondaryDisplay());
TestShelfDelegate* shelf_delegate = TestShelfDelegate::instance();
ASSERT_TRUE(shelf_delegate);
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.bounds = gfx::Rect(0, 0, 200, 200);
params.context = CurrentContext();
scoped_ptr<views::Widget> widget(new views::Widget());
widget->Init(params);
shelf_delegate->AddShelfItem(widget->GetNativeWindow());
shelf_view_test()->RunMessageLoopUntilAnimationsDone();
EXPECT_TRUE(observer()->change_notified());
EXPECT_TRUE(second_observer.change_notified());
observer()->Reset();
second_observer.Reset();
widget->GetNativeWindow()->parent()->RemoveChild(widget->GetNativeWindow());
shelf_view_test()->RunMessageLoopUntilAnimationsDone();
EXPECT_TRUE(observer()->change_notified());
EXPECT_TRUE(second_observer.change_notified());
observer()->Reset();
second_observer.Reset();
}
TEST_F(ShelfViewIconObserverTest, BoundsChanged) {
ShelfWidget* widget = Shell::GetPrimaryRootWindowController()->shelf();
Shelf* shelf = Shelf::ForPrimaryDisplay();
gfx::Size shelf_size = widget->GetWindowBoundsInScreen().size();
shelf_size.set_width(shelf_size.width() / 2);
ASSERT_GT(shelf_size.width(), 0);
shelf->SetShelfViewBounds(gfx::Rect(shelf_size));
EXPECT_TRUE(observer()->change_notified());
observer()->Reset();
}
class TestShelfDelegateForShelfView : public ShelfDelegate {
public:
explicit TestShelfDelegateForShelfView(ShelfModel* model)
: model_(model) {}
virtual ~TestShelfDelegateForShelfView() {}
virtual void OnShelfCreated(Shelf* shelf) OVERRIDE {}
virtual void OnShelfDestroyed(Shelf* shelf) OVERRIDE {}
virtual ShelfID GetShelfIDForAppID(const std::string& app_id) OVERRIDE {
ShelfID id = 0;
EXPECT_TRUE(base::StringToInt(app_id, &id));
return id;
}
virtual const std::string& GetAppIDForShelfID(ShelfID id) OVERRIDE {
app_id_ = base::IntToString(id);
return app_id_;
}
virtual void PinAppWithID(const std::string& app_id) OVERRIDE {
}
virtual bool IsAppPinned(const std::string& app_id) OVERRIDE {
return true;
}
virtual bool CanPin() const OVERRIDE {
return true;
}
virtual void UnpinAppWithID(const std::string& app_id) OVERRIDE {
ShelfID id = 0;
EXPECT_TRUE(base::StringToInt(app_id, &id));
ASSERT_GT(id, 0);
int index = model_->ItemIndexByID(id);
ASSERT_GE(index, 0);
model_->RemoveItemAt(index);
}
private:
ShelfModel* model_;
std::string app_id_;
DISALLOW_COPY_AND_ASSIGN(TestShelfDelegateForShelfView);
};
class ShelfViewTest : public AshTestBase {
public:
ShelfViewTest() : model_(NULL), shelf_view_(NULL), browser_index_(1) {}
virtual ~ShelfViewTest() {}
virtual void SetUp() OVERRIDE {
AshTestBase::SetUp();
test::ShellTestApi test_api(Shell::GetInstance());
model_ = test_api.shelf_model();
Shelf* shelf = Shelf::ForPrimaryDisplay();
shelf_view_ = ShelfTestAPI(shelf).shelf_view();
shelf_view_->SetBounds(
0, 0, 500, ShelfLayoutManager::GetPreferredShelfSize());
test_api_.reset(new ShelfViewTestAPI(shelf_view_));
test_api_->SetAnimationDuration(1);
item_manager_ = Shell::GetInstance()->shelf_item_delegate_manager();
DCHECK(item_manager_);
AddBrowserShortcut();
}
virtual void TearDown() OVERRIDE {
test_api_.reset();
AshTestBase::TearDown();
}
protected:
void CreateAndSetShelfItemDelegateForID(ShelfID id) {
scoped_ptr<ShelfItemDelegate> delegate(new TestShelfItemDelegate(NULL));
item_manager_->SetShelfItemDelegate(id, delegate.Pass());
}
ShelfID AddBrowserShortcut() {
ShelfItem browser_shortcut;
browser_shortcut.type = TYPE_BROWSER_SHORTCUT;
ShelfID id = model_->next_id();
model_->AddAt(browser_index_, browser_shortcut);
CreateAndSetShelfItemDelegateForID(id);
test_api_->RunMessageLoopUntilAnimationsDone();
return id;
}
ShelfID AddAppShortcut() {
ShelfItem item;
item.type = TYPE_APP_SHORTCUT;
item.status = STATUS_CLOSED;
ShelfID id = model_->next_id();
model_->Add(item);
CreateAndSetShelfItemDelegateForID(id);
test_api_->RunMessageLoopUntilAnimationsDone();
return id;
}
ShelfID AddPanel() {
ShelfID id = AddPanelNoWait();
test_api_->RunMessageLoopUntilAnimationsDone();
return id;
}
ShelfID AddPlatformAppNoWait() {
ShelfItem item;
item.type = TYPE_PLATFORM_APP;
item.status = STATUS_RUNNING;
ShelfID id = model_->next_id();
model_->Add(item);
CreateAndSetShelfItemDelegateForID(id);
return id;
}
ShelfID AddPanelNoWait() {
ShelfItem item;
item.type = TYPE_APP_PANEL;
item.status = STATUS_RUNNING;
ShelfID id = model_->next_id();
model_->Add(item);
CreateAndSetShelfItemDelegateForID(id);
return id;
}
ShelfID AddPlatformApp() {
ShelfID id = AddPlatformAppNoWait();
test_api_->RunMessageLoopUntilAnimationsDone();
return id;
}
void RemoveByID(ShelfID id) {
model_->RemoveItemAt(model_->ItemIndexByID(id));
test_api_->RunMessageLoopUntilAnimationsDone();
}
ShelfButton* GetButtonByID(ShelfID id) {
int index = model_->ItemIndexByID(id);
return test_api_->GetButton(index);
}
ShelfItem GetItemByID(ShelfID id) {
ShelfItems::const_iterator items = model_->ItemByID(id);
return *items;
}
void CheckModelIDs(
const std::vector<std::pair<ShelfID, views::View*> >& id_map) {
size_t map_index = 0;
for (size_t model_index = 0;
model_index < model_->items().size();
++model_index) {
ShelfItem item = model_->items()[model_index];
ShelfID id = item.id;
EXPECT_EQ(id_map[map_index].first, id);
EXPECT_EQ(id_map[map_index].second, GetButtonByID(id));
++map_index;
}
ASSERT_EQ(map_index, id_map.size());
}
void VerifyShelfItemBoundsAreValid() {
for (int i=0;i <= test_api_->GetLastVisibleIndex(); ++i) {
if (test_api_->GetButton(i)) {
gfx::Rect shelf_view_bounds = shelf_view_->GetLocalBounds();
gfx::Rect item_bounds = test_api_->GetBoundsByIndex(i);
EXPECT_GE(item_bounds.x(), 0);
EXPECT_GE(item_bounds.y(), 0);
EXPECT_LE(item_bounds.right(), shelf_view_bounds.width());
EXPECT_LE(item_bounds.bottom(), shelf_view_bounds.height());
}
}
}
views::View* SimulateButtonPressed(ShelfButtonHost::Pointer pointer,
int button_index) {
ShelfButtonHost* button_host = shelf_view_;
views::View* button = test_api_->GetButton(button_index);
ui::MouseEvent click_event(ui::ET_MOUSE_PRESSED,
button->bounds().origin(),
button->GetBoundsInScreen().origin(), 0, 0);
button_host->PointerPressedOnButton(button, pointer, click_event);
return button;
}
views::View* SimulateClick(ShelfButtonHost::Pointer pointer,
int button_index) {
ShelfButtonHost* button_host = shelf_view_;
views::View* button = SimulateButtonPressed(pointer, button_index);
button_host->PointerReleasedOnButton(button, ShelfButtonHost::MOUSE, false);
return button;
}
views::View* SimulateDrag(ShelfButtonHost::Pointer pointer,
int button_index,
int destination_index) {
ShelfButtonHost* button_host = shelf_view_;
views::View* button = SimulateButtonPressed(pointer, button_index);
views::View* destination = test_api_->GetButton(destination_index);
ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED,
destination->bounds().origin(),
destination->GetBoundsInScreen().origin(), 0, 0);
button_host->PointerDraggedOnButton(button, pointer, drag_event);
return button;
}
void SetupForDragTest(
std::vector<std::pair<ShelfID, views::View*> >* id_map) {
for (size_t i = 0; i < model_->items().size(); ++i) {
ShelfButton* button = test_api_->GetButton(i);
id_map->push_back(std::make_pair(model_->items()[i].id, button));
}
ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map));
for (int i = 0; i < 5; ++i) {
ShelfID id = AddAppShortcut();
id_map->insert(id_map->begin() + (i + browser_index_ + 1),
std::make_pair(id, GetButtonByID(id)));
}
ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map));
}
views::View* GetTooltipAnchorView() {
return shelf_view_->tooltip_manager()->anchor_;
}
void AddButtonsUntilOverflow() {
int items_added = 0;
while (!test_api_->IsOverflowButtonVisible()) {
AddAppShortcut();
++items_added;
ASSERT_LT(items_added, 10000);
}
}
void ShowTooltip() {
shelf_view_->tooltip_manager()->ShowInternal();
}
void TestDraggingAnItemFromOverflowToShelf(bool cancel) {
test_api_->ShowOverflowBubble();
ASSERT_TRUE(test_api_->overflow_bubble() &&
test_api_->overflow_bubble()->IsShowing());
ash::test::ShelfViewTestAPI test_api_for_overflow(
test_api_->overflow_bubble()->shelf_view());
int total_item_count = model_->item_count();
int last_visible_item_id_in_shelf =
GetItemId(test_api_->GetLastVisibleIndex());
int second_last_visible_item_id_in_shelf =
GetItemId(test_api_->GetLastVisibleIndex() - 1);
int first_visible_item_id_in_overflow =
GetItemId(test_api_for_overflow.GetFirstVisibleIndex());
int second_last_visible_item_id_in_overflow =
GetItemId(test_api_for_overflow.GetLastVisibleIndex() - 1);
int drag_item_index =
test_api_for_overflow.GetLastVisibleIndex();
ShelfID drag_item_id = GetItemId(drag_item_index);
ShelfButton* drag_button = test_api_for_overflow.GetButton(drag_item_index);
gfx::Point center_point_of_drag_item =
drag_button->GetBoundsInScreen().CenterPoint();
aura::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow(),
center_point_of_drag_item);
generator.PressLeftButton();
gfx::Point rip_off_point(center_point_of_drag_item.x(), 0);
generator.MoveMouseTo(rip_off_point);
test_api_for_overflow.RunMessageLoopUntilAnimationsDone();
ASSERT_TRUE(test_api_for_overflow.IsRippedOffFromShelf());
ASSERT_FALSE(test_api_for_overflow.DraggedItemFromOverflowToShelf());
int drop_index = 1;
gfx::Point drop_point =
test_api_->GetButton(drop_index)->GetBoundsInScreen().CenterPoint();
int item_width = test_api_for_overflow.GetButtonSize();
gfx::Point modified_drop_point(drop_point.x() - item_width / 4,
drop_point.y());
generator.MoveMouseTo(modified_drop_point);
test_api_for_overflow.RunMessageLoopUntilAnimationsDone();
test_api_->RunMessageLoopUntilAnimationsDone();
ASSERT_TRUE(test_api_for_overflow.IsRippedOffFromShelf());
ASSERT_TRUE(test_api_for_overflow.DraggedItemFromOverflowToShelf());
if (cancel)
drag_button->OnMouseCaptureLost();
else
generator.ReleaseLeftButton();
test_api_for_overflow.RunMessageLoopUntilAnimationsDone();
test_api_->RunMessageLoopUntilAnimationsDone();
ASSERT_FALSE(test_api_for_overflow.IsRippedOffFromShelf());
ASSERT_FALSE(test_api_for_overflow.DraggedItemFromOverflowToShelf());
if (cancel) {
EXPECT_EQ(last_visible_item_id_in_shelf,
GetItemId(test_api_->GetLastVisibleIndex()));
EXPECT_EQ(second_last_visible_item_id_in_shelf,
GetItemId(test_api_->GetLastVisibleIndex() - 1));
EXPECT_EQ(first_visible_item_id_in_overflow,
GetItemId(test_api_for_overflow.GetFirstVisibleIndex()));
EXPECT_EQ(second_last_visible_item_id_in_overflow,
GetItemId(test_api_for_overflow.GetLastVisibleIndex() - 1));
} else {
EXPECT_EQ(drag_item_id, GetItemId(drop_index));
EXPECT_EQ(total_item_count, model_->item_count());
EXPECT_EQ(last_visible_item_id_in_shelf,
GetItemId(test_api_for_overflow.GetFirstVisibleIndex()));
EXPECT_EQ(second_last_visible_item_id_in_shelf,
GetItemId(test_api_->GetLastVisibleIndex()));
EXPECT_EQ(first_visible_item_id_in_overflow,
GetItemId(test_api_for_overflow.GetFirstVisibleIndex() + 1));
EXPECT_EQ(second_last_visible_item_id_in_overflow,
GetItemId(test_api_for_overflow.GetLastVisibleIndex()));
}
}
ShelfID GetItemId(int index) {
DCHECK_GE(index, 0);
return model_->items()[index].id;
}
void ReplaceShelfDelegateForRipOffTest() {
test::ShellTestApi test_api(Shell::GetInstance());
test_api.SetShelfDelegate(NULL);
ShelfDelegate* delegate = new TestShelfDelegateForShelfView(model_);
test_api.SetShelfDelegate(delegate);
test::ShelfTestAPI(Shelf::ForPrimaryDisplay()).SetShelfDelegate(delegate);
test_api_->SetShelfDelegate(delegate);
}
ShelfModel* model_;
ShelfView* shelf_view_;
int browser_index_;
ShelfItemDelegateManager* item_manager_;
scoped_ptr<ShelfViewTestAPI> test_api_;
private:
DISALLOW_COPY_AND_ASSIGN(ShelfViewTest);
};
class ShelfViewLegacyShelfLayoutTest : public ShelfViewTest {
public:
ShelfViewLegacyShelfLayoutTest() : ShelfViewTest() {
browser_index_ = 0;
}
virtual ~ShelfViewLegacyShelfLayoutTest() {}
virtual void SetUp() OVERRIDE {
CommandLine::ForCurrentProcess()->AppendSwitch(
ash::switches::kAshDisableAlternateShelfLayout);
ShelfViewTest::SetUp();
}
private:
DISALLOW_COPY_AND_ASSIGN(ShelfViewLegacyShelfLayoutTest);
};
class ScopedTextDirectionChange {
public:
ScopedTextDirectionChange(bool is_rtl)
: is_rtl_(is_rtl) {
original_locale_ = l10n_util::GetApplicationLocale(std::string());
if (is_rtl_)
base::i18n::SetICUDefaultLocale("he");
CheckTextDirectionIsCorrect();
}
~ScopedTextDirectionChange() {
if (is_rtl_)
base::i18n::SetICUDefaultLocale(original_locale_);
}
private:
void CheckTextDirectionIsCorrect() {
ASSERT_EQ(is_rtl_, base::i18n::IsRTL());
}
bool is_rtl_;
std::string original_locale_;
};
class ShelfViewTextDirectionTest
: public ShelfViewTest,
public testing::WithParamInterface<bool> {
public:
ShelfViewTextDirectionTest() : text_direction_change_(GetParam()) {}
virtual ~ShelfViewTextDirectionTest() {}
virtual void SetUp() OVERRIDE {
ShelfViewTest::SetUp();
}
virtual void TearDown() OVERRIDE {
ShelfViewTest::TearDown();
}
private:
ScopedTextDirectionChange text_direction_change_;
DISALLOW_COPY_AND_ASSIGN(ShelfViewTextDirectionTest);
};
TEST_P(ShelfViewTextDirectionTest, IdealBoundsOfItemIcon) {
ShelfID id = AddPlatformApp();
ShelfButton* button = GetButtonByID(id);
gfx::Rect item_bounds = button->GetBoundsInScreen();
gfx::Point icon_offset = button->GetIconBounds().origin();
item_bounds.Offset(icon_offset.OffsetFromOrigin());
gfx::Rect ideal_bounds = shelf_view_->GetIdealBoundsOfItemIcon(id);
gfx::Point screen_origin;
views::View::ConvertPointToScreen(shelf_view_, &screen_origin);
ideal_bounds.Offset(screen_origin.x(), screen_origin.y());
EXPECT_EQ(item_bounds.x(), ideal_bounds.x());
EXPECT_EQ(item_bounds.y(), ideal_bounds.y());
}
TEST_F(ShelfViewTest, EnforceDragType) {
EXPECT_TRUE(test_api_->SameDragType(TYPE_PLATFORM_APP, TYPE_PLATFORM_APP));
EXPECT_FALSE(test_api_->SameDragType(TYPE_PLATFORM_APP, TYPE_APP_SHORTCUT));
EXPECT_FALSE(test_api_->SameDragType(TYPE_PLATFORM_APP,
TYPE_BROWSER_SHORTCUT));
EXPECT_FALSE(test_api_->SameDragType(TYPE_PLATFORM_APP, TYPE_WINDOWED_APP));
EXPECT_FALSE(test_api_->SameDragType(TYPE_PLATFORM_APP, TYPE_APP_LIST));
EXPECT_FALSE(test_api_->SameDragType(TYPE_PLATFORM_APP, TYPE_APP_PANEL));
EXPECT_TRUE(test_api_->SameDragType(TYPE_APP_SHORTCUT, TYPE_APP_SHORTCUT));
EXPECT_TRUE(test_api_->SameDragType(TYPE_APP_SHORTCUT,
TYPE_BROWSER_SHORTCUT));
EXPECT_FALSE(test_api_->SameDragType(TYPE_APP_SHORTCUT,
TYPE_WINDOWED_APP));
EXPECT_FALSE(test_api_->SameDragType(TYPE_APP_SHORTCUT, TYPE_APP_LIST));
EXPECT_FALSE(test_api_->SameDragType(TYPE_APP_SHORTCUT, TYPE_APP_PANEL));
EXPECT_TRUE(test_api_->SameDragType(TYPE_BROWSER_SHORTCUT,
TYPE_BROWSER_SHORTCUT));
EXPECT_FALSE(test_api_->SameDragType(TYPE_BROWSER_SHORTCUT,
TYPE_WINDOWED_APP));
EXPECT_FALSE(test_api_->SameDragType(TYPE_BROWSER_SHORTCUT, TYPE_APP_LIST));
EXPECT_FALSE(test_api_->SameDragType(TYPE_BROWSER_SHORTCUT, TYPE_APP_PANEL));
EXPECT_TRUE(test_api_->SameDragType(TYPE_WINDOWED_APP, TYPE_WINDOWED_APP));
EXPECT_FALSE(test_api_->SameDragType(TYPE_WINDOWED_APP, TYPE_APP_LIST));
EXPECT_FALSE(test_api_->SameDragType(TYPE_WINDOWED_APP, TYPE_APP_PANEL));
EXPECT_TRUE(test_api_->SameDragType(TYPE_APP_LIST, TYPE_APP_LIST));
EXPECT_FALSE(test_api_->SameDragType(TYPE_APP_LIST, TYPE_APP_PANEL));
EXPECT_TRUE(test_api_->SameDragType(TYPE_APP_PANEL, TYPE_APP_PANEL));
}
TEST_F(ShelfViewTest, AddBrowserUntilOverflow) {
ASSERT_EQ(test_api_->GetButtonCount(),
test_api_->GetLastVisibleIndex() + 1);
int items_added = 0;
ShelfID last_added = AddPlatformApp();
while (!test_api_->IsOverflowButtonVisible()) {
EXPECT_TRUE(GetButtonByID(last_added)->visible());
last_added = AddPlatformApp();
++items_added;
ASSERT_LT(items_added, 10000);
}
EXPECT_FALSE(GetButtonByID(last_added)->visible());
}
TEST_F(ShelfViewTest, AddAppShortcutWithBrowserButtonUntilOverflow) {
ASSERT_EQ(test_api_->GetButtonCount(),
test_api_->GetLastVisibleIndex() + 1);
ShelfID browser_button_id = AddPlatformApp();
int items_added = 0;
ShelfID last_added = AddAppShortcut();
while (!test_api_->IsOverflowButtonVisible()) {
EXPECT_TRUE(GetButtonByID(last_added)->visible());
last_added = AddAppShortcut();
++items_added;
ASSERT_LT(items_added, 10000);
}
EXPECT_FALSE(GetButtonByID(browser_button_id)->visible());
}
TEST_F(ShelfViewLegacyShelfLayoutTest,
AddAppShortcutWithBrowserButtonUntilOverflow) {
ASSERT_EQ(test_api_->GetButtonCount(),
test_api_->GetLastVisibleIndex() + 1);
ShelfID browser_button_id = AddPlatformApp();
int items_added = 0;
ShelfID last_added = AddAppShortcut();
while (!test_api_->IsOverflowButtonVisible()) {
EXPECT_TRUE(GetButtonByID(last_added)->visible());
last_added = AddAppShortcut();
++items_added;
ASSERT_LT(items_added, 10000);
}
EXPECT_TRUE(GetButtonByID(last_added)->visible());
EXPECT_FALSE(GetButtonByID(browser_button_id)->visible());
}
TEST_F(ShelfViewTest, AddPanelHidesPlatformAppButton) {
ASSERT_EQ(test_api_->GetButtonCount(),
test_api_->GetLastVisibleIndex() + 1);
int items_added = 0;
ShelfID first_added = AddPlatformApp();
EXPECT_TRUE(GetButtonByID(first_added)->visible());
while (true) {
ShelfID added = AddPlatformApp();
if (test_api_->IsOverflowButtonVisible()) {
EXPECT_FALSE(GetButtonByID(added)->visible());
RemoveByID(added);
break;
}
++items_added;
ASSERT_LT(items_added, 10000);
}
ShelfID panel = AddPanel();
EXPECT_TRUE(test_api_->IsOverflowButtonVisible());
RemoveByID(panel);
EXPECT_FALSE(test_api_->IsOverflowButtonVisible());
}
TEST_F(ShelfViewLegacyShelfLayoutTest, AddPanelHidesPlatformAppButton) {
ASSERT_EQ(test_api_->GetButtonCount(),
test_api_->GetLastVisibleIndex() + 1);
int items_added = 0;
ShelfID first_added = AddPlatformApp();
EXPECT_TRUE(GetButtonByID(first_added)->visible());
ShelfID last_visible = first_added;
while (true) {
ShelfID added = AddPlatformApp();
if (test_api_->IsOverflowButtonVisible()) {
EXPECT_FALSE(GetButtonByID(added)->visible());
break;
}
last_visible = added;
++items_added;
ASSERT_LT(items_added, 10000);
}
ShelfID panel = AddPanel();
EXPECT_TRUE(GetButtonByID(panel)->visible());
EXPECT_FALSE(GetButtonByID(last_visible)->visible());
RemoveByID(panel);
EXPECT_TRUE(GetButtonByID(last_visible)->visible());
}
TEST_F(ShelfViewTest, PlatformAppHidesExcessPanels) {
ASSERT_EQ(test_api_->GetButtonCount(),
test_api_->GetLastVisibleIndex() + 1);
ShelfID platform_app = AddPlatformApp();
ShelfID first_panel = AddPanel();
EXPECT_TRUE(GetButtonByID(platform_app)->visible());
EXPECT_TRUE(GetButtonByID(first_panel)->visible());
ShelfID last_panel = first_panel;
int items_added = 0;
while (!test_api_->IsOverflowButtonVisible()) {
last_panel = AddPanel();
++items_added;
ASSERT_LT(items_added, 10000);
}
EXPECT_FALSE(GetButtonByID(first_panel)->visible());
EXPECT_TRUE(GetButtonByID(last_panel)->visible());
EXPECT_TRUE(GetButtonByID(platform_app)->visible());
items_added = 0;
while (GetButtonByID(platform_app)->visible() &&
GetButtonByID(last_panel)->visible()) {
platform_app = AddPlatformApp();
++items_added;
ASSERT_LT(items_added, 10000);
}
EXPECT_TRUE(GetButtonByID(last_panel)->visible());
EXPECT_FALSE(GetButtonByID(platform_app)->visible());
}
TEST_F(ShelfViewTest, RemoveButtonRevealsOverflowed) {
ASSERT_EQ(test_api_->GetButtonCount(),
test_api_->GetLastVisibleIndex() + 1);
int items_added = 0;
ShelfID first_added = AddPlatformApp();
ShelfID last_added = first_added;
while (!test_api_->IsOverflowButtonVisible()) {
last_added = AddPlatformApp();
++items_added;
ASSERT_LT(items_added, 10000);
}
EXPECT_NE(first_added, last_added);
EXPECT_TRUE(GetButtonByID(first_added)->visible());
EXPECT_FALSE(GetButtonByID(last_added)->visible());
RemoveByID(first_added);
EXPECT_TRUE(GetButtonByID(last_added)->visible());
EXPECT_EQ(1.0f, GetButtonByID(last_added)->layer()->opacity());
EXPECT_FALSE(test_api_->IsOverflowButtonVisible());
}
TEST_F(ShelfViewTest, RemoveLastOverflowed) {
ASSERT_EQ(test_api_->GetButtonCount(),
test_api_->GetLastVisibleIndex() + 1);
int items_added = 0;
ShelfID last_added = AddPlatformApp();
while (!test_api_->IsOverflowButtonVisible()) {
last_added = AddPlatformApp();
++items_added;
ASSERT_LT(items_added, 10000);
}
RemoveByID(last_added);
EXPECT_FALSE(test_api_->IsOverflowButtonVisible());
}
TEST_F(ShelfViewTest, AddButtonQuickly) {
ASSERT_EQ(test_api_->GetButtonCount(),
test_api_->GetLastVisibleIndex() + 1);
int added_count = 0;
while (!test_api_->IsOverflowButtonVisible()) {
AddPlatformAppNoWait();
++added_count;
ASSERT_LT(added_count, 10000);
}
ASSERT_GE(added_count, 3);
test_api_->RunMessageLoopUntilAnimationsDone();
for (int i = 0; i <= test_api_->GetLastVisibleIndex(); ++i) {
ShelfButton* button = test_api_->GetButton(i);
if (button) {
EXPECT_TRUE(button->visible()) << "button index=" << i;
EXPECT_EQ(1.0f, button->layer()->opacity()) << "button index=" << i;
}
}
}
TEST_F(ShelfViewTest, ModelChangesWhileDragging) {
ShelfButtonHost* button_host = shelf_view_;
std::vector<std::pair<ShelfID, views::View*> > id_map;
SetupForDragTest(&id_map);
EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT);
views::View* dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 1, 3);
std::rotate(id_map.begin() + 1,
id_map.begin() + 2,
id_map.begin() + 4);
ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
button_host->PointerReleasedOnButton(
dragged_button, ShelfButtonHost::MOUSE, false);
EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT);
dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 1, 3);
std::rotate(id_map.begin() + 1,
id_map.begin() + 2,
id_map.begin() + 4);
ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
button_host->PointerReleasedOnButton(
dragged_button, ShelfButtonHost::MOUSE, true);
std::rotate(id_map.begin() + 1,
id_map.begin() + 3,
id_map.begin() + 4);
ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 1, 3);
model_->RemoveItemAt(1);
id_map.erase(id_map.begin() + 1);
ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
button_host->PointerReleasedOnButton(
dragged_button, ShelfButtonHost::MOUSE, false);
dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 1, 3);
ShelfID new_id = AddAppShortcut();
id_map.insert(id_map.begin() + 6,
std::make_pair(new_id, GetButtonByID(new_id)));
ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
button_host->PointerReleasedOnButton(
dragged_button, ShelfButtonHost::MOUSE, false);
dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 1, 3);
new_id = AddPanel();
id_map.insert(id_map.begin() + 7,
std::make_pair(new_id, GetButtonByID(new_id)));
ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
button_host->PointerReleasedOnButton(
dragged_button, ShelfButtonHost::MOUSE, false);
}
TEST_F(ShelfViewLegacyShelfLayoutTest, ModelChangesWhileDragging) {
ShelfButtonHost* button_host = shelf_view_;
std::vector<std::pair<ShelfID, views::View*> > id_map;
SetupForDragTest(&id_map);
EXPECT_TRUE(model_->items()[0].type == TYPE_BROWSER_SHORTCUT);
views::View* dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 0, 2);
std::rotate(id_map.begin(),
id_map.begin() + 1,
id_map.begin() + 3);
ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
button_host->PointerReleasedOnButton(
dragged_button, ShelfButtonHost::MOUSE, false);
EXPECT_TRUE(model_->items()[2].type == TYPE_BROWSER_SHORTCUT);
dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 0, 2);
std::rotate(id_map.begin(),
id_map.begin() + 1,
id_map.begin() + 3);
ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
button_host->PointerReleasedOnButton(
dragged_button, ShelfButtonHost::MOUSE, true);
std::rotate(id_map.begin(),
id_map.begin() + 2,
id_map.begin() + 3);
ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 0, 2);
model_->RemoveItemAt(1);
id_map.erase(id_map.begin() + 1);
ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
button_host->PointerReleasedOnButton(
dragged_button, ShelfButtonHost::MOUSE, false);
dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 0, 2);
ShelfID new_id = AddAppShortcut();
id_map.insert(id_map.begin() + 5,
std::make_pair(new_id, GetButtonByID(new_id)));
ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
button_host->PointerReleasedOnButton(
dragged_button, ShelfButtonHost::MOUSE, false);
dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 0, 2);
new_id = AddPanel();
id_map.insert(id_map.begin() + 7,
std::make_pair(new_id, GetButtonByID(new_id)));
ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
button_host->PointerReleasedOnButton(
dragged_button, ShelfButtonHost::MOUSE, false);
}
TEST_F(ShelfViewTest, SimultaneousDrag) {
ShelfButtonHost* button_host = shelf_view_;
std::vector<std::pair<ShelfID, views::View*> > id_map;
SetupForDragTest(&id_map);
views::View* dragged_button_mouse =
SimulateDrag(ShelfButtonHost::MOUSE, 1, 3);
std::rotate(id_map.begin() + 1,
id_map.begin() + 2,
id_map.begin() + 4);
ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
views::View* dragged_button_touch =
SimulateDrag(ShelfButtonHost::TOUCH, 4, 2);
ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
button_host->PointerReleasedOnButton(
dragged_button_mouse, ShelfButtonHost::MOUSE, false);
ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
dragged_button_touch = SimulateDrag(ShelfButtonHost::TOUCH, 4, 2);
std::rotate(id_map.begin() + 3,
id_map.begin() + 4,
id_map.begin() + 5);
ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
dragged_button_mouse = SimulateDrag(ShelfButtonHost::MOUSE, 1, 2);
ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
button_host->PointerReleasedOnButton(
dragged_button_touch, ShelfButtonHost::TOUCH, false);
ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
}
TEST_F(ShelfViewTest, ClickOneDragAnother) {
ShelfButtonHost* button_host = shelf_view_;
std::vector<std::pair<ShelfID, views::View*> > id_map;
SetupForDragTest(&id_map);
SimulateClick(ShelfButtonHost::MOUSE, 1);
EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT);
views::View* dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 1, 3);
std::rotate(id_map.begin() + 1,
id_map.begin() + 2,
id_map.begin() + 4);
ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
button_host->PointerReleasedOnButton(
dragged_button, ShelfButtonHost::MOUSE, false);
EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT);
}
TEST_F(ShelfViewTest, ShelfItemStatus) {
ASSERT_EQ(test_api_->GetButtonCount(),
test_api_->GetLastVisibleIndex() + 1);
ShelfID last_added = AddPlatformApp();
ShelfItem item = GetItemByID(last_added);
int index = model_->ItemIndexByID(last_added);
ShelfButton* button = GetButtonByID(last_added);
ASSERT_EQ(ShelfButton::STATE_RUNNING, button->state());
item.status = STATUS_ACTIVE;
model_->Set(index, item);
ASSERT_EQ(ShelfButton::STATE_ACTIVE, button->state());
item.status = STATUS_ATTENTION;
model_->Set(index, item);
ASSERT_EQ(ShelfButton::STATE_ATTENTION, button->state());
}
TEST_F(ShelfViewLegacyShelfLayoutTest,
ShelfItemPositionReflectedOnStateChanged) {
ASSERT_EQ(test_api_->GetButtonCount(),
test_api_->GetLastVisibleIndex() + 1);
ShelfID item1_id = AddPlatformApp();
ShelfID item2_id = AddPlatformAppNoWait();
ShelfButton* item1_button = GetButtonByID(item1_id);
ShelfButton* item2_button = GetButtonByID(item2_id);
ShelfButton::State state_mask = static_cast<ShelfButton::State>(
ShelfButton::STATE_NORMAL | ShelfButton::STATE_HOVERED |
ShelfButton::STATE_RUNNING | ShelfButton::STATE_ACTIVE |
ShelfButton::STATE_ATTENTION | ShelfButton::STATE_FOCUSED);
item1_button->ClearState(state_mask);
item2_button->ClearState(state_mask);
ASSERT_EQ(item1_button->GetIconBounds().y(),
item2_button->GetIconBounds().y());
item1_button->AddState(ShelfButton::STATE_HOVERED);
ASSERT_NE(item1_button->GetIconBounds().y(),
item2_button->GetIconBounds().y());
item1_button->ClearState(ShelfButton::STATE_HOVERED);
}
TEST_F(ShelfViewTest, ShelfItemStatusPlatformApp) {
ASSERT_EQ(test_api_->GetButtonCount(),
test_api_->GetLastVisibleIndex() + 1);
ShelfID last_added = AddPlatformApp();
ShelfItem item = GetItemByID(last_added);
int index = model_->ItemIndexByID(last_added);
ShelfButton* button = GetButtonByID(last_added);
ASSERT_EQ(ShelfButton::STATE_RUNNING, button->state());
item.status = STATUS_ACTIVE;
model_->Set(index, item);
ASSERT_EQ(ShelfButton::STATE_ACTIVE, button->state());
item.status = STATUS_ATTENTION;
model_->Set(index, item);
ASSERT_EQ(ShelfButton::STATE_ATTENTION, button->state());
}
TEST_F(ShelfViewTest, ShelfItemBoundsCheck) {
VerifyShelfItemBoundsAreValid();
shelf_view_->shelf_layout_manager()->SetAutoHideBehavior(
SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
test_api_->RunMessageLoopUntilAnimationsDone();
VerifyShelfItemBoundsAreValid();
shelf_view_->shelf_layout_manager()->SetAutoHideBehavior(
SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
test_api_->RunMessageLoopUntilAnimationsDone();
VerifyShelfItemBoundsAreValid();
}
TEST_F(ShelfViewTest, ShelfTooltipTest) {
ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
test_api_->GetButtonCount());
ShelfID app_button_id = AddAppShortcut();
ShelfID platform_button_id = AddPlatformApp();
ShelfButton* app_button = GetButtonByID(app_button_id);
ShelfButton* platform_button = GetButtonByID(platform_button_id);
ShelfButtonHost* button_host = shelf_view_;
ShelfTooltipManager* tooltip_manager = shelf_view_->tooltip_manager();
button_host->MouseEnteredButton(app_button);
EXPECT_FALSE(tooltip_manager->IsVisible());
EXPECT_EQ(app_button, GetTooltipAnchorView());
ShowTooltip();
EXPECT_TRUE(tooltip_manager->IsVisible());
button_host->MouseExitedButton(app_button);
EXPECT_TRUE(tooltip_manager->IsVisible());
EXPECT_EQ(app_button, GetTooltipAnchorView());
button_host->MouseEnteredButton(platform_button);
EXPECT_TRUE(tooltip_manager->IsVisible());
EXPECT_EQ(platform_button, GetTooltipAnchorView());
button_host->MouseExitedButton(platform_button);
tooltip_manager->Close();
button_host->MouseEnteredButton(app_button);
button_host->MouseExitedButton(app_button);
button_host->MouseEnteredButton(platform_button);
EXPECT_FALSE(tooltip_manager->IsVisible());
EXPECT_EQ(platform_button, GetTooltipAnchorView());
}
TEST_F(ShelfViewTest, RemovingItemClosesTooltip) {
ShelfButtonHost* button_host = shelf_view_;
ShelfTooltipManager* tooltip_manager = shelf_view_->tooltip_manager();
ShelfID app_button_id = AddAppShortcut();
ShelfButton* app_button = GetButtonByID(app_button_id);
button_host->MouseEnteredButton(app_button);
ShowTooltip();
EXPECT_TRUE(tooltip_manager->IsVisible());
RemoveByID(app_button_id);
EXPECT_FALSE(tooltip_manager->IsVisible());
Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT,
Shell::GetPrimaryRootWindow());
}
TEST_F(ShelfViewTest, ShelfAlignmentClosesTooltip) {
ShelfButtonHost* button_host = shelf_view_;
ShelfTooltipManager* tooltip_manager = shelf_view_->tooltip_manager();
ShelfID app_button_id = AddAppShortcut();
ShelfButton* app_button = GetButtonByID(app_button_id);
button_host->MouseEnteredButton(app_button);
ShowTooltip();
EXPECT_TRUE(tooltip_manager->IsVisible());
Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT,
Shell::GetPrimaryRootWindow());
EXPECT_FALSE(tooltip_manager->IsVisible());
}
TEST_F(ShelfViewTest, ShouldHideTooltipTest) {
ShelfID app_button_id = AddAppShortcut();
ShelfID platform_button_id = AddPlatformApp();
for (int i = 0; i < test_api_->GetButtonCount(); i++) {
ShelfButton* button = test_api_->GetButton(i);
if (!button)
continue;
EXPECT_FALSE(shelf_view_->ShouldHideTooltip(
button->GetMirroredBounds().CenterPoint()))
<< "ShelfView tries to hide on button " << i;
}
views::View* app_list_button = shelf_view_->GetAppListButtonView();
EXPECT_FALSE(shelf_view_->ShouldHideTooltip(
app_list_button->GetMirroredBounds().CenterPoint()));
gfx::Rect app_button_rect = GetButtonByID(app_button_id)->GetMirroredBounds();
gfx::Rect platform_button_rect =
GetButtonByID(platform_button_id)->GetMirroredBounds();
ASSERT_FALSE(app_button_rect.Intersects(platform_button_rect));
EXPECT_FALSE(shelf_view_->ShouldHideTooltip(
gfx::UnionRects(app_button_rect, platform_button_rect).CenterPoint()));
gfx::Rect all_area;
for (int i = 0; i < test_api_->GetButtonCount(); i++) {
ShelfButton* button = test_api_->GetButton(i);
if (!button)
continue;
all_area.Union(button->GetMirroredBounds());
}
all_area.Union(shelf_view_->GetAppListButtonView()->GetMirroredBounds());
EXPECT_FALSE(shelf_view_->ShouldHideTooltip(all_area.origin()));
EXPECT_FALSE(shelf_view_->ShouldHideTooltip(
gfx::Point(all_area.right() - 1, all_area.bottom() - 1)));
EXPECT_TRUE(shelf_view_->ShouldHideTooltip(
gfx::Point(all_area.right(), all_area.y())));
EXPECT_TRUE(shelf_view_->ShouldHideTooltip(
gfx::Point(all_area.x() - 1, all_area.y())));
EXPECT_TRUE(shelf_view_->ShouldHideTooltip(
gfx::Point(all_area.x(), all_area.y() - 1)));
EXPECT_TRUE(shelf_view_->ShouldHideTooltip(
gfx::Point(all_area.x(), all_area.bottom())));
}
TEST_F(ShelfViewTest, ShouldHideTooltipWithAppListWindowTest) {
Shell::GetInstance()->ToggleAppList(NULL);
ASSERT_TRUE(Shell::GetInstance()->GetAppListWindow());
for (int i = 1; i < test_api_->GetButtonCount(); i++) {
ShelfButton* button = test_api_->GetButton(i);
if (!button)
continue;
EXPECT_FALSE(shelf_view_->ShouldHideTooltip(
button->GetMirroredBounds().CenterPoint()))
<< "ShelfView tries to hide on button " << i;
}
views::View* app_list_button = shelf_view_->GetAppListButtonView();
EXPECT_TRUE(shelf_view_->ShouldHideTooltip(
app_list_button->GetMirroredBounds().CenterPoint()));
}
TEST_F(ShelfViewTest, ShouldHideTooltipWhenHoveringOnTooltip) {
ShelfTooltipManager* tooltip_manager = shelf_view_->tooltip_manager();
tooltip_manager->CreateZeroDelayTimerForTest();
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
generator.MoveMouseTo(gfx::Point(0, 0));
EXPECT_FALSE(tooltip_manager->IsVisible());
views::View* app_list_button = shelf_view_->GetAppListButtonView();
gfx::Rect bounds = app_list_button->GetBoundsInScreen();
generator.MoveMouseTo(bounds.CenterPoint());
RunAllPendingInMessageLoop();
EXPECT_TRUE(tooltip_manager->IsVisible());
generator.MoveMouseBy(bounds.width() / 2 + 5, 0);
RunAllPendingInMessageLoop();
EXPECT_TRUE(tooltip_manager->IsVisible());
generator.MoveMouseBy(-(bounds.width() / 2 + 5), 0);
RunAllPendingInMessageLoop();
EXPECT_TRUE(tooltip_manager->IsVisible());
generator.MoveMouseBy(0, -(bounds.height() / 2 + 5));
RunAllPendingInMessageLoop();
EXPECT_FALSE(tooltip_manager->IsVisible());
}
TEST_F(ShelfViewTest, ResizeDuringOverflowAddAnimation) {
ASSERT_EQ(test_api_->GetButtonCount(),
test_api_->GetLastVisibleIndex() + 1);
int items_added = 0;
AddPlatformAppNoWait();
while (!test_api_->IsOverflowButtonVisible()) {
test_api_->RunMessageLoopUntilAnimationsDone();
AddPlatformAppNoWait();
++items_added;
ASSERT_LT(items_added, 10000);
}
gfx::Rect bounds = shelf_view_->bounds();
bounds.set_width(bounds.width() - kShelfPreferredSize);
shelf_view_->SetBoundsRect(bounds);
ASSERT_TRUE(test_api_->IsOverflowButtonVisible());
test_api_->RunMessageLoopUntilAnimationsDone();
const int app_list_button_index = test_api_->GetButtonCount() - 1;
const gfx::Rect& app_list_ideal_bounds =
test_api_->GetIdealBoundsByIndex(app_list_button_index);
const gfx::Rect& app_list_bounds =
test_api_->GetBoundsByIndex(app_list_button_index);
EXPECT_EQ(app_list_ideal_bounds, app_list_bounds);
}
TEST_F(ShelfViewTest, OverflowBubbleSize) {
ReplaceShelfDelegateForRipOffTest();
AddButtonsUntilOverflow();
test_api_->ShowOverflowBubble();
ASSERT_TRUE(test_api_->overflow_bubble() &&
test_api_->overflow_bubble()->IsShowing());
ShelfViewTestAPI test_for_overflow_view(
test_api_->overflow_bubble()->shelf_view());
int ripped_index = test_for_overflow_view.GetLastVisibleIndex();
gfx::Size bubble_size = test_for_overflow_view.GetPreferredSize();
int item_width = test_for_overflow_view.GetButtonSize() +
test_for_overflow_view.GetButtonSpacing();
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
gfx::Point());
ShelfButton* button = test_for_overflow_view.GetButton(ripped_index);
gfx::Point start_point = button->GetBoundsInScreen().CenterPoint();
gfx::Point rip_off_point(start_point.x(), 0);
generator.MoveMouseTo(start_point.x(), start_point.y());
base::MessageLoop::current()->RunUntilIdle();
generator.PressLeftButton();
base::MessageLoop::current()->RunUntilIdle();
generator.MoveMouseTo(rip_off_point.x(), rip_off_point.y());
base::MessageLoop::current()->RunUntilIdle();
test_for_overflow_view.RunMessageLoopUntilAnimationsDone();
EXPECT_EQ(bubble_size.width() - item_width,
test_for_overflow_view.GetPreferredSize().width());
ASSERT_TRUE(test_api_->overflow_bubble() &&
test_api_->overflow_bubble()->IsShowing());
int first_index = test_for_overflow_view.GetFirstVisibleIndex();
button = test_for_overflow_view.GetButton(first_index);
generator.MoveMouseTo(button->GetBoundsInScreen().CenterPoint());
test_for_overflow_view.RunMessageLoopUntilAnimationsDone();
EXPECT_EQ(bubble_size.width(),
test_for_overflow_view.GetPreferredSize().width());
generator.ReleaseLeftButton();
test_for_overflow_view.RunMessageLoopUntilAnimationsDone();
EXPECT_EQ(bubble_size.width(),
test_for_overflow_view.GetPreferredSize().width());
}
TEST_F(ShelfViewLegacyShelfLayoutTest, CheckFittsLaw) {
ASSERT_EQ(test_api_->GetButtonCount(),
test_api_->GetLastVisibleIndex() + 1);
gfx::Rect ideal_bounds_0 = test_api_->GetIdealBoundsByIndex(0);
gfx::Rect ideal_bounds_1 = test_api_->GetIdealBoundsByIndex(1);
EXPECT_GT(ideal_bounds_0.width(), ideal_bounds_1.width());
}
TEST_F(ShelfViewTest, CheckDragInsertBoundsOfScrolledOverflowBubble) {
UpdateDisplay("400x300");
EXPECT_EQ(2, model_->item_count());
AddButtonsUntilOverflow();
test_api_->ShowOverflowBubble();
ASSERT_TRUE(test_api_->overflow_bubble() &&
test_api_->overflow_bubble()->IsShowing());
int item_width = test_api_->GetButtonSize() +
test_api_->GetButtonSpacing();
OverflowBubbleView* bubble_view = test_api_->overflow_bubble()->bubble_view();
test::OverflowBubbleViewTestAPI bubble_view_api(bubble_view);
while (bubble_view_api.GetContentsSize().width() <
(bubble_view->GetContentsBounds().width() + 3 * item_width))
AddAppShortcut();
ASSERT_TRUE(test_api_->overflow_bubble() &&
test_api_->overflow_bubble()->IsShowing());
ShelfViewTestAPI test_for_overflow_view(
test_api_->overflow_bubble()->shelf_view());
int first_index = test_for_overflow_view.GetFirstVisibleIndex();
int last_index = test_for_overflow_view.GetLastVisibleIndex();
ShelfButton* first_button = test_for_overflow_view.GetButton(first_index);
ShelfButton* last_button = test_for_overflow_view.GetButton(last_index);
gfx::Point first_point = first_button->GetBoundsInScreen().CenterPoint();
gfx::Point last_point = last_button->GetBoundsInScreen().CenterPoint();
gfx::Rect drag_reinsert_bounds =
test_for_overflow_view.GetBoundsForDragInsertInScreen();
EXPECT_TRUE(drag_reinsert_bounds.Contains(first_point));
EXPECT_FALSE(drag_reinsert_bounds.Contains(last_point));
bubble_view_api.ScrollByXOffset(3 * item_width);
drag_reinsert_bounds =
test_for_overflow_view.GetBoundsForDragInsertInScreen();
first_point = first_button->GetBoundsInScreen().CenterPoint();
last_point = last_button->GetBoundsInScreen().CenterPoint();
EXPECT_FALSE(drag_reinsert_bounds.Contains(first_point));
EXPECT_TRUE(drag_reinsert_bounds.Contains(last_point));
}
TEST_F(ShelfViewTest, CheckDragInsertBoundsWithMultiMonitor) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("800x600,800x600");
Shelf* secondary_shelf = Shelf::ForWindow(Shell::GetAllRootWindows()[1]);
ShelfView* shelf_view_for_secondary =
ShelfTestAPI(secondary_shelf).shelf_view();
shelf_view_for_secondary->SetBounds(
0, 0, 500, ShelfLayoutManager::GetPreferredShelfSize());
ShelfViewTestAPI test_api_for_secondary(shelf_view_for_secondary);
test_api_for_secondary.SetAnimationDuration(1);
AddButtonsUntilOverflow();
test_api_->ShowOverflowBubble();
ASSERT_TRUE(test_api_->overflow_bubble() &&
test_api_->overflow_bubble()->IsShowing());
ShelfViewTestAPI test_api_for_overflow_view(
test_api_->overflow_bubble()->shelf_view());
ShelfButton* button = test_api_for_overflow_view.GetButton(
test_api_for_overflow_view.GetLastVisibleIndex());
gfx::Point point_in_shelf_view = button->GetBoundsInScreen().CenterPoint();
gfx::Rect drag_reinsert_bounds =
test_api_for_overflow_view.GetBoundsForDragInsertInScreen();
EXPECT_TRUE(drag_reinsert_bounds.Contains(point_in_shelf_view));
EXPECT_FALSE(drag_reinsert_bounds.Contains(
gfx::Point(point_in_shelf_view.x(), 0)));
test_api_for_secondary.ShowOverflowBubble();
ASSERT_TRUE(test_api_for_secondary.overflow_bubble() &&
test_api_for_secondary.overflow_bubble()->IsShowing());
ShelfViewTestAPI test_api_for_overflow_view_of_secondary(
test_api_for_secondary.overflow_bubble()->shelf_view());
ShelfButton* button_in_secondary =
test_api_for_overflow_view_of_secondary.GetButton(
test_api_for_overflow_view_of_secondary.GetLastVisibleIndex());
gfx::Point point_in_secondary_shelf_view =
button_in_secondary->GetBoundsInScreen().CenterPoint();
gfx::Rect drag_reinsert_bounds_in_secondary =
test_api_for_overflow_view_of_secondary.GetBoundsForDragInsertInScreen();
EXPECT_TRUE(drag_reinsert_bounds_in_secondary.Contains(
point_in_secondary_shelf_view));
EXPECT_FALSE(drag_reinsert_bounds_in_secondary.Contains(
gfx::Point(point_in_secondary_shelf_view.x(), 0)));
EXPECT_FALSE(drag_reinsert_bounds_in_secondary.Contains(point_in_shelf_view));
}
TEST_F(ShelfViewTest, CheckRipOffFromLeftShelfAlignmentWithMultiMonitor) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("800x600,800x600");
ASSERT_EQ(2U, Shell::GetAllRootWindows().size());
aura::Window* second_root = Shell::GetAllRootWindows()[1];
Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, second_root);
ASSERT_EQ(SHELF_ALIGNMENT_LEFT,
Shell::GetInstance()->GetShelfAlignment(second_root));
EXPECT_EQ(2, model_->item_count());
int browser_index = model_->GetItemIndexForType(TYPE_BROWSER_SHORTCUT);
EXPECT_GT(browser_index, 0);
Shelf* secondary_shelf = Shelf::ForWindow(second_root);
ShelfView* shelf_view_for_secondary =
ShelfTestAPI(secondary_shelf).shelf_view();
ShelfViewTestAPI test_api_for_secondary_shelf_view(shelf_view_for_secondary);
ShelfButton* button =
test_api_for_secondary_shelf_view.GetButton(browser_index);
gfx::Point start_point = button->GetBoundsInScreen().CenterPoint();
wm::ConvertPointFromScreen(second_root, &start_point);
aura::test::EventGenerator generator(second_root, start_point);
generator.PressLeftButton();
generator.MoveMouseTo(start_point.x() + 400, start_point.y());
test_api_for_secondary_shelf_view.RunMessageLoopUntilAnimationsDone();
EXPECT_TRUE(test_api_for_secondary_shelf_view.IsRippedOffFromShelf());
}
TEST_F(ShelfViewTest, CheckDragAndDropFromOverflowBubbleToShelf) {
ReplaceShelfDelegateForRipOffTest();
AddButtonsUntilOverflow();
TestDraggingAnItemFromOverflowToShelf(false);
TestDraggingAnItemFromOverflowToShelf(true);
}
class ShelfViewVisibleBoundsTest : public ShelfViewTest,
public testing::WithParamInterface<bool> {
public:
ShelfViewVisibleBoundsTest() : text_direction_change_(GetParam()) {}
void CheckAllItemsAreInBounds() {
gfx::Rect visible_bounds = shelf_view_->GetVisibleItemsBoundsInScreen();
gfx::Rect shelf_bounds = shelf_view_->GetBoundsInScreen();
EXPECT_TRUE(shelf_bounds.Contains(visible_bounds));
for (int i = 0; i < test_api_->GetButtonCount(); ++i)
if (ShelfButton* button = test_api_->GetButton(i))
EXPECT_TRUE(visible_bounds.Contains(button->GetBoundsInScreen()));
CheckAppListButtonIsInBounds();
}
void CheckAppListButtonIsInBounds() {
gfx::Rect visible_bounds = shelf_view_->GetVisibleItemsBoundsInScreen();
gfx::Rect app_list_button_bounds = shelf_view_->GetAppListButtonView()->
GetBoundsInScreen();
EXPECT_TRUE(visible_bounds.Contains(app_list_button_bounds));
}
private:
ScopedTextDirectionChange text_direction_change_;
DISALLOW_COPY_AND_ASSIGN(ShelfViewVisibleBoundsTest);
};
TEST_P(ShelfViewVisibleBoundsTest, ItemsAreInBounds) {
for (int i = 0; i < 3; i++) {
AddAppShortcut();
}
test_api_->RunMessageLoopUntilAnimationsDone();
EXPECT_FALSE(test_api_->IsOverflowButtonVisible());
CheckAllItemsAreInBounds();
while (!test_api_->IsOverflowButtonVisible()) {
AddAppShortcut();
}
test_api_->RunMessageLoopUntilAnimationsDone();
CheckAllItemsAreInBounds();
}
INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool());
INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest,
testing::Bool());
}
}