Update CrOS OOBE throbber to MD throbber; delete old asset
[chromium-blink-merge.git] / chrome / test / remoting / me2me_browsertest.cc
blob99f989dbb2ae049a04191495b3def245649aa0fc
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, MANUAL_Me2Me_RetryOnHostOffline) {
139 content::WebContents* content = SetUpTest();
140 LoadScript(content, FILE_PATH_LITERAL("me2me_browser_test.js"));
141 RunJavaScriptTest(content, "RetryOnHostOffline", "{"
142 "pin: '" + me2me_pin() + "'"
143 "}");
145 Cleanup();
148 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest,
149 MANUAL_Me2Me_Disable_Remote_Connection) {
150 SetUpTest();
152 DisableRemoteConnection();
153 EXPECT_FALSE(IsLocalHostReady());
155 Cleanup();
158 void Me2MeBrowserTest::SetupForRemoteHostTest() {
159 VerifyInternetAccess();
160 OpenClientBrowserPage();
161 Install();
162 LaunchChromotingApp(false);
164 // Authorize, Authenticate, and Approve.
165 Auth();
166 ExpandMe2Me();
167 ConnectToRemoteHost(remote_host_name(), false);
169 // Wake up the machine if it's sleeping.
170 // This is only needed when testing manually as the host machine
171 // may be sleeping.
172 SimulateKeyPressWithCode(ui::VKEY_RETURN, "Enter");
175 void Me2MeBrowserTest::TestKeypressInput(
176 ui::KeyboardCode keyCode,
177 const char* code) {
178 remote_test_helper()->ClearLastEvent();
179 VLOG(1) << "Pressing " << code;
180 SimulateKeyPressWithCode(keyCode, code);
181 Event event;
182 remote_test_helper()->GetLastEvent(&event);
183 ASSERT_EQ(Action::Keydown, event.action);
184 ASSERT_EQ(keyCode, event.value);
187 void Me2MeBrowserTest::ConnectPinlessAndCleanupPairings(bool cleanup_all) {
188 // First connection: verify that a PIN is requested, and request pairing.
189 ConnectToLocalHost(true);
190 DisconnectMe2Me();
192 // TODO(jamiewalch): This reload is only needed because there's a bug in the
193 // web-app whereby it doesn't refresh its pairing state correctly.
194 // http://crbug.com/311290
195 LaunchChromotingApp(false);
196 ASSERT_TRUE(HtmlElementVisible("paired-client-manager-message"));
198 // Second connection: verify that no PIN is requested.
199 ClickOnControl("this-host-connect");
200 WaitForConnection();
201 DisconnectMe2Me();
203 // Clean up pairings.
204 ClickOnControl("open-paired-client-manager-dialog");
205 ASSERT_TRUE(HtmlElementVisible("paired-client-manager-dialog"));
207 if (cleanup_all) {
208 ClickOnControl("delete-all-paired-clients");
209 } else {
210 std::string host_id = ExecuteScriptAndExtractString(
211 "remoting.pairedClientManager.getFirstClientIdForTesting_()");
212 std::string node_id = "delete-client-" + host_id;
213 ClickOnControl(node_id);
216 // Wait for the "working" spinner to disappear. The spinner is shown by both
217 // methods of deleting a host and is removed when the operation completes.
218 ConditionalTimeoutWaiter waiter(
219 base::TimeDelta::FromSeconds(5),
220 base::TimeDelta::FromMilliseconds(200),
221 base::Bind(&Me2MeBrowserTest::IsPairingSpinnerHidden, this));
222 EXPECT_TRUE(waiter.Wait());
223 EXPECT_TRUE(ExecuteScriptAndExtractBool(
224 "document.getElementById('delete-all-paired-clients').disabled"));
226 ClickOnControl("close-paired-client-manager-dialog");
227 ASSERT_FALSE(HtmlElementVisible("paired-client-manager-dialog"));
228 ASSERT_FALSE(HtmlElementVisible("paired-client-manager-message"));
231 bool Me2MeBrowserTest::IsPairingSpinnerHidden() {
232 return !HtmlElementVisible("paired-client-manager-dialog-working");
235 } // namespace remoting