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/files/file_path.h"
6 #include "base/files/file_util.h"
7 #include "chrome/browser/ui/browser_window.h"
8 #include "chrome/test/remoting/key_code_test_map.h"
9 #include "chrome/test/remoting/remote_desktop_browsertest.h"
10 #include "chrome/test/remoting/remote_test_helper.h"
11 #include "chrome/test/remoting/waiter.h"
12 #include "extensions/browser/app_window/app_window.h"
16 class Me2MeBrowserTest
: public RemoteDesktopBrowserTest
{
18 void TestKeypressInput(ui::KeyboardCode
, const char*);
20 void ConnectPinlessAndCleanupPairings(bool cleanup_all
);
21 bool IsPairingSpinnerHidden();
22 void SetupForRemoteHostTest();
28 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest
,
29 MANUAL_Me2Me_Connect_Local_Host
) {
32 ConnectToLocalHost(false);
34 // TODO(chaitali): Change the mouse input test to also work in the
35 // HTTP server framework
42 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest
,
43 MANUAL_Me2Me_Connect_Remote_Host
) {
44 VerifyInternetAccess();
46 LaunchChromotingApp(false);
48 // Authorize, Authenticate, and Approve.
52 ConnectToRemoteHost(remote_host_name(), false);
54 // TODO(weitaosu): Find a way to verify keyboard input injection.
55 // We cannot use TestKeyboardInput because it assumes
56 // that the client and the host are on the same machine.
62 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest
,
63 MANUAL_Me2Me_Remote_Host_Keypress
) {
64 SetupForRemoteHostTest();
66 // Test all key characters
67 int length
= sizeof(test_alpha_map
)/sizeof(KeyCodeTestMap
);
68 for (int i
= 0; i
< length
; i
++) {
69 KeyCodeTestMap key
= test_alpha_map
[i
];
70 TestKeypressInput(key
.vkey_code
, key
.code
);
76 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest
,
77 MANUAL_Me2Me_Remote_Host_Digitpress
) {
78 SetupForRemoteHostTest();
80 // Test all digit characters
81 int length
= sizeof(test_digit_map
)/sizeof(KeyCodeTestMap
);
82 for (int i
= 0; i
< length
; i
++) {
83 KeyCodeTestMap key
= test_digit_map
[i
];
84 TestKeypressInput(key
.vkey_code
, key
.code
);
90 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest
,
91 MANUAL_Me2Me_Remote_Host_Specialpress
) {
92 SetupForRemoteHostTest();
94 // Test all special characters
95 int length
= sizeof(test_special_map
)/sizeof(KeyCodeTestMap
);
96 for (int i
= 0; i
< length
; i
++) {
97 KeyCodeTestMap key
= test_special_map
[i
];
98 TestKeypressInput(key
.vkey_code
, key
.code
);
104 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest
,
105 MANUAL_Me2Me_Remote_Host_Numpadpress
) {
106 SetupForRemoteHostTest();
108 // Test all numpad characters
109 int length
= sizeof(test_numpad_map
)/sizeof(KeyCodeTestMap
);
110 for (int i
= 0; i
< length
; i
++) {
111 KeyCodeTestMap key
= test_numpad_map
[i
];
112 TestKeypressInput(key
.vkey_code
, key
.code
);
118 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest
,
119 MANUAL_Me2Me_Connect_Pinless
) {
122 ASSERT_FALSE(HtmlElementVisible("paired-client-manager-message"))
123 << "The host must have no pairings before running the pinless test.";
125 // Test that cleanup works with either the Delete or Delete all buttons.
126 ConnectPinlessAndCleanupPairings(false);
127 ConnectPinlessAndCleanupPairings(true);
132 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest
,
133 MANUAL_Me2Me_v2_Alive_OnLostFocus
) {
137 ConnectToLocalHost(false);
139 // Minimize the window
142 // Wait for a few seconds for app to process any notifications it
143 // would have got from minimizing.
144 ASSERT_TRUE(TimeoutWaiter(base::TimeDelta::FromSeconds(4)).Wait());
146 // Validate that the session is still active.
147 EXPECT_TRUE(RemoteDesktopBrowserTest::IsSessionConnected());
149 // Maximize so we can disconnect and teardown.
157 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest
,
158 MANUAL_Me2Me_Disable_Remote_Connection
) {
161 DisableRemoteConnection();
162 EXPECT_FALSE(IsLocalHostReady());
167 void Me2MeBrowserTest::SetupForRemoteHostTest() {
168 VerifyInternetAccess();
169 OpenClientBrowserPage();
171 LaunchChromotingApp(false);
173 // Authorize, Authenticate, and Approve.
176 ConnectToRemoteHost(remote_host_name(), false);
178 // Wake up the machine if it's sleeping.
179 // This is only needed when testing manually as the host machine
181 SimulateKeyPressWithCode(ui::VKEY_RETURN
, "Enter");
184 void Me2MeBrowserTest::TestKeypressInput(
185 ui::KeyboardCode keyCode
,
187 remote_test_helper()->ClearLastEvent();
188 VLOG(1) << "Pressing " << code
;
189 SimulateKeyPressWithCode(keyCode
, code
);
191 remote_test_helper()->GetLastEvent(&event
);
192 ASSERT_EQ(Action::Keydown
, event
.action
);
193 ASSERT_EQ(keyCode
, event
.value
);
196 void Me2MeBrowserTest::ConnectPinlessAndCleanupPairings(bool cleanup_all
) {
197 // First connection: verify that a PIN is requested, and request pairing.
198 ConnectToLocalHost(true);
201 // TODO(jamiewalch): This reload is only needed because there's a bug in the
202 // web-app whereby it doesn't refresh its pairing state correctly.
203 // http://crbug.com/311290
204 LaunchChromotingApp(false);
205 ASSERT_TRUE(HtmlElementVisible("paired-client-manager-message"));
207 // Second connection: verify that no PIN is requested.
208 ClickOnControl("this-host-connect");
212 // Clean up pairings.
213 ClickOnControl("open-paired-client-manager-dialog");
214 ASSERT_TRUE(HtmlElementVisible("paired-client-manager-dialog"));
217 ClickOnControl("delete-all-paired-clients");
219 std::string host_id
= ExecuteScriptAndExtractString(
220 "remoting.pairedClientManager.getFirstClientIdForTesting_()");
221 std::string node_id
= "delete-client-" + host_id
;
222 ClickOnControl(node_id
);
225 // Wait for the "working" spinner to disappear. The spinner is shown by both
226 // methods of deleting a host and is removed when the operation completes.
227 ConditionalTimeoutWaiter
waiter(
228 base::TimeDelta::FromSeconds(5),
229 base::TimeDelta::FromMilliseconds(200),
230 base::Bind(&Me2MeBrowserTest::IsPairingSpinnerHidden
, this));
231 EXPECT_TRUE(waiter
.Wait());
232 EXPECT_TRUE(ExecuteScriptAndExtractBool(
233 "document.getElementById('delete-all-paired-clients').disabled"));
235 ClickOnControl("close-paired-client-manager-dialog");
236 ASSERT_FALSE(HtmlElementVisible("paired-client-manager-dialog"));
237 ASSERT_FALSE(HtmlElementVisible("paired-client-manager-message"));
240 bool Me2MeBrowserTest::IsPairingSpinnerHidden() {
241 return !HtmlElementVisible("paired-client-manager-dialog-working");
244 void Me2MeBrowserTest::MinimizeApp() {
245 extensions::AppWindow
* appWindow
= GetFirstAppWindow();
247 appWindow
->Minimize();
249 browser()->window()->Minimize();
253 void Me2MeBrowserTest::RestoreApp() {
254 extensions::AppWindow
* appWindow
= GetFirstAppWindow();
256 appWindow
->Restore();
258 browser()->window()->Restore();
262 } // namespace remoting