OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/shelf/shelf_view.h" | 5 #include "ash/shelf/shelf_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 | 278 |
279 // Temp member variable for returning a value. See the comment in the | 279 // Temp member variable for returning a value. See the comment in the |
280 // GetAppIDForShelfID(). | 280 // GetAppIDForShelfID(). |
281 std::string app_id_; | 281 std::string app_id_; |
282 | 282 |
283 DISALLOW_COPY_AND_ASSIGN(TestShelfDelegateForShelfView); | 283 DISALLOW_COPY_AND_ASSIGN(TestShelfDelegateForShelfView); |
284 }; | 284 }; |
285 | 285 |
286 class ShelfViewTest : public AshTestBase { | 286 class ShelfViewTest : public AshTestBase { |
287 public: | 287 public: |
288 ShelfViewTest() : model_(NULL), shelf_view_(NULL), browser_index_(1) {} | 288 ShelfViewTest() |
| 289 : model_(NULL), |
| 290 shelf_view_(NULL), |
| 291 browser_index_(1), |
| 292 item_manager_(NULL) {} |
289 virtual ~ShelfViewTest() {} | 293 virtual ~ShelfViewTest() {} |
290 | 294 |
291 virtual void SetUp() OVERRIDE { | 295 virtual void SetUp() OVERRIDE { |
292 AshTestBase::SetUp(); | 296 AshTestBase::SetUp(); |
293 test::ShellTestApi test_api(Shell::GetInstance()); | 297 test::ShellTestApi test_api(Shell::GetInstance()); |
294 model_ = test_api.shelf_model(); | 298 model_ = test_api.shelf_model(); |
295 Shelf* shelf = Shelf::ForPrimaryDisplay(); | 299 Shelf* shelf = Shelf::ForPrimaryDisplay(); |
296 shelf_view_ = ShelfTestAPI(shelf).shelf_view(); | 300 shelf_view_ = ShelfTestAPI(shelf).shelf_view(); |
297 | 301 |
298 // The bounds should be big enough for 4 buttons + overflow chevron. | 302 // The bounds should be big enough for 4 buttons + overflow chevron. |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 gfx::Rect shelf_view_bounds = shelf_view_->GetLocalBounds(); | 416 gfx::Rect shelf_view_bounds = shelf_view_->GetLocalBounds(); |
413 gfx::Rect item_bounds = test_api_->GetBoundsByIndex(i); | 417 gfx::Rect item_bounds = test_api_->GetBoundsByIndex(i); |
414 EXPECT_GE(item_bounds.x(), 0); | 418 EXPECT_GE(item_bounds.x(), 0); |
415 EXPECT_GE(item_bounds.y(), 0); | 419 EXPECT_GE(item_bounds.y(), 0); |
416 EXPECT_LE(item_bounds.right(), shelf_view_bounds.width()); | 420 EXPECT_LE(item_bounds.right(), shelf_view_bounds.width()); |
417 EXPECT_LE(item_bounds.bottom(), shelf_view_bounds.height()); | 421 EXPECT_LE(item_bounds.bottom(), shelf_view_bounds.height()); |
418 } | 422 } |
419 } | 423 } |
420 } | 424 } |
421 | 425 |
422 views::View* SimulateButtonPressed(ShelfButtonHost::Pointer pointer, | 426 ShelfButton* SimulateButtonPressed(ShelfButtonHost::Pointer pointer, |
423 int button_index) { | 427 int button_index) { |
424 ShelfButtonHost* button_host = shelf_view_; | 428 ShelfButtonHost* button_host = shelf_view_; |
425 views::View* button = test_api_->GetButton(button_index); | 429 ShelfButton* button = test_api_->GetButton(button_index); |
426 ui::MouseEvent click_event(ui::ET_MOUSE_PRESSED, | 430 ui::MouseEvent click_event(ui::ET_MOUSE_PRESSED, |
427 gfx::Point(), | 431 gfx::Point(), |
428 button->GetBoundsInScreen().origin(), 0, 0); | 432 button->GetBoundsInScreen().origin(), 0, 0); |
429 button_host->PointerPressedOnButton(button, pointer, click_event); | 433 button_host->PointerPressedOnButton(button, pointer, click_event); |
430 return button; | 434 return button; |
431 } | 435 } |
432 | 436 |
433 views::View* SimulateClick(ShelfButtonHost::Pointer pointer, | 437 views::View* SimulateClick(ShelfButtonHost::Pointer pointer, |
434 int button_index) { | 438 int button_index) { |
435 ShelfButtonHost* button_host = shelf_view_; | 439 ShelfButtonHost* button_host = shelf_view_; |
436 views::View* button = SimulateButtonPressed(pointer, button_index); | 440 ShelfButton* button = SimulateButtonPressed(pointer, button_index); |
| 441 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, |
| 442 gfx::Point(), |
| 443 button->GetBoundsInScreen().origin(), |
| 444 0, |
| 445 0); |
| 446 test_api_->ButtonPressed(button, release_event); |
437 button_host->PointerReleasedOnButton(button, ShelfButtonHost::MOUSE, false); | 447 button_host->PointerReleasedOnButton(button, ShelfButtonHost::MOUSE, false); |
438 return button; | 448 return button; |
439 } | 449 } |
440 | 450 |
441 views::View* SimulateDrag(ShelfButtonHost::Pointer pointer, | 451 views::View* SimulateDrag(ShelfButtonHost::Pointer pointer, |
442 int button_index, | 452 int button_index, |
443 int destination_index) { | 453 int destination_index) { |
444 ShelfButtonHost* button_host = shelf_view_; | 454 ShelfButtonHost* button_host = shelf_view_; |
445 views::View* button = SimulateButtonPressed(pointer, button_index); | 455 views::View* button = SimulateButtonPressed(pointer, button_index); |
446 | 456 |
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1050 views::View* dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 1, 3); | 1060 views::View* dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 1, 3); |
1051 std::rotate(id_map.begin() + 1, | 1061 std::rotate(id_map.begin() + 1, |
1052 id_map.begin() + 2, | 1062 id_map.begin() + 2, |
1053 id_map.begin() + 4); | 1063 id_map.begin() + 4); |
1054 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 1064 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
1055 button_host->PointerReleasedOnButton( | 1065 button_host->PointerReleasedOnButton( |
1056 dragged_button, ShelfButtonHost::MOUSE, false); | 1066 dragged_button, ShelfButtonHost::MOUSE, false); |
1057 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT); | 1067 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT); |
1058 } | 1068 } |
1059 | 1069 |
| 1070 // Tests that clicking on the browser item cleans up the menu model. |
| 1071 TEST_F(ShelfViewTest, ClickingBrowserIconCleansUpMenuModel) { |
| 1072 // Menu starts invisible. |
| 1073 ASSERT_FALSE(shelf_view_->IsShowingMenu()); |
| 1074 |
| 1075 // Clicking the browser icon doesn't show one (the menu is too short). |
| 1076 SimulateClick(ShelfButtonHost::MOUSE, browser_index_); |
| 1077 EXPECT_FALSE(shelf_view_->IsShowingMenu()); |
| 1078 |
| 1079 // No menu model, since no menu is showing. |
| 1080 EXPECT_FALSE(shelf_view_->list_menu_model_for_test()); |
| 1081 } |
| 1082 |
1060 // Check that clicking an item and jittering the mouse a bit still selects the | 1083 // Check that clicking an item and jittering the mouse a bit still selects the |
1061 // item. | 1084 // item. |
1062 TEST_F(ShelfViewTest, ClickAndMoveSlightly) { | 1085 TEST_F(ShelfViewTest, ClickAndMoveSlightly) { |
1063 std::vector<std::pair<ShelfID, views::View*> > id_map; | 1086 std::vector<std::pair<ShelfID, views::View*> > id_map; |
1064 SetupForDragTest(&id_map); | 1087 SetupForDragTest(&id_map); |
1065 | 1088 |
1066 ShelfID shelf_id = (id_map.begin() + 1)->first; | 1089 ShelfID shelf_id = (id_map.begin() + 1)->first; |
1067 views::View* button = (id_map.begin() + 1)->second; | 1090 views::View* button = (id_map.begin() + 1)->second; |
1068 | 1091 |
1069 // Replace the ShelfItemDelegate for |shelf_id| with one which tracks whether | 1092 // Replace the ShelfItemDelegate for |shelf_id| with one which tracks whether |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1669 test_api_->RunMessageLoopUntilAnimationsDone(); | 1692 test_api_->RunMessageLoopUntilAnimationsDone(); |
1670 CheckAllItemsAreInBounds(); | 1693 CheckAllItemsAreInBounds(); |
1671 } | 1694 } |
1672 | 1695 |
1673 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool()); | 1696 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool()); |
1674 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest, | 1697 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest, |
1675 testing::Bool()); | 1698 testing::Bool()); |
1676 | 1699 |
1677 } // namespace test | 1700 } // namespace test |
1678 } // namespace ash | 1701 } // namespace ash |
OLD | NEW |