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