Commit 30424ff1 authored by nancylingwang@google.com's avatar nancylingwang@google.com Committed by Commit Bot

Add test cases for notification metrics.

BUG=1068884

Change-Id: Ide76bd5cfc0f1a4ba497f0420a52fcc020f293a5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2223835Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#773932}
parent db99eb75
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "ash/system/message_center/arc/arc_notification_manager.h" #include "ash/system/message_center/arc/arc_notification_manager.h"
#include "ash/system/message_center/arc/arc_notification_manager_delegate.h" #include "ash/system/message_center/arc/arc_notification_manager_delegate.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h" #include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h" #include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
...@@ -470,8 +471,38 @@ IN_PROC_BROWSER_TEST_P(AppNotificationsWebNotificationTest, ...@@ -470,8 +471,38 @@ IN_PROC_BROWSER_TEST_P(AppNotificationsWebNotificationTest,
ASSERT_EQ(apps::mojom::OptionalBool::kFalse, HasBadge(profile(), app_id2)); ASSERT_EQ(apps::mojom::OptionalBool::kFalse, HasBadge(profile(), app_id2));
} }
IN_PROC_BROWSER_TEST_P(AppNotificationsWebNotificationTest,
AddAndRemoveNonPersistentNotificationForOneApp) {
base::HistogramTester histogram_tester;
const GURL origin = GetOrigin();
std::string app_id1 = CreateWebApp(GetUrl1(), GetScope1());
std::string app_id3 = CreateWebApp(GetUrl3(), GetScope3());
ASSERT_EQ(apps::mojom::OptionalBool::kFalse, HasBadge(profile(), app_id1));
ASSERT_EQ(apps::mojom::OptionalBool::kFalse, HasBadge(profile(), app_id3));
const std::string notification_id = "notification-id";
auto notification = CreateNotification(notification_id, origin);
NotificationDisplayService::GetForProfile(profile())->Display(
NotificationHandler::Type::WEB_NON_PERSISTENT, *notification,
/*metadata=*/nullptr);
ASSERT_EQ(apps::mojom::OptionalBool::kTrue, HasBadge(profile(), app_id1));
ASSERT_EQ(apps::mojom::OptionalBool::kFalse, HasBadge(profile(), app_id3));
histogram_tester.ExpectUniqueSample(
"ChromeOS.Apps.NumberOfAppsForNotification", false, 1);
RemoveNotification(profile(), notification_id);
ASSERT_EQ(apps::mojom::OptionalBool::kFalse, HasBadge(profile(), app_id1));
ASSERT_EQ(apps::mojom::OptionalBool::kFalse, HasBadge(profile(), app_id3));
}
IN_PROC_BROWSER_TEST_P(AppNotificationsWebNotificationTest, IN_PROC_BROWSER_TEST_P(AppNotificationsWebNotificationTest,
AddAndRemoveNonPersistentNotification) { AddAndRemoveNonPersistentNotification) {
base::HistogramTester histogram_tester;
const GURL origin = GetOrigin(); const GURL origin = GetOrigin();
std::string app_id1 = CreateWebApp(GetUrl1(), GetScope1()); std::string app_id1 = CreateWebApp(GetUrl1(), GetScope1());
std::string app_id2 = CreateWebApp(GetUrl2(), GetScope2()); std::string app_id2 = CreateWebApp(GetUrl2(), GetScope2());
...@@ -491,6 +522,9 @@ IN_PROC_BROWSER_TEST_P(AppNotificationsWebNotificationTest, ...@@ -491,6 +522,9 @@ IN_PROC_BROWSER_TEST_P(AppNotificationsWebNotificationTest,
ASSERT_EQ(apps::mojom::OptionalBool::kTrue, HasBadge(profile(), app_id2)); ASSERT_EQ(apps::mojom::OptionalBool::kTrue, HasBadge(profile(), app_id2));
ASSERT_EQ(apps::mojom::OptionalBool::kFalse, HasBadge(profile(), app_id3)); ASSERT_EQ(apps::mojom::OptionalBool::kFalse, HasBadge(profile(), app_id3));
histogram_tester.ExpectUniqueSample(
"ChromeOS.Apps.NumberOfAppsForNotification", true, 1);
RemoveNotification(profile(), notification_id); RemoveNotification(profile(), notification_id);
ASSERT_EQ(apps::mojom::OptionalBool::kFalse, HasBadge(profile(), app_id1)); ASSERT_EQ(apps::mojom::OptionalBool::kFalse, HasBadge(profile(), app_id1));
ASSERT_EQ(apps::mojom::OptionalBool::kFalse, HasBadge(profile(), app_id2)); ASSERT_EQ(apps::mojom::OptionalBool::kFalse, HasBadge(profile(), app_id2));
...@@ -499,6 +533,8 @@ IN_PROC_BROWSER_TEST_P(AppNotificationsWebNotificationTest, ...@@ -499,6 +533,8 @@ IN_PROC_BROWSER_TEST_P(AppNotificationsWebNotificationTest,
IN_PROC_BROWSER_TEST_P(AppNotificationsWebNotificationTest, IN_PROC_BROWSER_TEST_P(AppNotificationsWebNotificationTest,
NonPersistentNotificationWhenInstallAndUninstallApp) { NonPersistentNotificationWhenInstallAndUninstallApp) {
base::HistogramTester histogram_tester;
// Send the notification 1 before installing apps. // Send the notification 1 before installing apps.
const GURL origin = GetOrigin(); const GURL origin = GetOrigin();
const std::string notification_id1 = "notification-id1"; const std::string notification_id1 = "notification-id1";
...@@ -517,6 +553,9 @@ IN_PROC_BROWSER_TEST_P(AppNotificationsWebNotificationTest, ...@@ -517,6 +553,9 @@ IN_PROC_BROWSER_TEST_P(AppNotificationsWebNotificationTest,
ASSERT_EQ(apps::mojom::OptionalBool::kFalse, HasBadge(profile(), app_id2)); ASSERT_EQ(apps::mojom::OptionalBool::kFalse, HasBadge(profile(), app_id2));
ASSERT_EQ(apps::mojom::OptionalBool::kFalse, HasBadge(profile(), app_id3)); ASSERT_EQ(apps::mojom::OptionalBool::kFalse, HasBadge(profile(), app_id3));
histogram_tester.ExpectTotalCount("ChromeOS.Apps.NumberOfAppsForNotification",
0);
// Send the notification 2. // Send the notification 2.
const std::string notification_id2 = "notification-id2"; const std::string notification_id2 = "notification-id2";
notification = CreateNotification(notification_id2, origin); notification = CreateNotification(notification_id2, origin);
...@@ -529,6 +568,9 @@ IN_PROC_BROWSER_TEST_P(AppNotificationsWebNotificationTest, ...@@ -529,6 +568,9 @@ IN_PROC_BROWSER_TEST_P(AppNotificationsWebNotificationTest,
ASSERT_EQ(apps::mojom::OptionalBool::kTrue, HasBadge(profile(), app_id2)); ASSERT_EQ(apps::mojom::OptionalBool::kTrue, HasBadge(profile(), app_id2));
ASSERT_EQ(apps::mojom::OptionalBool::kFalse, HasBadge(profile(), app_id3)); ASSERT_EQ(apps::mojom::OptionalBool::kFalse, HasBadge(profile(), app_id3));
histogram_tester.ExpectUniqueSample(
"ChromeOS.Apps.NumberOfAppsForNotification", true, 1);
// Uninstall the app 1. The notification badge for app 2 and app 3 should not // Uninstall the app 1. The notification badge for app 2 and app 3 should not
// be affected. // be affected.
UninstallWebApp(app_id1); UninstallWebApp(app_id1);
...@@ -552,6 +594,9 @@ IN_PROC_BROWSER_TEST_P(AppNotificationsWebNotificationTest, ...@@ -552,6 +594,9 @@ IN_PROC_BROWSER_TEST_P(AppNotificationsWebNotificationTest,
ASSERT_EQ(apps::mojom::OptionalBool::kTrue, HasBadge(profile(), app_id2)); ASSERT_EQ(apps::mojom::OptionalBool::kTrue, HasBadge(profile(), app_id2));
ASSERT_EQ(apps::mojom::OptionalBool::kFalse, HasBadge(profile(), app_id3)); ASSERT_EQ(apps::mojom::OptionalBool::kFalse, HasBadge(profile(), app_id3));
histogram_tester.ExpectUniqueSample(
"ChromeOS.Apps.NumberOfAppsForNotification", true, 2);
// Remove the notification 3 // Remove the notification 3
RemoveNotification(profile(), notification_id3); RemoveNotification(profile(), notification_id3);
ASSERT_EQ(apps::mojom::OptionalBool::kFalse, HasBadge(profile(), app_id1)); ASSERT_EQ(apps::mojom::OptionalBool::kFalse, HasBadge(profile(), app_id1));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment