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

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

Issue 1289503002: Add device md5sum caching to device_utils.py (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « build/android/pylib/device/device_utils.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 self.call.adb.Shell('echo $EXTERNAL_STORAGE'), '/fake/storage/path\n'): 304 self.call.adb.Shell('echo $EXTERNAL_STORAGE'), '/fake/storage/path\n'):
305 self.assertEquals('/fake/storage/path', 305 self.assertEquals('/fake/storage/path',
306 self.device.GetExternalStoragePath()) 306 self.device.GetExternalStoragePath())
307 307
308 def testGetExternalStoragePath_fails(self): 308 def testGetExternalStoragePath_fails(self):
309 with self.assertCall(self.call.adb.Shell('echo $EXTERNAL_STORAGE'), '\n'): 309 with self.assertCall(self.call.adb.Shell('echo $EXTERNAL_STORAGE'), '\n'):
310 with self.assertRaises(device_errors.CommandFailedError): 310 with self.assertRaises(device_errors.CommandFailedError):
311 self.device.GetExternalStoragePath() 311 self.device.GetExternalStoragePath()
312 312
313 313
314 class DeviceUtilsGetApplicationPathsTest(DeviceUtilsTest): 314 class DeviceUtils_GetApplicationPathsInternalTest(DeviceUtilsTest):
315 315
316 def testGetApplicationPaths_exists(self): 316 def test_GetApplicationPathsInternal_exists(self):
317 with self.assertCalls( 317 with self.assertCalls(
318 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'), 318 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'),
319 (self.call.adb.Shell('pm path android'), 319 (self.call.adb.Shell('pm path android'),
320 'package:/path/to/android.apk\n')): 320 'package:/path/to/android.apk\n')):
321 self.assertEquals(['/path/to/android.apk'], 321 self.assertEquals(['/path/to/android.apk'],
322 self.device.GetApplicationPaths('android')) 322 self.device._GetApplicationPathsInternal('android'))
323 323
324 def testGetApplicationPaths_notExists(self): 324 def test_GetApplicationPathsInternal_notExists(self):
325 with self.assertCalls( 325 with self.assertCalls(
326 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'), 326 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'),
327 (self.call.adb.Shell('pm path not.installed.app'), '')): 327 (self.call.adb.Shell('pm path not.installed.app'), '')):
328 self.assertEquals([], 328 self.assertEquals([],
329 self.device.GetApplicationPaths('not.installed.app')) 329 self.device._GetApplicationPathsInternal('not.installed.app'))
330 330
331 def testGetApplicationPaths_fails(self): 331 def test_GetApplicationPathsInternal_fails(self):
332 with self.assertCalls( 332 with self.assertCalls(
333 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'), 333 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'),
334 (self.call.adb.Shell('pm path android'), 334 (self.call.adb.Shell('pm path android'),
335 self.CommandError('ERROR. Is package manager running?\n'))): 335 self.CommandError('ERROR. Is package manager running?\n'))):
336 with self.assertRaises(device_errors.CommandFailedError): 336 with self.assertRaises(device_errors.CommandFailedError):
337 self.device.GetApplicationPaths('android') 337 self.device._GetApplicationPathsInternal('android')
338 338
339 339
340 class DeviceUtilsGetApplicationDataDirectoryTest(DeviceUtilsTest): 340 class DeviceUtilsGetApplicationDataDirectoryTest(DeviceUtilsTest):
341 341
342 def testGetApplicationDataDirectory_exists(self): 342 def testGetApplicationDataDirectory_exists(self):
343 with self.assertCall( 343 with self.assertCall(
344 self.call.device._RunPipedShellCommand( 344 self.call.device._RunPipedShellCommand(
345 'pm dump foo.bar.baz | grep dataDir='), 345 'pm dump foo.bar.baz | grep dataDir='),
346 ['dataDir=/data/data/foo.bar.baz']): 346 ['dataDir=/data/data/foo.bar.baz']):
347 self.assertEquals( 347 self.assertEquals(
(...skipping 11 matching lines...) Expand all
359 @mock.patch('time.sleep', mock.Mock()) 359 @mock.patch('time.sleep', mock.Mock())
360 class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsTest): 360 class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsTest):
361 361
362 def testWaitUntilFullyBooted_succeedsNoWifi(self): 362 def testWaitUntilFullyBooted_succeedsNoWifi(self):
363 with self.assertCalls( 363 with self.assertCalls(
364 self.call.adb.WaitForDevice(), 364 self.call.adb.WaitForDevice(),
365 # sd_card_ready 365 # sd_card_ready
366 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), 366 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'),
367 (self.call.adb.Shell('test -d /fake/storage/path'), ''), 367 (self.call.adb.Shell('test -d /fake/storage/path'), ''),
368 # pm_ready 368 # pm_ready
369 (self.call.device.GetApplicationPaths('android'), 369 (self.call.device._GetApplicationPathsInternal('android',
370 skip_cache=True),
370 ['package:/some/fake/path']), 371 ['package:/some/fake/path']),
371 # boot_completed 372 # boot_completed
372 (self.call.device.GetProp('sys.boot_completed'), '1')): 373 (self.call.device.GetProp('sys.boot_completed'), '1')):
373 self.device.WaitUntilFullyBooted(wifi=False) 374 self.device.WaitUntilFullyBooted(wifi=False)
374 375
375 def testWaitUntilFullyBooted_succeedsWithWifi(self): 376 def testWaitUntilFullyBooted_succeedsWithWifi(self):
376 with self.assertCalls( 377 with self.assertCalls(
377 self.call.adb.WaitForDevice(), 378 self.call.adb.WaitForDevice(),
378 # sd_card_ready 379 # sd_card_ready
379 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), 380 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'),
380 (self.call.adb.Shell('test -d /fake/storage/path'), ''), 381 (self.call.adb.Shell('test -d /fake/storage/path'), ''),
381 # pm_ready 382 # pm_ready
382 (self.call.device.GetApplicationPaths('android'), 383 (self.call.device._GetApplicationPathsInternal('android',
384 skip_cache=True),
383 ['package:/some/fake/path']), 385 ['package:/some/fake/path']),
384 # boot_completed 386 # boot_completed
385 (self.call.device.GetProp('sys.boot_completed'), '1'), 387 (self.call.device.GetProp('sys.boot_completed'), '1'),
386 # wifi_enabled 388 # wifi_enabled
387 (self.call.adb.Shell('dumpsys wifi'), 389 (self.call.adb.Shell('dumpsys wifi'),
388 'stuff\nWi-Fi is enabled\nmore stuff\n')): 390 'stuff\nWi-Fi is enabled\nmore stuff\n')):
389 self.device.WaitUntilFullyBooted(wifi=True) 391 self.device.WaitUntilFullyBooted(wifi=True)
390 392
391 def testWaitUntilFullyBooted_deviceNotInitiallyAvailable(self): 393 def testWaitUntilFullyBooted_deviceNotInitiallyAvailable(self):
392 with self.assertCalls( 394 with self.assertCalls(
393 self.call.adb.WaitForDevice(), 395 self.call.adb.WaitForDevice(),
394 # sd_card_ready 396 # sd_card_ready
395 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()), 397 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()),
396 # sd_card_ready 398 # sd_card_ready
397 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()), 399 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()),
398 # sd_card_ready 400 # sd_card_ready
399 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()), 401 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()),
400 # sd_card_ready 402 # sd_card_ready
401 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()), 403 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()),
402 # sd_card_ready 404 # sd_card_ready
403 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), 405 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'),
404 (self.call.adb.Shell('test -d /fake/storage/path'), ''), 406 (self.call.adb.Shell('test -d /fake/storage/path'), ''),
405 # pm_ready 407 # pm_ready
406 (self.call.device.GetApplicationPaths('android'), 408 (self.call.device._GetApplicationPathsInternal('android',
409 skip_cache=True),
407 ['package:/some/fake/path']), 410 ['package:/some/fake/path']),
408 # boot_completed 411 # boot_completed
409 (self.call.device.GetProp('sys.boot_completed'), '1')): 412 (self.call.device.GetProp('sys.boot_completed'), '1')):
410 self.device.WaitUntilFullyBooted(wifi=False) 413 self.device.WaitUntilFullyBooted(wifi=False)
411 414
412 def testWaitUntilFullyBooted_sdCardReadyFails_noPath(self): 415 def testWaitUntilFullyBooted_sdCardReadyFails_noPath(self):
413 with self.assertCalls( 416 with self.assertCalls(
414 self.call.adb.WaitForDevice(), 417 self.call.adb.WaitForDevice(),
415 # sd_card_ready 418 # sd_card_ready
416 (self.call.device.GetExternalStoragePath(), self.CommandError())): 419 (self.call.device.GetExternalStoragePath(), self.CommandError())):
(...skipping 16 matching lines...) Expand all
433 with self.assertRaises(device_errors.CommandTimeoutError): 436 with self.assertRaises(device_errors.CommandTimeoutError):
434 self.device.WaitUntilFullyBooted(wifi=False) 437 self.device.WaitUntilFullyBooted(wifi=False)
435 438
436 def testWaitUntilFullyBooted_devicePmFails(self): 439 def testWaitUntilFullyBooted_devicePmFails(self):
437 with self.assertCalls( 440 with self.assertCalls(
438 self.call.adb.WaitForDevice(), 441 self.call.adb.WaitForDevice(),
439 # sd_card_ready 442 # sd_card_ready
440 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), 443 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'),
441 (self.call.adb.Shell('test -d /fake/storage/path'), ''), 444 (self.call.adb.Shell('test -d /fake/storage/path'), ''),
442 # pm_ready 445 # pm_ready
443 (self.call.device.GetApplicationPaths('android'), self.CommandError()), 446 (self.call.device._GetApplicationPathsInternal('android',
447 skip_cache=True),
448 self.CommandError()),
444 # pm_ready 449 # pm_ready
445 (self.call.device.GetApplicationPaths('android'), self.CommandError()), 450 (self.call.device._GetApplicationPathsInternal('android',
451 skip_cache=True),
452 self.CommandError()),
446 # pm_ready 453 # pm_ready
447 (self.call.device.GetApplicationPaths('android'), self.TimeoutError())): 454 (self.call.device._GetApplicationPathsInternal('android',
455 skip_cache=True),
456 self.TimeoutError())):
448 with self.assertRaises(device_errors.CommandTimeoutError): 457 with self.assertRaises(device_errors.CommandTimeoutError):
449 self.device.WaitUntilFullyBooted(wifi=False) 458 self.device.WaitUntilFullyBooted(wifi=False)
450 459
451 def testWaitUntilFullyBooted_bootFails(self): 460 def testWaitUntilFullyBooted_bootFails(self):
452 with self.assertCalls( 461 with self.assertCalls(
453 self.call.adb.WaitForDevice(), 462 self.call.adb.WaitForDevice(),
454 # sd_card_ready 463 # sd_card_ready
455 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), 464 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'),
456 (self.call.adb.Shell('test -d /fake/storage/path'), ''), 465 (self.call.adb.Shell('test -d /fake/storage/path'), ''),
457 # pm_ready 466 # pm_ready
458 (self.call.device.GetApplicationPaths('android'), 467 (self.call.device._GetApplicationPathsInternal('android',
468 skip_cache=True),
459 ['package:/some/fake/path']), 469 ['package:/some/fake/path']),
460 # boot_completed 470 # boot_completed
461 (self.call.device.GetProp('sys.boot_completed'), '0'), 471 (self.call.device.GetProp('sys.boot_completed'), '0'),
462 # boot_completed 472 # boot_completed
463 (self.call.device.GetProp('sys.boot_completed'), '0'), 473 (self.call.device.GetProp('sys.boot_completed'), '0'),
464 # boot_completed 474 # boot_completed
465 (self.call.device.GetProp('sys.boot_completed'), self.TimeoutError())): 475 (self.call.device.GetProp('sys.boot_completed'), self.TimeoutError())):
466 with self.assertRaises(device_errors.CommandTimeoutError): 476 with self.assertRaises(device_errors.CommandTimeoutError):
467 self.device.WaitUntilFullyBooted(wifi=False) 477 self.device.WaitUntilFullyBooted(wifi=False)
468 478
469 def testWaitUntilFullyBooted_wifiFails(self): 479 def testWaitUntilFullyBooted_wifiFails(self):
470 with self.assertCalls( 480 with self.assertCalls(
471 self.call.adb.WaitForDevice(), 481 self.call.adb.WaitForDevice(),
472 # sd_card_ready 482 # sd_card_ready
473 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), 483 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'),
474 (self.call.adb.Shell('test -d /fake/storage/path'), ''), 484 (self.call.adb.Shell('test -d /fake/storage/path'), ''),
475 # pm_ready 485 # pm_ready
476 (self.call.device.GetApplicationPaths('android'), 486 (self.call.device._GetApplicationPathsInternal('android',
487 skip_cache=True),
477 ['package:/some/fake/path']), 488 ['package:/some/fake/path']),
478 # boot_completed 489 # boot_completed
479 (self.call.device.GetProp('sys.boot_completed'), '1'), 490 (self.call.device.GetProp('sys.boot_completed'), '1'),
480 # wifi_enabled 491 # wifi_enabled
481 (self.call.adb.Shell('dumpsys wifi'), 'stuff\nmore stuff\n'), 492 (self.call.adb.Shell('dumpsys wifi'), 'stuff\nmore stuff\n'),
482 # wifi_enabled 493 # wifi_enabled
483 (self.call.adb.Shell('dumpsys wifi'), 'stuff\nmore stuff\n'), 494 (self.call.adb.Shell('dumpsys wifi'), 'stuff\nmore stuff\n'),
484 # wifi_enabled 495 # wifi_enabled
485 (self.call.adb.Shell('dumpsys wifi'), self.TimeoutError())): 496 (self.call.adb.Shell('dumpsys wifi'), self.TimeoutError())):
486 with self.assertRaises(device_errors.CommandTimeoutError): 497 with self.assertRaises(device_errors.CommandTimeoutError):
(...skipping 25 matching lines...) Expand all
512 (self.call.device.IsOnline(), False), 523 (self.call.device.IsOnline(), False),
513 self.call.device.WaitUntilFullyBooted(wifi=True)): 524 self.call.device.WaitUntilFullyBooted(wifi=True)):
514 self.device.Reboot(block=True, wifi=True) 525 self.device.Reboot(block=True, wifi=True)
515 526
516 527
517 class DeviceUtilsInstallTest(DeviceUtilsTest): 528 class DeviceUtilsInstallTest(DeviceUtilsTest):
518 529
519 def testInstall_noPriorInstall(self): 530 def testInstall_noPriorInstall(self):
520 with self.assertCalls( 531 with self.assertCalls(
521 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), 532 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'),
522 'this.is.a.test.package'), 533 'test.package'),
523 (self.call.device.GetApplicationPaths('this.is.a.test.package'), []), 534 (self.call.device._GetApplicationPathsInternal('test.package'), []),
524 self.call.adb.Install('/fake/test/app.apk', reinstall=False)): 535 self.call.adb.Install('/fake/test/app.apk', reinstall=False)):
525 self.device.Install('/fake/test/app.apk', retries=0) 536 self.device.Install('/fake/test/app.apk', retries=0)
526 537
527 def testInstall_differentPriorInstall(self): 538 def testInstall_differentPriorInstall(self):
528 with self.assertCalls( 539 with self.assertCalls(
529 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), 540 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'),
530 'this.is.a.test.package'), 541 'test.package'),
531 (self.call.device.GetApplicationPaths('this.is.a.test.package'), 542 (self.call.device._GetApplicationPathsInternal('test.package'),
532 ['/fake/data/app/this.is.a.test.package.apk']), 543 ['/fake/data/app/test.package.apk']),
533 (self.call.device._GetChangedAndStaleFiles( 544 (self.call.device._ComputeStaleApks('test.package',
534 '/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk'), 545 ['/fake/test/app.apk']),
535 ([('/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk')], 546 (['/fake/test/app.apk'], None)),
536 [])), 547 self.call.adb.Uninstall('test.package'),
537 self.call.adb.Uninstall('this.is.a.test.package'),
538 self.call.adb.Install('/fake/test/app.apk', reinstall=False)): 548 self.call.adb.Install('/fake/test/app.apk', reinstall=False)):
539 self.device.Install('/fake/test/app.apk', retries=0) 549 self.device.Install('/fake/test/app.apk', retries=0)
540 550
541 def testInstall_differentPriorInstall_reinstall(self): 551 def testInstall_differentPriorInstall_reinstall(self):
542 with self.assertCalls( 552 with self.assertCalls(
543 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), 553 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'),
544 'this.is.a.test.package'), 554 'test.package'),
545 (self.call.device.GetApplicationPaths('this.is.a.test.package'), 555 (self.call.device._GetApplicationPathsInternal('test.package'),
546 ['/fake/data/app/this.is.a.test.package.apk']), 556 ['/fake/data/app/test.package.apk']),
547 (self.call.device._GetChangedAndStaleFiles( 557 (self.call.device._ComputeStaleApks('test.package',
548 '/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk'), 558 ['/fake/test/app.apk']),
549 ([('/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk')], 559 (['/fake/test/app.apk'], None)),
550 [])),
551 self.call.adb.Install('/fake/test/app.apk', reinstall=True)): 560 self.call.adb.Install('/fake/test/app.apk', reinstall=True)):
552 self.device.Install('/fake/test/app.apk', reinstall=True, retries=0) 561 self.device.Install('/fake/test/app.apk', reinstall=True, retries=0)
553 562
554 def testInstall_identicalPriorInstall(self): 563 def testInstall_identicalPriorInstall(self):
555 with self.assertCalls( 564 with self.assertCalls(
556 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), 565 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'),
557 'this.is.a.test.package'), 566 'test.package'),
558 (self.call.device.GetApplicationPaths('this.is.a.test.package'), 567 (self.call.device._GetApplicationPathsInternal('test.package'),
559 ['/fake/data/app/this.is.a.test.package.apk']), 568 ['/fake/data/app/test.package.apk']),
560 (self.call.device._GetChangedAndStaleFiles( 569 (self.call.device._ComputeStaleApks('test.package',
561 '/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk'), 570 ['/fake/test/app.apk']),
562 ([], []))): 571 ([], None))):
563 self.device.Install('/fake/test/app.apk', retries=0) 572 self.device.Install('/fake/test/app.apk', retries=0)
564 573
565 def testInstall_fails(self): 574 def testInstall_fails(self):
566 with self.assertCalls( 575 with self.assertCalls(
567 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), 576 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'),
568 'this.is.a.test.package'), 577 'test.package'),
569 (self.call.device.GetApplicationPaths('this.is.a.test.package'), []), 578 (self.call.device._GetApplicationPathsInternal('test.package'), []),
570 (self.call.adb.Install('/fake/test/app.apk', reinstall=False), 579 (self.call.adb.Install('/fake/test/app.apk', reinstall=False),
571 self.CommandError('Failure\r\n'))): 580 self.CommandError('Failure\r\n'))):
572 with self.assertRaises(device_errors.CommandFailedError): 581 with self.assertRaises(device_errors.CommandFailedError):
573 self.device.Install('/fake/test/app.apk', retries=0) 582 self.device.Install('/fake/test/app.apk', retries=0)
574 583
575 class DeviceUtilsInstallSplitApkTest(DeviceUtilsTest): 584 class DeviceUtilsInstallSplitApkTest(DeviceUtilsTest):
576 585
577 def testInstallSplitApk_noPriorInstall(self): 586 def testInstallSplitApk_noPriorInstall(self):
578 with self.assertCalls( 587 with self.assertCalls(
579 (self.call.device._CheckSdkLevel(21)), 588 (self.call.device._CheckSdkLevel(21)),
580 (mock.call.pylib.sdk.split_select.SelectSplits( 589 (mock.call.pylib.sdk.split_select.SelectSplits(
581 self.device, 'base.apk', 590 self.device, 'base.apk',
582 ['split1.apk', 'split2.apk', 'split3.apk']), 591 ['split1.apk', 'split2.apk', 'split3.apk']),
583 ['split2.apk']), 592 ['split2.apk']),
584 (mock.call.pylib.utils.apk_helper.GetPackageName('base.apk'), 593 (mock.call.pylib.utils.apk_helper.GetPackageName('base.apk'),
585 'this.is.a.test.package'), 594 'test.package'),
586 (self.call.device.GetApplicationPaths('this.is.a.test.package'), []), 595 (self.call.device._GetApplicationPathsInternal('test.package'), []),
587 (self.call.adb.InstallMultiple( 596 (self.call.adb.InstallMultiple(
588 ['base.apk', 'split2.apk'], partial=None, reinstall=False))): 597 ['base.apk', 'split2.apk'], partial=None, reinstall=False))):
589 self.device.InstallSplitApk('base.apk', 598 self.device.InstallSplitApk('base.apk',
590 ['split1.apk', 'split2.apk', 'split3.apk'], retries=0) 599 ['split1.apk', 'split2.apk', 'split3.apk'], retries=0)
591 600
592 def testInstallSplitApk_partialInstall(self): 601 def testInstallSplitApk_partialInstall(self):
593 with self.assertCalls( 602 with self.assertCalls(
594 (self.call.device._CheckSdkLevel(21)), 603 (self.call.device._CheckSdkLevel(21)),
595 (mock.call.pylib.sdk.split_select.SelectSplits( 604 (mock.call.pylib.sdk.split_select.SelectSplits(
596 self.device, 'base.apk', 605 self.device, 'base.apk',
597 ['split1.apk', 'split2.apk', 'split3.apk']), 606 ['split1.apk', 'split2.apk', 'split3.apk']),
598 ['split2.apk']), 607 ['split2.apk']),
599 (mock.call.pylib.utils.apk_helper.GetPackageName('base.apk'), 608 (mock.call.pylib.utils.apk_helper.GetPackageName('base.apk'),
600 'test.package'), 609 'test.package'),
601 (self.call.device.GetApplicationPaths('test.package'), 610 (self.call.device._GetApplicationPathsInternal('test.package'),
602 ['base-on-device.apk', 'split2-on-device.apk']), 611 ['base-on-device.apk', 'split2-on-device.apk']),
603 (mock.call.pylib.utils.md5sum.CalculateDeviceMd5Sums( 612 (self.call.device._ComputeStaleApks('test.package',
604 ['base-on-device.apk', 'split2-on-device.apk'], self.device), 613 ['base.apk', 'split2.apk']),
605 {'base-on-device.apk': 'AAA', 'split2-on-device.apk': 'BBB'}), 614 (['split2.apk'], None)),
606 (mock.call.pylib.utils.md5sum.CalculateHostMd5Sums(
607 ['base.apk', 'split2.apk']),
608 {'base.apk': 'AAA', 'split2.apk': 'CCC'}),
609 (self.call.adb.InstallMultiple( 615 (self.call.adb.InstallMultiple(
610 ['split2.apk'], partial='test.package', reinstall=True))): 616 ['split2.apk'], partial='test.package', reinstall=True))):
611 self.device.InstallSplitApk('base.apk', 617 self.device.InstallSplitApk('base.apk',
612 ['split1.apk', 'split2.apk', 'split3.apk'], reinstall=True, retries=0) 618 ['split1.apk', 'split2.apk', 'split3.apk'], reinstall=True, retries=0)
613 619
614 620
615 class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): 621 class DeviceUtilsRunShellCommandTest(DeviceUtilsTest):
616 622
617 def setUp(self): 623 def setUp(self):
618 super(DeviceUtilsRunShellCommandTest, self).setUp() 624 super(DeviceUtilsRunShellCommandTest, self).setUp()
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 def testStartActivity_actionOnly(self): 883 def testStartActivity_actionOnly(self):
878 test_intent = intent.Intent(action='android.intent.action.VIEW') 884 test_intent = intent.Intent(action='android.intent.action.VIEW')
879 with self.assertCall( 885 with self.assertCall(
880 self.call.adb.Shell('am start ' 886 self.call.adb.Shell('am start '
881 '-a android.intent.action.VIEW'), 887 '-a android.intent.action.VIEW'),
882 'Starting: Intent { act=android.intent.action.VIEW }'): 888 'Starting: Intent { act=android.intent.action.VIEW }'):
883 self.device.StartActivity(test_intent) 889 self.device.StartActivity(test_intent)
884 890
885 def testStartActivity_success(self): 891 def testStartActivity_success(self):
886 test_intent = intent.Intent(action='android.intent.action.VIEW', 892 test_intent = intent.Intent(action='android.intent.action.VIEW',
887 package='this.is.a.test.package', 893 package='test.package',
888 activity='.Main') 894 activity='.Main')
889 with self.assertCall( 895 with self.assertCall(
890 self.call.adb.Shell('am start ' 896 self.call.adb.Shell('am start '
891 '-a android.intent.action.VIEW ' 897 '-a android.intent.action.VIEW '
892 '-n this.is.a.test.package/.Main'), 898 '-n test.package/.Main'),
893 'Starting: Intent { act=android.intent.action.VIEW }'): 899 'Starting: Intent { act=android.intent.action.VIEW }'):
894 self.device.StartActivity(test_intent) 900 self.device.StartActivity(test_intent)
895 901
896 def testStartActivity_failure(self): 902 def testStartActivity_failure(self):
897 test_intent = intent.Intent(action='android.intent.action.VIEW', 903 test_intent = intent.Intent(action='android.intent.action.VIEW',
898 package='this.is.a.test.package', 904 package='test.package',
899 activity='.Main') 905 activity='.Main')
900 with self.assertCall( 906 with self.assertCall(
901 self.call.adb.Shell('am start ' 907 self.call.adb.Shell('am start '
902 '-a android.intent.action.VIEW ' 908 '-a android.intent.action.VIEW '
903 '-n this.is.a.test.package/.Main'), 909 '-n test.package/.Main'),
904 'Error: Failed to start test activity'): 910 'Error: Failed to start test activity'):
905 with self.assertRaises(device_errors.CommandFailedError): 911 with self.assertRaises(device_errors.CommandFailedError):
906 self.device.StartActivity(test_intent) 912 self.device.StartActivity(test_intent)
907 913
908 def testStartActivity_blocking(self): 914 def testStartActivity_blocking(self):
909 test_intent = intent.Intent(action='android.intent.action.VIEW', 915 test_intent = intent.Intent(action='android.intent.action.VIEW',
910 package='this.is.a.test.package', 916 package='test.package',
911 activity='.Main') 917 activity='.Main')
912 with self.assertCall( 918 with self.assertCall(
913 self.call.adb.Shell('am start ' 919 self.call.adb.Shell('am start '
914 '-W ' 920 '-W '
915 '-a android.intent.action.VIEW ' 921 '-a android.intent.action.VIEW '
916 '-n this.is.a.test.package/.Main'), 922 '-n test.package/.Main'),
917 'Starting: Intent { act=android.intent.action.VIEW }'): 923 'Starting: Intent { act=android.intent.action.VIEW }'):
918 self.device.StartActivity(test_intent, blocking=True) 924 self.device.StartActivity(test_intent, blocking=True)
919 925
920 def testStartActivity_withCategory(self): 926 def testStartActivity_withCategory(self):
921 test_intent = intent.Intent(action='android.intent.action.VIEW', 927 test_intent = intent.Intent(action='android.intent.action.VIEW',
922 package='this.is.a.test.package', 928 package='test.package',
923 activity='.Main', 929 activity='.Main',
924 category='android.intent.category.HOME') 930 category='android.intent.category.HOME')
925 with self.assertCall( 931 with self.assertCall(
926 self.call.adb.Shell('am start ' 932 self.call.adb.Shell('am start '
927 '-a android.intent.action.VIEW ' 933 '-a android.intent.action.VIEW '
928 '-c android.intent.category.HOME ' 934 '-c android.intent.category.HOME '
929 '-n this.is.a.test.package/.Main'), 935 '-n test.package/.Main'),
930 'Starting: Intent { act=android.intent.action.VIEW }'): 936 'Starting: Intent { act=android.intent.action.VIEW }'):
931 self.device.StartActivity(test_intent) 937 self.device.StartActivity(test_intent)
932 938
933 def testStartActivity_withMultipleCategories(self): 939 def testStartActivity_withMultipleCategories(self):
934 test_intent = intent.Intent(action='android.intent.action.VIEW', 940 test_intent = intent.Intent(action='android.intent.action.VIEW',
935 package='this.is.a.test.package', 941 package='test.package',
936 activity='.Main', 942 activity='.Main',
937 category=['android.intent.category.HOME', 943 category=['android.intent.category.HOME',
938 'android.intent.category.BROWSABLE']) 944 'android.intent.category.BROWSABLE'])
939 with self.assertCall( 945 with self.assertCall(
940 self.call.adb.Shell('am start ' 946 self.call.adb.Shell('am start '
941 '-a android.intent.action.VIEW ' 947 '-a android.intent.action.VIEW '
942 '-c android.intent.category.HOME ' 948 '-c android.intent.category.HOME '
943 '-c android.intent.category.BROWSABLE ' 949 '-c android.intent.category.BROWSABLE '
944 '-n this.is.a.test.package/.Main'), 950 '-n test.package/.Main'),
945 'Starting: Intent { act=android.intent.action.VIEW }'): 951 'Starting: Intent { act=android.intent.action.VIEW }'):
946 self.device.StartActivity(test_intent) 952 self.device.StartActivity(test_intent)
947 953
948 def testStartActivity_withData(self): 954 def testStartActivity_withData(self):
949 test_intent = intent.Intent(action='android.intent.action.VIEW', 955 test_intent = intent.Intent(action='android.intent.action.VIEW',
950 package='this.is.a.test.package', 956 package='test.package',
951 activity='.Main', 957 activity='.Main',
952 data='http://www.google.com/') 958 data='http://www.google.com/')
953 with self.assertCall( 959 with self.assertCall(
954 self.call.adb.Shell('am start ' 960 self.call.adb.Shell('am start '
955 '-a android.intent.action.VIEW ' 961 '-a android.intent.action.VIEW '
956 '-d http://www.google.com/ ' 962 '-d http://www.google.com/ '
957 '-n this.is.a.test.package/.Main'), 963 '-n test.package/.Main'),
958 'Starting: Intent { act=android.intent.action.VIEW }'): 964 'Starting: Intent { act=android.intent.action.VIEW }'):
959 self.device.StartActivity(test_intent) 965 self.device.StartActivity(test_intent)
960 966
961 def testStartActivity_withStringExtra(self): 967 def testStartActivity_withStringExtra(self):
962 test_intent = intent.Intent(action='android.intent.action.VIEW', 968 test_intent = intent.Intent(action='android.intent.action.VIEW',
963 package='this.is.a.test.package', 969 package='test.package',
964 activity='.Main', 970 activity='.Main',
965 extras={'foo': 'test'}) 971 extras={'foo': 'test'})
966 with self.assertCall( 972 with self.assertCall(
967 self.call.adb.Shell('am start ' 973 self.call.adb.Shell('am start '
968 '-a android.intent.action.VIEW ' 974 '-a android.intent.action.VIEW '
969 '-n this.is.a.test.package/.Main ' 975 '-n test.package/.Main '
970 '--es foo test'), 976 '--es foo test'),
971 'Starting: Intent { act=android.intent.action.VIEW }'): 977 'Starting: Intent { act=android.intent.action.VIEW }'):
972 self.device.StartActivity(test_intent) 978 self.device.StartActivity(test_intent)
973 979
974 def testStartActivity_withBoolExtra(self): 980 def testStartActivity_withBoolExtra(self):
975 test_intent = intent.Intent(action='android.intent.action.VIEW', 981 test_intent = intent.Intent(action='android.intent.action.VIEW',
976 package='this.is.a.test.package', 982 package='test.package',
977 activity='.Main', 983 activity='.Main',
978 extras={'foo': True}) 984 extras={'foo': True})
979 with self.assertCall( 985 with self.assertCall(
980 self.call.adb.Shell('am start ' 986 self.call.adb.Shell('am start '
981 '-a android.intent.action.VIEW ' 987 '-a android.intent.action.VIEW '
982 '-n this.is.a.test.package/.Main ' 988 '-n test.package/.Main '
983 '--ez foo True'), 989 '--ez foo True'),
984 'Starting: Intent { act=android.intent.action.VIEW }'): 990 'Starting: Intent { act=android.intent.action.VIEW }'):
985 self.device.StartActivity(test_intent) 991 self.device.StartActivity(test_intent)
986 992
987 def testStartActivity_withIntExtra(self): 993 def testStartActivity_withIntExtra(self):
988 test_intent = intent.Intent(action='android.intent.action.VIEW', 994 test_intent = intent.Intent(action='android.intent.action.VIEW',
989 package='this.is.a.test.package', 995 package='test.package',
990 activity='.Main', 996 activity='.Main',
991 extras={'foo': 123}) 997 extras={'foo': 123})
992 with self.assertCall( 998 with self.assertCall(
993 self.call.adb.Shell('am start ' 999 self.call.adb.Shell('am start '
994 '-a android.intent.action.VIEW ' 1000 '-a android.intent.action.VIEW '
995 '-n this.is.a.test.package/.Main ' 1001 '-n test.package/.Main '
996 '--ei foo 123'), 1002 '--ei foo 123'),
997 'Starting: Intent { act=android.intent.action.VIEW }'): 1003 'Starting: Intent { act=android.intent.action.VIEW }'):
998 self.device.StartActivity(test_intent) 1004 self.device.StartActivity(test_intent)
999 1005
1000 def testStartActivity_withTraceFile(self): 1006 def testStartActivity_withTraceFile(self):
1001 test_intent = intent.Intent(action='android.intent.action.VIEW', 1007 test_intent = intent.Intent(action='android.intent.action.VIEW',
1002 package='this.is.a.test.package', 1008 package='test.package',
1003 activity='.Main') 1009 activity='.Main')
1004 with self.assertCall( 1010 with self.assertCall(
1005 self.call.adb.Shell('am start ' 1011 self.call.adb.Shell('am start '
1006 '--start-profiler test_trace_file.out ' 1012 '--start-profiler test_trace_file.out '
1007 '-a android.intent.action.VIEW ' 1013 '-a android.intent.action.VIEW '
1008 '-n this.is.a.test.package/.Main'), 1014 '-n test.package/.Main'),
1009 'Starting: Intent { act=android.intent.action.VIEW }'): 1015 'Starting: Intent { act=android.intent.action.VIEW }'):
1010 self.device.StartActivity(test_intent, 1016 self.device.StartActivity(test_intent,
1011 trace_file_name='test_trace_file.out') 1017 trace_file_name='test_trace_file.out')
1012 1018
1013 def testStartActivity_withForceStop(self): 1019 def testStartActivity_withForceStop(self):
1014 test_intent = intent.Intent(action='android.intent.action.VIEW', 1020 test_intent = intent.Intent(action='android.intent.action.VIEW',
1015 package='this.is.a.test.package', 1021 package='test.package',
1016 activity='.Main') 1022 activity='.Main')
1017 with self.assertCall( 1023 with self.assertCall(
1018 self.call.adb.Shell('am start ' 1024 self.call.adb.Shell('am start '
1019 '-S ' 1025 '-S '
1020 '-a android.intent.action.VIEW ' 1026 '-a android.intent.action.VIEW '
1021 '-n this.is.a.test.package/.Main'), 1027 '-n test.package/.Main'),
1022 'Starting: Intent { act=android.intent.action.VIEW }'): 1028 'Starting: Intent { act=android.intent.action.VIEW }'):
1023 self.device.StartActivity(test_intent, force_stop=True) 1029 self.device.StartActivity(test_intent, force_stop=True)
1024 1030
1025 def testStartActivity_withFlags(self): 1031 def testStartActivity_withFlags(self):
1026 test_intent = intent.Intent(action='android.intent.action.VIEW', 1032 test_intent = intent.Intent(action='android.intent.action.VIEW',
1027 package='this.is.a.test.package', 1033 package='test.package',
1028 activity='.Main', 1034 activity='.Main',
1029 flags='0x10000000') 1035 flags='0x10000000')
1030 with self.assertCall( 1036 with self.assertCall(
1031 self.call.adb.Shell('am start ' 1037 self.call.adb.Shell('am start '
1032 '-a android.intent.action.VIEW ' 1038 '-a android.intent.action.VIEW '
1033 '-n this.is.a.test.package/.Main ' 1039 '-n test.package/.Main '
1034 '-f 0x10000000'), 1040 '-f 0x10000000'),
1035 'Starting: Intent { act=android.intent.action.VIEW }'): 1041 'Starting: Intent { act=android.intent.action.VIEW }'):
1036 self.device.StartActivity(test_intent) 1042 self.device.StartActivity(test_intent)
1037 1043
1038 1044
1039 class DeviceUtilsStartInstrumentationTest(DeviceUtilsTest): 1045 class DeviceUtilsStartInstrumentationTest(DeviceUtilsTest):
1040 1046
1041 def testStartInstrumentation_nothing(self): 1047 def testStartInstrumentation_nothing(self):
1042 with self.assertCalls( 1048 with self.assertCalls(
1043 self.call.device.RunShellCommand( 1049 self.call.device.RunShellCommand(
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 (self.call.device.RunShellCommand( 1194 (self.call.device.RunShellCommand(
1189 ['dumpsys', 'window', 'windows'], check_return=True, 1195 ['dumpsys', 'window', 'windows'], check_return=True,
1190 large_output=True), 1196 large_output=True),
1191 ['mCurrentFocus Launcher'])): 1197 ['mCurrentFocus Launcher'])):
1192 self.device.GoHome() 1198 self.device.GoHome()
1193 1199
1194 class DeviceUtilsForceStopTest(DeviceUtilsTest): 1200 class DeviceUtilsForceStopTest(DeviceUtilsTest):
1195 1201
1196 def testForceStop(self): 1202 def testForceStop(self):
1197 with self.assertCall( 1203 with self.assertCall(
1198 self.call.adb.Shell('am force-stop this.is.a.test.package'), 1204 self.call.adb.Shell('am force-stop test.package'),
1199 ''): 1205 ''):
1200 self.device.ForceStop('this.is.a.test.package') 1206 self.device.ForceStop('test.package')
1201 1207
1202 1208
1203 class DeviceUtilsClearApplicationStateTest(DeviceUtilsTest): 1209 class DeviceUtilsClearApplicationStateTest(DeviceUtilsTest):
1204 1210
1205 def testClearApplicationState_packageDoesntExist(self): 1211 def testClearApplicationState_packageDoesntExist(self):
1206 with self.assertCalls( 1212 with self.assertCalls(
1207 (self.call.adb.Shell('getprop ro.build.version.sdk'), '17\n'), 1213 (self.call.adb.Shell('getprop ro.build.version.sdk'), '17\n'),
1208 (self.call.device.GetApplicationPaths('this.package.does.not.exist'), 1214 (self.call.device._GetApplicationPathsInternal('does.not.exist'),
1209 [])): 1215 [])):
1210 self.device.ClearApplicationState('this.package.does.not.exist') 1216 self.device.ClearApplicationState('does.not.exist')
1211 1217
1212 def testClearApplicationState_packageDoesntExistOnAndroidJBMR2OrAbove(self): 1218 def testClearApplicationState_packageDoesntExistOnAndroidJBMR2OrAbove(self):
1213 with self.assertCalls( 1219 with self.assertCalls(
1214 (self.call.adb.Shell('getprop ro.build.version.sdk'), '18\n'), 1220 (self.call.adb.Shell('getprop ro.build.version.sdk'), '18\n'),
1215 (self.call.adb.Shell('pm clear this.package.does.not.exist'), 1221 (self.call.adb.Shell('pm clear this.package.does.not.exist'),
1216 'Failed\r\n')): 1222 'Failed\r\n')):
1217 self.device.ClearApplicationState('this.package.does.not.exist') 1223 self.device.ClearApplicationState('this.package.does.not.exist')
1218 1224
1219 def testClearApplicationState_packageExists(self): 1225 def testClearApplicationState_packageExists(self):
1220 with self.assertCalls( 1226 with self.assertCalls(
1221 (self.call.adb.Shell('getprop ro.build.version.sdk'), '17\n'), 1227 (self.call.adb.Shell('getprop ro.build.version.sdk'), '17\n'),
1222 (self.call.device.GetApplicationPaths('this.package.exists'), 1228 (self.call.device._GetApplicationPathsInternal('this.package.exists'),
1223 ['/data/app/this.package.exists.apk']), 1229 ['/data/app/this.package.exists.apk']),
1224 (self.call.adb.Shell('pm clear this.package.exists'), 1230 (self.call.adb.Shell('pm clear this.package.exists'),
1225 'Success\r\n')): 1231 'Success\r\n')):
1226 self.device.ClearApplicationState('this.package.exists') 1232 self.device.ClearApplicationState('this.package.exists')
1227 1233
1228 def testClearApplicationState_packageExistsOnAndroidJBMR2OrAbove(self): 1234 def testClearApplicationState_packageExistsOnAndroidJBMR2OrAbove(self):
1229 with self.assertCalls( 1235 with self.assertCalls(
1230 (self.call.adb.Shell('getprop ro.build.version.sdk'), '18\n'), 1236 (self.call.adb.Shell('getprop ro.build.version.sdk'), '18\n'),
1231 (self.call.adb.Shell('pm clear this.package.exists'), 1237 (self.call.adb.Shell('pm clear this.package.exists'),
1232 'Success\r\n')): 1238 'Success\r\n')):
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
1841 1847
1842 1848
1843 class DeviceUtilsClientCache(DeviceUtilsTest): 1849 class DeviceUtilsClientCache(DeviceUtilsTest):
1844 1850
1845 def testClientCache_twoCaches(self): 1851 def testClientCache_twoCaches(self):
1846 self.device._cache['test'] = 0 1852 self.device._cache['test'] = 0
1847 client_cache_one = self.device.GetClientCache('ClientOne') 1853 client_cache_one = self.device.GetClientCache('ClientOne')
1848 client_cache_one['test'] = 1 1854 client_cache_one['test'] = 1
1849 client_cache_two = self.device.GetClientCache('ClientTwo') 1855 client_cache_two = self.device.GetClientCache('ClientTwo')
1850 client_cache_two['test'] = 2 1856 client_cache_two['test'] = 2
1851 self.assertEqual(self.device._cache, {'test': 0}) 1857 self.assertEqual(self.device._cache['test'], 0)
1852 self.assertEqual(client_cache_one, {'test': 1}) 1858 self.assertEqual(client_cache_one, {'test': 1})
1853 self.assertEqual(client_cache_two, {'test': 2}) 1859 self.assertEqual(client_cache_two, {'test': 2})
1854 self.device._ClearCache() 1860 self.device._ClearCache()
1855 self.assertEqual(self.device._cache, {}) 1861 self.assertTrue('test' not in self.device._cache)
1856 self.assertEqual(client_cache_one, {}) 1862 self.assertEqual(client_cache_one, {})
1857 self.assertEqual(client_cache_two, {}) 1863 self.assertEqual(client_cache_two, {})
1858 1864
1859 def testClientCache_multipleInstances(self): 1865 def testClientCache_multipleInstances(self):
1860 client_cache_one = self.device.GetClientCache('ClientOne') 1866 client_cache_one = self.device.GetClientCache('ClientOne')
1861 client_cache_one['test'] = 1 1867 client_cache_one['test'] = 1
1862 client_cache_two = self.device.GetClientCache('ClientOne') 1868 client_cache_two = self.device.GetClientCache('ClientOne')
1863 self.assertEqual(client_cache_one, {'test': 1}) 1869 self.assertEqual(client_cache_one, {'test': 1})
1864 self.assertEqual(client_cache_two, {'test': 1}) 1870 self.assertEqual(client_cache_two, {'test': 1})
1865 self.device._ClearCache() 1871 self.device._ClearCache()
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1927 self.call.device.WriteFile(mock.ANY, mock.ANY), 1933 self.call.device.WriteFile(mock.ANY, mock.ANY),
1928 (self.call.device.RunShellCommand( 1934 (self.call.device.RunShellCommand(
1929 ['source', mock_temp_file ], as_root=True)), 1935 ['source', mock_temp_file ], as_root=True)),
1930 self.call.adb.WaitForDevice()): 1936 self.call.adb.WaitForDevice()):
1931 self.device.RestartAdbd() 1937 self.device.RestartAdbd()
1932 1938
1933 1939
1934 if __name__ == '__main__': 1940 if __name__ == '__main__':
1935 logging.getLogger().setLevel(logging.DEBUG) 1941 logging.getLogger().setLevel(logging.DEBUG)
1936 unittest.main(verbosity=2) 1942 unittest.main(verbosity=2)
OLDNEW
« no previous file with comments | « 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