Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / test / remoting / me2me_browsertest.cc
blobd5cefe7331e6358c516336716d9da2fba94f6b0a
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 TestKeyboardInput();
34 TestMouseInput();
36 DisconnectMe2Me();
37 Cleanup();
40 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest,
41 MANUAL_Me2Me_Connect_Remote_Host) {
42 VerifyInternetAccess();
43 Install();
44 LaunchChromotingApp();
46 // Authorize, Authenticate, and Approve.
47 Auth();
48 ExpandMe2Me();
50 ConnectToRemoteHost(remote_host_name(), false);
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.
56 DisconnectMe2Me();
57 Cleanup();
60 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest,
61 MANUAL_Me2Me_Connect_Pinless) {
62 VerifyInternetAccess();
63 Install();
64 LaunchChromotingApp();
66 // Authorize, Authenticate, and Approve.
67 Auth();
68 ExpandMe2Me();
70 ASSERT_FALSE(HtmlElementVisible("paired-client-manager-message"))
71 << "The host must have no pairings before running the pinless test.";
73 // Test that cleanup works with either the Delete or Delete all buttons.
74 ConnectPinlessAndCleanupPairings(false);
75 ConnectPinlessAndCleanupPairings(true);
77 Cleanup();
80 // Typing a command which writes to a temp file and then verify the contents of
81 // the file.
82 void Me2MeBrowserTest::TestKeyboardInput() {
83 // Start a terminal window with ctrl+alt+T
84 SimulateKeyPressWithCode(ui::VKEY_T, "KeyT", true, false, true, false);
86 // Wait for the keyboard events to be sent to and processed by the host.
87 ASSERT_TRUE(TimeoutWaiter(base::TimeDelta::FromMilliseconds(300)).Wait());
89 base::FilePath temp_file;
90 EXPECT_TRUE(base::CreateTemporaryFile(&temp_file));
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");
99 // Wait for the keyboard events to be sent to and processed by the host.
100 ASSERT_TRUE(TimeoutWaiter(base::TimeDelta::FromSeconds(1)).Wait());
102 // Read the content of the temp file.
103 std::string content;
104 EXPECT_TRUE(base::ReadFileToString(temp_file, &content));
106 EXPECT_EQ(text, content);
108 EXPECT_TRUE(base::DeleteFile(temp_file, false));
111 void Me2MeBrowserTest::TestMouseInput() {
112 SimulateMouseLeftClickAt(10, 50);
113 // TODO: Verify programatically the mouse events are received by the host.
114 // This will be tricky as it depends on the host OS, window manager, desktop
115 // layout, and screen resolution. Until then we need to visually verify that
116 // "Dash Home" is clicked on a Unity window manager.
117 ASSERT_TRUE(TimeoutWaiter(base::TimeDelta::FromSeconds(5)).Wait());
120 void Me2MeBrowserTest::ConnectPinlessAndCleanupPairings(bool cleanup_all) {
121 // First connection: verify that a PIN is requested, and request pairing.
122 ConnectToLocalHost(true);
123 DisconnectMe2Me();
125 // TODO(jamiewalch): This reload is only needed because there's a bug in the
126 // web-app whereby it doesn't refresh its pairing state correctly.
127 // http://crbug.com/311290
128 LaunchChromotingApp();
129 ASSERT_TRUE(HtmlElementVisible("paired-client-manager-message"));
131 // Second connection: verify that no PIN is requested.
132 ClickOnControl("this-host-connect");
133 WaitForConnection();
134 DisconnectMe2Me();
136 // Clean up pairings.
137 ClickOnControl("open-paired-client-manager-dialog");
138 ASSERT_TRUE(HtmlElementVisible("paired-client-manager-dialog"));
140 if (cleanup_all) {
141 ClickOnControl("delete-all-paired-clients");
142 } else {
143 std::string host_id = ExecuteScriptAndExtractString(
144 "remoting.pairedClientManager.getFirstClientIdForTesting_()");
145 std::string node_id = "delete-client-" + host_id;
146 ClickOnControl(node_id);
149 // Wait for the "working" spinner to disappear. The spinner is shown by both
150 // methods of deleting a host and is removed when the operation completes.
151 ConditionalTimeoutWaiter waiter(
152 base::TimeDelta::FromSeconds(5),
153 base::TimeDelta::FromMilliseconds(200),
154 base::Bind(&Me2MeBrowserTest::IsPairingSpinnerHidden, this));
155 EXPECT_TRUE(waiter.Wait());
156 EXPECT_TRUE(ExecuteScriptAndExtractBool(
157 "document.getElementById('delete-all-paired-clients').disabled"));
159 ClickOnControl("close-paired-client-manager-dialog");
160 ASSERT_FALSE(HtmlElementVisible("paired-client-manager-dialog"));
161 ASSERT_FALSE(HtmlElementVisible("paired-client-manager-message"));
164 bool Me2MeBrowserTest::IsPairingSpinnerHidden() {
165 return !HtmlElementVisible("paired-client-manager-dialog-working");
168 } // namespace remoting