me2me_browsertest.cc revision 1e9bf3e0803691d0a228da41fc608347b6db4340
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
10namespace remoting {
11
12class Me2MeBrowserTest : public RemoteDesktopBrowserTest {
13 protected:
14  void TestKeyboardInput();
15  void TestMouseInput();
16
17  void ConnectPinlessAndCleanupPairings(bool cleanup_all);
18  bool IsPairingSpinnerHidden();
19};
20
21IN_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  TestKeyboardInput();
34  TestMouseInput();
35
36  DisconnectMe2Me();
37  Cleanup();
38}
39
40IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest,
41                       MANUAL_Me2Me_Connect_Remote_Host) {
42  VerifyInternetAccess();
43  Install();
44  LaunchChromotingApp();
45
46  // Authorize, Authenticate, and Approve.
47  Auth();
48  ExpandMe2Me();
49
50  ConnectToRemoteHost(remote_host_name(), false);
51
52  // TODO(weitaosu): Find a way to verify keyboard input injection.
53  // We cannot use TestKeyboardInput because it assumes
54  // that the client and the host are on the same machine.
55
56  DisconnectMe2Me();
57  Cleanup();
58}
59
60IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest,
61                       MANUAL_Me2Me_Connect_Pinless) {
62  VerifyInternetAccess();
63  Install();
64  LaunchChromotingApp();
65
66  // Authorize, Authenticate, and Approve.
67  Auth();
68  ExpandMe2Me();
69
70  ASSERT_FALSE(HtmlElementVisible("paired-client-manager-message"))
71      << "The host must have no pairings before running the pinless test.";
72
73  // Test that cleanup works with either the Delete or Delete all buttons.
74  ConnectPinlessAndCleanupPairings(false);
75  ConnectPinlessAndCleanupPairings(true);
76
77  Cleanup();
78}
79
80// Typing a command which writes to a temp file and then verify the contents of
81// the file.
82void Me2MeBrowserTest::TestKeyboardInput() {
83  // Start a terminal window with ctrl+alt+T
84  SimulateKeyPressWithCode(ui::VKEY_T, "KeyT", true, false, true, false);
85
86  // Wait for the keyboard events to be sent to and processed by the host.
87  ASSERT_TRUE(TimeoutWaiter(base::TimeDelta::FromMilliseconds(300)).Wait());
88
89  base::FilePath temp_file;
90  EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_file));
91
92  // Write some text into the temp file.
93  std::string text = "Abigail";
94  std::string command = "echo -n " + text + " > " +
95                        temp_file.MaybeAsASCII() + "\n";
96  SimulateStringInput(command);
97  SimulateStringInput("exit\n");
98
99  // Wait for the keyboard events to be sent to and processed by the host.
100  ASSERT_TRUE(TimeoutWaiter(base::TimeDelta::FromSeconds(1)).Wait());
101
102  // Read the content of the temp file.
103  std::string content;
104  EXPECT_TRUE(base::ReadFileToString(temp_file, &content));
105
106  LOG(INFO) << temp_file.value();
107
108  EXPECT_EQ(text, content);
109
110  EXPECT_TRUE(base::DeleteFile(temp_file, false));
111}
112
113void Me2MeBrowserTest::TestMouseInput() {
114  SimulateMouseLeftClickAt(10, 50);
115  // TODO: Verify programatically the mouse events are received by the host.
116  // This will be tricky as it depends on the host OS, window manager, desktop
117  // layout, and screen resolution. Until then we need to visually verify that
118  // "Dash Home" is clicked on a Unity window manager.
119  ASSERT_TRUE(TimeoutWaiter(base::TimeDelta::FromSeconds(5)).Wait());
120}
121
122void Me2MeBrowserTest::ConnectPinlessAndCleanupPairings(bool cleanup_all) {
123  // First connection: verify that a PIN is requested, and request pairing.
124  ConnectToLocalHost(true);
125  DisconnectMe2Me();
126
127  // TODO(jamiewalch): This reload is only needed because there's a bug in the
128  // web-app whereby it doesn't refresh its pairing state correctly.
129  // http://crbug.com/311290
130  LaunchChromotingApp();
131  ASSERT_TRUE(HtmlElementVisible("paired-client-manager-message"));
132
133  // Second connection: verify that no PIN is requested.
134  ClickOnControl("this-host-connect");
135  WaitForConnection();
136  DisconnectMe2Me();
137
138  // Clean up pairings.
139  ClickOnControl("open-paired-client-manager-dialog");
140  ASSERT_TRUE(HtmlElementVisible("paired-client-manager-dialog"));
141
142  if (cleanup_all) {
143    ClickOnControl("delete-all-paired-clients");
144  } else {
145    std::string host_id = ExecuteScriptAndExtractString(
146        "remoting.pairedClientManager.getFirstClientIdForTesting_()");
147    std::string node_id = "delete-client-" + host_id;
148    ClickOnControl(node_id);
149  }
150
151  // Wait for the "working" spinner to disappear. The spinner is shown by both
152  // methods of deleting a host and is removed when the operation completes.
153  ConditionalTimeoutWaiter waiter(
154      base::TimeDelta::FromSeconds(5),
155      base::TimeDelta::FromMilliseconds(200),
156      base::Bind(&Me2MeBrowserTest::IsPairingSpinnerHidden, this));
157  EXPECT_TRUE(waiter.Wait());
158  EXPECT_TRUE(ExecuteScriptAndExtractBool(
159      "document.getElementById('delete-all-paired-clients').disabled"));
160
161  ClickOnControl("close-paired-client-manager-dialog");
162  ASSERT_FALSE(HtmlElementVisible("paired-client-manager-dialog"));
163  ASSERT_FALSE(HtmlElementVisible("paired-client-manager-message"));
164}
165
166bool Me2MeBrowserTest::IsPairingSpinnerHidden() {
167  return !HtmlElementVisible("paired-client-manager-dialog-working");
168}
169
170}  // namespace remoting
171