OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 # TODO(nduca): Rewrite what some of these tests to use mocks instead of | 5 # TODO(nduca): Rewrite what some of these tests to use mocks instead of |
6 # actually talking to the device. This would improve our coverage quite | 6 # actually talking to the device. This would improve our coverage quite |
7 # a bit. | 7 # a bit. |
8 import unittest | 8 import unittest |
9 import socket | 9 import socket |
10 | 10 |
11 from telemetry import cros_browser_backend | 11 from telemetry import cros_browser_backend |
12 from telemetry import cros_interface | 12 from telemetry import cros_interface |
13 from telemetry import options_for_unittests | 13 from telemetry import options_for_unittests |
14 from telemetry import run_tests | 14 from telemetry import run_tests |
| 15 from telemetry import util |
15 | 16 |
16 class CrOSInterfaceTest(unittest.TestCase): | 17 class CrOSInterfaceTest(unittest.TestCase): |
17 @run_tests.RequiresBrowserOfType('cros-chrome') | 18 @run_tests.RequiresBrowserOfType('cros-chrome') |
18 def testDeviceSideProcessFailureToLaunch(self): | 19 def testDeviceSideProcessFailureToLaunch(self): |
19 remote = options_for_unittests.GetCopy().cros_remote | 20 remote = options_for_unittests.GetCopy().cros_remote |
20 cri = cros_interface.CrOSInterface( | 21 cri = cros_interface.CrOSInterface( |
21 remote, | 22 remote, |
22 options_for_unittests.GetCopy().cros_ssh_identity) | 23 options_for_unittests.GetCopy().cros_ssh_identity) |
23 | 24 |
24 def WillFail(): | 25 def WillFail(): |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 sock.bind(('', 0)) | 124 sock.bind(('', 0)) |
124 port = sock.getsockname()[1] | 125 port = sock.getsockname()[1] |
125 sock.listen(0) | 126 sock.listen(0) |
126 | 127 |
127 # Get remote port and ensure that it was unused. | 128 # Get remote port and ensure that it was unused. |
128 remote_port = cri.GetRemotePort() | 129 remote_port = cri.GetRemotePort() |
129 self.assertFalse(cri.IsHTTPServerRunningOnPort(remote_port)) | 130 self.assertFalse(cri.IsHTTPServerRunningOnPort(remote_port)) |
130 | 131 |
131 # Forward local server's port to remote device's remote_port. | 132 # Forward local server's port to remote device's remote_port. |
132 forwarder = cros_browser_backend.SSHForwarder( | 133 forwarder = cros_browser_backend.SSHForwarder( |
133 cri, 'R', (remote_port, port)) | 134 cri, 'R', util.PortPair(port, remote_port)) |
134 | 135 |
135 # At this point, remote device should be able to connect to local server. | 136 # At this point, remote device should be able to connect to local server. |
136 self.assertTrue(cri.IsHTTPServerRunningOnPort(remote_port)) | 137 self.assertTrue(cri.IsHTTPServerRunningOnPort(remote_port)) |
137 | 138 |
138 # Next remote port shouldn't be the same as remote_port, since remote_port | 139 # Next remote port shouldn't be the same as remote_port, since remote_port |
139 # is now in use. | 140 # is now in use. |
140 self.assertTrue(cri.GetRemotePort() != remote_port) | 141 self.assertTrue(cri.GetRemotePort() != remote_port) |
141 | 142 |
142 # Close forwarder and local server ports. | 143 # Close forwarder and local server ports. |
143 forwarder.Close() | 144 forwarder.Close() |
144 sock.close() | 145 sock.close() |
145 | 146 |
146 # Device should no longer be able to connect to remote_port since it is no | 147 # Device should no longer be able to connect to remote_port since it is no |
147 # longer in use. | 148 # longer in use. |
148 self.assertFalse(cri.IsHTTPServerRunningOnPort(remote_port)) | 149 self.assertFalse(cri.IsHTTPServerRunningOnPort(remote_port)) |
| 150 |
| 151 @run_tests.RequiresBrowserOfType('cros-chrome') |
| 152 def testGetRemotePortReservedPorts(self): |
| 153 remote = options_for_unittests.GetCopy().cros_remote |
| 154 cri = cros_interface.CrOSInterface( |
| 155 remote, |
| 156 options_for_unittests.GetCopy().cros_ssh_identity) |
| 157 |
| 158 # Should return 2 separate ports even though the first one isn't technically |
| 159 # being used yet. |
| 160 remote_port_1 = cri.GetRemotePort() |
| 161 remote_port_2 = cri.GetRemotePort() |
| 162 |
| 163 self.assertTrue(remote_port_1 != remote_port_2) |
OLD | NEW |