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