OLD | NEW |
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" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 // This class observes and collects user action notifications that are sent | 57 // This class observes and collects user action notifications that are sent |
58 // by the tests, so that they can be examined afterwards for correctness. | 58 // by the tests, so that they can be examined afterwards for correctness. |
59 class UserActionObserver : public NotificationObserver { | 59 class UserActionObserver : public NotificationObserver { |
60 public: | 60 public: |
61 UserActionObserver(); | 61 UserActionObserver(); |
62 | 62 |
63 void ValidateUserActions(const Extension* extension, | 63 void ValidateUserActions(const Extension* extension, |
64 const RecordedUserAction* recorded, | 64 const RecordedUserAction* recorded, |
65 int count); | 65 int count); |
66 | 66 |
67 virtual void Observe(NotificationType type, | 67 virtual void Observe(int type, |
68 const NotificationSource& source, | 68 const NotificationSource& source, |
69 const NotificationDetails& details); | 69 const NotificationDetails& details); |
70 | 70 |
71 private: | 71 private: |
72 typedef std::map<std::string, int> UserActionCountMap; | 72 typedef std::map<std::string, int> UserActionCountMap; |
73 | 73 |
74 int num_metrics() const { | 74 int num_metrics() const { |
75 return count_map_.size(); | 75 return count_map_.size(); |
76 } | 76 } |
77 | 77 |
78 int GetMetricCount(const std::string& name) const { | 78 int GetMetricCount(const std::string& name) const { |
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 NotificationRegistrar registrar_; | 83 NotificationRegistrar registrar_; |
84 UserActionCountMap count_map_; | 84 UserActionCountMap count_map_; |
85 }; | 85 }; |
86 | 86 |
87 UserActionObserver::UserActionObserver() { | 87 UserActionObserver::UserActionObserver() { |
88 registrar_.Add(this, NotificationType::USER_ACTION, | 88 registrar_.Add(this, content::NOTIFICATION_USER_ACTION, |
89 NotificationService::AllSources()); | 89 NotificationService::AllSources()); |
90 } | 90 } |
91 | 91 |
92 void UserActionObserver::Observe(NotificationType type, | 92 void UserActionObserver::Observe(int type, |
93 const NotificationSource& source, | 93 const NotificationSource& source, |
94 const NotificationDetails& details) { | 94 const NotificationDetails& details) { |
95 const char* name = *Details<const char*>(details).ptr(); | 95 const char* name = *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, |
100 const RecordedUserAction* recorded, | 100 const RecordedUserAction* recorded, |
101 int count) { | 101 int count) { |
102 EXPECT_EQ(count, num_metrics()); | 102 EXPECT_EQ(count, num_metrics()); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } |
OLD | NEW |