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

Side by Side Diff: chrome/browser/extensions/api/notifications/notifications_apitest.cc

Issue 2703213004: Migrate extension notifications to the new NotificationDisplayService (Closed)
Patch Set: Finish functionality Created 3 years, 10 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/strings/string_number_conversions.h" 5 #include "base/strings/string_number_conversions.h"
6 #include "base/strings/stringprintf.h" 6 #include "base/strings/stringprintf.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/test/scoped_feature_list.h" 8 #include "base/test/scoped_feature_list.h"
9 #include "chrome/browser/apps/app_browsertest_util.h" 9 #include "chrome/browser/apps/app_browsertest_util.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/extensions/api/notifications/extension_notification_dis play_helper.h"
11 #include "chrome/browser/extensions/api/notifications/extension_notification_dis play_helper_factory.h"
11 #include "chrome/browser/extensions/api/notifications/notifications_api.h" 12 #include "chrome/browser/extensions/api/notifications/notifications_api.h"
12 #include "chrome/browser/extensions/extension_apitest.h" 13 #include "chrome/browser/extensions/extension_apitest.h"
13 #include "chrome/browser/extensions/extension_function_test_utils.h" 14 #include "chrome/browser/extensions/extension_function_test_utils.h"
14 #include "chrome/browser/notifications/notification.h" 15 #include "chrome/browser/notifications/notification.h"
15 #include "chrome/browser/notifications/notification_ui_manager.h" 16 #include "chrome/browser/notifications/notification_common.h"
17 #include "chrome/browser/notifications/notification_display_service_factory.h"
18 #include "chrome/browser/notifications/notifier_state_tracker.h"
19 #include "chrome/browser/notifications/notifier_state_tracker_factory.h"
20 #include "chrome/browser/notifications/stub_notification_display_service.h"
16 #include "chrome/browser/profiles/profile_manager.h" 21 #include "chrome/browser/profiles/profile_manager.h"
17 #include "chrome/browser/ui/extensions/app_launch_params.h" 22 #include "chrome/browser/ui/extensions/app_launch_params.h"
18 #include "chrome/browser/ui/extensions/application_launch.h" 23 #include "chrome/browser/ui/extensions/application_launch.h"
19 #include "chrome/common/chrome_features.h" 24 #include "chrome/common/chrome_features.h"
20 #include "chrome/test/base/interactive_test_utils.h" 25 #include "chrome/test/base/interactive_test_utils.h"
21 #include "content/public/browser/notification_service.h" 26 #include "content/public/browser/notification_service.h"
22 #include "content/public/test/test_utils.h" 27 #include "content/public/test/test_utils.h"
23 #include "extensions/browser/api/test/test_api.h" 28 #include "extensions/browser/api/test/test_api.h"
24 #include "extensions/browser/app_window/app_window.h" 29 #include "extensions/browser/app_window/app_window.h"
25 #include "extensions/browser/app_window/app_window_registry.h" 30 #include "extensions/browser/app_window/app_window_registry.h"
26 #include "extensions/browser/app_window/native_app_window.h" 31 #include "extensions/browser/app_window/native_app_window.h"
27 #include "extensions/browser/notification_types.h" 32 #include "extensions/browser/notification_types.h"
28 #include "extensions/common/features/feature.h" 33 #include "extensions/common/features/feature.h"
29 #include "extensions/common/test_util.h" 34 #include "extensions/common/test_util.h"
30 #include "extensions/test/extension_test_message_listener.h" 35 #include "extensions/test/extension_test_message_listener.h"
31 #include "extensions/test/result_catcher.h" 36 #include "extensions/test/result_catcher.h"
32 #include "ui/message_center/message_center.h"
33 #include "ui/message_center/notification_list.h"
34 #include "ui/message_center/notifier_settings.h" 37 #include "ui/message_center/notifier_settings.h"
35 38
36 #if defined(OS_MACOSX) 39 #if defined(OS_MACOSX)
37 #include "base/mac/mac_util.h" 40 #include "base/mac/mac_util.h"
38 #include "ui/base/test/scoped_fake_nswindow_fullscreen.h" 41 #include "ui/base/test/scoped_fake_nswindow_fullscreen.h"
39 #endif 42 #endif
40 43
41 using extensions::AppWindow; 44 using extensions::AppWindow;
42 using extensions::AppWindowRegistry; 45 using extensions::AppWindowRegistry;
43 using extensions::Extension; 46 using extensions::Extension;
47 using extensions::ExtensionNotificationDisplayHelper;
48 using extensions::ExtensionNotificationDisplayHelperFactory;
44 using extensions::ResultCatcher; 49 using extensions::ResultCatcher;
45 50
46 namespace utils = extension_function_test_utils; 51 namespace utils = extension_function_test_utils;
47 52
48 namespace { 53 namespace {
49 54
50 // A class that waits for a |chrome.test.sendMessage| call, ignores the message, 55 // A class that waits for a |chrome.test.sendMessage| call, ignores the message,
51 // and writes down the user gesture status of the message. 56 // and writes down the user gesture status of the message.
52 class UserGestureCatcher : public content::NotificationObserver { 57 class UserGestureCatcher : public content::NotificationObserver {
53 public: 58 public:
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 AppWindowRegistry::AppWindowList app_windows = AppWindowRegistry::Get( 152 AppWindowRegistry::AppWindowList app_windows = AppWindowRegistry::Get(
148 browser()->profile())->GetAppWindowsForApp(app_id); 153 browser()->profile())->GetAppWindowsForApp(app_id);
149 154
150 AppWindowRegistry::const_iterator iter = app_windows.begin(); 155 AppWindowRegistry::const_iterator iter = app_windows.begin();
151 if (iter != app_windows.end()) 156 if (iter != app_windows.end())
152 return *iter; 157 return *iter;
153 158
154 return NULL; 159 return NULL;
155 } 160 }
156 161
162 ExtensionNotificationDisplayHelper* GetDisplayHelper() {
163 return ExtensionNotificationDisplayHelperFactory::GetForProfile(profile());
164 }
165
166 StubNotificationDisplayService* GetDisplayService() {
167 return reinterpret_cast<StubNotificationDisplayService*>(
168 NotificationDisplayServiceFactory::GetForProfile(profile()));
169 }
170
171 NotifierStateTracker* GetNotifierStateTracker() {
172 return NotifierStateTrackerFactory::GetForProfile(profile());
173 }
174
157 protected: 175 protected:
176 void SetUpOnMainThread() override {
177 ExtensionApiTest::SetUpOnMainThread();
178
179 DCHECK(profile());
180 NotificationDisplayServiceFactory::GetInstance()->SetTestingFactory(
181 profile(), &StubNotificationDisplayService::FactoryForTests);
182 }
183
158 std::string GetNotificationIdFromDelegateId(const std::string& delegate_id) { 184 std::string GetNotificationIdFromDelegateId(const std::string& delegate_id) {
159 return g_browser_process->notification_ui_manager() 185 return GetDisplayHelper()->GetByNotificationId(delegate_id)->id();
160 ->FindById(
161 delegate_id,
162 NotificationUIManager::GetProfileID(
163 g_browser_process->profile_manager()->GetLastUsedProfile()))
164 ->id();
165 } 186 }
166 187
167 void LaunchPlatformApp(const Extension* extension) { 188 void LaunchPlatformApp(const Extension* extension) {
168 OpenApplication(AppLaunchParams( 189 OpenApplication(AppLaunchParams(
169 browser()->profile(), extension, extensions::LAUNCH_CONTAINER_NONE, 190 browser()->profile(), extension, extensions::LAUNCH_CONTAINER_NONE,
170 WindowOpenDisposition::NEW_WINDOW, extensions::SOURCE_TEST)); 191 WindowOpenDisposition::NEW_WINDOW, extensions::SOURCE_TEST));
171 } 192 }
172 193
173 void EnableFullscreenNotifications() { 194 void EnableFullscreenNotifications() {
174 feature_list_.InitWithFeatures({ 195 feature_list_.InitWithFeatures({
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 229
209 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestByUser) { 230 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestByUser) {
210 const extensions::Extension* extension = 231 const extensions::Extension* extension =
211 LoadExtensionAndWait("notifications/api/by_user"); 232 LoadExtensionAndWait("notifications/api/by_user");
212 ASSERT_TRUE(extension) << message_; 233 ASSERT_TRUE(extension) << message_;
213 234
214 { 235 {
215 ResultCatcher catcher; 236 ResultCatcher catcher;
216 const std::string notification_id = 237 const std::string notification_id =
217 GetNotificationIdFromDelegateId(extension->id() + "-FOO"); 238 GetNotificationIdFromDelegateId(extension->id() + "-FOO");
218 g_browser_process->message_center()->RemoveNotification(notification_id, 239 GetDisplayService()->RemoveNotification(
219 false); 240 NotificationCommon::EXTENSION, notification_id, false /* by_user */);
220 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 241 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
221 } 242 }
222 243
223 { 244 {
224 ResultCatcher catcher; 245 ResultCatcher catcher;
225 const std::string notification_id = 246 const std::string notification_id =
226 GetNotificationIdFromDelegateId(extension->id() + "-BAR"); 247 GetNotificationIdFromDelegateId(extension->id() + "-BAR");
227 g_browser_process->message_center()->RemoveNotification(notification_id, 248 GetDisplayService()->RemoveNotification(
228 true); 249 NotificationCommon::EXTENSION, notification_id, true /* by_user */);
229 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 250 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
230 } 251 }
231 252
232 { 253 {
233 ResultCatcher catcher; 254 ResultCatcher catcher;
234 g_browser_process->message_center()->RemoveAllNotifications( 255 GetDisplayService()->RemoveAllNotifications(NotificationCommon::EXTENSION,
235 false /* by_user */, message_center::MessageCenter::RemoveType::ALL); 256 false /* by_user */);
236 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 257 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
237 } 258 }
238 { 259 {
239 ResultCatcher catcher; 260 ResultCatcher catcher;
240 g_browser_process->message_center()->RemoveAllNotifications( 261 GetDisplayService()->RemoveAllNotifications(NotificationCommon::EXTENSION,
241 true /* by_user */, message_center::MessageCenter::RemoveType::ALL); 262 true /* by_user */);
242 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 263 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
243 } 264 }
244 } 265 }
245 266
246 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestPartialUpdate) { 267 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestPartialUpdate) {
247 ASSERT_TRUE(RunExtensionTest("notifications/api/partial_update")) << message_; 268 ASSERT_TRUE(RunExtensionTest("notifications/api/partial_update")) << message_;
248 const extensions::Extension* extension = GetSingleLoadedExtension(); 269 const extensions::Extension* extension = GetSingleLoadedExtension();
249 ASSERT_TRUE(extension) << message_; 270 ASSERT_TRUE(extension) << message_;
250 271
251 const char kNewTitle[] = "Changed!"; 272 const char kNewTitle[] = "Changed!";
252 const char kNewMessage[] = "Too late! The show ended yesterday"; 273 const char kNewMessage[] = "Too late! The show ended yesterday";
253 int kNewPriority = 2; 274 int kNewPriority = 2;
254 const char kButtonTitle[] = "NewButton"; 275 const char kButtonTitle[] = "NewButton";
255 276
256 const message_center::NotificationList::Notifications& notifications = 277 const auto& notifications = GetDisplayHelper()->GetNotificationsForTests();
257 g_browser_process->message_center()->GetVisibleNotifications();
258 ASSERT_EQ(1u, notifications.size()); 278 ASSERT_EQ(1u, notifications.size());
259 message_center::Notification* notification = *(notifications.begin()); 279 Notification* notification = notifications.front().get();
260 ASSERT_EQ(extension->url(), notification->origin_url()); 280 ASSERT_EQ(extension->url(), notification->origin_url());
261 281
262 LOG(INFO) << "Notification ID: " << notification->id(); 282 LOG(INFO) << "Notification ID: " << notification->id();
263 283
264 EXPECT_EQ(base::ASCIIToUTF16(kNewTitle), notification->title()); 284 EXPECT_EQ(base::ASCIIToUTF16(kNewTitle), notification->title());
265 EXPECT_EQ(base::ASCIIToUTF16(kNewMessage), notification->message()); 285 EXPECT_EQ(base::ASCIIToUTF16(kNewMessage), notification->message());
266 EXPECT_EQ(kNewPriority, notification->priority()); 286 EXPECT_EQ(kNewPriority, notification->priority());
267 EXPECT_EQ(1u, notification->buttons().size()); 287 EXPECT_EQ(1u, notification->buttons().size());
268 EXPECT_EQ(base::ASCIIToUTF16(kButtonTitle), notification->buttons()[0].title); 288 EXPECT_EQ(base::ASCIIToUTF16(kButtonTitle), notification->buttons()[0].title);
269 } 289 }
(...skipping 25 matching lines...) Expand all
295 scoped_refptr<extensions::NotificationsGetPermissionLevelFunction> 315 scoped_refptr<extensions::NotificationsGetPermissionLevelFunction>
296 notification_function( 316 notification_function(
297 new extensions::NotificationsGetPermissionLevelFunction()); 317 new extensions::NotificationsGetPermissionLevelFunction());
298 318
299 notification_function->set_extension(empty_extension.get()); 319 notification_function->set_extension(empty_extension.get());
300 notification_function->set_has_callback(true); 320 notification_function->set_has_callback(true);
301 321
302 message_center::NotifierId notifier_id( 322 message_center::NotifierId notifier_id(
303 message_center::NotifierId::APPLICATION, 323 message_center::NotifierId::APPLICATION,
304 empty_extension->id()); 324 empty_extension->id());
305 message_center::Notifier notifier(notifier_id, base::string16(), true); 325 GetNotifierStateTracker()->SetNotifierEnabled(notifier_id, false);
306 g_browser_process->message_center()->GetNotifierSettingsProvider()->
307 SetNotifierEnabled(notifier, false);
308 326
309 std::unique_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( 327 std::unique_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
310 notification_function.get(), "[]", browser(), utils::NONE)); 328 notification_function.get(), "[]", browser(), utils::NONE));
311 329
312 EXPECT_EQ(base::Value::Type::STRING, result->GetType()); 330 EXPECT_EQ(base::Value::Type::STRING, result->GetType());
313 std::string permission_level; 331 std::string permission_level;
314 EXPECT_TRUE(result->GetAsString(&permission_level)); 332 EXPECT_TRUE(result->GetAsString(&permission_level));
315 EXPECT_EQ("denied", permission_level); 333 EXPECT_EQ("denied", permission_level);
316 } 334 }
317 } 335 }
318 336
319 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestOnPermissionLevelChanged) { 337 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestOnPermissionLevelChanged) {
320 const extensions::Extension* extension = 338 const extensions::Extension* extension =
321 LoadExtensionAndWait("notifications/api/permission"); 339 LoadExtensionAndWait("notifications/api/permission");
322 ASSERT_TRUE(extension) << message_; 340 ASSERT_TRUE(extension) << message_;
323 341
324 // Test permission level changing from granted to denied. 342 // Test permission level changing from granted to denied.
325 { 343 {
326 ResultCatcher catcher; 344 ResultCatcher catcher;
327 345
328 message_center::NotifierId notifier_id( 346 message_center::NotifierId notifier_id(
329 message_center::NotifierId::APPLICATION, 347 message_center::NotifierId::APPLICATION,
330 extension->id()); 348 extension->id());
331 message_center::Notifier notifier(notifier_id, base::string16(), true); 349 GetNotifierStateTracker()->SetNotifierEnabled(notifier_id, false);
332 g_browser_process->message_center()->GetNotifierSettingsProvider()->
333 SetNotifierEnabled(notifier, false);
334 350
335 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 351 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
336 } 352 }
337 353
338 // Test permission level changing from denied to granted. 354 // Test permission level changing from denied to granted.
339 { 355 {
340 ResultCatcher catcher; 356 ResultCatcher catcher;
341 357
342 message_center::NotifierId notifier_id( 358 message_center::NotifierId notifier_id(
343 message_center::NotifierId::APPLICATION, 359 message_center::NotifierId::APPLICATION,
344 extension->id()); 360 extension->id());
345 message_center::Notifier notifier(notifier_id, base::string16(), false); 361 GetNotifierStateTracker()->SetNotifierEnabled(notifier_id, true);
346 g_browser_process->message_center()->GetNotifierSettingsProvider()->
347 SetNotifierEnabled(notifier, true);
348 362
349 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 363 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
350 } 364 }
351 } 365 }
352 366
353 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestUserGesture) { 367 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestUserGesture) {
354 const extensions::Extension* extension = 368 const extensions::Extension* extension =
355 LoadExtensionAndWait("notifications/api/user_gesture"); 369 LoadExtensionAndWait("notifications/api/user_gesture");
356 ASSERT_TRUE(extension) << message_; 370 ASSERT_TRUE(extension) << message_;
357 371
358 const message_center::NotificationList::Notifications& notifications = 372 const auto& notifications = GetDisplayHelper()->GetNotificationsForTests();
359 g_browser_process->message_center()->GetVisibleNotifications();
360 ASSERT_EQ(1u, notifications.size()); 373 ASSERT_EQ(1u, notifications.size());
361 message_center::Notification* notification = *(notifications.begin()); 374 Notification* notification = notifications.front().get();
362 ASSERT_EQ(extension->url(), notification->origin_url()); 375 ASSERT_EQ(extension->url(), notification->origin_url());
363 376
364 { 377 {
365 UserGestureCatcher catcher; 378 UserGestureCatcher catcher;
366 notification->ButtonClick(0); 379 notification->ButtonClick(0);
367 EXPECT_TRUE(catcher.GetNextResult()); 380 EXPECT_TRUE(catcher.GetNextResult());
368 notification->Click(); 381 notification->Click();
369 EXPECT_TRUE(catcher.GetNextResult()); 382 EXPECT_TRUE(catcher.GetNextResult());
370 notification->Close(true); 383 notification->Close(true /* by_user */);
371 EXPECT_TRUE(catcher.GetNextResult()); 384 EXPECT_TRUE(catcher.GetNextResult());
372 notification->Close(false); 385
373 EXPECT_FALSE(catcher.GetNextResult()); 386 // Note that |notification| no longer points to valid memory.
374 } 387 }
388
389 ASSERT_EQ(0u, GetDisplayHelper()->GetNotificationsForTests().size());
375 } 390 }
376 391
377 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestRequireInteraction) { 392 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestRequireInteraction) {
378 const extensions::Extension* extension = 393 const extensions::Extension* extension =
379 LoadExtensionAndWait("notifications/api/require_interaction"); 394 LoadExtensionAndWait("notifications/api/require_interaction");
380 ASSERT_TRUE(extension) << message_; 395 ASSERT_TRUE(extension) << message_;
381 396
382 const message_center::NotificationList::Notifications& notifications = 397 const auto& notifications = GetDisplayHelper()->GetNotificationsForTests();
383 g_browser_process->message_center()->GetVisibleNotifications();
384 ASSERT_EQ(1u, notifications.size()); 398 ASSERT_EQ(1u, notifications.size());
385 message_center::Notification* notification = *(notifications.begin()); 399 Notification* notification = notifications.front().get();
386 ASSERT_EQ(extension->url(), notification->origin_url()); 400 ASSERT_EQ(extension->url(), notification->origin_url());
387 401
388 EXPECT_TRUE(notification->never_timeout()); 402 EXPECT_TRUE(notification->never_timeout());
389 } 403 }
390 404
391 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayNormal) { 405 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayNormal) {
392 EnableFullscreenNotifications(); 406 EnableFullscreenNotifications();
393 ExtensionTestMessageListener notification_created_listener("created", false); 407 ExtensionTestMessageListener notification_created_listener("created", false);
394 const Extension* extension = LoadAppWithWindowState( 408 const Extension* extension = LoadAppWithWindowState(
395 "notifications/api/basic_app", WindowState::NORMAL); 409 "notifications/api/basic_app", WindowState::NORMAL);
396 ASSERT_TRUE(extension) << message_; 410 ASSERT_TRUE(extension) << message_;
397 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied()); 411 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied());
398 412
399 // We start by making sure the window is actually focused. 413 // We start by making sure the window is actually focused.
400 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( 414 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
401 GetFirstAppWindow(extension->id())->GetNativeWindow())); 415 GetFirstAppWindow(extension->id())->GetNativeWindow()));
402 416
403 const message_center::NotificationList::Notifications& notifications = 417 const auto& notifications = GetDisplayHelper()->GetNotificationsForTests();
404 g_browser_process->message_center()->GetVisibleNotifications();
405 ASSERT_EQ(1u, notifications.size()); 418 ASSERT_EQ(1u, notifications.size());
406 message_center::Notification* notification = *(notifications.begin()); 419
407 // If the app hasn't created a fullscreen window, then its notifications 420 // If the app hasn't created a fullscreen window, then its notifications
408 // shouldn't be displayed when a window is fullscreen. 421 // shouldn't be displayed when a window is fullscreen.
409 ASSERT_FALSE(notification->delegate()->ShouldDisplayOverFullscreen()); 422 ASSERT_FALSE(notifications[0]->delegate()->ShouldDisplayOverFullscreen());
410 } 423 }
411 424
412 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayFullscreen) { 425 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayFullscreen) {
413 #if defined(OS_MACOSX) 426 #if defined(OS_MACOSX)
414 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen; 427 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen;
415 #endif 428 #endif
416 EnableFullscreenNotifications(); 429 EnableFullscreenNotifications();
417 ExtensionTestMessageListener notification_created_listener("created", false); 430 ExtensionTestMessageListener notification_created_listener("created", false);
418 const Extension* extension = LoadAppWithWindowState( 431 const Extension* extension = LoadAppWithWindowState(
419 "notifications/api/basic_app", WindowState::FULLSCREEN); 432 "notifications/api/basic_app", WindowState::FULLSCREEN);
420 ASSERT_TRUE(extension) << message_; 433 ASSERT_TRUE(extension) << message_;
421 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied()); 434 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied());
422 435
423 // We start by making sure the window is actually focused. 436 // We start by making sure the window is actually focused.
424 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( 437 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
425 GetFirstAppWindow(extension->id())->GetNativeWindow())); 438 GetFirstAppWindow(extension->id())->GetNativeWindow()));
426 439
427 ASSERT_TRUE(GetFirstAppWindow(extension->id())->IsFullscreen()) 440 ASSERT_TRUE(GetFirstAppWindow(extension->id())->IsFullscreen())
428 << "Not Fullscreen"; 441 << "Not Fullscreen";
429 ASSERT_TRUE(GetFirstAppWindow(extension->id())->GetBaseWindow()->IsActive()) 442 ASSERT_TRUE(GetFirstAppWindow(extension->id())->GetBaseWindow()->IsActive())
430 << "Not Active"; 443 << "Not Active";
431 444
432 const message_center::NotificationList::Notifications& notifications = 445 const auto& notifications = GetDisplayHelper()->GetNotificationsForTests();
433 g_browser_process->message_center()->GetVisibleNotifications();
434 ASSERT_EQ(1u, notifications.size()); 446 ASSERT_EQ(1u, notifications.size());
435 message_center::Notification* notification = *(notifications.begin()); 447
436 // If the app has created a fullscreen window, then its notifications should 448 // If the app has created a fullscreen window, then its notifications should
437 // be displayed when a window is fullscreen. 449 // be displayed when a window is fullscreen.
438 ASSERT_TRUE(notification->delegate()->ShouldDisplayOverFullscreen()); 450 ASSERT_TRUE(notifications[0]->delegate()->ShouldDisplayOverFullscreen());
439 } 451 }
440 452
441 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayFullscreenOff) { 453 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayFullscreenOff) {
442 #if defined(OS_MACOSX) 454 #if defined(OS_MACOSX)
443 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen; 455 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen;
444 #endif 456 #endif
445 DisableFullscreenNotifications(); 457 DisableFullscreenNotifications();
446 ExtensionTestMessageListener notification_created_listener("created", false); 458 ExtensionTestMessageListener notification_created_listener("created", false);
447 const Extension* extension = LoadAppWithWindowState( 459 const Extension* extension = LoadAppWithWindowState(
448 "notifications/api/basic_app", WindowState::FULLSCREEN); 460 "notifications/api/basic_app", WindowState::FULLSCREEN);
449 ASSERT_TRUE(extension) << message_; 461 ASSERT_TRUE(extension) << message_;
450 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied()); 462 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied());
451 463
452 // We start by making sure the window is actually focused. 464 // We start by making sure the window is actually focused.
453 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( 465 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
454 GetFirstAppWindow(extension->id())->GetNativeWindow())); 466 GetFirstAppWindow(extension->id())->GetNativeWindow()));
455 467
456 ASSERT_TRUE(GetFirstAppWindow(extension->id())->IsFullscreen()) 468 ASSERT_TRUE(GetFirstAppWindow(extension->id())->IsFullscreen())
457 << "Not Fullscreen"; 469 << "Not Fullscreen";
458 ASSERT_TRUE(GetFirstAppWindow(extension->id())->GetBaseWindow()->IsActive()) 470 ASSERT_TRUE(GetFirstAppWindow(extension->id())->GetBaseWindow()->IsActive())
459 << "Not Active"; 471 << "Not Active";
460 472
461 const message_center::NotificationList::Notifications& notifications = 473 const auto& notifications = GetDisplayHelper()->GetNotificationsForTests();
462 g_browser_process->message_center()->GetVisibleNotifications();
463 ASSERT_EQ(1u, notifications.size()); 474 ASSERT_EQ(1u, notifications.size());
464 message_center::Notification* notification = *(notifications.begin()); 475
465 // When the experiment flag is off, then ShouldDisplayOverFullscreen should 476 // When the experiment flag is off, then ShouldDisplayOverFullscreen should
466 // return false. 477 // return false.
467 ASSERT_FALSE(notification->delegate()->ShouldDisplayOverFullscreen()); 478 ASSERT_FALSE(notifications[0]->delegate()->ShouldDisplayOverFullscreen());
468 } 479 }
469 480
470 // The Fake OSX fullscreen window doesn't like drawing a second fullscreen 481 // The Fake OSX fullscreen window doesn't like drawing a second fullscreen
471 // window when another is visible. 482 // window when another is visible.
472 #if !defined(OS_MACOSX) 483 #if !defined(OS_MACOSX)
473 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayMultiFullscreen) { 484 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayMultiFullscreen) {
474 // Start a fullscreen app, and then start another fullscreen app on top of the 485 // Start a fullscreen app, and then start another fullscreen app on top of the
475 // first. Notifications from the first should not be displayed because it is 486 // first. Notifications from the first should not be displayed because it is
476 // not the app actually displaying on the screen. 487 // not the app actually displaying on the screen.
477 EnableFullscreenNotifications(); 488 EnableFullscreenNotifications();
478 ExtensionTestMessageListener notification_created_listener("created", false); 489 ExtensionTestMessageListener notification_created_listener("created", false);
479 const Extension* extension1 = LoadAppWithWindowState( 490 const Extension* extension1 = LoadAppWithWindowState(
480 "notifications/api/basic_app", WindowState::FULLSCREEN); 491 "notifications/api/basic_app", WindowState::FULLSCREEN);
481 ASSERT_TRUE(extension1) << message_; 492 ASSERT_TRUE(extension1) << message_;
482 493
483 ExtensionTestMessageListener window_visible_listener("visible", false); 494 ExtensionTestMessageListener window_visible_listener("visible", false);
484 const Extension* extension2 = LoadAppWithWindowState( 495 const Extension* extension2 = LoadAppWithWindowState(
485 "notifications/api/other_app", WindowState::FULLSCREEN); 496 "notifications/api/other_app", WindowState::FULLSCREEN);
486 ASSERT_TRUE(extension2) << message_; 497 ASSERT_TRUE(extension2) << message_;
487 498
488 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied()); 499 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied());
489 ASSERT_TRUE(window_visible_listener.WaitUntilSatisfied()); 500 ASSERT_TRUE(window_visible_listener.WaitUntilSatisfied());
490 501
491 // We start by making sure the window is actually focused. 502 // We start by making sure the window is actually focused.
492 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( 503 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
493 GetFirstAppWindow(extension2->id())->GetNativeWindow())); 504 GetFirstAppWindow(extension2->id())->GetNativeWindow()));
494 505
495 const message_center::NotificationList::Notifications& notifications = 506 const auto& notifications = GetDisplayHelper()->GetNotificationsForTests();
496 g_browser_process->message_center()->GetVisibleNotifications();
497 ASSERT_EQ(1u, notifications.size()); 507 ASSERT_EQ(1u, notifications.size());
498 message_center::Notification* notification = *(notifications.begin()); 508
499 // The first app window is superseded by the second window, so its 509 // The first app window is superseded by the second window, so its
500 // notification shouldn't be displayed. 510 // notification shouldn't be displayed.
501 ASSERT_FALSE(notification->delegate()->ShouldDisplayOverFullscreen()); 511 ASSERT_FALSE(notifications[0]->delegate()->ShouldDisplayOverFullscreen());
502 } 512 }
503 #endif 513 #endif
504 514
505 // Verify that a notification is actually displayed when the app window that 515 // Verify that a notification is actually displayed when the app window that
506 // creates it is fullscreen with the fullscreen notification flag turned on. 516 // creates it is fullscreen with the fullscreen notification flag turned on.
507 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, 517 IN_PROC_BROWSER_TEST_F(NotificationsApiTest,
508 TestShouldDisplayPopupNotification) { 518 TestShouldDisplayPopupNotification) {
509 #if defined(OS_MACOSX) 519 #if defined(OS_MACOSX)
510 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen; 520 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen;
511 #endif 521 #endif
512 EnableFullscreenNotifications(); 522 EnableFullscreenNotifications();
513 ExtensionTestMessageListener notification_created_listener("created", false); 523 ExtensionTestMessageListener notification_created_listener("created", false);
514 const Extension* extension = LoadAppWithWindowState( 524 const Extension* extension = LoadAppWithWindowState(
515 "notifications/api/basic_app", WindowState::FULLSCREEN); 525 "notifications/api/basic_app", WindowState::FULLSCREEN);
516 ASSERT_TRUE(extension) << message_; 526 ASSERT_TRUE(extension) << message_;
517 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied()); 527 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied());
518 528
519 // We start by making sure the window is actually focused. 529 // We start by making sure the window is actually focused.
520 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( 530 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
521 GetFirstAppWindow(extension->id())->GetNativeWindow())); 531 GetFirstAppWindow(extension->id())->GetNativeWindow()));
522 532
523 ASSERT_TRUE(GetFirstAppWindow(extension->id())->IsFullscreen()) 533 ASSERT_TRUE(GetFirstAppWindow(extension->id())->IsFullscreen())
524 << "Not Fullscreen"; 534 << "Not Fullscreen";
525 ASSERT_TRUE(GetFirstAppWindow(extension->id())->GetBaseWindow()->IsActive()) 535 ASSERT_TRUE(GetFirstAppWindow(extension->id())->GetBaseWindow()->IsActive())
526 << "Not Active"; 536 << "Not Active";
527 537
528 const message_center::NotificationList::PopupNotifications notifications = 538 const auto& notifications = GetDisplayHelper()->GetNotificationsForTests();
529 g_browser_process->message_center()->GetPopupNotifications();
530 ASSERT_EQ(1u, notifications.size()); 539 ASSERT_EQ(1u, notifications.size());
540
541 // The extension's window is being shown and focused, so its expected that
542 // the notification displays on top of it.
543 ASSERT_TRUE(notifications[0]->delegate()->ShouldDisplayOverFullscreen());
531 } 544 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698