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

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

Issue 12088090: Fix a memory error in ProxyResolverV8Tracing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months 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) 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/file_util.h" 7 #include "base/file_util.h"
8 #include "base/message_loop.h" 8 #include "base/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 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 BlockableHostResolver() 754 BlockableHostResolver()
755 : num_cancelled_requests_(0), waiting_for_resolve_(false) {} 755 : num_cancelled_requests_(0), waiting_for_resolve_(false) {}
756 756
757 virtual int Resolve(const RequestInfo& info, 757 virtual int Resolve(const RequestInfo& info,
758 AddressList* addresses, 758 AddressList* addresses,
759 const CompletionCallback& callback, 759 const CompletionCallback& callback,
760 RequestHandle* out_req, 760 RequestHandle* out_req,
761 const BoundNetLog& net_log) OVERRIDE { 761 const BoundNetLog& net_log) OVERRIDE {
762 EXPECT_FALSE(callback.is_null()); 762 EXPECT_FALSE(callback.is_null());
763 EXPECT_TRUE(out_req); 763 EXPECT_TRUE(out_req);
764 *out_req = reinterpret_cast<RequestHandle*>(1); // Magic value.
765 764
766 if (!action_.is_null()) 765 if (!action_.is_null())
767 action_.Run(); 766 action_.Run();
768 767
769 // Indicate to the caller that a request was received. 768 // Indicate to the caller that a request was received.
770 EXPECT_TRUE(waiting_for_resolve_); 769 EXPECT_TRUE(waiting_for_resolve_);
771 MessageLoop::current()->Quit(); 770 MessageLoop::current()->Quit();
772 771
772 // This line is intentionally after action_.Run(), since one of the
773 // tests does a cancellation inside of Resolve(), and it is more
774 // interesting if *out_req hasn't been written yet at that point.
775 *out_req = reinterpret_cast<RequestHandle*>(1); // Magic value.
776
773 // Return ERR_IO_PENDING as this request will NEVER be completed. 777 // Return ERR_IO_PENDING as this request will NEVER be completed.
774 // Expectation is for the caller to later cancel the request. 778 // Expectation is for the caller to later cancel the request.
775 return ERR_IO_PENDING; 779 return ERR_IO_PENDING;
776 } 780 }
777 781
778 virtual int ResolveFromCache(const RequestInfo& info, 782 virtual int ResolveFromCache(const RequestInfo& info,
779 AddressList* addresses, 783 AddressList* addresses,
780 const BoundNetLog& net_log) OVERRIDE { 784 const BoundNetLog& net_log) OVERRIDE {
781 NOTREACHED(); 785 NOTREACHED();
782 return ERR_DNS_CACHE_MISS; 786 return ERR_DNS_CACHE_MISS;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 resolver.CancelRequest(request1); 846 resolver.CancelRequest(request1);
843 resolver.CancelRequest(request2); 847 resolver.CancelRequest(request2);
844 848
845 EXPECT_EQ(2, host_resolver.num_cancelled_requests()); 849 EXPECT_EQ(2, host_resolver.num_cancelled_requests());
846 850
847 // After leaving this scope, the ProxyResolver is destroyed. 851 // After leaving this scope, the ProxyResolver is destroyed.
848 // This should not cause any problems, as the outstanding work 852 // This should not cause any problems, as the outstanding work
849 // should have been cancelled. 853 // should have been cancelled.
850 } 854 }
851 855
856 void CancelRequestAndPause(ProxyResolverV8Tracing* resolver,
857 ProxyResolver::RequestHandle request) {
858 resolver->CancelRequest(request);
859
860 // Sleep for a little bit. This makes it more likely for the worker
861 // thread to have returned from its call, and serves as a regression
862 // test for http://crbug.com/173373.
863 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(30));
864 }
865
852 // In non-blocking mode, the worker thread actually does block for 866 // In non-blocking mode, the worker thread actually does block for
853 // a short time to see if the result is in the DNS cache. Test 867 // a short time to see if the result is in the DNS cache. Test
854 // cancellation while the worker thread is waiting on this event. 868 // cancellation while the worker thread is waiting on this event.
855 TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns) { 869 TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns) {
mmenke 2013/01/31 21:11:23 Hmm...The purpose of this test was to cancel befor
eroman 2013/01/31 21:29:49 I think the test works as is (it is testing two im
856 BlockableHostResolver host_resolver; 870 BlockableHostResolver host_resolver;
857 MockErrorObserver* error_observer = new MockErrorObserver; 871 MockErrorObserver* error_observer = new MockErrorObserver;
858 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL); 872 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL);
859 873
860 InitResolver(&resolver, "dns.js"); 874 InitResolver(&resolver, "dns.js");
861 875
862 ProxyInfo proxy_info; 876 ProxyInfo proxy_info;
863 ProxyResolver::RequestHandle request; 877 ProxyResolver::RequestHandle request;
864 878
865 int rv = resolver.GetProxyForURL( 879 int rv = resolver.GetProxyForURL(
866 GURL("http://foo/"), &proxy_info, 880 GURL("http://foo/"), &proxy_info,
867 base::Bind(&CrashCallback), &request, BoundNetLog()); 881 base::Bind(&CrashCallback), &request, BoundNetLog());
868 882
869 EXPECT_EQ(ERR_IO_PENDING, rv); 883 EXPECT_EQ(ERR_IO_PENDING, rv);
870 884
871 host_resolver.SetAction(base::Bind(&ProxyResolverV8Tracing::CancelRequest, 885 host_resolver.SetAction(
872 base::Unretained(&resolver), request)); 886 base::Bind(CancelRequestAndPause, &resolver, request));
873 887
874 host_resolver.WaitUntilRequestIsReceived(); 888 host_resolver.WaitUntilRequestIsReceived();
875 889
876 // At this point the host resolver ran Resolve(), and should have cancelled 890 // At this point the host resolver ran Resolve(), and should have cancelled
877 // the request. 891 // the request.
878 892
879 EXPECT_EQ(1, host_resolver.num_cancelled_requests()); 893 EXPECT_EQ(1, host_resolver.num_cancelled_requests());
880 } 894 }
881 895
882 // Cancel the request while there is a pending DNS request, however before 896 // Cancel the request while there is a pending DNS request, however before
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 933
920 host_resolver.WaitUntilRequestIsReceived(); 934 host_resolver.WaitUntilRequestIsReceived();
921 935
922 resolver.CancelSetPacScript(); 936 resolver.CancelSetPacScript();
923 EXPECT_EQ(1, host_resolver.num_cancelled_requests()); 937 EXPECT_EQ(1, host_resolver.num_cancelled_requests());
924 } 938 }
925 939
926 } // namespace 940 } // namespace
927 941
928 } // namespace net 942 } // namespace net
OLDNEW
« net/proxy/proxy_resolver_v8_tracing.cc ('K') | « net/proxy/proxy_resolver_v8_tracing.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698