| 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" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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. |
| 96 TEST(NetworkDelegateErrorObserverTest, CallOnThread) { | 96 TEST(NetworkDelegateErrorObserverTest, CallOnThread) { |
| 97 base::Thread thread("test_thread"); | 97 base::Thread thread("test_thread"); |
| 98 thread.Start(); | 98 thread.Start(); |
| 99 TestNetworkDelegate network_delegate; | 99 TestNetworkDelegate network_delegate; |
| 100 NetworkDelegateErrorObserver observer( | 100 NetworkDelegateErrorObserver observer( |
| 101 &network_delegate, base::MessageLoopProxy::current().get()); | 101 &network_delegate, base::MessageLoopProxy::current().get()); |
| 102 thread.message_loop() | 102 thread.message_loop()->PostTask( |
| 103 ->PostTask(FROM_HERE, | 103 FROM_HERE, |
| 104 base::Bind(&NetworkDelegateErrorObserver::OnPACScriptError, | 104 base::Bind(&NetworkDelegateErrorObserver::OnPACScriptError, |
| 105 base::Unretained(&observer), | 105 base::Unretained(&observer), |
| 106 42, | 106 42, |
| 107 base::string16())); | 107 base::string16())); |
| 108 thread.Stop(); | 108 thread.Stop(); |
| 109 base::MessageLoop::current()->RunUntilIdle(); | 109 base::MessageLoop::current()->RunUntilIdle(); |
| 110 ASSERT_TRUE(network_delegate.got_pac_error()); | 110 ASSERT_TRUE(network_delegate.got_pac_error()); |
| 111 } | 111 } |
| 112 | 112 |
| 113 // Check that passing a NULL network delegate works. | 113 // Check that passing a NULL network delegate works. |
| 114 TEST(NetworkDelegateErrorObserverTest, NoDelegate) { | 114 TEST(NetworkDelegateErrorObserverTest, NoDelegate) { |
| 115 base::Thread thread("test_thread"); | 115 base::Thread thread("test_thread"); |
| 116 thread.Start(); | 116 thread.Start(); |
| 117 NetworkDelegateErrorObserver observer( | 117 NetworkDelegateErrorObserver observer( |
| 118 NULL, base::MessageLoopProxy::current().get()); | 118 NULL, base::MessageLoopProxy::current().get()); |
| 119 thread.message_loop() | 119 thread.message_loop()->PostTask( |
| 120 ->PostTask(FROM_HERE, | 120 FROM_HERE, |
| 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 |