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/bind.h" |
7 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
8 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
9 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
10 #include "net/base/network_delegate.h" | 11 #include "net/base/network_delegate.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
12 | 13 |
13 DISABLE_RUNNABLE_METHOD_REFCOUNT(net::NetworkDelegateErrorObserver); | 14 DISABLE_RUNNABLE_METHOD_REFCOUNT(net::NetworkDelegateErrorObserver); |
14 | 15 |
15 namespace net { | 16 namespace net { |
16 | 17 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 // thread. | 74 // thread. |
74 TEST(NetworkDelegateErrorObserverTest, CallOnThread) { | 75 TEST(NetworkDelegateErrorObserverTest, CallOnThread) { |
75 base::Thread thread("test_thread"); | 76 base::Thread thread("test_thread"); |
76 thread.Start(); | 77 thread.Start(); |
77 TestNetworkDelegate network_delegate; | 78 TestNetworkDelegate network_delegate; |
78 NetworkDelegateErrorObserver | 79 NetworkDelegateErrorObserver |
79 observer(&network_delegate, | 80 observer(&network_delegate, |
80 base::MessageLoopProxy::current()); | 81 base::MessageLoopProxy::current()); |
81 thread.message_loop()->PostTask( | 82 thread.message_loop()->PostTask( |
82 FROM_HERE, | 83 FROM_HERE, |
83 NewRunnableMethod(&observer, | 84 base::Bind(&NetworkDelegateErrorObserver::OnPACScriptError, &observer, 42, |
84 &NetworkDelegateErrorObserver::OnPACScriptError, | 85 string16())); |
85 42, string16())); | |
86 thread.Stop(); | 86 thread.Stop(); |
87 MessageLoop::current()->RunAllPending(); | 87 MessageLoop::current()->RunAllPending(); |
88 ASSERT_TRUE(network_delegate.got_pac_error()); | 88 ASSERT_TRUE(network_delegate.got_pac_error()); |
89 } | 89 } |
90 | 90 |
91 // Check that passing a NULL network delegate works. | 91 // Check that passing a NULL network delegate works. |
92 TEST(NetworkDelegateErrorObserverTest, NoDelegate) { | 92 TEST(NetworkDelegateErrorObserverTest, NoDelegate) { |
93 base::Thread thread("test_thread"); | 93 base::Thread thread("test_thread"); |
94 thread.Start(); | 94 thread.Start(); |
95 NetworkDelegateErrorObserver | 95 NetworkDelegateErrorObserver |
96 observer(NULL, base::MessageLoopProxy::current()); | 96 observer(NULL, base::MessageLoopProxy::current()); |
97 thread.message_loop()->PostTask( | 97 thread.message_loop()->PostTask( |
98 FROM_HERE, | 98 FROM_HERE, |
99 NewRunnableMethod(&observer, | 99 base::Bind(&NetworkDelegateErrorObserver::OnPACScriptError, &observer, 42, |
100 &NetworkDelegateErrorObserver::OnPACScriptError, | 100 string16())); |
101 42, string16())); | |
102 thread.Stop(); | 101 thread.Stop(); |
103 MessageLoop::current()->RunAllPending(); | 102 MessageLoop::current()->RunAllPending(); |
104 // Shouldn't have crashed until here... | 103 // Shouldn't have crashed until here... |
105 } | 104 } |
106 | 105 |
107 } // namespace net | 106 } // namespace net |
OLD | NEW |