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

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

Issue 299783004: Create PluginMetricsProvider class. (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
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/metrics/plugin_metrics_provider.h"
6
7 #include <string>
8 #include <vector>
9
10 #include "base/base64.h"
11 #include "base/basictypes.h"
12 #include "base/files/file_path.h"
13 #include "base/port.h"
14 #include "base/prefs/pref_service.h"
15 #include "base/prefs/scoped_user_pref_update.h"
16 #include "base/prefs/testing_pref_service.h"
17 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/string_util.h"
19 #include "base/strings/stringprintf.h"
20 #include "base/strings/utf_string_conversions.h"
21 #include "base/time/time.h"
22 #include "chrome/common/pref_names.h"
23 #include "components/metrics/proto/system_profile.pb.h"
24 #include "content/public/common/webplugininfo.h"
25 #include "content/public/test/test_browser_thread_bundle.h"
26 #include "testing/gtest/include/gtest/gtest.h"
27
28 namespace {
29
30 content::WebPluginInfo CreateFakePluginInfo(
31 const std::string& name,
32 const base::FilePath::CharType* path,
33 const std::string& version,
34 bool is_pepper) {
35 content::WebPluginInfo plugin(base::UTF8ToUTF16(name),
36 base::FilePath(path),
37 base::UTF8ToUTF16(version),
38 base::string16());
39 if (is_pepper)
40 plugin.type = content::WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS;
41 else
42 plugin.type = content::WebPluginInfo::PLUGIN_TYPE_NPAPI;
43 return plugin;
44 }
45
46 } // namespace
47
48 TEST(PluginMetricsProviderTest, Plugins) {
49 content::TestBrowserThreadBundle thread_bundle;
50
51 TestingPrefServiceSimple prefs;
52 PluginMetricsProvider::RegisterPrefs(prefs.registry());
53 PluginMetricsProvider provider(&prefs);
54
55 std::vector<content::WebPluginInfo> plugins;
56 plugins.push_back(CreateFakePluginInfo("p1", FILE_PATH_LITERAL("p1.plugin"),
57 "1.5", true));
58 plugins.push_back(CreateFakePluginInfo("p2", FILE_PATH_LITERAL("p2.plugin"),
59 "2.0", false));
60 provider.SetPluginsForTesting(plugins);
61
62 metrics::SystemProfileProto system_profile;
63 provider.ProvideSystemProfileMetrics(&system_profile);
64
65 ASSERT_EQ(2, system_profile.plugin_size());
66 EXPECT_EQ("p1", system_profile.plugin(0).name());
67 EXPECT_EQ("p1.plugin", system_profile.plugin(0).filename());
68 EXPECT_EQ("1.5", system_profile.plugin(0).version());
69 EXPECT_TRUE(system_profile.plugin(0).is_pepper());
70 EXPECT_EQ("p2", system_profile.plugin(1).name());
71 EXPECT_EQ("p2.plugin", system_profile.plugin(1).filename());
72 EXPECT_EQ("2.0", system_profile.plugin(1).version());
73 EXPECT_FALSE(system_profile.plugin(1).is_pepper());
74
75 // Now set some plugin stability stats for p2 and verify they're recorded.
76 scoped_ptr<base::DictionaryValue> plugin_dict(new base::DictionaryValue);
77 plugin_dict->SetString(prefs::kStabilityPluginName, "p2");
78 plugin_dict->SetInteger(prefs::kStabilityPluginLaunches, 1);
79 plugin_dict->SetInteger(prefs::kStabilityPluginCrashes, 2);
80 plugin_dict->SetInteger(prefs::kStabilityPluginInstances, 3);
81 plugin_dict->SetInteger(prefs::kStabilityPluginLoadingErrors, 4);
82 {
83 ListPrefUpdate update(&prefs, prefs::kStabilityPluginStats);
84 update.Get()->Append(plugin_dict.release());
85 }
86
87 provider.ProvideStabilityMetrics(&system_profile);
88
89 const metrics::SystemProfileProto_Stability& stability =
90 system_profile.stability();
91 ASSERT_EQ(1, stability.plugin_stability_size());
92 EXPECT_EQ("p2", stability.plugin_stability(0).plugin().name());
93 EXPECT_EQ("p2.plugin", stability.plugin_stability(0).plugin().filename());
94 EXPECT_EQ("2.0", stability.plugin_stability(0).plugin().version());
95 EXPECT_FALSE(stability.plugin_stability(0).plugin().is_pepper());
96 EXPECT_EQ(1, stability.plugin_stability(0).launch_count());
97 EXPECT_EQ(2, stability.plugin_stability(0).crash_count());
98 EXPECT_EQ(3, stability.plugin_stability(0).instance_count());
99 EXPECT_EQ(4, stability.plugin_stability(0).loading_error_count());
100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698