OLD | NEW |
---|---|
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/plugin_metrics_provider.h" | 5 #include "chrome/browser/metrics/plugin_metrics_provider.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/prefs/scoped_user_pref_update.h" | 11 #include "base/prefs/scoped_user_pref_update.h" |
12 #include "base/prefs/testing_pref_service.h" | 12 #include "base/prefs/testing_pref_service.h" |
13 #include "base/run_loop.h" | |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
15 #include "components/metrics/proto/system_profile.pb.h" | 16 #include "components/metrics/proto/system_profile.pb.h" |
16 #include "content/public/common/process_type.h" | 17 #include "content/public/common/process_type.h" |
17 #include "content/public/common/webplugininfo.h" | 18 #include "content/public/common/webplugininfo.h" |
18 #include "content/public/test/test_browser_thread_bundle.h" | 19 #include "content/public/test/test_browser_thread_bundle.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 ASSERT_EQ(1, stability.plugin_stability_size()); | 94 ASSERT_EQ(1, stability.plugin_stability_size()); |
94 EXPECT_EQ("p2", stability.plugin_stability(0).plugin().name()); | 95 EXPECT_EQ("p2", stability.plugin_stability(0).plugin().name()); |
95 EXPECT_EQ("p2.plugin", stability.plugin_stability(0).plugin().filename()); | 96 EXPECT_EQ("p2.plugin", stability.plugin_stability(0).plugin().filename()); |
96 EXPECT_EQ("2.0", stability.plugin_stability(0).plugin().version()); | 97 EXPECT_EQ("2.0", stability.plugin_stability(0).plugin().version()); |
97 EXPECT_FALSE(stability.plugin_stability(0).plugin().is_pepper()); | 98 EXPECT_FALSE(stability.plugin_stability(0).plugin().is_pepper()); |
98 EXPECT_EQ(1, stability.plugin_stability(0).launch_count()); | 99 EXPECT_EQ(1, stability.plugin_stability(0).launch_count()); |
99 EXPECT_EQ(2, stability.plugin_stability(0).crash_count()); | 100 EXPECT_EQ(2, stability.plugin_stability(0).crash_count()); |
100 EXPECT_EQ(3, stability.plugin_stability(0).instance_count()); | 101 EXPECT_EQ(3, stability.plugin_stability(0).instance_count()); |
101 EXPECT_EQ(4, stability.plugin_stability(0).loading_error_count()); | 102 EXPECT_EQ(4, stability.plugin_stability(0).loading_error_count()); |
102 } | 103 } |
104 | |
105 TEST(PluginMetricsProviderTest, CheckDelayedRecordCurrentState) { | |
106 content::TestBrowserThreadBundle thread_bundle; | |
107 | |
108 TestingPrefServiceSimple prefs; | |
109 PluginMetricsProvider::RegisterPrefs(prefs.registry()); | |
110 PluginMetricsProvider provider(&prefs); | |
111 | |
112 int delay_ms = 10; | |
113 EXPECT_TRUE(provider.RecordCurrentStateWithDelay(delay_ms)); | |
114 EXPECT_FALSE(provider.RecordCurrentStateWithDelay(delay_ms)); | |
115 | |
116 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(delay_ms)); | |
117 base::RunLoop().RunUntilIdle(); | |
118 | |
119 EXPECT_TRUE(provider.RecordCurrentStateWithDelay(delay_ms)); | |
120 } | |
121 | |
122 TEST(PluginMetricsProviderTest, CheckForcedRecordCurrentState) { | |
Alexei Svitkine (slow)
2014/08/06 15:10:01
Can you also add a test that verifies that Provide
gayane -on leave until 09-2017
2014/08/06 19:38:27
Done.
| |
123 content::TestBrowserThreadBundle thread_bundle; | |
124 | |
125 TestingPrefServiceSimple prefs; | |
126 PluginMetricsProvider::RegisterPrefs(prefs.registry()); | |
127 PluginMetricsProvider provider(&prefs); | |
128 | |
129 // First there should be now need to force RecordCurrentState. | |
130 EXPECT_FALSE(provider.RecordCurrentStateIfPending()); | |
131 | |
132 // After delayed task is posted RecordCurrentStateIfPending should return | |
133 // true. | |
134 int delay_ms = 100000; | |
135 EXPECT_TRUE(provider.RecordCurrentStateWithDelay(delay_ms)); | |
136 EXPECT_TRUE(provider.RecordCurrentStateIfPending()); | |
137 | |
138 // If RecordCurrentStateIfPending was successful then we should be able to | |
139 // post a new delayed task. | |
140 EXPECT_TRUE(provider.RecordCurrentStateWithDelay(delay_ms)); | |
141 } | |
OLD | NEW |