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

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

Issue 2849523005: CrOS: Fix appearance of notification toasts when sliding out via gesture (Closed)
Patch Set: update build includes Created 3 years, 7 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 | « ui/message_center/BUILD.gn ('k') | ui/message_center/views/message_center_view_unittest.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"
(...skipping 11 matching lines...) Expand all
22 #include "ui/views/background.h" 22 #include "ui/views/background.h"
23 #include "ui/views/controls/button/image_button.h" 23 #include "ui/views/controls/button/image_button.h"
24 #include "ui/views/test/views_test_base.h" 24 #include "ui/views/test/views_test_base.h"
25 25
26 namespace message_center { 26 namespace message_center {
27 27
28 namespace { 28 namespace {
29 29
30 const SkColor kBackgroundColor = SK_ColorGREEN; 30 const SkColor kBackgroundColor = SK_ColorGREEN;
31 31
32 std::unique_ptr<ui::GestureEvent> GenerateGestureEvent(ui::EventType type) {
33 ui::GestureEventDetails detail(type);
34 std::unique_ptr<ui::GestureEvent> event(
35 new ui::GestureEvent(0, 0, 0, base::TimeTicks(), detail));
36 return event;
37 }
38
39 std::unique_ptr<ui::GestureEvent> GenerateGestureHorizontalScrollUpdateEvent(
40 int dx) {
41 ui::GestureEventDetails detail(ui::ET_GESTURE_SCROLL_UPDATE, dx, 0);
42 std::unique_ptr<ui::GestureEvent> event(
43 new ui::GestureEvent(0, 0, 0, base::TimeTicks(), detail));
44 return event;
45 }
46
47 class TestCustomView : public views::View { 32 class TestCustomView : public views::View {
48 public: 33 public:
49 TestCustomView() { 34 TestCustomView() {
50 SetFocusBehavior(FocusBehavior::ALWAYS); 35 SetFocusBehavior(FocusBehavior::ALWAYS);
51 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); 36 set_background(views::Background::CreateSolidBackground(kBackgroundColor));
52 } 37 }
53 ~TestCustomView() override {} 38 ~TestCustomView() override {}
54 39
55 void Reset() { 40 void Reset() {
56 mouse_event_count_ = 0; 41 mouse_event_count_ = 0;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 226
242 void KeyPress(ui::KeyboardCode key_code) { 227 void KeyPress(ui::KeyboardCode key_code) {
243 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE); 228 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE);
244 widget()->OnKeyEvent(&event); 229 widget()->OnKeyEvent(&event);
245 } 230 }
246 231
247 void UpdateNotificationViews() { 232 void UpdateNotificationViews() {
248 notification_view()->UpdateWithNotification(*notification()); 233 notification_view()->UpdateWithNotification(*notification());
249 } 234 }
250 235
251 float GetNotificationScrollAmount() const {
252 return notification_view_->GetTransform().To2dTranslation().x();
253 }
254
255 TestMessageCenterController* controller() { return &controller_; } 236 TestMessageCenterController* controller() { return &controller_; }
256 Notification* notification() { return notification_.get(); } 237 Notification* notification() { return notification_.get(); }
257 TestCustomView* custom_view() { 238 TestCustomView* custom_view() {
258 return static_cast<TestCustomView*>(notification_view_->contents_view_); 239 return static_cast<TestCustomView*>(notification_view_->contents_view_);
259 } 240 }
260 views::Widget* widget() { return notification_view_->GetWidget(); } 241 views::Widget* widget() { return notification_view_->GetWidget(); }
261 CustomNotificationView* notification_view() { 242 CustomNotificationView* notification_view() {
262 return notification_view_.get(); 243 return notification_view_.get();
263 } 244 }
264 245
(...skipping 23 matching lines...) Expand all
288 ui::MouseEvent move(ui::ET_MOUSE_MOVED, cursor_location, cursor_location, 269 ui::MouseEvent move(ui::ET_MOUSE_MOVED, cursor_location, cursor_location,
289 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); 270 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE);
290 widget()->OnMouseEvent(&move); 271 widget()->OnMouseEvent(&move);
291 EXPECT_EQ(3, custom_view()->mouse_event_count()); 272 EXPECT_EQ(3, custom_view()->mouse_event_count());
292 273
293 EXPECT_EQ(0, custom_view()->keyboard_event_count()); 274 EXPECT_EQ(0, custom_view()->keyboard_event_count());
294 KeyPress(ui::VKEY_A); 275 KeyPress(ui::VKEY_A);
295 EXPECT_EQ(1, custom_view()->keyboard_event_count()); 276 EXPECT_EQ(1, custom_view()->keyboard_event_count());
296 } 277 }
297 278
298 TEST_F(CustomNotificationViewTest, SlideOut) {
299 UpdateNotificationViews();
300 std::string notification_id = notification()->id();
301
302 auto event_begin = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN);
303 auto event_scroll10 = GenerateGestureHorizontalScrollUpdateEvent(-10);
304 auto event_scroll500 = GenerateGestureHorizontalScrollUpdateEvent(-500);
305 auto event_end = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_END);
306
307 notification_view()->OnGestureEvent(event_begin.get());
308 notification_view()->OnGestureEvent(event_scroll10.get());
309 EXPECT_FALSE(controller()->IsRemoved(notification_id));
310 EXPECT_EQ(-10.f, GetNotificationScrollAmount());
311 notification_view()->OnGestureEvent(event_end.get());
312 EXPECT_FALSE(controller()->IsRemoved(notification_id));
313 EXPECT_EQ(0.f, GetNotificationScrollAmount());
314
315 notification_view()->OnGestureEvent(event_begin.get());
316 notification_view()->OnGestureEvent(event_scroll500.get());
317 EXPECT_FALSE(controller()->IsRemoved(notification_id));
318 EXPECT_EQ(-500.f, GetNotificationScrollAmount());
319 notification_view()->OnGestureEvent(event_end.get());
320 EXPECT_TRUE(controller()->IsRemoved(notification_id));
321 }
322
323 // Pinning notification is ChromeOS only feature.
324 #if defined(OS_CHROMEOS)
325
326 TEST_F(CustomNotificationViewTest, SlideOutPinned) {
327 notification()->set_pinned(true);
328 UpdateNotificationViews();
329 std::string notification_id = notification()->id();
330
331 auto event_begin = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN);
332 auto event_scroll500 = GenerateGestureHorizontalScrollUpdateEvent(-500);
333 auto event_end = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_END);
334
335 notification_view()->OnGestureEvent(event_begin.get());
336 notification_view()->OnGestureEvent(event_scroll500.get());
337 EXPECT_FALSE(controller()->IsRemoved(notification_id));
338 EXPECT_LT(-500.f, GetNotificationScrollAmount());
339 notification_view()->OnGestureEvent(event_end.get());
340 EXPECT_FALSE(controller()->IsRemoved(notification_id));
341 }
342
343 #endif // defined(OS_CHROMEOS)
344
345 TEST_F(CustomNotificationViewTest, PressBackspaceKey) { 279 TEST_F(CustomNotificationViewTest, PressBackspaceKey) {
346 std::string notification_id = notification()->id(); 280 std::string notification_id = notification()->id();
347 custom_view()->RequestFocus(); 281 custom_view()->RequestFocus();
348 282
349 ui::InputMethod* input_method = custom_view()->GetInputMethod(); 283 ui::InputMethod* input_method = custom_view()->GetInputMethod();
350 ASSERT_TRUE(input_method); 284 ASSERT_TRUE(input_method);
351 TestTextInputClient text_input_client; 285 TestTextInputClient text_input_client;
352 input_method->SetFocusedTextInputClient(&text_input_client); 286 input_method->SetFocusedTextInputClient(&text_input_client);
353 ASSERT_EQ(&text_input_client, input_method->GetTextInputClient()); 287 ASSERT_EQ(&text_input_client, input_method->GetTextInputClient());
354 288
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 EXPECT_EQ("360x10", size.ToString()); 325 EXPECT_EQ("360x10", size.ToString());
392 326
393 // The long notification. 327 // The long notification.
394 custom_view()->set_preferred_size(gfx::Size(1000, 1000)); 328 custom_view()->set_preferred_size(gfx::Size(1000, 1000));
395 size = notification_view()->GetPreferredSize(); 329 size = notification_view()->GetPreferredSize();
396 size.Enlarge(0, -notification_view()->GetInsets().height()); 330 size.Enlarge(0, -notification_view()->GetInsets().height());
397 EXPECT_EQ("360x1000", size.ToString()); 331 EXPECT_EQ("360x1000", size.ToString());
398 } 332 }
399 333
400 } // namespace message_center 334 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/BUILD.gn ('k') | ui/message_center/views/message_center_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698