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

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

Issue 1166113002: Add InstallSplitApk function to device utils. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
11 # pylint: disable=W0212 11 # pylint: disable=W0212
12 # pylint: disable=W0613 12 # pylint: disable=W0613
13 13
14 import collections 14 import collections
15 import datetime 15 import datetime
16 import logging 16 import logging
17 import os 17 import os
18 import re 18 import re
19 import sys 19 import sys
20 import unittest 20 import unittest
21 21
22 from pylib import android_commands 22 from pylib import android_commands
23 from pylib import cmd_helper 23 from pylib import cmd_helper
24 from pylib import constants 24 from pylib import constants
25 from pylib import device_signal 25 from pylib import device_signal
26 from pylib.device import adb_wrapper 26 from pylib.device import adb_wrapper
27 from pylib.device import device_errors 27 from pylib.device import device_errors
28 from pylib.device import device_utils 28 from pylib.device import device_utils
29 from pylib.device import intent 29 from pylib.device import intent
30 from pylib.device import split_select_wrapper
30 from pylib.utils import mock_calls 31 from pylib.utils import mock_calls
31 32
32 # RunCommand from third_party/android_testrunner/run_command.py is mocked 33 # RunCommand from third_party/android_testrunner/run_command.py is mocked
33 # below, so its path needs to be in sys.path. 34 # below, so its path needs to be in sys.path.
34 sys.path.append(os.path.join( 35 sys.path.append(os.path.join(
35 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) 36 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner'))
36 37
37 sys.path.append(os.path.join( 38 sys.path.append(os.path.join(
38 constants.DIR_SOURCE_ROOT, 'third_party', 'pymock')) 39 constants.DIR_SOURCE_ROOT, 'third_party', 'pymock'))
39 import mock # pylint: disable=F0401 40 import mock # pylint: disable=F0401
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 self.call.adb.Shell('echo $EXTERNAL_STORAGE'), '/fake/storage/path\n'): 304 self.call.adb.Shell('echo $EXTERNAL_STORAGE'), '/fake/storage/path\n'):
304 self.assertEquals('/fake/storage/path', 305 self.assertEquals('/fake/storage/path',
305 self.device.GetExternalStoragePath()) 306 self.device.GetExternalStoragePath())
306 307
307 def testGetExternalStoragePath_fails(self): 308 def testGetExternalStoragePath_fails(self):
308 with self.assertCall(self.call.adb.Shell('echo $EXTERNAL_STORAGE'), '\n'): 309 with self.assertCall(self.call.adb.Shell('echo $EXTERNAL_STORAGE'), '\n'):
309 with self.assertRaises(device_errors.CommandFailedError): 310 with self.assertRaises(device_errors.CommandFailedError):
310 self.device.GetExternalStoragePath() 311 self.device.GetExternalStoragePath()
311 312
312 313
313 class DeviceUtilsGetApplicationPathTest(DeviceUtilsTest): 314 class DeviceUtilsGetApplicationPathsTest(DeviceUtilsTest):
314 315
315 def testGetApplicationPath_exists(self): 316 def testGetApplicationPaths_exists(self):
316 with self.assertCalls( 317 with self.assertCalls(
317 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'), 318 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'),
318 (self.call.adb.Shell('pm path android'), 319 (self.call.adb.Shell('pm path android'),
319 'package:/path/to/android.apk\n')): 320 'package:/path/to/android.apk\n')):
320 self.assertEquals('/path/to/android.apk', 321 self.assertEquals(['/path/to/android.apk'],
321 self.device.GetApplicationPath('android')) 322 self.device.GetApplicationPaths('android'))
322 323
323 def testGetApplicationPath_notExists(self): 324 def testGetApplicationPaths_notExists(self):
324 with self.assertCalls( 325 with self.assertCalls(
325 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'), 326 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'),
326 (self.call.adb.Shell('pm path not.installed.app'), '')): 327 (self.call.adb.Shell('pm path not.installed.app'), '')):
327 self.assertEquals(None, 328 self.assertEquals([],
328 self.device.GetApplicationPath('not.installed.app')) 329 self.device.GetApplicationPaths('not.installed.app'))
329 330
330 def testGetApplicationPath_fails(self): 331 def testGetApplicationPaths_fails(self):
331 with self.assertCalls( 332 with self.assertCalls(
332 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'), 333 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'),
333 (self.call.adb.Shell('pm path android'), 334 (self.call.adb.Shell('pm path android'),
334 self.CommandError('ERROR. Is package manager running?\n'))): 335 self.CommandError('ERROR. Is package manager running?\n'))):
335 with self.assertRaises(device_errors.CommandFailedError): 336 with self.assertRaises(device_errors.CommandFailedError):
336 self.device.GetApplicationPath('android') 337 self.device.GetApplicationPaths('android')
337 338
338 339
339 class DeviceUtilsGetApplicationDataDirectoryTest(DeviceUtilsTest): 340 class DeviceUtilsGetApplicationDataDirectoryTest(DeviceUtilsTest):
340 341
341 def testGetApplicationDataDirectory_exists(self): 342 def testGetApplicationDataDirectory_exists(self):
342 with self.assertCall( 343 with self.assertCall(
343 self.call.device._RunPipedShellCommand( 344 self.call.device._RunPipedShellCommand(
344 'pm dump foo.bar.baz | grep dataDir='), 345 'pm dump foo.bar.baz | grep dataDir='),
345 ['dataDir=/data/data/foo.bar.baz']): 346 ['dataDir=/data/data/foo.bar.baz']):
346 self.assertEquals( 347 self.assertEquals(
(...skipping 11 matching lines...) Expand all
358 @mock.patch('time.sleep', mock.Mock()) 359 @mock.patch('time.sleep', mock.Mock())
359 class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsTest): 360 class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsTest):
360 361
361 def testWaitUntilFullyBooted_succeedsNoWifi(self): 362 def testWaitUntilFullyBooted_succeedsNoWifi(self):
362 with self.assertCalls( 363 with self.assertCalls(
363 self.call.adb.WaitForDevice(), 364 self.call.adb.WaitForDevice(),
364 # sd_card_ready 365 # sd_card_ready
365 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), 366 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'),
366 (self.call.adb.Shell('test -d /fake/storage/path'), ''), 367 (self.call.adb.Shell('test -d /fake/storage/path'), ''),
367 # pm_ready 368 # pm_ready
368 (self.call.device.GetApplicationPath('android'), 369 (self.call.device.GetApplicationPaths('android'),
369 'package:/some/fake/path'), 370 ['package:/some/fake/path']),
370 # boot_completed 371 # boot_completed
371 (self.call.device.GetProp('sys.boot_completed'), '1')): 372 (self.call.device.GetProp('sys.boot_completed'), '1')):
372 self.device.WaitUntilFullyBooted(wifi=False) 373 self.device.WaitUntilFullyBooted(wifi=False)
373 374
374 def testWaitUntilFullyBooted_succeedsWithWifi(self): 375 def testWaitUntilFullyBooted_succeedsWithWifi(self):
375 with self.assertCalls( 376 with self.assertCalls(
376 self.call.adb.WaitForDevice(), 377 self.call.adb.WaitForDevice(),
377 # sd_card_ready 378 # sd_card_ready
378 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), 379 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'),
379 (self.call.adb.Shell('test -d /fake/storage/path'), ''), 380 (self.call.adb.Shell('test -d /fake/storage/path'), ''),
380 # pm_ready 381 # pm_ready
381 (self.call.device.GetApplicationPath('android'), 382 (self.call.device.GetApplicationPaths('android'),
382 'package:/some/fake/path'), 383 ['package:/some/fake/path']),
383 # boot_completed 384 # boot_completed
384 (self.call.device.GetProp('sys.boot_completed'), '1'), 385 (self.call.device.GetProp('sys.boot_completed'), '1'),
385 # wifi_enabled 386 # wifi_enabled
386 (self.call.adb.Shell('dumpsys wifi'), 387 (self.call.adb.Shell('dumpsys wifi'),
387 'stuff\nWi-Fi is enabled\nmore stuff\n')): 388 'stuff\nWi-Fi is enabled\nmore stuff\n')):
388 self.device.WaitUntilFullyBooted(wifi=True) 389 self.device.WaitUntilFullyBooted(wifi=True)
389 390
390 def testWaitUntilFullyBooted_deviceNotInitiallyAvailable(self): 391 def testWaitUntilFullyBooted_deviceNotInitiallyAvailable(self):
391 with self.assertCalls( 392 with self.assertCalls(
392 self.call.adb.WaitForDevice(), 393 self.call.adb.WaitForDevice(),
393 # sd_card_ready 394 # sd_card_ready
394 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()), 395 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()),
395 # sd_card_ready 396 # sd_card_ready
396 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()), 397 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()),
397 # sd_card_ready 398 # sd_card_ready
398 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()), 399 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()),
399 # sd_card_ready 400 # sd_card_ready
400 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()), 401 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()),
401 # sd_card_ready 402 # sd_card_ready
402 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), 403 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'),
403 (self.call.adb.Shell('test -d /fake/storage/path'), ''), 404 (self.call.adb.Shell('test -d /fake/storage/path'), ''),
404 # pm_ready 405 # pm_ready
405 (self.call.device.GetApplicationPath('android'), 406 (self.call.device.GetApplicationPaths('android'),
406 'package:/some/fake/path'), 407 ['package:/some/fake/path']),
407 # boot_completed 408 # boot_completed
408 (self.call.device.GetProp('sys.boot_completed'), '1')): 409 (self.call.device.GetProp('sys.boot_completed'), '1')):
409 self.device.WaitUntilFullyBooted(wifi=False) 410 self.device.WaitUntilFullyBooted(wifi=False)
410 411
411 def testWaitUntilFullyBooted_sdCardReadyFails_noPath(self): 412 def testWaitUntilFullyBooted_sdCardReadyFails_noPath(self):
412 with self.assertCalls( 413 with self.assertCalls(
413 self.call.adb.WaitForDevice(), 414 self.call.adb.WaitForDevice(),
414 # sd_card_ready 415 # sd_card_ready
415 (self.call.device.GetExternalStoragePath(), self.CommandError())): 416 (self.call.device.GetExternalStoragePath(), self.CommandError())):
416 with self.assertRaises(device_errors.CommandFailedError): 417 with self.assertRaises(device_errors.CommandFailedError):
(...skipping 15 matching lines...) Expand all
432 with self.assertRaises(device_errors.CommandTimeoutError): 433 with self.assertRaises(device_errors.CommandTimeoutError):
433 self.device.WaitUntilFullyBooted(wifi=False) 434 self.device.WaitUntilFullyBooted(wifi=False)
434 435
435 def testWaitUntilFullyBooted_devicePmFails(self): 436 def testWaitUntilFullyBooted_devicePmFails(self):
436 with self.assertCalls( 437 with self.assertCalls(
437 self.call.adb.WaitForDevice(), 438 self.call.adb.WaitForDevice(),
438 # sd_card_ready 439 # sd_card_ready
439 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), 440 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'),
440 (self.call.adb.Shell('test -d /fake/storage/path'), ''), 441 (self.call.adb.Shell('test -d /fake/storage/path'), ''),
441 # pm_ready 442 # pm_ready
442 (self.call.device.GetApplicationPath('android'), self.CommandError()), 443 (self.call.device.GetApplicationPaths('android'), self.CommandError()),
443 # pm_ready 444 # pm_ready
444 (self.call.device.GetApplicationPath('android'), self.CommandError()), 445 (self.call.device.GetApplicationPaths('android'), self.CommandError()),
445 # pm_ready 446 # pm_ready
446 (self.call.device.GetApplicationPath('android'), self.TimeoutError())): 447 (self.call.device.GetApplicationPaths('android'), self.TimeoutError())):
447 with self.assertRaises(device_errors.CommandTimeoutError): 448 with self.assertRaises(device_errors.CommandTimeoutError):
448 self.device.WaitUntilFullyBooted(wifi=False) 449 self.device.WaitUntilFullyBooted(wifi=False)
449 450
450 def testWaitUntilFullyBooted_bootFails(self): 451 def testWaitUntilFullyBooted_bootFails(self):
451 with self.assertCalls( 452 with self.assertCalls(
452 self.call.adb.WaitForDevice(), 453 self.call.adb.WaitForDevice(),
453 # sd_card_ready 454 # sd_card_ready
454 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), 455 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'),
455 (self.call.adb.Shell('test -d /fake/storage/path'), ''), 456 (self.call.adb.Shell('test -d /fake/storage/path'), ''),
456 # pm_ready 457 # pm_ready
457 (self.call.device.GetApplicationPath('android'), 458 (self.call.device.GetApplicationPaths('android'),
458 'package:/some/fake/path'), 459 ['package:/some/fake/path']),
459 # boot_completed 460 # boot_completed
460 (self.call.device.GetProp('sys.boot_completed'), '0'), 461 (self.call.device.GetProp('sys.boot_completed'), '0'),
461 # boot_completed 462 # boot_completed
462 (self.call.device.GetProp('sys.boot_completed'), '0'), 463 (self.call.device.GetProp('sys.boot_completed'), '0'),
463 # boot_completed 464 # boot_completed
464 (self.call.device.GetProp('sys.boot_completed'), self.TimeoutError())): 465 (self.call.device.GetProp('sys.boot_completed'), self.TimeoutError())):
465 with self.assertRaises(device_errors.CommandTimeoutError): 466 with self.assertRaises(device_errors.CommandTimeoutError):
466 self.device.WaitUntilFullyBooted(wifi=False) 467 self.device.WaitUntilFullyBooted(wifi=False)
467 468
468 def testWaitUntilFullyBooted_wifiFails(self): 469 def testWaitUntilFullyBooted_wifiFails(self):
469 with self.assertCalls( 470 with self.assertCalls(
470 self.call.adb.WaitForDevice(), 471 self.call.adb.WaitForDevice(),
471 # sd_card_ready 472 # sd_card_ready
472 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), 473 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'),
473 (self.call.adb.Shell('test -d /fake/storage/path'), ''), 474 (self.call.adb.Shell('test -d /fake/storage/path'), ''),
474 # pm_ready 475 # pm_ready
475 (self.call.device.GetApplicationPath('android'), 476 (self.call.device.GetApplicationPaths('android'),
476 'package:/some/fake/path'), 477 ['package:/some/fake/path']),
477 # boot_completed 478 # boot_completed
478 (self.call.device.GetProp('sys.boot_completed'), '1'), 479 (self.call.device.GetProp('sys.boot_completed'), '1'),
479 # wifi_enabled 480 # wifi_enabled
480 (self.call.adb.Shell('dumpsys wifi'), 'stuff\nmore stuff\n'), 481 (self.call.adb.Shell('dumpsys wifi'), 'stuff\nmore stuff\n'),
481 # wifi_enabled 482 # wifi_enabled
482 (self.call.adb.Shell('dumpsys wifi'), 'stuff\nmore stuff\n'), 483 (self.call.adb.Shell('dumpsys wifi'), 'stuff\nmore stuff\n'),
483 # wifi_enabled 484 # wifi_enabled
484 (self.call.adb.Shell('dumpsys wifi'), self.TimeoutError())): 485 (self.call.adb.Shell('dumpsys wifi'), self.TimeoutError())):
485 with self.assertRaises(device_errors.CommandTimeoutError): 486 with self.assertRaises(device_errors.CommandTimeoutError):
486 self.device.WaitUntilFullyBooted(wifi=True) 487 self.device.WaitUntilFullyBooted(wifi=True)
(...skipping 25 matching lines...) Expand all
512 self.call.device.WaitUntilFullyBooted(wifi=True)): 513 self.call.device.WaitUntilFullyBooted(wifi=True)):
513 self.device.Reboot(block=True, wifi=True) 514 self.device.Reboot(block=True, wifi=True)
514 515
515 516
516 class DeviceUtilsInstallTest(DeviceUtilsTest): 517 class DeviceUtilsInstallTest(DeviceUtilsTest):
517 518
518 def testInstall_noPriorInstall(self): 519 def testInstall_noPriorInstall(self):
519 with self.assertCalls( 520 with self.assertCalls(
520 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), 521 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'),
521 'this.is.a.test.package'), 522 'this.is.a.test.package'),
522 (self.call.device.GetApplicationPath('this.is.a.test.package'), None), 523 (self.call.device.GetApplicationPaths('this.is.a.test.package'), []),
523 self.call.adb.Install('/fake/test/app.apk', reinstall=False)): 524 self.call.adb.Install('/fake/test/app.apk', reinstall=False)):
524 self.device.Install('/fake/test/app.apk', retries=0) 525 self.device.Install('/fake/test/app.apk', retries=0)
525 526
526 def testInstall_differentPriorInstall(self): 527 def testInstall_differentPriorInstall(self):
527 with self.assertCalls( 528 with self.assertCalls(
528 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), 529 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'),
529 'this.is.a.test.package'), 530 'this.is.a.test.package'),
530 (self.call.device.GetApplicationPath('this.is.a.test.package'), 531 (self.call.device.GetApplicationPaths('this.is.a.test.package'),
531 '/fake/data/app/this.is.a.test.package.apk'), 532 ['/fake/data/app/this.is.a.test.package.apk']),
532 (self.call.device._GetChangedAndStaleFiles( 533 (self.call.device._GetChangedAndStaleFiles(
533 '/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk'), 534 '/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk'),
534 ([('/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk')], 535 ([('/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk')],
535 [])), 536 [])),
536 self.call.adb.Uninstall('this.is.a.test.package'), 537 self.call.adb.Uninstall('this.is.a.test.package'),
537 self.call.adb.Install('/fake/test/app.apk', reinstall=False)): 538 self.call.adb.Install('/fake/test/app.apk', reinstall=False)):
538 self.device.Install('/fake/test/app.apk', retries=0) 539 self.device.Install('/fake/test/app.apk', retries=0)
539 540
540 def testInstall_differentPriorInstall_reinstall(self): 541 def testInstall_differentPriorInstall_reinstall(self):
541 with self.assertCalls( 542 with self.assertCalls(
542 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), 543 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'),
543 'this.is.a.test.package'), 544 'this.is.a.test.package'),
544 (self.call.device.GetApplicationPath('this.is.a.test.package'), 545 (self.call.device.GetApplicationPaths('this.is.a.test.package'),
545 '/fake/data/app/this.is.a.test.package.apk'), 546 ['/fake/data/app/this.is.a.test.package.apk']),
546 (self.call.device._GetChangedAndStaleFiles( 547 (self.call.device._GetChangedAndStaleFiles(
547 '/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk'), 548 '/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk'),
548 ([('/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk')], 549 ([('/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk')],
549 [])), 550 [])),
550 self.call.adb.Install('/fake/test/app.apk', reinstall=True)): 551 self.call.adb.Install('/fake/test/app.apk', reinstall=True)):
551 self.device.Install('/fake/test/app.apk', reinstall=True, retries=0) 552 self.device.Install('/fake/test/app.apk', reinstall=True, retries=0)
552 553
553 def testInstall_identicalPriorInstall(self): 554 def testInstall_identicalPriorInstall(self):
554 with self.assertCalls( 555 with self.assertCalls(
555 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), 556 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'),
556 'this.is.a.test.package'), 557 'this.is.a.test.package'),
557 (self.call.device.GetApplicationPath('this.is.a.test.package'), 558 (self.call.device.GetApplicationPaths('this.is.a.test.package'),
558 '/fake/data/app/this.is.a.test.package.apk'), 559 ['/fake/data/app/this.is.a.test.package.apk']),
559 (self.call.device._GetChangedAndStaleFiles( 560 (self.call.device._GetChangedAndStaleFiles(
560 '/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk'), 561 '/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk'),
561 ([], []))): 562 ([], []))):
562 self.device.Install('/fake/test/app.apk', retries=0) 563 self.device.Install('/fake/test/app.apk', retries=0)
563 564
564 def testInstall_fails(self): 565 def testInstall_fails(self):
565 with self.assertCalls( 566 with self.assertCalls(
566 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), 567 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'),
567 'this.is.a.test.package'), 568 'this.is.a.test.package'),
568 (self.call.device.GetApplicationPath('this.is.a.test.package'), None), 569 (self.call.device.GetApplicationPaths('this.is.a.test.package'), []),
569 (self.call.adb.Install('/fake/test/app.apk', reinstall=False), 570 (self.call.adb.Install('/fake/test/app.apk', reinstall=False),
570 self.CommandError('Failure\r\n'))): 571 self.CommandError('Failure\r\n'))):
571 with self.assertRaises(device_errors.CommandFailedError): 572 with self.assertRaises(device_errors.CommandFailedError):
572 self.device.Install('/fake/test/app.apk', retries=0) 573 self.device.Install('/fake/test/app.apk', retries=0)
573 574
575 class DeviceUtilsInstallSplitApkTest(DeviceUtilsTest):
576
577 def testInstallSplitApk_noPriorInstall(self):
agrieve 2015/06/18 20:28:50 might want to add a test when partial != None
mikecase (-- gone --) 2015/06/19 17:17:52 Done. Added new test for partial install.
578 with self.assertCalls(
579 (self.call.device._CheckSdkLevel(21)),
580 (mock.call.pylib.device.split_select_wrapper.SelectSplits(
581 self.device, 'base.apk',
582 ['split1.apk', 'split2.apk', 'split3.apk']),
583 ['split2.apk']),
584 (mock.call.pylib.utils.apk_helper.GetPackageName('base.apk'),
585 'this.is.a.test.package'),
586 (self.call.device.GetApplicationPaths('this.is.a.test.package'), []),
587 (self.call.adb.InstallMultiple(
588 ['base.apk', 'split2.apk'], partial=None, reinstall=False))):
589 self.device.InstallSplitApk('base.apk',
590 ['split1.apk', 'split2.apk', 'split3.apk'], retries=0)
591
574 592
575 class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): 593 class DeviceUtilsRunShellCommandTest(DeviceUtilsTest):
576 594
577 def setUp(self): 595 def setUp(self):
578 super(DeviceUtilsRunShellCommandTest, self).setUp() 596 super(DeviceUtilsRunShellCommandTest, self).setUp()
579 self.device.NeedsSU = mock.Mock(return_value=False) 597 self.device.NeedsSU = mock.Mock(return_value=False)
580 598
581 def testRunShellCommand_commandAsList(self): 599 def testRunShellCommand_commandAsList(self):
582 with self.assertCall(self.call.adb.Shell('pm list packages'), ''): 600 with self.assertCall(self.call.adb.Shell('pm list packages'), ''):
583 self.device.RunShellCommand(['pm', 'list', 'packages']) 601 self.device.RunShellCommand(['pm', 'list', 'packages'])
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 self.call.adb.Shell('am force-stop this.is.a.test.package'), 1092 self.call.adb.Shell('am force-stop this.is.a.test.package'),
1075 ''): 1093 ''):
1076 self.device.ForceStop('this.is.a.test.package') 1094 self.device.ForceStop('this.is.a.test.package')
1077 1095
1078 1096
1079 class DeviceUtilsClearApplicationStateTest(DeviceUtilsTest): 1097 class DeviceUtilsClearApplicationStateTest(DeviceUtilsTest):
1080 1098
1081 def testClearApplicationState_packageDoesntExist(self): 1099 def testClearApplicationState_packageDoesntExist(self):
1082 with self.assertCalls( 1100 with self.assertCalls(
1083 (self.call.adb.Shell('getprop ro.build.version.sdk'), '17\n'), 1101 (self.call.adb.Shell('getprop ro.build.version.sdk'), '17\n'),
1084 (self.call.device.GetApplicationPath('this.package.does.not.exist'), 1102 (self.call.device.GetApplicationPaths('this.package.does.not.exist'),
1085 None)): 1103 [])):
1086 self.device.ClearApplicationState('this.package.does.not.exist') 1104 self.device.ClearApplicationState('this.package.does.not.exist')
1087 1105
1088 def testClearApplicationState_packageDoesntExistOnAndroidJBMR2OrAbove(self): 1106 def testClearApplicationState_packageDoesntExistOnAndroidJBMR2OrAbove(self):
1089 with self.assertCalls( 1107 with self.assertCalls(
1090 (self.call.adb.Shell('getprop ro.build.version.sdk'), '18\n'), 1108 (self.call.adb.Shell('getprop ro.build.version.sdk'), '18\n'),
1091 (self.call.adb.Shell('pm clear this.package.does.not.exist'), 1109 (self.call.adb.Shell('pm clear this.package.does.not.exist'),
1092 'Failed\r\n')): 1110 'Failed\r\n')):
1093 self.device.ClearApplicationState('this.package.does.not.exist') 1111 self.device.ClearApplicationState('this.package.does.not.exist')
1094 1112
1095 def testClearApplicationState_packageExists(self): 1113 def testClearApplicationState_packageExists(self):
1096 with self.assertCalls( 1114 with self.assertCalls(
1097 (self.call.adb.Shell('getprop ro.build.version.sdk'), '17\n'), 1115 (self.call.adb.Shell('getprop ro.build.version.sdk'), '17\n'),
1098 (self.call.device.GetApplicationPath('this.package.exists'), 1116 (self.call.device.GetApplicationPaths('this.package.exists'),
1099 '/data/app/this.package.exists.apk'), 1117 ['/data/app/this.package.exists.apk']),
1100 (self.call.adb.Shell('pm clear this.package.exists'), 1118 (self.call.adb.Shell('pm clear this.package.exists'),
1101 'Success\r\n')): 1119 'Success\r\n')):
1102 self.device.ClearApplicationState('this.package.exists') 1120 self.device.ClearApplicationState('this.package.exists')
1103 1121
1104 def testClearApplicationState_packageExistsOnAndroidJBMR2OrAbove(self): 1122 def testClearApplicationState_packageExistsOnAndroidJBMR2OrAbove(self):
1105 with self.assertCalls( 1123 with self.assertCalls(
1106 (self.call.adb.Shell('getprop ro.build.version.sdk'), '18\n'), 1124 (self.call.adb.Shell('getprop ro.build.version.sdk'), '18\n'),
1107 (self.call.adb.Shell('pm clear this.package.exists'), 1125 (self.call.adb.Shell('pm clear this.package.exists'),
1108 'Success\r\n')): 1126 'Success\r\n')):
1109 self.device.ClearApplicationState('this.package.exists') 1127 self.device.ClearApplicationState('this.package.exists')
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
1721 devices = device_utils.DeviceUtils.HealthyDevices() 1739 devices = device_utils.DeviceUtils.HealthyDevices()
1722 self.assertEquals(1, len(devices)) 1740 self.assertEquals(1, len(devices))
1723 self.assertTrue(isinstance(devices[0], device_utils.DeviceUtils)) 1741 self.assertTrue(isinstance(devices[0], device_utils.DeviceUtils))
1724 self.assertEquals('0123456789abcdef', devices[0].adb.GetDeviceSerial()) 1742 self.assertEquals('0123456789abcdef', devices[0].adb.GetDeviceSerial())
1725 1743
1726 1744
1727 if __name__ == '__main__': 1745 if __name__ == '__main__':
1728 logging.getLogger().setLevel(logging.DEBUG) 1746 logging.getLogger().setLevel(logging.DEBUG)
1729 unittest.main(verbosity=2) 1747 unittest.main(verbosity=2)
1730 1748
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698