OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/message_center/views/notification_view.h" | 5 #include "ui/message_center/views/notification_view.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
11 #include "ui/gfx/image/image.h" | 11 #include "ui/gfx/image/image.h" |
12 #include "ui/message_center/notification.h" | 12 #include "ui/message_center/notification.h" |
13 #include "ui/message_center/notification_list.h" | 13 #include "ui/message_center/notification_list.h" |
14 #include "ui/message_center/notification_types.h" | 14 #include "ui/message_center/notification_types.h" |
15 #include "ui/message_center/views/message_center_controller.h" | 15 #include "ui/message_center/views/message_center_controller.h" |
| 16 #include "ui/message_center/views/notification_button.h" |
16 | 17 |
17 namespace message_center { | 18 namespace message_center { |
18 | 19 |
19 /* Test fixture ***************************************************************/ | 20 /* Test fixture ***************************************************************/ |
20 | 21 |
21 class NotificationViewTest : public testing::Test, | 22 class NotificationViewTest : public testing::Test, |
22 public MessageCenterController { | 23 public MessageCenterController { |
23 public: | 24 public: |
24 NotificationViewTest(); | 25 NotificationViewTest(); |
25 virtual ~NotificationViewTest(); | 26 virtual ~NotificationViewTest(); |
(...skipping 22 matching lines...) Expand all Loading... |
48 } | 49 } |
49 | 50 |
50 const SkBitmap CreateBitmap(int width, int height) { | 51 const SkBitmap CreateBitmap(int width, int height) { |
51 SkBitmap bitmap; | 52 SkBitmap bitmap; |
52 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 53 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
53 bitmap.allocPixels(); | 54 bitmap.allocPixels(); |
54 bitmap.eraseRGB(0, 255, 0); | 55 bitmap.eraseRGB(0, 255, 0); |
55 return bitmap; | 56 return bitmap; |
56 } | 57 } |
57 | 58 |
| 59 std::vector<ButtonInfo> CreateButtons(int number) { |
| 60 ButtonInfo info(base::ASCIIToUTF16("Test button title.")); |
| 61 info.icon = CreateTestImage(4, 4); |
| 62 return std::vector<ButtonInfo>(number, info); |
| 63 } |
| 64 |
58 private: | 65 private: |
59 scoped_ptr<RichNotificationData> data_; | 66 scoped_ptr<RichNotificationData> data_; |
60 scoped_ptr<Notification> notification_; | 67 scoped_ptr<Notification> notification_; |
61 scoped_ptr<NotificationView> notification_view_; | 68 scoped_ptr<NotificationView> notification_view_; |
62 | 69 |
63 DISALLOW_COPY_AND_ASSIGN(NotificationViewTest); | 70 DISALLOW_COPY_AND_ASSIGN(NotificationViewTest); |
64 }; | 71 }; |
65 | 72 |
66 NotificationViewTest::NotificationViewTest() { | 73 NotificationViewTest::NotificationViewTest() { |
67 } | 74 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 notification()->set_context_message(base::UTF8ToUTF16("foo")); | 175 notification()->set_context_message(base::UTF8ToUTF16("foo")); |
169 notification_view()->CreateOrUpdateViews(*notification()); | 176 notification_view()->CreateOrUpdateViews(*notification()); |
170 | 177 |
171 EXPECT_TRUE(notification_view()->context_message_view_ != NULL); | 178 EXPECT_TRUE(notification_view()->context_message_view_ != NULL); |
172 | 179 |
173 EXPECT_EQ(1, notification_view()->GetMessageLineLimit(0, 360)); | 180 EXPECT_EQ(1, notification_view()->GetMessageLineLimit(0, 360)); |
174 EXPECT_EQ(1, notification_view()->GetMessageLineLimit(1, 360)); | 181 EXPECT_EQ(1, notification_view()->GetMessageLineLimit(1, 360)); |
175 EXPECT_EQ(0, notification_view()->GetMessageLineLimit(2, 360)); | 182 EXPECT_EQ(0, notification_view()->GetMessageLineLimit(2, 360)); |
176 } | 183 } |
177 | 184 |
| 185 TEST_F(NotificationViewTest, UpdateButtonsStateTest) { |
| 186 notification()->set_buttons(CreateButtons(2)); |
| 187 notification_view()->CreateOrUpdateViews(*notification()); |
| 188 notification_view()->action_buttons_[0]->set_animate_on_state_change(false); |
| 189 notification_view()->action_buttons_[1]->set_animate_on_state_change(false); |
| 190 |
| 191 EXPECT_TRUE(NULL == notification_view()->action_buttons_[0]->background()); |
| 192 |
| 193 notification_view()->action_buttons_[0]->SetState( |
| 194 views::Button::STATE_HOVERED); |
| 195 |
| 196 EXPECT_TRUE(NULL != notification_view()->action_buttons_[0]->background()); |
| 197 |
| 198 notification_view()->CreateOrUpdateViews(*notification()); |
| 199 notification_view()->action_buttons_[0]->set_animate_on_state_change(false); |
| 200 notification_view()->action_buttons_[1]->set_animate_on_state_change(false); |
| 201 |
| 202 EXPECT_TRUE(NULL != notification_view()->action_buttons_[0]->background()); |
| 203 |
| 204 notification_view()->action_buttons_[0]->SetState( |
| 205 views::Button::STATE_NORMAL); |
| 206 |
| 207 notification_view()->CreateOrUpdateViews(*notification()); |
| 208 |
| 209 EXPECT_TRUE(NULL == notification_view()->action_buttons_[0]->background()); |
| 210 |
| 211 } |
| 212 |
178 } // namespace message_center | 213 } // namespace message_center |
OLD | NEW |