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

Unified Diff: chrome/browser/push_messaging/push_messaging_browsertest.cc

Issue 1977423002: Added UMA stats to track the budget for any service worker which receives a (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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/push_messaging/push_messaging_browsertest.cc
diff --git a/chrome/browser/push_messaging/push_messaging_browsertest.cc b/chrome/browser/push_messaging/push_messaging_browsertest.cc
index d619fa9939351a04c50d29f966d725e6cb4f1477..8ce4429d2c2e2c2cf4bb36bc4f799c159c0001e5 100644
--- a/chrome/browser/push_messaging/push_messaging_browsertest.cc
+++ b/chrome/browser/push_messaging/push_messaging_browsertest.cc
@@ -15,6 +15,7 @@
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/test/histogram_tester.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browsing_data/browsing_data_helper.h"
@@ -251,10 +252,13 @@ class PushMessagingBrowserTest : public InProcessBrowserTest {
virtual Browser* GetBrowser() const { return browser(); }
+ base::HistogramTester* GetHistogramTester() { return &histogram_tester_; }
+
private:
std::unique_ptr<net::EmbeddedTestServer> https_server_;
gcm::FakeGCMProfileService* gcm_service_;
PushMessagingServiceImpl* push_service_;
+ base::HistogramTester histogram_tester_;
#if defined(ENABLE_NOTIFICATIONS)
std::unique_ptr<StubNotificationUIManager> notification_manager_;
@@ -739,6 +743,10 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
content::WebContents* web_contents =
GetBrowser()->tab_strip_model()->GetActiveWebContents();
+ // Set the site engagement score for the site. Setting it to 4 means it should
+ // have enough budget for two non-shown notification, which cost 2 each.
+ SetSiteEngagementScore(web_contents->GetURL(), 4.0);
+
// If the site is visible in an active tab, we should not force a notification
// to be shown. Try it twice, since we allow one mistake per 10 push events.
gcm::IncomingMessage message;
@@ -757,10 +765,6 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
GetBrowser(), GURL("about:blank"), NEW_FOREGROUND_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
- // Set the site engagement score for the site. Setting it to 2 means we should
- // have enough budget for two non-shown notification.
- SetSiteEngagementScore(web_contents->GetURL(), 2.0);
-
// If the Service Worker push event handler shows a notification, we
// should not show a forced one.
message.raw_data = "shownotification";
@@ -813,6 +817,37 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
EXPECT_NE(kPushMessagingForcedNotificationTag, first_notification.tag());
}
+
+ // Check that the UMA has been recorded correctly.
+ // There should be a total of 7 budget samples, spread across 3 buckets. The
+ // first four notifications (before any budget is consumed) have budget of 4,
+ // which is the starting SES. The next one has 2 (one hidden notification) and
+ // the final two have 0 (two hidden notifications.
+ std::vector<base::Bucket> buckets =
+ GetHistogramTester()->GetAllSamples("PushMessaging.BackgroundBudget");
+ ASSERT_EQ(buckets.size(), 3.0);
+ // First bucket is for 0 budget, which has 2 samples.
+ EXPECT_EQ(buckets[0].min, 0);
Peter Beverloo 2016/05/17 11:04:34 nit: EXPECT_EQ(expected, actual) Elsewhere and wi
harkness 2016/05/17 13:08:16 Done.
+ EXPECT_EQ(buckets[0].count, 2);
+ // Second bucket is for 2 budget, which has 1 sample.
+ EXPECT_EQ(buckets[1].min, 2);
+ EXPECT_EQ(buckets[1].count, 1);
+ // Final bucket is for 4 budget, which has 4 samples.
+ EXPECT_EQ(buckets[2].min, 4);
+ EXPECT_EQ(buckets[2].count, 4);
+
+ std::vector<base::Bucket> sesForNoBudgetBuckets =
Peter Beverloo 2016/05/17 11:04:34 nit: Chromium style guide wants us to name things
harkness 2016/05/17 13:08:16 Somewhat shortened, but I still kept some context.
+ GetHistogramTester()->GetAllSamples("PushMessaging.SESForNoBudgetOrigin");
+ EXPECT_EQ(sesForNoBudgetBuckets.size(), 1.0);
+ EXPECT_EQ(sesForNoBudgetBuckets[0].min, 4);
+ EXPECT_EQ(sesForNoBudgetBuckets[0].count, 2);
+
+ std::vector<base::Bucket> sesForLowBudgetBuckets =
+ GetHistogramTester()->GetAllSamples(
+ "PushMessaging.SESForLowBudgetOrigin");
+ EXPECT_EQ(sesForLowBudgetBuckets.size(), 1.0);
+ EXPECT_EQ(sesForLowBudgetBuckets[0].min, 4);
+ EXPECT_EQ(sesForLowBudgetBuckets[0].count, 1);
}
IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,

Powered by Google App Engine
This is Rietveld 408576698