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

Side by Side Diff: remoting/jingle_glue/channel_socket_adapter_unittest.cc

Issue 4192012: Convert implicit scoped_refptr constructor calls to explicit ones, part 1 (Closed) Base URL: http://git.chromium.org/git/chromium.git
Patch Set: fix presubmit Created 10 years, 1 month 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
« no previous file with comments | « remoting/host/simple_host_process.cc ('k') | remoting/jingle_glue/ssl_socket_adapter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/message_loop.h" 5 #include "base/message_loop.h"
6 #include "base/ref_counted.h" 6 #include "base/ref_counted.h"
7 #include "base/scoped_ptr.h" 7 #include "base/scoped_ptr.h"
8 #include "net/base/io_buffer.h" 8 #include "net/base/io_buffer.h"
9 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 #include "net/socket/socket.h" 10 #include "net/socket/socket.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 MockTransportChannel channel_; 58 MockTransportChannel channel_;
59 scoped_ptr<TransportChannelSocketAdapter> target_; 59 scoped_ptr<TransportChannelSocketAdapter> target_;
60 net::CompletionCallbackImpl<TransportChannelSocketAdapterTest> callback_; 60 net::CompletionCallbackImpl<TransportChannelSocketAdapterTest> callback_;
61 int callback_result_; 61 int callback_result_;
62 MessageLoopForIO message_loop_; 62 MessageLoopForIO message_loop_;
63 }; 63 };
64 64
65 // Verify that Read() returns net::ERR_IO_PENDING. 65 // Verify that Read() returns net::ERR_IO_PENDING.
66 TEST_F(TransportChannelSocketAdapterTest, Read) { 66 TEST_F(TransportChannelSocketAdapterTest, Read) {
67 scoped_refptr<IOBuffer> buffer = new IOBuffer(kBufferSize); 67 scoped_refptr<IOBuffer> buffer(new IOBuffer(kBufferSize));
68 68
69 int result = target_->Read(buffer, kBufferSize, &callback_); 69 int result = target_->Read(buffer, kBufferSize, &callback_);
70 ASSERT_EQ(net::ERR_IO_PENDING, result); 70 ASSERT_EQ(net::ERR_IO_PENDING, result);
71 71
72 channel_.SignalReadPacket(&channel_, kTestData, kTestDataSize); 72 channel_.SignalReadPacket(&channel_, kTestData, kTestDataSize);
73 EXPECT_EQ(kTestDataSize, callback_result_); 73 EXPECT_EQ(kTestDataSize, callback_result_);
74 } 74 }
75 75
76 // Verify that Read() after Close() returns error. 76 // Verify that Read() after Close() returns error.
77 TEST_F(TransportChannelSocketAdapterTest, ReadClose) { 77 TEST_F(TransportChannelSocketAdapterTest, ReadClose) {
78 scoped_refptr<IOBuffer> buffer = new IOBuffer(kBufferSize); 78 scoped_refptr<IOBuffer> buffer(new IOBuffer(kBufferSize));
79 79
80 int result = target_->Read(buffer, kBufferSize, &callback_); 80 int result = target_->Read(buffer, kBufferSize, &callback_);
81 ASSERT_EQ(net::ERR_IO_PENDING, result); 81 ASSERT_EQ(net::ERR_IO_PENDING, result);
82 82
83 target_->Close(kTestError); 83 target_->Close(kTestError);
84 EXPECT_EQ(kTestError, callback_result_); 84 EXPECT_EQ(kTestError, callback_result_);
85 85
86 // All Read() calls after Close() should return the error. 86 // All Read() calls after Close() should return the error.
87 EXPECT_EQ(kTestError, target_->Read(buffer, kBufferSize, &callback_)); 87 EXPECT_EQ(kTestError, target_->Read(buffer, kBufferSize, &callback_));
88 } 88 }
89 89
90 // Verify that Write sends the packet and returns correct result. 90 // Verify that Write sends the packet and returns correct result.
91 TEST_F(TransportChannelSocketAdapterTest, Write) { 91 TEST_F(TransportChannelSocketAdapterTest, Write) {
92 scoped_refptr<IOBuffer> buffer = new IOBuffer(kTestDataSize); 92 scoped_refptr<IOBuffer> buffer(new IOBuffer(kTestDataSize));
93 93
94 EXPECT_CALL(channel_, SendPacket(buffer->data(), kTestDataSize)) 94 EXPECT_CALL(channel_, SendPacket(buffer->data(), kTestDataSize))
95 .WillOnce(Return(kTestDataSize)); 95 .WillOnce(Return(kTestDataSize));
96 96
97 int result = target_->Write(buffer, kTestDataSize, &callback_); 97 int result = target_->Write(buffer, kTestDataSize, &callback_);
98 EXPECT_EQ(kTestDataSize, result); 98 EXPECT_EQ(kTestDataSize, result);
99 } 99 }
100 100
101 // Verify that the message is still send if Write() is called while 101 // Verify that the message is still send if Write() is called while
102 // socket is not open yet, and that the callback is called. 102 // socket is not open yet, and that the callback is called.
103 TEST_F(TransportChannelSocketAdapterTest, WritePending) { 103 TEST_F(TransportChannelSocketAdapterTest, WritePending) {
104 scoped_refptr<IOBuffer> buffer = new IOBuffer(kTestDataSize); 104 scoped_refptr<IOBuffer> buffer(new IOBuffer(kTestDataSize));
105 105
106 EXPECT_CALL(channel_, SendPacket(buffer->data(), kTestDataSize)) 106 EXPECT_CALL(channel_, SendPacket(buffer->data(), kTestDataSize))
107 .Times(2) 107 .Times(2)
108 .WillOnce(Return(SOCKET_ERROR)) 108 .WillOnce(Return(SOCKET_ERROR))
109 .WillOnce(Return(kTestDataSize)); 109 .WillOnce(Return(kTestDataSize));
110 110
111 EXPECT_CALL(channel_, GetError()) 111 EXPECT_CALL(channel_, GetError())
112 .WillOnce(Return(EWOULDBLOCK)); 112 .WillOnce(Return(EWOULDBLOCK));
113 113
114 int result = target_->Write(buffer, kTestDataSize, &callback_); 114 int result = target_->Write(buffer, kTestDataSize, &callback_);
115 ASSERT_EQ(net::ERR_IO_PENDING, result); 115 ASSERT_EQ(net::ERR_IO_PENDING, result);
116 116
117 channel_.SignalWritableState(&channel_); 117 channel_.SignalWritableState(&channel_);
118 EXPECT_EQ(kTestDataSize, callback_result_); 118 EXPECT_EQ(kTestDataSize, callback_result_);
119 } 119 }
120 120
121 } // namespace remoting 121 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/simple_host_process.cc ('k') | remoting/jingle_glue/ssl_socket_adapter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698