OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_js_bindings.h" | 5 #include "net/proxy/proxy_resolver_js_bindings.h" |
6 | 6 |
7 #include "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "net/base/address_list.h" | 9 #include "net/base/address_list.h" |
10 #include "net/base/mock_host_resolver.h" | 10 #include "net/base/mock_host_resolver.h" |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 scoped_ptr<ProxyResolverJSBindings> bindings( | 297 scoped_ptr<ProxyResolverJSBindings> bindings( |
298 ProxyResolverJSBindings::CreateDefault(host_resolver.get(), &global_log)); | 298 ProxyResolverJSBindings::CreateDefault(host_resolver.get(), &global_log)); |
299 | 299 |
300 // Attach a capturing NetLog as the current request's log stream. | 300 // Attach a capturing NetLog as the current request's log stream. |
301 CapturingNetLog log(CapturingNetLog::kUnbounded); | 301 CapturingNetLog log(CapturingNetLog::kUnbounded); |
302 BoundNetLog bound_log(NetLog::Source(NetLog::SOURCE_NONE, 0), &log); | 302 BoundNetLog bound_log(NetLog::Source(NetLog::SOURCE_NONE, 0), &log); |
303 ProxyResolverRequestContext context(&bound_log, NULL); | 303 ProxyResolverRequestContext context(&bound_log, NULL); |
304 bindings->set_current_request_context(&context); | 304 bindings->set_current_request_context(&context); |
305 | 305 |
306 std::string ip_address; | 306 std::string ip_address; |
307 | 307 net::CapturingNetLog::EntryList entries; |
308 ASSERT_EQ(0u, log.entries().size()); | 308 log.GetEntries(&entries); |
| 309 ASSERT_EQ(0u, entries.size()); |
309 | 310 |
310 // Call all the bindings. Each call should be logging something to | 311 // Call all the bindings. Each call should be logging something to |
311 // our NetLog. | 312 // our NetLog. |
312 | 313 |
313 bindings->MyIpAddress(&ip_address); | 314 bindings->MyIpAddress(&ip_address); |
314 EXPECT_EQ(2u, log.entries().size()); | 315 |
| 316 log.GetEntries(&entries); |
| 317 EXPECT_EQ(2u, entries.size()); |
315 EXPECT_TRUE(LogContainsBeginEvent( | 318 EXPECT_TRUE(LogContainsBeginEvent( |
316 log.entries(), 0, NetLog::TYPE_PAC_JAVASCRIPT_MY_IP_ADDRESS)); | 319 entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_MY_IP_ADDRESS)); |
317 EXPECT_TRUE(LogContainsEndEvent( | 320 EXPECT_TRUE(LogContainsEndEvent( |
318 log.entries(), 1, NetLog::TYPE_PAC_JAVASCRIPT_MY_IP_ADDRESS)); | 321 entries, 1, NetLog::TYPE_PAC_JAVASCRIPT_MY_IP_ADDRESS)); |
319 | 322 |
320 bindings->MyIpAddressEx(&ip_address); | 323 bindings->MyIpAddressEx(&ip_address); |
321 EXPECT_EQ(4u, log.entries().size()); | 324 |
| 325 log.GetEntries(&entries); |
| 326 EXPECT_EQ(4u, entries.size()); |
322 EXPECT_TRUE(LogContainsBeginEvent( | 327 EXPECT_TRUE(LogContainsBeginEvent( |
323 log.entries(), 2, NetLog::TYPE_PAC_JAVASCRIPT_MY_IP_ADDRESS_EX)); | 328 entries, 2, NetLog::TYPE_PAC_JAVASCRIPT_MY_IP_ADDRESS_EX)); |
324 EXPECT_TRUE(LogContainsEndEvent( | 329 EXPECT_TRUE(LogContainsEndEvent( |
325 log.entries(), 3, NetLog::TYPE_PAC_JAVASCRIPT_MY_IP_ADDRESS_EX)); | 330 entries, 3, NetLog::TYPE_PAC_JAVASCRIPT_MY_IP_ADDRESS_EX)); |
326 | 331 |
327 bindings->DnsResolve("foo", &ip_address); | 332 bindings->DnsResolve("foo", &ip_address); |
328 EXPECT_EQ(6u, log.entries().size()); | 333 |
| 334 log.GetEntries(&entries); |
| 335 EXPECT_EQ(6u, entries.size()); |
329 EXPECT_TRUE(LogContainsBeginEvent( | 336 EXPECT_TRUE(LogContainsBeginEvent( |
330 log.entries(), 4, NetLog::TYPE_PAC_JAVASCRIPT_DNS_RESOLVE)); | 337 entries, 4, NetLog::TYPE_PAC_JAVASCRIPT_DNS_RESOLVE)); |
331 EXPECT_TRUE(LogContainsEndEvent( | 338 EXPECT_TRUE(LogContainsEndEvent( |
332 log.entries(), 5, NetLog::TYPE_PAC_JAVASCRIPT_DNS_RESOLVE)); | 339 entries, 5, NetLog::TYPE_PAC_JAVASCRIPT_DNS_RESOLVE)); |
333 | 340 |
334 bindings->DnsResolveEx("foo", &ip_address); | 341 bindings->DnsResolveEx("foo", &ip_address); |
335 EXPECT_EQ(8u, log.entries().size()); | 342 |
| 343 log.GetEntries(&entries); |
| 344 EXPECT_EQ(8u, entries.size()); |
336 EXPECT_TRUE(LogContainsBeginEvent( | 345 EXPECT_TRUE(LogContainsBeginEvent( |
337 log.entries(), 6, NetLog::TYPE_PAC_JAVASCRIPT_DNS_RESOLVE_EX)); | 346 entries, 6, NetLog::TYPE_PAC_JAVASCRIPT_DNS_RESOLVE_EX)); |
338 EXPECT_TRUE(LogContainsEndEvent( | 347 EXPECT_TRUE(LogContainsEndEvent( |
339 log.entries(), 7, NetLog::TYPE_PAC_JAVASCRIPT_DNS_RESOLVE_EX)); | 348 entries, 7, NetLog::TYPE_PAC_JAVASCRIPT_DNS_RESOLVE_EX)); |
340 | 349 |
341 // Nothing has been emitted globally yet. | 350 // Nothing has been emitted globally yet. |
342 EXPECT_EQ(0u, global_log.entries().size()); | 351 net::CapturingNetLog::EntryList global_log_entries; |
| 352 global_log.GetEntries(&global_log_entries); |
| 353 EXPECT_EQ(0u, global_log_entries.size()); |
343 | 354 |
344 bindings->OnError(30, string16()); | 355 bindings->OnError(30, string16()); |
345 EXPECT_EQ(9u, log.entries().size()); | 356 |
| 357 log.GetEntries(&entries); |
| 358 EXPECT_EQ(9u, entries.size()); |
346 EXPECT_TRUE(LogContainsEvent( | 359 EXPECT_TRUE(LogContainsEvent( |
347 log.entries(), 8, NetLog::TYPE_PAC_JAVASCRIPT_ERROR, | 360 entries, 8, NetLog::TYPE_PAC_JAVASCRIPT_ERROR, |
348 NetLog::PHASE_NONE)); | 361 NetLog::PHASE_NONE)); |
349 | 362 |
350 // We also emit errors to the top-level log stream. | 363 // We also emit errors to the top-level log stream. |
351 EXPECT_EQ(1u, global_log.entries().size()); | 364 global_log.GetEntries(&global_log_entries); |
| 365 EXPECT_EQ(1u, global_log_entries.size()); |
352 EXPECT_TRUE(LogContainsEvent( | 366 EXPECT_TRUE(LogContainsEvent( |
353 global_log.entries(), 0, NetLog::TYPE_PAC_JAVASCRIPT_ERROR, | 367 global_log_entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ERROR, |
354 NetLog::PHASE_NONE)); | 368 NetLog::PHASE_NONE)); |
355 | 369 |
356 bindings->Alert(string16()); | 370 bindings->Alert(string16()); |
357 EXPECT_EQ(10u, log.entries().size()); | 371 |
| 372 log.GetEntries(&entries); |
| 373 EXPECT_EQ(10u, entries.size()); |
358 EXPECT_TRUE(LogContainsEvent( | 374 EXPECT_TRUE(LogContainsEvent( |
359 log.entries(), 9, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, | 375 entries, 9, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, |
360 NetLog::PHASE_NONE)); | 376 NetLog::PHASE_NONE)); |
361 | 377 |
362 // We also emit javascript alerts to the top-level log stream. | 378 // We also emit javascript alerts to the top-level log stream. |
363 EXPECT_EQ(2u, global_log.entries().size()); | 379 global_log.GetEntries(&global_log_entries); |
| 380 EXPECT_EQ(2u, global_log_entries.size()); |
364 EXPECT_TRUE(LogContainsEvent( | 381 EXPECT_TRUE(LogContainsEvent( |
365 global_log.entries(), 1, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, | 382 global_log_entries, 1, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, |
366 NetLog::PHASE_NONE)); | 383 NetLog::PHASE_NONE)); |
367 } | 384 } |
368 | 385 |
369 } // namespace | 386 } // namespace |
370 | 387 |
371 } // namespace net | 388 } // namespace net |
OLD | NEW |