Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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::unique_ptr<CustomContent> CreateCustomContent() override { |
| 75 return base::WrapUnique(new TestCustomView); | 82 return base::MakeUnique<CustomContent>( |
| 83 base::WrapUnique(new TestCustomView), | |
| 84 base::WrapUnique(new TestContentViewDelegate)); | |
|
xiyuan
2016/12/06 17:11:16
nit: WrapUnique -> MakeUnique
yhanada
2016/12/07 00:23:24
Done.
| |
| 76 } | 85 } |
| 77 | 86 |
| 78 private: | 87 private: |
| 79 ~TestNotificationDelegate() override {} | 88 ~TestNotificationDelegate() override {} |
| 80 | 89 |
| 81 DISALLOW_COPY_AND_ASSIGN(TestNotificationDelegate); | 90 DISALLOW_COPY_AND_ASSIGN(TestNotificationDelegate); |
| 82 }; | 91 }; |
| 83 | 92 |
| 84 class TestMessageCenterController : public MessageCenterController { | 93 class TestMessageCenterController : public MessageCenterController { |
| 85 public: | 94 public: |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 ui::ET_MOUSE_RELEASED, point, point, ui::EventTimeForNow(), | 189 ui::ET_MOUSE_RELEASED, point, point, ui::EventTimeForNow(), |
| 181 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 190 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 182 widget()->OnMouseEvent(&released_event); | 191 widget()->OnMouseEvent(&released_event); |
| 183 } | 192 } |
| 184 | 193 |
| 185 void KeyPress(ui::KeyboardCode key_code) { | 194 void KeyPress(ui::KeyboardCode key_code) { |
| 186 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE); | 195 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE); |
| 187 widget()->OnKeyEvent(&event); | 196 widget()->OnKeyEvent(&event); |
| 188 } | 197 } |
| 189 | 198 |
| 190 views::ImageButton* close_button() { | |
| 191 return notification_view_->close_button(); | |
| 192 } | |
| 193 TestMessageCenterController* controller() { return &controller_; } | 199 TestMessageCenterController* controller() { return &controller_; } |
| 194 Notification* notification() { return notification_.get(); } | 200 Notification* notification() { return notification_.get(); } |
| 195 TestCustomView* custom_view() { | 201 TestCustomView* custom_view() { |
| 196 return static_cast<TestCustomView*>(notification_view_->contents_view_); | 202 return static_cast<TestCustomView*>(notification_view_->contents_view_); |
| 197 } | 203 } |
| 198 views::Widget* widget() { return notification_view_->GetWidget(); } | 204 views::Widget* widget() { return notification_view_->GetWidget(); } |
| 199 | 205 |
| 200 private: | 206 private: |
| 201 TestMessageCenterController controller_; | 207 TestMessageCenterController controller_; |
| 202 scoped_refptr<TestNotificationDelegate> notification_delegate_; | 208 scoped_refptr<TestNotificationDelegate> notification_delegate_; |
| 203 std::unique_ptr<Notification> notification_; | 209 std::unique_ptr<Notification> notification_; |
| 204 std::unique_ptr<CustomNotificationView> notification_view_; | 210 std::unique_ptr<CustomNotificationView> notification_view_; |
| 205 | 211 |
| 206 DISALLOW_COPY_AND_ASSIGN(CustomNotificationViewTest); | 212 DISALLOW_COPY_AND_ASSIGN(CustomNotificationViewTest); |
| 207 }; | 213 }; |
| 208 | 214 |
| 209 TEST_F(CustomNotificationViewTest, Background) { | 215 TEST_F(CustomNotificationViewTest, Background) { |
| 210 EXPECT_EQ(kBackgroundColor, GetBackgroundColor()); | 216 EXPECT_EQ(kBackgroundColor, GetBackgroundColor()); |
| 211 } | 217 } |
| 212 | 218 |
| 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) { | 219 TEST_F(CustomNotificationViewTest, Events) { |
| 223 widget()->Show(); | 220 widget()->Show(); |
| 224 custom_view()->RequestFocus(); | 221 custom_view()->RequestFocus(); |
| 225 | 222 |
| 226 EXPECT_EQ(0, custom_view()->mouse_event_count()); | 223 EXPECT_EQ(0, custom_view()->mouse_event_count()); |
| 227 gfx::Point cursor_location(1, 1); | 224 gfx::Point cursor_location(1, 1); |
| 228 views::View::ConvertPointToWidget(custom_view(), &cursor_location); | 225 views::View::ConvertPointToWidget(custom_view(), &cursor_location); |
| 229 PerformClick(cursor_location); | 226 PerformClick(cursor_location); |
| 230 EXPECT_EQ(2, custom_view()->mouse_event_count()); | 227 EXPECT_EQ(2, custom_view()->mouse_event_count()); |
| 231 | 228 |
| 232 ui::MouseEvent move(ui::ET_MOUSE_MOVED, cursor_location, cursor_location, | 229 ui::MouseEvent move(ui::ET_MOUSE_MOVED, cursor_location, cursor_location, |
| 233 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 230 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); |
| 234 widget()->OnMouseEvent(&move); | 231 widget()->OnMouseEvent(&move); |
| 235 EXPECT_EQ(3, custom_view()->mouse_event_count()); | 232 EXPECT_EQ(3, custom_view()->mouse_event_count()); |
| 236 | 233 |
| 237 EXPECT_EQ(0, custom_view()->keyboard_event_count()); | 234 EXPECT_EQ(0, custom_view()->keyboard_event_count()); |
| 238 KeyPress(ui::VKEY_A); | 235 KeyPress(ui::VKEY_A); |
| 239 EXPECT_EQ(1, custom_view()->keyboard_event_count()); | 236 EXPECT_EQ(1, custom_view()->keyboard_event_count()); |
| 240 } | 237 } |
| 241 | 238 |
| 242 } // namespace message_center | 239 } // namespace message_center |
| OLD | NEW |