| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "net/proxy/proxy_resolver_v8_tracing.h" | 5 #include "net/proxy/proxy_resolver_v8_tracing.h" |
| 6 | 6 |
| 7 #include <string> |
| 8 |
| 7 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 8 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 9 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 10 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 11 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 12 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
| 15 #include "base/threading/platform_thread.h" | 17 #include "base/threading/platform_thread.h" |
| 16 #include "base/values.h" | 18 #include "base/values.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 std::string file_contents; | 55 std::string file_contents; |
| 54 bool ok = base::ReadFileToString(path, &file_contents); | 56 bool ok = base::ReadFileToString(path, &file_contents); |
| 55 | 57 |
| 56 // If we can't load the file from disk, something is misconfigured. | 58 // If we can't load the file from disk, something is misconfigured. |
| 57 EXPECT_TRUE(ok) << "Failed to read file: " << path.value(); | 59 EXPECT_TRUE(ok) << "Failed to read file: " << path.value(); |
| 58 | 60 |
| 59 // Load the PAC script into the ProxyResolver. | 61 // Load the PAC script into the ProxyResolver. |
| 60 return ProxyResolverScriptData::FromUTF8(file_contents); | 62 return ProxyResolverScriptData::FromUTF8(file_contents); |
| 61 } | 63 } |
| 62 | 64 |
| 63 void InitResolver(ProxyResolverV8Tracing* resolver, const char* filename) { | 65 scoped_ptr<ProxyResolverErrorObserver> ReturnErrorObserver( |
| 66 scoped_ptr<ProxyResolverErrorObserver> error_observer) { |
| 67 return error_observer; |
| 68 } |
| 69 |
| 70 scoped_ptr<ProxyResolver> CreateResolver( |
| 71 NetLog* net_log, |
| 72 HostResolver* host_resolver, |
| 73 scoped_ptr<ProxyResolverErrorObserver> error_observer, |
| 74 const char* filename) { |
| 75 scoped_ptr<ProxyResolver> resolver; |
| 76 ProxyResolverFactoryV8Tracing factory( |
| 77 host_resolver, net_log, ProxyResolver::LoadStateChangedCallback(), |
| 78 base::Bind(&ReturnErrorObserver, base::Passed(&error_observer))); |
| 64 TestCompletionCallback callback; | 79 TestCompletionCallback callback; |
| 65 int rv = | 80 scoped_ptr<ProxyResolverFactory::Request> request; |
| 66 resolver->SetPacScript(LoadScriptData(filename), callback.callback()); | 81 int rv = factory.CreateProxyResolver(LoadScriptData(filename), &resolver, |
| 82 callback.callback(), &request); |
| 67 EXPECT_EQ(ERR_IO_PENDING, rv); | 83 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 68 EXPECT_EQ(OK, callback.WaitForResult()); | 84 EXPECT_EQ(OK, callback.WaitForResult()); |
| 85 EXPECT_TRUE(resolver); |
| 86 return resolver.Pass(); |
| 69 } | 87 } |
| 70 | 88 |
| 71 class MockErrorObserver : public ProxyResolverErrorObserver { | 89 class MockErrorObserver : public ProxyResolverErrorObserver { |
| 72 public: | 90 public: |
| 73 MockErrorObserver() : event_(true, false) {} | 91 MockErrorObserver() : event_(true, false) {} |
| 74 | 92 |
| 75 void OnPACScriptError(int line_number, const base::string16& error) override { | 93 void OnPACScriptError(int line_number, const base::string16& error) override { |
| 76 { | 94 { |
| 77 base::AutoLock l(lock_); | 95 base::AutoLock l(lock_); |
| 78 output += base::StringPrintf("Error: line %d: %s\n", line_number, | 96 output += base::StringPrintf("Error: line %d: %s\n", line_number, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 95 std::string output; | 113 std::string output; |
| 96 | 114 |
| 97 base::WaitableEvent event_; | 115 base::WaitableEvent event_; |
| 98 }; | 116 }; |
| 99 | 117 |
| 100 TEST_F(ProxyResolverV8TracingTest, Simple) { | 118 TEST_F(ProxyResolverV8TracingTest, Simple) { |
| 101 TestNetLog log; | 119 TestNetLog log; |
| 102 BoundTestNetLog request_log; | 120 BoundTestNetLog request_log; |
| 103 MockCachingHostResolver host_resolver; | 121 MockCachingHostResolver host_resolver; |
| 104 MockErrorObserver* error_observer = new MockErrorObserver; | 122 MockErrorObserver* error_observer = new MockErrorObserver; |
| 105 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | |
| 106 | 123 |
| 107 InitResolver(&resolver, "simple.js"); | 124 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
| 125 &log, &host_resolver, make_scoped_ptr(error_observer), "simple.js"); |
| 108 | 126 |
| 109 TestCompletionCallback callback; | 127 TestCompletionCallback callback; |
| 110 ProxyInfo proxy_info; | 128 ProxyInfo proxy_info; |
| 111 | 129 |
| 112 int rv = resolver.GetProxyForURL( | 130 int rv = |
| 113 GURL("http://foo/"), &proxy_info, callback.callback(), | 131 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
| 114 NULL, request_log.bound()); | 132 callback.callback(), NULL, request_log.bound()); |
| 115 | 133 |
| 116 EXPECT_EQ(ERR_IO_PENDING, rv); | 134 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 117 EXPECT_EQ(OK, callback.WaitForResult()); | 135 EXPECT_EQ(OK, callback.WaitForResult()); |
| 118 | 136 |
| 119 EXPECT_EQ("foo:99", proxy_info.proxy_server().ToURI()); | 137 EXPECT_EQ("foo:99", proxy_info.proxy_server().ToURI()); |
| 120 | 138 |
| 121 EXPECT_EQ(0u, host_resolver.num_resolve()); | 139 EXPECT_EQ(0u, host_resolver.num_resolve()); |
| 122 | 140 |
| 123 // There were no errors. | 141 // There were no errors. |
| 124 EXPECT_EQ("", error_observer->GetOutput()); | 142 EXPECT_EQ("", error_observer->GetOutput()); |
| 125 | 143 |
| 126 // Check the NetLogs -- nothing was logged. | 144 // Check the NetLogs -- nothing was logged. |
| 127 EXPECT_EQ(0u, log.GetSize()); | 145 EXPECT_EQ(0u, log.GetSize()); |
| 128 EXPECT_EQ(0u, request_log.GetSize()); | 146 EXPECT_EQ(0u, request_log.GetSize()); |
| 129 } | 147 } |
| 130 | 148 |
| 131 TEST_F(ProxyResolverV8TracingTest, JavascriptError) { | 149 TEST_F(ProxyResolverV8TracingTest, JavascriptError) { |
| 132 TestNetLog log; | 150 TestNetLog log; |
| 133 BoundTestNetLog request_log; | 151 BoundTestNetLog request_log; |
| 134 MockCachingHostResolver host_resolver; | 152 MockCachingHostResolver host_resolver; |
| 135 MockErrorObserver* error_observer = new MockErrorObserver; | 153 MockErrorObserver* error_observer = new MockErrorObserver; |
| 136 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | |
| 137 | 154 |
| 138 InitResolver(&resolver, "error.js"); | 155 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
| 156 &log, &host_resolver, make_scoped_ptr(error_observer), "error.js"); |
| 139 | 157 |
| 140 TestCompletionCallback callback; | 158 TestCompletionCallback callback; |
| 141 ProxyInfo proxy_info; | 159 ProxyInfo proxy_info; |
| 142 | 160 |
| 143 int rv = resolver.GetProxyForURL( | 161 int rv = |
| 144 GURL("http://throw-an-error/"), &proxy_info, callback.callback(), NULL, | 162 resolver->GetProxyForURL(GURL("http://throw-an-error/"), &proxy_info, |
| 145 request_log.bound()); | 163 callback.callback(), NULL, request_log.bound()); |
| 146 | 164 |
| 147 EXPECT_EQ(ERR_IO_PENDING, rv); | 165 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 148 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult()); | 166 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult()); |
| 149 | 167 |
| 150 EXPECT_EQ(0u, host_resolver.num_resolve()); | 168 EXPECT_EQ(0u, host_resolver.num_resolve()); |
| 151 | 169 |
| 152 EXPECT_EQ("Error: line 5: Uncaught TypeError: Cannot read property 'split' " | 170 EXPECT_EQ("Error: line 5: Uncaught TypeError: Cannot read property 'split' " |
| 153 "of null\n", error_observer->GetOutput()); | 171 "of null\n", error_observer->GetOutput()); |
| 154 | 172 |
| 155 // Check the NetLogs -- there was 1 alert and 1 javascript error, and they | 173 // Check the NetLogs -- there was 1 alert and 1 javascript error, and they |
| (...skipping 16 matching lines...) Expand all Loading... |
| 172 EXPECT_EQ("{\"line_number\":5,\"message\":\"Uncaught TypeError: Cannot " | 190 EXPECT_EQ("{\"line_number\":5,\"message\":\"Uncaught TypeError: Cannot " |
| 173 "read property 'split' of null\"}", entries[1].GetParamsJson()); | 191 "read property 'split' of null\"}", entries[1].GetParamsJson()); |
| 174 } | 192 } |
| 175 } | 193 } |
| 176 | 194 |
| 177 TEST_F(ProxyResolverV8TracingTest, TooManyAlerts) { | 195 TEST_F(ProxyResolverV8TracingTest, TooManyAlerts) { |
| 178 TestNetLog log; | 196 TestNetLog log; |
| 179 BoundTestNetLog request_log; | 197 BoundTestNetLog request_log; |
| 180 MockCachingHostResolver host_resolver; | 198 MockCachingHostResolver host_resolver; |
| 181 MockErrorObserver* error_observer = new MockErrorObserver; | 199 MockErrorObserver* error_observer = new MockErrorObserver; |
| 182 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | |
| 183 | 200 |
| 184 InitResolver(&resolver, "too_many_alerts.js"); | 201 scoped_ptr<ProxyResolver> resolver = |
| 202 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), |
| 203 "too_many_alerts.js"); |
| 185 | 204 |
| 186 TestCompletionCallback callback; | 205 TestCompletionCallback callback; |
| 187 ProxyInfo proxy_info; | 206 ProxyInfo proxy_info; |
| 188 | 207 |
| 189 int rv = resolver.GetProxyForURL( | 208 int rv = |
| 190 GURL("http://foo/"), | 209 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
| 191 &proxy_info, | 210 callback.callback(), NULL, request_log.bound()); |
| 192 callback.callback(), | |
| 193 NULL, | |
| 194 request_log.bound()); | |
| 195 | 211 |
| 196 EXPECT_EQ(ERR_IO_PENDING, rv); | 212 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 197 EXPECT_EQ(OK, callback.WaitForResult()); | 213 EXPECT_EQ(OK, callback.WaitForResult()); |
| 198 | 214 |
| 199 // Iteration1 does a DNS resolve | 215 // Iteration1 does a DNS resolve |
| 200 // Iteration2 exceeds the alert buffer | 216 // Iteration2 exceeds the alert buffer |
| 201 // Iteration3 runs in blocking mode and completes | 217 // Iteration3 runs in blocking mode and completes |
| 202 EXPECT_EQ("foo:3", proxy_info.proxy_server().ToURI()); | 218 EXPECT_EQ("foo:3", proxy_info.proxy_server().ToURI()); |
| 203 | 219 |
| 204 EXPECT_EQ(1u, host_resolver.num_resolve()); | 220 EXPECT_EQ(1u, host_resolver.num_resolve()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 223 } | 239 } |
| 224 } | 240 } |
| 225 | 241 |
| 226 // Verify that buffered alerts cannot grow unboundedly, even when the message is | 242 // Verify that buffered alerts cannot grow unboundedly, even when the message is |
| 227 // empty string. | 243 // empty string. |
| 228 TEST_F(ProxyResolverV8TracingTest, TooManyEmptyAlerts) { | 244 TEST_F(ProxyResolverV8TracingTest, TooManyEmptyAlerts) { |
| 229 TestNetLog log; | 245 TestNetLog log; |
| 230 BoundTestNetLog request_log; | 246 BoundTestNetLog request_log; |
| 231 MockCachingHostResolver host_resolver; | 247 MockCachingHostResolver host_resolver; |
| 232 MockErrorObserver* error_observer = new MockErrorObserver; | 248 MockErrorObserver* error_observer = new MockErrorObserver; |
| 233 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | |
| 234 | 249 |
| 235 InitResolver(&resolver, "too_many_empty_alerts.js"); | 250 scoped_ptr<ProxyResolver> resolver = |
| 251 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), |
| 252 "too_many_empty_alerts.js"); |
| 236 | 253 |
| 237 TestCompletionCallback callback; | 254 TestCompletionCallback callback; |
| 238 ProxyInfo proxy_info; | 255 ProxyInfo proxy_info; |
| 239 | 256 |
| 240 int rv = resolver.GetProxyForURL( | 257 int rv = |
| 241 GURL("http://foo/"), | 258 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
| 242 &proxy_info, | 259 callback.callback(), NULL, request_log.bound()); |
| 243 callback.callback(), | |
| 244 NULL, | |
| 245 request_log.bound()); | |
| 246 | 260 |
| 247 EXPECT_EQ(ERR_IO_PENDING, rv); | 261 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 248 EXPECT_EQ(OK, callback.WaitForResult()); | 262 EXPECT_EQ(OK, callback.WaitForResult()); |
| 249 | 263 |
| 250 EXPECT_EQ("foo:3", proxy_info.proxy_server().ToURI()); | 264 EXPECT_EQ("foo:3", proxy_info.proxy_server().ToURI()); |
| 251 | 265 |
| 252 EXPECT_EQ(1u, host_resolver.num_resolve()); | 266 EXPECT_EQ(1u, host_resolver.num_resolve()); |
| 253 | 267 |
| 254 // No errors. | 268 // No errors. |
| 255 EXPECT_EQ("", error_observer->GetOutput()); | 269 EXPECT_EQ("", error_observer->GetOutput()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 272 } | 286 } |
| 273 | 287 |
| 274 // This test runs a PAC script that issues a sequence of DNS resolves. The test | 288 // This test runs a PAC script that issues a sequence of DNS resolves. The test |
| 275 // verifies the final result, and that the underlying DNS resolver received | 289 // verifies the final result, and that the underlying DNS resolver received |
| 276 // the correct set of queries. | 290 // the correct set of queries. |
| 277 TEST_F(ProxyResolverV8TracingTest, Dns) { | 291 TEST_F(ProxyResolverV8TracingTest, Dns) { |
| 278 TestNetLog log; | 292 TestNetLog log; |
| 279 BoundTestNetLog request_log; | 293 BoundTestNetLog request_log; |
| 280 MockCachingHostResolver host_resolver; | 294 MockCachingHostResolver host_resolver; |
| 281 MockErrorObserver* error_observer = new MockErrorObserver; | 295 MockErrorObserver* error_observer = new MockErrorObserver; |
| 282 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | |
| 283 | 296 |
| 284 host_resolver.rules()->AddRuleForAddressFamily( | 297 host_resolver.rules()->AddRuleForAddressFamily( |
| 285 "host1", ADDRESS_FAMILY_IPV4, "166.155.144.44"); | 298 "host1", ADDRESS_FAMILY_IPV4, "166.155.144.44"); |
| 286 host_resolver.rules() | 299 host_resolver.rules() |
| 287 ->AddIPLiteralRule("host1", "::1,192.168.1.1", std::string()); | 300 ->AddIPLiteralRule("host1", "::1,192.168.1.1", std::string()); |
| 288 host_resolver.rules()->AddSimulatedFailure("host2"); | 301 host_resolver.rules()->AddSimulatedFailure("host2"); |
| 289 host_resolver.rules()->AddRule("host3", "166.155.144.33"); | 302 host_resolver.rules()->AddRule("host3", "166.155.144.33"); |
| 290 host_resolver.rules()->AddRule("host5", "166.155.144.55"); | 303 host_resolver.rules()->AddRule("host5", "166.155.144.55"); |
| 291 host_resolver.rules()->AddSimulatedFailure("host6"); | 304 host_resolver.rules()->AddSimulatedFailure("host6"); |
| 292 host_resolver.rules()->AddRuleForAddressFamily( | 305 host_resolver.rules()->AddRuleForAddressFamily( |
| 293 "*", ADDRESS_FAMILY_IPV4, "122.133.144.155"); | 306 "*", ADDRESS_FAMILY_IPV4, "122.133.144.155"); |
| 294 host_resolver.rules()->AddRule("*", "133.122.100.200"); | 307 host_resolver.rules()->AddRule("*", "133.122.100.200"); |
| 295 | 308 |
| 296 InitResolver(&resolver, "dns.js"); | 309 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
| 310 &log, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); |
| 297 | 311 |
| 298 TestCompletionCallback callback; | 312 TestCompletionCallback callback; |
| 299 ProxyInfo proxy_info; | 313 ProxyInfo proxy_info; |
| 300 | 314 |
| 301 int rv = resolver.GetProxyForURL( | 315 int rv = |
| 302 GURL("http://foo/"), | 316 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
| 303 &proxy_info, | 317 callback.callback(), NULL, request_log.bound()); |
| 304 callback.callback(), | |
| 305 NULL, | |
| 306 request_log.bound()); | |
| 307 | 318 |
| 308 EXPECT_EQ(ERR_IO_PENDING, rv); | 319 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 309 EXPECT_EQ(OK, callback.WaitForResult()); | 320 EXPECT_EQ(OK, callback.WaitForResult()); |
| 310 | 321 |
| 311 // The test does 13 DNS resolution, however only 7 of them are unique. | 322 // The test does 13 DNS resolution, however only 7 of them are unique. |
| 312 EXPECT_EQ(7u, host_resolver.num_resolve()); | 323 EXPECT_EQ(7u, host_resolver.num_resolve()); |
| 313 | 324 |
| 314 const char* kExpectedResult = | 325 const char* kExpectedResult = |
| 315 "122.133.144.155-" // myIpAddress() | 326 "122.133.144.155-" // myIpAddress() |
| 316 "null-" // dnsResolve('') | 327 "null-" // dnsResolve('') |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 } | 360 } |
| 350 | 361 |
| 351 // This test runs a PAC script that does "myIpAddress()" followed by | 362 // This test runs a PAC script that does "myIpAddress()" followed by |
| 352 // "dnsResolve()". This requires 2 restarts. However once the HostResolver's | 363 // "dnsResolve()". This requires 2 restarts. However once the HostResolver's |
| 353 // cache is warmed, subsequent calls should take 0 restarts. | 364 // cache is warmed, subsequent calls should take 0 restarts. |
| 354 TEST_F(ProxyResolverV8TracingTest, DnsChecksCache) { | 365 TEST_F(ProxyResolverV8TracingTest, DnsChecksCache) { |
| 355 TestNetLog log; | 366 TestNetLog log; |
| 356 BoundTestNetLog request_log; | 367 BoundTestNetLog request_log; |
| 357 MockCachingHostResolver host_resolver; | 368 MockCachingHostResolver host_resolver; |
| 358 MockErrorObserver* error_observer = new MockErrorObserver; | 369 MockErrorObserver* error_observer = new MockErrorObserver; |
| 359 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | |
| 360 | 370 |
| 361 host_resolver.rules()->AddRule("foopy", "166.155.144.11"); | 371 host_resolver.rules()->AddRule("foopy", "166.155.144.11"); |
| 362 host_resolver.rules()->AddRule("*", "122.133.144.155"); | 372 host_resolver.rules()->AddRule("*", "122.133.144.155"); |
| 363 | 373 |
| 364 InitResolver(&resolver, "simple_dns.js"); | 374 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
| 375 &log, &host_resolver, make_scoped_ptr(error_observer), "simple_dns.js"); |
| 365 | 376 |
| 366 TestCompletionCallback callback1; | 377 TestCompletionCallback callback1; |
| 367 TestCompletionCallback callback2; | 378 TestCompletionCallback callback2; |
| 368 ProxyInfo proxy_info; | 379 ProxyInfo proxy_info; |
| 369 | 380 |
| 370 int rv = resolver.GetProxyForURL( | 381 int rv = |
| 371 GURL("http://foopy/req1"), | 382 resolver->GetProxyForURL(GURL("http://foopy/req1"), &proxy_info, |
| 372 &proxy_info, | 383 callback1.callback(), NULL, request_log.bound()); |
| 373 callback1.callback(), | |
| 374 NULL, | |
| 375 request_log.bound()); | |
| 376 | 384 |
| 377 EXPECT_EQ(ERR_IO_PENDING, rv); | 385 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 378 EXPECT_EQ(OK, callback1.WaitForResult()); | 386 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 379 | 387 |
| 380 // The test does 2 DNS resolutions. | 388 // The test does 2 DNS resolutions. |
| 381 EXPECT_EQ(2u, host_resolver.num_resolve()); | 389 EXPECT_EQ(2u, host_resolver.num_resolve()); |
| 382 | 390 |
| 383 // The first request took 2 restarts, hence on g_iteration=3. | 391 // The first request took 2 restarts, hence on g_iteration=3. |
| 384 EXPECT_EQ("166.155.144.11:3", proxy_info.proxy_server().ToURI()); | 392 EXPECT_EQ("166.155.144.11:3", proxy_info.proxy_server().ToURI()); |
| 385 | 393 |
| 386 rv = resolver.GetProxyForURL( | 394 rv = |
| 387 GURL("http://foopy/req2"), | 395 resolver->GetProxyForURL(GURL("http://foopy/req2"), &proxy_info, |
| 388 &proxy_info, | 396 callback2.callback(), NULL, request_log.bound()); |
| 389 callback2.callback(), | |
| 390 NULL, | |
| 391 request_log.bound()); | |
| 392 | 397 |
| 393 EXPECT_EQ(ERR_IO_PENDING, rv); | 398 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 394 EXPECT_EQ(OK, callback2.WaitForResult()); | 399 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 395 | 400 |
| 396 EXPECT_EQ(4u, host_resolver.num_resolve()); | 401 EXPECT_EQ(4u, host_resolver.num_resolve()); |
| 397 | 402 |
| 398 // This time no restarts were required, so g_iteration incremented by 1. | 403 // This time no restarts were required, so g_iteration incremented by 1. |
| 399 EXPECT_EQ("166.155.144.11:4", proxy_info.proxy_server().ToURI()); | 404 EXPECT_EQ("166.155.144.11:4", proxy_info.proxy_server().ToURI()); |
| 400 | 405 |
| 401 // No errors. | 406 // No errors. |
| 402 EXPECT_EQ("", error_observer->GetOutput()); | 407 EXPECT_EQ("", error_observer->GetOutput()); |
| 403 | 408 |
| 404 EXPECT_EQ(0u, log.GetSize()); | 409 EXPECT_EQ(0u, log.GetSize()); |
| 405 EXPECT_EQ(0u, request_log.GetSize()); | 410 EXPECT_EQ(0u, request_log.GetSize()); |
| 406 } | 411 } |
| 407 | 412 |
| 408 // This test runs a weird PAC script that was designed to defeat the DNS tracing | 413 // This test runs a weird PAC script that was designed to defeat the DNS tracing |
| 409 // optimization. The proxy resolver should detect the inconsistency and | 414 // optimization. The proxy resolver should detect the inconsistency and |
| 410 // fall-back to synchronous mode execution. | 415 // fall-back to synchronous mode execution. |
| 411 TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous1) { | 416 TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous1) { |
| 412 TestNetLog log; | 417 TestNetLog log; |
| 413 BoundTestNetLog request_log; | 418 BoundTestNetLog request_log; |
| 414 MockCachingHostResolver host_resolver; | 419 MockCachingHostResolver host_resolver; |
| 415 MockErrorObserver* error_observer = new MockErrorObserver; | 420 MockErrorObserver* error_observer = new MockErrorObserver; |
| 416 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | |
| 417 | 421 |
| 418 host_resolver.rules()->AddRule("host1", "166.155.144.11"); | 422 host_resolver.rules()->AddRule("host1", "166.155.144.11"); |
| 419 host_resolver.rules()->AddRule("crazy4", "133.199.111.4"); | 423 host_resolver.rules()->AddRule("crazy4", "133.199.111.4"); |
| 420 host_resolver.rules()->AddRule("*", "122.133.144.155"); | 424 host_resolver.rules()->AddRule("*", "122.133.144.155"); |
| 421 | 425 |
| 422 InitResolver(&resolver, "global_sideffects1.js"); | 426 scoped_ptr<ProxyResolver> resolver = |
| 427 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), |
| 428 "global_sideffects1.js"); |
| 423 | 429 |
| 424 TestCompletionCallback callback; | 430 TestCompletionCallback callback; |
| 425 ProxyInfo proxy_info; | 431 ProxyInfo proxy_info; |
| 426 | 432 |
| 427 int rv = resolver.GetProxyForURL( | 433 int rv = |
| 428 GURL("http://foo/"), &proxy_info, callback.callback(), NULL, | 434 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
| 429 request_log.bound()); | 435 callback.callback(), NULL, request_log.bound()); |
| 430 EXPECT_EQ(ERR_IO_PENDING, rv); | 436 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 431 EXPECT_EQ(OK, callback.WaitForResult()); | 437 EXPECT_EQ(OK, callback.WaitForResult()); |
| 432 | 438 |
| 433 // The script itself only does 2 DNS resolves per execution, however it | 439 // The script itself only does 2 DNS resolves per execution, however it |
| 434 // constructs the hostname using a global counter which changes on each | 440 // constructs the hostname using a global counter which changes on each |
| 435 // invocation. | 441 // invocation. |
| 436 EXPECT_EQ(3u, host_resolver.num_resolve()); | 442 EXPECT_EQ(3u, host_resolver.num_resolve()); |
| 437 | 443 |
| 438 EXPECT_EQ("166.155.144.11-133.199.111.4:100", | 444 EXPECT_EQ("166.155.144.11-133.199.111.4:100", |
| 439 proxy_info.proxy_server().ToURI()); | 445 proxy_info.proxy_server().ToURI()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 458 } | 464 } |
| 459 | 465 |
| 460 // This test runs a weird PAC script that was designed to defeat the DNS tracing | 466 // This test runs a weird PAC script that was designed to defeat the DNS tracing |
| 461 // optimization. The proxy resolver should detect the inconsistency and | 467 // optimization. The proxy resolver should detect the inconsistency and |
| 462 // fall-back to synchronous mode execution. | 468 // fall-back to synchronous mode execution. |
| 463 TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous2) { | 469 TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous2) { |
| 464 TestNetLog log; | 470 TestNetLog log; |
| 465 BoundTestNetLog request_log; | 471 BoundTestNetLog request_log; |
| 466 MockCachingHostResolver host_resolver; | 472 MockCachingHostResolver host_resolver; |
| 467 MockErrorObserver* error_observer = new MockErrorObserver; | 473 MockErrorObserver* error_observer = new MockErrorObserver; |
| 468 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | |
| 469 | 474 |
| 470 host_resolver.rules()->AddRule("host1", "166.155.144.11"); | 475 host_resolver.rules()->AddRule("host1", "166.155.144.11"); |
| 471 host_resolver.rules()->AddRule("host2", "166.155.144.22"); | 476 host_resolver.rules()->AddRule("host2", "166.155.144.22"); |
| 472 host_resolver.rules()->AddRule("host3", "166.155.144.33"); | 477 host_resolver.rules()->AddRule("host3", "166.155.144.33"); |
| 473 host_resolver.rules()->AddRule("host4", "166.155.144.44"); | 478 host_resolver.rules()->AddRule("host4", "166.155.144.44"); |
| 474 host_resolver.rules()->AddRule("*", "122.133.144.155"); | 479 host_resolver.rules()->AddRule("*", "122.133.144.155"); |
| 475 | 480 |
| 476 InitResolver(&resolver, "global_sideffects2.js"); | 481 scoped_ptr<ProxyResolver> resolver = |
| 482 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), |
| 483 "global_sideffects2.js"); |
| 477 | 484 |
| 478 TestCompletionCallback callback; | 485 TestCompletionCallback callback; |
| 479 ProxyInfo proxy_info; | 486 ProxyInfo proxy_info; |
| 480 | 487 |
| 481 int rv = resolver.GetProxyForURL( | 488 int rv = |
| 482 GURL("http://foo/"), &proxy_info, callback.callback(), NULL, | 489 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
| 483 request_log.bound()); | 490 callback.callback(), NULL, request_log.bound()); |
| 484 EXPECT_EQ(ERR_IO_PENDING, rv); | 491 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 485 EXPECT_EQ(OK, callback.WaitForResult()); | 492 EXPECT_EQ(OK, callback.WaitForResult()); |
| 486 | 493 |
| 487 EXPECT_EQ(3u, host_resolver.num_resolve()); | 494 EXPECT_EQ(3u, host_resolver.num_resolve()); |
| 488 | 495 |
| 489 EXPECT_EQ("166.155.144.44:100", proxy_info.proxy_server().ToURI()); | 496 EXPECT_EQ("166.155.144.44:100", proxy_info.proxy_server().ToURI()); |
| 490 | 497 |
| 491 // No errors. | 498 // No errors. |
| 492 EXPECT_EQ("", error_observer->GetOutput()); | 499 EXPECT_EQ("", error_observer->GetOutput()); |
| 493 | 500 |
| 494 // Check the NetLogs -- nothing was logged. | 501 // Check the NetLogs -- nothing was logged. |
| 495 EXPECT_EQ(0u, log.GetSize()); | 502 EXPECT_EQ(0u, log.GetSize()); |
| 496 EXPECT_EQ(0u, request_log.GetSize()); | 503 EXPECT_EQ(0u, request_log.GetSize()); |
| 497 } | 504 } |
| 498 | 505 |
| 499 // This test runs a weird PAC script that yields a never ending sequence | 506 // This test runs a weird PAC script that yields a never ending sequence |
| 500 // of DNS resolves when restarting. Running it will hit the maximum | 507 // of DNS resolves when restarting. Running it will hit the maximum |
| 501 // DNS resolves per request limit (20) after which every DNS resolve will | 508 // DNS resolves per request limit (20) after which every DNS resolve will |
| 502 // fail. | 509 // fail. |
| 503 TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence) { | 510 TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence) { |
| 504 TestNetLog log; | 511 TestNetLog log; |
| 505 BoundTestNetLog request_log; | 512 BoundTestNetLog request_log; |
| 506 MockCachingHostResolver host_resolver; | 513 MockCachingHostResolver host_resolver; |
| 507 MockErrorObserver* error_observer = new MockErrorObserver; | 514 MockErrorObserver* error_observer = new MockErrorObserver; |
| 508 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | |
| 509 | 515 |
| 510 host_resolver.rules()->AddRule("host*", "166.155.144.11"); | 516 host_resolver.rules()->AddRule("host*", "166.155.144.11"); |
| 511 host_resolver.rules()->AddRule("*", "122.133.144.155"); | 517 host_resolver.rules()->AddRule("*", "122.133.144.155"); |
| 512 | 518 |
| 513 InitResolver(&resolver, "global_sideffects3.js"); | 519 scoped_ptr<ProxyResolver> resolver = |
| 520 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), |
| 521 "global_sideffects3.js"); |
| 514 | 522 |
| 515 TestCompletionCallback callback; | 523 TestCompletionCallback callback; |
| 516 ProxyInfo proxy_info; | 524 ProxyInfo proxy_info; |
| 517 | 525 |
| 518 int rv = resolver.GetProxyForURL( | 526 int rv = |
| 519 GURL("http://foo/"), &proxy_info, callback.callback(), NULL, | 527 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
| 520 request_log.bound()); | 528 callback.callback(), NULL, request_log.bound()); |
| 521 EXPECT_EQ(ERR_IO_PENDING, rv); | 529 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 522 EXPECT_EQ(OK, callback.WaitForResult()); | 530 EXPECT_EQ(OK, callback.WaitForResult()); |
| 523 | 531 |
| 524 EXPECT_EQ(20u, host_resolver.num_resolve()); | 532 EXPECT_EQ(20u, host_resolver.num_resolve()); |
| 525 | 533 |
| 526 EXPECT_EQ( | 534 EXPECT_EQ( |
| 527 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" | 535 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" |
| 528 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" | 536 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" |
| 529 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" | 537 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" |
| 530 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" | 538 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 541 | 549 |
| 542 // This test runs a weird PAC script that yields a never ending sequence | 550 // This test runs a weird PAC script that yields a never ending sequence |
| 543 // of DNS resolves when restarting. Running it will hit the maximum | 551 // of DNS resolves when restarting. Running it will hit the maximum |
| 544 // DNS resolves per request limit (20) after which every DNS resolve will | 552 // DNS resolves per request limit (20) after which every DNS resolve will |
| 545 // fail. | 553 // fail. |
| 546 TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence2) { | 554 TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence2) { |
| 547 TestNetLog log; | 555 TestNetLog log; |
| 548 BoundTestNetLog request_log; | 556 BoundTestNetLog request_log; |
| 549 MockCachingHostResolver host_resolver; | 557 MockCachingHostResolver host_resolver; |
| 550 MockErrorObserver* error_observer = new MockErrorObserver; | 558 MockErrorObserver* error_observer = new MockErrorObserver; |
| 551 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | |
| 552 | 559 |
| 553 host_resolver.rules()->AddRule("host*", "166.155.144.11"); | 560 host_resolver.rules()->AddRule("host*", "166.155.144.11"); |
| 554 host_resolver.rules()->AddRule("*", "122.133.144.155"); | 561 host_resolver.rules()->AddRule("*", "122.133.144.155"); |
| 555 | 562 |
| 556 InitResolver(&resolver, "global_sideffects4.js"); | 563 scoped_ptr<ProxyResolver> resolver = |
| 564 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), |
| 565 "global_sideffects4.js"); |
| 557 | 566 |
| 558 TestCompletionCallback callback; | 567 TestCompletionCallback callback; |
| 559 ProxyInfo proxy_info; | 568 ProxyInfo proxy_info; |
| 560 | 569 |
| 561 int rv = resolver.GetProxyForURL( | 570 int rv = |
| 562 GURL("http://foo/"), &proxy_info, callback.callback(), NULL, | 571 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
| 563 request_log.bound()); | 572 callback.callback(), NULL, request_log.bound()); |
| 564 EXPECT_EQ(ERR_IO_PENDING, rv); | 573 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 565 EXPECT_EQ(OK, callback.WaitForResult()); | 574 EXPECT_EQ(OK, callback.WaitForResult()); |
| 566 | 575 |
| 567 EXPECT_EQ(20u, host_resolver.num_resolve()); | 576 EXPECT_EQ(20u, host_resolver.num_resolve()); |
| 568 | 577 |
| 569 EXPECT_EQ("null21:34", proxy_info.proxy_server().ToURI()); | 578 EXPECT_EQ("null21:34", proxy_info.proxy_server().ToURI()); |
| 570 | 579 |
| 571 // No errors. | 580 // No errors. |
| 572 EXPECT_EQ("", error_observer->GetOutput()); | 581 EXPECT_EQ("", error_observer->GetOutput()); |
| 573 | 582 |
| 574 // Check the NetLogs -- 1 alert was logged. | 583 // Check the NetLogs -- 1 alert was logged. |
| 575 EXPECT_EQ(1u, log.GetSize()); | 584 EXPECT_EQ(1u, log.GetSize()); |
| 576 EXPECT_EQ(1u, request_log.GetSize()); | 585 EXPECT_EQ(1u, request_log.GetSize()); |
| 577 } | 586 } |
| 578 | 587 |
| 579 void DnsDuringInitHelper(bool synchronous_host_resolver) { | 588 void DnsDuringInitHelper(bool synchronous_host_resolver) { |
| 580 TestNetLog log; | 589 TestNetLog log; |
| 581 BoundTestNetLog request_log; | 590 BoundTestNetLog request_log; |
| 582 MockCachingHostResolver host_resolver; | 591 MockCachingHostResolver host_resolver; |
| 583 host_resolver.set_synchronous_mode(synchronous_host_resolver); | 592 host_resolver.set_synchronous_mode(synchronous_host_resolver); |
| 584 MockErrorObserver* error_observer = new MockErrorObserver; | 593 MockErrorObserver* error_observer = new MockErrorObserver; |
| 585 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | |
| 586 | 594 |
| 587 host_resolver.rules()->AddRule("host1", "91.13.12.1"); | 595 host_resolver.rules()->AddRule("host1", "91.13.12.1"); |
| 588 host_resolver.rules()->AddRule("host2", "91.13.12.2"); | 596 host_resolver.rules()->AddRule("host2", "91.13.12.2"); |
| 589 | 597 |
| 590 InitResolver(&resolver, "dns_during_init.js"); | 598 scoped_ptr<ProxyResolver> resolver = |
| 599 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), |
| 600 "dns_during_init.js"); |
| 591 | 601 |
| 592 // Initialization did 2 dnsResolves. | 602 // Initialization did 2 dnsResolves. |
| 593 EXPECT_EQ(2u, host_resolver.num_resolve()); | 603 EXPECT_EQ(2u, host_resolver.num_resolve()); |
| 594 | 604 |
| 595 host_resolver.rules()->ClearRules(); | 605 host_resolver.rules()->ClearRules(); |
| 596 host_resolver.GetHostCache()->clear(); | 606 host_resolver.GetHostCache()->clear(); |
| 597 | 607 |
| 598 host_resolver.rules()->AddRule("host1", "145.88.13.3"); | 608 host_resolver.rules()->AddRule("host1", "145.88.13.3"); |
| 599 host_resolver.rules()->AddRule("host2", "137.89.8.45"); | 609 host_resolver.rules()->AddRule("host2", "137.89.8.45"); |
| 600 | 610 |
| 601 TestCompletionCallback callback; | 611 TestCompletionCallback callback; |
| 602 ProxyInfo proxy_info; | 612 ProxyInfo proxy_info; |
| 603 | 613 |
| 604 int rv = resolver.GetProxyForURL( | 614 int rv = |
| 605 GURL("http://foo/"), &proxy_info, callback.callback(), NULL, | 615 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
| 606 request_log.bound()); | 616 callback.callback(), NULL, request_log.bound()); |
| 607 EXPECT_EQ(ERR_IO_PENDING, rv); | 617 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 608 EXPECT_EQ(OK, callback.WaitForResult()); | 618 EXPECT_EQ(OK, callback.WaitForResult()); |
| 609 | 619 |
| 610 // Fetched host1 and host2 again, since the ones done during initialization | 620 // Fetched host1 and host2 again, since the ones done during initialization |
| 611 // should not have been cached. | 621 // should not have been cached. |
| 612 EXPECT_EQ(4u, host_resolver.num_resolve()); | 622 EXPECT_EQ(4u, host_resolver.num_resolve()); |
| 613 | 623 |
| 614 EXPECT_EQ("91.13.12.1-91.13.12.2-145.88.13.3-137.89.8.45:99", | 624 EXPECT_EQ("91.13.12.1-91.13.12.2-145.88.13.3-137.89.8.45:99", |
| 615 proxy_info.proxy_server().ToURI()); | 625 proxy_info.proxy_server().ToURI()); |
| 616 | 626 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 644 CHECK(false); | 654 CHECK(false); |
| 645 } | 655 } |
| 646 | 656 |
| 647 // Start some requests, cancel them all, and then destroy the resolver. | 657 // Start some requests, cancel them all, and then destroy the resolver. |
| 648 // Note the execution order for this test can vary. Since multiple | 658 // Note the execution order for this test can vary. Since multiple |
| 649 // threads are involved, the cancellation may be received a different | 659 // threads are involved, the cancellation may be received a different |
| 650 // times. | 660 // times. |
| 651 TEST_F(ProxyResolverV8TracingTest, CancelAll) { | 661 TEST_F(ProxyResolverV8TracingTest, CancelAll) { |
| 652 MockCachingHostResolver host_resolver; | 662 MockCachingHostResolver host_resolver; |
| 653 MockErrorObserver* error_observer = new MockErrorObserver; | 663 MockErrorObserver* error_observer = new MockErrorObserver; |
| 654 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL); | |
| 655 | 664 |
| 656 host_resolver.rules()->AddSimulatedFailure("*"); | 665 host_resolver.rules()->AddSimulatedFailure("*"); |
| 657 | 666 |
| 658 InitResolver(&resolver, "dns.js"); | 667 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
| 668 nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); |
| 659 | 669 |
| 660 const size_t kNumRequests = 5; | 670 const size_t kNumRequests = 5; |
| 661 ProxyInfo proxy_info[kNumRequests]; | 671 ProxyInfo proxy_info[kNumRequests]; |
| 662 ProxyResolver::RequestHandle request[kNumRequests]; | 672 ProxyResolver::RequestHandle request[kNumRequests]; |
| 663 | 673 |
| 664 for (size_t i = 0; i < kNumRequests; ++i) { | 674 for (size_t i = 0; i < kNumRequests; ++i) { |
| 665 int rv = resolver.GetProxyForURL( | 675 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info[i], |
| 666 GURL("http://foo/"), &proxy_info[i], | 676 base::Bind(&CrashCallback), &request[i], |
| 667 base::Bind(&CrashCallback), &request[i], BoundNetLog()); | 677 BoundNetLog()); |
| 668 EXPECT_EQ(ERR_IO_PENDING, rv); | 678 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 669 } | 679 } |
| 670 | 680 |
| 671 for (size_t i = 0; i < kNumRequests; ++i) { | 681 for (size_t i = 0; i < kNumRequests; ++i) { |
| 672 resolver.CancelRequest(request[i]); | 682 resolver->CancelRequest(request[i]); |
| 673 } | 683 } |
| 674 } | 684 } |
| 675 | 685 |
| 676 // Note the execution order for this test can vary. Since multiple | 686 // Note the execution order for this test can vary. Since multiple |
| 677 // threads are involved, the cancellation may be received a different | 687 // threads are involved, the cancellation may be received a different |
| 678 // times. | 688 // times. |
| 679 TEST_F(ProxyResolverV8TracingTest, CancelSome) { | 689 TEST_F(ProxyResolverV8TracingTest, CancelSome) { |
| 680 MockCachingHostResolver host_resolver; | 690 MockCachingHostResolver host_resolver; |
| 681 MockErrorObserver* error_observer = new MockErrorObserver; | 691 MockErrorObserver* error_observer = new MockErrorObserver; |
| 682 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL); | |
| 683 | 692 |
| 684 host_resolver.rules()->AddSimulatedFailure("*"); | 693 host_resolver.rules()->AddSimulatedFailure("*"); |
| 685 | 694 |
| 686 InitResolver(&resolver, "dns.js"); | 695 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
| 696 nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); |
| 687 | 697 |
| 688 ProxyInfo proxy_info1; | 698 ProxyInfo proxy_info1; |
| 689 ProxyInfo proxy_info2; | 699 ProxyInfo proxy_info2; |
| 690 ProxyResolver::RequestHandle request1; | 700 ProxyResolver::RequestHandle request1; |
| 691 ProxyResolver::RequestHandle request2; | 701 ProxyResolver::RequestHandle request2; |
| 692 TestCompletionCallback callback; | 702 TestCompletionCallback callback; |
| 693 | 703 |
| 694 int rv = resolver.GetProxyForURL( | 704 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info1, |
| 695 GURL("http://foo/"), &proxy_info1, | 705 base::Bind(&CrashCallback), &request1, |
| 696 base::Bind(&CrashCallback), &request1, BoundNetLog()); | 706 BoundNetLog()); |
| 697 EXPECT_EQ(ERR_IO_PENDING, rv); | 707 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 698 | 708 |
| 699 rv = resolver.GetProxyForURL( | 709 rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info2, |
| 700 GURL("http://foo/"), &proxy_info2, | 710 callback.callback(), &request2, BoundNetLog()); |
| 701 callback.callback(), &request2, BoundNetLog()); | |
| 702 EXPECT_EQ(ERR_IO_PENDING, rv); | 711 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 703 | 712 |
| 704 resolver.CancelRequest(request1); | 713 resolver->CancelRequest(request1); |
| 705 | 714 |
| 706 EXPECT_EQ(OK, callback.WaitForResult()); | 715 EXPECT_EQ(OK, callback.WaitForResult()); |
| 707 } | 716 } |
| 708 | 717 |
| 709 // Cancel a request after it has finished running on the worker thread, and has | 718 // Cancel a request after it has finished running on the worker thread, and has |
| 710 // posted a task the completion task back to origin thread. | 719 // posted a task the completion task back to origin thread. |
| 711 TEST_F(ProxyResolverV8TracingTest, CancelWhilePendingCompletionTask) { | 720 TEST_F(ProxyResolverV8TracingTest, CancelWhilePendingCompletionTask) { |
| 712 MockCachingHostResolver host_resolver; | 721 MockCachingHostResolver host_resolver; |
| 713 MockErrorObserver* error_observer = new MockErrorObserver; | 722 MockErrorObserver* error_observer = new MockErrorObserver; |
| 714 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL); | |
| 715 | 723 |
| 716 host_resolver.rules()->AddSimulatedFailure("*"); | 724 host_resolver.rules()->AddSimulatedFailure("*"); |
| 717 | 725 |
| 718 InitResolver(&resolver, "error.js"); | 726 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
| 727 nullptr, &host_resolver, make_scoped_ptr(error_observer), "error.js"); |
| 719 | 728 |
| 720 ProxyInfo proxy_info1; | 729 ProxyInfo proxy_info1; |
| 721 ProxyInfo proxy_info2; | 730 ProxyInfo proxy_info2; |
| 722 ProxyInfo proxy_info3; | 731 ProxyInfo proxy_info3; |
| 723 ProxyResolver::RequestHandle request1; | 732 ProxyResolver::RequestHandle request1; |
| 724 ProxyResolver::RequestHandle request2; | 733 ProxyResolver::RequestHandle request2; |
| 725 ProxyResolver::RequestHandle request3; | 734 ProxyResolver::RequestHandle request3; |
| 726 TestCompletionCallback callback; | 735 TestCompletionCallback callback; |
| 727 | 736 |
| 728 int rv = resolver.GetProxyForURL( | 737 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info1, |
| 729 GURL("http://foo/"), &proxy_info1, | 738 base::Bind(&CrashCallback), &request1, |
| 730 base::Bind(&CrashCallback), &request1, BoundNetLog()); | 739 BoundNetLog()); |
| 731 EXPECT_EQ(ERR_IO_PENDING, rv); | 740 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 732 | 741 |
| 733 rv = resolver.GetProxyForURL( | 742 rv = resolver->GetProxyForURL(GURL("http://throw-an-error/"), &proxy_info2, |
| 734 GURL("http://throw-an-error/"), &proxy_info2, | 743 callback.callback(), &request2, BoundNetLog()); |
| 735 callback.callback(), &request2, BoundNetLog()); | |
| 736 EXPECT_EQ(ERR_IO_PENDING, rv); | 744 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 737 | 745 |
| 738 // Wait until the first request has finished running on the worker thread. | 746 // Wait until the first request has finished running on the worker thread. |
| 739 // (The second request will output an error). | 747 // (The second request will output an error). |
| 740 error_observer->WaitForOutput(); | 748 error_observer->WaitForOutput(); |
| 741 | 749 |
| 742 // Cancel the first request, while it has a pending completion task on | 750 // Cancel the first request, while it has a pending completion task on |
| 743 // the origin thread. | 751 // the origin thread. |
| 744 resolver.CancelRequest(request1); | 752 resolver->CancelRequest(request1); |
| 745 | 753 |
| 746 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult()); | 754 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult()); |
| 747 | 755 |
| 748 // Start another request, to make sure it is able to complete. | 756 // Start another request, to make sure it is able to complete. |
| 749 rv = resolver.GetProxyForURL( | 757 rv = resolver->GetProxyForURL(GURL("http://i-have-no-idea-what-im-doing/"), |
| 750 GURL("http://i-have-no-idea-what-im-doing/"), &proxy_info3, | 758 &proxy_info3, callback.callback(), &request3, |
| 751 callback.callback(), &request3, BoundNetLog()); | 759 BoundNetLog()); |
| 752 EXPECT_EQ(ERR_IO_PENDING, rv); | 760 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 753 | 761 |
| 754 EXPECT_EQ(OK, callback.WaitForResult()); | 762 EXPECT_EQ(OK, callback.WaitForResult()); |
| 755 | 763 |
| 756 EXPECT_EQ("i-approve-this-message:42", | 764 EXPECT_EQ("i-approve-this-message:42", |
| 757 proxy_info3.proxy_server().ToURI()); | 765 proxy_info3.proxy_server().ToURI()); |
| 758 } | 766 } |
| 759 | 767 |
| 760 // This implementation of HostResolver allows blocking until a resolve request | 768 // This implementation of HostResolver allows blocking until a resolve request |
| 761 // has been received. The resolve requests it receives will never be completed. | 769 // has been received. The resolve requests it receives will never be completed. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 int num_cancelled_requests_; | 830 int num_cancelled_requests_; |
| 823 bool waiting_for_resolve_; | 831 bool waiting_for_resolve_; |
| 824 base::Callback<void(void)> action_; | 832 base::Callback<void(void)> action_; |
| 825 }; | 833 }; |
| 826 | 834 |
| 827 // This cancellation test exercises a more predictable cancellation codepath -- | 835 // This cancellation test exercises a more predictable cancellation codepath -- |
| 828 // when the request has an outstanding DNS request in flight. | 836 // when the request has an outstanding DNS request in flight. |
| 829 TEST_F(ProxyResolverV8TracingTest, CancelWhileOutstandingNonBlockingDns) { | 837 TEST_F(ProxyResolverV8TracingTest, CancelWhileOutstandingNonBlockingDns) { |
| 830 BlockableHostResolver host_resolver; | 838 BlockableHostResolver host_resolver; |
| 831 MockErrorObserver* error_observer = new MockErrorObserver; | 839 MockErrorObserver* error_observer = new MockErrorObserver; |
| 832 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL); | |
| 833 | 840 |
| 834 InitResolver(&resolver, "dns.js"); | 841 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
| 842 nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); |
| 835 | 843 |
| 836 ProxyInfo proxy_info1; | 844 ProxyInfo proxy_info1; |
| 837 ProxyInfo proxy_info2; | 845 ProxyInfo proxy_info2; |
| 838 ProxyResolver::RequestHandle request1; | 846 ProxyResolver::RequestHandle request1; |
| 839 ProxyResolver::RequestHandle request2; | 847 ProxyResolver::RequestHandle request2; |
| 840 | 848 |
| 841 int rv = resolver.GetProxyForURL( | 849 int rv = resolver->GetProxyForURL(GURL("http://foo/req1"), &proxy_info1, |
| 842 GURL("http://foo/req1"), &proxy_info1, | 850 base::Bind(&CrashCallback), &request1, |
| 843 base::Bind(&CrashCallback), &request1, BoundNetLog()); | 851 BoundNetLog()); |
| 844 | 852 |
| 845 EXPECT_EQ(ERR_IO_PENDING, rv); | 853 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 846 | 854 |
| 847 host_resolver.WaitUntilRequestIsReceived(); | 855 host_resolver.WaitUntilRequestIsReceived(); |
| 848 | 856 |
| 849 rv = resolver.GetProxyForURL( | 857 rv = resolver->GetProxyForURL(GURL("http://foo/req2"), &proxy_info2, |
| 850 GURL("http://foo/req2"), &proxy_info2, | 858 base::Bind(&CrashCallback), &request2, |
| 851 base::Bind(&CrashCallback), &request2, BoundNetLog()); | 859 BoundNetLog()); |
| 852 | 860 |
| 853 EXPECT_EQ(ERR_IO_PENDING, rv); | 861 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 854 | 862 |
| 855 host_resolver.WaitUntilRequestIsReceived(); | 863 host_resolver.WaitUntilRequestIsReceived(); |
| 856 | 864 |
| 857 resolver.CancelRequest(request1); | 865 resolver->CancelRequest(request1); |
| 858 resolver.CancelRequest(request2); | 866 resolver->CancelRequest(request2); |
| 859 | 867 |
| 860 EXPECT_EQ(2, host_resolver.num_cancelled_requests()); | 868 EXPECT_EQ(2, host_resolver.num_cancelled_requests()); |
| 861 | 869 |
| 862 // After leaving this scope, the ProxyResolver is destroyed. | 870 // After leaving this scope, the ProxyResolver is destroyed. |
| 863 // This should not cause any problems, as the outstanding work | 871 // This should not cause any problems, as the outstanding work |
| 864 // should have been cancelled. | 872 // should have been cancelled. |
| 865 } | 873 } |
| 866 | 874 |
| 867 void CancelRequestAndPause(ProxyResolverV8Tracing* resolver, | 875 void CancelRequestAndPause(ProxyResolver* resolver, |
| 868 ProxyResolver::RequestHandle request) { | 876 ProxyResolver::RequestHandle request) { |
| 869 resolver->CancelRequest(request); | 877 resolver->CancelRequest(request); |
| 870 | 878 |
| 871 // Sleep for a little bit. This makes it more likely for the worker | 879 // Sleep for a little bit. This makes it more likely for the worker |
| 872 // thread to have returned from its call, and serves as a regression | 880 // thread to have returned from its call, and serves as a regression |
| 873 // test for http://crbug.com/173373. | 881 // test for http://crbug.com/173373. |
| 874 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(30)); | 882 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(30)); |
| 875 } | 883 } |
| 876 | 884 |
| 877 // In non-blocking mode, the worker thread actually does block for | 885 // In non-blocking mode, the worker thread actually does block for |
| 878 // a short time to see if the result is in the DNS cache. Test | 886 // a short time to see if the result is in the DNS cache. Test |
| 879 // cancellation while the worker thread is waiting on this event. | 887 // cancellation while the worker thread is waiting on this event. |
| 880 TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns) { | 888 TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns) { |
| 881 BlockableHostResolver host_resolver; | 889 BlockableHostResolver host_resolver; |
| 882 MockErrorObserver* error_observer = new MockErrorObserver; | 890 MockErrorObserver* error_observer = new MockErrorObserver; |
| 883 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL); | |
| 884 | 891 |
| 885 InitResolver(&resolver, "dns.js"); | 892 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
| 893 nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); |
| 886 | 894 |
| 887 ProxyInfo proxy_info; | 895 ProxyInfo proxy_info; |
| 888 ProxyResolver::RequestHandle request; | 896 ProxyResolver::RequestHandle request; |
| 889 | 897 |
| 890 int rv = resolver.GetProxyForURL( | 898 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
| 891 GURL("http://foo/"), &proxy_info, | 899 base::Bind(&CrashCallback), &request, |
| 892 base::Bind(&CrashCallback), &request, BoundNetLog()); | 900 BoundNetLog()); |
| 893 | 901 |
| 894 EXPECT_EQ(ERR_IO_PENDING, rv); | 902 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 895 | 903 |
| 896 host_resolver.SetAction( | 904 host_resolver.SetAction( |
| 897 base::Bind(CancelRequestAndPause, &resolver, request)); | 905 base::Bind(CancelRequestAndPause, resolver.get(), request)); |
| 898 | 906 |
| 899 host_resolver.WaitUntilRequestIsReceived(); | 907 host_resolver.WaitUntilRequestIsReceived(); |
| 900 | 908 |
| 901 // At this point the host resolver ran Resolve(), and should have cancelled | 909 // At this point the host resolver ran Resolve(), and should have cancelled |
| 902 // the request. | 910 // the request. |
| 903 | 911 |
| 904 EXPECT_EQ(1, host_resolver.num_cancelled_requests()); | 912 EXPECT_EQ(1, host_resolver.num_cancelled_requests()); |
| 905 } | 913 } |
| 906 | 914 |
| 907 // Cancel the request while there is a pending DNS request, however before | 915 // Cancel the request while there is a pending DNS request, however before |
| 908 // the request is sent to the host resolver. | 916 // the request is sent to the host resolver. |
| 909 TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns2) { | 917 TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns2) { |
| 910 MockCachingHostResolver host_resolver; | 918 MockCachingHostResolver host_resolver; |
| 911 MockErrorObserver* error_observer = new MockErrorObserver; | 919 MockErrorObserver* error_observer = new MockErrorObserver; |
| 912 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL); | |
| 913 | 920 |
| 914 InitResolver(&resolver, "dns.js"); | 921 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
| 922 nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); |
| 915 | 923 |
| 916 ProxyInfo proxy_info; | 924 ProxyInfo proxy_info; |
| 917 ProxyResolver::RequestHandle request; | 925 ProxyResolver::RequestHandle request; |
| 918 | 926 |
| 919 int rv = resolver.GetProxyForURL( | 927 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
| 920 GURL("http://foo/"), &proxy_info, | 928 base::Bind(&CrashCallback), &request, |
| 921 base::Bind(&CrashCallback), &request, BoundNetLog()); | 929 BoundNetLog()); |
| 922 | 930 |
| 923 EXPECT_EQ(ERR_IO_PENDING, rv); | 931 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 924 | 932 |
| 925 // Wait a bit, so the DNS task has hopefully been posted. The test will | 933 // Wait a bit, so the DNS task has hopefully been posted. The test will |
| 926 // work whatever the delay is here, but it is most useful if the delay | 934 // work whatever the delay is here, but it is most useful if the delay |
| 927 // is large enough to allow a task to be posted back. | 935 // is large enough to allow a task to be posted back. |
| 928 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); | 936 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); |
| 929 resolver.CancelRequest(request); | 937 resolver->CancelRequest(request); |
| 930 | 938 |
| 931 EXPECT_EQ(0u, host_resolver.num_resolve()); | 939 EXPECT_EQ(0u, host_resolver.num_resolve()); |
| 932 } | 940 } |
| 933 | 941 |
| 934 TEST_F(ProxyResolverV8TracingTest, CancelSetPacWhileOutstandingBlockingDns) { | 942 TEST_F(ProxyResolverV8TracingTest, |
| 943 CancelCreateResolverWhileOutstandingBlockingDns) { |
| 935 BlockableHostResolver host_resolver; | 944 BlockableHostResolver host_resolver; |
| 936 MockErrorObserver* error_observer = new MockErrorObserver; | 945 MockErrorObserver* error_observer = new MockErrorObserver; |
| 937 | 946 |
| 938 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL); | 947 ProxyResolverFactoryV8Tracing factory( |
| 948 &host_resolver, nullptr, ProxyResolver::LoadStateChangedCallback(), |
| 949 base::Bind(&ReturnErrorObserver, |
| 950 base::Passed(make_scoped_ptr(error_observer)))); |
| 939 | 951 |
| 940 int rv = | 952 scoped_ptr<ProxyResolver> resolver; |
| 941 resolver.SetPacScript(LoadScriptData("dns_during_init.js"), | 953 scoped_ptr<ProxyResolverFactory::Request> request; |
| 942 base::Bind(&CrashCallback)); | 954 int rv = factory.CreateProxyResolver(LoadScriptData("dns_during_init.js"), |
| 955 &resolver, base::Bind(&CrashCallback), |
| 956 &request); |
| 943 EXPECT_EQ(ERR_IO_PENDING, rv); | 957 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 944 | 958 |
| 945 host_resolver.WaitUntilRequestIsReceived(); | 959 host_resolver.WaitUntilRequestIsReceived(); |
| 946 | 960 |
| 947 resolver.CancelSetPacScript(); | 961 request.reset(); |
| 948 EXPECT_EQ(1, host_resolver.num_cancelled_requests()); | 962 EXPECT_EQ(1, host_resolver.num_cancelled_requests()); |
| 949 } | 963 } |
| 950 | 964 |
| 965 TEST_F(ProxyResolverV8TracingTest, DeleteFactoryWhileOutstandingBlockingDns) { |
| 966 BlockableHostResolver host_resolver; |
| 967 MockErrorObserver* error_observer = new MockErrorObserver; |
| 968 |
| 969 scoped_ptr<ProxyResolver> resolver; |
| 970 scoped_ptr<ProxyResolverFactory::Request> request; |
| 971 { |
| 972 ProxyResolverFactoryV8Tracing factory( |
| 973 &host_resolver, nullptr, ProxyResolver::LoadStateChangedCallback(), |
| 974 base::Bind(&ReturnErrorObserver, |
| 975 base::Passed(make_scoped_ptr(error_observer)))); |
| 976 |
| 977 int rv = factory.CreateProxyResolver(LoadScriptData("dns_during_init.js"), |
| 978 &resolver, base::Bind(&CrashCallback), |
| 979 &request); |
| 980 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 981 host_resolver.WaitUntilRequestIsReceived(); |
| 982 } |
| 983 EXPECT_EQ(1, host_resolver.num_cancelled_requests()); |
| 984 } |
| 985 |
| 986 TEST_F(ProxyResolverV8TracingTest, ErrorLoadingScript) { |
| 987 BlockableHostResolver host_resolver; |
| 988 MockErrorObserver* error_observer = new MockErrorObserver; |
| 989 |
| 990 ProxyResolverFactoryV8Tracing factory( |
| 991 &host_resolver, nullptr, ProxyResolver::LoadStateChangedCallback(), |
| 992 base::Bind(&ReturnErrorObserver, |
| 993 base::Passed(make_scoped_ptr(error_observer)))); |
| 994 |
| 995 scoped_ptr<ProxyResolver> resolver; |
| 996 scoped_ptr<ProxyResolverFactory::Request> request; |
| 997 TestCompletionCallback callback; |
| 998 int rv = |
| 999 factory.CreateProxyResolver(LoadScriptData("error_on_load.js"), &resolver, |
| 1000 callback.callback(), &request); |
| 1001 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1002 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult()); |
| 1003 EXPECT_FALSE(resolver); |
| 1004 } |
| 1005 |
| 951 // This tests that the execution of a PAC script is terminated when the DNS | 1006 // This tests that the execution of a PAC script is terminated when the DNS |
| 952 // dependencies are missing. If the test fails, then it will hang. | 1007 // dependencies are missing. If the test fails, then it will hang. |
| 953 TEST_F(ProxyResolverV8TracingTest, Terminate) { | 1008 TEST_F(ProxyResolverV8TracingTest, Terminate) { |
| 954 TestNetLog log; | 1009 TestNetLog log; |
| 955 BoundTestNetLog request_log; | 1010 BoundTestNetLog request_log; |
| 956 MockCachingHostResolver host_resolver; | 1011 MockCachingHostResolver host_resolver; |
| 957 MockErrorObserver* error_observer = new MockErrorObserver; | 1012 MockErrorObserver* error_observer = new MockErrorObserver; |
| 958 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | |
| 959 | 1013 |
| 960 host_resolver.rules()->AddRule("host1", "182.111.0.222"); | 1014 host_resolver.rules()->AddRule("host1", "182.111.0.222"); |
| 961 host_resolver.rules()->AddRule("host2", "111.33.44.55"); | 1015 host_resolver.rules()->AddRule("host2", "111.33.44.55"); |
| 962 | 1016 |
| 963 InitResolver(&resolver, "terminate.js"); | 1017 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
| 1018 &log, &host_resolver, make_scoped_ptr(error_observer), "terminate.js"); |
| 964 | 1019 |
| 965 TestCompletionCallback callback; | 1020 TestCompletionCallback callback; |
| 966 ProxyInfo proxy_info; | 1021 ProxyInfo proxy_info; |
| 967 | 1022 |
| 968 int rv = resolver.GetProxyForURL( | 1023 int rv = |
| 969 GURL("http://foopy/req1"), | 1024 resolver->GetProxyForURL(GURL("http://foopy/req1"), &proxy_info, |
| 970 &proxy_info, | 1025 callback.callback(), NULL, request_log.bound()); |
| 971 callback.callback(), | |
| 972 NULL, | |
| 973 request_log.bound()); | |
| 974 | 1026 |
| 975 EXPECT_EQ(ERR_IO_PENDING, rv); | 1027 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 976 EXPECT_EQ(OK, callback.WaitForResult()); | 1028 EXPECT_EQ(OK, callback.WaitForResult()); |
| 977 | 1029 |
| 978 // The test does 2 DNS resolutions. | 1030 // The test does 2 DNS resolutions. |
| 979 EXPECT_EQ(2u, host_resolver.num_resolve()); | 1031 EXPECT_EQ(2u, host_resolver.num_resolve()); |
| 980 | 1032 |
| 981 EXPECT_EQ("foopy:3", proxy_info.proxy_server().ToURI()); | 1033 EXPECT_EQ("foopy:3", proxy_info.proxy_server().ToURI()); |
| 982 | 1034 |
| 983 // No errors. | 1035 // No errors. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1000 "host1", ADDRESS_FAMILY_IPV4, "166.155.144.44"); | 1052 "host1", ADDRESS_FAMILY_IPV4, "166.155.144.44"); |
| 1001 host_resolver0.rules() | 1053 host_resolver0.rules() |
| 1002 ->AddIPLiteralRule("host1", "::1,192.168.1.1", std::string()); | 1054 ->AddIPLiteralRule("host1", "::1,192.168.1.1", std::string()); |
| 1003 host_resolver0.rules()->AddSimulatedFailure("host2"); | 1055 host_resolver0.rules()->AddSimulatedFailure("host2"); |
| 1004 host_resolver0.rules()->AddRule("host3", "166.155.144.33"); | 1056 host_resolver0.rules()->AddRule("host3", "166.155.144.33"); |
| 1005 host_resolver0.rules()->AddRule("host5", "166.155.144.55"); | 1057 host_resolver0.rules()->AddRule("host5", "166.155.144.55"); |
| 1006 host_resolver0.rules()->AddSimulatedFailure("host6"); | 1058 host_resolver0.rules()->AddSimulatedFailure("host6"); |
| 1007 host_resolver0.rules()->AddRuleForAddressFamily( | 1059 host_resolver0.rules()->AddRuleForAddressFamily( |
| 1008 "*", ADDRESS_FAMILY_IPV4, "122.133.144.155"); | 1060 "*", ADDRESS_FAMILY_IPV4, "122.133.144.155"); |
| 1009 host_resolver0.rules()->AddRule("*", "133.122.100.200"); | 1061 host_resolver0.rules()->AddRule("*", "133.122.100.200"); |
| 1010 ProxyResolverV8Tracing resolver0( | 1062 scoped_ptr<ProxyResolver> resolver0 = |
| 1011 &host_resolver0, new MockErrorObserver, NULL); | 1063 CreateResolver(nullptr, &host_resolver0, |
| 1012 InitResolver(&resolver0, "dns.js"); | 1064 make_scoped_ptr(new MockErrorObserver), "dns.js"); |
| 1013 | 1065 |
| 1014 // ------------------------ | 1066 // ------------------------ |
| 1015 // Setup resolver1 | 1067 // Setup resolver1 |
| 1016 // ------------------------ | 1068 // ------------------------ |
| 1017 ProxyResolverV8Tracing resolver1( | 1069 scoped_ptr<ProxyResolver> resolver1 = |
| 1018 &host_resolver0, new MockErrorObserver, NULL); | 1070 CreateResolver(nullptr, &host_resolver0, |
| 1019 InitResolver(&resolver1, "dns.js"); | 1071 make_scoped_ptr(new MockErrorObserver), "dns.js"); |
| 1020 | 1072 |
| 1021 // ------------------------ | 1073 // ------------------------ |
| 1022 // Setup resolver2 | 1074 // Setup resolver2 |
| 1023 // ------------------------ | 1075 // ------------------------ |
| 1024 ProxyResolverV8Tracing resolver2( | 1076 scoped_ptr<ProxyResolver> resolver2 = |
| 1025 &host_resolver0, new MockErrorObserver, NULL); | 1077 CreateResolver(nullptr, &host_resolver0, |
| 1026 InitResolver(&resolver2, "simple.js"); | 1078 make_scoped_ptr(new MockErrorObserver), "simple.js"); |
| 1027 | 1079 |
| 1028 // ------------------------ | 1080 // ------------------------ |
| 1029 // Setup resolver3 | 1081 // Setup resolver3 |
| 1030 // ------------------------ | 1082 // ------------------------ |
| 1031 MockHostResolver host_resolver3; | 1083 MockHostResolver host_resolver3; |
| 1032 host_resolver3.rules()->AddRule("foo", "166.155.144.33"); | 1084 host_resolver3.rules()->AddRule("foo", "166.155.144.33"); |
| 1033 ProxyResolverV8Tracing resolver3( | 1085 scoped_ptr<ProxyResolver> resolver3 = |
| 1034 &host_resolver3, new MockErrorObserver, NULL); | 1086 CreateResolver(nullptr, &host_resolver3, |
| 1035 InitResolver(&resolver3, "simple_dns.js"); | 1087 make_scoped_ptr(new MockErrorObserver), "simple_dns.js"); |
| 1036 | 1088 |
| 1037 // ------------------------ | 1089 // ------------------------ |
| 1038 // Queue up work for each resolver (which will be running in parallel). | 1090 // Queue up work for each resolver (which will be running in parallel). |
| 1039 // ------------------------ | 1091 // ------------------------ |
| 1040 | 1092 |
| 1041 ProxyResolverV8Tracing* resolver[] = { | 1093 ProxyResolver* resolver[] = { |
| 1042 &resolver0, &resolver1, &resolver2, &resolver3, | 1094 resolver0.get(), resolver1.get(), resolver2.get(), resolver3.get(), |
| 1043 }; | 1095 }; |
| 1044 | 1096 |
| 1045 const size_t kNumResolvers = arraysize(resolver); | 1097 const size_t kNumResolvers = arraysize(resolver); |
| 1046 const size_t kNumIterations = 20; | 1098 const size_t kNumIterations = 20; |
| 1047 const size_t kNumResults = kNumResolvers * kNumIterations; | 1099 const size_t kNumResults = kNumResolvers * kNumIterations; |
| 1048 TestCompletionCallback callback[kNumResults]; | 1100 TestCompletionCallback callback[kNumResults]; |
| 1049 ProxyInfo proxy_info[kNumResults]; | 1101 ProxyInfo proxy_info[kNumResults]; |
| 1050 | 1102 |
| 1051 for (size_t i = 0; i < kNumResults; ++i) { | 1103 for (size_t i = 0; i < kNumResults; ++i) { |
| 1052 size_t resolver_i = i % kNumResolvers; | 1104 size_t resolver_i = i % kNumResolvers; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1091 proxy_uri.substr(0, proxy_uri.find(':') + 1)); | 1143 proxy_uri.substr(0, proxy_uri.find(':') + 1)); |
| 1092 } else { | 1144 } else { |
| 1093 NOTREACHED(); | 1145 NOTREACHED(); |
| 1094 } | 1146 } |
| 1095 } | 1147 } |
| 1096 } | 1148 } |
| 1097 | 1149 |
| 1098 } // namespace | 1150 } // namespace |
| 1099 | 1151 |
| 1100 } // namespace net | 1152 } // namespace net |
| OLD | NEW |