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