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/popup_collection.h" | 5 #import "ui/message_center/cocoa/popup_collection.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
11 #include "base/message_loop/message_loop.h" | |
12 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
13 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
14 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/test/scoped_task_environment.h" |
15 #import "ui/gfx/test/ui_cocoa_test_helper.h" | 15 #import "ui/gfx/test/ui_cocoa_test_helper.h" |
16 #import "ui/message_center/cocoa/notification_controller.h" | 16 #import "ui/message_center/cocoa/notification_controller.h" |
17 #import "ui/message_center/cocoa/popup_controller.h" | 17 #import "ui/message_center/cocoa/popup_controller.h" |
18 #include "ui/message_center/message_center.h" | 18 #include "ui/message_center/message_center.h" |
19 #include "ui/message_center/message_center_style.h" | 19 #include "ui/message_center/message_center_style.h" |
20 #include "ui/message_center/notification.h" | 20 #include "ui/message_center/notification.h" |
21 | 21 |
22 using base::ASCIIToUTF16; | 22 using base::ASCIIToUTF16; |
23 | 23 |
24 namespace message_center { | 24 namespace message_center { |
25 | 25 |
26 class PopupCollectionTest : public ui::CocoaTest { | 26 class PopupCollectionTest : public ui::CocoaTest { |
27 public: | 27 public: |
28 PopupCollectionTest() { | 28 PopupCollectionTest() |
| 29 : scoped_task_environment_( |
| 30 base::test::ScopedTaskEnvironment::MainThreadType::UI) { |
29 message_center::MessageCenter::Initialize(); | 31 message_center::MessageCenter::Initialize(); |
30 center_ = message_center::MessageCenter::Get(); | 32 center_ = message_center::MessageCenter::Get(); |
31 collection_.reset( | 33 collection_.reset( |
32 [[MCPopupCollection alloc] initWithMessageCenter:center_]); | 34 [[MCPopupCollection alloc] initWithMessageCenter:center_]); |
33 [collection_ setAnimationDuration:0.001]; | 35 [collection_ setAnimationDuration:0.001]; |
34 [collection_ setAnimationEndedCallback:^{ | 36 [collection_ setAnimationEndedCallback:^{ |
35 if (nested_run_loop_.get()) | 37 if (nested_run_loop_.get()) |
36 nested_run_loop_->Quit(); | 38 nested_run_loop_->Quit(); |
37 }]; | 39 }]; |
38 } | 40 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 } | 90 } |
89 | 91 |
90 void WaitForAnimationEnded() { | 92 void WaitForAnimationEnded() { |
91 if (![collection_ isAnimating]) | 93 if (![collection_ isAnimating]) |
92 return; | 94 return; |
93 nested_run_loop_.reset(new base::RunLoop()); | 95 nested_run_loop_.reset(new base::RunLoop()); |
94 nested_run_loop_->Run(); | 96 nested_run_loop_->Run(); |
95 nested_run_loop_.reset(); | 97 nested_run_loop_.reset(); |
96 } | 98 } |
97 | 99 |
98 base::MessageLoopForUI message_loop_; | 100 base::test::ScopedTaskEnvironment scoped_task_environment_; |
99 std::unique_ptr<base::RunLoop> nested_run_loop_; | 101 std::unique_ptr<base::RunLoop> nested_run_loop_; |
100 message_center::MessageCenter* center_; | 102 message_center::MessageCenter* center_; |
101 base::scoped_nsobject<MCPopupCollection> collection_; | 103 base::scoped_nsobject<MCPopupCollection> collection_; |
102 }; | 104 }; |
103 | 105 |
104 TEST_F(PopupCollectionTest, AddThreeCloseOne) { | 106 TEST_F(PopupCollectionTest, AddThreeCloseOne) { |
105 EXPECT_EQ(0u, [[collection_ popups] count]); | 107 EXPECT_EQ(0u, [[collection_ popups] count]); |
106 AddThreeNotifications(); | 108 AddThreeNotifications(); |
107 EXPECT_EQ(3u, [[collection_ popups] count]); | 109 EXPECT_EQ(3u, [[collection_ popups] count]); |
108 | 110 |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 ASCIIToUTF16("New message."), gfx::Image(), base::string16(), GURL(), | 339 ASCIIToUTF16("New message."), gfx::Image(), base::string16(), GURL(), |
338 DummyNotifierId(), message_center::RichNotificationData(), NULL)); | 340 DummyNotifierId(), message_center::RichNotificationData(), NULL)); |
339 center_->UpdateNotification("1", std::move(notification)); | 341 center_->UpdateNotification("1", std::move(notification)); |
340 | 342 |
341 // Release the popup collection before the animation ends. No crash should | 343 // Release the popup collection before the animation ends. No crash should |
342 // be expected. | 344 // be expected. |
343 collection_.reset(); | 345 collection_.reset(); |
344 } | 346 } |
345 | 347 |
346 } // namespace message_center | 348 } // namespace message_center |
OLD | NEW |