| 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" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 } // namespace | 58 } // namespace |
| 59 | 59 |
| 60 // Check that the OnPACScriptError method can be called from an arbitrary | 60 // Check that the OnPACScriptError method can be called from an arbitrary |
| 61 // thread. | 61 // thread. |
| 62 TEST(NetworkDelegateErrorObserverTest, CallOnThread) { | 62 TEST(NetworkDelegateErrorObserverTest, CallOnThread) { |
| 63 base::Thread thread("test_thread"); | 63 base::Thread thread("test_thread"); |
| 64 thread.Start(); | 64 thread.Start(); |
| 65 TestNetworkDelegate network_delegate; | 65 TestNetworkDelegate network_delegate; |
| 66 NetworkDelegateErrorObserver | 66 NetworkDelegateErrorObserver |
| 67 observer(&network_delegate, | 67 observer(&network_delegate, |
| 68 base::MessageLoopProxy::CreateForCurrentThread()); | 68 base::MessageLoopProxy::current()); |
| 69 thread.message_loop()->PostTask( | 69 thread.message_loop()->PostTask( |
| 70 FROM_HERE, | 70 FROM_HERE, |
| 71 NewRunnableMethod(&observer, | 71 NewRunnableMethod(&observer, |
| 72 &NetworkDelegateErrorObserver::OnPACScriptError, | 72 &NetworkDelegateErrorObserver::OnPACScriptError, |
| 73 42, string16())); | 73 42, string16())); |
| 74 thread.Stop(); | 74 thread.Stop(); |
| 75 MessageLoop::current()->RunAllPending(); | 75 MessageLoop::current()->RunAllPending(); |
| 76 ASSERT_TRUE(network_delegate.got_pac_error()); | 76 ASSERT_TRUE(network_delegate.got_pac_error()); |
| 77 } | 77 } |
| 78 | 78 |
| 79 // Check that passing a NULL network delegate works. | 79 // Check that passing a NULL network delegate works. |
| 80 TEST(NetworkDelegateErrorObserverTest, NoDelegate) { | 80 TEST(NetworkDelegateErrorObserverTest, NoDelegate) { |
| 81 base::Thread thread("test_thread"); | 81 base::Thread thread("test_thread"); |
| 82 thread.Start(); | 82 thread.Start(); |
| 83 NetworkDelegateErrorObserver | 83 NetworkDelegateErrorObserver |
| 84 observer(NULL, base::MessageLoopProxy::CreateForCurrentThread()); | 84 observer(NULL, base::MessageLoopProxy::current()); |
| 85 thread.message_loop()->PostTask( | 85 thread.message_loop()->PostTask( |
| 86 FROM_HERE, | 86 FROM_HERE, |
| 87 NewRunnableMethod(&observer, | 87 NewRunnableMethod(&observer, |
| 88 &NetworkDelegateErrorObserver::OnPACScriptError, | 88 &NetworkDelegateErrorObserver::OnPACScriptError, |
| 89 42, string16())); | 89 42, string16())); |
| 90 thread.Stop(); | 90 thread.Stop(); |
| 91 MessageLoop::current()->RunAllPending(); | 91 MessageLoop::current()->RunAllPending(); |
| 92 // Shouldn't have crashed until here... | 92 // Shouldn't have crashed until here... |
| 93 } | 93 } |
| 94 | 94 |
| 95 } // namespace net | 95 } // namespace net |
| OLD | NEW |