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_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
103 observer(&network_delegate, | 103 observer(&network_delegate, |
104 base::MessageLoopProxy::current()); | 104 base::MessageLoopProxy::current().get()); |
105 thread.message_loop()->PostTask( | 105 thread.message_loop()->PostTask( |
106 FROM_HERE, | 106 FROM_HERE, |
107 base::Bind(&NetworkDelegateErrorObserver::OnPACScriptError, | 107 base::Bind(&NetworkDelegateErrorObserver::OnPACScriptError, |
108 base::Unretained(&observer), 42, string16())); | 108 base::Unretained(&observer), 42, string16())); |
109 thread.Stop(); | 109 thread.Stop(); |
110 MessageLoop::current()->RunAllPending(); | 110 MessageLoop::current()->RunAllPending(); |
111 ASSERT_TRUE(network_delegate.got_pac_error()); | 111 ASSERT_TRUE(network_delegate.got_pac_error()); |
112 } | 112 } |
113 | 113 |
114 // Check that passing a NULL network delegate works. | 114 // Check that passing a NULL network delegate works. |
115 TEST(NetworkDelegateErrorObserverTest, NoDelegate) { | 115 TEST(NetworkDelegateErrorObserverTest, NoDelegate) { |
116 base::Thread thread("test_thread"); | 116 base::Thread thread("test_thread"); |
117 thread.Start(); | 117 thread.Start(); |
118 NetworkDelegateErrorObserver | 118 NetworkDelegateErrorObserver |
119 observer(NULL, base::MessageLoopProxy::current()); | 119 observer(NULL, base::MessageLoopProxy::current().get()); |
120 thread.message_loop()->PostTask( | 120 thread.message_loop()->PostTask( |
121 FROM_HERE, | 121 FROM_HERE, |
122 base::Bind(&NetworkDelegateErrorObserver::OnPACScriptError, | 122 base::Bind(&NetworkDelegateErrorObserver::OnPACScriptError, |
123 base::Unretained(&observer), 42, string16())); | 123 base::Unretained(&observer), 42, string16())); |
124 thread.Stop(); | 124 thread.Stop(); |
125 MessageLoop::current()->RunAllPending(); | 125 MessageLoop::current()->RunAllPending(); |
126 // Shouldn't have crashed until here... | 126 // Shouldn't have crashed until here... |
127 } | 127 } |
128 | 128 |
129 } // namespace net | 129 } // namespace net |
OLD | NEW |