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