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