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

Side by Side Diff: ash/system/tray/tray_details_view_unittest.cc

Issue 556383002: Status Panel Touch Feedback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restrict test to ChromeOS Created 6 years, 2 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/system/tray/system_tray_unittest.cc ('k') | ash/system/tray/tray_popup_item_container.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/system/tray/tray_details_view.h" 5 #include "ash/system/tray/tray_details_view.h"
6 6
7 #include "ash/root_window_controller.h" 7 #include "ash/root_window_controller.h"
8 #include "ash/shelf/shelf_widget.h" 8 #include "ash/shelf/shelf_widget.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/system/status_area_widget.h" 10 #include "ash/system/status_area_widget.h"
11 #include "ash/system/tray/hover_highlight_view.h"
12 #include "ash/system/tray/special_popup_row.h"
11 #include "ash/system/tray/system_tray.h" 13 #include "ash/system/tray/system_tray.h"
12 #include "ash/system/tray/system_tray_item.h" 14 #include "ash/system/tray/system_tray_item.h"
13 #include "ash/system/tray/tray_details_view.h" 15 #include "ash/system/tray/tray_details_view.h"
14 #include "ash/system/tray/view_click_listener.h" 16 #include "ash/system/tray/view_click_listener.h"
15 #include "ash/test/ash_test_base.h" 17 #include "ash/test/ash_test_base.h"
18 #include "base/command_line.h"
16 #include "base/run_loop.h" 19 #include "base/run_loop.h"
17 #include "grit/ash_strings.h" 20 #include "grit/ash_strings.h"
18 #include "ui/aura/window.h" 21 #include "ui/aura/window.h"
22 #include "ui/base/ui_base_switches.h"
23 #include "ui/events/test/event_generator.h"
19 #include "ui/views/view.h" 24 #include "ui/views/view.h"
20 #include "ui/views/widget/widget.h" 25 #include "ui/views/widget/widget.h"
21 26
22 namespace ash { 27 namespace ash {
23 namespace test { 28 namespace test {
24 29
25 namespace { 30 namespace {
26 31
27 SystemTray* GetSystemTray() { 32 SystemTray* GetSystemTray() {
28 return Shell::GetPrimaryRootWindowController()->shelf()-> 33 return Shell::GetPrimaryRootWindowController()->shelf()->
29 status_area_widget()->system_tray(); 34 status_area_widget()->system_tray();
30 } 35 }
31 36
32 class TestDetailsView : public TrayDetailsView, public ViewClickListener { 37 class TestDetailsView : public TrayDetailsView, public ViewClickListener {
33 public: 38 public:
34 explicit TestDetailsView(SystemTrayItem* owner) : TrayDetailsView(owner) {} 39 explicit TestDetailsView(SystemTrayItem* owner) : TrayDetailsView(owner) {
40 // Uses bluetooth label for testing purpose. It can be changed to any
41 // string_id.
42 CreateSpecialRow(IDS_ASH_STATUS_TRAY_BLUETOOTH, this);
43 }
35 44
36 virtual ~TestDetailsView() {} 45 virtual ~TestDetailsView() {}
37 46
38 void CreateFooterAndFocus() { 47 void FocusFooter() {
39 // Uses bluetooth label for testing purpose. It can be changed to any
40 // string_id.
41 CreateSpecialRow(IDS_ASH_STATUS_TRAY_BLUETOOTH, this);
42 footer()->content()->RequestFocus(); 48 footer()->content()->RequestFocus();
43 } 49 }
44 50
45 // Overridden from ViewClickListener: 51 // Overridden from ViewClickListener:
46 virtual void OnViewClicked(views::View* sender) override {} 52 virtual void OnViewClicked(views::View* sender) override {}
47 53
48 private: 54 private:
49 DISALLOW_COPY_AND_ASSIGN(TestDetailsView); 55 DISALLOW_COPY_AND_ASSIGN(TestDetailsView);
50 }; 56 };
51 57
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 private: 91 private:
86 views::View* tray_view_; 92 views::View* tray_view_;
87 views::View* default_view_; 93 views::View* default_view_;
88 TestDetailsView* detailed_view_; 94 TestDetailsView* detailed_view_;
89 95
90 DISALLOW_COPY_AND_ASSIGN(TestItem); 96 DISALLOW_COPY_AND_ASSIGN(TestItem);
91 }; 97 };
92 98
93 } // namespace 99 } // namespace
94 100
95 typedef AshTestBase TrayDetailsViewTest; 101 class TrayDetailsViewTest : public AshTestBase {
102 public:
103 TrayDetailsViewTest() {}
104 virtual ~TrayDetailsViewTest() {}
105
106 HoverHighlightView* CreateAndShowHoverHighlightView() {
107 SystemTray* tray = GetSystemTray();
108 TestItem* test_item = new TestItem;
109 tray->AddTrayItem(test_item);
110 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
111 RunAllPendingInMessageLoop();
112 tray->ShowDetailedView(test_item, 0, true, BUBBLE_USE_EXISTING);
113 RunAllPendingInMessageLoop();
114
115 return static_cast<HoverHighlightView*>(test_item->detailed_view()->
116 footer()->content());
117 }
118
119 virtual void SetUp() OVERRIDE {
120 CommandLine::ForCurrentProcess()->AppendSwitch(
121 switches::kEnableTouchFeedback);
122 test::AshTestBase::SetUp();
123 }
124
125 private:
126 DISALLOW_COPY_AND_ASSIGN(TrayDetailsViewTest);
127 };
96 128
97 TEST_F(TrayDetailsViewTest, TransitionToDefaultViewTest) { 129 TEST_F(TrayDetailsViewTest, TransitionToDefaultViewTest) {
98 SystemTray* tray = GetSystemTray(); 130 SystemTray* tray = GetSystemTray();
99 ASSERT_TRUE(tray->GetWidget()); 131 ASSERT_TRUE(tray->GetWidget());
100 132
101 TestItem* test_item_1 = new TestItem; 133 TestItem* test_item_1 = new TestItem;
102 TestItem* test_item_2 = new TestItem; 134 TestItem* test_item_2 = new TestItem;
103 tray->AddTrayItem(test_item_1); 135 tray->AddTrayItem(test_item_1);
104 tray->AddTrayItem(test_item_2); 136 tray->AddTrayItem(test_item_2);
105 137
106 // Ensure the tray views are created. 138 // Ensure the tray views are created.
107 ASSERT_TRUE(test_item_1->tray_view() != NULL); 139 ASSERT_TRUE(test_item_1->tray_view() != NULL);
108 ASSERT_TRUE(test_item_2->tray_view() != NULL); 140 ASSERT_TRUE(test_item_2->tray_view() != NULL);
109 141
110 // Show the default view. 142 // Show the default view.
111 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 143 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
112 RunAllPendingInMessageLoop(); 144 RunAllPendingInMessageLoop();
113 145
114 // Show the detailed view of item 2. 146 // Show the detailed view of item 2.
115 tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING); 147 tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING);
116 EXPECT_TRUE(test_item_2->detailed_view()); 148 EXPECT_TRUE(test_item_2->detailed_view());
117 RunAllPendingInMessageLoop(); 149 RunAllPendingInMessageLoop();
118 EXPECT_FALSE(test_item_2->default_view()); 150 EXPECT_FALSE(test_item_2->default_view());
119 151
120 // Transition back to default view, the default view of item 2 should have 152 // Transition back to default view, the default view of item 2 should have
121 // focus. 153 // focus.
122 test_item_2->detailed_view()->CreateFooterAndFocus(); 154 test_item_2->detailed_view()->FocusFooter();
123 test_item_2->detailed_view()->TransitionToDefaultView(); 155 test_item_2->detailed_view()->TransitionToDefaultView();
124 RunAllPendingInMessageLoop(); 156 RunAllPendingInMessageLoop();
125 157
126 EXPECT_TRUE(test_item_2->default_view()); 158 EXPECT_TRUE(test_item_2->default_view());
127 EXPECT_FALSE(test_item_2->detailed_view()); 159 EXPECT_FALSE(test_item_2->detailed_view());
128 EXPECT_TRUE(test_item_2->default_view()->HasFocus()); 160 EXPECT_TRUE(test_item_2->default_view()->HasFocus());
129 161
130 // Show the detailed view of item 2 again. 162 // Show the detailed view of item 2 again.
131 tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING); 163 tray->ShowDetailedView(test_item_2, 0, true, BUBBLE_USE_EXISTING);
132 EXPECT_TRUE(test_item_2->detailed_view()); 164 EXPECT_TRUE(test_item_2->detailed_view());
133 RunAllPendingInMessageLoop(); 165 RunAllPendingInMessageLoop();
134 EXPECT_FALSE(test_item_2->default_view()); 166 EXPECT_FALSE(test_item_2->default_view());
135 167
136 // Transition back to default view, the default view of item 2 should NOT have 168 // Transition back to default view, the default view of item 2 should NOT have
137 // focus. 169 // focus.
138 test_item_2->detailed_view()->TransitionToDefaultView(); 170 test_item_2->detailed_view()->TransitionToDefaultView();
139 RunAllPendingInMessageLoop(); 171 RunAllPendingInMessageLoop();
140 172
141 EXPECT_TRUE(test_item_2->default_view()); 173 EXPECT_TRUE(test_item_2->default_view());
142 EXPECT_FALSE(test_item_2->detailed_view()); 174 EXPECT_FALSE(test_item_2->detailed_view());
143 EXPECT_FALSE(test_item_2->default_view()->HasFocus()); 175 EXPECT_FALSE(test_item_2->default_view()->HasFocus());
144 } 176 }
145 177
178 // Tests that HoverHighlightView enters hover state in response to touch.
179 TEST_F(TrayDetailsViewTest, HoverHighlightViewTouchFeedback) {
180 HoverHighlightView* view = CreateAndShowHoverHighlightView();
181 EXPECT_FALSE(view->hover());
182
183 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
184 generator.set_current_location(view->GetBoundsInScreen().CenterPoint());
185 generator.PressTouch();
186 RunAllPendingInMessageLoop();
187 EXPECT_TRUE(view->hover());
188
189 generator.ReleaseTouch();
190 RunAllPendingInMessageLoop();
191 EXPECT_FALSE(view->hover());
192 }
193
194 // Tests that touch events leaving HoverHighlightView cancel the hover state.
195 TEST_F(TrayDetailsViewTest, HoverHighlightViewTouchFeedbackCancellation) {
196 HoverHighlightView* view = CreateAndShowHoverHighlightView();
197 EXPECT_FALSE(view->hover());
198
199 gfx::Rect view_bounds = view->GetBoundsInScreen();
200 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
201 generator.set_current_location(view_bounds.CenterPoint());
202 generator.PressTouch();
203 RunAllPendingInMessageLoop();
204 EXPECT_TRUE(view->hover());
205
206 gfx::Point move_point(view_bounds.x(), view_bounds.CenterPoint().y());
207 generator.MoveTouch(move_point);
208 RunAllPendingInMessageLoop();
209 EXPECT_FALSE(view->hover());
210
211 generator.set_current_location(move_point);
212 generator.ReleaseTouch();
213 RunAllPendingInMessageLoop();
214 EXPECT_FALSE(view->hover());
215 }
216
146 } // namespace test 217 } // namespace test
147 } // namespace ash 218 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray/system_tray_unittest.cc ('k') | ash/system/tray/tray_popup_item_container.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698