Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chrome / test / remoting / me2me_browsertest.cc
blob3c3a031e71bc538e0c5ede4774affff48f5bcbab
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"
14 namespace remoting {
16 class Me2MeBrowserTest : public RemoteDesktopBrowserTest {
17 protected:
18 void TestKeypressInput(ui::KeyboardCode, const char*);
20 void ConnectPinlessAndCleanupPairings(bool cleanup_all);
21 bool IsPairingSpinnerHidden();
22 void SetupForRemoteHostTest();
24 void RestoreApp();
25 void MinimizeApp();
28 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest, MANUAL_Me2Me_Connect_Local_Host) {
29 content::WebContents* content = SetUpTest();
30 LoadScript(content, FILE_PATH_LITERAL("me2me_browser_test.js"));
31 RunJavaScriptTest(content, "ConnectToLocalHost", "{"
32 "pin: '" + me2me_pin() + "'"
33 "}");
35 Cleanup();
38 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest,
39 MANUAL_Me2Me_Connect_Remote_Host) {
40 VerifyInternetAccess();
41 Install();
42 LaunchChromotingApp(false);
44 // Authorize, Authenticate, and Approve.
45 Auth();
46 ExpandMe2Me();
48 ConnectToRemoteHost(remote_host_name(), false);
50 // TODO(weitaosu): Find a way to verify keyboard input injection.
51 // We cannot use TestKeyboardInput because it assumes
52 // that the client and the host are on the same machine.
54 DisconnectMe2Me();
55 Cleanup();
58 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest,
59 MANUAL_Me2Me_Remote_Host_Keypress) {
60 SetupForRemoteHostTest();
62 // Test all key characters
63 int length = sizeof(test_alpha_map)/sizeof(KeyCodeTestMap);
64 for (int i = 0; i < length; i++) {
65 KeyCodeTestMap key = test_alpha_map[i];
66 TestKeypressInput(key.vkey_code, key.code);
68 DisconnectMe2Me();
69 Cleanup();
72 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest,
73 MANUAL_Me2Me_Remote_Host_Digitpress) {
74 SetupForRemoteHostTest();
76 // Test all digit characters
77 int length = sizeof(test_digit_map)/sizeof(KeyCodeTestMap);
78 for (int i = 0; i < length; i++) {
79 KeyCodeTestMap key = test_digit_map[i];
80 TestKeypressInput(key.vkey_code, key.code);
82 DisconnectMe2Me();
83 Cleanup();
86 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest,
87 MANUAL_Me2Me_Remote_Host_Specialpress) {
88 SetupForRemoteHostTest();
90 // Test all special characters
91 int length = sizeof(test_special_map)/sizeof(KeyCodeTestMap);
92 for (int i = 0; i < length; i++) {
93 KeyCodeTestMap key = test_special_map[i];
94 TestKeypressInput(key.vkey_code, key.code);
96 DisconnectMe2Me();
97 Cleanup();
100 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest,
101 MANUAL_Me2Me_Remote_Host_Numpadpress) {
102 SetupForRemoteHostTest();
104 // Test all numpad characters
105 int length = sizeof(test_numpad_map)/sizeof(KeyCodeTestMap);
106 for (int i = 0; i < length; i++) {
107 KeyCodeTestMap key = test_numpad_map[i];
108 TestKeypressInput(key.vkey_code, key.code);
110 DisconnectMe2Me();
111 Cleanup();
114 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest,
115 MANUAL_Me2Me_Connect_Pinless) {
116 SetUpTest();
118 ASSERT_FALSE(HtmlElementVisible("paired-client-manager-message"))
119 << "The host must have no pairings before running the pinless test.";
121 // Test that cleanup works with either the Delete or Delete all buttons.
122 ConnectPinlessAndCleanupPairings(false);
123 ConnectPinlessAndCleanupPairings(true);
125 Cleanup();
128 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest, MANUAL_Me2Me_v2_Alive_OnLostFocus) {
129 content::WebContents* content = SetUpTest();
130 LoadScript(content, FILE_PATH_LITERAL("me2me_browser_test.js"));
131 RunJavaScriptTest(content, "AliveOnLostFocus", "{"
132 "pin: '" + me2me_pin() + "'"
133 "}");
135 Cleanup();
138 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest,
139 MANUAL_Me2Me_Disable_Remote_Connection) {
140 SetUpTest();
142 DisableRemoteConnection();
143 EXPECT_FALSE(IsLocalHostReady());
145 Cleanup();
148 void Me2MeBrowserTest::SetupForRemoteHostTest() {
149 VerifyInternetAccess();
150 OpenClientBrowserPage();
151 Install();
152 LaunchChromotingApp(false);
154 // Authorize, Authenticate, and Approve.
155 Auth();
156 ExpandMe2Me();
157 ConnectToRemoteHost(remote_host_name(), false);
159 // Wake up the machine if it's sleeping.
160 // This is only needed when testing manually as the host machine
161 // may be sleeping.
162 SimulateKeyPressWithCode(ui::VKEY_RETURN, "Enter");
165 void Me2MeBrowserTest::TestKeypressInput(
166 ui::KeyboardCode keyCode,
167 const char* code) {
168 remote_test_helper()->ClearLastEvent();
169 VLOG(1) << "Pressing " << code;
170 SimulateKeyPressWithCode(keyCode, code);
171 Event event;
172 remote_test_helper()->GetLastEvent(&event);
173 ASSERT_EQ(Action::Keydown, event.action);
174 ASSERT_EQ(keyCode, event.value);
177 void Me2MeBrowserTest::ConnectPinlessAndCleanupPairings(bool cleanup_all) {
178 // First connection: verify that a PIN is requested, and request pairing.
179 ConnectToLocalHost(true);
180 DisconnectMe2Me();
182 // TODO(jamiewalch): This reload is only needed because there's a bug in the
183 // web-app whereby it doesn't refresh its pairing state correctly.
184 // http://crbug.com/311290
185 LaunchChromotingApp(false);
186 ASSERT_TRUE(HtmlElementVisible("paired-client-manager-message"));
188 // Second connection: verify that no PIN is requested.
189 ClickOnControl("this-host-connect");
190 WaitForConnection();
191 DisconnectMe2Me();
193 // Clean up pairings.
194 ClickOnControl("open-paired-client-manager-dialog");
195 ASSERT_TRUE(HtmlElementVisible("paired-client-manager-dialog"));
197 if (cleanup_all) {
198 ClickOnControl("delete-all-paired-clients");
199 } else {
200 std::string host_id = ExecuteScriptAndExtractString(
201 "remoting.pairedClientManager.getFirstClientIdForTesting_()");
202 std::string node_id = "delete-client-" + host_id;
203 ClickOnControl(node_id);
206 // Wait for the "working" spinner to disappear. The spinner is shown by both
207 // methods of deleting a host and is removed when the operation completes.
208 ConditionalTimeoutWaiter waiter(
209 base::TimeDelta::FromSeconds(5),
210 base::TimeDelta::FromMilliseconds(200),
211 base::Bind(&Me2MeBrowserTest::IsPairingSpinnerHidden, this));
212 EXPECT_TRUE(waiter.Wait());
213 EXPECT_TRUE(ExecuteScriptAndExtractBool(
214 "document.getElementById('delete-all-paired-clients').disabled"));
216 ClickOnControl("close-paired-client-manager-dialog");
217 ASSERT_FALSE(HtmlElementVisible("paired-client-manager-dialog"));
218 ASSERT_FALSE(HtmlElementVisible("paired-client-manager-message"));
221 bool Me2MeBrowserTest::IsPairingSpinnerHidden() {
222 return !HtmlElementVisible("paired-client-manager-dialog-working");
225 } // namespace remoting