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

Side by Side Diff: chrome/browser/metrics/extensions_metrics_provider_unittest.cc

Issue 297483008: Refactor HashedExtensionMetrics into ExtensionsMetricsProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/metrics/extension_metrics.h" 5 #include "chrome/browser/metrics/extensions_metrics_provider.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/prefs/testing_pref_service.h"
10 #include "chrome/browser/metrics/metrics_state_manager.h"
9 #include "components/metrics/proto/system_profile.pb.h" 11 #include "components/metrics/proto/system_profile.pb.h"
10 #include "extensions/common/extension.h" 12 #include "extensions/common/extension.h"
11 #include "extensions/common/extension_builder.h" 13 #include "extensions/common/extension_builder.h"
12 #include "extensions/common/extension_set.h" 14 #include "extensions/common/extension_set.h"
13 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
14 16
15 namespace { 17 namespace {
16 18
17 class TestHashedExtensionMetrics : public HashedExtensionMetrics { 19 bool IsMetricsReportingEnabled() {
20 return true;
21 }
22
23 class TestExtensionsMetricsProvider : public ExtensionsMetricsProvider {
18 public: 24 public:
19 explicit TestHashedExtensionMetrics(uint64 client_id) 25 explicit TestExtensionsMetricsProvider(
20 : HashedExtensionMetrics(client_id) {} 26 metrics::MetricsStateManager* metrics_state_manager)
27 : ExtensionsMetricsProvider(metrics_state_manager) {}
21 28
22 // Makes the protected HashExtension method available to testing code. 29 // Makes the protected HashExtension method available to testing code.
23 using HashedExtensionMetrics::HashExtension; 30 using ExtensionsMetricsProvider::HashExtension;
24 31
25 protected: 32 protected:
26 // Override the GetInstalledExtensions method to return a set of extensions 33 // Override the GetInstalledExtensions method to return a set of extensions
27 // for tests. 34 // for tests.
28 virtual scoped_ptr<extensions::ExtensionSet> GetInstalledExtensions() 35 virtual scoped_ptr<extensions::ExtensionSet> GetInstalledExtensions()
29 OVERRIDE { 36 OVERRIDE {
30 scoped_ptr<extensions::ExtensionSet> extensions( 37 scoped_ptr<extensions::ExtensionSet> extensions(
31 new extensions::ExtensionSet()); 38 new extensions::ExtensionSet());
32 scoped_refptr<const extensions::Extension> extension; 39 scoped_refptr<const extensions::Extension> extension;
33 extension = extensions::ExtensionBuilder() 40 extension = extensions::ExtensionBuilder()
(...skipping 15 matching lines...) Expand all
49 extension = extensions::ExtensionBuilder() 56 extension = extensions::ExtensionBuilder()
50 .SetManifest(extensions::DictionaryBuilder() 57 .SetManifest(extensions::DictionaryBuilder()
51 .Set("name", "Colliding Extension") 58 .Set("name", "Colliding Extension")
52 .Set("version", "1.0.0") 59 .Set("version", "1.0.0")
53 .Set("manifest_version", 2)) 60 .Set("manifest_version", 2))
54 .SetID("mdhofdjgenpkhlmddfaegdjddcecipmo") 61 .SetID("mdhofdjgenpkhlmddfaegdjddcecipmo")
55 .Build(); 62 .Build();
56 extensions->Insert(extension); 63 extensions->Insert(extension);
57 return extensions.Pass(); 64 return extensions.Pass();
58 } 65 }
66
67 // Override GetClientID() to return a specific value on which test
68 // expectations are based.
69 virtual uint64 GetClientID() OVERRIDE { return 0x3f1bfee9; }
59 }; 70 };
60 71
61 } // namespace 72 } // namespace
62 73
63 // Checks that the hash function used to hide precise extension IDs produces 74 // Checks that the hash function used to hide precise extension IDs produces
64 // the expected values. 75 // the expected values.
65 TEST(HashedExtensionMetrics, HashExtension) { 76 TEST(ExtensionsMetricsProvider, HashExtension) {
66 EXPECT_EQ(978, TestHashedExtensionMetrics::HashExtension( 77 EXPECT_EQ(978,
67 "ahfgeienlihckogmohjhadlkjgocpleb", 0)); 78 TestExtensionsMetricsProvider::HashExtension(
68 EXPECT_EQ(10, TestHashedExtensionMetrics::HashExtension( 79 "ahfgeienlihckogmohjhadlkjgocpleb", 0));
69 "ahfgeienlihckogmohjhadlkjgocpleb", 3817)); 80 EXPECT_EQ(10,
70 EXPECT_EQ(1007, TestHashedExtensionMetrics::HashExtension( 81 TestExtensionsMetricsProvider::HashExtension(
71 "pknkgggnfecklokoggaggchhaebkajji", 3817)); 82 "ahfgeienlihckogmohjhadlkjgocpleb", 3817));
72 EXPECT_EQ(10, TestHashedExtensionMetrics::HashExtension( 83 EXPECT_EQ(1007,
73 "mdhofdjgenpkhlmddfaegdjddcecipmo", 3817)); 84 TestExtensionsMetricsProvider::HashExtension(
85 "pknkgggnfecklokoggaggchhaebkajji", 3817));
86 EXPECT_EQ(10,
87 TestExtensionsMetricsProvider::HashExtension(
88 "mdhofdjgenpkhlmddfaegdjddcecipmo", 3817));
74 } 89 }
75 90
76 // Checks that the fake set of extensions provided by 91 // Checks that the fake set of extensions provided by
77 // TestHashedExtensionMetrics is encoded properly. 92 // TestExtensionsMetricsProvider is encoded properly.
78 TEST(HashedExtensionMetrics, SystemProtoEncoding) { 93 TEST(ExtensionsMetricsProvider, SystemProtoEncoding) {
79 metrics::SystemProfileProto system_profile; 94 metrics::SystemProfileProto system_profile;
80 TestHashedExtensionMetrics extension_metrics(0x3f1bfee9); 95 TestingPrefServiceSimple local_state;
81 extension_metrics.WriteExtensionList(&system_profile); 96 metrics::MetricsStateManager::RegisterPrefs(local_state.registry());
97 scoped_ptr<metrics::MetricsStateManager> metrics_state_manager(
98 metrics::MetricsStateManager::Create(&local_state,
99 base::Bind(&IsMetricsReportingEnabled)));
100 TestExtensionsMetricsProvider extension_metrics(metrics_state_manager.get());
101 extension_metrics.ProvideSystemProfileMetrics(&system_profile);
82 ASSERT_EQ(2, system_profile.occupied_extension_bucket_size()); 102 ASSERT_EQ(2, system_profile.occupied_extension_bucket_size());
83 EXPECT_EQ(10, system_profile.occupied_extension_bucket(0)); 103 EXPECT_EQ(10, system_profile.occupied_extension_bucket(0));
84 EXPECT_EQ(1007, system_profile.occupied_extension_bucket(1)); 104 EXPECT_EQ(1007, system_profile.occupied_extension_bucket(1));
85 } 105 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/extensions_metrics_provider.cc ('k') | chrome/browser/metrics/metrics_log.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698