| 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 "chrome/browser/extensions/api/socket/tcp_socket.h" | 5 #include "chrome/browser/extensions/api/socket/tcp_socket.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "chrome/browser/extensions/api/api_resource_event_notifier.h" | 8 #include "chrome/browser/extensions/api/api_resource_event_notifier.h" |
| 9 #include "net/base/address_list.h" | 9 #include "net/base/address_list.h" |
| 10 #include "net/base/completion_callback.h" | 10 #include "net/base/completion_callback.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 class MockAPIResourceEventNotifier : public APIResourceEventNotifier { | 38 class MockAPIResourceEventNotifier : public APIResourceEventNotifier { |
| 39 public: | 39 public: |
| 40 MockAPIResourceEventNotifier() : APIResourceEventNotifier(NULL, NULL, | 40 MockAPIResourceEventNotifier() : APIResourceEventNotifier(NULL, NULL, |
| 41 std::string(), | 41 std::string(), |
| 42 0, GURL()) {} | 42 0, GURL()) {} |
| 43 | 43 |
| 44 MOCK_METHOD2(OnReadComplete, void(int result_code, | 44 MOCK_METHOD2(OnReadComplete, void(int result_code, |
| 45 const std::string& message)); | 45 const std::string& message)); |
| 46 MOCK_METHOD1(OnWriteComplete, void(int result_code)); | 46 MOCK_METHOD1(OnWriteComplete, void(int result_code)); |
| 47 |
| 48 protected: |
| 49 virtual ~MockAPIResourceEventNotifier() {} |
| 47 }; | 50 }; |
| 48 | 51 |
| 49 TEST(SocketTest, TestTCPSocketRead) { | 52 TEST(SocketTest, TestTCPSocketRead) { |
| 50 net::AddressList address_list; | 53 net::AddressList address_list; |
| 51 MockTCPSocket* tcp_client_socket = new MockTCPSocket(address_list); | 54 MockTCPSocket* tcp_client_socket = new MockTCPSocket(address_list); |
| 52 APIResourceEventNotifier* notifier = new MockAPIResourceEventNotifier(); | 55 APIResourceEventNotifier* notifier = new MockAPIResourceEventNotifier(); |
| 53 | 56 |
| 54 scoped_ptr<TCPSocket> socket(TCPSocket::CreateSocketForTesting( | 57 scoped_ptr<TCPSocket> socket(TCPSocket::CreateSocketForTesting( |
| 55 tcp_client_socket, "1.2.3.4", 1, notifier)); | 58 tcp_client_socket, "1.2.3.4", 1, notifier)); |
| 56 | 59 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 io_buffer->size())); | 101 io_buffer->size())); |
| 99 | 102 |
| 100 // Good. Original call came back unable to complete. Now pretend the socket | 103 // Good. Original call came back unable to complete. Now pretend the socket |
| 101 // finished, and confirm that we passed the error back. | 104 // finished, and confirm that we passed the error back. |
| 102 EXPECT_CALL(*notifier, OnWriteComplete(42)) | 105 EXPECT_CALL(*notifier, OnWriteComplete(42)) |
| 103 .Times(1); | 106 .Times(1); |
| 104 callback.Run(42); | 107 callback.Run(42); |
| 105 } | 108 } |
| 106 | 109 |
| 107 } // namespace extensions | 110 } // namespace extensions |
| OLD | NEW |