Index: chrome/browser/prefs/pref_hash_browsertest.cc |
diff --git a/chrome/browser/prefs/pref_hash_browsertest.cc b/chrome/browser/prefs/pref_hash_browsertest.cc |
index 1bcc0fd27f0f47d50d9bc44bf6841c8bc2a20d3f..19775c738ab0ff0a96af77c3ea5b900fb9b9e0c6 100644 |
--- a/chrome/browser/prefs/pref_hash_browsertest.cc |
+++ b/chrome/browser/prefs/pref_hash_browsertest.cc |
@@ -7,11 +7,16 @@ |
#include "base/bind.h" |
#include "base/files/file_path.h" |
+#include "base/macros.h" |
#include "base/message_loop/message_loop.h" |
+#include "base/metrics/histogram_base.h" |
+#include "base/metrics/histogram_samples.h" |
+#include "base/metrics/statistics_recorder.h" |
#include "base/prefs/pref_service.h" |
#include "base/strings/string16.h" |
#include "base/values.h" |
#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/prefs/pref_hash_store.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/profiles/profile_impl.h" |
#include "chrome/browser/profiles/profile_info_cache.h" |
@@ -58,6 +63,28 @@ base::FilePath GetUnloadedProfilePath() { |
return base::FilePath(); |
} |
+// Returns the number of times |histogram_name| was reported so far; adding the |
+// results of the first 100 buckets (there are only ~14 reporting IDs as of this |
+// writting; varies depending on the platform). If |expect_zero| is true, this |
+// method will explicitly report IDs that are non-zero for ease of diagnosis. |
+int GetTrackedPrefHistogramCount(const char* histogram_name, bool expect_zero) { |
+ const base::HistogramBase* histogram = |
+ base::StatisticsRecorder::FindHistogram(histogram_name); |
+ if (!histogram) |
+ return 0; |
+ |
+ scoped_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples()); |
+ int sum = 0; |
+ for (int i = 0; i < 100; ++i) { |
+ int count_for_id = samples->GetCount(i); |
+ sum += count_for_id; |
+ |
+ if (expect_zero) |
+ EXPECT_EQ(0, count_for_id) << "Faulty reporting_id: " << i; |
+ } |
+ return sum; |
+} |
+ |
} // namespace |
typedef InProcessBrowserTest PrefHashBrowserTest; |
@@ -126,12 +153,57 @@ IN_PROC_BROWSER_TEST_F(PrefHashBrowserTest, |
ASSERT_EQ(3U, hashes->size()); |
ProfileManager* profile_manager = g_browser_process->profile_manager(); |
- const std::vector<Profile*> loaded_profiles = |
- profile_manager->GetLoadedProfiles(); |
// Verify that only one profile was loaded. We assume that the unloaded |
// profile is the same one that wasn't loaded in the last launch (i.e., it's |
// the one whose hash store we reset, and the fact that it is now restored is |
// evidence that we restored the hashes of an unloaded profile.). |
- ASSERT_EQ(1U, loaded_profiles.size()); |
+ ASSERT_EQ(1U, profile_manager->GetLoadedProfiles().size()); |
+ |
+ // Loading the first profile should only have produced unchanged reports. |
+ EXPECT_EQ( |
+ 0, GetTrackedPrefHistogramCount( |
+ "Settings.TrackedPreferenceChanged", true)); |
+ EXPECT_EQ( |
+ 0, GetTrackedPrefHistogramCount( |
+ "Settings.TrackedPreferenceCleared", true)); |
+ EXPECT_EQ( |
+ 0, GetTrackedPrefHistogramCount( |
+ "Settings.TrackedPreferenceInitialized", true)); |
+ EXPECT_EQ( |
+ 0, GetTrackedPrefHistogramCount( |
+ "Settings.TrackedPreferenceTrustedInitialized", true)); |
+ EXPECT_EQ( |
+ 0, GetTrackedPrefHistogramCount( |
+ "Settings.TrackedPreferenceMigrated", true)); |
+ int initial_unchanged_count = |
+ GetTrackedPrefHistogramCount("Settings.TrackedPreferenceUnchanged", |
+ false); |
+ EXPECT_GT(initial_unchanged_count, 0); |
+ |
+ // Explicitly load the unloaded profile. |
+ profile_manager->GetProfile(GetUnloadedProfilePath()); |
+ ASSERT_EQ(2U, profile_manager->GetLoadedProfiles().size()); |
+ |
+ // Loading the unexpected profile should only generate unchanged pings; and |
+ // should have produced as many of them as loading the first profile. |
+ EXPECT_EQ( |
+ 0, GetTrackedPrefHistogramCount( |
+ "Settings.TrackedPreferenceChanged", true)); |
+ EXPECT_EQ( |
+ 0, GetTrackedPrefHistogramCount( |
+ "Settings.TrackedPreferenceCleared", true)); |
+ EXPECT_EQ( |
+ 0, GetTrackedPrefHistogramCount( |
+ "Settings.TrackedPreferenceInitialized", true)); |
+ EXPECT_EQ( |
+ 0, GetTrackedPrefHistogramCount( |
+ "Settings.TrackedPreferenceTrustedInitialized", true)); |
+ EXPECT_EQ( |
+ 0, GetTrackedPrefHistogramCount( |
+ "Settings.TrackedPreferenceMigrated", true)); |
+ EXPECT_EQ( |
+ initial_unchanged_count * 2, |
+ GetTrackedPrefHistogramCount("Settings.TrackedPreferenceUnchanged", |
+ false)); |
} |