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

Side by Side Diff: net/socket_stream/socket_stream_unittest.cc

Issue 3040016: Net: Convert username and password to string16. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: address comments Created 10 years, 4 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
« no previous file with comments | « net/socket_stream/socket_stream_job.h ('k') | net/spdy/spdy_network_transaction.h » ('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) 2009 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "net/base/mock_host_resolver.h" 9 #include "net/base/mock_host_resolver.h"
10 #include "net/base/net_log.h" 10 #include "net/base/net_log.h"
11 #include "net/base/net_log_unittest.h" 11 #include "net/base/net_log_unittest.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } 112 }
113 113
114 void DoClose(SocketStreamEvent* event) { 114 void DoClose(SocketStreamEvent* event) {
115 event->socket->Close(); 115 event->socket->Close();
116 } 116 }
117 void DoRestartWithAuth(SocketStreamEvent* event) { 117 void DoRestartWithAuth(SocketStreamEvent* event) {
118 LOG(INFO) << "RestartWithAuth username=" << username_ 118 LOG(INFO) << "RestartWithAuth username=" << username_
119 << " password=" << password_; 119 << " password=" << password_;
120 event->socket->RestartWithAuth(username_, password_); 120 event->socket->RestartWithAuth(username_, password_);
121 } 121 }
122 void SetAuthInfo(const std::wstring& username, 122 void SetAuthInfo(const string16& username,
123 const std::wstring& password) { 123 const string16& password) {
124 username_ = username; 124 username_ = username;
125 password_ = password; 125 password_ = password;
126 } 126 }
127 127
128 const std::vector<SocketStreamEvent>& GetSeenEvents() const { 128 const std::vector<SocketStreamEvent>& GetSeenEvents() const {
129 return events_; 129 return events_;
130 } 130 }
131 131
132 private: 132 private:
133 std::vector<SocketStreamEvent> events_; 133 std::vector<SocketStreamEvent> events_;
134 Callback1<SocketStreamEvent*>::Type* on_connected_; 134 Callback1<SocketStreamEvent*>::Type* on_connected_;
135 Callback1<SocketStreamEvent*>::Type* on_sent_data_; 135 Callback1<SocketStreamEvent*>::Type* on_sent_data_;
136 Callback1<SocketStreamEvent*>::Type* on_received_data_; 136 Callback1<SocketStreamEvent*>::Type* on_received_data_;
137 Callback1<SocketStreamEvent*>::Type* on_close_; 137 Callback1<SocketStreamEvent*>::Type* on_close_;
138 Callback1<SocketStreamEvent*>::Type* on_auth_required_; 138 Callback1<SocketStreamEvent*>::Type* on_auth_required_;
139 net::CompletionCallback* callback_; 139 net::CompletionCallback* callback_;
140 140
141 std::wstring username_; 141 string16 username_;
142 std::wstring password_; 142 string16 password_;
143 143
144 DISALLOW_COPY_AND_ASSIGN(SocketStreamEventRecorder); 144 DISALLOW_COPY_AND_ASSIGN(SocketStreamEventRecorder);
145 }; 145 };
146 146
147 namespace net { 147 namespace net {
148 148
149 class SocketStreamTest : public PlatformTest { 149 class SocketStreamTest : public PlatformTest {
150 public: 150 public:
151 virtual ~SocketStreamTest() {} 151 virtual ~SocketStreamTest() {}
152 virtual void SetUp() { 152 virtual void SetUp() {
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), 311 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
312 data_writes2, arraysize(data_writes2)); 312 data_writes2, arraysize(data_writes2));
313 mock_socket_factory.AddSocketDataProvider(&data2); 313 mock_socket_factory.AddSocketDataProvider(&data2);
314 314
315 TestCompletionCallback callback; 315 TestCompletionCallback callback;
316 316
317 scoped_ptr<SocketStreamEventRecorder> delegate( 317 scoped_ptr<SocketStreamEventRecorder> delegate(
318 new SocketStreamEventRecorder(&callback)); 318 new SocketStreamEventRecorder(&callback));
319 delegate->SetOnConnected(NewCallback(delegate.get(), 319 delegate->SetOnConnected(NewCallback(delegate.get(),
320 &SocketStreamEventRecorder::DoClose)); 320 &SocketStreamEventRecorder::DoClose));
321 const std::wstring kUsername = L"foo"; 321 delegate->SetAuthInfo(ASCIIToUTF16("foo"), ASCIIToUTF16("bar"));
322 const std::wstring kPassword = L"bar";
323 delegate->SetAuthInfo(kUsername, kPassword);
324 delegate->SetOnAuthRequired( 322 delegate->SetOnAuthRequired(
325 NewCallback(delegate.get(), 323 NewCallback(delegate.get(),
326 &SocketStreamEventRecorder::DoRestartWithAuth)); 324 &SocketStreamEventRecorder::DoRestartWithAuth));
327 325
328 scoped_refptr<SocketStream> socket_stream = 326 scoped_refptr<SocketStream> socket_stream =
329 new SocketStream(GURL("ws://example.com/demo"), delegate.get()); 327 new SocketStream(GURL("ws://example.com/demo"), delegate.get());
330 328
331 socket_stream->set_context(new TestURLRequestContext("myproxy:70")); 329 socket_stream->set_context(new TestURLRequestContext("myproxy:70"));
332 socket_stream->SetHostResolver(new MockHostResolver()); 330 socket_stream->SetHostResolver(new MockHostResolver());
333 socket_stream->SetClientSocketFactory(&mock_socket_factory); 331 socket_stream->SetClientSocketFactory(&mock_socket_factory);
334 332
335 socket_stream->Connect(); 333 socket_stream->Connect();
336 334
337 callback.WaitForResult(); 335 callback.WaitForResult();
338 336
339 const std::vector<SocketStreamEvent>& events = delegate->GetSeenEvents(); 337 const std::vector<SocketStreamEvent>& events = delegate->GetSeenEvents();
340 EXPECT_EQ(3U, events.size()); 338 EXPECT_EQ(3U, events.size());
341 339
342 EXPECT_EQ(SocketStreamEvent::EVENT_AUTH_REQUIRED, events[0].event_type); 340 EXPECT_EQ(SocketStreamEvent::EVENT_AUTH_REQUIRED, events[0].event_type);
343 EXPECT_EQ(SocketStreamEvent::EVENT_CONNECTED, events[1].event_type); 341 EXPECT_EQ(SocketStreamEvent::EVENT_CONNECTED, events[1].event_type);
344 EXPECT_EQ(SocketStreamEvent::EVENT_CLOSE, events[2].event_type); 342 EXPECT_EQ(SocketStreamEvent::EVENT_CLOSE, events[2].event_type);
345 343
346 // TODO(eroman): Add back NetLogTest here... 344 // TODO(eroman): Add back NetLogTest here...
347 } 345 }
348 346
349 } // namespace net 347 } // namespace net
OLDNEW
« no previous file with comments | « net/socket_stream/socket_stream_job.h ('k') | net/spdy/spdy_network_transaction.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698