| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/socket/tls_socket.h" | |
| 6 | |
| 7 #include <stddef.h> | 5 #include <stddef.h> |
| 8 #include <stdint.h> | 6 #include <stdint.h> |
| 9 | 7 |
| 10 #include <deque> | 8 #include <deque> |
| 9 #include <memory> |
| 11 #include <utility> | 10 #include <utility> |
| 12 | 11 |
| 13 #include "base/macros.h" | 12 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
| 14 #include "extensions/browser/api/socket/tls_socket.h" |
| 16 #include "net/base/address_list.h" | 15 #include "net/base/address_list.h" |
| 17 #include "net/base/completion_callback.h" | 16 #include "net/base/completion_callback.h" |
| 18 #include "net/base/io_buffer.h" | 17 #include "net/base/io_buffer.h" |
| 19 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
| 20 #include "net/base/rand_callback.h" | 19 #include "net/base/rand_callback.h" |
| 21 #include "net/socket/ssl_client_socket.h" | 20 #include "net/socket/ssl_client_socket.h" |
| 22 #include "net/socket/tcp_client_socket.h" | 21 #include "net/socket/tcp_client_socket.h" |
| 23 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 24 | 23 |
| 25 using testing::_; | 24 using testing::_; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 }; | 117 }; |
| 119 | 118 |
| 120 class TLSSocketTest : public ::testing::Test { | 119 class TLSSocketTest : public ::testing::Test { |
| 121 public: | 120 public: |
| 122 TLSSocketTest() {} | 121 TLSSocketTest() {} |
| 123 | 122 |
| 124 void SetUp() override { | 123 void SetUp() override { |
| 125 net::AddressList address_list; | 124 net::AddressList address_list; |
| 126 // |ssl_socket_| is owned by |socket_|. TLSSocketTest keeps a pointer to | 125 // |ssl_socket_| is owned by |socket_|. TLSSocketTest keeps a pointer to |
| 127 // it to expect invocations from TLSSocket to |ssl_socket_|. | 126 // it to expect invocations from TLSSocket to |ssl_socket_|. |
| 128 scoped_ptr<MockSSLClientSocket> ssl_sock(new MockSSLClientSocket); | 127 std::unique_ptr<MockSSLClientSocket> ssl_sock(new MockSSLClientSocket); |
| 129 ssl_socket_ = ssl_sock.get(); | 128 ssl_socket_ = ssl_sock.get(); |
| 130 socket_.reset(new TLSSocket(std::move(ssl_sock), "test_extension_id")); | 129 socket_.reset(new TLSSocket(std::move(ssl_sock), "test_extension_id")); |
| 131 EXPECT_CALL(*ssl_socket_, Disconnect()).Times(1); | 130 EXPECT_CALL(*ssl_socket_, Disconnect()).Times(1); |
| 132 }; | 131 }; |
| 133 | 132 |
| 134 void TearDown() override { | 133 void TearDown() override { |
| 135 ssl_socket_ = NULL; | 134 ssl_socket_ = NULL; |
| 136 socket_.reset(); | 135 socket_.reset(); |
| 137 }; | 136 }; |
| 138 | 137 |
| 139 protected: | 138 protected: |
| 140 MockSSLClientSocket* ssl_socket_; | 139 MockSSLClientSocket* ssl_socket_; |
| 141 scoped_ptr<TLSSocket> socket_; | 140 std::unique_ptr<TLSSocket> socket_; |
| 142 }; | 141 }; |
| 143 | 142 |
| 144 // Verify that a Read() on TLSSocket will pass through into a Read() on | 143 // Verify that a Read() on TLSSocket will pass through into a Read() on |
| 145 // |ssl_socket_| and invoke its completion callback. | 144 // |ssl_socket_| and invoke its completion callback. |
| 146 TEST_F(TLSSocketTest, TestTLSSocketRead) { | 145 TEST_F(TLSSocketTest, TestTLSSocketRead) { |
| 147 CompleteHandler handler; | 146 CompleteHandler handler; |
| 148 | 147 |
| 149 EXPECT_CALL(*ssl_socket_, Read(_, _, _)).Times(1); | 148 EXPECT_CALL(*ssl_socket_, Read(_, _, _)).Times(1); |
| 150 EXPECT_CALL(handler, OnReadComplete(_, _)).Times(1); | 149 EXPECT_CALL(handler, OnReadComplete(_, _)).Times(1); |
| 151 | 150 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 total_bytes_written += amount_written_invocation; | 314 total_bytes_written += amount_written_invocation; |
| 316 cb.first.Run(amount_written_invocation); | 315 cb.first.Run(amount_written_invocation); |
| 317 } | 316 } |
| 318 | 317 |
| 319 ASSERT_EQ(total_bytes_requested, total_bytes_written) | 318 ASSERT_EQ(total_bytes_requested, total_bytes_written) |
| 320 << "There should be exactly as many bytes written as originally " | 319 << "There should be exactly as many bytes written as originally " |
| 321 << "requested to Write()."; | 320 << "requested to Write()."; |
| 322 } | 321 } |
| 323 | 322 |
| 324 } // namespace extensions | 323 } // namespace extensions |
| OLD | NEW |