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

Side by Side Diff: net/proxy/multi_threaded_proxy_resolver_unittest.cc

Issue 4118004: Update NetLog to be thread safe. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Final sync with trunk Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/multi_threaded_proxy_resolver.h" 5 #include "net/proxy/multi_threaded_proxy_resolver.h"
6 6
7 #include "base/stl_util-inl.h" 7 #include "base/stl_util-inl.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 253
254 // Wait for request 0 to finish. 254 // Wait for request 0 to finish.
255 rv = callback0.WaitForResult(); 255 rv = callback0.WaitForResult();
256 EXPECT_EQ(0, rv); 256 EXPECT_EQ(0, rv);
257 EXPECT_EQ("PROXY request0:80", results0.ToPacString()); 257 EXPECT_EQ("PROXY request0:80", results0.ToPacString());
258 258
259 // The mock proxy resolver should have written 1 log entry. And 259 // The mock proxy resolver should have written 1 log entry. And
260 // on completion, this should have been copied into |log0|. 260 // on completion, this should have been copied into |log0|.
261 // We also have 1 log entry that was emitted by the 261 // We also have 1 log entry that was emitted by the
262 // MultiThreadedProxyResolver. 262 // MultiThreadedProxyResolver.
263 ASSERT_EQ(2u, log0.entries().size()); 263 net::CapturingNetLog::EntryList entries0;
264 EXPECT_EQ(NetLog::TYPE_SUBMITTED_TO_RESOLVER_THREAD, 264 log0.GetEntries(&entries0);
265 log0.entries()[0].type); 265
266 ASSERT_EQ(2u, entries0.size());
267 EXPECT_EQ(NetLog::TYPE_SUBMITTED_TO_RESOLVER_THREAD, entries0[0].type);
266 268
267 // Start 3 more requests (request1 to request3). 269 // Start 3 more requests (request1 to request3).
268 270
269 TestCompletionCallback callback1; 271 TestCompletionCallback callback1;
270 ProxyInfo results1; 272 ProxyInfo results1;
271 rv = resolver.GetProxyForURL( 273 rv = resolver.GetProxyForURL(
272 GURL("http://request1"), &results1, &callback1, NULL, BoundNetLog()); 274 GURL("http://request1"), &results1, &callback1, NULL, BoundNetLog());
273 EXPECT_EQ(ERR_IO_PENDING, rv); 275 EXPECT_EQ(ERR_IO_PENDING, rv);
274 276
275 TestCompletionCallback callback2; 277 TestCompletionCallback callback2;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 363
362 // Unblock the worker thread so the requests can continue running. 364 // Unblock the worker thread so the requests can continue running.
363 mock->WaitUntilBlocked(); 365 mock->WaitUntilBlocked();
364 mock->Unblock(); 366 mock->Unblock();
365 367
366 // Check that request 0 completed as expected. 368 // Check that request 0 completed as expected.
367 // The NetLog has 1 entry that came from the MultiThreadedProxyResolver, and 369 // The NetLog has 1 entry that came from the MultiThreadedProxyResolver, and
368 // 1 entry from the mock proxy resolver. 370 // 1 entry from the mock proxy resolver.
369 EXPECT_EQ(0, callback0.WaitForResult()); 371 EXPECT_EQ(0, callback0.WaitForResult());
370 EXPECT_EQ("PROXY request0:80", results0.ToPacString()); 372 EXPECT_EQ("PROXY request0:80", results0.ToPacString());
371 ASSERT_EQ(2u, log0.entries().size()); 373
374 net::CapturingNetLog::EntryList entries0;
375 log0.GetEntries(&entries0);
376
377 ASSERT_EQ(2u, entries0.size());
372 EXPECT_EQ(NetLog::TYPE_SUBMITTED_TO_RESOLVER_THREAD, 378 EXPECT_EQ(NetLog::TYPE_SUBMITTED_TO_RESOLVER_THREAD,
373 log0.entries()[0].type); 379 entries0[0].type);
374 380
375 // Check that request 1 completed as expected. 381 // Check that request 1 completed as expected.
376 EXPECT_EQ(1, callback1.WaitForResult()); 382 EXPECT_EQ(1, callback1.WaitForResult());
377 EXPECT_EQ("PROXY request1:80", results1.ToPacString()); 383 EXPECT_EQ("PROXY request1:80", results1.ToPacString());
378 ASSERT_EQ(4u, log1.entries().size()); 384
385 net::CapturingNetLog::EntryList entries1;
386 log1.GetEntries(&entries1);
387
388 ASSERT_EQ(4u, entries1.size());
379 EXPECT_TRUE(LogContainsBeginEvent( 389 EXPECT_TRUE(LogContainsBeginEvent(
380 log1.entries(), 0, 390 entries1, 0,
381 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); 391 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD));
382 EXPECT_TRUE(LogContainsEndEvent( 392 EXPECT_TRUE(LogContainsEndEvent(
383 log1.entries(), 1, 393 entries1, 1,
384 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); 394 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD));
385 395
386 // Check that request 2 completed as expected. 396 // Check that request 2 completed as expected.
387 EXPECT_EQ(2, callback2.WaitForResult()); 397 EXPECT_EQ(2, callback2.WaitForResult());
388 EXPECT_EQ("PROXY request2:80", results2.ToPacString()); 398 EXPECT_EQ("PROXY request2:80", results2.ToPacString());
389 ASSERT_EQ(4u, log2.entries().size()); 399
400 net::CapturingNetLog::EntryList entries2;
401 log2.GetEntries(&entries2);
402
403 ASSERT_EQ(4u, entries2.size());
390 EXPECT_TRUE(LogContainsBeginEvent( 404 EXPECT_TRUE(LogContainsBeginEvent(
391 log2.entries(), 0, 405 entries2, 0,
392 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); 406 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD));
393 EXPECT_TRUE(LogContainsEndEvent( 407 EXPECT_TRUE(LogContainsEndEvent(
394 log2.entries(), 1, 408 entries2, 1,
395 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD)); 409 NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD));
396 } 410 }
397 411
398 // Cancel a request which is in progress, and then cancel a request which 412 // Cancel a request which is in progress, and then cancel a request which
399 // is pending. 413 // is pending.
400 TEST(MultiThreadedProxyResolverTest, SingleThread_CancelRequest) { 414 TEST(MultiThreadedProxyResolverTest, SingleThread_CancelRequest) {
401 const size_t kNumThreads = 1u; 415 const size_t kNumThreads = 1u;
402 scoped_ptr<BlockableProxyResolver> mock(new BlockableProxyResolver); 416 scoped_ptr<BlockableProxyResolver> mock(new BlockableProxyResolver);
403 MultiThreadedProxyResolver resolver( 417 MultiThreadedProxyResolver resolver(
404 new ForwardingProxyResolverFactory(mock.get()), 418 new ForwardingProxyResolverFactory(mock.get()),
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 // All in all, the first thread should have seen just 1 request. And the 758 // All in all, the first thread should have seen just 1 request. And the
745 // second thread 3 requests. 759 // second thread 3 requests.
746 ASSERT_EQ(2u, factory->resolvers().size()); 760 ASSERT_EQ(2u, factory->resolvers().size());
747 EXPECT_EQ(1, factory->resolvers()[0]->request_count()); 761 EXPECT_EQ(1, factory->resolvers()[0]->request_count());
748 EXPECT_EQ(3, factory->resolvers()[1]->request_count()); 762 EXPECT_EQ(3, factory->resolvers()[1]->request_count());
749 } 763 }
750 764
751 } // namespace 765 } // namespace
752 766
753 } // namespace net 767 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/multi_threaded_proxy_resolver.cc ('k') | net/proxy/proxy_resolver_js_bindings_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698