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/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/threading/platform_thread.h" | 12 #include "base/threading/platform_thread.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 16 #include "chrome/browser/notifications/message_center_display_service.h" |
16 #include "chrome/browser/notifications/notification_delegate.h" | 17 #include "chrome/browser/notifications/notification_delegate.h" |
17 #include "chrome/browser/notifications/notification_test_util.h" | 18 #include "chrome/browser/notifications/notification_test_util.h" |
18 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 19 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 20 #include "chrome/test/base/testing_browser_process.h" |
19 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
| 22 #include "chrome/test/base/testing_profile_manager.h" |
20 #include "components/content_settings/core/browser/host_content_settings_map.h" | 23 #include "components/content_settings/core/browser/host_content_settings_map.h" |
21 #include "content/public/browser/desktop_notification_delegate.h" | 24 #include "content/public/browser/desktop_notification_delegate.h" |
22 #include "content/public/common/notification_resources.h" | 25 #include "content/public/common/notification_resources.h" |
23 #include "content/public/common/platform_notification_data.h" | 26 #include "content/public/common/platform_notification_data.h" |
24 #include "content/public/test/test_browser_thread_bundle.h" | 27 #include "content/public/test/test_browser_thread_bundle.h" |
25 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
27 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" | 30 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" |
28 | 31 |
29 #if defined(ENABLE_EXTENSIONS) | 32 #if defined(ENABLE_EXTENSIONS) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 private: | 78 private: |
76 bool displayed_; | 79 bool displayed_; |
77 bool clicked_; | 80 bool clicked_; |
78 }; | 81 }; |
79 | 82 |
80 } // namespace | 83 } // namespace |
81 | 84 |
82 class PlatformNotificationServiceTest : public testing::Test { | 85 class PlatformNotificationServiceTest : public testing::Test { |
83 public: | 86 public: |
84 void SetUp() override { | 87 void SetUp() override { |
| 88 profile_.reset(new TestingProfile()); |
85 ui_manager_.reset(new StubNotificationUIManager); | 89 ui_manager_.reset(new StubNotificationUIManager); |
86 profile_.reset(new TestingProfile()); | 90 display_service_.reset( |
87 | 91 new MessageCenterDisplayService(profile_.get(), ui_manager_.get())); |
88 service()->SetNotificationUIManagerForTesting(ui_manager_.get()); | 92 service()->SetNotificationDisplayServiceForTesting(display_service_.get()); |
| 93 profile_manager_.reset( |
| 94 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); |
| 95 ASSERT_TRUE(profile_manager_->SetUp()); |
89 } | 96 } |
90 | 97 |
91 void TearDown() override { | 98 void TearDown() override { |
92 service()->SetNotificationUIManagerForTesting(nullptr); | 99 service()->SetNotificationDisplayServiceForTesting(nullptr); |
93 | 100 display_service_.reset(); |
| 101 ui_manager_.reset(); |
94 profile_.reset(); | 102 profile_.reset(); |
95 ui_manager_.reset(); | 103 profile_manager_.reset(); |
| 104 TestingBrowserProcess::DeleteInstance(); |
96 } | 105 } |
97 | 106 |
98 protected: | 107 protected: |
99 // Displays a simple, fake notifications and returns a weak pointer to the | 108 // Displays a simple, fake notifications and returns a weak pointer to the |
100 // delegate receiving events for it (ownership is transferred to the service). | 109 // delegate receiving events for it (ownership is transferred to the service). |
101 MockDesktopNotificationDelegate* CreateSimplePageNotification() const { | 110 MockDesktopNotificationDelegate* CreateSimplePageNotification() const { |
102 return CreateSimplePageNotificationWithCloseClosure(nullptr); | 111 return CreateSimplePageNotificationWithCloseClosure(nullptr); |
103 } | 112 } |
104 | 113 |
105 // Displays a simple, fake notification and returns a weak pointer to the | 114 // Displays a simple, fake notification and returns a weak pointer to the |
(...skipping 20 matching lines...) Expand all Loading... |
126 return PlatformNotificationServiceImpl::GetInstance(); | 135 return PlatformNotificationServiceImpl::GetInstance(); |
127 } | 136 } |
128 | 137 |
129 // Returns the Profile to be used for these tests. | 138 // Returns the Profile to be used for these tests. |
130 Profile* profile() const { return profile_.get(); } | 139 Profile* profile() const { return profile_.get(); } |
131 | 140 |
132 // Returns the UI Manager on which notifications will be displayed. | 141 // Returns the UI Manager on which notifications will be displayed. |
133 StubNotificationUIManager* ui_manager() const { return ui_manager_.get(); } | 142 StubNotificationUIManager* ui_manager() const { return ui_manager_.get(); } |
134 | 143 |
135 private: | 144 private: |
| 145 std::unique_ptr<TestingProfile> profile_; |
136 std::unique_ptr<StubNotificationUIManager> ui_manager_; | 146 std::unique_ptr<StubNotificationUIManager> ui_manager_; |
137 std::unique_ptr<TestingProfile> profile_; | 147 std::unique_ptr<MessageCenterDisplayService> display_service_; |
138 | 148 |
| 149 std::unique_ptr<TestingProfileManager> profile_manager_; |
139 content::TestBrowserThreadBundle thread_bundle_; | 150 content::TestBrowserThreadBundle thread_bundle_; |
140 }; | 151 }; |
141 | 152 |
142 TEST_F(PlatformNotificationServiceTest, DisplayPageDisplayedEvent) { | 153 TEST_F(PlatformNotificationServiceTest, DisplayPageDisplayedEvent) { |
143 auto* delegate = CreateSimplePageNotification(); | 154 auto* delegate = CreateSimplePageNotification(); |
144 | 155 |
145 EXPECT_EQ(1u, ui_manager()->GetNotificationCount()); | 156 EXPECT_EQ(1u, ui_manager()->GetNotificationCount()); |
146 EXPECT_TRUE(delegate->displayed()); | 157 EXPECT_TRUE(delegate->displayed()); |
147 } | 158 } |
148 | 159 |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 notification = service()->CreateNotificationFromData( | 412 notification = service()->CreateNotificationFromData( |
402 profile(), | 413 profile(), |
403 GURL("chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"), | 414 GURL("chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"), |
404 notification_data, NotificationResources(), | 415 notification_data, NotificationResources(), |
405 new MockNotificationDelegate("hello")); | 416 new MockNotificationDelegate("hello")); |
406 EXPECT_EQ("NotificationTest", | 417 EXPECT_EQ("NotificationTest", |
407 base::UTF16ToUTF8(notification.context_message())); | 418 base::UTF16ToUTF8(notification.context_message())); |
408 } | 419 } |
409 | 420 |
410 #endif // defined(ENABLE_EXTENSIONS) | 421 #endif // defined(ENABLE_EXTENSIONS) |
OLD | NEW |