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. 4 5 #include "base/files/file_path.h" 6 #include "base/files/file_util.h" 7 #include "chrome/test/remoting/remote_desktop_browsertest.h" 8 #include "chrome/test/remoting/waiter.h" 9 10 namespace remoting { 11 12 class Me2MeBrowserTest : public RemoteDesktopBrowserTest { 13 protected: 14 void TestKeyboardInput(); 15 void TestMouseInput(); 16 17 void ConnectPinlessAndCleanupPairings(bool cleanup_all); 18 bool IsPairingSpinnerHidden(); 19 }; 20 21 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest, 22 MANUAL_Me2Me_Connect_Local_Host) { 23 SetUpTestForMe2Me(); 24 25 ConnectToLocalHost(false); 26 27 // TODO(chaitali): Change the mouse input test to also work in the 28 // HTTP server framework 29 // TestMouseInput(); 30 31 DisconnectMe2Me(); 32 Cleanup(); 33 } 34 35 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest, 36 MANUAL_Me2Me_Connect_Remote_Host) { 37 VerifyInternetAccess(); 38 Install(); 39 LaunchChromotingApp(); 40 41 // Authorize, Authenticate, and Approve. 42 Auth(); 43 ExpandMe2Me(); 44 45 ConnectToRemoteHost(remote_host_name(), false); 46 47 // TODO(weitaosu): Find a way to verify keyboard input injection. 48 // We cannot use TestKeyboardInput because it assumes 49 // that the client and the host are on the same machine. 50 51 DisconnectMe2Me(); 52 Cleanup(); 53 } 54 55 IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest, 56 MANUAL_Me2Me_Connect_Pinless) { 57 SetUpTestForMe2Me(); 58 59 ASSERT_FALSE(HtmlElementVisible("paired-client-manager-message")) 60 << "The host must have no pairings before running the pinless test."; 61 62 // Test that cleanup works with either the Delete or Delete all buttons. 63 ConnectPinlessAndCleanupPairings(false); 64 ConnectPinlessAndCleanupPairings(true); 65 66 Cleanup(); 67 } 68 69 void Me2MeBrowserTest::TestKeyboardInput() { 70 // We will assume here that the browser window is already open on the host 71 // and in focus. 72 // Press tab to put focus on the textbox. 73 SimulateKeyPressWithCode(ui::VKEY_TAB, "Tab", false, false, false, false); 74 75 // Write some text in the box and press enter 76 std::string text = "Abigail"; 77 SimulateStringInput(text); 78 SimulateKeyPressWithCode( 79 ui::VKEY_RETURN, "Enter", false, false, false, false); 80 81 // Wait until the client tab sets the right variables 82 ConditionalTimeoutWaiter waiter( 83 base::TimeDelta::FromSeconds(10), 84 base::TimeDelta::FromMilliseconds(500), 85 base::Bind(&RemoteDesktopBrowserTest::IsHostActionComplete, 86 client_web_content(), 87 "testResult.keypressSucceeded")); 88 EXPECT_TRUE(waiter.Wait()); 89 90 // Check that the text we got is correct 91 EXPECT_TRUE(ExecuteScriptAndExtractBool( 92 client_web_content(), 93 "testResult.keypressText == '" + text + "'")); 94 } 95 96 void Me2MeBrowserTest::TestMouseInput() { 97 SimulateMouseLeftClickAt(10, 50); 98 // TODO: Verify programatically the mouse events are received by the host. 99 // This will be tricky as it depends on the host OS, window manager, desktop 100 // layout, and screen resolution. Until then we need to visually verify that 101 // "Dash Home" is clicked on a Unity window manager. 102 ASSERT_TRUE(TimeoutWaiter(base::TimeDelta::FromSeconds(5)).Wait()); 103 } 104 105 void Me2MeBrowserTest::ConnectPinlessAndCleanupPairings(bool cleanup_all) { 106 // First connection: verify that a PIN is requested, and request pairing. 107 ConnectToLocalHost(true); 108 DisconnectMe2Me(); 109 110 // TODO(jamiewalch): This reload is only needed because there's a bug in the 111 // web-app whereby it doesn't refresh its pairing state correctly. 112 // http://crbug.com/311290 113 LaunchChromotingApp(); 114 ASSERT_TRUE(HtmlElementVisible("paired-client-manager-message")); 115 116 // Second connection: verify that no PIN is requested. 117 ClickOnControl("this-host-connect"); 118 WaitForConnection(); 119 DisconnectMe2Me(); 120 121 // Clean up pairings. 122 ClickOnControl("open-paired-client-manager-dialog"); 123 ASSERT_TRUE(HtmlElementVisible("paired-client-manager-dialog")); 124 125 if (cleanup_all) { 126 ClickOnControl("delete-all-paired-clients"); 127 } else { 128 std::string host_id = ExecuteScriptAndExtractString( 129 "remoting.pairedClientManager.getFirstClientIdForTesting_()"); 130 std::string node_id = "delete-client-" + host_id; 131 ClickOnControl(node_id); 132 } 133 134 // Wait for the "working" spinner to disappear. The spinner is shown by both 135 // methods of deleting a host and is removed when the operation completes. 136 ConditionalTimeoutWaiter waiter( 137 base::TimeDelta::FromSeconds(5), 138 base::TimeDelta::FromMilliseconds(200), 139 base::Bind(&Me2MeBrowserTest::IsPairingSpinnerHidden, this)); 140 EXPECT_TRUE(waiter.Wait()); 141 EXPECT_TRUE(ExecuteScriptAndExtractBool( 142 "document.getElementById('delete-all-paired-clients').disabled")); 143 144 ClickOnControl("close-paired-client-manager-dialog"); 145 ASSERT_FALSE(HtmlElementVisible("paired-client-manager-dialog")); 146 ASSERT_FALSE(HtmlElementVisible("paired-client-manager-message")); 147 } 148 149 bool Me2MeBrowserTest::IsPairingSpinnerHidden() { 150 return !HtmlElementVisible("paired-client-manager-dialog-working"); 151 } 152 153 } // namespace remoting 154