| 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 "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 } | 89 } |
| 90 | 90 |
| 91 private: | 91 private: |
| 92 base::Lock lock_; | 92 base::Lock lock_; |
| 93 std::string output; | 93 std::string output; |
| 94 | 94 |
| 95 base::WaitableEvent event_; | 95 base::WaitableEvent event_; |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 TEST_F(ProxyResolverV8TracingTest, Simple) { | 98 TEST_F(ProxyResolverV8TracingTest, Simple) { |
| 99 CapturingNetLog log; | 99 TestNetLog log; |
| 100 CapturingBoundNetLog request_log; | 100 BoundTestNetLog request_log; |
| 101 MockCachingHostResolver host_resolver; | 101 MockCachingHostResolver host_resolver; |
| 102 MockErrorObserver* error_observer = new MockErrorObserver; | 102 MockErrorObserver* error_observer = new MockErrorObserver; |
| 103 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | 103 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); |
| 104 | 104 |
| 105 InitResolver(&resolver, "simple.js"); | 105 InitResolver(&resolver, "simple.js"); |
| 106 | 106 |
| 107 TestCompletionCallback callback; | 107 TestCompletionCallback callback; |
| 108 ProxyInfo proxy_info; | 108 ProxyInfo proxy_info; |
| 109 | 109 |
| 110 int rv = resolver.GetProxyForURL( | 110 int rv = resolver.GetProxyForURL( |
| 111 GURL("http://foo/"), &proxy_info, callback.callback(), | 111 GURL("http://foo/"), &proxy_info, callback.callback(), |
| 112 NULL, request_log.bound()); | 112 NULL, request_log.bound()); |
| 113 | 113 |
| 114 EXPECT_EQ(ERR_IO_PENDING, rv); | 114 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 115 EXPECT_EQ(OK, callback.WaitForResult()); | 115 EXPECT_EQ(OK, callback.WaitForResult()); |
| 116 | 116 |
| 117 EXPECT_EQ("foo:99", proxy_info.proxy_server().ToURI()); | 117 EXPECT_EQ("foo:99", proxy_info.proxy_server().ToURI()); |
| 118 | 118 |
| 119 EXPECT_EQ(0u, host_resolver.num_resolve()); | 119 EXPECT_EQ(0u, host_resolver.num_resolve()); |
| 120 | 120 |
| 121 // There were no errors. | 121 // There were no errors. |
| 122 EXPECT_EQ("", error_observer->GetOutput()); | 122 EXPECT_EQ("", error_observer->GetOutput()); |
| 123 | 123 |
| 124 // Check the NetLogs -- nothing was logged. | 124 // Check the NetLogs -- nothing was logged. |
| 125 EXPECT_EQ(0u, log.GetSize()); | 125 EXPECT_EQ(0u, log.GetSize()); |
| 126 EXPECT_EQ(0u, request_log.GetSize()); | 126 EXPECT_EQ(0u, request_log.GetSize()); |
| 127 } | 127 } |
| 128 | 128 |
| 129 TEST_F(ProxyResolverV8TracingTest, JavascriptError) { | 129 TEST_F(ProxyResolverV8TracingTest, JavascriptError) { |
| 130 CapturingNetLog log; | 130 TestNetLog log; |
| 131 CapturingBoundNetLog request_log; | 131 BoundTestNetLog request_log; |
| 132 MockCachingHostResolver host_resolver; | 132 MockCachingHostResolver host_resolver; |
| 133 MockErrorObserver* error_observer = new MockErrorObserver; | 133 MockErrorObserver* error_observer = new MockErrorObserver; |
| 134 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | 134 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); |
| 135 | 135 |
| 136 InitResolver(&resolver, "error.js"); | 136 InitResolver(&resolver, "error.js"); |
| 137 | 137 |
| 138 TestCompletionCallback callback; | 138 TestCompletionCallback callback; |
| 139 ProxyInfo proxy_info; | 139 ProxyInfo proxy_info; |
| 140 | 140 |
| 141 int rv = resolver.GetProxyForURL( | 141 int rv = resolver.GetProxyForURL( |
| 142 GURL("http://throw-an-error/"), &proxy_info, callback.callback(), NULL, | 142 GURL("http://throw-an-error/"), &proxy_info, callback.callback(), NULL, |
| 143 request_log.bound()); | 143 request_log.bound()); |
| 144 | 144 |
| 145 EXPECT_EQ(ERR_IO_PENDING, rv); | 145 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 146 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult()); | 146 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult()); |
| 147 | 147 |
| 148 EXPECT_EQ(0u, host_resolver.num_resolve()); | 148 EXPECT_EQ(0u, host_resolver.num_resolve()); |
| 149 | 149 |
| 150 EXPECT_EQ("Error: line 5: Uncaught TypeError: Cannot read property 'split' " | 150 EXPECT_EQ("Error: line 5: Uncaught TypeError: Cannot read property 'split' " |
| 151 "of null\n", error_observer->GetOutput()); | 151 "of null\n", error_observer->GetOutput()); |
| 152 | 152 |
| 153 // Check the NetLogs -- there was 1 alert and 1 javascript error, and they | 153 // Check the NetLogs -- there was 1 alert and 1 javascript error, and they |
| 154 // were output to both the global log, and per-request log. | 154 // were output to both the global log, and per-request log. |
| 155 CapturingNetLog::CapturedEntryList entries_list[2]; | 155 TestNetLog::CapturedEntryList entries_list[2]; |
| 156 log.GetEntries(&entries_list[0]); | 156 log.GetEntries(&entries_list[0]); |
| 157 request_log.GetEntries(&entries_list[1]); | 157 request_log.GetEntries(&entries_list[1]); |
| 158 | 158 |
| 159 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { | 159 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { |
| 160 const CapturingNetLog::CapturedEntryList& entries = entries_list[list_i]; | 160 const TestNetLog::CapturedEntryList& entries = entries_list[list_i]; |
| 161 EXPECT_EQ(2u, entries.size()); | 161 EXPECT_EQ(2u, entries.size()); |
| 162 EXPECT_TRUE( | 162 EXPECT_TRUE( |
| 163 LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, | 163 LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, |
| 164 NetLog::PHASE_NONE)); | 164 NetLog::PHASE_NONE)); |
| 165 EXPECT_TRUE( | 165 EXPECT_TRUE( |
| 166 LogContainsEvent(entries, 1, NetLog::TYPE_PAC_JAVASCRIPT_ERROR, | 166 LogContainsEvent(entries, 1, NetLog::TYPE_PAC_JAVASCRIPT_ERROR, |
| 167 NetLog::PHASE_NONE)); | 167 NetLog::PHASE_NONE)); |
| 168 | 168 |
| 169 EXPECT_EQ("{\"message\":\"Prepare to DIE!\"}", entries[0].GetParamsJson()); | 169 EXPECT_EQ("{\"message\":\"Prepare to DIE!\"}", entries[0].GetParamsJson()); |
| 170 EXPECT_EQ("{\"line_number\":5,\"message\":\"Uncaught TypeError: Cannot " | 170 EXPECT_EQ("{\"line_number\":5,\"message\":\"Uncaught TypeError: Cannot " |
| 171 "read property 'split' of null\"}", entries[1].GetParamsJson()); | 171 "read property 'split' of null\"}", entries[1].GetParamsJson()); |
| 172 } | 172 } |
| 173 } | 173 } |
| 174 | 174 |
| 175 TEST_F(ProxyResolverV8TracingTest, TooManyAlerts) { | 175 TEST_F(ProxyResolverV8TracingTest, TooManyAlerts) { |
| 176 CapturingNetLog log; | 176 TestNetLog log; |
| 177 CapturingBoundNetLog request_log; | 177 BoundTestNetLog request_log; |
| 178 MockCachingHostResolver host_resolver; | 178 MockCachingHostResolver host_resolver; |
| 179 MockErrorObserver* error_observer = new MockErrorObserver; | 179 MockErrorObserver* error_observer = new MockErrorObserver; |
| 180 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | 180 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); |
| 181 | 181 |
| 182 InitResolver(&resolver, "too_many_alerts.js"); | 182 InitResolver(&resolver, "too_many_alerts.js"); |
| 183 | 183 |
| 184 TestCompletionCallback callback; | 184 TestCompletionCallback callback; |
| 185 ProxyInfo proxy_info; | 185 ProxyInfo proxy_info; |
| 186 | 186 |
| 187 int rv = resolver.GetProxyForURL( | 187 int rv = resolver.GetProxyForURL( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 199 // Iteration3 runs in blocking mode and completes | 199 // Iteration3 runs in blocking mode and completes |
| 200 EXPECT_EQ("foo:3", proxy_info.proxy_server().ToURI()); | 200 EXPECT_EQ("foo:3", proxy_info.proxy_server().ToURI()); |
| 201 | 201 |
| 202 EXPECT_EQ(1u, host_resolver.num_resolve()); | 202 EXPECT_EQ(1u, host_resolver.num_resolve()); |
| 203 | 203 |
| 204 // No errors. | 204 // No errors. |
| 205 EXPECT_EQ("", error_observer->GetOutput()); | 205 EXPECT_EQ("", error_observer->GetOutput()); |
| 206 | 206 |
| 207 // Check the NetLogs -- the script generated 50 alerts, which were mirrored | 207 // Check the NetLogs -- the script generated 50 alerts, which were mirrored |
| 208 // to both the global and per-request logs. | 208 // to both the global and per-request logs. |
| 209 CapturingNetLog::CapturedEntryList entries_list[2]; | 209 TestNetLog::CapturedEntryList entries_list[2]; |
| 210 log.GetEntries(&entries_list[0]); | 210 log.GetEntries(&entries_list[0]); |
| 211 request_log.GetEntries(&entries_list[1]); | 211 request_log.GetEntries(&entries_list[1]); |
| 212 | 212 |
| 213 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { | 213 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { |
| 214 const CapturingNetLog::CapturedEntryList& entries = entries_list[list_i]; | 214 const TestNetLog::CapturedEntryList& entries = entries_list[list_i]; |
| 215 EXPECT_EQ(50u, entries.size()); | 215 EXPECT_EQ(50u, entries.size()); |
| 216 for (size_t i = 0; i < entries.size(); ++i) { | 216 for (size_t i = 0; i < entries.size(); ++i) { |
| 217 ASSERT_TRUE( | 217 ASSERT_TRUE( |
| 218 LogContainsEvent(entries, i, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, | 218 LogContainsEvent(entries, i, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, |
| 219 NetLog::PHASE_NONE)); | 219 NetLog::PHASE_NONE)); |
| 220 } | 220 } |
| 221 } | 221 } |
| 222 } | 222 } |
| 223 | 223 |
| 224 // Verify that buffered alerts cannot grow unboundedly, even when the message is | 224 // Verify that buffered alerts cannot grow unboundedly, even when the message is |
| 225 // empty string. | 225 // empty string. |
| 226 TEST_F(ProxyResolverV8TracingTest, TooManyEmptyAlerts) { | 226 TEST_F(ProxyResolverV8TracingTest, TooManyEmptyAlerts) { |
| 227 CapturingNetLog log; | 227 TestNetLog log; |
| 228 CapturingBoundNetLog request_log; | 228 BoundTestNetLog request_log; |
| 229 MockCachingHostResolver host_resolver; | 229 MockCachingHostResolver host_resolver; |
| 230 MockErrorObserver* error_observer = new MockErrorObserver; | 230 MockErrorObserver* error_observer = new MockErrorObserver; |
| 231 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | 231 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); |
| 232 | 232 |
| 233 InitResolver(&resolver, "too_many_empty_alerts.js"); | 233 InitResolver(&resolver, "too_many_empty_alerts.js"); |
| 234 | 234 |
| 235 TestCompletionCallback callback; | 235 TestCompletionCallback callback; |
| 236 ProxyInfo proxy_info; | 236 ProxyInfo proxy_info; |
| 237 | 237 |
| 238 int rv = resolver.GetProxyForURL( | 238 int rv = resolver.GetProxyForURL( |
| 239 GURL("http://foo/"), | 239 GURL("http://foo/"), |
| 240 &proxy_info, | 240 &proxy_info, |
| 241 callback.callback(), | 241 callback.callback(), |
| 242 NULL, | 242 NULL, |
| 243 request_log.bound()); | 243 request_log.bound()); |
| 244 | 244 |
| 245 EXPECT_EQ(ERR_IO_PENDING, rv); | 245 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 246 EXPECT_EQ(OK, callback.WaitForResult()); | 246 EXPECT_EQ(OK, callback.WaitForResult()); |
| 247 | 247 |
| 248 EXPECT_EQ("foo:3", proxy_info.proxy_server().ToURI()); | 248 EXPECT_EQ("foo:3", proxy_info.proxy_server().ToURI()); |
| 249 | 249 |
| 250 EXPECT_EQ(1u, host_resolver.num_resolve()); | 250 EXPECT_EQ(1u, host_resolver.num_resolve()); |
| 251 | 251 |
| 252 // No errors. | 252 // No errors. |
| 253 EXPECT_EQ("", error_observer->GetOutput()); | 253 EXPECT_EQ("", error_observer->GetOutput()); |
| 254 | 254 |
| 255 // Check the NetLogs -- the script generated 50 alerts, which were mirrored | 255 // Check the NetLogs -- the script generated 50 alerts, which were mirrored |
| 256 // to both the global and per-request logs. | 256 // to both the global and per-request logs. |
| 257 CapturingNetLog::CapturedEntryList entries_list[2]; | 257 TestNetLog::CapturedEntryList entries_list[2]; |
| 258 log.GetEntries(&entries_list[0]); | 258 log.GetEntries(&entries_list[0]); |
| 259 request_log.GetEntries(&entries_list[1]); | 259 request_log.GetEntries(&entries_list[1]); |
| 260 | 260 |
| 261 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { | 261 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { |
| 262 const CapturingNetLog::CapturedEntryList& entries = entries_list[list_i]; | 262 const TestNetLog::CapturedEntryList& entries = entries_list[list_i]; |
| 263 EXPECT_EQ(1000u, entries.size()); | 263 EXPECT_EQ(1000u, entries.size()); |
| 264 for (size_t i = 0; i < entries.size(); ++i) { | 264 for (size_t i = 0; i < entries.size(); ++i) { |
| 265 ASSERT_TRUE( | 265 ASSERT_TRUE( |
| 266 LogContainsEvent(entries, i, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, | 266 LogContainsEvent(entries, i, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, |
| 267 NetLog::PHASE_NONE)); | 267 NetLog::PHASE_NONE)); |
| 268 } | 268 } |
| 269 } | 269 } |
| 270 } | 270 } |
| 271 | 271 |
| 272 // This test runs a PAC script that issues a sequence of DNS resolves. The test | 272 // This test runs a PAC script that issues a sequence of DNS resolves. The test |
| 273 // verifies the final result, and that the underlying DNS resolver received | 273 // verifies the final result, and that the underlying DNS resolver received |
| 274 // the correct set of queries. | 274 // the correct set of queries. |
| 275 TEST_F(ProxyResolverV8TracingTest, Dns) { | 275 TEST_F(ProxyResolverV8TracingTest, Dns) { |
| 276 CapturingNetLog log; | 276 TestNetLog log; |
| 277 CapturingBoundNetLog request_log; | 277 BoundTestNetLog request_log; |
| 278 MockCachingHostResolver host_resolver; | 278 MockCachingHostResolver host_resolver; |
| 279 MockErrorObserver* error_observer = new MockErrorObserver; | 279 MockErrorObserver* error_observer = new MockErrorObserver; |
| 280 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | 280 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); |
| 281 | 281 |
| 282 host_resolver.rules()->AddRuleForAddressFamily( | 282 host_resolver.rules()->AddRuleForAddressFamily( |
| 283 "host1", ADDRESS_FAMILY_IPV4, "166.155.144.44"); | 283 "host1", ADDRESS_FAMILY_IPV4, "166.155.144.44"); |
| 284 host_resolver.rules() | 284 host_resolver.rules() |
| 285 ->AddIPLiteralRule("host1", "::1,192.168.1.1", std::string()); | 285 ->AddIPLiteralRule("host1", "::1,192.168.1.1", std::string()); |
| 286 host_resolver.rules()->AddSimulatedFailure("host2"); | 286 host_resolver.rules()->AddSimulatedFailure("host2"); |
| 287 host_resolver.rules()->AddRule("host3", "166.155.144.33"); | 287 host_resolver.rules()->AddRule("host3", "166.155.144.33"); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 "166.155.144.44" // dnsResolve('host1') | 325 "166.155.144.44" // dnsResolve('host1') |
| 326 ":99"; | 326 ":99"; |
| 327 | 327 |
| 328 EXPECT_EQ(kExpectedResult, proxy_info.proxy_server().ToURI()); | 328 EXPECT_EQ(kExpectedResult, proxy_info.proxy_server().ToURI()); |
| 329 | 329 |
| 330 // No errors. | 330 // No errors. |
| 331 EXPECT_EQ("", error_observer->GetOutput()); | 331 EXPECT_EQ("", error_observer->GetOutput()); |
| 332 | 332 |
| 333 // Check the NetLogs -- the script generated 1 alert, mirrored to both | 333 // Check the NetLogs -- the script generated 1 alert, mirrored to both |
| 334 // the per-request and global logs. | 334 // the per-request and global logs. |
| 335 CapturingNetLog::CapturedEntryList entries_list[2]; | 335 TestNetLog::CapturedEntryList entries_list[2]; |
| 336 log.GetEntries(&entries_list[0]); | 336 log.GetEntries(&entries_list[0]); |
| 337 request_log.GetEntries(&entries_list[1]); | 337 request_log.GetEntries(&entries_list[1]); |
| 338 | 338 |
| 339 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { | 339 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { |
| 340 const CapturingNetLog::CapturedEntryList& entries = entries_list[list_i]; | 340 const TestNetLog::CapturedEntryList& entries = entries_list[list_i]; |
| 341 EXPECT_EQ(1u, entries.size()); | 341 EXPECT_EQ(1u, entries.size()); |
| 342 EXPECT_TRUE( | 342 EXPECT_TRUE( |
| 343 LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, | 343 LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, |
| 344 NetLog::PHASE_NONE)); | 344 NetLog::PHASE_NONE)); |
| 345 EXPECT_EQ("{\"message\":\"iteration: 7\"}", entries[0].GetParamsJson()); | 345 EXPECT_EQ("{\"message\":\"iteration: 7\"}", entries[0].GetParamsJson()); |
| 346 } | 346 } |
| 347 } | 347 } |
| 348 | 348 |
| 349 // This test runs a PAC script that does "myIpAddress()" followed by | 349 // This test runs a PAC script that does "myIpAddress()" followed by |
| 350 // "dnsResolve()". This requires 2 restarts. However once the HostResolver's | 350 // "dnsResolve()". This requires 2 restarts. However once the HostResolver's |
| 351 // cache is warmed, subsequent calls should take 0 restarts. | 351 // cache is warmed, subsequent calls should take 0 restarts. |
| 352 TEST_F(ProxyResolverV8TracingTest, DnsChecksCache) { | 352 TEST_F(ProxyResolverV8TracingTest, DnsChecksCache) { |
| 353 CapturingNetLog log; | 353 TestNetLog log; |
| 354 CapturingBoundNetLog request_log; | 354 BoundTestNetLog request_log; |
| 355 MockCachingHostResolver host_resolver; | 355 MockCachingHostResolver host_resolver; |
| 356 MockErrorObserver* error_observer = new MockErrorObserver; | 356 MockErrorObserver* error_observer = new MockErrorObserver; |
| 357 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | 357 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); |
| 358 | 358 |
| 359 host_resolver.rules()->AddRule("foopy", "166.155.144.11"); | 359 host_resolver.rules()->AddRule("foopy", "166.155.144.11"); |
| 360 host_resolver.rules()->AddRule("*", "122.133.144.155"); | 360 host_resolver.rules()->AddRule("*", "122.133.144.155"); |
| 361 | 361 |
| 362 InitResolver(&resolver, "simple_dns.js"); | 362 InitResolver(&resolver, "simple_dns.js"); |
| 363 | 363 |
| 364 TestCompletionCallback callback1; | 364 TestCompletionCallback callback1; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 EXPECT_EQ("", error_observer->GetOutput()); | 400 EXPECT_EQ("", error_observer->GetOutput()); |
| 401 | 401 |
| 402 EXPECT_EQ(0u, log.GetSize()); | 402 EXPECT_EQ(0u, log.GetSize()); |
| 403 EXPECT_EQ(0u, request_log.GetSize()); | 403 EXPECT_EQ(0u, request_log.GetSize()); |
| 404 } | 404 } |
| 405 | 405 |
| 406 // This test runs a weird PAC script that was designed to defeat the DNS tracing | 406 // This test runs a weird PAC script that was designed to defeat the DNS tracing |
| 407 // optimization. The proxy resolver should detect the inconsistency and | 407 // optimization. The proxy resolver should detect the inconsistency and |
| 408 // fall-back to synchronous mode execution. | 408 // fall-back to synchronous mode execution. |
| 409 TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous1) { | 409 TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous1) { |
| 410 CapturingNetLog log; | 410 TestNetLog log; |
| 411 CapturingBoundNetLog request_log; | 411 BoundTestNetLog request_log; |
| 412 MockCachingHostResolver host_resolver; | 412 MockCachingHostResolver host_resolver; |
| 413 MockErrorObserver* error_observer = new MockErrorObserver; | 413 MockErrorObserver* error_observer = new MockErrorObserver; |
| 414 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | 414 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); |
| 415 | 415 |
| 416 host_resolver.rules()->AddRule("host1", "166.155.144.11"); | 416 host_resolver.rules()->AddRule("host1", "166.155.144.11"); |
| 417 host_resolver.rules()->AddRule("crazy4", "133.199.111.4"); | 417 host_resolver.rules()->AddRule("crazy4", "133.199.111.4"); |
| 418 host_resolver.rules()->AddRule("*", "122.133.144.155"); | 418 host_resolver.rules()->AddRule("*", "122.133.144.155"); |
| 419 | 419 |
| 420 InitResolver(&resolver, "global_sideffects1.js"); | 420 InitResolver(&resolver, "global_sideffects1.js"); |
| 421 | 421 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 434 EXPECT_EQ(3u, host_resolver.num_resolve()); | 434 EXPECT_EQ(3u, host_resolver.num_resolve()); |
| 435 | 435 |
| 436 EXPECT_EQ("166.155.144.11-133.199.111.4:100", | 436 EXPECT_EQ("166.155.144.11-133.199.111.4:100", |
| 437 proxy_info.proxy_server().ToURI()); | 437 proxy_info.proxy_server().ToURI()); |
| 438 | 438 |
| 439 // No errors. | 439 // No errors. |
| 440 EXPECT_EQ("", error_observer->GetOutput()); | 440 EXPECT_EQ("", error_observer->GetOutput()); |
| 441 | 441 |
| 442 // Check the NetLogs -- the script generated 1 alert, mirrored to both | 442 // Check the NetLogs -- the script generated 1 alert, mirrored to both |
| 443 // the per-request and global logs. | 443 // the per-request and global logs. |
| 444 CapturingNetLog::CapturedEntryList entries_list[2]; | 444 TestNetLog::CapturedEntryList entries_list[2]; |
| 445 log.GetEntries(&entries_list[0]); | 445 log.GetEntries(&entries_list[0]); |
| 446 request_log.GetEntries(&entries_list[1]); | 446 request_log.GetEntries(&entries_list[1]); |
| 447 | 447 |
| 448 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { | 448 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { |
| 449 const CapturingNetLog::CapturedEntryList& entries = entries_list[list_i]; | 449 const TestNetLog::CapturedEntryList& entries = entries_list[list_i]; |
| 450 EXPECT_EQ(1u, entries.size()); | 450 EXPECT_EQ(1u, entries.size()); |
| 451 EXPECT_TRUE( | 451 EXPECT_TRUE( |
| 452 LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, | 452 LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, |
| 453 NetLog::PHASE_NONE)); | 453 NetLog::PHASE_NONE)); |
| 454 EXPECT_EQ("{\"message\":\"iteration: 4\"}", entries[0].GetParamsJson()); | 454 EXPECT_EQ("{\"message\":\"iteration: 4\"}", entries[0].GetParamsJson()); |
| 455 } | 455 } |
| 456 } | 456 } |
| 457 | 457 |
| 458 // This test runs a weird PAC script that was designed to defeat the DNS tracing | 458 // This test runs a weird PAC script that was designed to defeat the DNS tracing |
| 459 // optimization. The proxy resolver should detect the inconsistency and | 459 // optimization. The proxy resolver should detect the inconsistency and |
| 460 // fall-back to synchronous mode execution. | 460 // fall-back to synchronous mode execution. |
| 461 TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous2) { | 461 TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous2) { |
| 462 CapturingNetLog log; | 462 TestNetLog log; |
| 463 CapturingBoundNetLog request_log; | 463 BoundTestNetLog request_log; |
| 464 MockCachingHostResolver host_resolver; | 464 MockCachingHostResolver host_resolver; |
| 465 MockErrorObserver* error_observer = new MockErrorObserver; | 465 MockErrorObserver* error_observer = new MockErrorObserver; |
| 466 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | 466 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); |
| 467 | 467 |
| 468 host_resolver.rules()->AddRule("host1", "166.155.144.11"); | 468 host_resolver.rules()->AddRule("host1", "166.155.144.11"); |
| 469 host_resolver.rules()->AddRule("host2", "166.155.144.22"); | 469 host_resolver.rules()->AddRule("host2", "166.155.144.22"); |
| 470 host_resolver.rules()->AddRule("host3", "166.155.144.33"); | 470 host_resolver.rules()->AddRule("host3", "166.155.144.33"); |
| 471 host_resolver.rules()->AddRule("host4", "166.155.144.44"); | 471 host_resolver.rules()->AddRule("host4", "166.155.144.44"); |
| 472 host_resolver.rules()->AddRule("*", "122.133.144.155"); | 472 host_resolver.rules()->AddRule("*", "122.133.144.155"); |
| 473 | 473 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 492 // Check the NetLogs -- nothing was logged. | 492 // Check the NetLogs -- nothing was logged. |
| 493 EXPECT_EQ(0u, log.GetSize()); | 493 EXPECT_EQ(0u, log.GetSize()); |
| 494 EXPECT_EQ(0u, request_log.GetSize()); | 494 EXPECT_EQ(0u, request_log.GetSize()); |
| 495 } | 495 } |
| 496 | 496 |
| 497 // This test runs a weird PAC script that yields a never ending sequence | 497 // This test runs a weird PAC script that yields a never ending sequence |
| 498 // of DNS resolves when restarting. Running it will hit the maximum | 498 // of DNS resolves when restarting. Running it will hit the maximum |
| 499 // DNS resolves per request limit (20) after which every DNS resolve will | 499 // DNS resolves per request limit (20) after which every DNS resolve will |
| 500 // fail. | 500 // fail. |
| 501 TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence) { | 501 TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence) { |
| 502 CapturingNetLog log; | 502 TestNetLog log; |
| 503 CapturingBoundNetLog request_log; | 503 BoundTestNetLog request_log; |
| 504 MockCachingHostResolver host_resolver; | 504 MockCachingHostResolver host_resolver; |
| 505 MockErrorObserver* error_observer = new MockErrorObserver; | 505 MockErrorObserver* error_observer = new MockErrorObserver; |
| 506 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | 506 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); |
| 507 | 507 |
| 508 host_resolver.rules()->AddRule("host*", "166.155.144.11"); | 508 host_resolver.rules()->AddRule("host*", "166.155.144.11"); |
| 509 host_resolver.rules()->AddRule("*", "122.133.144.155"); | 509 host_resolver.rules()->AddRule("*", "122.133.144.155"); |
| 510 | 510 |
| 511 InitResolver(&resolver, "global_sideffects3.js"); | 511 InitResolver(&resolver, "global_sideffects3.js"); |
| 512 | 512 |
| 513 TestCompletionCallback callback; | 513 TestCompletionCallback callback; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 535 // Check the NetLogs -- 1 alert was logged. | 535 // Check the NetLogs -- 1 alert was logged. |
| 536 EXPECT_EQ(1u, log.GetSize()); | 536 EXPECT_EQ(1u, log.GetSize()); |
| 537 EXPECT_EQ(1u, request_log.GetSize()); | 537 EXPECT_EQ(1u, request_log.GetSize()); |
| 538 } | 538 } |
| 539 | 539 |
| 540 // This test runs a weird PAC script that yields a never ending sequence | 540 // This test runs a weird PAC script that yields a never ending sequence |
| 541 // of DNS resolves when restarting. Running it will hit the maximum | 541 // of DNS resolves when restarting. Running it will hit the maximum |
| 542 // DNS resolves per request limit (20) after which every DNS resolve will | 542 // DNS resolves per request limit (20) after which every DNS resolve will |
| 543 // fail. | 543 // fail. |
| 544 TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence2) { | 544 TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence2) { |
| 545 CapturingNetLog log; | 545 TestNetLog log; |
| 546 CapturingBoundNetLog request_log; | 546 BoundTestNetLog request_log; |
| 547 MockCachingHostResolver host_resolver; | 547 MockCachingHostResolver host_resolver; |
| 548 MockErrorObserver* error_observer = new MockErrorObserver; | 548 MockErrorObserver* error_observer = new MockErrorObserver; |
| 549 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | 549 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); |
| 550 | 550 |
| 551 host_resolver.rules()->AddRule("host*", "166.155.144.11"); | 551 host_resolver.rules()->AddRule("host*", "166.155.144.11"); |
| 552 host_resolver.rules()->AddRule("*", "122.133.144.155"); | 552 host_resolver.rules()->AddRule("*", "122.133.144.155"); |
| 553 | 553 |
| 554 InitResolver(&resolver, "global_sideffects4.js"); | 554 InitResolver(&resolver, "global_sideffects4.js"); |
| 555 | 555 |
| 556 TestCompletionCallback callback; | 556 TestCompletionCallback callback; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 568 | 568 |
| 569 // No errors. | 569 // No errors. |
| 570 EXPECT_EQ("", error_observer->GetOutput()); | 570 EXPECT_EQ("", error_observer->GetOutput()); |
| 571 | 571 |
| 572 // Check the NetLogs -- 1 alert was logged. | 572 // Check the NetLogs -- 1 alert was logged. |
| 573 EXPECT_EQ(1u, log.GetSize()); | 573 EXPECT_EQ(1u, log.GetSize()); |
| 574 EXPECT_EQ(1u, request_log.GetSize()); | 574 EXPECT_EQ(1u, request_log.GetSize()); |
| 575 } | 575 } |
| 576 | 576 |
| 577 void DnsDuringInitHelper(bool synchronous_host_resolver) { | 577 void DnsDuringInitHelper(bool synchronous_host_resolver) { |
| 578 CapturingNetLog log; | 578 TestNetLog log; |
| 579 CapturingBoundNetLog request_log; | 579 BoundTestNetLog request_log; |
| 580 MockCachingHostResolver host_resolver; | 580 MockCachingHostResolver host_resolver; |
| 581 host_resolver.set_synchronous_mode(synchronous_host_resolver); | 581 host_resolver.set_synchronous_mode(synchronous_host_resolver); |
| 582 MockErrorObserver* error_observer = new MockErrorObserver; | 582 MockErrorObserver* error_observer = new MockErrorObserver; |
| 583 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | 583 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); |
| 584 | 584 |
| 585 host_resolver.rules()->AddRule("host1", "91.13.12.1"); | 585 host_resolver.rules()->AddRule("host1", "91.13.12.1"); |
| 586 host_resolver.rules()->AddRule("host2", "91.13.12.2"); | 586 host_resolver.rules()->AddRule("host2", "91.13.12.2"); |
| 587 | 587 |
| 588 InitResolver(&resolver, "dns_during_init.js"); | 588 InitResolver(&resolver, "dns_during_init.js"); |
| 589 | 589 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 607 | 607 |
| 608 // Fetched host1 and host2 again, since the ones done during initialization | 608 // Fetched host1 and host2 again, since the ones done during initialization |
| 609 // should not have been cached. | 609 // should not have been cached. |
| 610 EXPECT_EQ(4u, host_resolver.num_resolve()); | 610 EXPECT_EQ(4u, host_resolver.num_resolve()); |
| 611 | 611 |
| 612 EXPECT_EQ("91.13.12.1-91.13.12.2-145.88.13.3-137.89.8.45:99", | 612 EXPECT_EQ("91.13.12.1-91.13.12.2-145.88.13.3-137.89.8.45:99", |
| 613 proxy_info.proxy_server().ToURI()); | 613 proxy_info.proxy_server().ToURI()); |
| 614 | 614 |
| 615 // Check the NetLogs -- the script generated 2 alerts during initialization. | 615 // Check the NetLogs -- the script generated 2 alerts during initialization. |
| 616 EXPECT_EQ(0u, request_log.GetSize()); | 616 EXPECT_EQ(0u, request_log.GetSize()); |
| 617 CapturingNetLog::CapturedEntryList entries; | 617 TestNetLog::CapturedEntryList entries; |
| 618 log.GetEntries(&entries); | 618 log.GetEntries(&entries); |
| 619 | 619 |
| 620 ASSERT_EQ(2u, entries.size()); | 620 ASSERT_EQ(2u, entries.size()); |
| 621 EXPECT_TRUE( | 621 EXPECT_TRUE( |
| 622 LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, | 622 LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, |
| 623 NetLog::PHASE_NONE)); | 623 NetLog::PHASE_NONE)); |
| 624 EXPECT_TRUE( | 624 EXPECT_TRUE( |
| 625 LogContainsEvent(entries, 1, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, | 625 LogContainsEvent(entries, 1, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, |
| 626 NetLog::PHASE_NONE)); | 626 NetLog::PHASE_NONE)); |
| 627 | 627 |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 | 942 |
| 943 host_resolver.WaitUntilRequestIsReceived(); | 943 host_resolver.WaitUntilRequestIsReceived(); |
| 944 | 944 |
| 945 resolver.CancelSetPacScript(); | 945 resolver.CancelSetPacScript(); |
| 946 EXPECT_EQ(1, host_resolver.num_cancelled_requests()); | 946 EXPECT_EQ(1, host_resolver.num_cancelled_requests()); |
| 947 } | 947 } |
| 948 | 948 |
| 949 // This tests that the execution of a PAC script is terminated when the DNS | 949 // This tests that the execution of a PAC script is terminated when the DNS |
| 950 // dependencies are missing. If the test fails, then it will hang. | 950 // dependencies are missing. If the test fails, then it will hang. |
| 951 TEST_F(ProxyResolverV8TracingTest, Terminate) { | 951 TEST_F(ProxyResolverV8TracingTest, Terminate) { |
| 952 CapturingNetLog log; | 952 TestNetLog log; |
| 953 CapturingBoundNetLog request_log; | 953 BoundTestNetLog request_log; |
| 954 MockCachingHostResolver host_resolver; | 954 MockCachingHostResolver host_resolver; |
| 955 MockErrorObserver* error_observer = new MockErrorObserver; | 955 MockErrorObserver* error_observer = new MockErrorObserver; |
| 956 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | 956 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); |
| 957 | 957 |
| 958 host_resolver.rules()->AddRule("host1", "182.111.0.222"); | 958 host_resolver.rules()->AddRule("host1", "182.111.0.222"); |
| 959 host_resolver.rules()->AddRule("host2", "111.33.44.55"); | 959 host_resolver.rules()->AddRule("host2", "111.33.44.55"); |
| 960 | 960 |
| 961 InitResolver(&resolver, "terminate.js"); | 961 InitResolver(&resolver, "terminate.js"); |
| 962 | 962 |
| 963 TestCompletionCallback callback; | 963 TestCompletionCallback callback; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1089 proxy_uri.substr(0, proxy_uri.find(':') + 1)); | 1089 proxy_uri.substr(0, proxy_uri.find(':') + 1)); |
| 1090 } else { | 1090 } else { |
| 1091 NOTREACHED(); | 1091 NOTREACHED(); |
| 1092 } | 1092 } |
| 1093 } | 1093 } |
| 1094 } | 1094 } |
| 1095 | 1095 |
| 1096 } // namespace | 1096 } // namespace |
| 1097 | 1097 |
| 1098 } // namespace net | 1098 } // namespace net |
| OLD | NEW |