Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / test / remoting / me2me_browsertest.cc
1 // Copyright 2013 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/file_util.h"
6 #include "base/files/file_path.h"
7 #include "chrome/test/remoting/remote_desktop_browsertest.h"
8 #include "chrome/test/remoting/waiter.h"
9
10 namespace remoting {
11
12 class Me2MeBrowserTest : public RemoteDesktopBrowserTest {
13  protected:
14   void TestKeyboardInput();
15   void TestMouseInput();
16
17   void ConnectPinlessAndCleanupPairings(bool cleanup_all);
18   bool IsPairingSpinnerHidden();
19 };
20
21 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest,
22                        MANUAL_Me2Me_Connect_Local_Host) {
23   VerifyInternetAccess();
24   Install();
25   LaunchChromotingApp();
26
27   // Authorize, Authenticate, and Approve.
28   Auth();
29   ExpandMe2Me();
30
31   ConnectToLocalHost(false);
32
33   OpenClientBrowserPage();
34
35   TestKeyboardInput();
36
37   // TODO(chaitali): Change the mouse input test to also work in the
38   // HTTP server framework
39   // TestMouseInput();
40
41   DisconnectMe2Me();
42   Cleanup();
43 }
44
45 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest,
46                        MANUAL_Me2Me_Connect_Remote_Host) {
47   VerifyInternetAccess();
48   Install();
49   LaunchChromotingApp();
50
51   // Authorize, Authenticate, and Approve.
52   Auth();
53   ExpandMe2Me();
54
55   ConnectToRemoteHost(remote_host_name(), false);
56
57   // TODO(weitaosu): Find a way to verify keyboard input injection.
58   // We cannot use TestKeyboardInput because it assumes
59   // that the client and the host are on the same machine.
60
61   DisconnectMe2Me();
62   Cleanup();
63 }
64
65 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest,
66                        MANUAL_Me2Me_Connect_Pinless) {
67   VerifyInternetAccess();
68   Install();
69   LaunchChromotingApp();
70
71   // Authorize, Authenticate, and Approve.
72   Auth();
73   ExpandMe2Me();
74
75   ASSERT_FALSE(HtmlElementVisible("paired-client-manager-message"))
76       << "The host must have no pairings before running the pinless test.";
77
78   // Test that cleanup works with either the Delete or Delete all buttons.
79   ConnectPinlessAndCleanupPairings(false);
80   ConnectPinlessAndCleanupPairings(true);
81
82   Cleanup();
83 }
84
85 void Me2MeBrowserTest::TestKeyboardInput() {
86   // We will assume here that the browser window is already open on the host
87   // and in focus.
88   // Press tab to put focus on the textbox.
89   SimulateKeyPressWithCode(ui::VKEY_TAB, "Tab", false, false, false, false);
90
91   // Write some text in the box and press enter
92   std::string text = "Abigail";
93   SimulateStringInput(text);
94   SimulateKeyPressWithCode(
95       ui::VKEY_RETURN, "Enter", false, false, false, false);
96
97   // Wait until the client tab sets the right variables
98   ConditionalTimeoutWaiter waiter(
99           base::TimeDelta::FromSeconds(10),
100           base::TimeDelta::FromMilliseconds(500),
101           base::Bind(&RemoteDesktopBrowserTest::IsHostActionComplete,
102                      client_web_content(),
103                      "testResult.keypressSucceeded"));
104   EXPECT_TRUE(waiter.Wait());
105
106   // Check that the text we got is correct
107   EXPECT_TRUE(ExecuteScriptAndExtractBool(
108       client_web_content(),
109       "testResult.keypressText == '" + text + "'"));
110 }
111
112 void Me2MeBrowserTest::TestMouseInput() {
113   SimulateMouseLeftClickAt(10, 50);
114   // TODO: Verify programatically the mouse events are received by the host.
115   // This will be tricky as it depends on the host OS, window manager, desktop
116   // layout, and screen resolution. Until then we need to visually verify that
117   // "Dash Home" is clicked on a Unity window manager.
118   ASSERT_TRUE(TimeoutWaiter(base::TimeDelta::FromSeconds(5)).Wait());
119 }
120
121 void Me2MeBrowserTest::ConnectPinlessAndCleanupPairings(bool cleanup_all) {
122   // First connection: verify that a PIN is requested, and request pairing.
123   ConnectToLocalHost(true);
124   DisconnectMe2Me();
125
126   // TODO(jamiewalch): This reload is only needed because there's a bug in the
127   // web-app whereby it doesn't refresh its pairing state correctly.
128   // http://crbug.com/311290
129   LaunchChromotingApp();
130   ASSERT_TRUE(HtmlElementVisible("paired-client-manager-message"));
131
132   // Second connection: verify that no PIN is requested.
133   ClickOnControl("this-host-connect");
134   WaitForConnection();
135   DisconnectMe2Me();
136
137   // Clean up pairings.
138   ClickOnControl("open-paired-client-manager-dialog");
139   ASSERT_TRUE(HtmlElementVisible("paired-client-manager-dialog"));
140
141   if (cleanup_all) {
142     ClickOnControl("delete-all-paired-clients");
143   } else {
144     std::string host_id = ExecuteScriptAndExtractString(
145         "remoting.pairedClientManager.getFirstClientIdForTesting_()");
146     std::string node_id = "delete-client-" + host_id;
147     ClickOnControl(node_id);
148   }
149
150   // Wait for the "working" spinner to disappear. The spinner is shown by both
151   // methods of deleting a host and is removed when the operation completes.
152   ConditionalTimeoutWaiter waiter(
153       base::TimeDelta::FromSeconds(5),
154       base::TimeDelta::FromMilliseconds(200),
155       base::Bind(&Me2MeBrowserTest::IsPairingSpinnerHidden, this));
156   EXPECT_TRUE(waiter.Wait());
157   EXPECT_TRUE(ExecuteScriptAndExtractBool(
158       "document.getElementById('delete-all-paired-clients').disabled"));
159
160   ClickOnControl("close-paired-client-manager-dialog");
161   ASSERT_FALSE(HtmlElementVisible("paired-client-manager-dialog"));
162   ASSERT_FALSE(HtmlElementVisible("paired-client-manager-message"));
163 }
164
165 bool Me2MeBrowserTest::IsPairingSpinnerHidden() {
166   return !HtmlElementVisible("paired-client-manager-dialog-working");
167 }
168
169 }  // namespace remoting