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

Unified Diff: extensions/browser/event_router_unittest.cc

Issue 1606943005: Adds UMA for counting component event page wakeups. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « extensions/browser/event_router.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/browser/event_router_unittest.cc
diff --git a/extensions/browser/event_router_unittest.cc b/extensions/browser/event_router_unittest.cc
index ff5d5db0d1ab022e226715f0ab72451416430ac6..f662a909c7029a6eef32da1c76d37633707888f9 100644
--- a/extensions/browser/event_router_unittest.cc
+++ b/extensions/browser/event_router_unittest.cc
@@ -8,12 +8,17 @@
#include "base/bind.h"
#include "base/compiler_specific.h"
+#include "base/test/histogram_tester.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/values.h"
#include "content/public/browser/notification_service.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "extensions/browser/event_listener_map.h"
#include "extensions/browser/extensions_test.h"
+#include "extensions/common/extension_builder.h"
+#include "extensions/common/test_util.h"
+#include "extensions/common/value_builder.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace extensions {
@@ -81,6 +86,14 @@ scoped_ptr<EventListener> CreateEventListenerForURL(
event_name, listener_url, process, make_scoped_ptr(filter));
}
+scoped_ptr<base::DictionaryValue> CreateBackgroundManifest(bool persistent) {
+ scoped_ptr<base::DictionaryValue> manifest =
+ make_scoped_ptr(new base::DictionaryValue());
+ manifest->SetString("background.page", "background.html");
+ manifest->SetBoolean("background.persistent", persistent);
+ return manifest;
imcheng 2016/01/20 18:28:21 It should compile if you changed this to: std::mo
mark a. foltz 2016/01/20 21:58:07 Thanks! That was the fix. It isn't clear to me y
+}
+
} // namespace
class EventRouterTest : public ExtensionsTest {
@@ -92,8 +105,52 @@ class EventRouterTest : public ExtensionsTest {
// Tests adding and removing observers from EventRouter.
void RunEventRouterObserverTest(const EventListenerConstructor& constructor);
+ // Tests that the correct counts are recorded for the Extensions.Events
+ // histograms.
+ void ExpectHistogramCounts(int dispatch_count, int component_count,
+ int persistent_count, int suspended_count,
+ int component_suspended_count, int running_count) {
+ if (dispatch_count) {
+ histogram_tester_.ExpectBucketCount("Extensions.Events.Dispatch",
+ events::HistogramValue::FOR_TEST,
+ dispatch_count);
+ }
+ if (component_count) {
+ histogram_tester_.ExpectBucketCount(
+ "Extensions.Events.DispatchToComponent",
+ events::HistogramValue::FOR_TEST,
+ component_count);
+ }
+ if (persistent_count) {
+ histogram_tester_.ExpectBucketCount(
+ "Extensions.Events.DispatchWithPersistentBackgroundPage",
+ events::HistogramValue::FOR_TEST,
+ persistent_count);
+ }
+ if (suspended_count) {
+ histogram_tester_.ExpectBucketCount(
+ "Extensions.Events.DispatchWithSuspendedEventPage",
+ events::HistogramValue::FOR_TEST,
+ suspended_count);
+ }
+ if (component_suspended_count) {
+ histogram_tester_.ExpectBucketCount(
+ "Extensions.Events.DispatchToComponentWithSuspendedEventPage",
+ events::HistogramValue::FOR_TEST,
+ component_suspended_count);
+ }
+ if (running_count) {
+ histogram_tester_.ExpectBucketCount(
+ "Extensions.Events.DispatchWithRunningEventPage",
+ events::HistogramValue::FOR_TEST,
+ running_count);
+ }
+ }
+
private:
scoped_ptr<content::NotificationService> notification_service_;
+ content::TestBrowserThreadBundle thread_bundle_;
+ base::HistogramTester histogram_tester_;
DISALLOW_COPY_AND_ASSIGN(EventRouterTest);
};
@@ -171,4 +228,62 @@ TEST_F(EventRouterTest, EventRouterObserverForURLs) {
base::Bind(&CreateEventListenerForURL, GURL("http://google.com/path")));
}
+TEST_F(EventRouterTest, TestReportEvent) {
+ EventRouter router(browser_context(), NULL);
+ // TODO: Create component extensions w/ and w/out lazy background page
+ // Use ExtensionBuilder.
+ scoped_refptr<Extension> normal = test_util::CreateEmptyExtension("id1");
+ router.ReportEvent(events::HistogramValue::FOR_TEST,
+ normal.get(),
+ false /** did_enqueue */);
+ ExpectHistogramCounts(1 /** Dispatch */,
+ 0 /** DispatchToComponent */,
+ 0 /** DispatchWithPersistentBackgroundPage */,
+ 0 /** DispatchWithSuspendedEventPage */,
+ 0 /** DispatchToComponentWithSuspendedEventPage */,
+ 0 /** DispatchWithRunningEventPage */);
+
+ ExtensionBuilder component_builder;
+ scoped_refptr<Extension> component = component_builder.
+ SetLocation(Manifest::Location::COMPONENT).Build();
+ router.ReportEvent(events::HistogramValue::FOR_TEST,
+ component.get(),
+ false /** did_enqueue */);
+ ExpectHistogramCounts(2, 1, 0, 0, 0, 0);
+
+ ExtensionBuilder persistent_builder;
+ scoped_ptr<base::DictionaryValue> persistent_manifest =
+ CreateBackgroundManifest(true);
+
+ scoped_refptr<Extension> persistent = persistent_builder.
+ SetManifest(persistent_manifest).Build();
+ router.ReportEvent(events::HistogramValue::FOR_TEST,
+ persistent.get(),
+ false /** did_enqueue */);
+ ExpectHistogramCounts(3, 1, 1, 0, 0, 0);
+
+ // ExtensionBuilder event_builder;
+ // scoped_refptr<Extension> event = event_builder.
+ // SetManifest(CreateBackgroundManifest(false)).Build();
+ // router.ReportEvent(events::HistogramValue::FOR_TEST,
+ // event.get(),
+ // false /** did_enqueue */);
+ // router.ReportEvent(events::HistogramValue::FOR_TEST,
+ // event.get(),
+ // true /** did_enqueue */);
+ // ExpectHistogramCounts(4, 1, 1, 1, 0, 1);
+
+ // ExtensionBuilder component_event_builder;
+ // scoped_refptr<Extension> component_event = component_event_builder.
+ // SetLocation(Manifest::Location::COMPONENT).
+ // SetManifest(CreateBackgroundManifest(false)).Build();
+ // router.ReportEvent(events::HistogramValue::FOR_TEST,
+ // component_event.get(),
+ // false /** did_enqueue */);
+ // router.ReportEvent(events::HistogramValue::FOR_TEST,
+ // component_event.get(),
+ // true /** did_enqueue */);
+ // ExpectHistogramCounts(5, 2, 1, 2, 1, 2);
+}
+
} // namespace extensions
« no previous file with comments | « extensions/browser/event_router.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698