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 }; | 92 }; |
93 | 93 |
94 } // namespace | 94 } // namespace |
95 | 95 |
96 // Check that the OnPACScriptError method can be called from an arbitrary | 96 // Check that the OnPACScriptError method can be called from an arbitrary |
97 // thread. | 97 // thread. |
98 TEST(NetworkDelegateErrorObserverTest, CallOnThread) { | 98 TEST(NetworkDelegateErrorObserverTest, CallOnThread) { |
99 base::Thread thread("test_thread"); | 99 base::Thread thread("test_thread"); |
100 thread.Start(); | 100 thread.Start(); |
101 TestNetworkDelegate network_delegate; | 101 TestNetworkDelegate network_delegate; |
102 NetworkDelegateErrorObserver | 102 NetworkDelegateErrorObserver observer( |
103 observer(&network_delegate, | 103 &network_delegate, base::MessageLoopProxy::current().get()); |
104 base::MessageLoopProxy::current()); | 104 thread.message_loop() |
105 thread.message_loop()->PostTask( | 105 ->PostTask(FROM_HERE, |
106 FROM_HERE, | 106 base::Bind(&NetworkDelegateErrorObserver::OnPACScriptError, |
107 base::Bind(&NetworkDelegateErrorObserver::OnPACScriptError, | 107 base::Unretained(&observer), |
108 base::Unretained(&observer), 42, base::string16())); | 108 42, |
| 109 base::string16())); |
109 thread.Stop(); | 110 thread.Stop(); |
110 base::MessageLoop::current()->RunUntilIdle(); | 111 base::MessageLoop::current()->RunUntilIdle(); |
111 ASSERT_TRUE(network_delegate.got_pac_error()); | 112 ASSERT_TRUE(network_delegate.got_pac_error()); |
112 } | 113 } |
113 | 114 |
114 // Check that passing a NULL network delegate works. | 115 // Check that passing a NULL network delegate works. |
115 TEST(NetworkDelegateErrorObserverTest, NoDelegate) { | 116 TEST(NetworkDelegateErrorObserverTest, NoDelegate) { |
116 base::Thread thread("test_thread"); | 117 base::Thread thread("test_thread"); |
117 thread.Start(); | 118 thread.Start(); |
118 NetworkDelegateErrorObserver | 119 NetworkDelegateErrorObserver observer( |
119 observer(NULL, base::MessageLoopProxy::current()); | 120 NULL, base::MessageLoopProxy::current().get()); |
120 thread.message_loop()->PostTask( | 121 thread.message_loop() |
121 FROM_HERE, | 122 ->PostTask(FROM_HERE, |
122 base::Bind(&NetworkDelegateErrorObserver::OnPACScriptError, | 123 base::Bind(&NetworkDelegateErrorObserver::OnPACScriptError, |
123 base::Unretained(&observer), 42, base::string16())); | 124 base::Unretained(&observer), |
| 125 42, |
| 126 base::string16())); |
124 thread.Stop(); | 127 thread.Stop(); |
125 base::MessageLoop::current()->RunUntilIdle(); | 128 base::MessageLoop::current()->RunUntilIdle(); |
126 // Shouldn't have crashed until here... | 129 // Shouldn't have crashed until here... |
127 } | 130 } |
128 | 131 |
129 } // namespace net | 132 } // namespace net |
OLD | NEW |