| 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" | |
| 14 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 15 #include "base/metrics/histogram_samples.h" | 14 #include "base/metrics/histogram_samples.h" |
| 16 #include "base/metrics/statistics_recorder.h" | 15 #include "base/metrics/statistics_recorder.h" |
| 16 #include "base/run_loop.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/browser/browser_thread.h" |
| 20 #include "content/public/test/test_browser_thread_bundle.h" |
| 20 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
| 21 #include "net/base/test_completion_callback.h" | 22 #include "net/base/test_completion_callback.h" |
| 22 #include "net/test/spawned_test_server/spawned_test_server.h" | 23 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 23 #include "net/url_request/url_request_context_getter.h" | 24 #include "net/url_request/url_request_context_getter.h" |
| 24 #include "net/url_request/url_request_test_util.h" | 25 #include "net/url_request/url_request_test_util.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 28 |
| 28 using base::HistogramBase; | 29 using base::HistogramBase; |
| 29 using base::HistogramSamples; | 30 using base::HistogramSamples; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 using content::BrowserThread; | 75 using content::BrowserThread; |
| 75 using testing::_; | 76 using testing::_; |
| 76 using testing::Field; | 77 using testing::Field; |
| 77 using testing::Invoke; | 78 using testing::Invoke; |
| 78 using testing::Return; | 79 using testing::Return; |
| 79 using testing::StrEq; | 80 using testing::StrEq; |
| 80 | 81 |
| 81 class HttpPipeliningCompatibilityClientTest : public testing::Test { | 82 class HttpPipeliningCompatibilityClientTest : public testing::Test { |
| 82 public: | 83 public: |
| 83 HttpPipeliningCompatibilityClientTest() | 84 HttpPipeliningCompatibilityClientTest() |
| 84 : test_server_(net::SpawnedTestServer::TYPE_HTTP, | 85 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 86 test_server_(net::SpawnedTestServer::TYPE_HTTP, |
| 85 net::SpawnedTestServer::kLocalhost, | 87 net::SpawnedTestServer::kLocalhost, |
| 86 base::FilePath(FILE_PATH_LITERAL( | 88 base::FilePath(FILE_PATH_LITERAL( |
| 87 "chrome/test/data/http_pipelining"))), | 89 "chrome/test/data/http_pipelining"))) { |
| 88 io_thread_(BrowserThread::IO, &message_loop_) { | |
| 89 } | 90 } |
| 90 | 91 |
| 91 protected: | 92 protected: |
| 92 virtual void SetUp() OVERRIDE { | 93 virtual void SetUp() OVERRIDE { |
| 93 // Start up a histogram recorder. | 94 // Start up a histogram recorder. |
| 94 // TODO(rtenneti): Leaks StatisticsRecorder and will update suppressions. | 95 // TODO(rtenneti): Leaks StatisticsRecorder and will update suppressions. |
| 95 base::StatisticsRecorder::Initialize(); | 96 base::StatisticsRecorder::Initialize(); |
| 96 ASSERT_TRUE(test_server_.Start()); | 97 ASSERT_TRUE(test_server_.Start()); |
| 97 context_ = new net::TestURLRequestContextGetter( | 98 context_ = new net::TestURLRequestContextGetter( |
| 98 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); | 99 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
| 99 context_->AddRef(); | 100 context_->AddRef(); |
| 100 | 101 |
| 101 for (size_t i = 0; i < arraysize(kHistogramNames); ++i) { | 102 for (size_t i = 0; i < arraysize(kHistogramNames); ++i) { |
| 102 const char* name = kHistogramNames[i]; | 103 const char* name = kHistogramNames[i]; |
| 103 scoped_ptr<HistogramSamples> samples = GetHistogram(name); | 104 scoped_ptr<HistogramSamples> samples = GetHistogram(name); |
| 104 if (samples.get() && samples->TotalCount() > 0) { | 105 if (samples.get() && samples->TotalCount() > 0) { |
| 105 original_samples_[name] = samples.release(); | 106 original_samples_[name] = samples.release(); |
| 106 } | 107 } |
| 107 } | 108 } |
| 108 } | 109 } |
| 109 | 110 |
| 110 virtual void TearDown() OVERRIDE { | 111 virtual void TearDown() OVERRIDE { |
| 111 BrowserThread::ReleaseSoon(BrowserThread::IO, FROM_HERE, context_); | 112 BrowserThread::ReleaseSoon(BrowserThread::IO, FROM_HERE, context_); |
| 112 message_loop_.RunUntilIdle(); | 113 base::RunLoop().RunUntilIdle(); |
| 113 STLDeleteValues(&original_samples_); | 114 STLDeleteValues(&original_samples_); |
| 114 } | 115 } |
| 115 | 116 |
| 116 void RunTest( | 117 void RunTest( |
| 117 std::vector<RequestInfo> requests, | 118 std::vector<RequestInfo> requests, |
| 118 HttpPipeliningCompatibilityClient::Options options) { | 119 HttpPipeliningCompatibilityClient::Options options) { |
| 119 HttpPipeliningCompatibilityClient client(NULL); | 120 HttpPipeliningCompatibilityClient client(NULL); |
| 120 net::TestCompletionCallback callback; | 121 net::TestCompletionCallback callback; |
| 121 client.Start(test_server_.GetURL(std::string()).spec(), | 122 client.Start(test_server_.GetURL(std::string()).spec(), |
| 122 requests, | 123 requests, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 if (ContainsKey(original_samples_, name)) { | 198 if (ContainsKey(original_samples_, name)) { |
| 198 samples->Subtract(*(original_samples_[name])); | 199 samples->Subtract(*(original_samples_[name])); |
| 199 } | 200 } |
| 200 | 201 |
| 201 EXPECT_EQ(expected_count, samples->TotalCount()) << name; | 202 EXPECT_EQ(expected_count, samples->TotalCount()) << name; |
| 202 if (expected_count > 0) { | 203 if (expected_count > 0) { |
| 203 EXPECT_EQ(expected_count, samples->GetCount(expected_value)) << name; | 204 EXPECT_EQ(expected_count, samples->GetCount(expected_value)) << name; |
| 204 } | 205 } |
| 205 } | 206 } |
| 206 | 207 |
| 207 base::MessageLoopForIO message_loop_; | 208 content::TestBrowserThreadBundle thread_bundle_; |
| 208 net::SpawnedTestServer test_server_; | 209 net::SpawnedTestServer test_server_; |
| 209 net::TestURLRequestContextGetter* context_; | 210 net::TestURLRequestContextGetter* context_; |
| 210 content::TestBrowserThread io_thread_; | |
| 211 | 211 |
| 212 private: | 212 private: |
| 213 scoped_ptr<HistogramSamples> GetHistogram(const char* name) { | 213 scoped_ptr<HistogramSamples> GetHistogram(const char* name) { |
| 214 scoped_ptr<HistogramSamples> samples; | 214 scoped_ptr<HistogramSamples> samples; |
| 215 HistogramBase* cached_histogram = NULL; | 215 HistogramBase* cached_histogram = NULL; |
| 216 HistogramBase* current_histogram = | 216 HistogramBase* current_histogram = |
| 217 base::StatisticsRecorder::FindHistogram(name); | 217 base::StatisticsRecorder::FindHistogram(name); |
| 218 if (ContainsKey(histograms_, name)) { | 218 if (ContainsKey(histograms_, name)) { |
| 219 cached_histogram = histograms_[name]; | 219 cached_histogram = histograms_[name]; |
| 220 } | 220 } |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 callback.WaitForResult(); | 588 callback.WaitForResult(); |
| 589 | 589 |
| 590 ExpectHistogramCount(1, false, FIELD_CANARY); | 590 ExpectHistogramCount(1, false, FIELD_CANARY); |
| 591 ExpectHistogramCount(0, false, FIELD_SUCCESS); | 591 ExpectHistogramCount(0, false, FIELD_SUCCESS); |
| 592 ExpectHistogramCount(0, true, FIELD_SUCCESS); | 592 ExpectHistogramCount(0, true, FIELD_SUCCESS); |
| 593 } | 593 } |
| 594 | 594 |
| 595 } // anonymous namespace | 595 } // anonymous namespace |
| 596 | 596 |
| 597 } // namespace chrome_browser_net | 597 } // namespace chrome_browser_net |
| OLD | NEW |