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

Side by Side Diff: chrome/browser/extensions/extension_metrics_apitest.cc

Issue 8342048: Make NotificationService an interface in the content namespace, and switch callers to use it. Mov... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <map> 5 #include <map>
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "chrome/browser/extensions/extension_apitest.h" 8 #include "chrome/browser/extensions/extension_apitest.h"
9 #include "chrome/common/chrome_switches.h" 9 #include "chrome/common/chrome_switches.h"
10 #include "chrome/common/extensions/extension.h" 10 #include "chrome/common/extensions/extension.h"
11 #include "content/public/browser/notification_registrar.h" 11 #include "content/public/browser/notification_registrar.h"
12 #include "content/common/notification_service.h" 12 #include "content/public/browser/notification_service.h"
13 13
14 namespace { 14 namespace {
15 15
16 // The tests that are run by this extension are expected to record the following 16 // The tests that are run by this extension are expected to record the following
17 // user actions, with the specified counts. If the tests in test.js are 17 // user actions, with the specified counts. If the tests in test.js are
18 // modified, this array may need to be updated. 18 // modified, this array may need to be updated.
19 struct RecordedUserAction { 19 struct RecordedUserAction {
20 const char* name; // base name of metric without extension id. 20 const char* name; // base name of metric without extension id.
21 int count; // number of times the metric was recorded. 21 int count; // number of times the metric was recorded.
22 } g_user_actions[] = { 22 } g_user_actions[] = {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 UserActionCountMap::const_iterator i = count_map_.find(name); 79 UserActionCountMap::const_iterator i = count_map_.find(name);
80 return i == count_map_.end() ? -1 : i->second; 80 return i == count_map_.end() ? -1 : i->second;
81 } 81 }
82 82
83 content::NotificationRegistrar registrar_; 83 content::NotificationRegistrar registrar_;
84 UserActionCountMap count_map_; 84 UserActionCountMap count_map_;
85 }; 85 };
86 86
87 UserActionObserver::UserActionObserver() { 87 UserActionObserver::UserActionObserver() {
88 registrar_.Add(this, content::NOTIFICATION_USER_ACTION, 88 registrar_.Add(this, content::NOTIFICATION_USER_ACTION,
89 NotificationService::AllSources()); 89 content::NotificationService::AllSources());
90 } 90 }
91 91
92 void UserActionObserver::Observe(int type, 92 void UserActionObserver::Observe(int type,
93 const content::NotificationSource& source, 93 const content::NotificationSource& source,
94 const content::NotificationDetails& details) { 94 const content::NotificationDetails& details) {
95 const char* name = *content::Details<const char*>(details).ptr(); 95 const char* name = *content::Details<const char*>(details).ptr();
96 ++(count_map_[name]); 96 ++(count_map_[name]);
97 } 97 }
98 98
99 void UserActionObserver::ValidateUserActions(const Extension* extension, 99 void UserActionObserver::ValidateUserActions(const Extension* extension,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 147
148 ASSERT_TRUE(RunExtensionTest("metrics")) << message_; 148 ASSERT_TRUE(RunExtensionTest("metrics")) << message_;
149 const Extension* extension = GetSingleLoadedExtension(); 149 const Extension* extension = GetSingleLoadedExtension();
150 ASSERT_TRUE(extension); 150 ASSERT_TRUE(extension);
151 151
152 observer.ValidateUserActions(extension, 152 observer.ValidateUserActions(extension,
153 g_user_actions, 153 g_user_actions,
154 arraysize(g_user_actions)); 154 arraysize(g_user_actions));
155 ValidateHistograms(extension, g_histograms, arraysize(g_histograms)); 155 ValidateHistograms(extension, g_histograms, arraysize(g_histograms));
156 } 156 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_messages_apitest.cc ('k') | chrome/browser/extensions/extension_navigation_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698