| 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/local_input_monitor.h" | 10 #include "remoting/host/local_input_monitor.h" |
| 11 #include "remoting/host/mouse_move_observer.h" | |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "third_party/skia/include/core/SkPoint.h" | 13 #include "third_party/skia/include/core/SkPoint.h" |
| 15 | 14 |
| 16 namespace remoting { | 15 namespace remoting { |
| 17 | 16 |
| 18 using testing::_; | 17 using testing::_; |
| 19 using testing::AnyNumber; | 18 using testing::AnyNumber; |
| 20 | 19 |
| 21 namespace { | 20 namespace { |
| 22 | 21 |
| 23 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
| 24 const MessageLoop::Type kDesiredMessageLoopType = MessageLoop::TYPE_UI; | 23 const MessageLoop::Type kDesiredMessageLoopType = MessageLoop::TYPE_UI; |
| 25 #else // !defined(OS_WIN) | 24 #else // !defined(OS_WIN) |
| 26 const MessageLoop::Type kDesiredMessageLoopType = MessageLoop::TYPE_IO; | 25 const MessageLoop::Type kDesiredMessageLoopType = MessageLoop::TYPE_IO; |
| 27 #endif // !defined(OS_WIN) | 26 #endif // !defined(OS_WIN) |
| 28 | 27 |
| 29 class FakeMouseMoveObserver : public MouseMoveObserver { | 28 class FakeDelegate : public SessionController::Delegate { |
| 30 public: | 29 public: |
| 31 FakeMouseMoveObserver() {} | 30 FakeDelegate() {} |
| 32 virtual ~FakeMouseMoveObserver() {} | 31 virtual ~FakeDelegate() {} |
| 33 | 32 |
| 34 // Ignore mouse events to avoid breaking the test of someone moves the mouse. | 33 // Ignore all callbacks. |
| 35 virtual void OnLocalMouseMoved(const SkIPoint&) OVERRIDE {} | 34 virtual void DisconnectSession() OVERRIDE {} |
| 36 void OnDisconnectCallback() {} | 35 virtual void OnLocalMouseMoved(const SkIPoint& position) OVERRIDE {} |
| 37 }; | 36 }; |
| 38 | 37 |
| 39 } // namespace | 38 } // namespace |
| 40 | 39 |
| 41 class LocalInputMonitorTest : public testing::Test { | 40 class LocalInputMonitorTest : public testing::Test { |
| 42 public: | 41 public: |
| 43 LocalInputMonitorTest() : message_loop_(kDesiredMessageLoopType) { | 42 LocalInputMonitorTest() : message_loop_(kDesiredMessageLoopType) { |
| 44 } | 43 } |
| 45 | 44 |
| 46 virtual void SetUp() OVERRIDE { | 45 virtual void SetUp() OVERRIDE { |
| 47 // Arrange to run |message_loop_| until no components depend on it. | 46 // Arrange to run |message_loop_| until no components depend on it. |
| 48 task_runner_ = new AutoThreadTaskRunner( | 47 task_runner_ = new AutoThreadTaskRunner( |
| 49 message_loop_.message_loop_proxy(), run_loop_.QuitClosure()); | 48 message_loop_.message_loop_proxy(), run_loop_.QuitClosure()); |
| 50 } | 49 } |
| 51 | 50 |
| 52 MessageLoop message_loop_; | 51 MessageLoop message_loop_; |
| 53 base::RunLoop run_loop_; | 52 base::RunLoop run_loop_; |
| 54 scoped_refptr<AutoThreadTaskRunner> task_runner_; | 53 scoped_refptr<AutoThreadTaskRunner> task_runner_; |
| 55 | 54 |
| 56 FakeMouseMoveObserver mouse_move_observer_; | 55 FakeDelegate fake_delegate_; |
| 57 }; | 56 }; |
| 58 | 57 |
| 59 // This test is really to exercise only the creation and destruction code in | 58 // This test is really to exercise only the creation and destruction code in |
| 60 // LocalInputMonitor. | 59 // LocalInputMonitor. |
| 61 TEST_F(LocalInputMonitorTest, Basic) { | 60 TEST_F(LocalInputMonitorTest, Basic) { |
| 62 { | 61 { |
| 63 scoped_ptr<LocalInputMonitor> local_input_monitor = | 62 scoped_ptr<LocalInputMonitor> local_input_monitor = |
| 64 LocalInputMonitor::Create(task_runner_, task_runner_, task_runner_); | 63 LocalInputMonitor::Create(task_runner_, task_runner_, task_runner_, |
| 64 &fake_delegate_); |
| 65 task_runner_ = NULL; | 65 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 } | 66 } |
| 73 | 67 |
| 74 run_loop_.Run(); | 68 run_loop_.Run(); |
| 75 } | 69 } |
| 76 | 70 |
| 77 } // namespace remoting | 71 } // namespace remoting |
| OLD | NEW |