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 | 9 |
10 import browser_options | 10 from chrome_remote_control import browser_options |
11 import cros_interface | 11 from chrome_remote_control import cros_interface |
12 import run_tests | 12 from chrome_remote_control import run_tests |
13 | 13 |
14 class CrOSInterfaceTest(unittest.TestCase): | 14 class CrOSInterfaceTest(unittest.TestCase): |
15 @run_tests.RequiresBrowserOfType('cros-chrome') | 15 @run_tests.RequiresBrowserOfType('cros-chrome') |
16 def testDeviceSideProcessFailureToLaunch(self): | 16 def testDeviceSideProcessFailureToLaunch(self): |
17 remote = browser_options.options_for_unittests.cros_remote | 17 remote = browser_options.options_for_unittests.cros_remote |
18 cri = cros_interface.CrOSInterface(remote) | 18 cri = cros_interface.CrOSInterface(remote) |
19 | 19 |
20 def WillFail(): | 20 def WillFail(): |
21 dsp = cros_interface.DeviceSideProcess( | 21 dsp = cros_interface.DeviceSideProcess( |
22 cri, | 22 cri, |
(...skipping 29 matching lines...) Expand all Loading... |
52 | 52 |
53 @run_tests.RequiresBrowserOfType('cros-chrome') | 53 @run_tests.RequiresBrowserOfType('cros-chrome') |
54 def testExists(self): | 54 def testExists(self): |
55 remote = browser_options.options_for_unittests.cros_remote | 55 remote = browser_options.options_for_unittests.cros_remote |
56 cri = cros_interface.CrOSInterface(remote) | 56 cri = cros_interface.CrOSInterface(remote) |
57 self.assertTrue(cri.FileExistsOnDevice('/proc/cpuinfo')) | 57 self.assertTrue(cri.FileExistsOnDevice('/proc/cpuinfo')) |
58 self.assertTrue(cri.FileExistsOnDevice('/etc/passwd')) | 58 self.assertTrue(cri.FileExistsOnDevice('/etc/passwd')) |
59 self.assertFalse(cri.FileExistsOnDevice('/etc/sdlfsdjflskfjsflj')) | 59 self.assertFalse(cri.FileExistsOnDevice('/etc/sdlfsdjflskfjsflj')) |
60 | 60 |
61 @run_tests.RequiresBrowserOfType('cros-chrome') | 61 @run_tests.RequiresBrowserOfType('cros-chrome') |
62 def testGetFileContents(self): | 62 def testGetFileContents(self): # pylint: disable=R0201 |
63 remote = browser_options.options_for_unittests.cros_remote | 63 remote = browser_options.options_for_unittests.cros_remote |
64 cri = cros_interface.CrOSInterface(remote) | 64 cri = cros_interface.CrOSInterface(remote) |
65 hosts = cri.GetFileContents('/etc/hosts') | 65 hosts = cri.GetFileContents('/etc/hosts') |
66 assert hosts.startswith('# /etc/hosts') | 66 assert hosts.startswith('# /etc/hosts') |
67 | 67 |
68 @run_tests.RequiresBrowserOfType('cros-chrome') | 68 @run_tests.RequiresBrowserOfType('cros-chrome') |
69 def testGetFileContentsForSomethingThatDoesntExist(self): | 69 def testGetFileContentsForSomethingThatDoesntExist(self): |
70 remote = browser_options.options_for_unittests.cros_remote | 70 remote = browser_options.options_for_unittests.cros_remote |
71 cri = cros_interface.CrOSInterface(remote) | 71 cri = cros_interface.CrOSInterface(remote) |
72 self.assertRaises( | 72 self.assertRaises( |
73 OSError, | 73 OSError, |
74 lambda: cri.GetFileContents('/tmp/209fuslfskjf/dfsfsf')) | 74 lambda: cri.GetFileContents('/tmp/209fuslfskjf/dfsfsf')) |
75 | 75 |
76 @run_tests.RequiresBrowserOfType('cros-chrome') | 76 @run_tests.RequiresBrowserOfType('cros-chrome') |
77 def testListProcesses(self): | 77 def testListProcesses(self): # pylint: disable=R0201 |
78 remote = browser_options.options_for_unittests.cros_remote | 78 remote = browser_options.options_for_unittests.cros_remote |
79 cri = cros_interface.CrOSInterface(remote) | 79 cri = cros_interface.CrOSInterface(remote) |
80 | 80 |
81 with cros_interface.DeviceSideProcess( | 81 with cros_interface.DeviceSideProcess( |
82 cri, | 82 cri, |
83 ['sleep', '11']) as sleep: | 83 ['sleep', '11']): |
84 procs = cri.ListProcesses() | 84 procs = cri.ListProcesses() |
85 sleeps = [x for x in procs | 85 sleeps = [x for x in procs |
86 if x[1] == 'sleep 11'] | 86 if x[1] == 'sleep 11'] |
87 | 87 |
88 assert len(sleeps) == 1 | 88 assert len(sleeps) == 1 |
89 | 89 |
90 @run_tests.RequiresBrowserOfType('cros-chrome') | 90 @run_tests.RequiresBrowserOfType('cros-chrome') |
91 def testIsServiceRunning(self): | 91 def testIsServiceRunning(self): |
92 remote = browser_options.options_for_unittests.cros_remote | 92 remote = browser_options.options_for_unittests.cros_remote |
93 cri = cros_interface.CrOSInterface(remote) | 93 cri = cros_interface.CrOSInterface(remote) |
94 | 94 |
95 self.assertTrue(cri.IsServiceRunning('openssh-server')) | 95 self.assertTrue(cri.IsServiceRunning('openssh-server')) |
96 | 96 |
OLD | NEW |