OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 """Tests for the AdbWrapper class.""" | 5 """Tests for the AdbWrapper class.""" |
6 | 6 |
7 import os | 7 import os |
8 import tempfile | 8 import tempfile |
9 import time | 9 import time |
10 import unittest | 10 import unittest |
(...skipping 23 matching lines...) Expand all Loading... |
34 fi, path = tempfile.mkstemp() | 34 fi, path = tempfile.mkstemp() |
35 with os.fdopen(fi, 'wb') as f: | 35 with os.fdopen(fi, 'wb') as f: |
36 f.write(contents) | 36 f.write(contents) |
37 return path | 37 return path |
38 | 38 |
39 def testShell(self): | 39 def testShell(self): |
40 output = self._adb.Shell('echo test', expect_rc=0) | 40 output = self._adb.Shell('echo test', expect_rc=0) |
41 self.assertEqual(output.strip(), 'test') | 41 self.assertEqual(output.strip(), 'test') |
42 output = self._adb.Shell('echo test') | 42 output = self._adb.Shell('echo test') |
43 self.assertEqual(output.strip(), 'test') | 43 self.assertEqual(output.strip(), 'test') |
44 self.assertRaises(device_errors.CommandFailedError, self._adb.Shell, | 44 self.assertRaises(device_errors.AdbCommandFailedError, self._adb.Shell, |
45 'echo test', expect_rc=1) | 45 'echo test', expect_rc=1) |
46 | 46 |
47 def testPushPull(self): | 47 def testPushPull(self): |
48 path = self._MakeTempFile('foo') | 48 path = self._MakeTempFile('foo') |
49 device_path = '/data/local/tmp/testfile.txt' | 49 device_path = '/data/local/tmp/testfile.txt' |
50 local_tmpdir = os.path.dirname(path) | 50 local_tmpdir = os.path.dirname(path) |
51 self._adb.Push(path, device_path) | 51 self._adb.Push(path, device_path) |
52 self.assertEqual(self._adb.Shell('cat %s' % device_path), 'foo') | 52 self.assertEqual(self._adb.Shell('cat %s' % device_path), 'foo') |
53 self._adb.Pull(device_path, local_tmpdir) | 53 self._adb.Pull(device_path, local_tmpdir) |
54 with open(os.path.join(local_tmpdir, 'testfile.txt'), 'r') as f: | 54 with open(os.path.join(local_tmpdir, 'testfile.txt'), 'r') as f: |
55 self.assertEqual(f.read(), 'foo') | 55 self.assertEqual(f.read(), 'foo') |
56 | 56 |
57 def testInstall(self): | 57 def testInstall(self): |
58 path = self._MakeTempFile('foo') | 58 path = self._MakeTempFile('foo') |
59 self.assertRaises(device_errors.CommandFailedError, self._adb.Install, path) | 59 self.assertRaises(device_errors.AdbCommandFailedError, self._adb.Install, |
| 60 path) |
60 | 61 |
61 def testForward(self): | 62 def testForward(self): |
62 self.assertRaises(device_errors.CommandFailedError, self._adb.Forward, 0, 0) | 63 self.assertRaises(device_errors.AdbCommandFailedError, self._adb.Forward, |
| 64 0, 0) |
63 | 65 |
64 def testUninstall(self): | 66 def testUninstall(self): |
65 self.assertRaises(device_errors.CommandFailedError, self._adb.Uninstall, | 67 self.assertRaises(device_errors.AdbCommandFailedError, self._adb.Uninstall, |
66 'some.nonexistant.package') | 68 'some.nonexistant.package') |
67 | 69 |
68 def testRebootWaitForDevice(self): | 70 def testRebootWaitForDevice(self): |
69 self._adb.Reboot() | 71 self._adb.Reboot() |
70 print 'waiting for device to reboot...' | 72 print 'waiting for device to reboot...' |
71 while self._adb.GetState() == 'device': | 73 while self._adb.GetState() == 'device': |
72 time.sleep(1) | 74 time.sleep(1) |
73 self._adb.WaitForDevice() | 75 self._adb.WaitForDevice() |
74 self.assertEqual(self._adb.GetState(), 'device') | 76 self.assertEqual(self._adb.GetState(), 'device') |
75 print 'waiting for package manager...' | 77 print 'waiting for package manager...' |
76 while 'package:' not in self._adb.Shell('pm path android'): | 78 while 'package:' not in self._adb.Shell('pm path android'): |
77 time.sleep(1) | 79 time.sleep(1) |
78 | 80 |
79 def testRootRemount(self): | 81 def testRootRemount(self): |
80 self._adb.Root() | 82 self._adb.Root() |
81 while True: | 83 while True: |
82 try: | 84 try: |
83 self._adb.Shell('start') | 85 self._adb.Shell('start') |
84 break | 86 break |
85 except device_errors.CommandFailedError: | 87 except device_errors.AdbCommandFailedError: |
86 time.sleep(1) | 88 time.sleep(1) |
87 self._adb.Remount() | 89 self._adb.Remount() |
88 | 90 |
89 | 91 |
90 if __name__ == '__main__': | 92 if __name__ == '__main__': |
91 unittest.main() | 93 unittest.main() |
OLD | NEW |