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

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

Issue 1097393002: Added Launcher_SwitchTask UMA user action. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « ash/shelf/shelf_view.cc ('k') | ash/test/shelf_view_test_api.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 <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 16 matching lines...) Expand all
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"
30 #include "ash/test/shell_test_api.h" 30 #include "ash/test/shell_test_api.h"
31 #include "ash/test/test_shelf_delegate.h" 31 #include "ash/test/test_shelf_delegate.h"
32 #include "ash/test/test_shelf_item_delegate.h" 32 #include "ash/test/test_shelf_item_delegate.h"
33 #include "base/basictypes.h" 33 #include "base/basictypes.h"
34 #include "base/compiler_specific.h" 34 #include "base/compiler_specific.h"
35 #include "base/memory/scoped_ptr.h" 35 #include "base/memory/scoped_ptr.h"
36 #include "base/strings/string_number_conversions.h" 36 #include "base/strings/string_number_conversions.h"
37 #include "base/test/user_action_tester.h"
38 #include "base/time/time.h"
37 #include "ui/aura/test/aura_test_base.h" 39 #include "ui/aura/test/aura_test_base.h"
38 #include "ui/aura/window.h" 40 #include "ui/aura/window.h"
39 #include "ui/aura/window_event_dispatcher.h" 41 #include "ui/aura/window_event_dispatcher.h"
40 #include "ui/base/l10n/l10n_util.h" 42 #include "ui/base/l10n/l10n_util.h"
41 #include "ui/compositor/layer.h" 43 #include "ui/compositor/layer.h"
42 #include "ui/events/event.h" 44 #include "ui/events/event.h"
43 #include "ui/events/event_constants.h" 45 #include "ui/events/event_constants.h"
44 #include "ui/events/event_utils.h" 46 #include "ui/events/event_utils.h"
45 #include "ui/events/test/event_generator.h" 47 #include "ui/events/test/event_generator.h"
48 #include "ui/gfx/geometry/point.h"
46 #include "ui/views/view_model.h" 49 #include "ui/views/view_model.h"
47 #include "ui/views/widget/widget.h" 50 #include "ui/views/widget/widget.h"
48 #include "ui/views/widget/widget_delegate.h" 51 #include "ui/views/widget/widget_delegate.h"
49 #include "ui/wm/core/coordinate_conversion.h" 52 #include "ui/wm/core/coordinate_conversion.h"
50 53
51 namespace ash { 54 namespace ash {
52 namespace test { 55 namespace test {
53 56
54 //////////////////////////////////////////////////////////////////////////////// 57 ////////////////////////////////////////////////////////////////////////////////
55 // ShelfIconObserver tests. 58 // ShelfIconObserver tests.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 private: 117 private:
115 scoped_ptr<TestShelfIconObserver> observer_; 118 scoped_ptr<TestShelfIconObserver> observer_;
116 scoped_ptr<ShelfViewTestAPI> shelf_view_test_; 119 scoped_ptr<ShelfViewTestAPI> shelf_view_test_;
117 120
118 DISALLOW_COPY_AND_ASSIGN(ShelfViewIconObserverTest); 121 DISALLOW_COPY_AND_ASSIGN(ShelfViewIconObserverTest);
119 }; 122 };
120 123
121 // TestShelfItemDelegate which tracks whether it gets selected. 124 // TestShelfItemDelegate which tracks whether it gets selected.
122 class ShelfItemSelectionTracker : public TestShelfItemDelegate { 125 class ShelfItemSelectionTracker : public TestShelfItemDelegate {
123 public: 126 public:
124 ShelfItemSelectionTracker() : TestShelfItemDelegate(NULL), selected_(false) { 127 ShelfItemSelectionTracker()
125 } 128 : TestShelfItemDelegate(NULL),
129 selected_(false),
130 item_selected_action_(kNoAction) {}
126 131
127 ~ShelfItemSelectionTracker() override {} 132 ~ShelfItemSelectionTracker() override {}
128 133
129 // Resets to the initial state. 134 // Resets to the initial state.
130 void Reset() { selected_ = false; } 135 void Reset() { selected_ = false; }
131 136
137 void set_item_selected_action(
138 ShelfItemDelegate::PerformedAction item_selected_action) {
139 item_selected_action_ = item_selected_action;
140 }
141
132 // Returns true if the delegate was selected. 142 // Returns true if the delegate was selected.
133 bool WasSelected() { 143 bool WasSelected() {
134 return selected_; 144 return selected_;
135 } 145 }
136 146
137 // TestShelfItemDelegate: 147 // TestShelfItemDelegate:
138 ShelfItemDelegate::PerformedAction ItemSelected( 148 ShelfItemDelegate::PerformedAction ItemSelected(
139 const ui::Event& event) override { 149 const ui::Event& event) override {
140 selected_ = true; 150 selected_ = true;
141 return kNoAction; 151 return item_selected_action_;
142 } 152 }
143 153
144 private: 154 private:
145 bool selected_; 155 bool selected_;
146 156
157 // The action returned from ItemSelected(const ui::Event&).
158 ShelfItemDelegate::PerformedAction item_selected_action_;
159
147 DISALLOW_COPY_AND_ASSIGN(ShelfItemSelectionTracker); 160 DISALLOW_COPY_AND_ASSIGN(ShelfItemSelectionTracker);
148 }; 161 };
149 162
150 TEST_F(ShelfViewIconObserverTest, AddRemove) { 163 TEST_F(ShelfViewIconObserverTest, AddRemove) {
151 TestShelfDelegate* shelf_delegate = TestShelfDelegate::instance(); 164 TestShelfDelegate* shelf_delegate = TestShelfDelegate::instance();
152 ASSERT_TRUE(shelf_delegate); 165 ASSERT_TRUE(shelf_delegate);
153 166
154 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 167 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
155 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 168 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
156 params.bounds = gfx::Rect(0, 0, 200, 200); 169 params.bounds = gfx::Rect(0, 0, 200, 200);
(...skipping 1598 matching lines...) Expand 10 before | Expand all | Expand 10 after
1755 GetBoundsInScreen().CenterPoint().y()); 1768 GetBoundsInScreen().CenterPoint().y());
1756 generator.MoveTouch(moved_point); 1769 generator.MoveTouch(moved_point);
1757 EXPECT_FALSE(app_list_button->draw_background_as_active()); 1770 EXPECT_FALSE(app_list_button->draw_background_as_active());
1758 1771
1759 generator.set_current_location(moved_point); 1772 generator.set_current_location(moved_point);
1760 generator.ReleaseTouch(); 1773 generator.ReleaseTouch();
1761 EXPECT_FALSE(app_list_button->draw_background_as_active()); 1774 EXPECT_FALSE(app_list_button->draw_background_as_active());
1762 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility()); 1775 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility());
1763 } 1776 }
1764 1777
1778 // Verifies that Launcher_ButtonPressed_* UMA user actions are recorded when an
1779 // item is selected.
1780 TEST_F(ShelfViewTest,
1781 Launcher_ButtonPressedUserActionsRecordedWhenItemSelected) {
1782 base::UserActionTester user_action_tester;
1783
1784 ShelfID browser_shelf_id = model_->items()[browser_index_].id;
1785 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker;
1786 item_manager_->SetShelfItemDelegate(
1787 browser_shelf_id,
1788 scoped_ptr<ShelfItemDelegate>(selection_tracker).Pass());
1789
1790 SimulateClick(browser_index_);
1791 EXPECT_EQ(1,
1792 user_action_tester.GetActionCount("Launcher_ButtonPressed_Mouse"));
1793 }
1794
1795 // Verifies that Launcher_*Task UMA user actions are recorded when an item is
1796 // selected.
1797 TEST_F(ShelfViewTest, Launcher_TaskUserActionsRecordedWhenItemSelected) {
1798 base::UserActionTester user_action_tester;
1799
1800 ShelfID browser_shelf_id = model_->items()[browser_index_].id;
1801 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker;
1802 selection_tracker->set_item_selected_action(
1803 ShelfItemDelegate::kNewWindowCreated);
1804 item_manager_->SetShelfItemDelegate(
1805 browser_shelf_id,
1806 scoped_ptr<ShelfItemDelegate>(selection_tracker).Pass());
1807
1808 SimulateClick(browser_index_);
1809 EXPECT_EQ(1, user_action_tester.GetActionCount("Launcher_LaunchTask"));
1810 }
1811
1812 // Verifies that a Launcher_ButtonPressed_Mouse UMA user action is recorded when
1813 // an icon is activated by a mouse event.
1814 TEST_F(ShelfViewTest,
1815 Launcher_ButtonPressed_MouseIsRecordedWhenIconActivatedByMouse) {
1816 base::UserActionTester user_action_tester;
1817 ui::MouseEvent mouse_event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
1818 base::TimeDelta(), 0, 0);
1819 test_api_->RecordIconActivatedSource(mouse_event);
1820 EXPECT_EQ(1,
1821 user_action_tester.GetActionCount("Launcher_ButtonPressed_Mouse"));
1822 }
1823
1824 // Verifies that a Launcher_ButtonPressed_Touch UMA user action is recorded when
1825 // an icon is activated by a touch event.
1826 TEST_F(ShelfViewTest,
1827 Launcher_ButtonPressed_MouseIsRecordedWhenIconActivatedByTouch) {
1828 base::UserActionTester user_action_tester;
1829 ui::TouchEvent touch_event(ui::ET_GESTURE_TAP, gfx::Point(), 0,
1830 base::TimeDelta());
1831 test_api_->RecordIconActivatedSource(touch_event);
1832 EXPECT_EQ(1,
1833 user_action_tester.GetActionCount("Launcher_ButtonPressed_Touch"));
1834 }
1835
1836 // Verifies that a Launcher_LaunchTask UMA user action is recorded when
1837 // selecting an icon causes a new window to be created.
1838 TEST_F(ShelfViewTest, Launcher_LaunchTaskIsRecordedWhenNewWindowIsCreated) {
1839 base::UserActionTester user_action_tester;
1840 test_api_->RecordIconActivatedAction(ShelfItemDelegate::kNewWindowCreated);
1841 EXPECT_EQ(1, user_action_tester.GetActionCount("Launcher_LaunchTask"));
1842 }
1843
1844 // Verifies that a Launcher_SwitchTask UMA user action is recorded when
1845 // selecting an icon causes an existing window to be activated.
1846 TEST_F(ShelfViewTest,
1847 Launcher_SwitchTaskIsRecordedWhenExistingWindowIsActivated) {
1848 base::UserActionTester user_action_tester;
1849 test_api_->RecordIconActivatedAction(
1850 ShelfItemDelegate::kExistingWindowActivated);
1851 EXPECT_EQ(1, user_action_tester.GetActionCount("Launcher_SwitchTask"));
1852 }
1853
1765 class ShelfViewVisibleBoundsTest : public ShelfViewTest, 1854 class ShelfViewVisibleBoundsTest : public ShelfViewTest,
1766 public testing::WithParamInterface<bool> { 1855 public testing::WithParamInterface<bool> {
1767 public: 1856 public:
1768 ShelfViewVisibleBoundsTest() : text_direction_change_(GetParam()) {} 1857 ShelfViewVisibleBoundsTest() : text_direction_change_(GetParam()) {}
1769 1858
1770 void CheckAllItemsAreInBounds() { 1859 void CheckAllItemsAreInBounds() {
1771 gfx::Rect visible_bounds = shelf_view_->GetVisibleItemsBoundsInScreen(); 1860 gfx::Rect visible_bounds = shelf_view_->GetVisibleItemsBoundsInScreen();
1772 gfx::Rect shelf_bounds = shelf_view_->GetBoundsInScreen(); 1861 gfx::Rect shelf_bounds = shelf_view_->GetBoundsInScreen();
1773 EXPECT_TRUE(shelf_bounds.Contains(visible_bounds)); 1862 EXPECT_TRUE(shelf_bounds.Contains(visible_bounds));
1774 for (int i = 0; i < test_api_->GetButtonCount(); ++i) 1863 for (int i = 0; i < test_api_->GetButtonCount(); ++i)
(...skipping 30 matching lines...) Expand all
1805 test_api_->RunMessageLoopUntilAnimationsDone(); 1894 test_api_->RunMessageLoopUntilAnimationsDone();
1806 CheckAllItemsAreInBounds(); 1895 CheckAllItemsAreInBounds();
1807 } 1896 }
1808 1897
1809 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool()); 1898 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool());
1810 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest, 1899 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest,
1811 testing::Bool()); 1900 testing::Bool());
1812 1901
1813 } // namespace test 1902 } // namespace test
1814 } // namespace ash 1903 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_view.cc ('k') | ash/test/shelf_view_test_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698