OLD | NEW |
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 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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.GetApplicationPaths('android', skip_cache=True), |
370 ['package:/some/fake/path']), | 370 ['package:/some/fake/path']), |
371 # boot_completed | 371 # boot_completed |
372 (self.call.device.GetProp('sys.boot_completed'), '1')): | 372 (self.call.device.GetProp('sys.boot_completed'), '1')): |
373 self.device.WaitUntilFullyBooted(wifi=False) | 373 self.device.WaitUntilFullyBooted(wifi=False) |
374 | 374 |
375 def testWaitUntilFullyBooted_succeedsWithWifi(self): | 375 def testWaitUntilFullyBooted_succeedsWithWifi(self): |
376 with self.assertCalls( | 376 with self.assertCalls( |
377 self.call.adb.WaitForDevice(), | 377 self.call.adb.WaitForDevice(), |
378 # sd_card_ready | 378 # sd_card_ready |
379 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), | 379 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), |
380 (self.call.adb.Shell('test -d /fake/storage/path'), ''), | 380 (self.call.adb.Shell('test -d /fake/storage/path'), ''), |
381 # pm_ready | 381 # pm_ready |
382 (self.call.device.GetApplicationPaths('android'), | 382 (self.call.device.GetApplicationPaths('android', skip_cache=True), |
383 ['package:/some/fake/path']), | 383 ['package:/some/fake/path']), |
384 # boot_completed | 384 # boot_completed |
385 (self.call.device.GetProp('sys.boot_completed'), '1'), | 385 (self.call.device.GetProp('sys.boot_completed'), '1'), |
386 # wifi_enabled | 386 # wifi_enabled |
387 (self.call.adb.Shell('dumpsys wifi'), | 387 (self.call.adb.Shell('dumpsys wifi'), |
388 'stuff\nWi-Fi is enabled\nmore stuff\n')): | 388 'stuff\nWi-Fi is enabled\nmore stuff\n')): |
389 self.device.WaitUntilFullyBooted(wifi=True) | 389 self.device.WaitUntilFullyBooted(wifi=True) |
390 | 390 |
391 def testWaitUntilFullyBooted_deviceNotInitiallyAvailable(self): | 391 def testWaitUntilFullyBooted_deviceNotInitiallyAvailable(self): |
392 with self.assertCalls( | 392 with self.assertCalls( |
393 self.call.adb.WaitForDevice(), | 393 self.call.adb.WaitForDevice(), |
394 # sd_card_ready | 394 # sd_card_ready |
395 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()), | 395 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()), |
396 # sd_card_ready | 396 # sd_card_ready |
397 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()), | 397 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()), |
398 # sd_card_ready | 398 # sd_card_ready |
399 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()), | 399 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()), |
400 # sd_card_ready | 400 # sd_card_ready |
401 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()), | 401 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()), |
402 # sd_card_ready | 402 # sd_card_ready |
403 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), | 403 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), |
404 (self.call.adb.Shell('test -d /fake/storage/path'), ''), | 404 (self.call.adb.Shell('test -d /fake/storage/path'), ''), |
405 # pm_ready | 405 # pm_ready |
406 (self.call.device.GetApplicationPaths('android'), | 406 (self.call.device.GetApplicationPaths('android', skip_cache=True), |
407 ['package:/some/fake/path']), | 407 ['package:/some/fake/path']), |
408 # boot_completed | 408 # boot_completed |
409 (self.call.device.GetProp('sys.boot_completed'), '1')): | 409 (self.call.device.GetProp('sys.boot_completed'), '1')): |
410 self.device.WaitUntilFullyBooted(wifi=False) | 410 self.device.WaitUntilFullyBooted(wifi=False) |
411 | 411 |
412 def testWaitUntilFullyBooted_sdCardReadyFails_noPath(self): | 412 def testWaitUntilFullyBooted_sdCardReadyFails_noPath(self): |
413 with self.assertCalls( | 413 with self.assertCalls( |
414 self.call.adb.WaitForDevice(), | 414 self.call.adb.WaitForDevice(), |
415 # sd_card_ready | 415 # sd_card_ready |
416 (self.call.device.GetExternalStoragePath(), self.CommandError())): | 416 (self.call.device.GetExternalStoragePath(), self.CommandError())): |
(...skipping 16 matching lines...) Expand all Loading... |
433 with self.assertRaises(device_errors.CommandTimeoutError): | 433 with self.assertRaises(device_errors.CommandTimeoutError): |
434 self.device.WaitUntilFullyBooted(wifi=False) | 434 self.device.WaitUntilFullyBooted(wifi=False) |
435 | 435 |
436 def testWaitUntilFullyBooted_devicePmFails(self): | 436 def testWaitUntilFullyBooted_devicePmFails(self): |
437 with self.assertCalls( | 437 with self.assertCalls( |
438 self.call.adb.WaitForDevice(), | 438 self.call.adb.WaitForDevice(), |
439 # sd_card_ready | 439 # sd_card_ready |
440 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), | 440 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), |
441 (self.call.adb.Shell('test -d /fake/storage/path'), ''), | 441 (self.call.adb.Shell('test -d /fake/storage/path'), ''), |
442 # pm_ready | 442 # pm_ready |
443 (self.call.device.GetApplicationPaths('android'), self.CommandError()), | 443 (self.call.device.GetApplicationPaths('android', skip_cache=True), |
| 444 self.CommandError()), |
444 # pm_ready | 445 # pm_ready |
445 (self.call.device.GetApplicationPaths('android'), self.CommandError()), | 446 (self.call.device.GetApplicationPaths('android', skip_cache=True), |
| 447 self.CommandError()), |
446 # pm_ready | 448 # pm_ready |
447 (self.call.device.GetApplicationPaths('android'), self.TimeoutError())): | 449 (self.call.device.GetApplicationPaths('android', skip_cache=True), |
| 450 self.TimeoutError())): |
448 with self.assertRaises(device_errors.CommandTimeoutError): | 451 with self.assertRaises(device_errors.CommandTimeoutError): |
449 self.device.WaitUntilFullyBooted(wifi=False) | 452 self.device.WaitUntilFullyBooted(wifi=False) |
450 | 453 |
451 def testWaitUntilFullyBooted_bootFails(self): | 454 def testWaitUntilFullyBooted_bootFails(self): |
452 with self.assertCalls( | 455 with self.assertCalls( |
453 self.call.adb.WaitForDevice(), | 456 self.call.adb.WaitForDevice(), |
454 # sd_card_ready | 457 # sd_card_ready |
455 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), | 458 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), |
456 (self.call.adb.Shell('test -d /fake/storage/path'), ''), | 459 (self.call.adb.Shell('test -d /fake/storage/path'), ''), |
457 # pm_ready | 460 # pm_ready |
458 (self.call.device.GetApplicationPaths('android'), | 461 (self.call.device.GetApplicationPaths('android', skip_cache=True), |
459 ['package:/some/fake/path']), | 462 ['package:/some/fake/path']), |
460 # boot_completed | 463 # boot_completed |
461 (self.call.device.GetProp('sys.boot_completed'), '0'), | 464 (self.call.device.GetProp('sys.boot_completed'), '0'), |
462 # boot_completed | 465 # boot_completed |
463 (self.call.device.GetProp('sys.boot_completed'), '0'), | 466 (self.call.device.GetProp('sys.boot_completed'), '0'), |
464 # boot_completed | 467 # boot_completed |
465 (self.call.device.GetProp('sys.boot_completed'), self.TimeoutError())): | 468 (self.call.device.GetProp('sys.boot_completed'), self.TimeoutError())): |
466 with self.assertRaises(device_errors.CommandTimeoutError): | 469 with self.assertRaises(device_errors.CommandTimeoutError): |
467 self.device.WaitUntilFullyBooted(wifi=False) | 470 self.device.WaitUntilFullyBooted(wifi=False) |
468 | 471 |
469 def testWaitUntilFullyBooted_wifiFails(self): | 472 def testWaitUntilFullyBooted_wifiFails(self): |
470 with self.assertCalls( | 473 with self.assertCalls( |
471 self.call.adb.WaitForDevice(), | 474 self.call.adb.WaitForDevice(), |
472 # sd_card_ready | 475 # sd_card_ready |
473 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), | 476 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), |
474 (self.call.adb.Shell('test -d /fake/storage/path'), ''), | 477 (self.call.adb.Shell('test -d /fake/storage/path'), ''), |
475 # pm_ready | 478 # pm_ready |
476 (self.call.device.GetApplicationPaths('android'), | 479 (self.call.device.GetApplicationPaths('android', skip_cache=True), |
477 ['package:/some/fake/path']), | 480 ['package:/some/fake/path']), |
478 # boot_completed | 481 # boot_completed |
479 (self.call.device.GetProp('sys.boot_completed'), '1'), | 482 (self.call.device.GetProp('sys.boot_completed'), '1'), |
480 # wifi_enabled | 483 # wifi_enabled |
481 (self.call.adb.Shell('dumpsys wifi'), 'stuff\nmore stuff\n'), | 484 (self.call.adb.Shell('dumpsys wifi'), 'stuff\nmore stuff\n'), |
482 # wifi_enabled | 485 # wifi_enabled |
483 (self.call.adb.Shell('dumpsys wifi'), 'stuff\nmore stuff\n'), | 486 (self.call.adb.Shell('dumpsys wifi'), 'stuff\nmore stuff\n'), |
484 # wifi_enabled | 487 # wifi_enabled |
485 (self.call.adb.Shell('dumpsys wifi'), self.TimeoutError())): | 488 (self.call.adb.Shell('dumpsys wifi'), self.TimeoutError())): |
486 with self.assertRaises(device_errors.CommandTimeoutError): | 489 with self.assertRaises(device_errors.CommandTimeoutError): |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 (self.call.device.GetApplicationPaths('this.is.a.test.package'), []), | 526 (self.call.device.GetApplicationPaths('this.is.a.test.package'), []), |
524 self.call.adb.Install('/fake/test/app.apk', reinstall=False)): | 527 self.call.adb.Install('/fake/test/app.apk', reinstall=False)): |
525 self.device.Install('/fake/test/app.apk', retries=0) | 528 self.device.Install('/fake/test/app.apk', retries=0) |
526 | 529 |
527 def testInstall_differentPriorInstall(self): | 530 def testInstall_differentPriorInstall(self): |
528 with self.assertCalls( | 531 with self.assertCalls( |
529 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), | 532 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), |
530 'this.is.a.test.package'), | 533 'this.is.a.test.package'), |
531 (self.call.device.GetApplicationPaths('this.is.a.test.package'), | 534 (self.call.device.GetApplicationPaths('this.is.a.test.package'), |
532 ['/fake/data/app/this.is.a.test.package.apk']), | 535 ['/fake/data/app/this.is.a.test.package.apk']), |
533 (self.call.device._GetChangedAndStaleFiles( | 536 (self.call.device._ComputeStaleApks('this.is.a.test.package', |
534 '/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk'), | 537 ['/fake/test/app.apk']), |
535 ([('/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk')], | 538 (['/fake/test/app.apk'], None)), |
536 [])), | |
537 self.call.adb.Uninstall('this.is.a.test.package'), | 539 self.call.adb.Uninstall('this.is.a.test.package'), |
538 self.call.adb.Install('/fake/test/app.apk', reinstall=False)): | 540 self.call.adb.Install('/fake/test/app.apk', reinstall=False)): |
539 self.device.Install('/fake/test/app.apk', retries=0) | 541 self.device.Install('/fake/test/app.apk', retries=0) |
540 | 542 |
541 def testInstall_differentPriorInstall_reinstall(self): | 543 def testInstall_differentPriorInstall_reinstall(self): |
542 with self.assertCalls( | 544 with self.assertCalls( |
543 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), | 545 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), |
544 'this.is.a.test.package'), | 546 'this.is.a.test.package'), |
545 (self.call.device.GetApplicationPaths('this.is.a.test.package'), | 547 (self.call.device.GetApplicationPaths('this.is.a.test.package'), |
546 ['/fake/data/app/this.is.a.test.package.apk']), | 548 ['/fake/data/app/this.is.a.test.package.apk']), |
547 (self.call.device._GetChangedAndStaleFiles( | 549 (self.call.device._ComputeStaleApks('this.is.a.test.package', |
548 '/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk'), | 550 ['/fake/test/app.apk']), |
549 ([('/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk')], | 551 (['/fake/test/app.apk'], None)), |
550 [])), | |
551 self.call.adb.Install('/fake/test/app.apk', reinstall=True)): | 552 self.call.adb.Install('/fake/test/app.apk', reinstall=True)): |
552 self.device.Install('/fake/test/app.apk', reinstall=True, retries=0) | 553 self.device.Install('/fake/test/app.apk', reinstall=True, retries=0) |
553 | 554 |
554 def testInstall_identicalPriorInstall(self): | 555 def testInstall_identicalPriorInstall(self): |
555 with self.assertCalls( | 556 with self.assertCalls( |
556 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), | 557 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), |
557 'this.is.a.test.package'), | 558 'this.is.a.test.package'), |
558 (self.call.device.GetApplicationPaths('this.is.a.test.package'), | 559 (self.call.device.GetApplicationPaths('this.is.a.test.package'), |
559 ['/fake/data/app/this.is.a.test.package.apk']), | 560 ['/fake/data/app/this.is.a.test.package.apk']), |
560 (self.call.device._GetChangedAndStaleFiles( | 561 (self.call.device._ComputeStaleApks('this.is.a.test.package', |
561 '/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk'), | 562 ['/fake/test/app.apk']), |
562 ([], []))): | 563 ([], None))): |
563 self.device.Install('/fake/test/app.apk', retries=0) | 564 self.device.Install('/fake/test/app.apk', retries=0) |
564 | 565 |
565 def testInstall_fails(self): | 566 def testInstall_fails(self): |
566 with self.assertCalls( | 567 with self.assertCalls( |
567 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), | 568 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), |
568 'this.is.a.test.package'), | 569 'this.is.a.test.package'), |
569 (self.call.device.GetApplicationPaths('this.is.a.test.package'), []), | 570 (self.call.device.GetApplicationPaths('this.is.a.test.package'), []), |
570 (self.call.adb.Install('/fake/test/app.apk', reinstall=False), | 571 (self.call.adb.Install('/fake/test/app.apk', reinstall=False), |
571 self.CommandError('Failure\r\n'))): | 572 self.CommandError('Failure\r\n'))): |
572 with self.assertRaises(device_errors.CommandFailedError): | 573 with self.assertRaises(device_errors.CommandFailedError): |
(...skipping 20 matching lines...) Expand all Loading... |
593 with self.assertCalls( | 594 with self.assertCalls( |
594 (self.call.device._CheckSdkLevel(21)), | 595 (self.call.device._CheckSdkLevel(21)), |
595 (mock.call.pylib.sdk.split_select.SelectSplits( | 596 (mock.call.pylib.sdk.split_select.SelectSplits( |
596 self.device, 'base.apk', | 597 self.device, 'base.apk', |
597 ['split1.apk', 'split2.apk', 'split3.apk']), | 598 ['split1.apk', 'split2.apk', 'split3.apk']), |
598 ['split2.apk']), | 599 ['split2.apk']), |
599 (mock.call.pylib.utils.apk_helper.GetPackageName('base.apk'), | 600 (mock.call.pylib.utils.apk_helper.GetPackageName('base.apk'), |
600 'test.package'), | 601 'test.package'), |
601 (self.call.device.GetApplicationPaths('test.package'), | 602 (self.call.device.GetApplicationPaths('test.package'), |
602 ['base-on-device.apk', 'split2-on-device.apk']), | 603 ['base-on-device.apk', 'split2-on-device.apk']), |
603 (mock.call.pylib.utils.md5sum.CalculateDeviceMd5Sums( | 604 (self.call.device._ComputeStaleApks('test.package', |
604 ['base-on-device.apk', 'split2-on-device.apk'], self.device), | 605 ['base.apk', 'split2.apk']), |
605 {'base-on-device.apk': 'AAA', 'split2-on-device.apk': 'BBB'}), | 606 (['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( | 607 (self.call.adb.InstallMultiple( |
610 ['split2.apk'], partial='test.package', reinstall=True))): | 608 ['split2.apk'], partial='test.package', reinstall=True))): |
611 self.device.InstallSplitApk('base.apk', | 609 self.device.InstallSplitApk('base.apk', |
612 ['split1.apk', 'split2.apk', 'split3.apk'], reinstall=True, retries=0) | 610 ['split1.apk', 'split2.apk', 'split3.apk'], reinstall=True, retries=0) |
613 | 611 |
614 | 612 |
615 class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): | 613 class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): |
616 | 614 |
617 def setUp(self): | 615 def setUp(self): |
618 super(DeviceUtilsRunShellCommandTest, self).setUp() | 616 super(DeviceUtilsRunShellCommandTest, self).setUp() |
(...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1836 devices = device_utils.DeviceUtils.HealthyDevices() | 1834 devices = device_utils.DeviceUtils.HealthyDevices() |
1837 self.assertEquals(1, len(devices)) | 1835 self.assertEquals(1, len(devices)) |
1838 self.assertTrue(isinstance(devices[0], device_utils.DeviceUtils)) | 1836 self.assertTrue(isinstance(devices[0], device_utils.DeviceUtils)) |
1839 self.assertEquals('0123456789abcdef', devices[0].adb.GetDeviceSerial()) | 1837 self.assertEquals('0123456789abcdef', devices[0].adb.GetDeviceSerial()) |
1840 | 1838 |
1841 | 1839 |
1842 if __name__ == '__main__': | 1840 if __name__ == '__main__': |
1843 logging.getLogger().setLevel(logging.DEBUG) | 1841 logging.getLogger().setLevel(logging.DEBUG) |
1844 unittest.main(verbosity=2) | 1842 unittest.main(verbosity=2) |
1845 | 1843 |
OLD | NEW |