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

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

Issue 138753005: Add gnubby authentication to remoting host (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Another Windows warning Created 6 years, 10 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
« no previous file with comments | « remoting/host/client_session.cc ('k') | remoting/host/desktop_environment.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) 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 "base/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "base/test/test_simple_task_runner.h"
6 #include "remoting/base/auto_thread_task_runner.h" 7 #include "remoting/base/auto_thread_task_runner.h"
7 #include "remoting/base/constants.h" 8 #include "remoting/base/constants.h"
8 #include "remoting/host/audio_capturer.h" 9 #include "remoting/host/audio_capturer.h"
9 #include "remoting/host/client_session.h" 10 #include "remoting/host/client_session.h"
10 #include "remoting/host/desktop_environment.h" 11 #include "remoting/host/desktop_environment.h"
11 #include "remoting/host/host_mock_objects.h" 12 #include "remoting/host/host_mock_objects.h"
12 #include "remoting/host/screen_capturer_fake.h" 13 #include "remoting/host/screen_capturer_fake.h"
13 #include "remoting/protocol/protocol_mock_objects.h" 14 #include "remoting/protocol/protocol_mock_objects.h"
15 #include "testing/gmock/include/gmock/gmock-matchers.h"
14 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" 17 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
16 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" 18 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h"
17 #include "third_party/webrtc/modules/desktop_capture/screen_capturer_mock_object s.h" 19 #include "third_party/webrtc/modules/desktop_capture/screen_capturer_mock_object s.h"
18 20
19 namespace remoting { 21 namespace remoting {
20 22
21 using protocol::MockConnectionToClient; 23 using protocol::MockConnectionToClient;
22 using protocol::MockClientStub; 24 using protocol::MockClientStub;
23 using protocol::MockHostStub; 25 using protocol::MockHostStub;
24 using protocol::MockInputStub; 26 using protocol::MockInputStub;
25 using protocol::MockSession; 27 using protocol::MockSession;
26 using protocol::MockVideoStub; 28 using protocol::MockVideoStub;
27 using protocol::SessionConfig; 29 using protocol::SessionConfig;
28 30
29 using testing::_; 31 using testing::_;
30 using testing::AnyNumber; 32 using testing::AnyNumber;
31 using testing::AtMost; 33 using testing::AtMost;
32 using testing::DeleteArg; 34 using testing::DeleteArg;
33 using testing::DoAll; 35 using testing::DoAll;
34 using testing::Expectation; 36 using testing::Expectation;
35 using testing::Return; 37 using testing::Return;
36 using testing::ReturnRef; 38 using testing::ReturnRef;
37 using testing::Sequence; 39 using testing::Sequence;
40 using testing::StrEq;
41 using testing::StrictMock;
38 42
39 namespace { 43 namespace {
40 44
41 ACTION_P2(InjectClipboardEvent, connection, event) { 45 ACTION_P2(InjectClipboardEvent, connection, event) {
42 connection->clipboard_stub()->InjectClipboardEvent(event); 46 connection->clipboard_stub()->InjectClipboardEvent(event);
43 } 47 }
44 48
45 ACTION_P2(InjectKeyEvent, connection, event) { 49 ACTION_P2(InjectKeyEvent, connection, event) {
46 connection->input_stub()->InjectKeyEvent(event); 50 connection->input_stub()->InjectKeyEvent(event);
47 } 51 }
48 52
49 ACTION_P2(InjectMouseEvent, connection, event) { 53 ACTION_P2(InjectMouseEvent, connection, event) {
50 connection->input_stub()->InjectMouseEvent(event); 54 connection->input_stub()->InjectMouseEvent(event);
51 } 55 }
52 56
53 ACTION_P2(LocalMouseMoved, client_session, event) { 57 ACTION_P2(LocalMouseMoved, client_session, event) {
54 client_session->OnLocalMouseMoved( 58 client_session->OnLocalMouseMoved(
55 webrtc::DesktopVector(event.x(), event.y())); 59 webrtc::DesktopVector(event.x(), event.y()));
56 } 60 }
57 61
58 } // namespace 62 ACTION_P2(SetGnubbyAuthHandlerForTesting, client_session, gnubby_auth_handler) {
63 client_session->SetGnubbyAuthHandlerForTesting(gnubby_auth_handler);
64 }
65
66 ACTION_P2(DeliverClientMessage, client_session, message) {
67 client_session->DeliverClientMessage(message);
68 }
69
70 }
59 71
60 class ClientSessionTest : public testing::Test { 72 class ClientSessionTest : public testing::Test {
61 public: 73 public:
62 ClientSessionTest() : client_jid_("user@domain/rest-of-jid") {} 74 ClientSessionTest() : client_jid_("user@domain/rest-of-jid") {}
63 75
64 virtual void SetUp() OVERRIDE; 76 virtual void SetUp() OVERRIDE;
65 virtual void TearDown() OVERRIDE; 77 virtual void TearDown() OVERRIDE;
66 78
67 // Disconnects the client session. 79 // Disconnects the client session.
68 void DisconnectClientSession(); 80 void DisconnectClientSession();
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 } 299 }
288 300
289 MATCHER_P2(EqualsMouseEvent, x, y, "") { 301 MATCHER_P2(EqualsMouseEvent, x, y, "") {
290 return arg.x() == x && arg.y() == y; 302 return arg.x() == x && arg.y() == y;
291 } 303 }
292 304
293 MATCHER_P2(EqualsMouseButtonEvent, button, down, "") { 305 MATCHER_P2(EqualsMouseButtonEvent, button, down, "") {
294 return arg.button() == button && arg.button_down() == down; 306 return arg.button() == button && arg.button_down() == down;
295 } 307 }
296 308
297 } 309 } // namespace
298 310
299 TEST_F(ClientSessionTest, InputStubFilter) { 311 TEST_F(ClientSessionTest, InputStubFilter) {
300 protocol::KeyEvent key_event1; 312 protocol::KeyEvent key_event1;
301 key_event1.set_pressed(true); 313 key_event1.set_pressed(true);
302 key_event1.set_usb_keycode(1); 314 key_event1.set_usb_keycode(1);
303 315
304 protocol::KeyEvent key_event2_down; 316 protocol::KeyEvent key_event2_down;
305 key_event2_down.set_pressed(true); 317 key_event2_down.set_pressed(true);
306 key_event2_down.set_usb_keycode(2); 318 key_event2_down.set_usb_keycode(2);
307 319
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 expected_event.y()))) 544 expected_event.y())))
533 .After(connected) 545 .After(connected)
534 .WillOnce(DoAll( 546 .WillOnce(DoAll(
535 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession), 547 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
536 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession))); 548 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
537 549
538 ConnectClientSession(); 550 ConnectClientSession();
539 message_loop_.Run(); 551 message_loop_.Run();
540 } 552 }
541 553
554 TEST_F(ClientSessionTest, NoGnubbyAuth) {
555 protocol::ExtensionMessage message;
556 message.set_type("gnubby-auth");
557 message.set_data("test");
558
559 Expectation authenticated =
560 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_))
561 .WillOnce(Return(true));
562 EXPECT_CALL(*input_injector_, StartPtr(_)).After(authenticated);
563 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_))
564 .After(authenticated)
565 .WillOnce(DoAll(
566 DeliverClientMessage(client_session_.get(), message),
567 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
568 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
569 EXPECT_CALL(session_event_handler_, OnSessionClosed(_));
570
571 ConnectClientSession();
572 message_loop_.Run();
573 }
574
575 TEST_F(ClientSessionTest, EnableGnubbyAuth) {
576 // Lifetime controlled by object under test.
577 MockGnubbyAuthHandler* gnubby_auth_handler = new MockGnubbyAuthHandler();
578
579 protocol::ExtensionMessage message;
580 message.set_type("gnubby-auth");
581 message.set_data("test");
582
583 Expectation authenticated =
584 EXPECT_CALL(session_event_handler_, OnSessionAuthenticated(_))
585 .WillOnce(Return(true));
586 EXPECT_CALL(*input_injector_, StartPtr(_)).After(authenticated);
587 EXPECT_CALL(session_event_handler_, OnSessionChannelsConnected(_))
588 .After(authenticated)
589 .WillOnce(DoAll(
590 SetGnubbyAuthHandlerForTesting(client_session_.get(),
591 gnubby_auth_handler),
592 DeliverClientMessage(client_session_.get(), message),
593 InvokeWithoutArgs(this, &ClientSessionTest::DisconnectClientSession),
594 InvokeWithoutArgs(this, &ClientSessionTest::StopClientSession)));
595 EXPECT_CALL(*gnubby_auth_handler, DeliverClientMessage(_));
596 EXPECT_CALL(session_event_handler_, OnSessionClosed(_));
597
598 ConnectClientSession();
599 message_loop_.Run();
600 }
601
542 } // namespace remoting 602 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/client_session.cc ('k') | remoting/host/desktop_environment.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698