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