| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <memory> | 5 #include <memory> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
| 14 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/test/scoped_feature_list.h" | 16 #include "base/test/scoped_feature_list.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "chrome/browser/engagement/site_engagement_score.h" |
| 19 #include "chrome/browser/engagement/site_engagement_service.h" |
| 18 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 20 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
| 19 #include "chrome/browser/notifications/message_center_display_service.h" | 21 #include "chrome/browser/notifications/message_center_display_service.h" |
| 20 #include "chrome/browser/notifications/notification.h" | 22 #include "chrome/browser/notifications/notification.h" |
| 21 #include "chrome/browser/notifications/notification_test_util.h" | 23 #include "chrome/browser/notifications/notification_test_util.h" |
| 22 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 24 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 23 #include "chrome/browser/notifications/web_notification_delegate.h" | 25 #include "chrome/browser/notifications/web_notification_delegate.h" |
| 24 #include "chrome/browser/permissions/permission_manager.h" | 26 #include "chrome/browser/permissions/permission_manager.h" |
| 25 #include "chrome/browser/permissions/permission_request_manager.h" | 27 #include "chrome/browser/permissions/permission_request_manager.h" |
| 26 #include "chrome/browser/permissions/permission_result.h" | 28 #include "chrome/browser/permissions/permission_result.h" |
| 27 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 // Grants permission to display Web Notifications for origin of the test | 82 // Grants permission to display Web Notifications for origin of the test |
| 81 // page that's being used in this browser test. | 83 // page that's being used in this browser test. |
| 82 void GrantNotificationPermissionForTest() const; | 84 void GrantNotificationPermissionForTest() const; |
| 83 | 85 |
| 84 bool RequestAndAcceptPermission(); | 86 bool RequestAndAcceptPermission(); |
| 85 bool RequestAndDenyPermission(); | 87 bool RequestAndDenyPermission(); |
| 86 | 88 |
| 87 void EnableFullscreenNotifications(); | 89 void EnableFullscreenNotifications(); |
| 88 void DisableFullscreenNotifications(); | 90 void DisableFullscreenNotifications(); |
| 89 | 91 |
| 92 double GetEngagementScore(const GURL& origin) const; |
| 93 GURL GetLastCommittedURL() const; |
| 94 |
| 90 // Returns the UI Manager on which notifications will be displayed. | 95 // Returns the UI Manager on which notifications will be displayed. |
| 91 StubNotificationUIManager* ui_manager() const { return ui_manager_.get(); } | 96 StubNotificationUIManager* ui_manager() const { return ui_manager_.get(); } |
| 92 | 97 |
| 93 const base::FilePath& server_root() const { return server_root_; } | 98 const base::FilePath& server_root() const { return server_root_; } |
| 94 | 99 |
| 95 // Navigates the browser to the test page indicated by |path|. | 100 // Navigates the browser to the test page indicated by |path|. |
| 96 void NavigateToTestPage(const std::string& path) const; | 101 void NavigateToTestPage(const std::string& path) const; |
| 97 | 102 |
| 98 // Executes |script| and stores the result as a string in |result|. A boolean | 103 // Executes |script| and stores the result as a string in |result|. A boolean |
| 99 // will be returned, indicating whether the script was executed successfully. | 104 // will be returned, indicating whether the script was executed successfully. |
| 100 bool RunScript(const std::string& script, std::string* result) const; | 105 bool RunScript(const std::string& script, std::string* result) const; |
| 101 | 106 |
| 102 net::HostPortPair ServerHostPort() const; | 107 net::HostPortPair ServerHostPort() const; |
| 103 GURL TestPageUrl() const; | 108 GURL TestPageUrl() const; |
| 104 | 109 |
| 105 private: | 110 private: |
| 106 std::string RequestAndRespondToPermission( | 111 std::string RequestAndRespondToPermission( |
| 107 PermissionRequestManager::AutoResponseType bubble_response); | 112 PermissionRequestManager::AutoResponseType bubble_response); |
| 108 | 113 |
| 109 content::WebContents* GetActiveWebContents(Browser* browser) { | 114 content::WebContents* GetActiveWebContents(Browser* browser) { |
| 110 return browser->tab_strip_model()->GetActiveWebContents(); | 115 return browser->tab_strip_model()->GetActiveWebContents(); |
| 111 } | 116 } |
| 112 | 117 |
| 118 SiteEngagementService* engagement_service_; |
| 113 const base::FilePath server_root_; | 119 const base::FilePath server_root_; |
| 114 const std::string test_page_url_; | 120 const std::string test_page_url_; |
| 115 std::unique_ptr<StubNotificationUIManager> ui_manager_; | 121 std::unique_ptr<StubNotificationUIManager> ui_manager_; |
| 116 std::unique_ptr<MessageCenterDisplayService> display_service_; | 122 std::unique_ptr<MessageCenterDisplayService> display_service_; |
| 117 std::unique_ptr<net::EmbeddedTestServer> https_server_; | 123 std::unique_ptr<net::EmbeddedTestServer> https_server_; |
| 118 base::test::ScopedFeatureList feature_list_; | 124 base::test::ScopedFeatureList feature_list_; |
| 119 }; | 125 }; |
| 120 | 126 |
| 121 // ----------------------------------------------------------------------------- | 127 // ----------------------------------------------------------------------------- |
| 122 | 128 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 140 void PlatformNotificationServiceBrowserTest::SetUp() { | 146 void PlatformNotificationServiceBrowserTest::SetUp() { |
| 141 ui_manager_.reset(new StubNotificationUIManager); | 147 ui_manager_.reset(new StubNotificationUIManager); |
| 142 https_server_.reset( | 148 https_server_.reset( |
| 143 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); | 149 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); |
| 144 https_server_->ServeFilesFromSourceDirectory(server_root_); | 150 https_server_->ServeFilesFromSourceDirectory(server_root_); |
| 145 ASSERT_TRUE(https_server_->Start()); | 151 ASSERT_TRUE(https_server_->Start()); |
| 146 InProcessBrowserTest::SetUp(); | 152 InProcessBrowserTest::SetUp(); |
| 147 } | 153 } |
| 148 | 154 |
| 149 void PlatformNotificationServiceBrowserTest::SetUpOnMainThread() { | 155 void PlatformNotificationServiceBrowserTest::SetUpOnMainThread() { |
| 156 SiteEngagementScore::SetParamValuesForTesting(); |
| 157 engagement_service_ = SiteEngagementService::Get(browser()->profile()); |
| 150 NavigateToTestPage(test_page_url_); | 158 NavigateToTestPage(test_page_url_); |
| 151 display_service_.reset( | 159 display_service_.reset( |
| 152 new MessageCenterDisplayService(browser()->profile(), ui_manager_.get())); | 160 new MessageCenterDisplayService(browser()->profile(), ui_manager_.get())); |
| 153 service()->SetNotificationDisplayServiceForTesting(display_service_.get()); | 161 service()->SetNotificationDisplayServiceForTesting(display_service_.get()); |
| 154 InProcessBrowserTest::SetUpOnMainThread(); | 162 InProcessBrowserTest::SetUpOnMainThread(); |
| 155 } | 163 } |
| 156 | 164 |
| 157 void PlatformNotificationServiceBrowserTest::TearDown() { | 165 void PlatformNotificationServiceBrowserTest::TearDown() { |
| 158 service()->SetNotificationDisplayServiceForTesting(nullptr); | 166 service()->SetNotificationDisplayServiceForTesting(nullptr); |
| 159 } | 167 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 features::kPreferHtmlOverPlugins, | 228 features::kPreferHtmlOverPlugins, |
| 221 features::kAllowFullscreenWebNotificationsFeature}, {}); | 229 features::kAllowFullscreenWebNotificationsFeature}, {}); |
| 222 } | 230 } |
| 223 | 231 |
| 224 void PlatformNotificationServiceBrowserTest::DisableFullscreenNotifications() { | 232 void PlatformNotificationServiceBrowserTest::DisableFullscreenNotifications() { |
| 225 feature_list_.InitWithFeatures( | 233 feature_list_.InitWithFeatures( |
| 226 {features::kPreferHtmlOverPlugins}, | 234 {features::kPreferHtmlOverPlugins}, |
| 227 {features::kAllowFullscreenWebNotificationsFeature}); | 235 {features::kAllowFullscreenWebNotificationsFeature}); |
| 228 } | 236 } |
| 229 | 237 |
| 238 double PlatformNotificationServiceBrowserTest::GetEngagementScore( |
| 239 const GURL& origin) const { |
| 240 return engagement_service_->GetScore(origin); |
| 241 } |
| 242 |
| 243 GURL PlatformNotificationServiceBrowserTest::GetLastCommittedURL() const { |
| 244 return browser() |
| 245 ->tab_strip_model() |
| 246 ->GetActiveWebContents() |
| 247 ->GetLastCommittedURL(); |
| 248 } |
| 249 |
| 230 // ----------------------------------------------------------------------------- | 250 // ----------------------------------------------------------------------------- |
| 231 | 251 |
| 232 // TODO(peter): Move PlatformNotificationService-related tests over from | 252 // TODO(peter): Move PlatformNotificationService-related tests over from |
| 233 // notification_browsertest.cc to this file. | 253 // notification_browsertest.cc to this file. |
| 234 | 254 |
| 235 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, | 255 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, |
| 236 DisplayPersistentNotificationWithoutPermission) { | 256 DisplayPersistentNotificationWithoutPermission) { |
| 237 RequestAndDenyPermission(); | 257 RequestAndDenyPermission(); |
| 238 | 258 |
| 239 std::string script_result; | 259 std::string script_result; |
| 240 ASSERT_TRUE(RunScript("DisplayPersistentNotification()", &script_result)); | 260 ASSERT_TRUE(RunScript("DisplayPersistentNotification()", &script_result)); |
| 241 EXPECT_EQ( | 261 EXPECT_EQ( |
| 242 "TypeError: No notification permission has been granted for this origin.", | 262 "TypeError: No notification permission has been granted for this origin.", |
| 243 script_result); | 263 script_result); |
| 244 | 264 |
| 245 ASSERT_EQ(0u, ui_manager()->GetNotificationCount()); | 265 ASSERT_EQ(0u, ui_manager()->GetNotificationCount()); |
| 246 } | 266 } |
| 247 | 267 |
| 248 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, | 268 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, |
| 249 DisplayPersistentNotificationWithPermission) { | 269 DisplayPersistentNotificationWithPermission) { |
| 250 RequestAndAcceptPermission(); | 270 RequestAndAcceptPermission(); |
| 251 | 271 |
| 272 // Expect 5 engagement for notification permission and 0.5 for the navigation. |
| 273 EXPECT_DOUBLE_EQ(5.5, GetEngagementScore(GetLastCommittedURL())); |
| 274 |
| 252 std::string script_result; | 275 std::string script_result; |
| 253 ASSERT_TRUE(RunScript("DisplayPersistentNotification('action_none')", | 276 ASSERT_TRUE(RunScript("DisplayPersistentNotification('action_none')", |
| 254 &script_result)); | 277 &script_result)); |
| 255 EXPECT_EQ("ok", script_result); | 278 EXPECT_EQ("ok", script_result); |
| 256 | 279 |
| 257 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); | 280 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); |
| 258 | 281 |
| 259 #if BUILDFLAG(ENABLE_BACKGROUND) | 282 #if BUILDFLAG(ENABLE_BACKGROUND) |
| 260 ASSERT_FALSE(KeepAliveRegistry::GetInstance()->IsOriginRegistered( | 283 ASSERT_FALSE(KeepAliveRegistry::GetInstance()->IsOriginRegistered( |
| 261 KeepAliveOrigin::PENDING_NOTIFICATION_CLICK_EVENT)); | 284 KeepAliveOrigin::PENDING_NOTIFICATION_CLICK_EVENT)); |
| 262 #endif | 285 #endif |
| 263 | 286 |
| 287 // We expect +1 engagement for the notification interaction. |
| 264 const Notification& notification = ui_manager()->GetNotificationAt(0); | 288 const Notification& notification = ui_manager()->GetNotificationAt(0); |
| 265 notification.delegate()->Click(); | 289 notification.delegate()->Click(); |
| 290 EXPECT_DOUBLE_EQ(6.5, GetEngagementScore(GetLastCommittedURL())); |
| 266 | 291 |
| 267 #if BUILDFLAG(ENABLE_BACKGROUND) | 292 #if BUILDFLAG(ENABLE_BACKGROUND) |
| 268 ASSERT_TRUE(KeepAliveRegistry::GetInstance()->IsOriginRegistered( | 293 ASSERT_TRUE(KeepAliveRegistry::GetInstance()->IsOriginRegistered( |
| 269 KeepAliveOrigin::PENDING_NOTIFICATION_CLICK_EVENT)); | 294 KeepAliveOrigin::PENDING_NOTIFICATION_CLICK_EVENT)); |
| 270 #endif | 295 #endif |
| 271 | 296 |
| 272 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); | 297 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); |
| 273 EXPECT_EQ("action_none", script_result); | 298 EXPECT_EQ("action_none", script_result); |
| 274 | 299 |
| 275 #if BUILDFLAG(ENABLE_BACKGROUND) | 300 #if BUILDFLAG(ENABLE_BACKGROUND) |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 base::UTF16ToUTF8(all_options_notification.buttons()[0].title)); | 368 base::UTF16ToUTF8(all_options_notification.buttons()[0].title)); |
| 344 EXPECT_FALSE(all_options_notification.buttons()[0].icon.IsEmpty()); | 369 EXPECT_FALSE(all_options_notification.buttons()[0].icon.IsEmpty()); |
| 345 EXPECT_EQ(kIconWidth, all_options_notification.buttons()[0].icon.Width()); | 370 EXPECT_EQ(kIconWidth, all_options_notification.buttons()[0].icon.Width()); |
| 346 EXPECT_EQ(kIconHeight, all_options_notification.buttons()[0].icon.Height()); | 371 EXPECT_EQ(kIconHeight, all_options_notification.buttons()[0].icon.Height()); |
| 347 } | 372 } |
| 348 | 373 |
| 349 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, | 374 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, |
| 350 WebNotificationSiteSettingsButton) { | 375 WebNotificationSiteSettingsButton) { |
| 351 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); | 376 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); |
| 352 | 377 |
| 378 // Expect 5 engagement for notification permission and 0.5 for the navigation. |
| 379 content::WebContents* web_contents = |
| 380 browser()->tab_strip_model()->GetActiveWebContents(); |
| 381 GURL origin = web_contents->GetLastCommittedURL(); |
| 382 EXPECT_DOUBLE_EQ(5.5, GetEngagementScore(origin)); |
| 383 |
| 353 std::string script_result; | 384 std::string script_result; |
| 354 ASSERT_TRUE(RunScript("DisplayPersistentNotification('Some title', {})", | 385 ASSERT_TRUE(RunScript("DisplayPersistentNotification('Some title', {})", |
| 355 &script_result)); | 386 &script_result)); |
| 356 EXPECT_EQ("ok", script_result); | 387 EXPECT_EQ("ok", script_result); |
| 357 | 388 |
| 358 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); | 389 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); |
| 359 | 390 |
| 360 const Notification& notification = ui_manager()->GetNotificationAt(0); | 391 const Notification& notification = ui_manager()->GetNotificationAt(0); |
| 361 const std::vector<message_center::ButtonInfo>& buttons = | 392 const std::vector<message_center::ButtonInfo>& buttons = |
| 362 notification.buttons(); | 393 notification.buttons(); |
| 363 EXPECT_EQ(0u, buttons.size()); | 394 EXPECT_EQ(0u, buttons.size()); |
| 364 | 395 |
| 365 notification.delegate()->SettingsClick(); | 396 notification.delegate()->SettingsClick(); |
| 366 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); | 397 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); |
| 367 content::WebContents* web_contents = | 398 web_contents = browser()->tab_strip_model()->GetActiveWebContents(); |
| 368 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 369 ASSERT_TRUE(content::WaitForLoadStop(web_contents)); | 399 ASSERT_TRUE(content::WaitForLoadStop(web_contents)); |
| 370 | 400 |
| 401 // No engagement should be granted for clicking on the settings link. |
| 402 EXPECT_DOUBLE_EQ(5.5, GetEngagementScore(origin)); |
| 403 |
| 371 std::string url = web_contents->GetLastCommittedURL().spec(); | 404 std::string url = web_contents->GetLastCommittedURL().spec(); |
| 372 if (base::FeatureList::IsEnabled(features::kMaterialDesignSettings)) | 405 if (base::FeatureList::IsEnabled(features::kMaterialDesignSettings)) |
| 373 ASSERT_EQ("chrome://settings/content/notifications", url); | 406 ASSERT_EQ("chrome://settings/content/notifications", url); |
| 374 else | 407 else |
| 375 ASSERT_EQ("chrome://settings/contentExceptions#notifications", url); | 408 ASSERT_EQ("chrome://settings/contentExceptions#notifications", url); |
| 376 } | 409 } |
| 377 | 410 |
| 378 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, | 411 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, |
| 379 WebNotificationOptionsVibrationPattern) { | 412 WebNotificationOptionsVibrationPattern) { |
| 380 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); | 413 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 391 EXPECT_EQ("Contents", base::UTF16ToUTF8(notification.message())); | 424 EXPECT_EQ("Contents", base::UTF16ToUTF8(notification.message())); |
| 392 | 425 |
| 393 EXPECT_THAT(notification.vibration_pattern(), | 426 EXPECT_THAT(notification.vibration_pattern(), |
| 394 testing::ElementsAreArray(kNotificationVibrationPattern)); | 427 testing::ElementsAreArray(kNotificationVibrationPattern)); |
| 395 } | 428 } |
| 396 | 429 |
| 397 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, | 430 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, |
| 398 CloseDisplayedPersistentNotification) { | 431 CloseDisplayedPersistentNotification) { |
| 399 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); | 432 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); |
| 400 | 433 |
| 434 // Expect 5 engagement for notification permission and 0.5 for the navigation. |
| 435 EXPECT_DOUBLE_EQ(5.5, GetEngagementScore(GetLastCommittedURL())); |
| 436 |
| 401 std::string script_result; | 437 std::string script_result; |
| 402 ASSERT_TRUE(RunScript("DisplayPersistentNotification('action_close')", | 438 ASSERT_TRUE(RunScript("DisplayPersistentNotification('action_close')", |
| 403 &script_result)); | 439 &script_result)); |
| 404 EXPECT_EQ("ok", script_result); | 440 EXPECT_EQ("ok", script_result); |
| 405 | 441 |
| 406 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); | 442 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); |
| 407 | 443 |
| 408 const Notification& notification = ui_manager()->GetNotificationAt(0); | 444 const Notification& notification = ui_manager()->GetNotificationAt(0); |
| 409 notification.delegate()->Click(); | 445 notification.delegate()->Click(); |
| 410 | 446 |
| 447 // We have interacted with the button, so expect a notification bump. |
| 448 EXPECT_DOUBLE_EQ(6.5, GetEngagementScore(GetLastCommittedURL())); |
| 449 |
| 411 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); | 450 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); |
| 412 EXPECT_EQ("action_close", script_result); | 451 EXPECT_EQ("action_close", script_result); |
| 413 | 452 |
| 414 ASSERT_EQ(0u, ui_manager()->GetNotificationCount()); | 453 ASSERT_EQ(0u, ui_manager()->GetNotificationCount()); |
| 415 } | 454 } |
| 416 | 455 |
| 417 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, | 456 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, |
| 418 UserClosesPersistentNotification) { | 457 UserClosesPersistentNotification) { |
| 419 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); | 458 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); |
| 420 | 459 |
| 460 // Expect 5 engagement for notification permission and 0.5 for the navigation. |
| 461 EXPECT_DOUBLE_EQ(5.5, GetEngagementScore(GetLastCommittedURL())); |
| 462 |
| 421 std::string script_result; | 463 std::string script_result; |
| 422 ASSERT_TRUE( | 464 ASSERT_TRUE( |
| 423 RunScript("DisplayPersistentNotification('close_test')", &script_result)); | 465 RunScript("DisplayPersistentNotification('close_test')", &script_result)); |
| 424 EXPECT_EQ("ok", script_result); | 466 EXPECT_EQ("ok", script_result); |
| 425 | 467 |
| 426 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); | 468 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); |
| 427 const Notification& notification = ui_manager()->GetNotificationAt(0); | 469 const Notification& notification = ui_manager()->GetNotificationAt(0); |
| 428 notification.delegate()->Close(true /* by_user */); | 470 notification.delegate()->Close(true /* by_user */); |
| 429 | 471 |
| 472 // The user closed this notification so the score should remain the same. |
| 473 EXPECT_DOUBLE_EQ(5.5, GetEngagementScore(GetLastCommittedURL())); |
| 474 |
| 430 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); | 475 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); |
| 431 EXPECT_EQ("closing notification: close_test", script_result); | 476 EXPECT_EQ("closing notification: close_test", script_result); |
| 432 } | 477 } |
| 433 | 478 |
| 434 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, | 479 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, |
| 435 TestDisplayOriginContextMessage) { | 480 TestDisplayOriginContextMessage) { |
| 436 RequestAndAcceptPermission(); | 481 RequestAndAcceptPermission(); |
| 437 | 482 |
| 438 // Creates a simple notification. | 483 // Creates a simple notification. |
| 439 std::string script_result; | 484 std::string script_result; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 | 588 |
| 544 EXPECT_EQ("Blob Title", base::UTF16ToUTF8(notification.title())); | 589 EXPECT_EQ("Blob Title", base::UTF16ToUTF8(notification.title())); |
| 545 EXPECT_EQ(kIconWidth, notification.icon().Width()); | 590 EXPECT_EQ(kIconWidth, notification.icon().Width()); |
| 546 EXPECT_EQ(kIconHeight, notification.icon().Height()); | 591 EXPECT_EQ(kIconHeight, notification.icon().Height()); |
| 547 } | 592 } |
| 548 | 593 |
| 549 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, | 594 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, |
| 550 DisplayPersistentNotificationWithActionButtons) { | 595 DisplayPersistentNotificationWithActionButtons) { |
| 551 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); | 596 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); |
| 552 | 597 |
| 598 // Expect 5 engagement for notification permission and 0.5 for the navigation. |
| 599 EXPECT_DOUBLE_EQ(5.5, GetEngagementScore(GetLastCommittedURL())); |
| 600 |
| 553 std::string script_result; | 601 std::string script_result; |
| 554 ASSERT_TRUE(RunScript("DisplayPersistentNotificationWithActionButtons()", | 602 ASSERT_TRUE(RunScript("DisplayPersistentNotificationWithActionButtons()", |
| 555 &script_result)); | 603 &script_result)); |
| 556 EXPECT_EQ("ok", script_result); | 604 EXPECT_EQ("ok", script_result); |
| 557 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); | 605 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); |
| 558 | 606 |
| 559 const Notification& notification = ui_manager()->GetNotificationAt(0); | 607 const Notification& notification = ui_manager()->GetNotificationAt(0); |
| 560 ASSERT_EQ(2u, notification.buttons().size()); | 608 ASSERT_EQ(2u, notification.buttons().size()); |
| 561 EXPECT_EQ("actionTitle1", base::UTF16ToUTF8(notification.buttons()[0].title)); | 609 EXPECT_EQ("actionTitle1", base::UTF16ToUTF8(notification.buttons()[0].title)); |
| 562 EXPECT_EQ("actionTitle2", base::UTF16ToUTF8(notification.buttons()[1].title)); | 610 EXPECT_EQ("actionTitle2", base::UTF16ToUTF8(notification.buttons()[1].title)); |
| 563 | 611 |
| 564 notification.delegate()->ButtonClick(0); | 612 notification.delegate()->ButtonClick(0); |
| 565 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); | 613 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); |
| 566 EXPECT_EQ("action_button_click actionId1", script_result); | 614 EXPECT_EQ("action_button_click actionId1", script_result); |
| 615 EXPECT_DOUBLE_EQ(6.5, GetEngagementScore(GetLastCommittedURL())); |
| 567 | 616 |
| 568 notification.delegate()->ButtonClick(1); | 617 notification.delegate()->ButtonClick(1); |
| 569 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); | 618 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); |
| 570 EXPECT_EQ("action_button_click actionId2", script_result); | 619 EXPECT_EQ("action_button_click actionId2", script_result); |
| 620 EXPECT_DOUBLE_EQ(7.5, GetEngagementScore(GetLastCommittedURL())); |
| 571 } | 621 } |
| 572 | 622 |
| 573 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, | 623 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, |
| 574 DisplayPersistentNotificationWithReplyButton) { | 624 DisplayPersistentNotificationWithReplyButton) { |
| 575 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); | 625 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); |
| 576 | 626 |
| 627 // Expect 5 engagement for notification permission and 0.5 for the navigation. |
| 628 EXPECT_DOUBLE_EQ(5.5, GetEngagementScore(GetLastCommittedURL())); |
| 629 |
| 577 std::string script_result; | 630 std::string script_result; |
| 578 ASSERT_TRUE(RunScript("DisplayPersistentNotificationWithReplyButton()", | 631 ASSERT_TRUE(RunScript("DisplayPersistentNotificationWithReplyButton()", |
| 579 &script_result)); | 632 &script_result)); |
| 580 EXPECT_EQ("ok", script_result); | 633 EXPECT_EQ("ok", script_result); |
| 581 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); | 634 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); |
| 582 | 635 |
| 583 const Notification& notification = ui_manager()->GetNotificationAt(0); | 636 const Notification& notification = ui_manager()->GetNotificationAt(0); |
| 584 ASSERT_EQ(1u, notification.buttons().size()); | 637 ASSERT_EQ(1u, notification.buttons().size()); |
| 585 EXPECT_EQ("actionTitle1", base::UTF16ToUTF8(notification.buttons()[0].title)); | 638 EXPECT_EQ("actionTitle1", base::UTF16ToUTF8(notification.buttons()[0].title)); |
| 586 | 639 |
| 587 notification.delegate()->ButtonClickWithReply(0, base::ASCIIToUTF16("hello")); | 640 notification.delegate()->ButtonClickWithReply(0, base::ASCIIToUTF16("hello")); |
| 588 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); | 641 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); |
| 589 EXPECT_EQ("action_button_click actionId1 hello", script_result); | 642 EXPECT_EQ("action_button_click actionId1 hello", script_result); |
| 643 EXPECT_DOUBLE_EQ(6.5, GetEngagementScore(GetLastCommittedURL())); |
| 590 } | 644 } |
| 591 | 645 |
| 592 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, | 646 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, |
| 593 GetDisplayedNotifications) { | 647 GetDisplayedNotifications) { |
| 594 RequestAndAcceptPermission(); | 648 RequestAndAcceptPermission(); |
| 595 | 649 |
| 596 std::string script_result; | 650 std::string script_result; |
| 597 std::string script_message; | 651 std::string script_message; |
| 598 ASSERT_TRUE(RunScript("DisplayNonPersistentNotification('NonPersistent')", | 652 ASSERT_TRUE(RunScript("DisplayNonPersistentNotification('NonPersistent')", |
| 599 &script_result)); | 653 &script_result)); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 RunScript("DisplayPersistentAllOptionsNotification()", &script_result)); | 841 RunScript("DisplayPersistentAllOptionsNotification()", &script_result)); |
| 788 EXPECT_EQ("ok", script_result); | 842 EXPECT_EQ("ok", script_result); |
| 789 | 843 |
| 790 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); | 844 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); |
| 791 const Notification& notification = ui_manager()->GetNotificationAt(0); | 845 const Notification& notification = ui_manager()->GetNotificationAt(0); |
| 792 | 846 |
| 793 // Since the kNotificationContentImage kill switch has disabled images, the | 847 // Since the kNotificationContentImage kill switch has disabled images, the |
| 794 // notification should be shown without an image. | 848 // notification should be shown without an image. |
| 795 EXPECT_TRUE(notification.image().IsEmpty()); | 849 EXPECT_TRUE(notification.image().IsEmpty()); |
| 796 } | 850 } |
| OLD | NEW |