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