| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/message_loop_proxy.h" | 7 #include "base/message_loop_proxy.h" |
| 8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 #include "net/base/network_delegate.h" | 10 #include "net/base/network_delegate.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 DISABLE_RUNNABLE_METHOD_REFCOUNT(net::NetworkDelegateErrorObserver); | 13 DISABLE_RUNNABLE_METHOD_REFCOUNT(net::NetworkDelegateErrorObserver); |
| 14 | 14 |
| 15 namespace net { | 15 namespace net { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 |
| 18 class TestNetworkDelegate : public net::NetworkDelegate { | 19 class TestNetworkDelegate : public net::NetworkDelegate { |
| 19 public: | 20 public: |
| 20 TestNetworkDelegate() : got_pac_error_(false) {} | 21 TestNetworkDelegate() : got_pac_error_(false) {} |
| 21 virtual ~TestNetworkDelegate() {} | 22 virtual ~TestNetworkDelegate() {} |
| 22 | 23 |
| 23 bool got_pac_error() const { return got_pac_error_; } | 24 bool got_pac_error() const { return got_pac_error_; } |
| 24 | 25 |
| 25 private: | 26 private: |
| 26 // net::NetworkDelegate: | 27 // net::NetworkDelegate: |
| 27 virtual int OnBeforeURLRequest(URLRequest* request, | 28 virtual int OnBeforeURLRequest(URLRequest* request, |
| 28 CompletionCallback* callback, | 29 CompletionCallback* callback, |
| 29 GURL* new_url) { | 30 GURL* new_url) { |
| 30 return net::OK; | 31 return net::OK; |
| 31 } | 32 } |
| 32 virtual int OnBeforeSendHeaders(uint64 request_id, | 33 virtual int OnBeforeSendHeaders(uint64 request_id, |
| 33 CompletionCallback* callback, | 34 CompletionCallback* callback, |
| 34 HttpRequestHeaders* headers) { | 35 HttpRequestHeaders* headers) { |
| 35 return net::OK; | 36 return net::OK; |
| 36 } | 37 } |
| 37 virtual void OnRequestSent(uint64 request_id, | 38 virtual void OnRequestSent(uint64 request_id, |
| 38 const HostPortPair& socket_address, | 39 const HostPortPair& socket_address, |
| 39 const HttpRequestHeaders& headers) {} | 40 const HttpRequestHeaders& headers) {} |
| 40 virtual void OnBeforeRedirect(URLRequest* request, | 41 virtual void OnBeforeRedirect(URLRequest* request, |
| 41 const GURL& new_location) {} | 42 const GURL& new_location) {} |
| 42 virtual void OnResponseStarted(URLRequest* request) {} | 43 virtual void OnResponseStarted(URLRequest* request) {} |
| 44 virtual void OnRawBytesRead(const URLRequest& request, |
| 45 int bytes_read) {} |
| 43 virtual void OnCompleted(URLRequest* request) {} | 46 virtual void OnCompleted(URLRequest* request) {} |
| 44 virtual void OnURLRequestDestroyed(URLRequest* request) {} | 47 virtual void OnURLRequestDestroyed(URLRequest* request) {} |
| 45 virtual void OnHttpTransactionDestroyed(uint64 request_id) {} | 48 virtual void OnHttpTransactionDestroyed(uint64 request_id) {} |
| 46 virtual URLRequestJob* OnMaybeCreateURLRequestJob(URLRequest* request) { | 49 virtual URLRequestJob* OnMaybeCreateURLRequestJob(URLRequest* request) { |
| 47 return NULL; | 50 return NULL; |
| 48 } | 51 } |
| 49 virtual void OnPACScriptError(int line_number, const string16& error) { | 52 virtual void OnPACScriptError(int line_number, |
| 53 const string16& error) { |
| 50 got_pac_error_ = true; | 54 got_pac_error_ = true; |
| 51 } | 55 } |
| 52 | 56 |
| 53 bool got_pac_error_; | 57 bool got_pac_error_; |
| 54 }; | 58 }; |
| 55 | 59 |
| 56 } // namespace | 60 } // namespace |
| 57 | 61 |
| 58 // Check that the OnPACScriptError method can be called from an arbitrary | 62 // Check that the OnPACScriptError method can be called from an arbitrary |
| 59 // thread. | 63 // thread. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 84 FROM_HERE, | 88 FROM_HERE, |
| 85 NewRunnableMethod(&observer, | 89 NewRunnableMethod(&observer, |
| 86 &NetworkDelegateErrorObserver::OnPACScriptError, | 90 &NetworkDelegateErrorObserver::OnPACScriptError, |
| 87 42, string16())); | 91 42, string16())); |
| 88 thread.Stop(); | 92 thread.Stop(); |
| 89 MessageLoop::current()->RunAllPending(); | 93 MessageLoop::current()->RunAllPending(); |
| 90 // Shouldn't have crashed until here... | 94 // Shouldn't have crashed until here... |
| 91 } | 95 } |
| 92 | 96 |
| 93 } // namespace net | 97 } // namespace net |
| OLD | NEW |