OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/network_delegate_error_observer.h" | 5 #include "net/proxy/network_delegate_error_observer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
12 #include "net/base/network_delegate.h" | 12 #include "net/base/network_delegate.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace net { | 15 namespace net { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 class TestNetworkDelegate : public net::NetworkDelegate { | 19 class TestNetworkDelegate : public net::NetworkDelegate { |
20 public: | 20 public: |
21 TestNetworkDelegate() : got_pac_error_(false) {} | 21 TestNetworkDelegate() : got_pac_error_(false) {} |
22 virtual ~TestNetworkDelegate() {} | 22 virtual ~TestNetworkDelegate() {} |
23 | 23 |
24 bool got_pac_error() const { return got_pac_error_; } | 24 bool got_pac_error() const { return got_pac_error_; } |
25 | 25 |
26 private: | 26 private: |
27 // net::NetworkDelegate implementation. | 27 // net::NetworkDelegate implementation. |
28 virtual int OnBeforeURLRequest(URLRequest* request, | 28 virtual int OnBeforeURLRequest(URLRequest* request, |
29 const CompletionCallback& callback, | 29 const CompletionCallback& callback, |
30 GURL* new_url) OVERRIDE { | 30 GURL* new_url) override { |
31 return OK; | 31 return OK; |
32 } | 32 } |
33 virtual int OnBeforeSendHeaders(URLRequest* request, | 33 virtual int OnBeforeSendHeaders(URLRequest* request, |
34 const CompletionCallback& callback, | 34 const CompletionCallback& callback, |
35 HttpRequestHeaders* headers) OVERRIDE { | 35 HttpRequestHeaders* headers) override { |
36 return OK; | 36 return OK; |
37 } | 37 } |
38 virtual void OnSendHeaders(URLRequest* request, | 38 virtual void OnSendHeaders(URLRequest* request, |
39 const HttpRequestHeaders& headers) OVERRIDE {} | 39 const HttpRequestHeaders& headers) override {} |
40 virtual int OnHeadersReceived( | 40 virtual int OnHeadersReceived( |
41 URLRequest* request, | 41 URLRequest* request, |
42 const CompletionCallback& callback, | 42 const CompletionCallback& callback, |
43 const HttpResponseHeaders* original_response_headers, | 43 const HttpResponseHeaders* original_response_headers, |
44 scoped_refptr<HttpResponseHeaders>* override_response_headers, | 44 scoped_refptr<HttpResponseHeaders>* override_response_headers, |
45 GURL* allowed_unsafe_redirect_url) OVERRIDE { | 45 GURL* allowed_unsafe_redirect_url) override { |
46 return net::OK; | 46 return net::OK; |
47 } | 47 } |
48 virtual void OnBeforeRedirect(URLRequest* request, | 48 virtual void OnBeforeRedirect(URLRequest* request, |
49 const GURL& new_location) OVERRIDE {} | 49 const GURL& new_location) override {} |
50 virtual void OnResponseStarted(URLRequest* request) OVERRIDE {} | 50 virtual void OnResponseStarted(URLRequest* request) override {} |
51 virtual void OnRawBytesRead(const URLRequest& request, | 51 virtual void OnRawBytesRead(const URLRequest& request, |
52 int bytes_read) OVERRIDE {} | 52 int bytes_read) override {} |
53 virtual void OnCompleted(URLRequest* request, bool started) OVERRIDE {} | 53 virtual void OnCompleted(URLRequest* request, bool started) override {} |
54 virtual void OnURLRequestDestroyed(URLRequest* request) OVERRIDE {} | 54 virtual void OnURLRequestDestroyed(URLRequest* request) override {} |
55 | 55 |
56 virtual void OnPACScriptError(int line_number, | 56 virtual void OnPACScriptError(int line_number, |
57 const base::string16& error) OVERRIDE { | 57 const base::string16& error) override { |
58 got_pac_error_ = true; | 58 got_pac_error_ = true; |
59 } | 59 } |
60 virtual AuthRequiredResponse OnAuthRequired( | 60 virtual AuthRequiredResponse OnAuthRequired( |
61 URLRequest* request, | 61 URLRequest* request, |
62 const AuthChallengeInfo& auth_info, | 62 const AuthChallengeInfo& auth_info, |
63 const AuthCallback& callback, | 63 const AuthCallback& callback, |
64 AuthCredentials* credentials) OVERRIDE { | 64 AuthCredentials* credentials) override { |
65 return AUTH_REQUIRED_RESPONSE_NO_ACTION; | 65 return AUTH_REQUIRED_RESPONSE_NO_ACTION; |
66 } | 66 } |
67 virtual bool OnCanGetCookies(const URLRequest& request, | 67 virtual bool OnCanGetCookies(const URLRequest& request, |
68 const CookieList& cookie_list) OVERRIDE { | 68 const CookieList& cookie_list) override { |
69 return true; | 69 return true; |
70 } | 70 } |
71 virtual bool OnCanSetCookie(const URLRequest& request, | 71 virtual bool OnCanSetCookie(const URLRequest& request, |
72 const std::string& cookie_line, | 72 const std::string& cookie_line, |
73 CookieOptions* options) OVERRIDE { | 73 CookieOptions* options) override { |
74 return true; | 74 return true; |
75 } | 75 } |
76 virtual bool OnCanAccessFile(const net::URLRequest& request, | 76 virtual bool OnCanAccessFile(const net::URLRequest& request, |
77 const base::FilePath& path) const OVERRIDE { | 77 const base::FilePath& path) const override { |
78 return true; | 78 return true; |
79 } | 79 } |
80 virtual bool OnCanThrottleRequest(const URLRequest& request) const OVERRIDE { | 80 virtual bool OnCanThrottleRequest(const URLRequest& request) const override { |
81 return false; | 81 return false; |
82 } | 82 } |
83 virtual int OnBeforeSocketStreamConnect( | 83 virtual int OnBeforeSocketStreamConnect( |
84 SocketStream* stream, | 84 SocketStream* stream, |
85 const CompletionCallback& callback) OVERRIDE { | 85 const CompletionCallback& callback) override { |
86 return OK; | 86 return OK; |
87 } | 87 } |
88 | 88 |
89 bool got_pac_error_; | 89 bool got_pac_error_; |
90 }; | 90 }; |
91 | 91 |
92 } // namespace | 92 } // namespace |
93 | 93 |
94 // Check that the OnPACScriptError method can be called from an arbitrary | 94 // Check that the OnPACScriptError method can be called from an arbitrary |
95 // thread. | 95 // thread. |
(...skipping 25 matching lines...) Expand all Loading... |
121 base::Bind(&NetworkDelegateErrorObserver::OnPACScriptError, | 121 base::Bind(&NetworkDelegateErrorObserver::OnPACScriptError, |
122 base::Unretained(&observer), | 122 base::Unretained(&observer), |
123 42, | 123 42, |
124 base::string16())); | 124 base::string16())); |
125 thread.Stop(); | 125 thread.Stop(); |
126 base::MessageLoop::current()->RunUntilIdle(); | 126 base::MessageLoop::current()->RunUntilIdle(); |
127 // Shouldn't have crashed until here... | 127 // Shouldn't have crashed until here... |
128 } | 128 } |
129 | 129 |
130 } // namespace net | 130 } // namespace net |
OLD | NEW |