OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #import "ui/message_center/cocoa/notification_controller.h" | 5 #import "ui/message_center/cocoa/notification_controller.h" |
6 | 6 |
7 #include "base/memory/scoped_nsobject.h" | 7 #include "base/memory/scoped_nsobject.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
11 #import "ui/base/cocoa/hover_image_button.h" | 11 #import "ui/base/cocoa/hover_image_button.h" |
12 #import "ui/base/test/ui_cocoa_test_helper.h" | 12 #import "ui/base/test/ui_cocoa_test_helper.h" |
13 #include "ui/message_center/fake_message_center.h" | 13 #include "ui/message_center/fake_message_center.h" |
14 #include "ui/message_center/message_center_constants.h" | 14 #include "ui/message_center/message_center_constants.h" |
15 #include "ui/message_center/notification.h" | 15 #include "ui/message_center/notification.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 class MockMessageCenter : public FakeMessageCenter { | 19 class MockMessageCenter : public message_center::FakeMessageCenter { |
20 public: | 20 public: |
21 MockMessageCenter() | 21 MockMessageCenter() |
22 : last_removed_by_user_(false), | 22 : last_removed_by_user_(false), |
23 remove_count_(0) { | 23 remove_count_(0) { |
24 } | 24 } |
25 | 25 |
26 virtual void RemoveNotification(const std::string& id, | 26 virtual void RemoveNotification(const std::string& id, |
27 bool by_user) OVERRIDE { | 27 bool by_user) OVERRIDE { |
28 last_removed_id_ = id; | 28 last_removed_id_ = id; |
29 last_removed_by_user_ = by_user_; | 29 last_removed_by_user_ = by_user; |
| 30 ++remove_count_; |
30 } | 31 } |
31 | 32 |
32 const std::string& last_removed_id() const { return last_removed_id_; } | 33 const std::string& last_removed_id() const { return last_removed_id_; } |
33 bool last_removed_by_user() const { return last_removed_by_user_; } | 34 bool last_removed_by_user() const { return last_removed_by_user_; } |
34 int remove_count() const { return remove_count_; } | 35 int remove_count() const { return remove_count_; } |
35 | 36 |
36 private: | 37 private: |
37 std::string last_removed_id_; | 38 std::string last_removed_id_; |
38 bool last_removed_by_user_; | 39 bool last_removed_by_user_; |
39 int remove_count_; | 40 int remove_count_; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 "", | 76 "", |
76 ASCIIToUTF16("Added to circles"), | 77 ASCIIToUTF16("Added to circles"), |
77 ASCIIToUTF16("Jonathan and 5 others"), | 78 ASCIIToUTF16("Jonathan and 5 others"), |
78 string16(), | 79 string16(), |
79 std::string(), | 80 std::string(), |
80 NULL)); | 81 NULL)); |
81 notification->set_icon(gfx::Image([TestIcon() retain])); | 82 notification->set_icon(gfx::Image([TestIcon() retain])); |
82 | 83 |
83 scoped_nsobject<MCNotificationController> controller( | 84 scoped_nsobject<MCNotificationController> controller( |
84 [[MCNotificationController alloc] initWithNotification:notification.get() | 85 [[MCNotificationController alloc] initWithNotification:notification.get() |
85 changeObserver:NULL]); | 86 messageCenter:NULL]); |
86 [controller view]; | 87 [controller view]; |
87 | 88 |
88 EXPECT_EQ(TestIcon(), [[controller iconView] image]); | 89 EXPECT_EQ(TestIcon(), [[controller iconView] image]); |
89 EXPECT_EQ(base::SysNSStringToUTF16([[controller titleView] stringValue]), | 90 EXPECT_EQ(base::SysNSStringToUTF16([[controller titleView] stringValue]), |
90 notification->title()); | 91 notification->title()); |
91 EXPECT_EQ(base::SysNSStringToUTF16([[controller messageView] stringValue]), | 92 EXPECT_EQ(base::SysNSStringToUTF16([[controller messageView] stringValue]), |
92 notification->message()); | 93 notification->message()); |
93 EXPECT_EQ(controller.get(), [[controller closeButton] target]); | 94 EXPECT_EQ(controller.get(), [[controller closeButton] target]); |
94 } | 95 } |
95 | 96 |
96 TEST_F(NotificationControllerTest, OverflowText) { | 97 TEST_F(NotificationControllerTest, OverflowText) { |
97 scoped_ptr<message_center::Notification> notification( | 98 scoped_ptr<message_center::Notification> notification( |
98 new message_center::Notification( | 99 new message_center::Notification( |
99 message_center::NOTIFICATION_TYPE_SIMPLE, | 100 message_center::NOTIFICATION_TYPE_SIMPLE, |
100 "", | 101 "", |
101 ASCIIToUTF16("This is a much longer title that should wrap " | 102 ASCIIToUTF16("This is a much longer title that should wrap " |
102 "multiple lines."), | 103 "multiple lines."), |
103 ASCIIToUTF16("And even the message is long. This sure is a wordy " | 104 ASCIIToUTF16("And even the message is long. This sure is a wordy " |
104 "notification. Are you really going to read this " | 105 "notification. Are you really going to read this " |
105 "entire thing?"), | 106 "entire thing?"), |
106 string16(), | 107 string16(), |
107 std::string(), | 108 std::string(), |
108 NULL)); | 109 NULL)); |
109 scoped_nsobject<MCNotificationController> controller( | 110 scoped_nsobject<MCNotificationController> controller( |
110 [[MCNotificationController alloc] initWithNotification:notification.get() | 111 [[MCNotificationController alloc] initWithNotification:notification.get() |
111 changeObserver:NULL]); | 112 messageCenter:NULL]); |
112 [controller view]; | 113 [controller view]; |
113 | 114 |
114 EXPECT_GT(NSHeight([[controller view] frame]), | 115 EXPECT_GT(NSHeight([[controller view] frame]), |
115 message_center::kNotificationIconSize); | 116 message_center::kNotificationIconSize); |
116 } | 117 } |
117 | 118 |
118 TEST_F(NotificationControllerTest, Close) { | 119 TEST_F(NotificationControllerTest, Close) { |
119 scoped_ptr<message_center::Notification> notification( | 120 scoped_ptr<message_center::Notification> notification( |
120 new message_center::Notification( | 121 new message_center::Notification( |
121 message_center::NOTIFICATION_TYPE_SIMPLE, | 122 message_center::NOTIFICATION_TYPE_SIMPLE, |
122 "an_id", | 123 "an_id", |
123 string16(), | 124 string16(), |
124 string16(), | 125 string16(), |
125 string16(), | 126 string16(), |
126 std::string(), | 127 std::string(), |
127 NULL)); | 128 NULL)); |
128 MockMessageCenter messageCenter; | 129 MockMessageCenter messageCenter; |
129 | 130 |
130 scoped_nsobject<MCNotificationController> controller( | 131 scoped_nsobject<MCNotificationController> controller( |
131 [[MCNotificationController alloc] initWithNotification:notification.get() | 132 [[MCNotificationController alloc] initWithNotification:notification.get() |
132 messageCenter:&messageCenter]); | 133 messageCenter:&messageCenter]); |
133 [controller view]; | 134 [controller view]; |
134 | 135 |
135 EXPECT_TRUE(1, messageCenter.remove_count()); | 136 [[controller closeButton] performClick:nil]; |
| 137 |
| 138 EXPECT_EQ(1, messageCenter.remove_count()); |
136 EXPECT_EQ("an_id", messageCenter.last_removed_id()); | 139 EXPECT_EQ("an_id", messageCenter.last_removed_id()); |
137 EXPECT_TRUE(messageCenter.last_removed_by_user()); | 140 EXPECT_TRUE(messageCenter.last_removed_by_user()); |
138 | |
139 [[controller closeButton] performClick:nil]; | |
140 } | 141 } |
OLD | NEW |