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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 using content::PlatformNotificationData; | 58 using content::PlatformNotificationData; |
59 | 59 |
60 namespace { | 60 namespace { |
61 | 61 |
62 const char kNotificationId[] = "my-notification-id"; | 62 const char kNotificationId[] = "my-notification-id"; |
63 const int kNotificationVibrationPattern[] = { 100, 200, 300 }; | 63 const int kNotificationVibrationPattern[] = { 100, 200, 300 }; |
64 | 64 |
65 class MockDesktopNotificationDelegate | 65 class MockDesktopNotificationDelegate |
66 : public content::DesktopNotificationDelegate { | 66 : public content::DesktopNotificationDelegate { |
67 public: | 67 public: |
68 MockDesktopNotificationDelegate() | 68 MockDesktopNotificationDelegate() : displayed_(false) {} |
69 : displayed_(false), | |
70 clicked_(false) {} | |
71 | 69 |
72 ~MockDesktopNotificationDelegate() override {} | 70 ~MockDesktopNotificationDelegate() override {} |
73 | 71 |
74 // content::DesktopNotificationDelegate implementation. | 72 // content::DesktopNotificationDelegate implementation. |
75 void NotificationDisplayed() override { displayed_ = true; } | 73 void NotificationDisplayed() override { displayed_ = true; } |
76 void NotificationClosed() override {} | 74 void NotificationClosed() override {} |
77 void NotificationClick() override { clicked_ = true; } | 75 void NotificationClick() override {} |
78 | 76 |
79 bool displayed() const { return displayed_; } | 77 bool displayed() const { return displayed_; } |
80 bool clicked() const { return clicked_; } | |
81 | 78 |
82 private: | 79 private: |
83 bool displayed_; | 80 bool displayed_; |
84 bool clicked_; | |
85 | 81 |
86 DISALLOW_COPY_AND_ASSIGN(MockDesktopNotificationDelegate); | 82 DISALLOW_COPY_AND_ASSIGN(MockDesktopNotificationDelegate); |
87 }; | 83 }; |
88 | 84 |
89 } // namespace | 85 } // namespace |
90 | 86 |
91 class PlatformNotificationServiceTest : public testing::Test { | 87 class PlatformNotificationServiceTest : public testing::Test { |
92 public: | 88 public: |
93 void SetUp() override { | 89 void SetUp() override { |
94 profile_manager_ = base::MakeUnique<TestingProfileManager>( | 90 profile_manager_ = base::MakeUnique<TestingProfileManager>( |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 NotificationDisplayService* display_service() const { | 182 NotificationDisplayService* display_service() const { |
187 return NotificationDisplayServiceFactory::GetForProfile(profile_); | 183 return NotificationDisplayServiceFactory::GetForProfile(profile_); |
188 } | 184 } |
189 | 185 |
190 std::unique_ptr<TestingProfileManager> profile_manager_; | 186 std::unique_ptr<TestingProfileManager> profile_manager_; |
191 TestingProfile* profile_; | 187 TestingProfile* profile_; |
192 content::TestBrowserThreadBundle thread_bundle_; | 188 content::TestBrowserThreadBundle thread_bundle_; |
193 std::unique_ptr<std::set<std::string>> displayed_notifications_; | 189 std::unique_ptr<std::set<std::string>> displayed_notifications_; |
194 }; | 190 }; |
195 | 191 |
| 192 // Native, non persistent notifications don't have delegates any more |
| 193 #if !defined(OS_MACOSX) |
196 TEST_F(PlatformNotificationServiceTest, DisplayPageDisplayedEvent) { | 194 TEST_F(PlatformNotificationServiceTest, DisplayPageDisplayedEvent) { |
197 auto* delegate = CreateSimplePageNotification(); | 195 auto* delegate = CreateSimplePageNotification(); |
198 | 196 |
199 EXPECT_EQ(1u, GetNotificationCount()); | 197 EXPECT_EQ(1u, GetNotificationCount()); |
200 EXPECT_TRUE(delegate->displayed()); | 198 EXPECT_TRUE(delegate->displayed()); |
201 } | 199 } |
| 200 #endif // !defined(OS_MACOSX) |
202 | 201 |
203 TEST_F(PlatformNotificationServiceTest, DisplayPageCloseClosure) { | 202 TEST_F(PlatformNotificationServiceTest, DisplayPageCloseClosure) { |
204 base::Closure close_closure; | 203 base::Closure close_closure; |
205 CreateSimplePageNotificationWithCloseClosure(&close_closure); | 204 CreateSimplePageNotificationWithCloseClosure(&close_closure); |
206 | 205 |
207 EXPECT_EQ(1u, GetNotificationCount()); | 206 EXPECT_EQ(1u, GetNotificationCount()); |
208 | 207 |
209 ASSERT_FALSE(close_closure.is_null()); | 208 ASSERT_FALSE(close_closure.is_null()); |
210 close_closure.Run(); | 209 close_closure.Run(); |
211 | 210 |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 profile(), | 432 profile(), |
434 GURL() /* service_worker_scope */, | 433 GURL() /* service_worker_scope */, |
435 GURL("chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"), | 434 GURL("chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"), |
436 notification_data, NotificationResources(), | 435 notification_data, NotificationResources(), |
437 new MockNotificationDelegate("hello")); | 436 new MockNotificationDelegate("hello")); |
438 EXPECT_EQ("NotificationTest", | 437 EXPECT_EQ("NotificationTest", |
439 base::UTF16ToUTF8(notification.context_message())); | 438 base::UTF16ToUTF8(notification.context_message())); |
440 } | 439 } |
441 | 440 |
442 #endif // BUILDFLAG(ENABLE_EXTENSIONS) | 441 #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
OLD | NEW |