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

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

Issue 2807473003: Shelf: Hide overflow bubble when app launched from overflow. (Closed)
Patch Set: Created 3 years, 8 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
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/common/shelf/shelf_view.h" 5 #include "ash/common/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>
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 } 682 }
683 683
684 void ReplaceShelfDelegate() { 684 void ReplaceShelfDelegate() {
685 // Clear the value first to avoid TestShelfDelegate's singleton check. 685 // Clear the value first to avoid TestShelfDelegate's singleton check.
686 test::ShellTestApi().SetShelfDelegate(nullptr); 686 test::ShellTestApi().SetShelfDelegate(nullptr);
687 shelf_delegate_ = new TestShelfDelegateForShelfView(); 687 shelf_delegate_ = new TestShelfDelegateForShelfView();
688 test_api_->SetShelfDelegate(shelf_delegate_); 688 test_api_->SetShelfDelegate(shelf_delegate_);
689 test::ShellTestApi().SetShelfDelegate(base::WrapUnique(shelf_delegate_)); 689 test::ShellTestApi().SetShelfDelegate(base::WrapUnique(shelf_delegate_));
690 } 690 }
691 691
692 // Returns the center coordinates for a button. Helper function for an event
693 // generator.
694 gfx::Point GetButtonCenter(ShelfID button_id) {
695 return GetButtonCenter(
696 test_api_->GetButton(model_->ItemIndexByID(button_id)));
697 }
698
699 gfx::Point GetButtonCenter(ShelfButton* button) {
700 return button->GetBoundsInScreen().CenterPoint();
701 }
702
692 ShelfModel* model_; 703 ShelfModel* model_;
693 ShelfView* shelf_view_; 704 ShelfView* shelf_view_;
694 int browser_index_; 705 int browser_index_;
695 706
696 // Owned by ash::WmShell. 707 // Owned by ash::WmShell.
697 TestShelfDelegateForShelfView* shelf_delegate_; 708 TestShelfDelegateForShelfView* shelf_delegate_;
698 709
699 std::unique_ptr<ShelfViewTestAPI> test_api_; 710 std::unique_ptr<ShelfViewTestAPI> test_api_;
700 711
701 private: 712 private:
(...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1825 selection_tracker->set_item_selected_action(SHELF_ACTION_WINDOW_MINIMIZED); 1836 selection_tracker->set_item_selected_action(SHELF_ACTION_WINDOW_MINIMIZED);
1826 SimulateClick(browser_index_); 1837 SimulateClick(browser_index_);
1827 1838
1828 selection_tracker->set_item_selected_action(SHELF_ACTION_WINDOW_ACTIVATED); 1839 selection_tracker->set_item_selected_action(SHELF_ACTION_WINDOW_ACTIVATED);
1829 SimulateClick(browser_index_); 1840 SimulateClick(browser_index_);
1830 1841
1831 histogram_tester.ExpectTotalCount( 1842 histogram_tester.ExpectTotalCount(
1832 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName, 1); 1843 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName, 1);
1833 } 1844 }
1834 1845
1846 TEST_F(ShelfViewTest, TestHideOverflow) {
1847 // Use an event generator instead of SimulateClick because the overflow bubble
1848 // is a PointerWatcher and gets the events directly.
1849 ui::test::EventGenerator& generator = GetEventGenerator();
1850
1851 // Add one app (which is on the main shelf) and then add buttons until
1852 // overflow. Add two more apps (which are on the overflow shelf).
1853 ShelfID first_app_id = AddAppShortcut();
1854 AddButtonsUntilOverflow();
1855 ShelfID overflow_app_id1 = AddAppShortcut();
1856 ShelfID overflow_app_id2 = AddAppShortcut();
1857
1858 // Verify that by clicking anywhere outside the shelf and overflow bubble, the
1859 // overflow bubble will close if it were open.
1860 EXPECT_FALSE(test_api_->IsShowingOverflowBubble());
1861 test_api_->ShowOverflowBubble();
1862 const gfx::Point kPointNotOnShelfOrOverflow = gfx::Point(0, 0);
msw 2017/04/06 21:57:50 Remove this constant and skip set_current_location
sammiequon 2017/04/06 23:03:11 Done.
1863
1864 // Make sure the point we chose is not on the shelf or its overflow bubble.
1865 ASSERT_FALSE(test_api_->shelf_view()->GetBoundsInScreen().Contains(
1866 kPointNotOnShelfOrOverflow));
1867 ASSERT_FALSE(
1868 test_api_->overflow_bubble()->shelf_view()->GetBoundsInScreen().Contains(
1869 kPointNotOnShelfOrOverflow));
1870 generator.set_current_location(kPointNotOnShelfOrOverflow);
1871 generator.ClickLeftButton();
1872 EXPECT_FALSE(test_api_->IsShowingOverflowBubble());
1873
1874 // Verify that by clicking a app which is on the main shelf while the overflow
1875 // bubble is opened, the overflow bubble will close.
1876 EXPECT_FALSE(test_api_->IsShowingOverflowBubble());
1877 test_api_->ShowOverflowBubble();
1878 generator.set_current_location(GetButtonCenter(first_app_id));
1879 generator.ClickLeftButton();
1880 EXPECT_FALSE(test_api_->IsShowingOverflowBubble());
1881
1882 // Verify that by clicking a app which is on the overflow shelf, the overflow
1883 // bubble will close.
1884 EXPECT_FALSE(test_api_->IsShowingOverflowBubble());
1885 test_api_->ShowOverflowBubble();
1886 ShelfViewTestAPI test_api_for_overflow(
1887 test_api_->overflow_bubble()->shelf_view());
1888 ShelfButton* button_on_overflow_shelf =
1889 test_api_for_overflow.GetButton(model_->ItemIndexByID(overflow_app_id2));
1890 generator.set_current_location(GetButtonCenter(button_on_overflow_shelf));
1891 generator.ClickLeftButton();
1892 EXPECT_FALSE(test_api_->IsShowingOverflowBubble());
1893
1894 // Verify dragging apps on the overflow shelf does not close the overflow
1895 // bubble.
1896 EXPECT_FALSE(test_api_->IsShowingOverflowBubble());
1897 test_api_->ShowOverflowBubble();
1898 ShelfViewTestAPI test_api_for_overflow2(
msw 2017/04/06 21:57:50 optional nit: |test_api_for_overflow1|
sammiequon 2017/04/06 23:03:11 Done.
1899 test_api_->overflow_bubble()->shelf_view());
1900 ShelfButton* button_on_overflow_shelf1 =
1901 test_api_for_overflow2.GetButton(model_->ItemIndexByID(overflow_app_id1));
1902 ShelfButton* button_on_overflow_shelf2 =
1903 test_api_for_overflow2.GetButton(model_->ItemIndexByID(overflow_app_id2));
1904 generator.set_current_location(GetButtonCenter(button_on_overflow_shelf1));
1905 generator.DragMouseTo(GetButtonCenter(button_on_overflow_shelf2));
1906 EXPECT_TRUE(test_api_->IsShowingOverflowBubble());
1907 }
1908
1835 class ShelfViewVisibleBoundsTest : public ShelfViewTest, 1909 class ShelfViewVisibleBoundsTest : public ShelfViewTest,
1836 public testing::WithParamInterface<bool> { 1910 public testing::WithParamInterface<bool> {
1837 public: 1911 public:
1838 ShelfViewVisibleBoundsTest() : text_direction_change_(GetParam()) {} 1912 ShelfViewVisibleBoundsTest() : text_direction_change_(GetParam()) {}
1839 1913
1840 void CheckAllItemsAreInBounds() { 1914 void CheckAllItemsAreInBounds() {
1841 gfx::Rect visible_bounds = shelf_view_->GetVisibleItemsBoundsInScreen(); 1915 gfx::Rect visible_bounds = shelf_view_->GetVisibleItemsBoundsInScreen();
1842 gfx::Rect shelf_bounds = shelf_view_->GetBoundsInScreen(); 1916 gfx::Rect shelf_bounds = shelf_view_->GetBoundsInScreen();
1843 EXPECT_TRUE(shelf_bounds.Contains(visible_bounds)); 1917 EXPECT_TRUE(shelf_bounds.Contains(visible_bounds));
1844 for (int i = 0; i < test_api_->GetButtonCount(); ++i) 1918 for (int i = 0; i < test_api_->GetButtonCount(); ++i)
(...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after
3047 EXPECT_EQ(views::InkDropState::ACTIVATED, 3121 EXPECT_EQ(views::InkDropState::ACTIVATED,
3048 overflow_button_ink_drop_->GetTargetInkDropState()); 3122 overflow_button_ink_drop_->GetTargetInkDropState());
3049 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(), 3123 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
3050 IsEmpty()); 3124 IsEmpty());
3051 3125
3052 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); 3126 ASSERT_TRUE(test_api_->IsShowingOverflowBubble());
3053 } 3127 }
3054 3128
3055 } // namespace test 3129 } // namespace test
3056 } // namespace ash 3130 } // namespace ash
OLDNEW
« ash/common/shelf/shelf_view.cc ('K') | « ash/common/shelf/shelf_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698