| OLD | NEW |
| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "remoting/base/auto_thread_task_runner.h" | 9 #include "remoting/base/auto_thread_task_runner.h" |
| 10 #include "remoting/host/client_session_control.h" |
| 11 #include "remoting/host/host_mock_objects.h" |
| 10 #include "remoting/host/local_input_monitor.h" | 12 #include "remoting/host/local_input_monitor.h" |
| 11 #include "remoting/host/mouse_move_observer.h" | 13 #include "remoting/protocol/protocol_mock_objects.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "third_party/skia/include/core/SkPoint.h" | 16 #include "third_party/skia/include/core/SkPoint.h" |
| 15 | 17 |
| 16 namespace remoting { | 18 namespace remoting { |
| 17 | 19 |
| 18 using testing::_; | 20 using testing::_; |
| 19 using testing::AnyNumber; | 21 using testing::AnyNumber; |
| 22 using testing::ReturnRef; |
| 20 | 23 |
| 21 namespace { | 24 namespace { |
| 22 | 25 |
| 23 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
| 24 const MessageLoop::Type kDesiredMessageLoopType = MessageLoop::TYPE_UI; | 27 const MessageLoop::Type kDesiredMessageLoopType = MessageLoop::TYPE_UI; |
| 25 #else // !defined(OS_WIN) | 28 #else // !defined(OS_WIN) |
| 26 const MessageLoop::Type kDesiredMessageLoopType = MessageLoop::TYPE_IO; | 29 const MessageLoop::Type kDesiredMessageLoopType = MessageLoop::TYPE_IO; |
| 27 #endif // !defined(OS_WIN) | 30 #endif // !defined(OS_WIN) |
| 28 | 31 |
| 29 class FakeMouseMoveObserver : public MouseMoveObserver { | |
| 30 public: | |
| 31 FakeMouseMoveObserver() {} | |
| 32 virtual ~FakeMouseMoveObserver() {} | |
| 33 | |
| 34 // Ignore mouse events to avoid breaking the test of someone moves the mouse. | |
| 35 virtual void OnLocalMouseMoved(const SkIPoint&) OVERRIDE {} | |
| 36 void OnDisconnectCallback() {} | |
| 37 }; | |
| 38 | |
| 39 } // namespace | 32 } // namespace |
| 40 | 33 |
| 41 class LocalInputMonitorTest : public testing::Test { | 34 class LocalInputMonitorTest : public testing::Test { |
| 42 public: | 35 public: |
| 43 LocalInputMonitorTest() : message_loop_(kDesiredMessageLoopType) { | 36 LocalInputMonitorTest(); |
| 44 } | |
| 45 | 37 |
| 46 virtual void SetUp() OVERRIDE { | 38 virtual void SetUp() OVERRIDE; |
| 47 // Arrange to run |message_loop_| until no components depend on it. | |
| 48 task_runner_ = new AutoThreadTaskRunner( | |
| 49 message_loop_.message_loop_proxy(), run_loop_.QuitClosure()); | |
| 50 } | |
| 51 | 39 |
| 52 MessageLoop message_loop_; | 40 MessageLoop message_loop_; |
| 53 base::RunLoop run_loop_; | 41 base::RunLoop run_loop_; |
| 54 scoped_refptr<AutoThreadTaskRunner> task_runner_; | 42 scoped_refptr<AutoThreadTaskRunner> task_runner_; |
| 55 | 43 |
| 56 FakeMouseMoveObserver mouse_move_observer_; | 44 std::string client_jid_; |
| 45 MockClientSessionControl client_session_control_; |
| 46 base::WeakPtrFactory<ClientSessionControl> client_session_control_factory_; |
| 57 }; | 47 }; |
| 58 | 48 |
| 49 LocalInputMonitorTest::LocalInputMonitorTest() |
| 50 : message_loop_(kDesiredMessageLoopType), |
| 51 client_jid_("user@domain/rest-of-jid"), |
| 52 client_session_control_factory_(&client_session_control_) { |
| 53 } |
| 54 |
| 55 void LocalInputMonitorTest::SetUp() { |
| 56 // Arrange to run |message_loop_| until no components depend on it. |
| 57 task_runner_ = new AutoThreadTaskRunner( |
| 58 message_loop_.message_loop_proxy(), run_loop_.QuitClosure()); |
| 59 } |
| 60 |
| 61 |
| 59 // This test is really to exercise only the creation and destruction code in | 62 // This test is really to exercise only the creation and destruction code in |
| 60 // LocalInputMonitor. | 63 // LocalInputMonitor. |
| 61 TEST_F(LocalInputMonitorTest, Basic) { | 64 TEST_F(LocalInputMonitorTest, Basic) { |
| 65 // Ignore all callbacks. |
| 66 EXPECT_CALL(client_session_control_, client_jid()) |
| 67 .Times(AnyNumber()) |
| 68 .WillRepeatedly(ReturnRef(client_jid_)); |
| 69 EXPECT_CALL(client_session_control_, DisconnectSession()) |
| 70 .Times(AnyNumber()); |
| 71 EXPECT_CALL(client_session_control_, OnLocalMouseMoved(_)) |
| 72 .Times(AnyNumber()); |
| 73 EXPECT_CALL(client_session_control_, SetDisableInputs(_)) |
| 74 .Times(0); |
| 75 |
| 62 { | 76 { |
| 63 scoped_ptr<LocalInputMonitor> local_input_monitor = | 77 scoped_ptr<LocalInputMonitor> local_input_monitor = |
| 64 LocalInputMonitor::Create(task_runner_, task_runner_, task_runner_); | 78 LocalInputMonitor::Create(task_runner_, |
| 79 task_runner_, |
| 80 task_runner_, |
| 81 client_session_control_factory_.GetWeakPtr()); |
| 65 task_runner_ = NULL; | 82 task_runner_ = NULL; |
| 66 | |
| 67 local_input_monitor->Start( | |
| 68 &mouse_move_observer_, | |
| 69 base::Bind(&FakeMouseMoveObserver::OnDisconnectCallback, | |
| 70 base::Unretained(&mouse_move_observer_))); | |
| 71 local_input_monitor->Stop(); | |
| 72 } | 83 } |
| 73 | 84 |
| 74 run_loop_.Run(); | 85 run_loop_.Run(); |
| 75 } | 86 } |
| 76 | 87 |
| 77 } // namespace remoting | 88 } // namespace remoting |
| OLD | NEW |