Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(838)

Side by Side Diff: net/socket/buffered_write_stream_socket_unittest.cc

Issue 10690104: DeterministicSocketDataProvider should not be RefCounted (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: One more leak fix Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/socket/buffered_write_stream_socket.h" 5 #include "net/socket/buffered_write_stream_socket.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
9 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
10 #include "net/base/net_log.h" 11 #include "net/base/net_log.h"
11 #include "net/socket/socket_test_util.h" 12 #include "net/socket/socket_test_util.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 namespace net { 15 namespace net {
15 16
16 namespace { 17 namespace {
17 18
18 class BufferedWriteStreamSocketTest : public testing::Test { 19 class BufferedWriteStreamSocketTest : public testing::Test {
19 public: 20 public:
20 void Finish() { 21 void Finish() {
21 MessageLoop::current()->RunAllPending(); 22 MessageLoop::current()->RunAllPending();
22 EXPECT_TRUE(data_->at_read_eof()); 23 EXPECT_TRUE(data_->at_read_eof());
23 EXPECT_TRUE(data_->at_write_eof()); 24 EXPECT_TRUE(data_->at_write_eof());
24 } 25 }
25 26
26 void Initialize(MockWrite* writes, size_t writes_count) { 27 void Initialize(MockWrite* writes, size_t writes_count) {
27 data_ = new DeterministicSocketData(NULL, 0, writes, writes_count); 28 data_.reset(new DeterministicSocketData(NULL, 0, writes, writes_count));
28 data_->set_connect_data(MockConnect(SYNCHRONOUS, 0)); 29 data_->set_connect_data(MockConnect(SYNCHRONOUS, 0));
29 if (writes_count) { 30 if (writes_count) {
30 data_->StopAfter(writes_count); 31 data_->StopAfter(writes_count);
31 } 32 }
32 DeterministicMockTCPClientSocket* wrapped_socket = 33 DeterministicMockTCPClientSocket* wrapped_socket =
33 new DeterministicMockTCPClientSocket(net_log_.net_log(), data_.get()); 34 new DeterministicMockTCPClientSocket(net_log_.net_log(), data_.get());
34 data_->set_socket(wrapped_socket->AsWeakPtr()); 35 data_->set_socket(wrapped_socket->AsWeakPtr());
35 socket_.reset(new BufferedWriteStreamSocket(wrapped_socket)); 36 socket_.reset(new BufferedWriteStreamSocket(wrapped_socket));
36 socket_->Connect(callback_.callback()); 37 socket_->Connect(callback_.callback());
37 } 38 }
38 39
39 void TestWrite(const char* text) { 40 void TestWrite(const char* text) {
40 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(text)); 41 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(text));
41 EXPECT_EQ(buf->size(), 42 EXPECT_EQ(buf->size(),
42 socket_->Write(buf.get(), buf->size(), callback_.callback())); 43 socket_->Write(buf.get(), buf->size(), callback_.callback()));
43 } 44 }
44 45
45 scoped_ptr<BufferedWriteStreamSocket> socket_; 46 scoped_ptr<BufferedWriteStreamSocket> socket_;
46 scoped_refptr<DeterministicSocketData> data_; 47 scoped_ptr<DeterministicSocketData> data_;
47 BoundNetLog net_log_; 48 BoundNetLog net_log_;
48 TestCompletionCallback callback_; 49 TestCompletionCallback callback_;
49 }; 50 };
50 51
51 TEST_F(BufferedWriteStreamSocketTest, SingleWrite) { 52 TEST_F(BufferedWriteStreamSocketTest, SingleWrite) {
52 MockWrite writes[] = { 53 MockWrite writes[] = {
53 MockWrite(SYNCHRONOUS, 0, "abc"), 54 MockWrite(SYNCHRONOUS, 0, "abc"),
54 }; 55 };
55 Initialize(writes, arraysize(writes)); 56 Initialize(writes, arraysize(writes));
56 TestWrite("abc"); 57 TestWrite("abc");
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 TestWrite("abc"); 114 TestWrite("abc");
114 data_->RunFor(1); 115 data_->RunFor(1);
115 TestWrite("def"); 116 TestWrite("def");
116 data_->RunFor(1); 117 data_->RunFor(1);
117 Finish(); 118 Finish();
118 } 119 }
119 120
120 } // anonymous namespace 121 } // anonymous namespace
121 122
122 } // namespace net 123 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_stream_parser_unittest.cc ('k') | net/socket/deterministic_socket_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698