diff options
author | ncbray@google.com <ncbray@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-12 00:23:32 +0000 |
---|---|---|
committer | ncbray@google.com <ncbray@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-12 00:23:32 +0000 |
commit | 07d4c7d6585a2b86c7cacf65e8b2bcf05ff6e4c3 (patch) | |
tree | 6ae04dfbe357578c43597cdda76d0bed1c3a0f30 /chrome/test/nacl/nacl_browsertest_uma.cc | |
parent | bb71b717c12c96d7fe1ad986137d52e20f2c476f (diff) | |
download | chromium_src-07d4c7d6585a2b86c7cacf65e8b2bcf05ff6e4c3.zip chromium_src-07d4c7d6585a2b86c7cacf65e8b2bcf05ff6e4c3.tar.gz chromium_src-07d4c7d6585a2b86c7cacf65e8b2bcf05ff6e4c3.tar.bz2 |
Move UMAHistogramHelper into chrome/test/base so that it can be shared.
BUG= http://code.google.com/p/nativeclient/issues/detail?id=2959
Review URL: https://chromiumcodereview.appspot.com/10908179
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156187 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/nacl/nacl_browsertest_uma.cc')
-rw-r--r-- | chrome/test/nacl/nacl_browsertest_uma.cc | 99 |
1 files changed, 2 insertions, 97 deletions
diff --git a/chrome/test/nacl/nacl_browsertest_uma.cc b/chrome/test/nacl/nacl_browsertest_uma.cc index fc7ac73..e67e267 100644 --- a/chrome/test/nacl/nacl_browsertest_uma.cc +++ b/chrome/test/nacl/nacl_browsertest_uma.cc @@ -2,115 +2,20 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/bind.h" -#include "base/metrics/histogram.h" -#include "base/metrics/statistics_recorder.h" -#include "chrome/test/base/ui_test_utils.h" +#include "chrome/test/base/uma_histogram_helper.h" #include "chrome/test/nacl/nacl_browsertest_util.h" -#include "content/public/browser/histogram_fetcher.h" #include "native_client/src/trusted/service_runtime/nacl_error_code.h" #include "ppapi/native_client/src/trusted/plugin/plugin_error.h" namespace { -class HistogramHelper { - public: - HistogramHelper(); - - // Each child process may have its own histogram data, make sure this data - // gets accumulated into the browser process before we examine the histograms. - void Fetch(); - - // We know the exact number of samples in a bucket, and that no other bucket - // should have samples. - void ExpectUniqueSample(const std::string& name, size_t bucket_id, - base::Histogram::Count expected_count); - - // We don't know the values of the samples, but we know how many there are. - void ExpectTotalCount(const std::string& name, base::Histogram::Count count); - - private: - void FetchCallback(); - - void CheckBucketCount(const std::string& name, size_t bucket_id, - base::Histogram::Count expected_count, - base::Histogram::SampleSet& samples); - - void CheckTotalCount(const std::string& name, - base::Histogram::Count expected_count, - base::Histogram::SampleSet& samples); -}; - -HistogramHelper::HistogramHelper() { -} - -void HistogramHelper::Fetch() { - base::Closure callback = base::Bind(&HistogramHelper::FetchCallback, - base::Unretained(this)); - - content::FetchHistogramsAsynchronously( - MessageLoop::current(), - callback, - // Give up after 60 seconds, which is longer than the 45 second timeout - // for browser tests. If this call times out, it means that a child - // process is not responding which is something we should not ignore. - base::TimeDelta::FromMilliseconds(60000)); - content::RunMessageLoop(); -} - -void HistogramHelper::ExpectUniqueSample( - const std::string& name, - size_t bucket_id, - base::Histogram::Count expected_count) { - base::Histogram* histogram = base::StatisticsRecorder::FindHistogram(name); - ASSERT_NE(static_cast<base::Histogram*>(NULL), histogram) << - "Histogram \"" << name << "\" does not exist."; - - base::Histogram::SampleSet samples; - histogram->SnapshotSample(&samples); - CheckBucketCount(name, bucket_id, expected_count, samples); - CheckTotalCount(name, expected_count, samples); -} - -void HistogramHelper::ExpectTotalCount(const std::string& name, - base::Histogram::Count count) { - base::Histogram* histogram = base::StatisticsRecorder::FindHistogram(name); - ASSERT_NE((base::Histogram*)NULL, histogram) << "Histogram \"" << name << - "\" does not exist."; - - base::Histogram::SampleSet samples; - histogram->SnapshotSample(&samples); - CheckTotalCount(name, count, samples); -} - -void HistogramHelper::FetchCallback() { - MessageLoopForUI::current()->Quit(); -} - -void HistogramHelper::CheckBucketCount(const std::string& name, - size_t bucket_id, - base::Histogram::Count expected_count, - base::Histogram::SampleSet& samples) { - EXPECT_EQ(expected_count, samples.counts(bucket_id)) << "Histogram \"" << - name << "\" does not have the right number of samples (" << - expected_count << ") in the expected bucket (" << bucket_id << ")."; -} - -void HistogramHelper::CheckTotalCount(const std::string& name, - base::Histogram::Count expected_count, - base::Histogram::SampleSet& samples) { - EXPECT_EQ(expected_count, samples.TotalCount()) << "Histogram \"" << name << - "\" does not have the right total number of samples (" << - expected_count << ")."; -} - NACL_BROWSER_TEST_F(NaClBrowserTest, SuccessfulLoadUMA, { // Load a NaCl module to generate UMA data. RunLoadTest(FILE_PATH_LITERAL("nacl_load_test.html")); // Make sure histograms from child processes have been accumulated in the // browser brocess. - HistogramHelper histograms; + UMAHistogramHelper histograms; histograms.Fetch(); // Did the plugin report success? |