| 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/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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 void Reset() { selected_ = false; } | 148 void Reset() { selected_ = false; } |
| 149 | 149 |
| 150 void set_item_selected_action(ShelfAction item_selected_action) { | 150 void set_item_selected_action(ShelfAction item_selected_action) { |
| 151 item_selected_action_ = item_selected_action; | 151 item_selected_action_ = item_selected_action; |
| 152 } | 152 } |
| 153 | 153 |
| 154 // Returns true if the delegate was selected. | 154 // Returns true if the delegate was selected. |
| 155 bool WasSelected() { return selected_; } | 155 bool WasSelected() { return selected_; } |
| 156 | 156 |
| 157 // TestShelfItemDelegate: | 157 // TestShelfItemDelegate: |
| 158 ShelfAction ItemSelected(ui::EventType event_type, | 158 void ItemSelected(std::unique_ptr<ui::Event> event, |
| 159 int event_flags, | 159 int64_t display_id, |
| 160 int64_t display_id, | 160 ShelfLaunchSource source, |
| 161 ShelfLaunchSource source) override { | 161 const ItemSelectedCallback& callback) override { |
| 162 selected_ = true; | 162 selected_ = true; |
| 163 return item_selected_action_; | 163 callback.Run(item_selected_action_, std::vector<mojom::MenuItemPtr>()); |
| 164 } | 164 } |
| 165 | 165 |
| 166 private: | 166 private: |
| 167 bool selected_; | 167 bool selected_; |
| 168 | 168 |
| 169 // The action returned from ItemSelected(const ui::Event&). | 169 // The action reported by ItemSelected. |
| 170 ShelfAction item_selected_action_; | 170 ShelfAction item_selected_action_; |
| 171 | 171 |
| 172 DISALLOW_COPY_AND_ASSIGN(ShelfItemSelectionTracker); | 172 DISALLOW_COPY_AND_ASSIGN(ShelfItemSelectionTracker); |
| 173 }; | 173 }; |
| 174 | 174 |
| 175 TEST_F(WmShelfObserverIconTest, AddRemove) { | 175 TEST_F(WmShelfObserverIconTest, AddRemove) { |
| 176 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 176 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 177 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 177 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 178 params.bounds = gfx::Rect(0, 0, 200, 200); | 178 params.bounds = gfx::Rect(0, 0, 200, 200); |
| 179 params.context = CurrentContext(); | 179 params.context = CurrentContext(); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 void TearDown() override { | 319 void TearDown() override { |
| 320 WebNotificationTray::DisableAnimationsForTest(false); // Reenable animation | 320 WebNotificationTray::DisableAnimationsForTest(false); // Reenable animation |
| 321 | 321 |
| 322 shelf_delegate_ = nullptr; | 322 shelf_delegate_ = nullptr; |
| 323 test_api_.reset(); | 323 test_api_.reset(); |
| 324 AshTestBase::TearDown(); | 324 AshTestBase::TearDown(); |
| 325 } | 325 } |
| 326 | 326 |
| 327 protected: | 327 protected: |
| 328 void CreateAndSetShelfItemDelegateForID(ShelfID id) { | 328 void CreateAndSetShelfItemDelegateForID(ShelfID id) { |
| 329 std::unique_ptr<ShelfItemDelegate> delegate( | 329 model_->SetShelfItemDelegate( |
| 330 new TestShelfItemDelegate(NULL)); | 330 id, base::MakeUnique<TestShelfItemDelegate>(nullptr)); |
| 331 model_->SetShelfItemDelegate(id, std::move(delegate)); | |
| 332 } | 331 } |
| 333 | 332 |
| 334 ShelfID AddBrowserShortcut() { | 333 ShelfID AddBrowserShortcut() { |
| 335 ShelfItem browser_shortcut; | 334 ShelfItem browser_shortcut; |
| 336 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; | 335 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; |
| 337 | 336 |
| 338 ShelfID id = model_->next_id(); | 337 ShelfID id = model_->next_id(); |
| 339 model_->AddAt(browser_index_, browser_shortcut); | 338 model_->AddAt(browser_index_, browser_shortcut); |
| 340 CreateAndSetShelfItemDelegateForID(id); | 339 CreateAndSetShelfItemDelegateForID(id); |
| 341 test_api_->RunMessageLoopUntilAnimationsDone(); | 340 test_api_->RunMessageLoopUntilAnimationsDone(); |
| (...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1223 shelf_view_->PointerReleasedOnButton(dragged_button, ShelfView::MOUSE, false); | 1222 shelf_view_->PointerReleasedOnButton(dragged_button, ShelfView::MOUSE, false); |
| 1224 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT); | 1223 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT); |
| 1225 } | 1224 } |
| 1226 | 1225 |
| 1227 // Tests that double-clicking an item does not activate it twice. | 1226 // Tests that double-clicking an item does not activate it twice. |
| 1228 TEST_F(ShelfViewTest, ClickingTwiceActivatesOnce) { | 1227 TEST_F(ShelfViewTest, ClickingTwiceActivatesOnce) { |
| 1229 // Watch for selection of the browser shortcut. | 1228 // Watch for selection of the browser shortcut. |
| 1230 ShelfID browser_shelf_id = model_->items()[browser_index_].id; | 1229 ShelfID browser_shelf_id = model_->items()[browser_index_].id; |
| 1231 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker; | 1230 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker; |
| 1232 model_->SetShelfItemDelegate( | 1231 model_->SetShelfItemDelegate( |
| 1233 browser_shelf_id, std::unique_ptr<ShelfItemDelegate>(selection_tracker)); | 1232 browser_shelf_id, |
| 1233 base::WrapUnique<ShelfItemSelectionTracker>(selection_tracker)); |
| 1234 | 1234 |
| 1235 // A single click selects the item. | 1235 // A single click selects the item. |
| 1236 SimulateClick(browser_index_); | 1236 SimulateClick(browser_index_); |
| 1237 EXPECT_TRUE(selection_tracker->WasSelected()); | 1237 EXPECT_TRUE(selection_tracker->WasSelected()); |
| 1238 | 1238 |
| 1239 // A double-click does not select the item. | 1239 // A double-click does not select the item. |
| 1240 selection_tracker->Reset(); | 1240 selection_tracker->Reset(); |
| 1241 SimulateDoubleClick(browser_index_); | 1241 SimulateDoubleClick(browser_index_); |
| 1242 EXPECT_FALSE(selection_tracker->WasSelected()); | 1242 EXPECT_FALSE(selection_tracker->WasSelected()); |
| 1243 } | 1243 } |
| 1244 | 1244 |
| 1245 // Check that clicking an item and jittering the mouse a bit still selects the | 1245 // Check that clicking an item and jittering the mouse a bit still selects the |
| 1246 // item. | 1246 // item. |
| 1247 TEST_F(ShelfViewTest, ClickAndMoveSlightly) { | 1247 TEST_F(ShelfViewTest, ClickAndMoveSlightly) { |
| 1248 std::vector<std::pair<ShelfID, views::View*>> id_map; | 1248 std::vector<std::pair<ShelfID, views::View*>> id_map; |
| 1249 SetupForDragTest(&id_map); | 1249 SetupForDragTest(&id_map); |
| 1250 | 1250 |
| 1251 ShelfID shelf_id = (id_map.begin() + 1)->first; | 1251 ShelfID shelf_id = (id_map.begin() + 1)->first; |
| 1252 views::View* button = (id_map.begin() + 1)->second; | 1252 views::View* button = (id_map.begin() + 1)->second; |
| 1253 | 1253 |
| 1254 // Replace the ShelfItemDelegate for |shelf_id| with one which tracks whether | 1254 // Replace the ShelfItemDelegate for |shelf_id| with one which tracks whether |
| 1255 // the shelf item gets selected. | 1255 // the shelf item gets selected. |
| 1256 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker; | 1256 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker; |
| 1257 model_->SetShelfItemDelegate( | 1257 model_->SetShelfItemDelegate( |
| 1258 shelf_id, std::unique_ptr<ShelfItemDelegate>(selection_tracker)); | 1258 shelf_id, base::WrapUnique<ShelfItemSelectionTracker>(selection_tracker)); |
| 1259 | 1259 |
| 1260 gfx::Vector2d press_offset(5, 30); | 1260 gfx::Vector2d press_offset(5, 30); |
| 1261 gfx::Point press_location = gfx::Point() + press_offset; | 1261 gfx::Point press_location = gfx::Point() + press_offset; |
| 1262 gfx::Point press_location_in_screen = | 1262 gfx::Point press_location_in_screen = |
| 1263 button->GetBoundsInScreen().origin() + press_offset; | 1263 button->GetBoundsInScreen().origin() + press_offset; |
| 1264 | 1264 |
| 1265 ui::MouseEvent click_event(ui::ET_MOUSE_PRESSED, press_location, | 1265 ui::MouseEvent click_event(ui::ET_MOUSE_PRESSED, press_location, |
| 1266 press_location_in_screen, ui::EventTimeForNow(), | 1266 press_location_in_screen, ui::EventTimeForNow(), |
| 1267 ui::EF_LEFT_MOUSE_BUTTON, 0); | 1267 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 1268 button->OnMousePressed(click_event); | 1268 button->OnMousePressed(click_event); |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1822 Launcher_ButtonPressedUserActionsRecordedWhenItemSelected) { | 1822 Launcher_ButtonPressedUserActionsRecordedWhenItemSelected) { |
| 1823 // TODO: investigate failure in mash, http://crbug.com/695751. | 1823 // TODO: investigate failure in mash, http://crbug.com/695751. |
| 1824 if (WmShell::Get()->IsRunningInMash()) | 1824 if (WmShell::Get()->IsRunningInMash()) |
| 1825 return; | 1825 return; |
| 1826 | 1826 |
| 1827 base::UserActionTester user_action_tester; | 1827 base::UserActionTester user_action_tester; |
| 1828 | 1828 |
| 1829 ShelfID browser_shelf_id = model_->items()[browser_index_].id; | 1829 ShelfID browser_shelf_id = model_->items()[browser_index_].id; |
| 1830 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker; | 1830 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker; |
| 1831 model_->SetShelfItemDelegate( | 1831 model_->SetShelfItemDelegate( |
| 1832 browser_shelf_id, std::unique_ptr<ShelfItemDelegate>(selection_tracker)); | 1832 browser_shelf_id, |
| 1833 base::WrapUnique<ShelfItemSelectionTracker>(selection_tracker)); |
| 1833 | 1834 |
| 1834 SimulateClick(browser_index_); | 1835 SimulateClick(browser_index_); |
| 1835 EXPECT_EQ(1, | 1836 EXPECT_EQ(1, |
| 1836 user_action_tester.GetActionCount("Launcher_ButtonPressed_Mouse")); | 1837 user_action_tester.GetActionCount("Launcher_ButtonPressed_Mouse")); |
| 1837 } | 1838 } |
| 1838 | 1839 |
| 1839 // Verifies that Launcher_*Task UMA user actions are recorded when an item is | 1840 // Verifies that Launcher_*Task UMA user actions are recorded when an item is |
| 1840 // selected. | 1841 // selected. |
| 1841 TEST_F(ShelfViewTest, Launcher_TaskUserActionsRecordedWhenItemSelected) { | 1842 TEST_F(ShelfViewTest, Launcher_TaskUserActionsRecordedWhenItemSelected) { |
| 1842 // TODO: investigate failure in mash, http://crbug.com/695751. | 1843 // TODO: investigate failure in mash, http://crbug.com/695751. |
| 1843 if (WmShell::Get()->IsRunningInMash()) | 1844 if (WmShell::Get()->IsRunningInMash()) |
| 1844 return; | 1845 return; |
| 1845 | 1846 |
| 1846 base::UserActionTester user_action_tester; | 1847 base::UserActionTester user_action_tester; |
| 1847 | 1848 |
| 1848 ShelfID browser_shelf_id = model_->items()[browser_index_].id; | 1849 ShelfID browser_shelf_id = model_->items()[browser_index_].id; |
| 1849 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker; | 1850 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker; |
| 1850 selection_tracker->set_item_selected_action(SHELF_ACTION_NEW_WINDOW_CREATED); | 1851 selection_tracker->set_item_selected_action(SHELF_ACTION_NEW_WINDOW_CREATED); |
| 1851 model_->SetShelfItemDelegate( | 1852 model_->SetShelfItemDelegate( |
| 1852 browser_shelf_id, std::unique_ptr<ShelfItemDelegate>(selection_tracker)); | 1853 browser_shelf_id, |
| 1854 base::WrapUnique<ShelfItemSelectionTracker>(selection_tracker)); |
| 1853 | 1855 |
| 1854 SimulateClick(browser_index_); | 1856 SimulateClick(browser_index_); |
| 1855 EXPECT_EQ(1, user_action_tester.GetActionCount("Launcher_LaunchTask")); | 1857 EXPECT_EQ(1, user_action_tester.GetActionCount("Launcher_LaunchTask")); |
| 1856 } | 1858 } |
| 1857 | 1859 |
| 1858 // Verifies that metrics are recorded when an item is minimized and subsequently | 1860 // Verifies that metrics are recorded when an item is minimized and subsequently |
| 1859 // activated. | 1861 // activated. |
| 1860 TEST_F(ShelfViewTest, | 1862 TEST_F(ShelfViewTest, |
| 1861 VerifyMetricsAreRecordedWhenAnItemIsMinimizedAndActivated) { | 1863 VerifyMetricsAreRecordedWhenAnItemIsMinimizedAndActivated) { |
| 1862 base::HistogramTester histogram_tester; | 1864 base::HistogramTester histogram_tester; |
| 1863 | 1865 |
| 1864 ShelfID browser_shelf_id = model_->items()[browser_index_].id; | 1866 ShelfID browser_shelf_id = model_->items()[browser_index_].id; |
| 1865 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker; | 1867 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker; |
| 1866 model_->SetShelfItemDelegate( | 1868 model_->SetShelfItemDelegate( |
| 1867 browser_shelf_id, std::unique_ptr<ShelfItemDelegate>(selection_tracker)); | 1869 browser_shelf_id, |
| 1870 base::WrapUnique<ShelfItemSelectionTracker>(selection_tracker)); |
| 1868 | 1871 |
| 1869 selection_tracker->set_item_selected_action(SHELF_ACTION_WINDOW_MINIMIZED); | 1872 selection_tracker->set_item_selected_action(SHELF_ACTION_WINDOW_MINIMIZED); |
| 1870 SimulateClick(browser_index_); | 1873 SimulateClick(browser_index_); |
| 1871 | 1874 |
| 1872 selection_tracker->set_item_selected_action(SHELF_ACTION_WINDOW_ACTIVATED); | 1875 selection_tracker->set_item_selected_action(SHELF_ACTION_WINDOW_ACTIVATED); |
| 1873 SimulateClick(browser_index_); | 1876 SimulateClick(browser_index_); |
| 1874 | 1877 |
| 1875 histogram_tester.ExpectTotalCount( | 1878 histogram_tester.ExpectTotalCount( |
| 1876 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName, 1); | 1879 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName, 1); |
| 1877 } | 1880 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1972 }; | 1975 }; |
| 1973 | 1976 |
| 1974 // A ShelfItemDelegate that returns a menu for the shelf item. | 1977 // A ShelfItemDelegate that returns a menu for the shelf item. |
| 1975 class ListMenuShelfItemDelegate : public TestShelfItemDelegate { | 1978 class ListMenuShelfItemDelegate : public TestShelfItemDelegate { |
| 1976 public: | 1979 public: |
| 1977 ListMenuShelfItemDelegate() : TestShelfItemDelegate(nullptr) {} | 1980 ListMenuShelfItemDelegate() : TestShelfItemDelegate(nullptr) {} |
| 1978 ~ListMenuShelfItemDelegate() override {} | 1981 ~ListMenuShelfItemDelegate() override {} |
| 1979 | 1982 |
| 1980 private: | 1983 private: |
| 1981 // TestShelfItemDelegate: | 1984 // TestShelfItemDelegate: |
| 1982 ShelfAppMenuItemList GetAppMenuItems(int event_flags) override { | 1985 void ItemSelected(std::unique_ptr<ui::Event> event, |
| 1983 ShelfAppMenuItemList items; | 1986 int64_t display_id, |
| 1984 base::string16 title = base::ASCIIToUTF16("title"); | 1987 ShelfLaunchSource source, |
| 1985 items.push_back(base::MakeUnique<ShelfApplicationMenuItem>(0, title)); | 1988 const ItemSelectedCallback& callback) override { |
| 1986 items.push_back(base::MakeUnique<ShelfApplicationMenuItem>(1, title)); | 1989 // Two items are needed to show a menu; the data in the items is not tested. |
| 1987 return items; | 1990 std::vector<mojom::MenuItemPtr> items; |
| 1991 items.push_back(ash::mojom::MenuItem::New()); |
| 1992 items.push_back(ash::mojom::MenuItem::New()); |
| 1993 callback.Run(ash::SHELF_ACTION_NONE, std::move(items)); |
| 1988 } | 1994 } |
| 1989 | 1995 |
| 1990 DISALLOW_COPY_AND_ASSIGN(ListMenuShelfItemDelegate); | 1996 DISALLOW_COPY_AND_ASSIGN(ListMenuShelfItemDelegate); |
| 1991 }; | 1997 }; |
| 1992 | 1998 |
| 1993 } // namespace | 1999 } // namespace |
| 1994 | 2000 |
| 1995 // Test fixture for testing material design ink drop ripples on shelf. | 2001 // Test fixture for testing material design ink drop ripples on shelf. |
| 1996 class ShelfViewInkDropTest : public ShelfViewTest { | 2002 class ShelfViewInkDropTest : public ShelfViewTest { |
| 1997 public: | 2003 public: |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2419 IsEmpty()); | 2425 IsEmpty()); |
| 2420 } | 2426 } |
| 2421 | 2427 |
| 2422 // Tests that clicking on a shelf item that shows an app list menu transitions | 2428 // Tests that clicking on a shelf item that shows an app list menu transitions |
| 2423 // ink drop state correctly. | 2429 // ink drop state correctly. |
| 2424 TEST_F(ShelfViewInkDropTest, ShelfButtonWithMenuPressRelease) { | 2430 TEST_F(ShelfViewInkDropTest, ShelfButtonWithMenuPressRelease) { |
| 2425 InitBrowserButtonInkDrop(); | 2431 InitBrowserButtonInkDrop(); |
| 2426 | 2432 |
| 2427 // Set a delegate for the shelf item that returns an app list menu. | 2433 // Set a delegate for the shelf item that returns an app list menu. |
| 2428 ShelfID browser_shelf_id = model_->items()[browser_index_].id; | 2434 ShelfID browser_shelf_id = model_->items()[browser_index_].id; |
| 2429 ListMenuShelfItemDelegate* list_menu_delegate = new ListMenuShelfItemDelegate; | |
| 2430 model_->SetShelfItemDelegate(browser_shelf_id, | 2435 model_->SetShelfItemDelegate(browser_shelf_id, |
| 2431 base::WrapUnique(list_menu_delegate)); | 2436 base::MakeUnique<ListMenuShelfItemDelegate>()); |
| 2432 | 2437 |
| 2433 views::CustomButton* button = browser_button_; | 2438 views::CustomButton* button = browser_button_; |
| 2434 gfx::Point mouse_location = button->GetLocalBounds().CenterPoint(); | 2439 gfx::Point mouse_location = button->GetLocalBounds().CenterPoint(); |
| 2435 | 2440 |
| 2436 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, mouse_location, | 2441 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, mouse_location, |
| 2437 mouse_location, ui::EventTimeForNow(), | 2442 mouse_location, ui::EventTimeForNow(), |
| 2438 ui::EF_LEFT_MOUSE_BUTTON, 0); | 2443 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 2439 button->OnMousePressed(press_event); | 2444 button->OnMousePressed(press_event); |
| 2440 EXPECT_EQ(views::InkDropState::ACTION_PENDING, | 2445 EXPECT_EQ(views::InkDropState::ACTION_PENDING, |
| 2441 browser_button_ink_drop_->GetTargetInkDropState()); | 2446 browser_button_ink_drop_->GetTargetInkDropState()); |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3007 EXPECT_EQ(views::InkDropState::ACTIVATED, | 3012 EXPECT_EQ(views::InkDropState::ACTIVATED, |
| 3008 overflow_button_ink_drop_->GetTargetInkDropState()); | 3013 overflow_button_ink_drop_->GetTargetInkDropState()); |
| 3009 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(), | 3014 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(), |
| 3010 IsEmpty()); | 3015 IsEmpty()); |
| 3011 | 3016 |
| 3012 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); | 3017 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); |
| 3013 } | 3018 } |
| 3014 | 3019 |
| 3015 } // namespace test | 3020 } // namespace test |
| 3016 } // namespace ash | 3021 } // namespace ash |
| OLD | NEW |