Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: build/android/pylib/device/adb_wrapper_test.py

Issue 64553012: [android] Adds AdbWrapper which is the base of the eventual AndroidCommands replacement. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added chromium header to test file Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright (c) 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 """Tests for the AdbWrapper class."""
6
7 import os
8 import socket
9 import tempfile
10 import time
11 import unittest
12
13 import adb_wrapper
14
15
16 class TestAdbWrapper(unittest.TestCase):
17
18 def setUp(self):
19 devices = adb_wrapper.AdbWrapper.GetDevices()
20 assert devices, 'A device must be attached'
21 self._adb = devices[0]
22 self._adb.WaitForDevice()
23
24 def _MakeTempFile(self, contents):
25 """Make a temporary file with the given contents.
26
27 Args:
28 contents: string to write to the temporary file.
29
30 Returns:
31 The absolute path to the file.
32 """
33 fi, path = tempfile.mkstemp()
34 with os.fdopen(fi, 'wb') as f:
35 f.write('foo')
36 return path
37
38 def testShell(self):
39 output = self._adb.Shell('echo test', expect_rc=0)
frankf 2013/11/27 23:35:03 also test the failure case
craigdh 2013/11/28 00:51:55 Done.
40 self.assertEqual(output.strip(), 'test')
41 output = self._adb.Shell('echo test')
42 self.assertEqual(output.strip(), 'test')
43
44 def testPushPull(self):
45 path = self._MakeTempFile('foo')
46 device_path = '/data/local/tmp/testfile.txt'
47 local_tmpdir = os.path.dirname(path)
48 self._adb.Push(path, device_path)
49 self.assertEqual(self._adb.Shell('cat %s' % device_path), 'foo')
50 self._adb.Pull(device_path, local_tmpdir)
51 with open(os.path.join(local_tmpdir, 'testfile.txt'), 'r') as f:
52 self.assertEqual(f.read(), 'foo')
53
54 def testInstall(self):
55 path = self._MakeTempFile('foo')
56 self.assertRaises(adb_wrapper.CommandFailedError, self._adb.Install, path)
57
58 def testForward(self):
59 self.assertRaises(adb_wrapper.CommandFailedError, self._adb.Forward, 0, 0)
60
61 def testLogcat(self):
62 self.assertRaises(adb_wrapper.CommandTimeoutError, self._adb.Logcat,
frankf 2013/11/27 23:35:03 I'd remove this test case
craigdh 2013/11/28 00:51:55 Done.
63 timeout=0.1, retries=0)
64
65 def testUninstall(self):
66 self.assertRaises(adb_wrapper.CommandFailedError, self._adb.Uninstall,
67 'some.nonexistant.package')
68
69 def testRebootWaitForDevice(self):
70 self._adb.Reboot()
71 print 'waiting for device to reboot...'
72 while self._adb.GetState() == 'device':
73 time.sleep(1)
74 self._adb.WaitForDevice()
75 self.assertEqual(self._adb.GetState(), 'device')
76 print 'waiting for package manager...'
77 while 'package:' not in self._adb.Shell('pm path android'):
78 time.sleep(1)
79
80 def testRootRemount(self):
81 self._adb.Root()
82 while True:
83 try:
84 self._adb.Shell('start')
85 break
86 except adb_wrapper.CommandFailedError:
87 time.sleep(1)
88 self._adb.Remount()
89
90
91 if __name__ == '__main__':
92 unittest.main()
OLDNEW
« build/android/pylib/device/adb_wrapper.py ('K') | « build/android/pylib/device/adb_wrapper.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698