Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: http_fetcher_unittest.cc

Issue 5205002: AU: Manual proxy support (Closed) Base URL: http://git.chromium.org/git/update_engine.git@master
Patch Set: fixes for review Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "update_engine/libcurl_http_fetcher.h" 16 #include "update_engine/libcurl_http_fetcher.h"
petkov 2010/11/22 17:49:00 blank line before and use <> for the headers above
adlr 2010/11/22 18:54:46 Done.
17 #include "update_engine/mock_http_fetcher.h" 17 #include "update_engine/mock_http_fetcher.h"
18 #include "update_engine/multi_http_fetcher.h" 18 #include "update_engine/multi_http_fetcher.h"
19 #include "update_engine/proxy_resolver.h"
19 20
20 using std::make_pair; 21 using std::make_pair;
21 using std::string; 22 using std::string;
22 using std::vector; 23 using std::vector;
23 24
24 namespace chromeos_update_engine { 25 namespace chromeos_update_engine {
25 26
26 namespace { 27 namespace {
27 // WARNING, if you update these, you must also update test_http_server.cc. 28 // WARNING, if you update these, you must also update test_http_server.cc.
28 const char* const kServerPort = "8088"; 29 const char* const kServerPort = "8088";
(...skipping 20 matching lines...) Expand all
49 ~NullHttpServer() {} 50 ~NullHttpServer() {}
50 bool started_; 51 bool started_;
51 }; 52 };
52 53
53 54
54 template <> 55 template <>
55 class HttpFetcherTest<MockHttpFetcher> : public ::testing::Test { 56 class HttpFetcherTest<MockHttpFetcher> : public ::testing::Test {
56 public: 57 public:
57 HttpFetcher* NewLargeFetcher() { 58 HttpFetcher* NewLargeFetcher() {
58 vector<char> big_data(1000000); 59 vector<char> big_data(1000000);
59 return new MockHttpFetcher(big_data.data(), big_data.size()); 60 return new MockHttpFetcher(
61 big_data.data(),
62 big_data.size(),
63 reinterpret_cast<ProxyResolver*>(&proxy_resolver_));
60 } 64 }
61 HttpFetcher* NewSmallFetcher() { 65 HttpFetcher* NewSmallFetcher() {
62 return new MockHttpFetcher("x", 1); 66 return new MockHttpFetcher(
67 "x",
68 1,
69 reinterpret_cast<ProxyResolver*>(&proxy_resolver_));
63 } 70 }
64 string BigUrl() const { 71 string BigUrl() const {
65 return "unused://unused"; 72 return "unused://unused";
66 } 73 }
67 string SmallUrl() const { 74 string SmallUrl() const {
68 return "unused://unused"; 75 return "unused://unused";
69 } 76 }
70 bool IsMock() const { return true; } 77 bool IsMock() const { return true; }
71 bool IsMulti() const { return false; } 78 bool IsMulti() const { return false; }
72 typedef NullHttpServer HttpServer; 79 typedef NullHttpServer HttpServer;
73 void IgnoreServerAborting(HttpServer* server) const {} 80 void IgnoreServerAborting(HttpServer* server) const {}
81
82 DirectProxyResolver proxy_resolver_;
74 }; 83 };
75 84
76 class PythonHttpServer { 85 class PythonHttpServer {
77 public: 86 public:
78 PythonHttpServer() { 87 PythonHttpServer() {
79 char *argv[2] = {strdup("./test_http_server"), NULL}; 88 char *argv[2] = {strdup("./test_http_server"), NULL};
80 GError *err; 89 GError *err;
81 started_ = false; 90 started_ = false;
82 validate_quit_ = true; 91 validate_quit_ = true;
83 if (!g_spawn_async(NULL, 92 if (!g_spawn_async(NULL,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 } 133 }
125 GPid pid_; 134 GPid pid_;
126 bool started_; 135 bool started_;
127 bool validate_quit_; 136 bool validate_quit_;
128 }; 137 };
129 138
130 template <> 139 template <>
131 class HttpFetcherTest<LibcurlHttpFetcher> : public ::testing::Test { 140 class HttpFetcherTest<LibcurlHttpFetcher> : public ::testing::Test {
132 public: 141 public:
133 virtual HttpFetcher* NewLargeFetcher() { 142 virtual HttpFetcher* NewLargeFetcher() {
134 LibcurlHttpFetcher *ret = new LibcurlHttpFetcher; 143 LibcurlHttpFetcher *ret = new
144 LibcurlHttpFetcher(reinterpret_cast<ProxyResolver*>(&proxy_resolver_));
135 // Speed up test execution. 145 // Speed up test execution.
136 ret->set_idle_seconds(1); 146 ret->set_idle_seconds(1);
137 ret->set_retry_seconds(1); 147 ret->set_retry_seconds(1);
138 ret->SetConnectionAsExpensive(false); 148 ret->SetConnectionAsExpensive(false);
139 ret->SetBuildType(false); 149 ret->SetBuildType(false);
140 return ret; 150 return ret;
141 } 151 }
142 HttpFetcher* NewSmallFetcher() { 152 HttpFetcher* NewSmallFetcher() {
143 return NewLargeFetcher(); 153 return NewLargeFetcher();
144 } 154 }
145 string BigUrl() const { 155 string BigUrl() const {
146 return LocalServerUrlForPath("/big"); 156 return LocalServerUrlForPath("/big");
147 } 157 }
148 string SmallUrl() const { 158 string SmallUrl() const {
149 return LocalServerUrlForPath("/foo"); 159 return LocalServerUrlForPath("/foo");
150 } 160 }
151 bool IsMock() const { return false; } 161 bool IsMock() const { return false; }
152 bool IsMulti() const { return false; } 162 bool IsMulti() const { return false; }
153 typedef PythonHttpServer HttpServer; 163 typedef PythonHttpServer HttpServer;
154 void IgnoreServerAborting(HttpServer* server) const { 164 void IgnoreServerAborting(HttpServer* server) const {
155 PythonHttpServer *pyserver = reinterpret_cast<PythonHttpServer*>(server); 165 PythonHttpServer *pyserver = reinterpret_cast<PythonHttpServer*>(server);
156 pyserver->validate_quit_ = false; 166 pyserver->validate_quit_ = false;
157 } 167 }
168 DirectProxyResolver proxy_resolver_;
158 }; 169 };
159 170
160 template <> 171 template <>
161 class HttpFetcherTest<MultiHttpFetcher<LibcurlHttpFetcher> > 172 class HttpFetcherTest<MultiHttpFetcher<LibcurlHttpFetcher> >
162 : public HttpFetcherTest<LibcurlHttpFetcher> { 173 : public HttpFetcherTest<LibcurlHttpFetcher> {
163 public: 174 public:
164 HttpFetcher* NewLargeFetcher() { 175 HttpFetcher* NewLargeFetcher() {
165 MultiHttpFetcher<LibcurlHttpFetcher> *ret = 176 MultiHttpFetcher<LibcurlHttpFetcher> *ret =
166 new MultiHttpFetcher<LibcurlHttpFetcher>; 177 new MultiHttpFetcher<LibcurlHttpFetcher>(
178 reinterpret_cast<ProxyResolver*>(&proxy_resolver_));
167 MultiHttpFetcher<LibcurlHttpFetcher>::RangesVect 179 MultiHttpFetcher<LibcurlHttpFetcher>::RangesVect
168 ranges(1, make_pair(0, -1)); 180 ranges(1, make_pair(0, -1));
169 ret->set_ranges(ranges); 181 ret->set_ranges(ranges);
170 // Speed up test execution. 182 // Speed up test execution.
171 ret->set_idle_seconds(1); 183 ret->set_idle_seconds(1);
172 ret->set_retry_seconds(1); 184 ret->set_retry_seconds(1);
173 ret->SetConnectionAsExpensive(false); 185 ret->SetConnectionAsExpensive(false);
174 ret->SetBuildType(false); 186 ret->SetBuildType(false);
175 return ret; 187 return ret;
176 } 188 }
177 bool IsMulti() const { return true; } 189 bool IsMulti() const { return true; }
190 DirectProxyResolver proxy_resolver_;
178 }; 191 };
179 192
180 typedef ::testing::Types<LibcurlHttpFetcher, 193 typedef ::testing::Types<LibcurlHttpFetcher,
181 MockHttpFetcher, 194 MockHttpFetcher,
182 MultiHttpFetcher<LibcurlHttpFetcher> > 195 MultiHttpFetcher<LibcurlHttpFetcher> >
183 HttpFetcherTestTypes; 196 HttpFetcherTestTypes;
184 TYPED_TEST_CASE(HttpFetcherTest, HttpFetcherTestTypes); 197 TYPED_TEST_CASE(HttpFetcherTest, HttpFetcherTestTypes);
185 198
186 namespace { 199 namespace {
187 class HttpFetcherTestDelegate : public HttpFetcherDelegate { 200 class HttpFetcherTestDelegate : public HttpFetcherDelegate {
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 StartTransferArgs start_xfer_args = 795 StartTransferArgs start_xfer_args =
783 { fetcher.get(), LocalServerUrlForPath(this->SmallUrl()) }; 796 { fetcher.get(), LocalServerUrlForPath(this->SmallUrl()) };
784 797
785 g_timeout_add(0, StartTransfer, &start_xfer_args); 798 g_timeout_add(0, StartTransfer, &start_xfer_args);
786 g_main_loop_run(loop); 799 g_main_loop_run(loop);
787 g_main_loop_unref(loop); 800 g_main_loop_unref(loop);
788 } 801 }
789 } 802 }
790 803
791 } // namespace chromeos_update_engine 804 } // namespace chromeos_update_engine
OLDNEW
« http_fetcher.h ('K') | « http_fetcher.h ('k') | libcurl_http_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698