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

Side by Side Diff: ui/message_center/views/custom_notification_view_unittest.cc

Issue 2620133003: Set slide_out_enabled property for CustomNotification (Closed)
Patch Set: Fix the wrong term: vertical -> horizontal Created 3 years, 11 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 | « no previous file | ui/message_center/views/message_view.cc » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <memory> 5 #include <memory>
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "third_party/skia/include/core/SkColor.h" 11 #include "third_party/skia/include/core/SkColor.h"
12 #include "ui/events/event.h" 12 #include "ui/events/event.h"
13 #include "ui/events/event_utils.h" 13 #include "ui/events/event_utils.h"
14 #include "ui/message_center/notification.h" 14 #include "ui/message_center/notification.h"
15 #include "ui/message_center/notification_delegate.h" 15 #include "ui/message_center/notification_delegate.h"
16 #include "ui/message_center/views/custom_notification_view.h" 16 #include "ui/message_center/views/custom_notification_view.h"
17 #include "ui/message_center/views/message_center_controller.h" 17 #include "ui/message_center/views/message_center_controller.h"
18 #include "ui/message_center/views/message_view_factory.h" 18 #include "ui/message_center/views/message_view_factory.h"
19 #include "ui/views/background.h" 19 #include "ui/views/background.h"
20 #include "ui/views/controls/button/image_button.h" 20 #include "ui/views/controls/button/image_button.h"
21 #include "ui/views/test/views_test_base.h" 21 #include "ui/views/test/views_test_base.h"
22 22
23 namespace message_center { 23 namespace message_center {
24 24
25 namespace { 25 namespace {
26 26
27 const SkColor kBackgroundColor = SK_ColorGREEN; 27 const SkColor kBackgroundColor = SK_ColorGREEN;
28 28
29 std::unique_ptr<ui::GestureEvent> GenerateGestureEvent(ui::EventType type) {
30 ui::GestureEventDetails detail(type);
31 std::unique_ptr<ui::GestureEvent> event(
32 new ui::GestureEvent(0, 0, 0, base::TimeTicks(), detail));
33 return event;
34 }
35
36 std::unique_ptr<ui::GestureEvent> GenerateGestureHorizontalScrollUpdateEvent(
37 int dx) {
38 ui::GestureEventDetails detail(ui::ET_GESTURE_SCROLL_UPDATE, dx, 0);
39 std::unique_ptr<ui::GestureEvent> event(
40 new ui::GestureEvent(0, 0, 0, base::TimeTicks(), detail));
41 return event;
42 }
43
29 class TestCustomView : public views::View { 44 class TestCustomView : public views::View {
30 public: 45 public:
31 TestCustomView() { 46 TestCustomView() {
32 SetFocusBehavior(FocusBehavior::ALWAYS); 47 SetFocusBehavior(FocusBehavior::ALWAYS);
33 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); 48 set_background(views::Background::CreateSolidBackground(kBackgroundColor));
34 } 49 }
35 ~TestCustomView() override {} 50 ~TestCustomView() override {}
36 51
37 void Reset() { 52 void Reset() {
38 mouse_event_count_ = 0; 53 mouse_event_count_ = 0;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 ui::ET_MOUSE_RELEASED, point, point, ui::EventTimeForNow(), 204 ui::ET_MOUSE_RELEASED, point, point, ui::EventTimeForNow(),
190 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); 205 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
191 widget()->OnMouseEvent(&released_event); 206 widget()->OnMouseEvent(&released_event);
192 } 207 }
193 208
194 void KeyPress(ui::KeyboardCode key_code) { 209 void KeyPress(ui::KeyboardCode key_code) {
195 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE); 210 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE);
196 widget()->OnKeyEvent(&event); 211 widget()->OnKeyEvent(&event);
197 } 212 }
198 213
214 void UpdateNotificationViews() {
215 notification_view()->UpdateWithNotification(*notification());
216 }
217
218 float GetNotificationScrollAmount() const {
219 return notification_view_->GetTransform().To2dTranslation().x();
220 }
221
199 TestMessageCenterController* controller() { return &controller_; } 222 TestMessageCenterController* controller() { return &controller_; }
200 Notification* notification() { return notification_.get(); } 223 Notification* notification() { return notification_.get(); }
201 TestCustomView* custom_view() { 224 TestCustomView* custom_view() {
202 return static_cast<TestCustomView*>(notification_view_->contents_view_); 225 return static_cast<TestCustomView*>(notification_view_->contents_view_);
203 } 226 }
204 views::Widget* widget() { return notification_view_->GetWidget(); } 227 views::Widget* widget() { return notification_view_->GetWidget(); }
228 CustomNotificationView* notification_view() {
229 return notification_view_.get();
230 }
205 231
206 private: 232 private:
207 TestMessageCenterController controller_; 233 TestMessageCenterController controller_;
208 scoped_refptr<TestNotificationDelegate> notification_delegate_; 234 scoped_refptr<TestNotificationDelegate> notification_delegate_;
209 std::unique_ptr<Notification> notification_; 235 std::unique_ptr<Notification> notification_;
210 std::unique_ptr<CustomNotificationView> notification_view_; 236 std::unique_ptr<CustomNotificationView> notification_view_;
211 237
212 DISALLOW_COPY_AND_ASSIGN(CustomNotificationViewTest); 238 DISALLOW_COPY_AND_ASSIGN(CustomNotificationViewTest);
213 }; 239 };
214 240
(...skipping 14 matching lines...) Expand all
229 ui::MouseEvent move(ui::ET_MOUSE_MOVED, cursor_location, cursor_location, 255 ui::MouseEvent move(ui::ET_MOUSE_MOVED, cursor_location, cursor_location,
230 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); 256 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE);
231 widget()->OnMouseEvent(&move); 257 widget()->OnMouseEvent(&move);
232 EXPECT_EQ(3, custom_view()->mouse_event_count()); 258 EXPECT_EQ(3, custom_view()->mouse_event_count());
233 259
234 EXPECT_EQ(0, custom_view()->keyboard_event_count()); 260 EXPECT_EQ(0, custom_view()->keyboard_event_count());
235 KeyPress(ui::VKEY_A); 261 KeyPress(ui::VKEY_A);
236 EXPECT_EQ(1, custom_view()->keyboard_event_count()); 262 EXPECT_EQ(1, custom_view()->keyboard_event_count());
237 } 263 }
238 264
265 TEST_F(CustomNotificationViewTest, SlideOut) {
266 UpdateNotificationViews();
267 std::string notification_id = notification()->id();
268
269 auto event_begin = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN);
270 auto event_scroll10 = GenerateGestureHorizontalScrollUpdateEvent(-10);
271 auto event_scroll500 = GenerateGestureHorizontalScrollUpdateEvent(-500);
272 auto event_end = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_END);
273
274 notification_view()->OnGestureEvent(event_begin.get());
275 notification_view()->OnGestureEvent(event_scroll10.get());
276 EXPECT_FALSE(controller()->IsRemoved(notification_id));
277 EXPECT_EQ(-10.f, GetNotificationScrollAmount());
278 notification_view()->OnGestureEvent(event_end.get());
279 EXPECT_FALSE(controller()->IsRemoved(notification_id));
280 EXPECT_EQ(0.f, GetNotificationScrollAmount());
281
282 notification_view()->OnGestureEvent(event_begin.get());
283 notification_view()->OnGestureEvent(event_scroll500.get());
284 EXPECT_FALSE(controller()->IsRemoved(notification_id));
285 EXPECT_EQ(-500.f, GetNotificationScrollAmount());
286 notification_view()->OnGestureEvent(event_end.get());
287 EXPECT_TRUE(controller()->IsRemoved(notification_id));
288 }
289
290 // Pinning notification is ChromeOS only feature.
291 #if defined(OS_CHROMEOS)
292
293 TEST_F(CustomNotificationViewTest, SlideOutPinned) {
294 notification()->set_pinned(true);
295 UpdateNotificationViews();
296 std::string notification_id = notification()->id();
297
298 auto event_begin = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN);
299 auto event_scroll500 = GenerateGestureHorizontalScrollUpdateEvent(-500);
300 auto event_end = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_END);
301
302 notification_view()->OnGestureEvent(event_begin.get());
303 notification_view()->OnGestureEvent(event_scroll500.get());
304 EXPECT_FALSE(controller()->IsRemoved(notification_id));
305 EXPECT_LT(-500.f, GetNotificationScrollAmount());
306 notification_view()->OnGestureEvent(event_end.get());
307 EXPECT_FALSE(controller()->IsRemoved(notification_id));
308 }
309
310 #endif // defined(OS_CHROMEOS)
311
239 } // namespace message_center 312 } // namespace message_center
OLDNEW
« no previous file with comments | « no previous file | ui/message_center/views/message_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698