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

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

Issue 2813943002: Drop the const modifier on NotificationDisplayService::GetDisplayed (Closed)
Patch Set: sync and rebase Created 3 years, 8 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/bind.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 std::move(notification_bridge)); 106 std::move(notification_bridge));
107 } 107 }
108 108
109 void TearDown() override { 109 void TearDown() override {
110 profile_manager_.reset(); 110 profile_manager_.reset();
111 TestingBrowserProcess::DeleteInstance(); 111 TestingBrowserProcess::DeleteInstance();
112 } 112 }
113 113
114 void DidGetDisplayedNotifications( 114 void DidGetDisplayedNotifications(
115 std::unique_ptr<std::set<std::string>> displayed_notifications, 115 std::unique_ptr<std::set<std::string>> displayed_notifications,
116 bool supports_synchronization) const { 116 bool supports_synchronization) {
117 displayed_notifications_ = std::move(displayed_notifications); 117 displayed_notifications_ = std::move(displayed_notifications);
118 } 118 }
119 119
120 protected: 120 protected:
121 // Displays a simple, fake notifications and returns a weak pointer to the 121 // Displays a simple, fake notifications and returns a weak pointer to the
122 // delegate receiving events for it (ownership is transferred to the service). 122 // delegate receiving events for it (ownership is transferred to the service).
123 MockDesktopNotificationDelegate* CreateSimplePageNotification() const { 123 MockDesktopNotificationDelegate* CreateSimplePageNotification() const {
124 return CreateSimplePageNotificationWithCloseClosure(nullptr); 124 return CreateSimplePageNotificationWithCloseClosure(nullptr);
125 } 125 }
126 126
(...skipping 18 matching lines...) Expand all
145 } 145 }
146 146
147 // Returns the Platform Notification Service these unit tests are for. 147 // Returns the Platform Notification Service these unit tests are for.
148 PlatformNotificationServiceImpl* service() const { 148 PlatformNotificationServiceImpl* service() const {
149 return PlatformNotificationServiceImpl::GetInstance(); 149 return PlatformNotificationServiceImpl::GetInstance();
150 } 150 }
151 151
152 // Returns the Profile to be used for these tests. 152 // Returns the Profile to be used for these tests.
153 Profile* profile() const { return profile_; } 153 Profile* profile() const { return profile_; }
154 154
155 size_t GetNotificationCount() const { 155 size_t GetNotificationCount() {
156 display_service()->GetDisplayed(base::Bind( 156 display_service()->GetDisplayed(base::Bind(
157 &PlatformNotificationServiceTest::DidGetDisplayedNotifications, 157 &PlatformNotificationServiceTest::DidGetDisplayedNotifications,
158 base::Unretained(this))); 158 base::Unretained(this)));
159 base::RunLoop().RunUntilIdle(); 159 base::RunLoop().RunUntilIdle();
160 160
161 EXPECT_TRUE(displayed_notifications_.get()); 161 EXPECT_TRUE(displayed_notifications_.get());
162 return displayed_notifications_->size(); 162 return displayed_notifications_->size();
163 } 163 }
164 164
165 Notification GetDisplayedNotification() { 165 Notification GetDisplayedNotification() {
166 #if defined(OS_ANDROID) 166 #if defined(OS_ANDROID)
167 return static_cast<StubNotificationPlatformBridge*>( 167 return static_cast<StubNotificationPlatformBridge*>(
168 g_browser_process->notification_platform_bridge()) 168 g_browser_process->notification_platform_bridge())
169 ->GetNotificationAt(profile_->GetPath().BaseName().value(), 0); 169 ->GetNotificationAt(profile_->GetPath().BaseName().value(), 0);
170 #else 170 #else
171 return static_cast<StubNotificationUIManager*>( 171 return static_cast<StubNotificationUIManager*>(
172 g_browser_process->notification_ui_manager()) 172 g_browser_process->notification_ui_manager())
173 ->GetNotificationAt(0); 173 ->GetNotificationAt(0);
174 #endif 174 #endif
175 } 175 }
176 176
177 private: 177 private:
178 NotificationDisplayService* display_service() const { 178 NotificationDisplayService* display_service() const {
179 return NotificationDisplayServiceFactory::GetForProfile(profile_); 179 return NotificationDisplayServiceFactory::GetForProfile(profile_);
180 } 180 }
181 181
182 std::unique_ptr<TestingProfileManager> profile_manager_; 182 std::unique_ptr<TestingProfileManager> profile_manager_;
183 TestingProfile* profile_; 183 TestingProfile* profile_;
184 content::TestBrowserThreadBundle thread_bundle_; 184 content::TestBrowserThreadBundle thread_bundle_;
185 mutable std::unique_ptr<std::set<std::string>> displayed_notifications_; 185 std::unique_ptr<std::set<std::string>> displayed_notifications_;
186 }; 186 };
187 187
188 TEST_F(PlatformNotificationServiceTest, DisplayPageDisplayedEvent) { 188 TEST_F(PlatformNotificationServiceTest, DisplayPageDisplayedEvent) {
189 auto* delegate = CreateSimplePageNotification(); 189 auto* delegate = CreateSimplePageNotification();
190 190
191 EXPECT_EQ(1u, GetNotificationCount()); 191 EXPECT_EQ(1u, GetNotificationCount());
192 EXPECT_TRUE(delegate->displayed()); 192 EXPECT_TRUE(delegate->displayed());
193 } 193 }
194 194
195 TEST_F(PlatformNotificationServiceTest, DisplayPageCloseClosure) { 195 TEST_F(PlatformNotificationServiceTest, DisplayPageCloseClosure) {
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 profile(), 425 profile(),
426 GURL() /* service_worker_scope */, 426 GURL() /* service_worker_scope */,
427 GURL("chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"), 427 GURL("chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"),
428 notification_data, NotificationResources(), 428 notification_data, NotificationResources(),
429 new MockNotificationDelegate("hello")); 429 new MockNotificationDelegate("hello"));
430 EXPECT_EQ("NotificationTest", 430 EXPECT_EQ("NotificationTest",
431 base::UTF16ToUTF8(notification.context_message())); 431 base::UTF16ToUTF8(notification.context_message()));
432 } 432 }
433 433
434 #endif // BUILDFLAG(ENABLE_EXTENSIONS) 434 #endif // BUILDFLAG(ENABLE_EXTENSIONS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698