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

Unified Diff: chrome/browser/metrics/plugin_metrics_provider_unittest.cc

Issue 441013002: Eliminate MetricsProvider::RecordCurrentState() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: RecordCurrentState is called before reading from prefs and delayed calls are canceled. Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/metrics/plugin_metrics_provider_unittest.cc
diff --git a/chrome/browser/metrics/plugin_metrics_provider_unittest.cc b/chrome/browser/metrics/plugin_metrics_provider_unittest.cc
index dc961918faef9174469fa3a9df5fbfc382d1a409..3bbc2990c4282d545a86714d947982ac38ad4023 100644
--- a/chrome/browser/metrics/plugin_metrics_provider_unittest.cc
+++ b/chrome/browser/metrics/plugin_metrics_provider_unittest.cc
@@ -10,6 +10,7 @@
#include "base/prefs/pref_service.h"
#include "base/prefs/scoped_user_pref_update.h"
#include "base/prefs/testing_pref_service.h"
+#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/common/pref_names.h"
#include "components/metrics/proto/system_profile.pb.h"
@@ -100,3 +101,40 @@ TEST(PluginMetricsProviderTest, Plugins) {
EXPECT_EQ(3, stability.plugin_stability(0).instance_count());
EXPECT_EQ(4, stability.plugin_stability(0).loading_error_count());
}
+
+TEST(PluginMetricsProviderTest, CheckDelayedRecordCurrentState) {
+ content::TestBrowserThreadBundle thread_bundle;
+
+ TestingPrefServiceSimple prefs;
+ PluginMetricsProvider::RegisterPrefs(prefs.registry());
+ PluginMetricsProvider provider(&prefs);
+
+ int delay_ms = 10;
+ EXPECT_TRUE(provider.DelayedRecordCurrentState(delay_ms));
+ EXPECT_FALSE(provider.DelayedRecordCurrentState(delay_ms));
+
+ base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(delay_ms));
+ base::RunLoop().RunUntilIdle();
+
+ EXPECT_TRUE(provider.DelayedRecordCurrentState(delay_ms));
+}
+
+TEST(PluginMetricsProviderTest, CheckForcedRecordCurrentState) {
+ content::TestBrowserThreadBundle thread_bundle;
+
+ TestingPrefServiceSimple prefs;
+ PluginMetricsProvider::RegisterPrefs(prefs.registry());
+ PluginMetricsProvider provider(&prefs);
+
+ // First there should be now need to force RecordCurrentState.
+ EXPECT_FALSE(provider.ForcedRecordCurrentState());
+
+ // After delayed task is posted ForcedRecordCurrentState should return true.
+ int delay_ms = 100000;
+ EXPECT_TRUE(provider.DelayedRecordCurrentState(delay_ms));
+ EXPECT_TRUE(provider.ForcedRecordCurrentState());
+
+ // if ForcedRecordCurrentState was successful then we should be able to post
Alexei Svitkine (slow) 2014/08/05 21:35:21 Nit: Capitalize if.
gayane -on leave until 09-2017 2014/08/06 14:51:35 Done.
+ // a new delayed task
+ EXPECT_TRUE(provider.DelayedRecordCurrentState(delay_ms));
+}

Powered by Google App Engine
This is Rietveld 408576698