Index: chrome/browser/net/http_pipelining_compatibility_client_unittest.cc |
diff --git a/chrome/browser/net/http_pipelining_compatibility_client_unittest.cc b/chrome/browser/net/http_pipelining_compatibility_client_unittest.cc |
index 39ebfcd3c5e68fe9a445269122a3c69c2ac6bbe2..eb9dd0f1313a95bc315e5a3ee35772d2d954594b 100644 |
--- a/chrome/browser/net/http_pipelining_compatibility_client_unittest.cc |
+++ b/chrome/browser/net/http_pipelining_compatibility_client_unittest.cc |
@@ -126,13 +126,32 @@ class HttpPipeliningCompatibilityClientTest : public testing::Test { |
private: |
base::Histogram::SampleSet GetHistogram(const char* name) { |
base::Histogram::SampleSet sample; |
- base::Histogram* histogram; |
+ base::Histogram* current_histogram = NULL; |
+ base::Histogram* cached_histogram = NULL; |
+ base::StatisticsRecorder::FindHistogram(name, ¤t_histogram); |
if (ContainsKey(histograms_, name)) { |
- histogram = histograms_[name]; |
- histogram->SnapshotSample(&sample); |
- } else if (base::StatisticsRecorder::FindHistogram(name, &histogram)) { |
- histograms_[name] = histogram; |
- histogram->SnapshotSample(&sample); |
+ cached_histogram = histograms_[name]; |
+ } |
+ |
+ // This is to work around the CACHE_HISTOGRAM_* macros caching the last used |
+ // histogram by name. So, even though we throw out the StatisticsRecorder |
+ // between tests, the CACHE_HISTOGRAM_* might still write into the old |
+ // Histogram if it has the same name as the last run. We keep a cache of the |
+ // last used Histogram and then update the cache if it's different than the |
+ // current Histogram. |
mmenke
2012/02/23 18:54:58
Why was this working before, but is now causing pr
James Simonsen
2012/02/23 23:49:46
The old version was broken, but just happened to w
|
+ if (cached_histogram && current_histogram) { |
+ cached_histogram->SnapshotSample(&sample); |
+ if (cached_histogram != current_histogram) { |
+ base::Histogram::SampleSet current_sample; |
+ current_histogram->SnapshotSample(¤t_sample); |
+ sample.Add(current_sample); |
+ histograms_[name] = current_histogram; |
+ } |
+ } else if (current_histogram) { |
+ current_histogram->SnapshotSample(&sample); |
+ histograms_[name] = current_histogram; |
+ } else if (cached_histogram) { |
+ cached_histogram->SnapshotSample(&sample); |
} |
return sample; |
} |
@@ -415,7 +434,7 @@ TEST_F(HttpPipeliningCompatibilityClientTest, MultipleRequests) { |
base::Histogram::SampleSet network_sample2 = |
GetHistogramValue(1, FIELD_NETWORK_ERROR); |
EXPECT_EQ(1, network_sample2.TotalCount()); |
- EXPECT_EQ(1, network_sample2.counts(-net::ERR_EMPTY_RESPONSE)); |
+ EXPECT_EQ(1, network_sample2.counts(-net::ERR_PIPELINE_EVICTION)); |
base::Histogram::SampleSet response_sample2 = |
GetHistogramValue(1, FIELD_RESPONSE_CODE); |
@@ -425,16 +444,16 @@ TEST_F(HttpPipeliningCompatibilityClientTest, MultipleRequests) { |
GetHistogramValue(2, FIELD_STATUS); |
EXPECT_EQ(1, status_sample3.TotalCount()); |
EXPECT_EQ(1, status_sample3.counts( |
- HttpPipeliningCompatibilityClient::BAD_RESPONSE_CODE)); |
+ HttpPipeliningCompatibilityClient::NETWORK_ERROR)); |
base::Histogram::SampleSet network_sample3 = |
GetHistogramValue(2, FIELD_NETWORK_ERROR); |
- EXPECT_EQ(0, network_sample3.TotalCount()); |
+ EXPECT_EQ(1, network_sample3.TotalCount()); |
+ EXPECT_EQ(1, network_sample3.counts(-net::ERR_PIPELINE_EVICTION)); |
base::Histogram::SampleSet response_sample3 = |
GetHistogramValue(2, FIELD_RESPONSE_CODE); |
- EXPECT_EQ(1, response_sample3.TotalCount()); |
- EXPECT_EQ(1, response_sample3.counts(401)); |
+ EXPECT_EQ(0, response_sample3.TotalCount()); |
} |
} // anonymous namespace |