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

Side by Side Diff: ui/arc/notification/arc_notification_view_unittest.cc

Issue 2870283002: Move message_center::CustomNotificationView to arc::ArcNotificationView (Closed)
Patch Set: Fixed test 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
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"
11 #include "third_party/skia/include/core/SkColor.h" 11 #include "third_party/skia/include/core/SkColor.h"
12 #include "ui/arc/notification/arc_notification_content_view_delegate.h"
13 #include "ui/arc/notification/arc_notification_view.h"
12 #include "ui/base/ime/dummy_text_input_client.h" 14 #include "ui/base/ime/dummy_text_input_client.h"
13 #include "ui/base/ime/input_method.h" 15 #include "ui/base/ime/input_method.h"
14 #include "ui/base/ime/text_input_client.h" 16 #include "ui/base/ime/text_input_client.h"
15 #include "ui/events/event.h" 17 #include "ui/events/event.h"
16 #include "ui/events/event_utils.h" 18 #include "ui/events/event_utils.h"
17 #include "ui/message_center/notification.h" 19 #include "ui/message_center/notification.h"
18 #include "ui/message_center/notification_delegate.h" 20 #include "ui/message_center/notification_delegate.h"
19 #include "ui/message_center/views/custom_notification_view.h"
20 #include "ui/message_center/views/message_center_controller.h" 21 #include "ui/message_center/views/message_center_controller.h"
21 #include "ui/message_center/views/message_view_factory.h" 22 #include "ui/message_center/views/message_view_factory.h"
22 #include "ui/views/background.h" 23 #include "ui/views/background.h"
23 #include "ui/views/controls/button/image_button.h" 24 #include "ui/views/controls/button/image_button.h"
24 #include "ui/views/test/views_test_base.h" 25 #include "ui/views/test/views_test_base.h"
25 26
26 namespace message_center { 27 namespace arc {
27 28
28 namespace { 29 namespace {
29 30
30 const SkColor kBackgroundColor = SK_ColorGREEN; 31 const SkColor kBackgroundColor = SK_ColorGREEN;
31 32
32 class TestCustomView : public views::View { 33 class TestNotificationContentsView : public views::View {
33 public: 34 public:
34 TestCustomView() { 35 TestNotificationContentsView() {
35 SetFocusBehavior(FocusBehavior::ALWAYS); 36 SetFocusBehavior(FocusBehavior::ALWAYS);
36 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); 37 set_background(views::Background::CreateSolidBackground(kBackgroundColor));
37 } 38 }
38 ~TestCustomView() override {} 39 ~TestNotificationContentsView() override {}
hidehiko 2017/05/11 14:22:47 Similarly, s/{}/= default;/ Ditto for below.
yoshiki 2017/05/12 08:42:38 Done.
39 40
40 void Reset() { 41 void Reset() {
41 mouse_event_count_ = 0; 42 mouse_event_count_ = 0;
42 keyboard_event_count_ = 0; 43 keyboard_event_count_ = 0;
43 } 44 }
44 45
45 void set_preferred_size(gfx::Size size) { preferred_size_ = size; } 46 void set_preferred_size(gfx::Size size) { preferred_size_ = size; }
46 47
47 // views::View 48 // views::View
48 gfx::Size GetPreferredSize() const override { return preferred_size_; } 49 gfx::Size GetPreferredSize() const override { return preferred_size_; }
(...skipping 13 matching lines...) Expand all
62 } 63 }
63 64
64 int mouse_event_count() const { return mouse_event_count_; } 65 int mouse_event_count() const { return mouse_event_count_; }
65 int keyboard_event_count() const { return keyboard_event_count_; } 66 int keyboard_event_count() const { return keyboard_event_count_; }
66 67
67 private: 68 private:
68 int mouse_event_count_ = 0; 69 int mouse_event_count_ = 0;
69 int keyboard_event_count_ = 0; 70 int keyboard_event_count_ = 0;
70 gfx::Size preferred_size_ = gfx::Size(100, 100); 71 gfx::Size preferred_size_ = gfx::Size(100, 100);
71 72
72 DISALLOW_COPY_AND_ASSIGN(TestCustomView); 73 DISALLOW_COPY_AND_ASSIGN(TestNotificationContentsView);
73 }; 74 };
74 75
75 class TestContentViewDelegate : public CustomNotificationContentViewDelegate { 76 class TestContentViewDelegate : public ArcNotificationContentViewDelegate {
76 public: 77 public:
77 bool IsCloseButtonFocused() const override { return false; } 78 bool IsCloseButtonFocused() const override { return false; }
78 void RequestFocusOnCloseButton() override {} 79 void RequestFocusOnCloseButton() override {}
79 void UpdateControlButtonsVisibility() override {} 80 void UpdateControlButtonsVisibility() override {}
80 }; 81 };
81 82
82 class TestNotificationDelegate : public NotificationDelegate { 83 class TestNotificationDelegate : public message_center::NotificationDelegate {
83 public: 84 public:
84 TestNotificationDelegate() {} 85 TestNotificationDelegate() {}
85 86
86 // NotificateDelegate 87 // NotificateDelegate
87 std::unique_ptr<CustomContent> CreateCustomContent() override { 88 std::unique_ptr<message_center::MessageView> CreateCustomMessageView(
88 return base::MakeUnique<CustomContent>( 89 message_center::MessageCenterController* controller,
89 base::MakeUnique<TestCustomView>(), 90 const message_center::Notification& notification) override {
90 base::MakeUnique<TestContentViewDelegate>()); 91 return base::MakeUnique<ArcNotificationView>(
92 base::MakeUnique<TestNotificationContentsView>(),
93 base::MakeUnique<TestContentViewDelegate>(), controller, notification);
91 } 94 }
92 95
93 private: 96 private:
94 ~TestNotificationDelegate() override {} 97 ~TestNotificationDelegate() override {}
95 98
96 DISALLOW_COPY_AND_ASSIGN(TestNotificationDelegate); 99 DISALLOW_COPY_AND_ASSIGN(TestNotificationDelegate);
97 }; 100 };
98 101
99 class TestMessageCenterController : public MessageCenterController { 102 class TestMessageCenterController
103 : public message_center::MessageCenterController {
100 public: 104 public:
101 TestMessageCenterController() {} 105 TestMessageCenterController() {}
102 106
103 // MessageCenterController 107 // MessageCenterController
104 void ClickOnNotification(const std::string& notification_id) override { 108 void ClickOnNotification(const std::string& notification_id) override {
105 // For this test, this method should not be invoked. 109 // For this test, this method should not be invoked.
106 NOTREACHED(); 110 NOTREACHED();
107 } 111 }
108 112
109 void RemoveNotification(const std::string& notification_id, 113 void RemoveNotification(const std::string& notification_id,
110 bool by_user) override { 114 bool by_user) override {
111 removed_ids_.insert(notification_id); 115 removed_ids_.insert(notification_id);
112 } 116 }
113 117
114 std::unique_ptr<ui::MenuModel> CreateMenuModel( 118 std::unique_ptr<ui::MenuModel> CreateMenuModel(
115 const NotifierId& notifier_id, 119 const message_center::NotifierId& notifier_id,
116 const base::string16& display_source) override { 120 const base::string16& display_source) override {
117 // For this test, this method should not be invoked. 121 // For this test, this method should not be invoked.
118 NOTREACHED(); 122 NOTREACHED();
119 return nullptr; 123 return nullptr;
120 } 124 }
121 125
122 bool HasClickedListener(const std::string& notification_id) override { 126 bool HasClickedListener(const std::string& notification_id) override {
123 return false; 127 return false;
124 } 128 }
125 129
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 void set_text_input_type(ui::TextInputType type) { type_ = type; } 162 void set_text_input_type(ui::TextInputType type) { type_ = type; }
159 163
160 private: 164 private:
161 ui::TextInputType type_ = ui::TEXT_INPUT_TYPE_NONE; 165 ui::TextInputType type_ = ui::TEXT_INPUT_TYPE_NONE;
162 166
163 DISALLOW_COPY_AND_ASSIGN(TestTextInputClient); 167 DISALLOW_COPY_AND_ASSIGN(TestTextInputClient);
164 }; 168 };
165 169
166 } // namespace 170 } // namespace
167 171
168 class CustomNotificationViewTest : public views::ViewsTestBase { 172 class ArcNotificationViewTest : public views::ViewsTestBase {
169 public: 173 public:
170 CustomNotificationViewTest() {} 174 ArcNotificationViewTest() {}
171 ~CustomNotificationViewTest() override {} 175 ~ArcNotificationViewTest() override {}
172 176
173 // views::ViewsTestBase 177 // views::ViewsTestBase
174 void SetUp() override { 178 void SetUp() override {
175 views::ViewsTestBase::SetUp(); 179 views::ViewsTestBase::SetUp();
176 180
177 notification_delegate_ = new TestNotificationDelegate; 181 notification_delegate_ = new TestNotificationDelegate;
178 182
179 notification_.reset(new Notification( 183 notification_.reset(new message_center::Notification(
hidehiko 2017/05/11 14:22:47 nit/style: Could you use base::MakeUnique<> instea
yoshiki 2017/05/12 08:42:38 Done.
180 NOTIFICATION_TYPE_CUSTOM, std::string("notification id"), 184 message_center::NOTIFICATION_TYPE_CUSTOM,
181 base::UTF8ToUTF16("title"), base::UTF8ToUTF16("message"), gfx::Image(), 185 std::string("notification id"), base::UTF8ToUTF16("title"),
186 base::UTF8ToUTF16("message"), gfx::Image(),
182 base::UTF8ToUTF16("display source"), GURL(), 187 base::UTF8ToUTF16("display source"), GURL(),
183 NotifierId(NotifierId::APPLICATION, "extension_id"), 188 message_center::NotifierId(message_center::NotifierId::APPLICATION,
189 "extension_id"),
184 message_center::RichNotificationData(), notification_delegate_.get())); 190 message_center::RichNotificationData(), notification_delegate_.get()));
185 191
186 notification_view_.reset(static_cast<CustomNotificationView*>( 192 notification_view_.reset(static_cast<ArcNotificationView*>(
hidehiko 2017/05/11 14:22:47 Ditto.
yoshiki 2017/05/12 08:42:38 This line doesn't construct an object so we can't
187 MessageViewFactory::Create(controller(), *notification_, true))); 193 message_center::MessageViewFactory::Create(controller(), *notification_,
194 true)));
188 notification_view_->set_owned_by_client(); 195 notification_view_->set_owned_by_client();
189 196
190 views::Widget::InitParams init_params( 197 views::Widget::InitParams init_params(
191 CreateParams(views::Widget::InitParams::TYPE_POPUP)); 198 CreateParams(views::Widget::InitParams::TYPE_POPUP));
192 views::Widget* widget = new views::Widget(); 199 views::Widget* widget = new views::Widget();
193 widget->Init(init_params); 200 widget->Init(init_params);
194 widget->SetContentsView(notification_view_.get()); 201 widget->SetContentsView(notification_view_.get());
195 widget->SetSize(notification_view_->GetPreferredSize()); 202 widget->SetSize(notification_view_->GetPreferredSize());
196 } 203 }
197 204
(...skipping 28 matching lines...) Expand all
226 void KeyPress(ui::KeyboardCode key_code) { 233 void KeyPress(ui::KeyboardCode key_code) {
227 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE); 234 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE);
228 widget()->OnKeyEvent(&event); 235 widget()->OnKeyEvent(&event);
229 } 236 }
230 237
231 void UpdateNotificationViews() { 238 void UpdateNotificationViews() {
232 notification_view()->UpdateWithNotification(*notification()); 239 notification_view()->UpdateWithNotification(*notification());
233 } 240 }
234 241
235 TestMessageCenterController* controller() { return &controller_; } 242 TestMessageCenterController* controller() { return &controller_; }
236 Notification* notification() { return notification_.get(); } 243 message_center::Notification* notification() { return notification_.get(); }
237 TestCustomView* custom_view() { 244 TestNotificationContentsView* contents_view() {
238 return static_cast<TestCustomView*>(notification_view_->contents_view_); 245 return static_cast<TestNotificationContentsView*>(
246 notification_view_->contents_view_);
239 } 247 }
240 views::Widget* widget() { return notification_view_->GetWidget(); } 248 views::Widget* widget() { return notification_view_->GetWidget(); }
241 CustomNotificationView* notification_view() { 249 ArcNotificationView* notification_view() { return notification_view_.get(); }
242 return notification_view_.get();
243 }
244 250
245 private: 251 private:
246 TestMessageCenterController controller_; 252 TestMessageCenterController controller_;
247 scoped_refptr<TestNotificationDelegate> notification_delegate_; 253 scoped_refptr<TestNotificationDelegate> notification_delegate_;
248 std::unique_ptr<Notification> notification_; 254 std::unique_ptr<message_center::Notification> notification_;
249 std::unique_ptr<CustomNotificationView> notification_view_; 255 std::unique_ptr<ArcNotificationView> notification_view_;
250 256
251 DISALLOW_COPY_AND_ASSIGN(CustomNotificationViewTest); 257 DISALLOW_COPY_AND_ASSIGN(ArcNotificationViewTest);
252 }; 258 };
253 259
254 TEST_F(CustomNotificationViewTest, Background) { 260 TEST_F(ArcNotificationViewTest, Background) {
255 EXPECT_EQ(kBackgroundColor, GetBackgroundColor()); 261 EXPECT_EQ(kBackgroundColor, GetBackgroundColor());
256 } 262 }
257 263
258 TEST_F(CustomNotificationViewTest, Events) { 264 TEST_F(ArcNotificationViewTest, Events) {
259 widget()->Show(); 265 widget()->Show();
260 custom_view()->RequestFocus(); 266 contents_view()->RequestFocus();
261 267
262 EXPECT_EQ(0, custom_view()->mouse_event_count()); 268 EXPECT_EQ(0, contents_view()->mouse_event_count());
263 gfx::Point cursor_location(1, 1); 269 gfx::Point cursor_location(1, 1);
264 views::View::ConvertPointToWidget(custom_view(), &cursor_location); 270 views::View::ConvertPointToWidget(contents_view(), &cursor_location);
265 PerformClick(cursor_location); 271 PerformClick(cursor_location);
266 EXPECT_EQ(2, custom_view()->mouse_event_count()); 272 EXPECT_EQ(2, contents_view()->mouse_event_count());
267 273
268 ui::MouseEvent move(ui::ET_MOUSE_MOVED, cursor_location, cursor_location, 274 ui::MouseEvent move(ui::ET_MOUSE_MOVED, cursor_location, cursor_location,
269 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); 275 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE);
270 widget()->OnMouseEvent(&move); 276 widget()->OnMouseEvent(&move);
271 EXPECT_EQ(3, custom_view()->mouse_event_count()); 277 EXPECT_EQ(3, contents_view()->mouse_event_count());
272 278
273 EXPECT_EQ(0, custom_view()->keyboard_event_count()); 279 EXPECT_EQ(0, contents_view()->keyboard_event_count());
274 KeyPress(ui::VKEY_A); 280 KeyPress(ui::VKEY_A);
275 EXPECT_EQ(1, custom_view()->keyboard_event_count()); 281 EXPECT_EQ(1, contents_view()->keyboard_event_count());
276 } 282 }
277 283
278 TEST_F(CustomNotificationViewTest, PressBackspaceKey) { 284 TEST_F(ArcNotificationViewTest, PressBackspaceKey) {
279 std::string notification_id = notification()->id(); 285 std::string notification_id = notification()->id();
280 custom_view()->RequestFocus(); 286 contents_view()->RequestFocus();
281 287
282 ui::InputMethod* input_method = custom_view()->GetInputMethod(); 288 ui::InputMethod* input_method = contents_view()->GetInputMethod();
283 ASSERT_TRUE(input_method); 289 ASSERT_TRUE(input_method);
284 TestTextInputClient text_input_client; 290 TestTextInputClient text_input_client;
285 input_method->SetFocusedTextInputClient(&text_input_client); 291 input_method->SetFocusedTextInputClient(&text_input_client);
286 ASSERT_EQ(&text_input_client, input_method->GetTextInputClient()); 292 ASSERT_EQ(&text_input_client, input_method->GetTextInputClient());
287 293
288 EXPECT_FALSE(controller()->IsRemoved(notification_id)); 294 EXPECT_FALSE(controller()->IsRemoved(notification_id));
289 PerformKeyEvents(ui::VKEY_BACK); 295 PerformKeyEvents(ui::VKEY_BACK);
290 EXPECT_TRUE(controller()->IsRemoved(notification_id)); 296 EXPECT_TRUE(controller()->IsRemoved(notification_id));
291 297
292 input_method->SetFocusedTextInputClient(nullptr); 298 input_method->SetFocusedTextInputClient(nullptr);
293 } 299 }
294 300
295 TEST_F(CustomNotificationViewTest, PressBackspaceKeyOnEditBox) { 301 TEST_F(ArcNotificationViewTest, PressBackspaceKeyOnEditBox) {
296 std::string notification_id = notification()->id(); 302 std::string notification_id = notification()->id();
297 custom_view()->RequestFocus(); 303 contents_view()->RequestFocus();
298 304
299 ui::InputMethod* input_method = custom_view()->GetInputMethod(); 305 ui::InputMethod* input_method = contents_view()->GetInputMethod();
300 ASSERT_TRUE(input_method); 306 ASSERT_TRUE(input_method);
301 TestTextInputClient text_input_client; 307 TestTextInputClient text_input_client;
302 input_method->SetFocusedTextInputClient(&text_input_client); 308 input_method->SetFocusedTextInputClient(&text_input_client);
303 ASSERT_EQ(&text_input_client, input_method->GetTextInputClient()); 309 ASSERT_EQ(&text_input_client, input_method->GetTextInputClient());
304 310
305 text_input_client.set_text_input_type(ui::TEXT_INPUT_TYPE_TEXT); 311 text_input_client.set_text_input_type(ui::TEXT_INPUT_TYPE_TEXT);
306 312
307 EXPECT_FALSE(controller()->IsRemoved(notification_id)); 313 EXPECT_FALSE(controller()->IsRemoved(notification_id));
308 PerformKeyEvents(ui::VKEY_BACK); 314 PerformKeyEvents(ui::VKEY_BACK);
309 EXPECT_FALSE(controller()->IsRemoved(notification_id)); 315 EXPECT_FALSE(controller()->IsRemoved(notification_id));
310 316
311 input_method->SetFocusedTextInputClient(nullptr); 317 input_method->SetFocusedTextInputClient(nullptr);
312 } 318 }
313 319
314 TEST_F(CustomNotificationViewTest, ChangeContentHeight) { 320 TEST_F(ArcNotificationViewTest, ChangeContentHeight) {
315 // Default size. 321 // Default size.
316 gfx::Size size = notification_view()->GetPreferredSize(); 322 gfx::Size size = notification_view()->GetPreferredSize();
317 size.Enlarge(0, -notification_view()->GetInsets().height()); 323 size.Enlarge(0, -notification_view()->GetInsets().height());
318 EXPECT_EQ("360x100", size.ToString()); 324 EXPECT_EQ("360x100", size.ToString());
319 325
320 // Allow small notifications. 326 // Allow small notifications.
321 custom_view()->set_preferred_size(gfx::Size(10, 10)); 327 contents_view()->set_preferred_size(gfx::Size(10, 10));
322 size = notification_view()->GetPreferredSize(); 328 size = notification_view()->GetPreferredSize();
323 size.Enlarge(0, -notification_view()->GetInsets().height()); 329 size.Enlarge(0, -notification_view()->GetInsets().height());
324 EXPECT_EQ("360x10", size.ToString()); 330 EXPECT_EQ("360x10", size.ToString());
325 331
326 // The long notification. 332 // The long notification.
327 custom_view()->set_preferred_size(gfx::Size(1000, 1000)); 333 contents_view()->set_preferred_size(gfx::Size(1000, 1000));
328 size = notification_view()->GetPreferredSize(); 334 size = notification_view()->GetPreferredSize();
329 size.Enlarge(0, -notification_view()->GetInsets().height()); 335 size.Enlarge(0, -notification_view()->GetInsets().height());
330 EXPECT_EQ("360x1000", size.ToString()); 336 EXPECT_EQ("360x1000", size.ToString());
331 } 337 }
332 338
333 } // namespace message_center 339 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698