| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/net/http_pipelining_compatibility_client.h" | 5 #include "chrome/browser/net/http_pipelining_compatibility_client.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/metrics/histogram_samples.h" | 15 #include "base/metrics/histogram_samples.h" |
| 16 #include "base/metrics/statistics_recorder.h" | 16 #include "base/metrics/statistics_recorder.h" |
| 17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 18 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
| 19 #include "content/public/test/test_browser_thread.h" | 19 #include "content/public/test/test_browser_thread.h" |
| 20 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
| 21 #include "net/base/test_completion_callback.h" | 21 #include "net/base/test_completion_callback.h" |
| 22 #include "net/url_request/url_request_context_getter.h" | 22 #include "net/url_request/url_request_context_getter.h" |
| 23 #include "net/url_request/url_request_test_util.h" | 23 #include "net/url_request/url_request_test_util.h" |
| 24 #include "net/test/test_server.h" | 24 #include "net/test/test_server.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 27 |
| 28 using base::Histogram; | 28 using base::HistogramBase; |
| 29 using base::HistogramSamples; | 29 using base::HistogramSamples; |
| 30 | 30 |
| 31 namespace chrome_browser_net { | 31 namespace chrome_browser_net { |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 static const char* const kHistogramNames[] = { | 35 static const char* const kHistogramNames[] = { |
| 36 "NetConnectivity.Pipeline.CanarySuccess", | 36 "NetConnectivity.Pipeline.CanarySuccess", |
| 37 "NetConnectivity.Pipeline.Depth", | 37 "NetConnectivity.Pipeline.Depth", |
| 38 "NetConnectivity.Pipeline.AllHTTP11", | 38 "NetConnectivity.Pipeline.AllHTTP11", |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 } | 203 } |
| 204 | 204 |
| 205 MessageLoopForIO message_loop_; | 205 MessageLoopForIO message_loop_; |
| 206 net::TestServer test_server_; | 206 net::TestServer test_server_; |
| 207 net::TestURLRequestContextGetter* context_; | 207 net::TestURLRequestContextGetter* context_; |
| 208 content::TestBrowserThread io_thread_; | 208 content::TestBrowserThread io_thread_; |
| 209 | 209 |
| 210 private: | 210 private: |
| 211 scoped_ptr<HistogramSamples> GetHistogram(const char* name) { | 211 scoped_ptr<HistogramSamples> GetHistogram(const char* name) { |
| 212 scoped_ptr<HistogramSamples> samples; | 212 scoped_ptr<HistogramSamples> samples; |
| 213 Histogram* cached_histogram = NULL; | 213 HistogramBase* cached_histogram = NULL; |
| 214 Histogram* current_histogram = | 214 HistogramBase* current_histogram = |
| 215 base::StatisticsRecorder::FindHistogram(name); | 215 base::StatisticsRecorder::FindHistogram(name); |
| 216 if (ContainsKey(histograms_, name)) { | 216 if (ContainsKey(histograms_, name)) { |
| 217 cached_histogram = histograms_[name]; | 217 cached_histogram = histograms_[name]; |
| 218 } | 218 } |
| 219 | 219 |
| 220 // This is to work around the CACHE_HISTOGRAM_* macros caching the last used | 220 // This is to work around the CACHE_HISTOGRAM_* macros caching the last used |
| 221 // histogram by name. So, even though we throw out the StatisticsRecorder | 221 // histogram by name. So, even though we throw out the StatisticsRecorder |
| 222 // between tests, the CACHE_HISTOGRAM_* might still write into the old | 222 // between tests, the CACHE_HISTOGRAM_* might still write into the old |
| 223 // Histogram if it has the same name as the last run. We keep a cache of the | 223 // Histogram if it has the same name as the last run. We keep a cache of the |
| 224 // last used Histogram and then update the cache if it's different than the | 224 // last used Histogram and then update the cache if it's different than the |
| 225 // current Histogram. | 225 // current Histogram. |
| 226 if (cached_histogram && current_histogram) { | 226 if (cached_histogram && current_histogram) { |
| 227 samples = cached_histogram->SnapshotSamples(); | 227 samples = cached_histogram->SnapshotSamples(); |
| 228 if (cached_histogram != current_histogram) { | 228 if (cached_histogram != current_histogram) { |
| 229 samples->Add(*(current_histogram->SnapshotSamples())); | 229 samples->Add(*(current_histogram->SnapshotSamples())); |
| 230 histograms_[name] = current_histogram; | 230 histograms_[name] = current_histogram; |
| 231 } | 231 } |
| 232 } else if (current_histogram) { | 232 } else if (current_histogram) { |
| 233 samples = current_histogram->SnapshotSamples(); | 233 samples = current_histogram->SnapshotSamples(); |
| 234 histograms_[name] = current_histogram; | 234 histograms_[name] = current_histogram; |
| 235 } else if (cached_histogram) { | 235 } else if (cached_histogram) { |
| 236 samples = cached_histogram->SnapshotSamples(); | 236 samples = cached_histogram->SnapshotSamples(); |
| 237 } | 237 } |
| 238 return samples.Pass(); | 238 return samples.Pass(); |
| 239 } | 239 } |
| 240 | 240 |
| 241 static std::map<std::string, Histogram*> histograms_; | 241 static std::map<std::string, HistogramBase*> histograms_; |
| 242 std::map<std::string, HistogramSamples*> original_samples_; | 242 std::map<std::string, HistogramSamples*> original_samples_; |
| 243 }; | 243 }; |
| 244 | 244 |
| 245 // static | 245 // static |
| 246 std::map<std::string, Histogram*> | 246 std::map<std::string, HistogramBase*> |
| 247 HttpPipeliningCompatibilityClientTest::histograms_; | 247 HttpPipeliningCompatibilityClientTest::histograms_; |
| 248 | 248 |
| 249 TEST_F(HttpPipeliningCompatibilityClientTest, Success) { | 249 TEST_F(HttpPipeliningCompatibilityClientTest, Success) { |
| 250 RequestInfo info; | 250 RequestInfo info; |
| 251 info.filename = "files/alphabet.txt"; | 251 info.filename = "files/alphabet.txt"; |
| 252 info.expected_response = "abcdefghijklmnopqrstuvwxyz"; | 252 info.expected_response = "abcdefghijklmnopqrstuvwxyz"; |
| 253 std::vector<RequestInfo> requests; | 253 std::vector<RequestInfo> requests; |
| 254 requests.push_back(info); | 254 requests.push_back(info); |
| 255 | 255 |
| 256 RunTest(requests, HttpPipeliningCompatibilityClient::PIPE_TEST_DEFAULTS); | 256 RunTest(requests, HttpPipeliningCompatibilityClient::PIPE_TEST_DEFAULTS); |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 callback.WaitForResult(); | 586 callback.WaitForResult(); |
| 587 | 587 |
| 588 ExpectHistogramCount(1, false, FIELD_CANARY); | 588 ExpectHistogramCount(1, false, FIELD_CANARY); |
| 589 ExpectHistogramCount(0, false, FIELD_SUCCESS); | 589 ExpectHistogramCount(0, false, FIELD_SUCCESS); |
| 590 ExpectHistogramCount(0, true, FIELD_SUCCESS); | 590 ExpectHistogramCount(0, true, FIELD_SUCCESS); |
| 591 } | 591 } |
| 592 | 592 |
| 593 } // anonymous namespace | 593 } // anonymous namespace |
| 594 | 594 |
| 595 } // namespace chrome_browser_net | 595 } // namespace chrome_browser_net |
| OLD | NEW |