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

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: 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 class TestExtensionsMetricsProvider : public ExtensionsMetricsProvider {
18 public: 20 public:
19 explicit TestHashedExtensionMetrics(uint64 client_id) 21 explicit TestExtensionsMetricsProvider(
20 : HashedExtensionMetrics(client_id) {} 22 metrics::MetricsStateManager* metrics_state_manager)
23 : ExtensionsMetricsProvider(metrics_state_manager) {}
21 24
22 // Makes the protected HashExtension method available to testing code. 25 // Makes the protected HashExtension method available to testing code.
23 using HashedExtensionMetrics::HashExtension; 26 using ExtensionsMetricsProvider::HashExtension;
24 27
25 protected: 28 protected:
26 // Override the GetInstalledExtensions method to return a set of extensions 29 // Override the GetInstalledExtensions method to return a set of extensions
27 // for tests. 30 // for tests.
28 virtual scoped_ptr<extensions::ExtensionSet> GetInstalledExtensions() 31 virtual scoped_ptr<extensions::ExtensionSet> GetInstalledExtensions()
29 OVERRIDE { 32 OVERRIDE {
30 scoped_ptr<extensions::ExtensionSet> extensions( 33 scoped_ptr<extensions::ExtensionSet> extensions(
31 new extensions::ExtensionSet()); 34 new extensions::ExtensionSet());
32 scoped_refptr<const extensions::Extension> extension; 35 scoped_refptr<const extensions::Extension> extension;
33 extension = extensions::ExtensionBuilder() 36 extension = extensions::ExtensionBuilder()
(...skipping 15 matching lines...) Expand all
49 extension = extensions::ExtensionBuilder() 52 extension = extensions::ExtensionBuilder()
50 .SetManifest(extensions::DictionaryBuilder() 53 .SetManifest(extensions::DictionaryBuilder()
51 .Set("name", "Colliding Extension") 54 .Set("name", "Colliding Extension")
52 .Set("version", "1.0.0") 55 .Set("version", "1.0.0")
53 .Set("manifest_version", 2)) 56 .Set("manifest_version", 2))
54 .SetID("mdhofdjgenpkhlmddfaegdjddcecipmo") 57 .SetID("mdhofdjgenpkhlmddfaegdjddcecipmo")
55 .Build(); 58 .Build();
56 extensions->Insert(extension); 59 extensions->Insert(extension);
57 return extensions.Pass(); 60 return extensions.Pass();
58 } 61 }
62
63 // Override GetClientID() to return a specific value on which test
64 // expectations are based.
65 virtual uint64 GetClientID() OVERRIDE { return 0x3f1bfee9; }
59 }; 66 };
60 67
61 } // namespace 68 } // namespace
62 69
63 // Checks that the hash function used to hide precise extension IDs produces 70 // Checks that the hash function used to hide precise extension IDs produces
64 // the expected values. 71 // the expected values.
65 TEST(HashedExtensionMetrics, HashExtension) { 72 TEST(ExtensionsMetricsProvider, HashExtension) {
66 EXPECT_EQ(978, TestHashedExtensionMetrics::HashExtension( 73 EXPECT_EQ(978,
67 "ahfgeienlihckogmohjhadlkjgocpleb", 0)); 74 TestExtensionsMetricsProvider::HashExtension(
68 EXPECT_EQ(10, TestHashedExtensionMetrics::HashExtension( 75 "ahfgeienlihckogmohjhadlkjgocpleb", 0));
69 "ahfgeienlihckogmohjhadlkjgocpleb", 3817)); 76 EXPECT_EQ(10,
70 EXPECT_EQ(1007, TestHashedExtensionMetrics::HashExtension( 77 TestExtensionsMetricsProvider::HashExtension(
71 "pknkgggnfecklokoggaggchhaebkajji", 3817)); 78 "ahfgeienlihckogmohjhadlkjgocpleb", 3817));
72 EXPECT_EQ(10, TestHashedExtensionMetrics::HashExtension( 79 EXPECT_EQ(1007,
73 "mdhofdjgenpkhlmddfaegdjddcecipmo", 3817)); 80 TestExtensionsMetricsProvider::HashExtension(
81 "pknkgggnfecklokoggaggchhaebkajji", 3817));
82 EXPECT_EQ(10,
83 TestExtensionsMetricsProvider::HashExtension(
84 "mdhofdjgenpkhlmddfaegdjddcecipmo", 3817));
74 } 85 }
75 86
76 // Checks that the fake set of extensions provided by 87 // Checks that the fake set of extensions provided by
77 // TestHashedExtensionMetrics is encoded properly. 88 // TestExtensionsMetricsProvider is encoded properly.
78 TEST(HashedExtensionMetrics, SystemProtoEncoding) { 89 TEST(ExtensionsMetricsProvider, SystemProtoEncoding) {
79 metrics::SystemProfileProto system_profile; 90 metrics::SystemProfileProto system_profile;
80 TestHashedExtensionMetrics extension_metrics(0x3f1bfee9); 91 TestingPrefServiceSimple local_state;
81 extension_metrics.WriteExtensionList(&system_profile); 92 metrics::MetricsStateManager::RegisterPrefs(local_state.registry());
93 scoped_ptr<metrics::MetricsStateManager> metrics_state_manager(
94 metrics::MetricsStateManager::Create(&local_state));
95 TestExtensionsMetricsProvider extension_metrics(metrics_state_manager.get());
96 extension_metrics.ProvideSystemProfileMetrics(&system_profile);
82 ASSERT_EQ(2, system_profile.occupied_extension_bucket_size()); 97 ASSERT_EQ(2, system_profile.occupied_extension_bucket_size());
83 EXPECT_EQ(10, system_profile.occupied_extension_bucket(0)); 98 EXPECT_EQ(10, system_profile.occupied_extension_bucket(0));
84 EXPECT_EQ(1007, system_profile.occupied_extension_bucket(1)); 99 EXPECT_EQ(1007, system_profile.occupied_extension_bucket(1));
85 } 100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698