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

Side by Side Diff: remoting/host/client_session_unittest.cc

Issue 6780014: Clean up remoting project (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: got rid of ref counting on user authenticator Created 9 years, 8 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 | « remoting/host/client_session.cc ('k') | remoting/host/curtain_linux.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/bind.h"
6 #include "remoting/host/client_session.h" 5 #include "remoting/host/client_session.h"
7 #include "remoting/host/host_mock_objects.h" 6 #include "remoting/host/host_mock_objects.h"
8 #include "remoting/host/user_authenticator_fake.h"
9 #include "remoting/protocol/protocol_mock_objects.h" 7 #include "remoting/protocol/protocol_mock_objects.h"
10 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
11 9
12 namespace remoting { 10 namespace remoting {
13 11
14 namespace { 12 namespace {
15 13
16 UserAuthenticator* MakeUserAuthenticator() {
17 return new UserAuthenticatorFake();
18 }
19
20 // A task that does nothing. 14 // A task that does nothing.
21 class DummyTask : public Task { 15 class DummyTask : public Task {
22 public: 16 public:
23 void Run() {} 17 void Run() {}
24 }; 18 };
25 19
26 } // namespace 20 } // namespace
27 21
28 using protocol::MockConnectionToClient; 22 using protocol::MockConnectionToClient;
29 using protocol::MockConnectionToClientEventHandler; 23 using protocol::MockConnectionToClientEventHandler;
30 using protocol::MockHostStub; 24 using protocol::MockHostStub;
31 using protocol::MockInputStub; 25 using protocol::MockInputStub;
32 26
33 using testing::_; 27 using testing::_;
34 using testing::DeleteArg; 28 using testing::DeleteArg;
35 using testing::InSequence; 29 using testing::InSequence;
30 using testing::Return;
36 31
37 class ClientSessionTest : public testing::Test { 32 class ClientSessionTest : public testing::Test {
38 public: 33 public:
39 ClientSessionTest() { 34 ClientSessionTest() {}
40 }
41 35
42 virtual void SetUp() { 36 virtual void SetUp() {
43 connection_ = new MockConnectionToClient(&message_loop_, 37 connection_ = new MockConnectionToClient(&message_loop_,
44 &connection_event_handler_, 38 &connection_event_handler_,
45 &host_stub_, 39 &host_stub_,
46 &input_stub_); 40 &input_stub_);
47 client_session_ = new ClientSession(&session_event_handler_, 41 user_authenticator_ = new MockUserAuthenticator();
48 base::Bind(MakeUserAuthenticator), 42 client_session_ = new ClientSession(
49 connection_, 43 &session_event_handler_,
50 &input_stub_); 44 user_authenticator_,
51 credentials_.set_type(protocol::PASSWORD); 45 connection_,
52 credentials_.set_username("user"); 46 &input_stub_);
53 credentials_.set_credential("password");
54 47
55 ON_CALL(input_stub_, InjectKeyEvent(_, _)).WillByDefault(DeleteArg<1>()); 48 ON_CALL(input_stub_, InjectKeyEvent(_, _)).WillByDefault(DeleteArg<1>());
56 ON_CALL(input_stub_, InjectMouseEvent(_, _)).WillByDefault(DeleteArg<1>()); 49 ON_CALL(input_stub_, InjectMouseEvent(_, _)).WillByDefault(DeleteArg<1>());
57 } 50 }
58 51
59 virtual void TearDown() {
60 }
61
62 protected: 52 protected:
63 MessageLoop message_loop_; 53 MessageLoop message_loop_;
64 MockConnectionToClientEventHandler connection_event_handler_; 54 MockConnectionToClientEventHandler connection_event_handler_;
65 MockHostStub host_stub_; 55 MockHostStub host_stub_;
66 MockInputStub input_stub_; 56 MockInputStub input_stub_;
67 MockClientSessionEventHandler session_event_handler_; 57 MockClientSessionEventHandler session_event_handler_;
58 MockUserAuthenticator* user_authenticator_;
68 scoped_refptr<MockConnectionToClient> connection_; 59 scoped_refptr<MockConnectionToClient> connection_;
69 scoped_refptr<ClientSession> client_session_; 60 scoped_refptr<ClientSession> client_session_;
70 protocol::LocalLoginCredentials credentials_;
71 }; 61 };
72 62
73 TEST_F(ClientSessionTest, InputStubFilter) { 63 TEST_F(ClientSessionTest, InputStubFilter) {
74 protocol::KeyEvent key_event1; 64 protocol::KeyEvent key_event1;
75 key_event1.set_pressed(true); 65 key_event1.set_pressed(true);
76 key_event1.set_keycode(1); 66 key_event1.set_keycode(1);
77 67
78 protocol::KeyEvent key_event2; 68 protocol::KeyEvent key_event2;
79 key_event2.set_pressed(true); 69 key_event2.set_pressed(true);
80 key_event2.set_keycode(2); 70 key_event2.set_keycode(2);
81 71
82 protocol::KeyEvent key_event3; 72 protocol::KeyEvent key_event3;
83 key_event3.set_pressed(true); 73 key_event3.set_pressed(true);
84 key_event3.set_keycode(3); 74 key_event3.set_keycode(3);
85 75
86 protocol::MouseEvent mouse_event1; 76 protocol::MouseEvent mouse_event1;
87 mouse_event1.set_x(100); 77 mouse_event1.set_x(100);
88 mouse_event1.set_y(101); 78 mouse_event1.set_y(101);
89 79
90 protocol::MouseEvent mouse_event2; 80 protocol::MouseEvent mouse_event2;
91 mouse_event2.set_x(200); 81 mouse_event2.set_x(200);
92 mouse_event2.set_y(201); 82 mouse_event2.set_y(201);
93 83
94 protocol::MouseEvent mouse_event3; 84 protocol::MouseEvent mouse_event3;
95 mouse_event3.set_x(300); 85 mouse_event3.set_x(300);
96 mouse_event3.set_y(301); 86 mouse_event3.set_y(301);
97 87
98 credentials_.set_type(protocol::PASSWORD); 88 protocol::LocalLoginCredentials credentials;
99 credentials_.set_username("user"); 89 credentials.set_type(protocol::PASSWORD);
100 credentials_.set_credential("password"); 90 credentials.set_username("user");
91 credentials.set_credential("password");
101 92
102 InSequence s; 93 InSequence s;
94 EXPECT_CALL(*user_authenticator_, Authenticate(_, _))
95 .WillOnce(Return(true));
103 EXPECT_CALL(session_event_handler_, LocalLoginSucceeded(_)); 96 EXPECT_CALL(session_event_handler_, LocalLoginSucceeded(_));
104 EXPECT_CALL(input_stub_, InjectKeyEvent(&key_event2, _)); 97 EXPECT_CALL(input_stub_, InjectKeyEvent(&key_event2, _));
105 EXPECT_CALL(input_stub_, InjectMouseEvent(&mouse_event2, _)); 98 EXPECT_CALL(input_stub_, InjectMouseEvent(&mouse_event2, _));
106 EXPECT_CALL(*connection_.get(), Disconnect()); 99 EXPECT_CALL(*connection_.get(), Disconnect());
107 100
108 // These events should not get through to the input stub, 101 // These events should not get through to the input stub,
109 // because the client isn't authenticated yet. 102 // because the client isn't authenticated yet.
110 client_session_->InjectKeyEvent(&key_event1, new DummyTask()); 103 client_session_->InjectKeyEvent(&key_event1, new DummyTask());
111 client_session_->InjectMouseEvent(&mouse_event1, new DummyTask()); 104 client_session_->InjectMouseEvent(&mouse_event1, new DummyTask());
112 client_session_->BeginSessionRequest(&credentials_, new DummyTask()); 105 client_session_->BeginSessionRequest(&credentials, new DummyTask());
113 // These events should get through to the input stub. 106 // These events should get through to the input stub.
114 client_session_->InjectKeyEvent(&key_event2, new DummyTask()); 107 client_session_->InjectKeyEvent(&key_event2, new DummyTask());
115 client_session_->InjectMouseEvent(&mouse_event2, new DummyTask()); 108 client_session_->InjectMouseEvent(&mouse_event2, new DummyTask());
116 client_session_->Disconnect(); 109 client_session_->Disconnect();
117 // These events should not get through to the input stub, 110 // These events should not get through to the input stub,
118 // because the client has disconnected. 111 // because the client has disconnected.
119 client_session_->InjectKeyEvent(&key_event3, new DummyTask()); 112 client_session_->InjectKeyEvent(&key_event3, new DummyTask());
120 client_session_->InjectMouseEvent(&mouse_event3, new DummyTask()); 113 client_session_->InjectMouseEvent(&mouse_event3, new DummyTask());
121 } 114 }
122 115
123 } // namespace remoting 116 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/client_session.cc ('k') | remoting/host/curtain_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698