Do not announce robot account token before account ID is available
[chromium-blink-merge.git] / chrome / test / remoting / me2me_browsertest.cc
blobcc1415a1f37c8105ee5f1f2c809976e83cfe3b95
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,
29 MANUAL_Me2Me_Connect_Local_Host) {
30 SetUpTest();
32 ConnectToLocalHost(false);
34 // TODO(chaitali): Change the mouse input test to also work in the
35 // HTTP server framework
36 // TestMouseInput();
38 DisconnectMe2Me();
39 Cleanup();
42 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest,
43 MANUAL_Me2Me_Connect_Remote_Host) {
44 VerifyInternetAccess();
45 Install();
46 LaunchChromotingApp(false);
48 // Authorize, Authenticate, and Approve.
49 Auth();
50 ExpandMe2Me();
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.
58 DisconnectMe2Me();
59 Cleanup();
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);
72 DisconnectMe2Me();
73 Cleanup();
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);
86 DisconnectMe2Me();
87 Cleanup();
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);
100 DisconnectMe2Me();
101 Cleanup();
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);
114 DisconnectMe2Me();
115 Cleanup();
118 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest,
119 MANUAL_Me2Me_Connect_Pinless) {
120 SetUpTest();
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);
129 Cleanup();
132 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest,
133 MANUAL_Me2Me_v2_Alive_OnLostFocus) {
134 SetUpTest();
136 // Connect to host.
137 ConnectToLocalHost(false);
139 // Minimize the window
140 MinimizeApp();
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.
150 RestoreApp();
152 // Cleanup
153 DisconnectMe2Me();
154 Cleanup();
157 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest,
158 MANUAL_Me2Me_Disable_Remote_Connection) {
159 SetUpTest();
161 DisableRemoteConnection();
162 EXPECT_FALSE(IsLocalHostReady());
164 Cleanup();
167 void Me2MeBrowserTest::SetupForRemoteHostTest() {
168 VerifyInternetAccess();
169 OpenClientBrowserPage();
170 Install();
171 LaunchChromotingApp(false);
173 // Authorize, Authenticate, and Approve.
174 Auth();
175 ExpandMe2Me();
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
180 // may be sleeping.
181 SimulateKeyPressWithCode(ui::VKEY_RETURN, "Enter");
184 void Me2MeBrowserTest::TestKeypressInput(
185 ui::KeyboardCode keyCode,
186 const char* code) {
187 remote_test_helper()->ClearLastEvent();
188 VLOG(1) << "Pressing " << code;
189 SimulateKeyPressWithCode(keyCode, code);
190 Event event;
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);
199 DisconnectMe2Me();
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");
209 WaitForConnection();
210 DisconnectMe2Me();
212 // Clean up pairings.
213 ClickOnControl("open-paired-client-manager-dialog");
214 ASSERT_TRUE(HtmlElementVisible("paired-client-manager-dialog"));
216 if (cleanup_all) {
217 ClickOnControl("delete-all-paired-clients");
218 } else {
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();
246 if (appWindow) {
247 appWindow->Minimize();
248 } else {
249 browser()->window()->Minimize();
253 void Me2MeBrowserTest::RestoreApp() {
254 extensions::AppWindow* appWindow = GetFirstAppWindow();
255 if (appWindow) {
256 appWindow->Restore();
257 } else {
258 browser()->window()->Restore();
262 } // namespace remoting