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 2696073002: Merge ShelfItemDelegate::ItemSelected & LauncherItemDelegate::Activate. (Closed)
Patch Set: Cleanup Created 3 years, 10 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 ShelfItemSelectionTracker() 141 ShelfItemSelectionTracker()
142 : TestShelfItemDelegate(NULL), 142 : TestShelfItemDelegate(NULL),
143 selected_(false), 143 selected_(false),
144 item_selected_action_(kNoAction) {} 144 item_selected_action_(kNoAction) {}
145 145
146 ~ShelfItemSelectionTracker() override {} 146 ~ShelfItemSelectionTracker() override {}
147 147
148 // Resets to the initial state. 148 // Resets to the initial state.
149 void Reset() { selected_ = false; } 149 void Reset() { selected_ = false; }
150 150
151 void set_item_selected_action( 151 void set_item_selected_action(ShelfAction item_selected_action) {
152 ShelfItemDelegate::PerformedAction item_selected_action) {
153 item_selected_action_ = item_selected_action; 152 item_selected_action_ = item_selected_action;
154 } 153 }
155 154
156 // Returns true if the delegate was selected. 155 // Returns true if the delegate was selected.
157 bool WasSelected() { return selected_; } 156 bool WasSelected() { return selected_; }
158 157
159 // TestShelfItemDelegate: 158 // TestShelfItemDelegate:
160 ShelfItemDelegate::PerformedAction ItemSelected( 159 ShelfAction ItemSelected(ui::EventType event_type,
161 const ui::Event& event) override { 160 int event_flags,
161 int64_t display_id,
162 ShelfLaunchSource source) override {
162 selected_ = true; 163 selected_ = true;
163 return item_selected_action_; 164 return item_selected_action_;
164 } 165 }
165 166
166 private: 167 private:
167 bool selected_; 168 bool selected_;
168 169
169 // The action returned from ItemSelected(const ui::Event&). 170 // The action returned from ItemSelected(const ui::Event&).
170 ShelfItemDelegate::PerformedAction item_selected_action_; 171 ShelfAction item_selected_action_;
171 172
172 DISALLOW_COPY_AND_ASSIGN(ShelfItemSelectionTracker); 173 DISALLOW_COPY_AND_ASSIGN(ShelfItemSelectionTracker);
173 }; 174 };
174 175
175 TEST_F(WmShelfObserverIconTest, AddRemove) { 176 TEST_F(WmShelfObserverIconTest, AddRemove) {
176 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 177 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
177 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 178 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
178 params.bounds = gfx::Rect(0, 0, 200, 200); 179 params.bounds = gfx::Rect(0, 0, 200, 200);
179 params.context = CurrentContext(); 180 params.context = CurrentContext();
180 views::Widget widget; 181 views::Widget widget;
(...skipping 1640 matching lines...) Expand 10 before | Expand all | Expand 10 after
1821 user_action_tester.GetActionCount("Launcher_ButtonPressed_Mouse")); 1822 user_action_tester.GetActionCount("Launcher_ButtonPressed_Mouse"));
1822 } 1823 }
1823 1824
1824 // Verifies that Launcher_*Task UMA user actions are recorded when an item is 1825 // Verifies that Launcher_*Task UMA user actions are recorded when an item is
1825 // selected. 1826 // selected.
1826 TEST_F(ShelfViewTest, Launcher_TaskUserActionsRecordedWhenItemSelected) { 1827 TEST_F(ShelfViewTest, Launcher_TaskUserActionsRecordedWhenItemSelected) {
1827 base::UserActionTester user_action_tester; 1828 base::UserActionTester user_action_tester;
1828 1829
1829 ShelfID browser_shelf_id = model_->items()[browser_index_].id; 1830 ShelfID browser_shelf_id = model_->items()[browser_index_].id;
1830 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker; 1831 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker;
1831 selection_tracker->set_item_selected_action( 1832 selection_tracker->set_item_selected_action(kNewWindowCreated);
1832 ShelfItemDelegate::kNewWindowCreated);
1833 model_->SetShelfItemDelegate( 1833 model_->SetShelfItemDelegate(
1834 browser_shelf_id, std::unique_ptr<ShelfItemDelegate>(selection_tracker)); 1834 browser_shelf_id, std::unique_ptr<ShelfItemDelegate>(selection_tracker));
1835 1835
1836 SimulateClick(browser_index_); 1836 SimulateClick(browser_index_);
1837 EXPECT_EQ(1, user_action_tester.GetActionCount("Launcher_LaunchTask")); 1837 EXPECT_EQ(1, user_action_tester.GetActionCount("Launcher_LaunchTask"));
1838 } 1838 }
1839 1839
1840 // Verifies that metrics are recorded when an item is minimized and subsequently 1840 // Verifies that metrics are recorded when an item is minimized and subsequently
1841 // activated. 1841 // activated.
1842 TEST_F(ShelfViewTest, 1842 TEST_F(ShelfViewTest,
1843 VerifyMetricsAreRecordedWhenAnItemIsMinimizedAndActivated) { 1843 VerifyMetricsAreRecordedWhenAnItemIsMinimizedAndActivated) {
1844 base::HistogramTester histogram_tester; 1844 base::HistogramTester histogram_tester;
1845 1845
1846 ShelfID browser_shelf_id = model_->items()[browser_index_].id; 1846 ShelfID browser_shelf_id = model_->items()[browser_index_].id;
1847 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker; 1847 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker;
1848 model_->SetShelfItemDelegate( 1848 model_->SetShelfItemDelegate(
1849 browser_shelf_id, std::unique_ptr<ShelfItemDelegate>(selection_tracker)); 1849 browser_shelf_id, std::unique_ptr<ShelfItemDelegate>(selection_tracker));
1850 1850
1851 selection_tracker->set_item_selected_action( 1851 selection_tracker->set_item_selected_action(kExistingWindowMinimized);
1852 ShelfItemDelegate::kExistingWindowMinimized);
1853 SimulateClick(browser_index_); 1852 SimulateClick(browser_index_);
1854 1853
1855 selection_tracker->set_item_selected_action( 1854 selection_tracker->set_item_selected_action(kExistingWindowActivated);
1856 ShelfItemDelegate::kExistingWindowActivated);
1857 SimulateClick(browser_index_); 1855 SimulateClick(browser_index_);
1858 1856
1859 histogram_tester.ExpectTotalCount( 1857 histogram_tester.ExpectTotalCount(
1860 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName, 1); 1858 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName, 1);
1861 } 1859 }
1862 1860
1863 class ShelfViewVisibleBoundsTest : public ShelfViewTest, 1861 class ShelfViewVisibleBoundsTest : public ShelfViewTest,
1864 public testing::WithParamInterface<bool> { 1862 public testing::WithParamInterface<bool> {
1865 public: 1863 public:
1866 ShelfViewVisibleBoundsTest() : text_direction_change_(GetParam()) {} 1864 ShelfViewVisibleBoundsTest() : text_direction_change_(GetParam()) {}
(...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after
2970 EXPECT_EQ(views::InkDropState::ACTIVATED, 2968 EXPECT_EQ(views::InkDropState::ACTIVATED,
2971 overflow_button_ink_drop_->GetTargetInkDropState()); 2969 overflow_button_ink_drop_->GetTargetInkDropState());
2972 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(), 2970 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
2973 IsEmpty()); 2971 IsEmpty());
2974 2972
2975 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); 2973 ASSERT_TRUE(test_api_->IsShowingOverflowBubble());
2976 } 2974 }
2977 2975
2978 } // namespace test 2976 } // namespace test
2979 } // namespace ash 2977 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698