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

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

Issue 1315603002: [Android] Add DeviceUtils.GetApplicationVersion (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months 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
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """ 6 """
7 Unit tests for the contents of device_utils.py (mostly DeviceUtils). 7 Unit tests for the contents of device_utils.py (mostly DeviceUtils).
8 """ 8 """
9 9
10 # pylint: disable=C0321 10 # pylint: disable=C0321
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 318
319 def test_GetApplicationPathsInternal_fails(self): 319 def test_GetApplicationPathsInternal_fails(self):
320 with self.assertCalls( 320 with self.assertCalls(
321 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'), 321 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'),
322 (self.call.adb.Shell('pm path android'), 322 (self.call.adb.Shell('pm path android'),
323 self.CommandError('ERROR. Is package manager running?\n'))): 323 self.CommandError('ERROR. Is package manager running?\n'))):
324 with self.assertRaises(device_errors.CommandFailedError): 324 with self.assertRaises(device_errors.CommandFailedError):
325 self.device._GetApplicationPathsInternal('android') 325 self.device._GetApplicationPathsInternal('android')
326 326
327 327
328 class DeviceUtils_GetApplicationVersionTest(DeviceUtilsTest):
329
330 def test_GetApplicationVersion_exists(self):
331 with self.assertCalls(
332 (self.call.adb.Shell('dumpsys package com.android.chrome'),
333 'Packages:\n'
334 ' Package [com.android.chrome] (3901ecfb):\n'
335 ' userId=1234 gids=[123, 456, 789]\n'
336 ' pkg=Package{1fecf634 com.android.chrome}\n'
337 ' versionName=45.0.1234.7\n')):
338 self.assertEquals('45.0.1234.7',
339 self.device.GetApplicationVersion('com.android.chrome'))
340
341 def test_GetApplicationVersion_notExists(self):
342 with self.assertCalls(
343 (self.call.adb.Shell('dumpsys package com.android.chrome'), '')):
344 self.assertEquals(None,
345 self.device.GetApplicationVersion('com.android.chrome'))
346
347 def test_GetApplicationVersion_fails(self):
348 with self.assertCalls(
349 (self.call.adb.Shell('dumpsys package com.android.chrome'),
350 'Packages:\n'
351 ' Package [com.android.chrome] (3901ecfb):\n'
352 ' userId=1234 gids=[123, 456, 789]\n'
353 ' pkg=Package{1fecf634 com.android.chrome}\n')):
354 with self.assertRaises(device_errors.CommandFailedError):
355 self.device.GetApplicationVersion('com.android.chrome')
356
357
328 class DeviceUtilsGetApplicationDataDirectoryTest(DeviceUtilsTest): 358 class DeviceUtilsGetApplicationDataDirectoryTest(DeviceUtilsTest):
329 359
330 def testGetApplicationDataDirectory_exists(self): 360 def testGetApplicationDataDirectory_exists(self):
331 with self.assertCall( 361 with self.assertCall(
332 self.call.device._RunPipedShellCommand( 362 self.call.device._RunPipedShellCommand(
333 'pm dump foo.bar.baz | grep dataDir='), 363 'pm dump foo.bar.baz | grep dataDir='),
334 ['dataDir=/data/data/foo.bar.baz']): 364 ['dataDir=/data/data/foo.bar.baz']):
335 self.assertEquals( 365 self.assertEquals(
336 '/data/data/foo.bar.baz', 366 '/data/data/foo.bar.baz',
337 self.device.GetApplicationDataDirectory('foo.bar.baz')) 367 self.device.GetApplicationDataDirectory('foo.bar.baz'))
(...skipping 1591 matching lines...) Expand 10 before | Expand all | Expand 10 after
1929 self.call.device.WriteFile(mock.ANY, mock.ANY), 1959 self.call.device.WriteFile(mock.ANY, mock.ANY),
1930 (self.call.device.RunShellCommand( 1960 (self.call.device.RunShellCommand(
1931 ['source', mock_temp_file ], as_root=True)), 1961 ['source', mock_temp_file ], as_root=True)),
1932 self.call.adb.WaitForDevice()): 1962 self.call.adb.WaitForDevice()):
1933 self.device.RestartAdbd() 1963 self.device.RestartAdbd()
1934 1964
1935 1965
1936 if __name__ == '__main__': 1966 if __name__ == '__main__':
1937 logging.getLogger().setLevel(logging.DEBUG) 1967 logging.getLogger().setLevel(logging.DEBUG)
1938 unittest.main(verbosity=2) 1968 unittest.main(verbosity=2)
OLDNEW
« build/android/pylib/device/device_utils.py ('K') | « build/android/pylib/device/device_utils.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698