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

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

Issue 2547433002: Transfer responsibility for providing a close button for a notification to each implementation of M… (Closed)
Patch Set: Delete debug logs Created 4 years 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 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 int mouse_event_count() const { return mouse_event_count_; } 59 int mouse_event_count() const { return mouse_event_count_; }
60 int keyboard_event_count() const { return keyboard_event_count_; } 60 int keyboard_event_count() const { return keyboard_event_count_; }
61 61
62 private: 62 private:
63 int mouse_event_count_ = 0; 63 int mouse_event_count_ = 0;
64 int keyboard_event_count_ = 0; 64 int keyboard_event_count_ = 0;
65 65
66 DISALLOW_COPY_AND_ASSIGN(TestCustomView); 66 DISALLOW_COPY_AND_ASSIGN(TestCustomView);
67 }; 67 };
68 68
69 class TestContentViewDelegate : public CustomNotificationContentViewDelegate {
70 public:
71 bool IsCloseButtonFocused() const override { return false; }
72 void RequestFocusOnCloseButton() override {}
73 bool IsPinned() const override { return false; }
74 };
75
69 class TestNotificationDelegate : public NotificationDelegate { 76 class TestNotificationDelegate : public NotificationDelegate {
70 public: 77 public:
71 TestNotificationDelegate() {} 78 TestNotificationDelegate() {}
72 79
73 // NotificateDelegate 80 // NotificateDelegate
74 std::unique_ptr<views::View> CreateCustomContent() override { 81 std::tuple<std::unique_ptr<views::View>,
75 return base::WrapUnique(new TestCustomView); 82 std::unique_ptr<CustomNotificationContentViewDelegate>>
83 CreateCustomContent() override {
84 return std::make_tuple(base::WrapUnique(new TestCustomView),
85 base::WrapUnique(new TestContentViewDelegate));
76 } 86 }
77 87
78 private: 88 private:
79 ~TestNotificationDelegate() override {} 89 ~TestNotificationDelegate() override {}
80 90
81 DISALLOW_COPY_AND_ASSIGN(TestNotificationDelegate); 91 DISALLOW_COPY_AND_ASSIGN(TestNotificationDelegate);
82 }; 92 };
83 93
84 class TestMessageCenterController : public MessageCenterController { 94 class TestMessageCenterController : public MessageCenterController {
85 public: 95 public:
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 ui::ET_MOUSE_RELEASED, point, point, ui::EventTimeForNow(), 190 ui::ET_MOUSE_RELEASED, point, point, ui::EventTimeForNow(),
181 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); 191 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
182 widget()->OnMouseEvent(&released_event); 192 widget()->OnMouseEvent(&released_event);
183 } 193 }
184 194
185 void KeyPress(ui::KeyboardCode key_code) { 195 void KeyPress(ui::KeyboardCode key_code) {
186 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE); 196 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE);
187 widget()->OnKeyEvent(&event); 197 widget()->OnKeyEvent(&event);
188 } 198 }
189 199
190 views::ImageButton* close_button() {
191 return notification_view_->close_button();
192 }
193 TestMessageCenterController* controller() { return &controller_; } 200 TestMessageCenterController* controller() { return &controller_; }
194 Notification* notification() { return notification_.get(); } 201 Notification* notification() { return notification_.get(); }
195 TestCustomView* custom_view() { 202 TestCustomView* custom_view() {
196 return static_cast<TestCustomView*>(notification_view_->contents_view_); 203 return static_cast<TestCustomView*>(notification_view_->contents_view_);
197 } 204 }
198 views::Widget* widget() { return notification_view_->GetWidget(); } 205 views::Widget* widget() { return notification_view_->GetWidget(); }
199 206
200 private: 207 private:
201 TestMessageCenterController controller_; 208 TestMessageCenterController controller_;
202 scoped_refptr<TestNotificationDelegate> notification_delegate_; 209 scoped_refptr<TestNotificationDelegate> notification_delegate_;
203 std::unique_ptr<Notification> notification_; 210 std::unique_ptr<Notification> notification_;
204 std::unique_ptr<CustomNotificationView> notification_view_; 211 std::unique_ptr<CustomNotificationView> notification_view_;
205 212
206 DISALLOW_COPY_AND_ASSIGN(CustomNotificationViewTest); 213 DISALLOW_COPY_AND_ASSIGN(CustomNotificationViewTest);
207 }; 214 };
208 215
209 TEST_F(CustomNotificationViewTest, Background) { 216 TEST_F(CustomNotificationViewTest, Background) {
210 EXPECT_EQ(kBackgroundColor, GetBackgroundColor()); 217 EXPECT_EQ(kBackgroundColor, GetBackgroundColor());
211 } 218 }
212 219
213 TEST_F(CustomNotificationViewTest, ClickCloseButton) {
214 widget()->Show();
215
216 gfx::Point cursor_location(1, 1);
217 views::View::ConvertPointToWidget(close_button(), &cursor_location);
218 PerformClick(cursor_location);
219 EXPECT_TRUE(controller()->IsRemoved(notification()->id()));
220 }
221
222 TEST_F(CustomNotificationViewTest, Events) { 220 TEST_F(CustomNotificationViewTest, Events) {
223 widget()->Show(); 221 widget()->Show();
224 custom_view()->RequestFocus(); 222 custom_view()->RequestFocus();
225 223
226 EXPECT_EQ(0, custom_view()->mouse_event_count()); 224 EXPECT_EQ(0, custom_view()->mouse_event_count());
227 gfx::Point cursor_location(1, 1); 225 gfx::Point cursor_location(1, 1);
228 views::View::ConvertPointToWidget(custom_view(), &cursor_location); 226 views::View::ConvertPointToWidget(custom_view(), &cursor_location);
229 PerformClick(cursor_location); 227 PerformClick(cursor_location);
230 EXPECT_EQ(2, custom_view()->mouse_event_count()); 228 EXPECT_EQ(2, custom_view()->mouse_event_count());
231 229
232 ui::MouseEvent move(ui::ET_MOUSE_MOVED, cursor_location, cursor_location, 230 ui::MouseEvent move(ui::ET_MOUSE_MOVED, cursor_location, cursor_location,
233 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); 231 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE);
234 widget()->OnMouseEvent(&move); 232 widget()->OnMouseEvent(&move);
235 EXPECT_EQ(3, custom_view()->mouse_event_count()); 233 EXPECT_EQ(3, custom_view()->mouse_event_count());
236 234
237 EXPECT_EQ(0, custom_view()->keyboard_event_count()); 235 EXPECT_EQ(0, custom_view()->keyboard_event_count());
238 KeyPress(ui::VKEY_A); 236 KeyPress(ui::VKEY_A);
239 EXPECT_EQ(1, custom_view()->keyboard_event_count()); 237 EXPECT_EQ(1, custom_view()->keyboard_event_count());
240 } 238 }
241 239
242 } // namespace message_center 240 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698