Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: chrome/browser/notifications/platform_notification_service_unittest.cc

Issue 2749453002: Make GetDisplayedNotifications asynchronous. (Closed)
Patch Set: review Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/macros.h" 10 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/run_loop.h"
11 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
12 #include "base/threading/platform_thread.h" 14 #include "base/threading/platform_thread.h"
13 #include "base/time/time.h" 15 #include "base/time/time.h"
14 #include "build/build_config.h" 16 #include "build/build_config.h"
15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 17 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
16 #include "chrome/browser/notifications/message_center_display_service.h" 18 #include "chrome/browser/notifications/message_center_display_service.h"
17 #include "chrome/browser/notifications/notification_delegate.h" 19 #include "chrome/browser/notifications/notification_delegate.h"
18 #include "chrome/browser/notifications/notification_display_service_factory.h" 20 #include "chrome/browser/notifications/notification_display_service_factory.h"
19 #include "chrome/browser/notifications/notification_test_util.h" 21 #include "chrome/browser/notifications/notification_test_util.h"
20 #include "chrome/browser/notifications/platform_notification_service_impl.h" 22 #include "chrome/browser/notifications/platform_notification_service_impl.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 std::move(ui_manager)); 102 std::move(ui_manager));
101 TestingBrowserProcess::GetGlobal()->SetNotificationPlatformBridge( 103 TestingBrowserProcess::GetGlobal()->SetNotificationPlatformBridge(
102 std::move(notification_bridge)); 104 std::move(notification_bridge));
103 } 105 }
104 106
105 void TearDown() override { 107 void TearDown() override {
106 profile_manager_.reset(); 108 profile_manager_.reset();
107 TestingBrowserProcess::DeleteInstance(); 109 TestingBrowserProcess::DeleteInstance();
108 } 110 }
109 111
112 void DidGetDisplayedNotifications(
113 std::unique_ptr<std::set<std::string>> displayed_notifications,
114 bool supports_synchronization) const {
115 displayed_notifications_ = std::move(displayed_notifications);
116 }
117
110 protected: 118 protected:
111 // Displays a simple, fake notifications and returns a weak pointer to the 119 // Displays a simple, fake notifications and returns a weak pointer to the
112 // delegate receiving events for it (ownership is transferred to the service). 120 // delegate receiving events for it (ownership is transferred to the service).
113 MockDesktopNotificationDelegate* CreateSimplePageNotification() const { 121 MockDesktopNotificationDelegate* CreateSimplePageNotification() const {
114 return CreateSimplePageNotificationWithCloseClosure(nullptr); 122 return CreateSimplePageNotificationWithCloseClosure(nullptr);
115 } 123 }
116 124
117 // Displays a simple, fake notification and returns a weak pointer to the 125 // Displays a simple, fake notification and returns a weak pointer to the
118 // delegate receiving events for it (ownership is transferred to the service). 126 // delegate receiving events for it (ownership is transferred to the service).
119 // The close closure may be specified if so desired. 127 // The close closure may be specified if so desired.
(...skipping 16 matching lines...) Expand all
136 144
137 // Returns the Platform Notification Service these unit tests are for. 145 // Returns the Platform Notification Service these unit tests are for.
138 PlatformNotificationServiceImpl* service() const { 146 PlatformNotificationServiceImpl* service() const {
139 return PlatformNotificationServiceImpl::GetInstance(); 147 return PlatformNotificationServiceImpl::GetInstance();
140 } 148 }
141 149
142 // Returns the Profile to be used for these tests. 150 // Returns the Profile to be used for these tests.
143 Profile* profile() const { return profile_; } 151 Profile* profile() const { return profile_; }
144 152
145 size_t GetNotificationCount() const { 153 size_t GetNotificationCount() const {
146 std::set<std::string> notifications; 154 display_service()->GetDisplayed(base::Bind(
147 EXPECT_TRUE(display_service()->GetDisplayed(&notifications)); 155 &PlatformNotificationServiceTest::DidGetDisplayedNotifications,
148 return notifications.size(); 156 base::Unretained(this)));
157 base::RunLoop().RunUntilIdle();
158
159 EXPECT_TRUE(displayed_notifications_.get());
160 return displayed_notifications_->size();
149 } 161 }
150 162
151 Notification GetDisplayedNotification() { 163 Notification GetDisplayedNotification() {
152 #if defined(OS_ANDROID) 164 #if defined(OS_ANDROID)
153 return static_cast<StubNotificationPlatformBridge*>( 165 return static_cast<StubNotificationPlatformBridge*>(
154 g_browser_process->notification_platform_bridge()) 166 g_browser_process->notification_platform_bridge())
155 ->GetNotificationAt(profile_->GetPath().BaseName().value(), 0); 167 ->GetNotificationAt(profile_->GetPath().BaseName().value(), 0);
156 #else 168 #else
157 return static_cast<StubNotificationUIManager*>( 169 return static_cast<StubNotificationUIManager*>(
158 g_browser_process->notification_ui_manager()) 170 g_browser_process->notification_ui_manager())
159 ->GetNotificationAt(0); 171 ->GetNotificationAt(0);
160 #endif 172 #endif
161 } 173 }
162 174
163 private: 175 private:
164 NotificationDisplayService* display_service() const { 176 NotificationDisplayService* display_service() const {
165 return NotificationDisplayServiceFactory::GetForProfile(profile_); 177 return NotificationDisplayServiceFactory::GetForProfile(profile_);
166 } 178 }
167 179
168 std::unique_ptr<TestingProfileManager> profile_manager_; 180 std::unique_ptr<TestingProfileManager> profile_manager_;
169 TestingProfile* profile_; 181 TestingProfile* profile_;
170 content::TestBrowserThreadBundle thread_bundle_; 182 content::TestBrowserThreadBundle thread_bundle_;
183 mutable std::unique_ptr<std::set<std::string>> displayed_notifications_;
171 }; 184 };
172 185
173 TEST_F(PlatformNotificationServiceTest, DisplayPageDisplayedEvent) { 186 TEST_F(PlatformNotificationServiceTest, DisplayPageDisplayedEvent) {
174 auto* delegate = CreateSimplePageNotification(); 187 auto* delegate = CreateSimplePageNotification();
175 188
176 EXPECT_EQ(1u, GetNotificationCount()); 189 EXPECT_EQ(1u, GetNotificationCount());
177 EXPECT_TRUE(delegate->displayed()); 190 EXPECT_TRUE(delegate->displayed());
178 } 191 }
179 192
180 TEST_F(PlatformNotificationServiceTest, DisplayPageCloseClosure) { 193 TEST_F(PlatformNotificationServiceTest, DisplayPageCloseClosure) {
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 profile(), 423 profile(),
411 GURL() /* service_worker_scope */, 424 GURL() /* service_worker_scope */,
412 GURL("chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"), 425 GURL("chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"),
413 notification_data, NotificationResources(), 426 notification_data, NotificationResources(),
414 new MockNotificationDelegate("hello")); 427 new MockNotificationDelegate("hello"));
415 EXPECT_EQ("NotificationTest", 428 EXPECT_EQ("NotificationTest",
416 base::UTF16ToUTF8(notification.context_message())); 429 base::UTF16ToUTF8(notification.context_message()));
417 } 430 }
418 431
419 #endif // BUILDFLAG(ENABLE_EXTENSIONS) 432 #endif // BUILDFLAG(ENABLE_EXTENSIONS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698