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