Chromium Code Reviews| Index: ash/common/shelf/shelf_tooltip_manager_unittest.cc |
| diff --git a/ash/shelf/shelf_tooltip_manager_unittest.cc b/ash/common/shelf/shelf_tooltip_manager_unittest.cc |
| similarity index 77% |
| rename from ash/shelf/shelf_tooltip_manager_unittest.cc |
| rename to ash/common/shelf/shelf_tooltip_manager_unittest.cc |
| index 342789ef50128bfb620fd8f30ad1f2716a873e8b..fc8495335ff052383e00858ae41921ceeb57390b 100644 |
| --- a/ash/shelf/shelf_tooltip_manager_unittest.cc |
| +++ b/ash/common/shelf/shelf_tooltip_manager_unittest.cc |
| @@ -7,11 +7,9 @@ |
| #include "ash/common/shelf/app_list_button.h" |
| #include "ash/common/shelf/shelf_model.h" |
| #include "ash/common/shelf/wm_shelf.h" |
| -#include "ash/common/wm_shell.h" |
| +#include "ash/common/shell_window_ids.h" |
|
James Cook
2016/08/01 16:58:03
nit: remove
msw
2016/08/01 17:25:46
Done.
|
| #include "ash/shelf/shelf_view.h" |
| -#include "ash/shell.h" |
| #include "ash/test/ash_test_base.h" |
| -#include "ash/test/shelf_test_api.h" |
| #include "ash/test/shelf_view_test_api.h" |
| #include "ash/test/test_shelf_item_delegate.h" |
| #include "base/memory/ptr_util.h" |
| @@ -30,8 +28,7 @@ class ShelfTooltipManagerTest : public AshTestBase { |
| void SetUp() override { |
| AshTestBase::SetUp(); |
| - shelf_ = Shelf::ForPrimaryDisplay(); |
| - shelf_view_ = test::ShelfTestAPI(shelf_).shelf_view(); |
| + shelf_view_ = GetPrimaryShelf()->GetShelfViewForTesting(); |
| tooltip_manager_ = test::ShelfViewTestAPI(shelf_view_).tooltip_manager(); |
| tooltip_manager_->set_timer_delay_for_test(0); |
| } |
| @@ -39,8 +36,17 @@ class ShelfTooltipManagerTest : public AshTestBase { |
| bool IsTimerRunning() { return tooltip_manager_->timer_.IsRunning(); } |
| views::Widget* GetTooltip() { return tooltip_manager_->bubble_->GetWidget(); } |
| + std::unique_ptr<views::Widget> CreateTestWidget() { |
|
James Cook
2016/08/01 16:58:03
Odd that AshTestBase::CreateTestWidget doesn't wor
msw
2016/08/01 17:25:46
Acknowledged. I can look separately.
|
| + std::unique_ptr<views::Widget> widget = base::MakeUnique<views::Widget>(); |
| + views::Widget::InitParams params; |
| + params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| + params.context = CurrentContext(); |
| + widget->Init(params); |
| + widget->Show(); |
| + return widget; |
| + } |
| + |
| protected: |
| - Shelf* shelf_; |
| ShelfView* shelf_view_; |
| ShelfTooltipManager* tooltip_manager_; |
| @@ -49,14 +55,14 @@ class ShelfTooltipManagerTest : public AshTestBase { |
| }; |
| TEST_F(ShelfTooltipManagerTest, ShowTooltip) { |
| - tooltip_manager_->ShowTooltip(shelf_->GetAppListButton()); |
| + tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton()); |
| EXPECT_TRUE(tooltip_manager_->IsVisible()); |
| EXPECT_FALSE(IsTimerRunning()); |
| } |
| TEST_F(ShelfTooltipManagerTest, ShowTooltipWithDelay) { |
| // ShowTooltipWithDelay should start the timer instead of showing immediately. |
| - tooltip_manager_->ShowTooltipWithDelay(shelf_->GetAppListButton()); |
| + tooltip_manager_->ShowTooltipWithDelay(shelf_view_->GetAppListButton()); |
| EXPECT_FALSE(tooltip_manager_->IsVisible()); |
| EXPECT_TRUE(IsTimerRunning()); |
| // TODO: Test that the delayed tooltip is shown, without flaky failures. |
| @@ -77,13 +83,13 @@ TEST_F(ShelfTooltipManagerTest, DoNotShowForInvalidView) { |
| EXPECT_FALSE(IsTimerRunning()); |
| // The manager should start the timer for a view on the shelf. |
| - ShelfModel* model = WmShell::Get()->shelf_model(); |
| + ShelfModel* model = shelf_view_->model(); |
| ShelfItem item; |
| item.type = TYPE_APP_SHORTCUT; |
| const int index = model->Add(item); |
| const ShelfID id = model->items()[index].id; |
| - model->SetShelfItemDelegate( |
| - id, base::WrapUnique(new TestShelfItemDelegate(nullptr))); |
| + model->SetShelfItemDelegate(id, |
| + base::MakeUnique<TestShelfItemDelegate>(nullptr)); |
| // Note: There's no easy way to correlate shelf a model index/id to its view. |
| tooltip_manager_->ShowTooltipWithDelay( |
| shelf_view_->child_at(shelf_view_->child_count() - 1)); |
| @@ -98,41 +104,30 @@ TEST_F(ShelfTooltipManagerTest, DoNotShowForInvalidView) { |
| } |
| TEST_F(ShelfTooltipManagerTest, HideWhenShelfIsHidden) { |
| - tooltip_manager_->ShowTooltip(shelf_->GetAppListButton()); |
| + tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton()); |
| ASSERT_TRUE(tooltip_manager_->IsVisible()); |
| // Create a full-screen window to hide the shelf. |
| - std::unique_ptr<views::Widget> widget(new views::Widget); |
| - views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| - params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| - params.context = CurrentContext(); |
| - widget->Init(params); |
| + std::unique_ptr<views::Widget> widget = CreateTestWidget(); |
| widget->SetFullscreen(true); |
| - widget->Show(); |
| // Once the shelf is hidden, the tooltip should be invisible. |
| ASSERT_EQ(SHELF_HIDDEN, GetPrimaryShelf()->GetVisibilityState()); |
| EXPECT_FALSE(tooltip_manager_->IsVisible()); |
| // Do not show the view if the shelf is hidden. |
| - tooltip_manager_->ShowTooltip(shelf_->GetAppListButton()); |
| + tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton()); |
| EXPECT_FALSE(tooltip_manager_->IsVisible()); |
| // ShowTooltipWithDelay doesn't even start the timer for the hidden shelf. |
| - tooltip_manager_->ShowTooltipWithDelay(shelf_->GetAppListButton()); |
| + tooltip_manager_->ShowTooltipWithDelay(shelf_view_->GetAppListButton()); |
| EXPECT_FALSE(IsTimerRunning()); |
| } |
| TEST_F(ShelfTooltipManagerTest, HideWhenShelfIsAutoHide) { |
| // Create a visible window so auto-hide behavior is enforced. |
| - views::Widget* dummy = new views::Widget; |
| - views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| - params.bounds = gfx::Rect(0, 0, 200, 200); |
| - params.context = CurrentContext(); |
| - dummy->Init(params); |
| - dummy->Show(); |
| - |
| - tooltip_manager_->ShowTooltip(shelf_->GetAppListButton()); |
| + std::unique_ptr<views::Widget> widget = CreateTestWidget(); |
| + tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton()); |
| ASSERT_TRUE(tooltip_manager_->IsVisible()); |
| GetPrimaryShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
| @@ -145,11 +140,11 @@ TEST_F(ShelfTooltipManagerTest, HideWhenShelfIsAutoHide) { |
| EXPECT_FALSE(tooltip_manager_->IsVisible()); |
| // Do not show the view if the shelf is hidden. |
| - tooltip_manager_->ShowTooltip(shelf_->GetAppListButton()); |
| + tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton()); |
| EXPECT_FALSE(tooltip_manager_->IsVisible()); |
| // ShowTooltipWithDelay doesn't even run the timer for the hidden shelf. |
| - tooltip_manager_->ShowTooltipWithDelay(shelf_->GetAppListButton()); |
| + tooltip_manager_->ShowTooltipWithDelay(shelf_view_->GetAppListButton()); |
| EXPECT_FALSE(IsTimerRunning()); |
| } |
| @@ -158,28 +153,28 @@ TEST_F(ShelfTooltipManagerTest, HideForEvents) { |
| gfx::Rect shelf_bounds = shelf_view_->GetBoundsInScreen(); |
| // Should hide if the mouse exits the shelf area. |
| - tooltip_manager_->ShowTooltip(shelf_->GetAppListButton()); |
| + tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton()); |
| ASSERT_TRUE(tooltip_manager_->IsVisible()); |
| generator.MoveMouseTo(shelf_bounds.CenterPoint()); |
| generator.SendMouseExit(); |
| EXPECT_FALSE(tooltip_manager_->IsVisible()); |
| // Should hide if the mouse is pressed in the shelf area. |
| - tooltip_manager_->ShowTooltip(shelf_->GetAppListButton()); |
| + tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton()); |
| ASSERT_TRUE(tooltip_manager_->IsVisible()); |
| generator.MoveMouseTo(shelf_bounds.CenterPoint()); |
| generator.PressLeftButton(); |
| EXPECT_FALSE(tooltip_manager_->IsVisible()); |
| // Should hide for touch events in the shelf. |
| - tooltip_manager_->ShowTooltip(shelf_->GetAppListButton()); |
| + tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton()); |
| ASSERT_TRUE(tooltip_manager_->IsVisible()); |
| generator.set_current_location(shelf_bounds.CenterPoint()); |
| generator.PressTouch(); |
| EXPECT_FALSE(tooltip_manager_->IsVisible()); |
| // Should hide for gesture events in the shelf. |
| - tooltip_manager_->ShowTooltip(shelf_->GetAppListButton()); |
| + tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton()); |
| ASSERT_TRUE(tooltip_manager_->IsVisible()); |
| generator.GestureTapDownAndUp(shelf_bounds.CenterPoint()); |
| EXPECT_FALSE(tooltip_manager_->IsVisible()); |
| @@ -189,7 +184,7 @@ TEST_F(ShelfTooltipManagerTest, HideForExternalEvents) { |
| ui::test::EventGenerator& generator = GetEventGenerator(); |
| // Should hide for touches outside the shelf. |
| - tooltip_manager_->ShowTooltip(shelf_->GetAppListButton()); |
| + tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton()); |
| ASSERT_TRUE(tooltip_manager_->IsVisible()); |
| generator.set_current_location(gfx::Point()); |
| generator.PressTouch(); |
| @@ -197,7 +192,7 @@ TEST_F(ShelfTooltipManagerTest, HideForExternalEvents) { |
| generator.ReleaseTouch(); |
| // Should hide for touch events on the tooltip. |
| - tooltip_manager_->ShowTooltip(shelf_->GetAppListButton()); |
| + tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton()); |
| ASSERT_TRUE(tooltip_manager_->IsVisible()); |
| generator.set_current_location( |
| GetTooltip()->GetWindowBoundsInScreen().CenterPoint()); |
| @@ -206,7 +201,7 @@ TEST_F(ShelfTooltipManagerTest, HideForExternalEvents) { |
| generator.ReleaseTouch(); |
| // Should hide for gestures outside the shelf. |
| - tooltip_manager_->ShowTooltip(shelf_->GetAppListButton()); |
| + tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton()); |
| ASSERT_TRUE(tooltip_manager_->IsVisible()); |
| generator.GestureTapDownAndUp(gfx::Point()); |
| EXPECT_FALSE(tooltip_manager_->IsVisible()); |
| @@ -216,7 +211,7 @@ TEST_F(ShelfTooltipManagerTest, DoNotHideForKeyEvents) { |
| ui::test::EventGenerator& generator = GetEventGenerator(); |
| // Should not hide for key events. |
| - tooltip_manager_->ShowTooltip(shelf_->GetAppListButton()); |
| + tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton()); |
| ASSERT_TRUE(tooltip_manager_->IsVisible()); |
| generator.PressKey(ui::VKEY_A, ui::EF_NONE); |
| EXPECT_TRUE(tooltip_manager_->IsVisible()); |