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

Unified Diff: chrome/browser/notifications/platform_notification_service_interactive_uitest.cc

Issue 2748103011: Grant origins engagement for having interactions on their notifications. (Closed)
Patch Set: Unfriend Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/notifications/platform_notification_service_interactive_uitest.cc
diff --git a/chrome/browser/notifications/platform_notification_service_interactive_uitest.cc b/chrome/browser/notifications/platform_notification_service_interactive_uitest.cc
index 2314d241b4c66bfb50afb9f694ccba952df448a0..b454f6d9febbb992222e770c156cee8aee7854eb 100644
--- a/chrome/browser/notifications/platform_notification_service_interactive_uitest.cc
+++ b/chrome/browser/notifications/platform_notification_service_interactive_uitest.cc
@@ -15,6 +15,8 @@
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
+#include "chrome/browser/engagement/site_engagement_score.h"
+#include "chrome/browser/engagement/site_engagement_service.h"
#include "chrome/browser/notifications/desktop_notification_profile_util.h"
#include "chrome/browser/notifications/message_center_display_service.h"
#include "chrome/browser/notifications/notification.h"
@@ -87,6 +89,9 @@ class PlatformNotificationServiceBrowserTest : public InProcessBrowserTest {
void EnableFullscreenNotifications();
void DisableFullscreenNotifications();
+ double GetEngagementScore(const GURL& origin) const;
+ GURL GetLastCommittedURL() const;
+
// Returns the UI Manager on which notifications will be displayed.
StubNotificationUIManager* ui_manager() const { return ui_manager_.get(); }
@@ -110,6 +115,7 @@ class PlatformNotificationServiceBrowserTest : public InProcessBrowserTest {
return browser->tab_strip_model()->GetActiveWebContents();
}
+ SiteEngagementService* engagement_service_;
const base::FilePath server_root_;
const std::string test_page_url_;
std::unique_ptr<StubNotificationUIManager> ui_manager_;
@@ -147,6 +153,8 @@ void PlatformNotificationServiceBrowserTest::SetUp() {
}
void PlatformNotificationServiceBrowserTest::SetUpOnMainThread() {
+ SiteEngagementScore::SetParamValuesForTesting();
+ engagement_service_ = SiteEngagementService::Get(browser()->profile());
NavigateToTestPage(test_page_url_);
display_service_.reset(
new MessageCenterDisplayService(browser()->profile(), ui_manager_.get()));
@@ -227,6 +235,18 @@ void PlatformNotificationServiceBrowserTest::DisableFullscreenNotifications() {
{features::kAllowFullscreenWebNotificationsFeature});
}
+double PlatformNotificationServiceBrowserTest::GetEngagementScore(
+ const GURL& origin) const {
+ return engagement_service_->GetScore(origin);
+}
+
+GURL PlatformNotificationServiceBrowserTest::GetLastCommittedURL() const {
+ return browser()
+ ->tab_strip_model()
+ ->GetActiveWebContents()
+ ->GetLastCommittedURL();
+}
+
// -----------------------------------------------------------------------------
// TODO(peter): Move PlatformNotificationService-related tests over from
@@ -249,6 +269,9 @@ IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
DisplayPersistentNotificationWithPermission) {
RequestAndAcceptPermission();
+ // Expect 5 engagement for notification permission and 0.5 for the navigation.
+ EXPECT_DOUBLE_EQ(5.5, GetEngagementScore(GetLastCommittedURL()));
+
std::string script_result;
ASSERT_TRUE(RunScript("DisplayPersistentNotification('action_none')",
&script_result));
@@ -261,8 +284,10 @@ IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
KeepAliveOrigin::PENDING_NOTIFICATION_CLICK_EVENT));
#endif
+ // We expect +1 engagement for the notification interaction.
const Notification& notification = ui_manager()->GetNotificationAt(0);
notification.delegate()->Click();
+ EXPECT_DOUBLE_EQ(6.5, GetEngagementScore(GetLastCommittedURL()));
#if BUILDFLAG(ENABLE_BACKGROUND)
ASSERT_TRUE(KeepAliveRegistry::GetInstance()->IsOriginRegistered(
@@ -350,6 +375,12 @@ IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
WebNotificationSiteSettingsButton) {
ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest());
+ // Expect 5 engagement for notification permission and 0.5 for the navigation.
+ content::WebContents* web_contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ GURL origin = web_contents->GetLastCommittedURL();
+ EXPECT_DOUBLE_EQ(5.5, GetEngagementScore(origin));
+
std::string script_result;
ASSERT_TRUE(RunScript("DisplayPersistentNotification('Some title', {})",
&script_result));
@@ -364,10 +395,12 @@ IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
notification.delegate()->SettingsClick();
ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
- content::WebContents* web_contents =
- browser()->tab_strip_model()->GetActiveWebContents();
+ web_contents = browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(content::WaitForLoadStop(web_contents));
+ // No engagement should be granted for clicking on the settings link.
+ EXPECT_DOUBLE_EQ(5.5, GetEngagementScore(origin));
+
std::string url = web_contents->GetLastCommittedURL().spec();
if (base::FeatureList::IsEnabled(features::kMaterialDesignSettings))
ASSERT_EQ("chrome://settings/content/notifications", url);
@@ -398,6 +431,9 @@ IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
CloseDisplayedPersistentNotification) {
ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest());
+ // Expect 5 engagement for notification permission and 0.5 for the navigation.
+ EXPECT_DOUBLE_EQ(5.5, GetEngagementScore(GetLastCommittedURL()));
+
std::string script_result;
ASSERT_TRUE(RunScript("DisplayPersistentNotification('action_close')",
&script_result));
@@ -408,6 +444,9 @@ IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
const Notification& notification = ui_manager()->GetNotificationAt(0);
notification.delegate()->Click();
+ // We have interacted with the button, so expect a notification bump.
+ EXPECT_DOUBLE_EQ(6.5, GetEngagementScore(GetLastCommittedURL()));
+
ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result));
EXPECT_EQ("action_close", script_result);
@@ -418,6 +457,9 @@ IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
UserClosesPersistentNotification) {
ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest());
+ // Expect 5 engagement for notification permission and 0.5 for the navigation.
+ EXPECT_DOUBLE_EQ(5.5, GetEngagementScore(GetLastCommittedURL()));
+
std::string script_result;
ASSERT_TRUE(
RunScript("DisplayPersistentNotification('close_test')", &script_result));
@@ -427,6 +469,9 @@ IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
const Notification& notification = ui_manager()->GetNotificationAt(0);
notification.delegate()->Close(true /* by_user */);
+ // The user closed this notification so the score should remain the same.
+ EXPECT_DOUBLE_EQ(5.5, GetEngagementScore(GetLastCommittedURL()));
+
ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result));
EXPECT_EQ("closing notification: close_test", script_result);
}
@@ -550,6 +595,9 @@ IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
DisplayPersistentNotificationWithActionButtons) {
ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest());
+ // Expect 5 engagement for notification permission and 0.5 for the navigation.
+ EXPECT_DOUBLE_EQ(5.5, GetEngagementScore(GetLastCommittedURL()));
+
std::string script_result;
ASSERT_TRUE(RunScript("DisplayPersistentNotificationWithActionButtons()",
&script_result));
@@ -564,16 +612,21 @@ IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
notification.delegate()->ButtonClick(0);
ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result));
EXPECT_EQ("action_button_click actionId1", script_result);
+ EXPECT_DOUBLE_EQ(6.5, GetEngagementScore(GetLastCommittedURL()));
notification.delegate()->ButtonClick(1);
ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result));
EXPECT_EQ("action_button_click actionId2", script_result);
+ EXPECT_DOUBLE_EQ(7.5, GetEngagementScore(GetLastCommittedURL()));
}
IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
DisplayPersistentNotificationWithReplyButton) {
ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest());
+ // Expect 5 engagement for notification permission and 0.5 for the navigation.
+ EXPECT_DOUBLE_EQ(5.5, GetEngagementScore(GetLastCommittedURL()));
+
std::string script_result;
ASSERT_TRUE(RunScript("DisplayPersistentNotificationWithReplyButton()",
&script_result));
@@ -587,6 +640,7 @@ IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
notification.delegate()->ButtonClickWithReply(0, base::ASCIIToUTF16("hello"));
ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result));
EXPECT_EQ("action_button_click actionId1 hello", script_result);
+ EXPECT_DOUBLE_EQ(6.5, GetEngagementScore(GetLastCommittedURL()));
}
IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
« no previous file with comments | « chrome/browser/notifications/platform_notification_service_impl.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698