Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: ash/shelf/shelf_view_unittest.cc

Issue 2036353002: mash: Move ash/common/wm/shelf to ash/common/shelf (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase again Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/shelf/shelf_view.cc ('k') | ash/shelf/shelf_widget.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "ash/common/shelf/shelf_constants.h"
12 #include "ash/common/shell_window_ids.h" 13 #include "ash/common/shell_window_ids.h"
13 #include "ash/root_window_controller.h" 14 #include "ash/root_window_controller.h"
14 #include "ash/shelf/app_list_button.h" 15 #include "ash/shelf/app_list_button.h"
15 #include "ash/shelf/overflow_bubble.h" 16 #include "ash/shelf/overflow_bubble.h"
16 #include "ash/shelf/overflow_bubble_view.h" 17 #include "ash/shelf/overflow_bubble_view.h"
17 #include "ash/shelf/shelf.h" 18 #include "ash/shelf/shelf.h"
18 #include "ash/shelf/shelf_button.h" 19 #include "ash/shelf/shelf_button.h"
19 #include "ash/shelf/shelf_constants.h"
20 #include "ash/shelf/shelf_icon_observer.h" 20 #include "ash/shelf/shelf_icon_observer.h"
21 #include "ash/shelf/shelf_item_delegate_manager.h" 21 #include "ash/shelf/shelf_item_delegate_manager.h"
22 #include "ash/shelf/shelf_model.h" 22 #include "ash/shelf/shelf_model.h"
23 #include "ash/shelf/shelf_tooltip_manager.h" 23 #include "ash/shelf/shelf_tooltip_manager.h"
24 #include "ash/shelf/shelf_widget.h" 24 #include "ash/shelf/shelf_widget.h"
25 #include "ash/shell.h" 25 #include "ash/shell.h"
26 #include "ash/test/ash_test_base.h" 26 #include "ash/test/ash_test_base.h"
27 #include "ash/test/overflow_bubble_view_test_api.h" 27 #include "ash/test/overflow_bubble_view_test_api.h"
28 #include "ash/test/shelf_test_api.h" 28 #include "ash/test/shelf_test_api.h"
29 #include "ash/test/shelf_view_test_api.h" 29 #include "ash/test/shelf_view_test_api.h"
(...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 // Add 20 panel icons, and expect to have overflow. 970 // Add 20 panel icons, and expect to have overflow.
971 for (int i = 0; i < 20; ++i) { 971 for (int i = 0; i < 20; ++i) {
972 ShelfID id = AddPanel(); 972 ShelfID id = AddPanel();
973 button_ids.push_back(id); 973 button_ids.push_back(id);
974 } 974 }
975 ASSERT_LT(button_ids.size(), 10000U); 975 ASSERT_LT(button_ids.size(), 10000U);
976 EXPECT_TRUE(test_api_->IsOverflowButtonVisible()); 976 EXPECT_TRUE(test_api_->IsOverflowButtonVisible());
977 977
978 // Test that any two successive visible icons never overlap in all shelf 978 // Test that any two successive visible icons never overlap in all shelf
979 // alignment types. 979 // alignment types.
980 const wm::ShelfAlignment kAlignments[] = { 980 const ShelfAlignment kAlignments[] = {
981 wm::SHELF_ALIGNMENT_LEFT, wm::SHELF_ALIGNMENT_RIGHT, 981 SHELF_ALIGNMENT_LEFT, SHELF_ALIGNMENT_RIGHT, SHELF_ALIGNMENT_BOTTOM,
982 wm::SHELF_ALIGNMENT_BOTTOM, wm::SHELF_ALIGNMENT_BOTTOM_LOCKED, 982 SHELF_ALIGNMENT_BOTTOM_LOCKED,
983 }; 983 };
984 984
985 for (wm::ShelfAlignment alignment : kAlignments) { 985 for (ShelfAlignment alignment : kAlignments) {
986 shelf_view_->shelf()->SetAlignment(alignment); 986 shelf_view_->shelf()->SetAlignment(alignment);
987 // For every 2 successive visible icons, expect that their bounds don't 987 // For every 2 successive visible icons, expect that their bounds don't
988 // intersect. 988 // intersect.
989 for (int i = 1; i < test_api_->GetButtonCount() - 1; ++i) { 989 for (int i = 1; i < test_api_->GetButtonCount() - 1; ++i) {
990 if (!(test_api_->GetButton(i)->visible() && 990 if (!(test_api_->GetButton(i)->visible() &&
991 test_api_->GetButton(i + 1)->visible())) { 991 test_api_->GetButton(i + 1)->visible())) {
992 continue; 992 continue;
993 } 993 }
994 994
995 const gfx::Rect& bounds1 = test_api_->GetBoundsByIndex(i); 995 const gfx::Rect& bounds1 = test_api_->GetBoundsByIndex(i);
996 const gfx::Rect& bounds2 = test_api_->GetBoundsByIndex(i + 1); 996 const gfx::Rect& bounds2 = test_api_->GetBoundsByIndex(i + 1);
997 EXPECT_FALSE(bounds1.Intersects(bounds2)); 997 EXPECT_FALSE(bounds1.Intersects(bounds2));
998 } 998 }
999 } 999 }
1000 } 1000 }
1001 1001
1002 // Making sure the overflow bubble arrow correctly tracks with shelf position. 1002 // Making sure the overflow bubble arrow correctly tracks with shelf position.
1003 TEST_P(ShelfViewTextDirectionTest, OverflowArrowForShelfPosition) { 1003 TEST_P(ShelfViewTextDirectionTest, OverflowArrowForShelfPosition) {
1004 const wm::ShelfAlignment kAlignments[] = { 1004 const ShelfAlignment kAlignments[] = {
1005 wm::SHELF_ALIGNMENT_BOTTOM, wm::SHELF_ALIGNMENT_LEFT, 1005 SHELF_ALIGNMENT_BOTTOM, SHELF_ALIGNMENT_LEFT, SHELF_ALIGNMENT_RIGHT,
1006 wm::SHELF_ALIGNMENT_RIGHT, wm::SHELF_ALIGNMENT_BOTTOM_LOCKED, 1006 SHELF_ALIGNMENT_BOTTOM_LOCKED,
1007 }; 1007 };
1008 1008
1009 // These must match what is expected for each alignment above. 1009 // These must match what is expected for each alignment above.
1010 const views::BubbleBorder::Arrow kArrows[] = { 1010 const views::BubbleBorder::Arrow kArrows[] = {
1011 views::BubbleBorder::BOTTOM_LEFT, views::BubbleBorder::LEFT_TOP, 1011 views::BubbleBorder::BOTTOM_LEFT, views::BubbleBorder::LEFT_TOP,
1012 views::BubbleBorder::RIGHT_TOP, views::BubbleBorder::BOTTOM_LEFT, 1012 views::BubbleBorder::RIGHT_TOP, views::BubbleBorder::BOTTOM_LEFT,
1013 }; 1013 };
1014 1014
1015 for (size_t i = 0; i < arraysize(kAlignments); i++) { 1015 for (size_t i = 0; i < arraysize(kAlignments); i++) {
1016 shelf_view_->shelf()->SetAlignment(kAlignments[i]); 1016 shelf_view_->shelf()->SetAlignment(kAlignments[i]);
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 // Spawn a tooltip on that item. 1423 // Spawn a tooltip on that item.
1424 tooltip_manager->ShowTooltip(app_button); 1424 tooltip_manager->ShowTooltip(app_button);
1425 EXPECT_TRUE(tooltip_manager->IsVisible()); 1425 EXPECT_TRUE(tooltip_manager->IsVisible());
1426 1426
1427 // Remove the app shortcut while the tooltip is open. The tooltip should be 1427 // Remove the app shortcut while the tooltip is open. The tooltip should be
1428 // closed. 1428 // closed.
1429 RemoveByID(app_button_id); 1429 RemoveByID(app_button_id);
1430 EXPECT_FALSE(tooltip_manager->IsVisible()); 1430 EXPECT_FALSE(tooltip_manager->IsVisible());
1431 1431
1432 // Change the shelf layout. This should not crash. 1432 // Change the shelf layout. This should not crash.
1433 Shelf::ForPrimaryDisplay()->SetAlignment(wm::SHELF_ALIGNMENT_LEFT); 1433 Shelf::ForPrimaryDisplay()->SetAlignment(SHELF_ALIGNMENT_LEFT);
1434 } 1434 }
1435 1435
1436 // Changing the shelf alignment closes any open tooltip. 1436 // Changing the shelf alignment closes any open tooltip.
1437 TEST_F(ShelfViewTest, ShelfAlignmentClosesTooltip) { 1437 TEST_F(ShelfViewTest, ShelfAlignmentClosesTooltip) {
1438 ShelfTooltipManager* tooltip_manager = test_api_->tooltip_manager(); 1438 ShelfTooltipManager* tooltip_manager = test_api_->tooltip_manager();
1439 1439
1440 // Add an item to the shelf. 1440 // Add an item to the shelf.
1441 ShelfID app_button_id = AddAppShortcut(); 1441 ShelfID app_button_id = AddAppShortcut();
1442 ShelfButton* app_button = GetButtonByID(app_button_id); 1442 ShelfButton* app_button = GetButtonByID(app_button_id);
1443 1443
1444 // Spawn a tooltip on the item. 1444 // Spawn a tooltip on the item.
1445 tooltip_manager->ShowTooltip(app_button); 1445 tooltip_manager->ShowTooltip(app_button);
1446 EXPECT_TRUE(tooltip_manager->IsVisible()); 1446 EXPECT_TRUE(tooltip_manager->IsVisible());
1447 1447
1448 // Changing shelf alignment hides the tooltip. 1448 // Changing shelf alignment hides the tooltip.
1449 Shelf::ForPrimaryDisplay()->SetAlignment(wm::SHELF_ALIGNMENT_LEFT); 1449 Shelf::ForPrimaryDisplay()->SetAlignment(SHELF_ALIGNMENT_LEFT);
1450 EXPECT_FALSE(tooltip_manager->IsVisible()); 1450 EXPECT_FALSE(tooltip_manager->IsVisible());
1451 } 1451 }
1452 1452
1453 TEST_F(ShelfViewTest, ShouldHideTooltipTest) { 1453 TEST_F(ShelfViewTest, ShouldHideTooltipTest) {
1454 ShelfID app_button_id = AddAppShortcut(); 1454 ShelfID app_button_id = AddAppShortcut();
1455 ShelfID platform_button_id = AddPlatformApp(); 1455 ShelfID platform_button_id = AddPlatformApp();
1456 1456
1457 // The tooltip shouldn't hide if the mouse is on normal buttons. 1457 // The tooltip shouldn't hide if the mouse is on normal buttons.
1458 for (int i = 0; i < test_api_->GetButtonCount(); i++) { 1458 for (int i = 0; i < test_api_->GetButtonCount(); i++) {
1459 ShelfButton* button = test_api_->GetButton(i); 1459 ShelfButton* button = test_api_->GetButton(i);
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1780 // win8-aura doesn't support multiple display. 1780 // win8-aura doesn't support multiple display.
1781 if (!SupportsMultipleDisplays()) 1781 if (!SupportsMultipleDisplays())
1782 return; 1782 return;
1783 1783
1784 UpdateDisplay("800x600,800x600"); 1784 UpdateDisplay("800x600,800x600");
1785 ASSERT_EQ(2U, Shell::GetAllRootWindows().size()); 1785 ASSERT_EQ(2U, Shell::GetAllRootWindows().size());
1786 1786
1787 aura::Window* second_root = Shell::GetAllRootWindows()[1]; 1787 aura::Window* second_root = Shell::GetAllRootWindows()[1];
1788 Shelf* secondary_shelf = Shelf::ForWindow(second_root); 1788 Shelf* secondary_shelf = Shelf::ForWindow(second_root);
1789 1789
1790 secondary_shelf->SetAlignment(wm::SHELF_ALIGNMENT_LEFT); 1790 secondary_shelf->SetAlignment(SHELF_ALIGNMENT_LEFT);
1791 ASSERT_EQ(wm::SHELF_ALIGNMENT_LEFT, secondary_shelf->alignment()); 1791 ASSERT_EQ(SHELF_ALIGNMENT_LEFT, secondary_shelf->alignment());
1792 1792
1793 // Initially, app list and browser shortcut are added. 1793 // Initially, app list and browser shortcut are added.
1794 EXPECT_EQ(2, model_->item_count()); 1794 EXPECT_EQ(2, model_->item_count());
1795 int browser_index = model_->GetItemIndexForType(TYPE_BROWSER_SHORTCUT); 1795 int browser_index = model_->GetItemIndexForType(TYPE_BROWSER_SHORTCUT);
1796 EXPECT_GT(browser_index, 0); 1796 EXPECT_GT(browser_index, 0);
1797 1797
1798 ShelfView* shelf_view_for_secondary = 1798 ShelfView* shelf_view_for_secondary =
1799 ShelfTestAPI(secondary_shelf).shelf_view(); 1799 ShelfTestAPI(secondary_shelf).shelf_view();
1800 1800
1801 ShelfViewTestAPI test_api_for_secondary_shelf_view(shelf_view_for_secondary); 1801 ShelfViewTestAPI test_api_for_secondary_shelf_view(shelf_view_for_secondary);
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1982 test_api_->RunMessageLoopUntilAnimationsDone(); 1982 test_api_->RunMessageLoopUntilAnimationsDone();
1983 CheckAllItemsAreInBounds(); 1983 CheckAllItemsAreInBounds();
1984 } 1984 }
1985 1985
1986 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool()); 1986 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool());
1987 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest, 1987 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest,
1988 testing::Bool()); 1988 testing::Bool());
1989 1989
1990 } // namespace test 1990 } // namespace test
1991 } // namespace ash 1991 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_view.cc ('k') | ash/shelf/shelf_widget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698