| OLD | NEW |
| 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 Loading... |
| 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 |
| 184 // Returns the notification that's being displayed for |extension|, or nullptr |
| 185 // when the notification count is not equal to one. It's not safe to rely on |
| 186 // the Notification pointer after closing the notification, but a copy can be |
| 187 // made to continue to be able to access the underlying information. |
| 188 Notification* GetNotificationForExtension( |
| 189 const extensions::Extension* extension) { |
| 190 DCHECK(extension); |
| 191 |
| 192 std::set<std::string> notifications = |
| 193 GetDisplayHelper()->GetNotificationIdsForExtension(extension->url()); |
| 194 if (notifications.size() != 1) |
| 195 return nullptr; |
| 196 |
| 197 return GetDisplayHelper()->GetByNotificationId(*notifications.begin()); |
| 198 } |
| 199 |
| 158 std::string GetNotificationIdFromDelegateId(const std::string& delegate_id) { | 200 std::string GetNotificationIdFromDelegateId(const std::string& delegate_id) { |
| 159 return g_browser_process->notification_ui_manager() | 201 return GetDisplayHelper()->GetByNotificationId(delegate_id)->id(); |
| 160 ->FindById( | |
| 161 delegate_id, | |
| 162 NotificationUIManager::GetProfileID( | |
| 163 g_browser_process->profile_manager()->GetLastUsedProfile())) | |
| 164 ->id(); | |
| 165 } | 202 } |
| 166 | 203 |
| 167 void LaunchPlatformApp(const Extension* extension) { | 204 void LaunchPlatformApp(const Extension* extension) { |
| 168 OpenApplication(AppLaunchParams( | 205 OpenApplication(AppLaunchParams( |
| 169 browser()->profile(), extension, extensions::LAUNCH_CONTAINER_NONE, | 206 browser()->profile(), extension, extensions::LAUNCH_CONTAINER_NONE, |
| 170 WindowOpenDisposition::NEW_WINDOW, extensions::SOURCE_TEST)); | 207 WindowOpenDisposition::NEW_WINDOW, extensions::SOURCE_TEST)); |
| 171 } | 208 } |
| 172 | 209 |
| 173 void EnableFullscreenNotifications() { | 210 void EnableFullscreenNotifications() { |
| 174 feature_list_.InitWithFeatures({ | 211 feature_list_.InitWithFeatures({ |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 | 245 |
| 209 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestByUser) { | 246 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestByUser) { |
| 210 const extensions::Extension* extension = | 247 const extensions::Extension* extension = |
| 211 LoadExtensionAndWait("notifications/api/by_user"); | 248 LoadExtensionAndWait("notifications/api/by_user"); |
| 212 ASSERT_TRUE(extension) << message_; | 249 ASSERT_TRUE(extension) << message_; |
| 213 | 250 |
| 214 { | 251 { |
| 215 ResultCatcher catcher; | 252 ResultCatcher catcher; |
| 216 const std::string notification_id = | 253 const std::string notification_id = |
| 217 GetNotificationIdFromDelegateId(extension->id() + "-FOO"); | 254 GetNotificationIdFromDelegateId(extension->id() + "-FOO"); |
| 218 g_browser_process->message_center()->RemoveNotification(notification_id, | 255 GetDisplayService()->RemoveNotification( |
| 219 false); | 256 NotificationCommon::EXTENSION, notification_id, false /* by_user */); |
| 220 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 257 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 221 } | 258 } |
| 222 | 259 |
| 223 { | 260 { |
| 224 ResultCatcher catcher; | 261 ResultCatcher catcher; |
| 225 const std::string notification_id = | 262 const std::string notification_id = |
| 226 GetNotificationIdFromDelegateId(extension->id() + "-BAR"); | 263 GetNotificationIdFromDelegateId(extension->id() + "-BAR"); |
| 227 g_browser_process->message_center()->RemoveNotification(notification_id, | 264 GetDisplayService()->RemoveNotification( |
| 228 true); | 265 NotificationCommon::EXTENSION, notification_id, true /* by_user */); |
| 229 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 266 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 230 } | 267 } |
| 231 | 268 |
| 232 { | 269 { |
| 233 ResultCatcher catcher; | 270 ResultCatcher catcher; |
| 234 g_browser_process->message_center()->RemoveAllNotifications( | 271 GetDisplayService()->RemoveAllNotifications(NotificationCommon::EXTENSION, |
| 235 false /* by_user */, message_center::MessageCenter::RemoveType::ALL); | 272 false /* by_user */); |
| 236 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 273 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 237 } | 274 } |
| 238 { | 275 { |
| 239 ResultCatcher catcher; | 276 ResultCatcher catcher; |
| 240 g_browser_process->message_center()->RemoveAllNotifications( | 277 GetDisplayService()->RemoveAllNotifications(NotificationCommon::EXTENSION, |
| 241 true /* by_user */, message_center::MessageCenter::RemoveType::ALL); | 278 true /* by_user */); |
| 242 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 279 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 243 } | 280 } |
| 244 } | 281 } |
| 245 | 282 |
| 246 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestPartialUpdate) { | 283 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestPartialUpdate) { |
| 247 ASSERT_TRUE(RunExtensionTest("notifications/api/partial_update")) << message_; | 284 ASSERT_TRUE(RunExtensionTest("notifications/api/partial_update")) << message_; |
| 248 const extensions::Extension* extension = GetSingleLoadedExtension(); | 285 const extensions::Extension* extension = GetSingleLoadedExtension(); |
| 249 ASSERT_TRUE(extension) << message_; | 286 ASSERT_TRUE(extension) << message_; |
| 250 | 287 |
| 251 const char kNewTitle[] = "Changed!"; | 288 const char kNewTitle[] = "Changed!"; |
| 252 const char kNewMessage[] = "Too late! The show ended yesterday"; | 289 const char kNewMessage[] = "Too late! The show ended yesterday"; |
| 253 int kNewPriority = 2; | 290 int kNewPriority = 2; |
| 254 const char kButtonTitle[] = "NewButton"; | 291 const char kButtonTitle[] = "NewButton"; |
| 255 | 292 |
| 256 const message_center::NotificationList::Notifications& notifications = | 293 Notification* notification = GetNotificationForExtension(extension); |
| 257 g_browser_process->message_center()->GetVisibleNotifications(); | 294 ASSERT_TRUE(notification); |
| 258 ASSERT_EQ(1u, notifications.size()); | |
| 259 message_center::Notification* notification = *(notifications.begin()); | |
| 260 ASSERT_EQ(extension->url(), notification->origin_url()); | |
| 261 | 295 |
| 262 LOG(INFO) << "Notification ID: " << notification->id(); | 296 LOG(INFO) << "Notification ID: " << notification->id(); |
| 263 | 297 |
| 264 EXPECT_EQ(base::ASCIIToUTF16(kNewTitle), notification->title()); | 298 EXPECT_EQ(base::ASCIIToUTF16(kNewTitle), notification->title()); |
| 265 EXPECT_EQ(base::ASCIIToUTF16(kNewMessage), notification->message()); | 299 EXPECT_EQ(base::ASCIIToUTF16(kNewMessage), notification->message()); |
| 266 EXPECT_EQ(kNewPriority, notification->priority()); | 300 EXPECT_EQ(kNewPriority, notification->priority()); |
| 267 EXPECT_EQ(1u, notification->buttons().size()); | 301 EXPECT_EQ(1u, notification->buttons().size()); |
| 268 EXPECT_EQ(base::ASCIIToUTF16(kButtonTitle), notification->buttons()[0].title); | 302 EXPECT_EQ(base::ASCIIToUTF16(kButtonTitle), notification->buttons()[0].title); |
| 269 } | 303 } |
| 270 | 304 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 295 scoped_refptr<extensions::NotificationsGetPermissionLevelFunction> | 329 scoped_refptr<extensions::NotificationsGetPermissionLevelFunction> |
| 296 notification_function( | 330 notification_function( |
| 297 new extensions::NotificationsGetPermissionLevelFunction()); | 331 new extensions::NotificationsGetPermissionLevelFunction()); |
| 298 | 332 |
| 299 notification_function->set_extension(empty_extension.get()); | 333 notification_function->set_extension(empty_extension.get()); |
| 300 notification_function->set_has_callback(true); | 334 notification_function->set_has_callback(true); |
| 301 | 335 |
| 302 message_center::NotifierId notifier_id( | 336 message_center::NotifierId notifier_id( |
| 303 message_center::NotifierId::APPLICATION, | 337 message_center::NotifierId::APPLICATION, |
| 304 empty_extension->id()); | 338 empty_extension->id()); |
| 305 message_center::Notifier notifier(notifier_id, base::string16(), true); | 339 GetNotifierStateTracker()->SetNotifierEnabled(notifier_id, false); |
| 306 g_browser_process->message_center()->GetNotifierSettingsProvider()-> | |
| 307 SetNotifierEnabled(notifier, false); | |
| 308 | 340 |
| 309 std::unique_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( | 341 std::unique_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
| 310 notification_function.get(), "[]", browser(), utils::NONE)); | 342 notification_function.get(), "[]", browser(), utils::NONE)); |
| 311 | 343 |
| 312 EXPECT_EQ(base::Value::Type::STRING, result->GetType()); | 344 EXPECT_EQ(base::Value::Type::STRING, result->GetType()); |
| 313 std::string permission_level; | 345 std::string permission_level; |
| 314 EXPECT_TRUE(result->GetAsString(&permission_level)); | 346 EXPECT_TRUE(result->GetAsString(&permission_level)); |
| 315 EXPECT_EQ("denied", permission_level); | 347 EXPECT_EQ("denied", permission_level); |
| 316 } | 348 } |
| 317 } | 349 } |
| 318 | 350 |
| 319 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestOnPermissionLevelChanged) { | 351 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestOnPermissionLevelChanged) { |
| 320 const extensions::Extension* extension = | 352 const extensions::Extension* extension = |
| 321 LoadExtensionAndWait("notifications/api/permission"); | 353 LoadExtensionAndWait("notifications/api/permission"); |
| 322 ASSERT_TRUE(extension) << message_; | 354 ASSERT_TRUE(extension) << message_; |
| 323 | 355 |
| 324 // Test permission level changing from granted to denied. | 356 // Test permission level changing from granted to denied. |
| 325 { | 357 { |
| 326 ResultCatcher catcher; | 358 ResultCatcher catcher; |
| 327 | 359 |
| 328 message_center::NotifierId notifier_id( | 360 message_center::NotifierId notifier_id( |
| 329 message_center::NotifierId::APPLICATION, | 361 message_center::NotifierId::APPLICATION, |
| 330 extension->id()); | 362 extension->id()); |
| 331 message_center::Notifier notifier(notifier_id, base::string16(), true); | 363 GetNotifierStateTracker()->SetNotifierEnabled(notifier_id, false); |
| 332 g_browser_process->message_center()->GetNotifierSettingsProvider()-> | |
| 333 SetNotifierEnabled(notifier, false); | |
| 334 | 364 |
| 335 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 365 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 336 } | 366 } |
| 337 | 367 |
| 338 // Test permission level changing from denied to granted. | 368 // Test permission level changing from denied to granted. |
| 339 { | 369 { |
| 340 ResultCatcher catcher; | 370 ResultCatcher catcher; |
| 341 | 371 |
| 342 message_center::NotifierId notifier_id( | 372 message_center::NotifierId notifier_id( |
| 343 message_center::NotifierId::APPLICATION, | 373 message_center::NotifierId::APPLICATION, |
| 344 extension->id()); | 374 extension->id()); |
| 345 message_center::Notifier notifier(notifier_id, base::string16(), false); | 375 GetNotifierStateTracker()->SetNotifierEnabled(notifier_id, true); |
| 346 g_browser_process->message_center()->GetNotifierSettingsProvider()-> | |
| 347 SetNotifierEnabled(notifier, true); | |
| 348 | 376 |
| 349 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 377 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 350 } | 378 } |
| 351 } | 379 } |
| 352 | 380 |
| 353 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestUserGesture) { | 381 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestUserGesture) { |
| 354 const extensions::Extension* extension = | 382 const extensions::Extension* extension = |
| 355 LoadExtensionAndWait("notifications/api/user_gesture"); | 383 LoadExtensionAndWait("notifications/api/user_gesture"); |
| 356 ASSERT_TRUE(extension) << message_; | 384 ASSERT_TRUE(extension) << message_; |
| 357 | 385 |
| 358 const message_center::NotificationList::Notifications& notifications = | 386 Notification* notification = GetNotificationForExtension(extension); |
| 359 g_browser_process->message_center()->GetVisibleNotifications(); | 387 ASSERT_TRUE(notification); |
| 360 ASSERT_EQ(1u, notifications.size()); | |
| 361 message_center::Notification* notification = *(notifications.begin()); | |
| 362 ASSERT_EQ(extension->url(), notification->origin_url()); | |
| 363 | 388 |
| 364 { | 389 { |
| 365 UserGestureCatcher catcher; | 390 UserGestureCatcher catcher; |
| 366 notification->ButtonClick(0); | 391 notification->ButtonClick(0); |
| 367 EXPECT_TRUE(catcher.GetNextResult()); | 392 EXPECT_TRUE(catcher.GetNextResult()); |
| 368 notification->Click(); | 393 notification->Click(); |
| 369 EXPECT_TRUE(catcher.GetNextResult()); | 394 EXPECT_TRUE(catcher.GetNextResult()); |
| 370 notification->Close(true); | 395 notification->Close(true /* by_user */); |
| 371 EXPECT_TRUE(catcher.GetNextResult()); | 396 EXPECT_TRUE(catcher.GetNextResult()); |
| 372 notification->Close(false); | 397 |
| 373 EXPECT_FALSE(catcher.GetNextResult()); | 398 // Note that |notification| no longer points to valid memory. |
| 374 } | 399 } |
| 400 |
| 401 ASSERT_FALSE(GetNotificationForExtension(extension)); |
| 375 } | 402 } |
| 376 | 403 |
| 377 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestRequireInteraction) { | 404 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestRequireInteraction) { |
| 378 const extensions::Extension* extension = | 405 const extensions::Extension* extension = |
| 379 LoadExtensionAndWait("notifications/api/require_interaction"); | 406 LoadExtensionAndWait("notifications/api/require_interaction"); |
| 380 ASSERT_TRUE(extension) << message_; | 407 ASSERT_TRUE(extension) << message_; |
| 381 | 408 |
| 382 const message_center::NotificationList::Notifications& notifications = | 409 Notification* notification = GetNotificationForExtension(extension); |
| 383 g_browser_process->message_center()->GetVisibleNotifications(); | 410 ASSERT_TRUE(notification); |
| 384 ASSERT_EQ(1u, notifications.size()); | |
| 385 message_center::Notification* notification = *(notifications.begin()); | |
| 386 ASSERT_EQ(extension->url(), notification->origin_url()); | |
| 387 | 411 |
| 388 EXPECT_TRUE(notification->never_timeout()); | 412 EXPECT_TRUE(notification->never_timeout()); |
| 389 } | 413 } |
| 390 | 414 |
| 391 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayNormal) { | 415 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayNormal) { |
| 392 EnableFullscreenNotifications(); | 416 EnableFullscreenNotifications(); |
| 393 ExtensionTestMessageListener notification_created_listener("created", false); | 417 ExtensionTestMessageListener notification_created_listener("created", false); |
| 394 const Extension* extension = LoadAppWithWindowState( | 418 const Extension* extension = LoadAppWithWindowState( |
| 395 "notifications/api/basic_app", WindowState::NORMAL); | 419 "notifications/api/basic_app", WindowState::NORMAL); |
| 396 ASSERT_TRUE(extension) << message_; | 420 ASSERT_TRUE(extension) << message_; |
| 397 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied()); | 421 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied()); |
| 398 | 422 |
| 399 // We start by making sure the window is actually focused. | 423 // We start by making sure the window is actually focused. |
| 400 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( | 424 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( |
| 401 GetFirstAppWindow(extension->id())->GetNativeWindow())); | 425 GetFirstAppWindow(extension->id())->GetNativeWindow())); |
| 402 | 426 |
| 403 const message_center::NotificationList::Notifications& notifications = | 427 Notification* notification = GetNotificationForExtension(extension); |
| 404 g_browser_process->message_center()->GetVisibleNotifications(); | 428 ASSERT_TRUE(notification); |
| 405 ASSERT_EQ(1u, notifications.size()); | 429 |
| 406 message_center::Notification* notification = *(notifications.begin()); | |
| 407 // If the app hasn't created a fullscreen window, then its notifications | 430 // If the app hasn't created a fullscreen window, then its notifications |
| 408 // shouldn't be displayed when a window is fullscreen. | 431 // shouldn't be displayed when a window is fullscreen. |
| 409 ASSERT_FALSE(notification->delegate()->ShouldDisplayOverFullscreen()); | 432 ASSERT_FALSE(notification->delegate()->ShouldDisplayOverFullscreen()); |
| 410 } | 433 } |
| 411 | 434 |
| 412 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayFullscreen) { | 435 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayFullscreen) { |
| 413 #if defined(OS_MACOSX) | 436 #if defined(OS_MACOSX) |
| 414 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen; | 437 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen; |
| 415 #endif | 438 #endif |
| 416 EnableFullscreenNotifications(); | 439 EnableFullscreenNotifications(); |
| 417 ExtensionTestMessageListener notification_created_listener("created", false); | 440 ExtensionTestMessageListener notification_created_listener("created", false); |
| 418 const Extension* extension = LoadAppWithWindowState( | 441 const Extension* extension = LoadAppWithWindowState( |
| 419 "notifications/api/basic_app", WindowState::FULLSCREEN); | 442 "notifications/api/basic_app", WindowState::FULLSCREEN); |
| 420 ASSERT_TRUE(extension) << message_; | 443 ASSERT_TRUE(extension) << message_; |
| 421 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied()); | 444 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied()); |
| 422 | 445 |
| 423 // We start by making sure the window is actually focused. | 446 // We start by making sure the window is actually focused. |
| 424 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( | 447 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( |
| 425 GetFirstAppWindow(extension->id())->GetNativeWindow())); | 448 GetFirstAppWindow(extension->id())->GetNativeWindow())); |
| 426 | 449 |
| 427 ASSERT_TRUE(GetFirstAppWindow(extension->id())->IsFullscreen()) | 450 ASSERT_TRUE(GetFirstAppWindow(extension->id())->IsFullscreen()) |
| 428 << "Not Fullscreen"; | 451 << "Not Fullscreen"; |
| 429 ASSERT_TRUE(GetFirstAppWindow(extension->id())->GetBaseWindow()->IsActive()) | 452 ASSERT_TRUE(GetFirstAppWindow(extension->id())->GetBaseWindow()->IsActive()) |
| 430 << "Not Active"; | 453 << "Not Active"; |
| 431 | 454 |
| 432 const message_center::NotificationList::Notifications& notifications = | 455 Notification* notification = GetNotificationForExtension(extension); |
| 433 g_browser_process->message_center()->GetVisibleNotifications(); | 456 ASSERT_TRUE(notification); |
| 434 ASSERT_EQ(1u, notifications.size()); | 457 |
| 435 message_center::Notification* notification = *(notifications.begin()); | |
| 436 // If the app has created a fullscreen window, then its notifications should | 458 // If the app has created a fullscreen window, then its notifications should |
| 437 // be displayed when a window is fullscreen. | 459 // be displayed when a window is fullscreen. |
| 438 ASSERT_TRUE(notification->delegate()->ShouldDisplayOverFullscreen()); | 460 ASSERT_TRUE(notification->delegate()->ShouldDisplayOverFullscreen()); |
| 439 } | 461 } |
| 440 | 462 |
| 441 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayFullscreenOff) { | 463 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayFullscreenOff) { |
| 442 #if defined(OS_MACOSX) | 464 #if defined(OS_MACOSX) |
| 443 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen; | 465 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen; |
| 444 #endif | 466 #endif |
| 445 DisableFullscreenNotifications(); | 467 DisableFullscreenNotifications(); |
| 446 ExtensionTestMessageListener notification_created_listener("created", false); | 468 ExtensionTestMessageListener notification_created_listener("created", false); |
| 447 const Extension* extension = LoadAppWithWindowState( | 469 const Extension* extension = LoadAppWithWindowState( |
| 448 "notifications/api/basic_app", WindowState::FULLSCREEN); | 470 "notifications/api/basic_app", WindowState::FULLSCREEN); |
| 449 ASSERT_TRUE(extension) << message_; | 471 ASSERT_TRUE(extension) << message_; |
| 450 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied()); | 472 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied()); |
| 451 | 473 |
| 452 // We start by making sure the window is actually focused. | 474 // We start by making sure the window is actually focused. |
| 453 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( | 475 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( |
| 454 GetFirstAppWindow(extension->id())->GetNativeWindow())); | 476 GetFirstAppWindow(extension->id())->GetNativeWindow())); |
| 455 | 477 |
| 456 ASSERT_TRUE(GetFirstAppWindow(extension->id())->IsFullscreen()) | 478 ASSERT_TRUE(GetFirstAppWindow(extension->id())->IsFullscreen()) |
| 457 << "Not Fullscreen"; | 479 << "Not Fullscreen"; |
| 458 ASSERT_TRUE(GetFirstAppWindow(extension->id())->GetBaseWindow()->IsActive()) | 480 ASSERT_TRUE(GetFirstAppWindow(extension->id())->GetBaseWindow()->IsActive()) |
| 459 << "Not Active"; | 481 << "Not Active"; |
| 460 | 482 |
| 461 const message_center::NotificationList::Notifications& notifications = | 483 Notification* notification = GetNotificationForExtension(extension); |
| 462 g_browser_process->message_center()->GetVisibleNotifications(); | 484 ASSERT_TRUE(notification); |
| 463 ASSERT_EQ(1u, notifications.size()); | 485 |
| 464 message_center::Notification* notification = *(notifications.begin()); | |
| 465 // When the experiment flag is off, then ShouldDisplayOverFullscreen should | 486 // When the experiment flag is off, then ShouldDisplayOverFullscreen should |
| 466 // return false. | 487 // return false. |
| 467 ASSERT_FALSE(notification->delegate()->ShouldDisplayOverFullscreen()); | 488 ASSERT_FALSE(notification->delegate()->ShouldDisplayOverFullscreen()); |
| 468 } | 489 } |
| 469 | 490 |
| 470 // The Fake OSX fullscreen window doesn't like drawing a second fullscreen | 491 // The Fake OSX fullscreen window doesn't like drawing a second fullscreen |
| 471 // window when another is visible. | 492 // window when another is visible. |
| 472 #if !defined(OS_MACOSX) | 493 #if !defined(OS_MACOSX) |
| 473 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayMultiFullscreen) { | 494 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestShouldDisplayMultiFullscreen) { |
| 474 // Start a fullscreen app, and then start another fullscreen app on top of the | 495 // Start a fullscreen app, and then start another fullscreen app on top of the |
| (...skipping 10 matching lines...) Expand all Loading... |
| 485 "notifications/api/other_app", WindowState::FULLSCREEN); | 506 "notifications/api/other_app", WindowState::FULLSCREEN); |
| 486 ASSERT_TRUE(extension2) << message_; | 507 ASSERT_TRUE(extension2) << message_; |
| 487 | 508 |
| 488 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied()); | 509 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied()); |
| 489 ASSERT_TRUE(window_visible_listener.WaitUntilSatisfied()); | 510 ASSERT_TRUE(window_visible_listener.WaitUntilSatisfied()); |
| 490 | 511 |
| 491 // We start by making sure the window is actually focused. | 512 // We start by making sure the window is actually focused. |
| 492 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( | 513 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( |
| 493 GetFirstAppWindow(extension2->id())->GetNativeWindow())); | 514 GetFirstAppWindow(extension2->id())->GetNativeWindow())); |
| 494 | 515 |
| 495 const message_center::NotificationList::Notifications& notifications = | 516 Notification* notification = GetNotificationForExtension(extension1); |
| 496 g_browser_process->message_center()->GetVisibleNotifications(); | 517 ASSERT_TRUE(notification); |
| 497 ASSERT_EQ(1u, notifications.size()); | 518 |
| 498 message_center::Notification* notification = *(notifications.begin()); | |
| 499 // The first app window is superseded by the second window, so its | 519 // The first app window is superseded by the second window, so its |
| 500 // notification shouldn't be displayed. | 520 // notification shouldn't be displayed. |
| 501 ASSERT_FALSE(notification->delegate()->ShouldDisplayOverFullscreen()); | 521 ASSERT_FALSE(notification->delegate()->ShouldDisplayOverFullscreen()); |
| 502 } | 522 } |
| 503 #endif | 523 #endif |
| 504 | 524 |
| 505 // Verify that a notification is actually displayed when the app window that | 525 // Verify that a notification is actually displayed when the app window that |
| 506 // creates it is fullscreen with the fullscreen notification flag turned on. | 526 // creates it is fullscreen with the fullscreen notification flag turned on. |
| 507 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, | 527 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, |
| 508 TestShouldDisplayPopupNotification) { | 528 TestShouldDisplayPopupNotification) { |
| 509 #if defined(OS_MACOSX) | 529 #if defined(OS_MACOSX) |
| 510 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen; | 530 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen; |
| 511 #endif | 531 #endif |
| 512 EnableFullscreenNotifications(); | 532 EnableFullscreenNotifications(); |
| 513 ExtensionTestMessageListener notification_created_listener("created", false); | 533 ExtensionTestMessageListener notification_created_listener("created", false); |
| 514 const Extension* extension = LoadAppWithWindowState( | 534 const Extension* extension = LoadAppWithWindowState( |
| 515 "notifications/api/basic_app", WindowState::FULLSCREEN); | 535 "notifications/api/basic_app", WindowState::FULLSCREEN); |
| 516 ASSERT_TRUE(extension) << message_; | 536 ASSERT_TRUE(extension) << message_; |
| 517 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied()); | 537 ASSERT_TRUE(notification_created_listener.WaitUntilSatisfied()); |
| 518 | 538 |
| 519 // We start by making sure the window is actually focused. | 539 // We start by making sure the window is actually focused. |
| 520 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( | 540 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( |
| 521 GetFirstAppWindow(extension->id())->GetNativeWindow())); | 541 GetFirstAppWindow(extension->id())->GetNativeWindow())); |
| 522 | 542 |
| 523 ASSERT_TRUE(GetFirstAppWindow(extension->id())->IsFullscreen()) | 543 ASSERT_TRUE(GetFirstAppWindow(extension->id())->IsFullscreen()) |
| 524 << "Not Fullscreen"; | 544 << "Not Fullscreen"; |
| 525 ASSERT_TRUE(GetFirstAppWindow(extension->id())->GetBaseWindow()->IsActive()) | 545 ASSERT_TRUE(GetFirstAppWindow(extension->id())->GetBaseWindow()->IsActive()) |
| 526 << "Not Active"; | 546 << "Not Active"; |
| 527 | 547 |
| 528 const message_center::NotificationList::PopupNotifications notifications = | 548 Notification* notification = GetNotificationForExtension(extension); |
| 529 g_browser_process->message_center()->GetPopupNotifications(); | 549 ASSERT_TRUE(notification); |
| 530 ASSERT_EQ(1u, notifications.size()); | 550 |
| 551 // The extension's window is being shown and focused, so its expected that |
| 552 // the notification displays on top of it. |
| 553 ASSERT_TRUE(notification->delegate()->ShouldDisplayOverFullscreen()); |
| 531 } | 554 } |
| OLD | NEW |