OLD | NEW |
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS 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 <unistd.h> | 5 #include <unistd.h> |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/logging.h" | 11 #include <base/logging.h> |
12 #include "base/scoped_ptr.h" | 12 #include <base/scoped_ptr.h> |
13 #include "base/string_util.h" | 13 #include <base/string_util.h> |
14 #include "glib.h" | 14 #include <glib.h> |
15 #include "gtest/gtest.h" | 15 #include <gtest/gtest.h> |
| 16 |
16 #include "update_engine/libcurl_http_fetcher.h" | 17 #include "update_engine/libcurl_http_fetcher.h" |
17 #include "update_engine/mock_http_fetcher.h" | 18 #include "update_engine/mock_http_fetcher.h" |
18 #include "update_engine/multi_http_fetcher.h" | 19 #include "update_engine/multi_http_fetcher.h" |
| 20 #include "update_engine/proxy_resolver.h" |
19 | 21 |
20 using std::make_pair; | 22 using std::make_pair; |
21 using std::string; | 23 using std::string; |
22 using std::vector; | 24 using std::vector; |
23 | 25 |
24 namespace chromeos_update_engine { | 26 namespace chromeos_update_engine { |
25 | 27 |
26 namespace { | 28 namespace { |
27 // WARNING, if you update these, you must also update test_http_server.cc. | 29 // WARNING, if you update these, you must also update test_http_server.cc. |
28 const char* const kServerPort = "8088"; | 30 const char* const kServerPort = "8088"; |
(...skipping 20 matching lines...) Expand all Loading... |
49 ~NullHttpServer() {} | 51 ~NullHttpServer() {} |
50 bool started_; | 52 bool started_; |
51 }; | 53 }; |
52 | 54 |
53 | 55 |
54 template <> | 56 template <> |
55 class HttpFetcherTest<MockHttpFetcher> : public ::testing::Test { | 57 class HttpFetcherTest<MockHttpFetcher> : public ::testing::Test { |
56 public: | 58 public: |
57 HttpFetcher* NewLargeFetcher() { | 59 HttpFetcher* NewLargeFetcher() { |
58 vector<char> big_data(1000000); | 60 vector<char> big_data(1000000); |
59 return new MockHttpFetcher(big_data.data(), big_data.size()); | 61 return new MockHttpFetcher( |
| 62 big_data.data(), |
| 63 big_data.size(), |
| 64 reinterpret_cast<ProxyResolver*>(&proxy_resolver_)); |
60 } | 65 } |
61 HttpFetcher* NewSmallFetcher() { | 66 HttpFetcher* NewSmallFetcher() { |
62 return new MockHttpFetcher("x", 1); | 67 return new MockHttpFetcher( |
| 68 "x", |
| 69 1, |
| 70 reinterpret_cast<ProxyResolver*>(&proxy_resolver_)); |
63 } | 71 } |
64 string BigUrl() const { | 72 string BigUrl() const { |
65 return "unused://unused"; | 73 return "unused://unused"; |
66 } | 74 } |
67 string SmallUrl() const { | 75 string SmallUrl() const { |
68 return "unused://unused"; | 76 return "unused://unused"; |
69 } | 77 } |
70 bool IsMock() const { return true; } | 78 bool IsMock() const { return true; } |
71 bool IsMulti() const { return false; } | 79 bool IsMulti() const { return false; } |
72 typedef NullHttpServer HttpServer; | 80 typedef NullHttpServer HttpServer; |
73 void IgnoreServerAborting(HttpServer* server) const {} | 81 void IgnoreServerAborting(HttpServer* server) const {} |
| 82 |
| 83 DirectProxyResolver proxy_resolver_; |
74 }; | 84 }; |
75 | 85 |
76 class PythonHttpServer { | 86 class PythonHttpServer { |
77 public: | 87 public: |
78 PythonHttpServer() { | 88 PythonHttpServer() { |
79 char *argv[2] = {strdup("./test_http_server"), NULL}; | 89 char *argv[2] = {strdup("./test_http_server"), NULL}; |
80 GError *err; | 90 GError *err; |
81 started_ = false; | 91 started_ = false; |
82 validate_quit_ = true; | 92 validate_quit_ = true; |
83 if (!g_spawn_async(NULL, | 93 if (!g_spawn_async(NULL, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 } | 134 } |
125 GPid pid_; | 135 GPid pid_; |
126 bool started_; | 136 bool started_; |
127 bool validate_quit_; | 137 bool validate_quit_; |
128 }; | 138 }; |
129 | 139 |
130 template <> | 140 template <> |
131 class HttpFetcherTest<LibcurlHttpFetcher> : public ::testing::Test { | 141 class HttpFetcherTest<LibcurlHttpFetcher> : public ::testing::Test { |
132 public: | 142 public: |
133 virtual HttpFetcher* NewLargeFetcher() { | 143 virtual HttpFetcher* NewLargeFetcher() { |
134 LibcurlHttpFetcher *ret = new LibcurlHttpFetcher; | 144 LibcurlHttpFetcher *ret = new |
| 145 LibcurlHttpFetcher(reinterpret_cast<ProxyResolver*>(&proxy_resolver_)); |
135 // Speed up test execution. | 146 // Speed up test execution. |
136 ret->set_idle_seconds(1); | 147 ret->set_idle_seconds(1); |
137 ret->set_retry_seconds(1); | 148 ret->set_retry_seconds(1); |
138 ret->SetConnectionAsExpensive(false); | 149 ret->SetConnectionAsExpensive(false); |
139 ret->SetBuildType(false); | 150 ret->SetBuildType(false); |
140 return ret; | 151 return ret; |
141 } | 152 } |
142 HttpFetcher* NewSmallFetcher() { | 153 HttpFetcher* NewSmallFetcher() { |
143 return NewLargeFetcher(); | 154 return NewLargeFetcher(); |
144 } | 155 } |
145 string BigUrl() const { | 156 string BigUrl() const { |
146 return LocalServerUrlForPath("/big"); | 157 return LocalServerUrlForPath("/big"); |
147 } | 158 } |
148 string SmallUrl() const { | 159 string SmallUrl() const { |
149 return LocalServerUrlForPath("/foo"); | 160 return LocalServerUrlForPath("/foo"); |
150 } | 161 } |
151 bool IsMock() const { return false; } | 162 bool IsMock() const { return false; } |
152 bool IsMulti() const { return false; } | 163 bool IsMulti() const { return false; } |
153 typedef PythonHttpServer HttpServer; | 164 typedef PythonHttpServer HttpServer; |
154 void IgnoreServerAborting(HttpServer* server) const { | 165 void IgnoreServerAborting(HttpServer* server) const { |
155 PythonHttpServer *pyserver = reinterpret_cast<PythonHttpServer*>(server); | 166 PythonHttpServer *pyserver = reinterpret_cast<PythonHttpServer*>(server); |
156 pyserver->validate_quit_ = false; | 167 pyserver->validate_quit_ = false; |
157 } | 168 } |
| 169 DirectProxyResolver proxy_resolver_; |
158 }; | 170 }; |
159 | 171 |
160 template <> | 172 template <> |
161 class HttpFetcherTest<MultiHttpFetcher<LibcurlHttpFetcher> > | 173 class HttpFetcherTest<MultiHttpFetcher<LibcurlHttpFetcher> > |
162 : public HttpFetcherTest<LibcurlHttpFetcher> { | 174 : public HttpFetcherTest<LibcurlHttpFetcher> { |
163 public: | 175 public: |
164 HttpFetcher* NewLargeFetcher() { | 176 HttpFetcher* NewLargeFetcher() { |
165 MultiHttpFetcher<LibcurlHttpFetcher> *ret = | 177 MultiHttpFetcher<LibcurlHttpFetcher> *ret = |
166 new MultiHttpFetcher<LibcurlHttpFetcher>; | 178 new MultiHttpFetcher<LibcurlHttpFetcher>( |
| 179 reinterpret_cast<ProxyResolver*>(&proxy_resolver_)); |
167 MultiHttpFetcher<LibcurlHttpFetcher>::RangesVect | 180 MultiHttpFetcher<LibcurlHttpFetcher>::RangesVect |
168 ranges(1, make_pair(0, -1)); | 181 ranges(1, make_pair(0, -1)); |
169 ret->set_ranges(ranges); | 182 ret->set_ranges(ranges); |
170 // Speed up test execution. | 183 // Speed up test execution. |
171 ret->set_idle_seconds(1); | 184 ret->set_idle_seconds(1); |
172 ret->set_retry_seconds(1); | 185 ret->set_retry_seconds(1); |
173 ret->SetConnectionAsExpensive(false); | 186 ret->SetConnectionAsExpensive(false); |
174 ret->SetBuildType(false); | 187 ret->SetBuildType(false); |
175 return ret; | 188 return ret; |
176 } | 189 } |
177 bool IsMulti() const { return true; } | 190 bool IsMulti() const { return true; } |
| 191 DirectProxyResolver proxy_resolver_; |
178 }; | 192 }; |
179 | 193 |
180 typedef ::testing::Types<LibcurlHttpFetcher, | 194 typedef ::testing::Types<LibcurlHttpFetcher, |
181 MockHttpFetcher, | 195 MockHttpFetcher, |
182 MultiHttpFetcher<LibcurlHttpFetcher> > | 196 MultiHttpFetcher<LibcurlHttpFetcher> > |
183 HttpFetcherTestTypes; | 197 HttpFetcherTestTypes; |
184 TYPED_TEST_CASE(HttpFetcherTest, HttpFetcherTestTypes); | 198 TYPED_TEST_CASE(HttpFetcherTest, HttpFetcherTestTypes); |
185 | 199 |
186 namespace { | 200 namespace { |
187 class HttpFetcherTestDelegate : public HttpFetcherDelegate { | 201 class HttpFetcherTestDelegate : public HttpFetcherDelegate { |
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 StartTransferArgs start_xfer_args = | 796 StartTransferArgs start_xfer_args = |
783 { fetcher.get(), LocalServerUrlForPath(this->SmallUrl()) }; | 797 { fetcher.get(), LocalServerUrlForPath(this->SmallUrl()) }; |
784 | 798 |
785 g_timeout_add(0, StartTransfer, &start_xfer_args); | 799 g_timeout_add(0, StartTransfer, &start_xfer_args); |
786 g_main_loop_run(loop); | 800 g_main_loop_run(loop); |
787 g_main_loop_unref(loop); | 801 g_main_loop_unref(loop); |
788 } | 802 } |
789 } | 803 } |
790 | 804 |
791 } // namespace chromeos_update_engine | 805 } // namespace chromeos_update_engine |
OLD | NEW |