| 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 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._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 Loading... |
| 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 Loading... |
| 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', False), |
| 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 |
| 621 class DeviceUtilsUninstallTest(DeviceUtilsTest): |
| 622 |
| 623 def testUninstall_callsThrough(self): |
| 624 with self.assertCalls( |
| 625 self.call.adb.Uninstall('test.package', True)): |
| 626 self.device.Uninstall('test.package', True) |
| 627 |
| 628 |
| 615 class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): | 629 class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): |
| 616 | 630 |
| 617 def setUp(self): | 631 def setUp(self): |
| 618 super(DeviceUtilsRunShellCommandTest, self).setUp() | 632 super(DeviceUtilsRunShellCommandTest, self).setUp() |
| 619 self.device.NeedsSU = mock.Mock(return_value=False) | 633 self.device.NeedsSU = mock.Mock(return_value=False) |
| 620 | 634 |
| 621 def testRunShellCommand_commandAsList(self): | 635 def testRunShellCommand_commandAsList(self): |
| 622 with self.assertCall(self.call.adb.Shell('pm list packages'), ''): | 636 with self.assertCall(self.call.adb.Shell('pm list packages'), ''): |
| 623 self.device.RunShellCommand(['pm', 'list', 'packages']) | 637 self.device.RunShellCommand(['pm', 'list', 'packages']) |
| 624 | 638 |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 def testStartActivity_actionOnly(self): | 891 def testStartActivity_actionOnly(self): |
| 878 test_intent = intent.Intent(action='android.intent.action.VIEW') | 892 test_intent = intent.Intent(action='android.intent.action.VIEW') |
| 879 with self.assertCall( | 893 with self.assertCall( |
| 880 self.call.adb.Shell('am start ' | 894 self.call.adb.Shell('am start ' |
| 881 '-a android.intent.action.VIEW'), | 895 '-a android.intent.action.VIEW'), |
| 882 'Starting: Intent { act=android.intent.action.VIEW }'): | 896 'Starting: Intent { act=android.intent.action.VIEW }'): |
| 883 self.device.StartActivity(test_intent) | 897 self.device.StartActivity(test_intent) |
| 884 | 898 |
| 885 def testStartActivity_success(self): | 899 def testStartActivity_success(self): |
| 886 test_intent = intent.Intent(action='android.intent.action.VIEW', | 900 test_intent = intent.Intent(action='android.intent.action.VIEW', |
| 887 package='this.is.a.test.package', | 901 package='test.package', |
| 888 activity='.Main') | 902 activity='.Main') |
| 889 with self.assertCall( | 903 with self.assertCall( |
| 890 self.call.adb.Shell('am start ' | 904 self.call.adb.Shell('am start ' |
| 891 '-a android.intent.action.VIEW ' | 905 '-a android.intent.action.VIEW ' |
| 892 '-n this.is.a.test.package/.Main'), | 906 '-n test.package/.Main'), |
| 893 'Starting: Intent { act=android.intent.action.VIEW }'): | 907 'Starting: Intent { act=android.intent.action.VIEW }'): |
| 894 self.device.StartActivity(test_intent) | 908 self.device.StartActivity(test_intent) |
| 895 | 909 |
| 896 def testStartActivity_failure(self): | 910 def testStartActivity_failure(self): |
| 897 test_intent = intent.Intent(action='android.intent.action.VIEW', | 911 test_intent = intent.Intent(action='android.intent.action.VIEW', |
| 898 package='this.is.a.test.package', | 912 package='test.package', |
| 899 activity='.Main') | 913 activity='.Main') |
| 900 with self.assertCall( | 914 with self.assertCall( |
| 901 self.call.adb.Shell('am start ' | 915 self.call.adb.Shell('am start ' |
| 902 '-a android.intent.action.VIEW ' | 916 '-a android.intent.action.VIEW ' |
| 903 '-n this.is.a.test.package/.Main'), | 917 '-n test.package/.Main'), |
| 904 'Error: Failed to start test activity'): | 918 'Error: Failed to start test activity'): |
| 905 with self.assertRaises(device_errors.CommandFailedError): | 919 with self.assertRaises(device_errors.CommandFailedError): |
| 906 self.device.StartActivity(test_intent) | 920 self.device.StartActivity(test_intent) |
| 907 | 921 |
| 908 def testStartActivity_blocking(self): | 922 def testStartActivity_blocking(self): |
| 909 test_intent = intent.Intent(action='android.intent.action.VIEW', | 923 test_intent = intent.Intent(action='android.intent.action.VIEW', |
| 910 package='this.is.a.test.package', | 924 package='test.package', |
| 911 activity='.Main') | 925 activity='.Main') |
| 912 with self.assertCall( | 926 with self.assertCall( |
| 913 self.call.adb.Shell('am start ' | 927 self.call.adb.Shell('am start ' |
| 914 '-W ' | 928 '-W ' |
| 915 '-a android.intent.action.VIEW ' | 929 '-a android.intent.action.VIEW ' |
| 916 '-n this.is.a.test.package/.Main'), | 930 '-n test.package/.Main'), |
| 917 'Starting: Intent { act=android.intent.action.VIEW }'): | 931 'Starting: Intent { act=android.intent.action.VIEW }'): |
| 918 self.device.StartActivity(test_intent, blocking=True) | 932 self.device.StartActivity(test_intent, blocking=True) |
| 919 | 933 |
| 920 def testStartActivity_withCategory(self): | 934 def testStartActivity_withCategory(self): |
| 921 test_intent = intent.Intent(action='android.intent.action.VIEW', | 935 test_intent = intent.Intent(action='android.intent.action.VIEW', |
| 922 package='this.is.a.test.package', | 936 package='test.package', |
| 923 activity='.Main', | 937 activity='.Main', |
| 924 category='android.intent.category.HOME') | 938 category='android.intent.category.HOME') |
| 925 with self.assertCall( | 939 with self.assertCall( |
| 926 self.call.adb.Shell('am start ' | 940 self.call.adb.Shell('am start ' |
| 927 '-a android.intent.action.VIEW ' | 941 '-a android.intent.action.VIEW ' |
| 928 '-c android.intent.category.HOME ' | 942 '-c android.intent.category.HOME ' |
| 929 '-n this.is.a.test.package/.Main'), | 943 '-n test.package/.Main'), |
| 930 'Starting: Intent { act=android.intent.action.VIEW }'): | 944 'Starting: Intent { act=android.intent.action.VIEW }'): |
| 931 self.device.StartActivity(test_intent) | 945 self.device.StartActivity(test_intent) |
| 932 | 946 |
| 933 def testStartActivity_withMultipleCategories(self): | 947 def testStartActivity_withMultipleCategories(self): |
| 934 test_intent = intent.Intent(action='android.intent.action.VIEW', | 948 test_intent = intent.Intent(action='android.intent.action.VIEW', |
| 935 package='this.is.a.test.package', | 949 package='test.package', |
| 936 activity='.Main', | 950 activity='.Main', |
| 937 category=['android.intent.category.HOME', | 951 category=['android.intent.category.HOME', |
| 938 'android.intent.category.BROWSABLE']) | 952 'android.intent.category.BROWSABLE']) |
| 939 with self.assertCall( | 953 with self.assertCall( |
| 940 self.call.adb.Shell('am start ' | 954 self.call.adb.Shell('am start ' |
| 941 '-a android.intent.action.VIEW ' | 955 '-a android.intent.action.VIEW ' |
| 942 '-c android.intent.category.HOME ' | 956 '-c android.intent.category.HOME ' |
| 943 '-c android.intent.category.BROWSABLE ' | 957 '-c android.intent.category.BROWSABLE ' |
| 944 '-n this.is.a.test.package/.Main'), | 958 '-n test.package/.Main'), |
| 945 'Starting: Intent { act=android.intent.action.VIEW }'): | 959 'Starting: Intent { act=android.intent.action.VIEW }'): |
| 946 self.device.StartActivity(test_intent) | 960 self.device.StartActivity(test_intent) |
| 947 | 961 |
| 948 def testStartActivity_withData(self): | 962 def testStartActivity_withData(self): |
| 949 test_intent = intent.Intent(action='android.intent.action.VIEW', | 963 test_intent = intent.Intent(action='android.intent.action.VIEW', |
| 950 package='this.is.a.test.package', | 964 package='test.package', |
| 951 activity='.Main', | 965 activity='.Main', |
| 952 data='http://www.google.com/') | 966 data='http://www.google.com/') |
| 953 with self.assertCall( | 967 with self.assertCall( |
| 954 self.call.adb.Shell('am start ' | 968 self.call.adb.Shell('am start ' |
| 955 '-a android.intent.action.VIEW ' | 969 '-a android.intent.action.VIEW ' |
| 956 '-d http://www.google.com/ ' | 970 '-d http://www.google.com/ ' |
| 957 '-n this.is.a.test.package/.Main'), | 971 '-n test.package/.Main'), |
| 958 'Starting: Intent { act=android.intent.action.VIEW }'): | 972 'Starting: Intent { act=android.intent.action.VIEW }'): |
| 959 self.device.StartActivity(test_intent) | 973 self.device.StartActivity(test_intent) |
| 960 | 974 |
| 961 def testStartActivity_withStringExtra(self): | 975 def testStartActivity_withStringExtra(self): |
| 962 test_intent = intent.Intent(action='android.intent.action.VIEW', | 976 test_intent = intent.Intent(action='android.intent.action.VIEW', |
| 963 package='this.is.a.test.package', | 977 package='test.package', |
| 964 activity='.Main', | 978 activity='.Main', |
| 965 extras={'foo': 'test'}) | 979 extras={'foo': 'test'}) |
| 966 with self.assertCall( | 980 with self.assertCall( |
| 967 self.call.adb.Shell('am start ' | 981 self.call.adb.Shell('am start ' |
| 968 '-a android.intent.action.VIEW ' | 982 '-a android.intent.action.VIEW ' |
| 969 '-n this.is.a.test.package/.Main ' | 983 '-n test.package/.Main ' |
| 970 '--es foo test'), | 984 '--es foo test'), |
| 971 'Starting: Intent { act=android.intent.action.VIEW }'): | 985 'Starting: Intent { act=android.intent.action.VIEW }'): |
| 972 self.device.StartActivity(test_intent) | 986 self.device.StartActivity(test_intent) |
| 973 | 987 |
| 974 def testStartActivity_withBoolExtra(self): | 988 def testStartActivity_withBoolExtra(self): |
| 975 test_intent = intent.Intent(action='android.intent.action.VIEW', | 989 test_intent = intent.Intent(action='android.intent.action.VIEW', |
| 976 package='this.is.a.test.package', | 990 package='test.package', |
| 977 activity='.Main', | 991 activity='.Main', |
| 978 extras={'foo': True}) | 992 extras={'foo': True}) |
| 979 with self.assertCall( | 993 with self.assertCall( |
| 980 self.call.adb.Shell('am start ' | 994 self.call.adb.Shell('am start ' |
| 981 '-a android.intent.action.VIEW ' | 995 '-a android.intent.action.VIEW ' |
| 982 '-n this.is.a.test.package/.Main ' | 996 '-n test.package/.Main ' |
| 983 '--ez foo True'), | 997 '--ez foo True'), |
| 984 'Starting: Intent { act=android.intent.action.VIEW }'): | 998 'Starting: Intent { act=android.intent.action.VIEW }'): |
| 985 self.device.StartActivity(test_intent) | 999 self.device.StartActivity(test_intent) |
| 986 | 1000 |
| 987 def testStartActivity_withIntExtra(self): | 1001 def testStartActivity_withIntExtra(self): |
| 988 test_intent = intent.Intent(action='android.intent.action.VIEW', | 1002 test_intent = intent.Intent(action='android.intent.action.VIEW', |
| 989 package='this.is.a.test.package', | 1003 package='test.package', |
| 990 activity='.Main', | 1004 activity='.Main', |
| 991 extras={'foo': 123}) | 1005 extras={'foo': 123}) |
| 992 with self.assertCall( | 1006 with self.assertCall( |
| 993 self.call.adb.Shell('am start ' | 1007 self.call.adb.Shell('am start ' |
| 994 '-a android.intent.action.VIEW ' | 1008 '-a android.intent.action.VIEW ' |
| 995 '-n this.is.a.test.package/.Main ' | 1009 '-n test.package/.Main ' |
| 996 '--ei foo 123'), | 1010 '--ei foo 123'), |
| 997 'Starting: Intent { act=android.intent.action.VIEW }'): | 1011 'Starting: Intent { act=android.intent.action.VIEW }'): |
| 998 self.device.StartActivity(test_intent) | 1012 self.device.StartActivity(test_intent) |
| 999 | 1013 |
| 1000 def testStartActivity_withTraceFile(self): | 1014 def testStartActivity_withTraceFile(self): |
| 1001 test_intent = intent.Intent(action='android.intent.action.VIEW', | 1015 test_intent = intent.Intent(action='android.intent.action.VIEW', |
| 1002 package='this.is.a.test.package', | 1016 package='test.package', |
| 1003 activity='.Main') | 1017 activity='.Main') |
| 1004 with self.assertCall( | 1018 with self.assertCall( |
| 1005 self.call.adb.Shell('am start ' | 1019 self.call.adb.Shell('am start ' |
| 1006 '--start-profiler test_trace_file.out ' | 1020 '--start-profiler test_trace_file.out ' |
| 1007 '-a android.intent.action.VIEW ' | 1021 '-a android.intent.action.VIEW ' |
| 1008 '-n this.is.a.test.package/.Main'), | 1022 '-n test.package/.Main'), |
| 1009 'Starting: Intent { act=android.intent.action.VIEW }'): | 1023 'Starting: Intent { act=android.intent.action.VIEW }'): |
| 1010 self.device.StartActivity(test_intent, | 1024 self.device.StartActivity(test_intent, |
| 1011 trace_file_name='test_trace_file.out') | 1025 trace_file_name='test_trace_file.out') |
| 1012 | 1026 |
| 1013 def testStartActivity_withForceStop(self): | 1027 def testStartActivity_withForceStop(self): |
| 1014 test_intent = intent.Intent(action='android.intent.action.VIEW', | 1028 test_intent = intent.Intent(action='android.intent.action.VIEW', |
| 1015 package='this.is.a.test.package', | 1029 package='test.package', |
| 1016 activity='.Main') | 1030 activity='.Main') |
| 1017 with self.assertCall( | 1031 with self.assertCall( |
| 1018 self.call.adb.Shell('am start ' | 1032 self.call.adb.Shell('am start ' |
| 1019 '-S ' | 1033 '-S ' |
| 1020 '-a android.intent.action.VIEW ' | 1034 '-a android.intent.action.VIEW ' |
| 1021 '-n this.is.a.test.package/.Main'), | 1035 '-n test.package/.Main'), |
| 1022 'Starting: Intent { act=android.intent.action.VIEW }'): | 1036 'Starting: Intent { act=android.intent.action.VIEW }'): |
| 1023 self.device.StartActivity(test_intent, force_stop=True) | 1037 self.device.StartActivity(test_intent, force_stop=True) |
| 1024 | 1038 |
| 1025 def testStartActivity_withFlags(self): | 1039 def testStartActivity_withFlags(self): |
| 1026 test_intent = intent.Intent(action='android.intent.action.VIEW', | 1040 test_intent = intent.Intent(action='android.intent.action.VIEW', |
| 1027 package='this.is.a.test.package', | 1041 package='test.package', |
| 1028 activity='.Main', | 1042 activity='.Main', |
| 1029 flags='0x10000000') | 1043 flags='0x10000000') |
| 1030 with self.assertCall( | 1044 with self.assertCall( |
| 1031 self.call.adb.Shell('am start ' | 1045 self.call.adb.Shell('am start ' |
| 1032 '-a android.intent.action.VIEW ' | 1046 '-a android.intent.action.VIEW ' |
| 1033 '-n this.is.a.test.package/.Main ' | 1047 '-n test.package/.Main ' |
| 1034 '-f 0x10000000'), | 1048 '-f 0x10000000'), |
| 1035 'Starting: Intent { act=android.intent.action.VIEW }'): | 1049 'Starting: Intent { act=android.intent.action.VIEW }'): |
| 1036 self.device.StartActivity(test_intent) | 1050 self.device.StartActivity(test_intent) |
| 1037 | 1051 |
| 1038 | 1052 |
| 1039 class DeviceUtilsStartInstrumentationTest(DeviceUtilsTest): | 1053 class DeviceUtilsStartInstrumentationTest(DeviceUtilsTest): |
| 1040 | 1054 |
| 1041 def testStartInstrumentation_nothing(self): | 1055 def testStartInstrumentation_nothing(self): |
| 1042 with self.assertCalls( | 1056 with self.assertCalls( |
| 1043 self.call.device.RunShellCommand( | 1057 self.call.device.RunShellCommand( |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1188 (self.call.device.RunShellCommand( | 1202 (self.call.device.RunShellCommand( |
| 1189 ['dumpsys', 'window', 'windows'], check_return=True, | 1203 ['dumpsys', 'window', 'windows'], check_return=True, |
| 1190 large_output=True), | 1204 large_output=True), |
| 1191 ['mCurrentFocus Launcher'])): | 1205 ['mCurrentFocus Launcher'])): |
| 1192 self.device.GoHome() | 1206 self.device.GoHome() |
| 1193 | 1207 |
| 1194 class DeviceUtilsForceStopTest(DeviceUtilsTest): | 1208 class DeviceUtilsForceStopTest(DeviceUtilsTest): |
| 1195 | 1209 |
| 1196 def testForceStop(self): | 1210 def testForceStop(self): |
| 1197 with self.assertCall( | 1211 with self.assertCall( |
| 1198 self.call.adb.Shell('am force-stop this.is.a.test.package'), | 1212 self.call.adb.Shell('am force-stop test.package'), |
| 1199 ''): | 1213 ''): |
| 1200 self.device.ForceStop('this.is.a.test.package') | 1214 self.device.ForceStop('test.package') |
| 1201 | 1215 |
| 1202 | 1216 |
| 1203 class DeviceUtilsClearApplicationStateTest(DeviceUtilsTest): | 1217 class DeviceUtilsClearApplicationStateTest(DeviceUtilsTest): |
| 1204 | 1218 |
| 1205 def testClearApplicationState_packageDoesntExist(self): | 1219 def testClearApplicationState_packageDoesntExist(self): |
| 1206 with self.assertCalls( | 1220 with self.assertCalls( |
| 1207 (self.call.adb.Shell('getprop ro.build.version.sdk'), '17\n'), | 1221 (self.call.adb.Shell('getprop ro.build.version.sdk'), '17\n'), |
| 1208 (self.call.device.GetApplicationPaths('this.package.does.not.exist'), | 1222 (self.call.device._GetApplicationPathsInternal('does.not.exist'), |
| 1209 [])): | 1223 [])): |
| 1210 self.device.ClearApplicationState('this.package.does.not.exist') | 1224 self.device.ClearApplicationState('does.not.exist') |
| 1211 | 1225 |
| 1212 def testClearApplicationState_packageDoesntExistOnAndroidJBMR2OrAbove(self): | 1226 def testClearApplicationState_packageDoesntExistOnAndroidJBMR2OrAbove(self): |
| 1213 with self.assertCalls( | 1227 with self.assertCalls( |
| 1214 (self.call.adb.Shell('getprop ro.build.version.sdk'), '18\n'), | 1228 (self.call.adb.Shell('getprop ro.build.version.sdk'), '18\n'), |
| 1215 (self.call.adb.Shell('pm clear this.package.does.not.exist'), | 1229 (self.call.adb.Shell('pm clear this.package.does.not.exist'), |
| 1216 'Failed\r\n')): | 1230 'Failed\r\n')): |
| 1217 self.device.ClearApplicationState('this.package.does.not.exist') | 1231 self.device.ClearApplicationState('this.package.does.not.exist') |
| 1218 | 1232 |
| 1219 def testClearApplicationState_packageExists(self): | 1233 def testClearApplicationState_packageExists(self): |
| 1220 with self.assertCalls( | 1234 with self.assertCalls( |
| 1221 (self.call.adb.Shell('getprop ro.build.version.sdk'), '17\n'), | 1235 (self.call.adb.Shell('getprop ro.build.version.sdk'), '17\n'), |
| 1222 (self.call.device.GetApplicationPaths('this.package.exists'), | 1236 (self.call.device._GetApplicationPathsInternal('this.package.exists'), |
| 1223 ['/data/app/this.package.exists.apk']), | 1237 ['/data/app/this.package.exists.apk']), |
| 1224 (self.call.adb.Shell('pm clear this.package.exists'), | 1238 (self.call.adb.Shell('pm clear this.package.exists'), |
| 1225 'Success\r\n')): | 1239 'Success\r\n')): |
| 1226 self.device.ClearApplicationState('this.package.exists') | 1240 self.device.ClearApplicationState('this.package.exists') |
| 1227 | 1241 |
| 1228 def testClearApplicationState_packageExistsOnAndroidJBMR2OrAbove(self): | 1242 def testClearApplicationState_packageExistsOnAndroidJBMR2OrAbove(self): |
| 1229 with self.assertCalls( | 1243 with self.assertCalls( |
| 1230 (self.call.adb.Shell('getprop ro.build.version.sdk'), '18\n'), | 1244 (self.call.adb.Shell('getprop ro.build.version.sdk'), '18\n'), |
| 1231 (self.call.adb.Shell('pm clear this.package.exists'), | 1245 (self.call.adb.Shell('pm clear this.package.exists'), |
| 1232 'Success\r\n')): | 1246 'Success\r\n')): |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1841 | 1855 |
| 1842 | 1856 |
| 1843 class DeviceUtilsClientCache(DeviceUtilsTest): | 1857 class DeviceUtilsClientCache(DeviceUtilsTest): |
| 1844 | 1858 |
| 1845 def testClientCache_twoCaches(self): | 1859 def testClientCache_twoCaches(self): |
| 1846 self.device._cache['test'] = 0 | 1860 self.device._cache['test'] = 0 |
| 1847 client_cache_one = self.device.GetClientCache('ClientOne') | 1861 client_cache_one = self.device.GetClientCache('ClientOne') |
| 1848 client_cache_one['test'] = 1 | 1862 client_cache_one['test'] = 1 |
| 1849 client_cache_two = self.device.GetClientCache('ClientTwo') | 1863 client_cache_two = self.device.GetClientCache('ClientTwo') |
| 1850 client_cache_two['test'] = 2 | 1864 client_cache_two['test'] = 2 |
| 1851 self.assertEqual(self.device._cache, {'test': 0}) | 1865 self.assertEqual(self.device._cache['test'], 0) |
| 1852 self.assertEqual(client_cache_one, {'test': 1}) | 1866 self.assertEqual(client_cache_one, {'test': 1}) |
| 1853 self.assertEqual(client_cache_two, {'test': 2}) | 1867 self.assertEqual(client_cache_two, {'test': 2}) |
| 1854 self.device._ClearCache() | 1868 self.device._ClearCache() |
| 1855 self.assertEqual(self.device._cache, {}) | 1869 self.assertTrue('test' not in self.device._cache) |
| 1856 self.assertEqual(client_cache_one, {}) | 1870 self.assertEqual(client_cache_one, {}) |
| 1857 self.assertEqual(client_cache_two, {}) | 1871 self.assertEqual(client_cache_two, {}) |
| 1858 | 1872 |
| 1859 def testClientCache_multipleInstances(self): | 1873 def testClientCache_multipleInstances(self): |
| 1860 client_cache_one = self.device.GetClientCache('ClientOne') | 1874 client_cache_one = self.device.GetClientCache('ClientOne') |
| 1861 client_cache_one['test'] = 1 | 1875 client_cache_one['test'] = 1 |
| 1862 client_cache_two = self.device.GetClientCache('ClientOne') | 1876 client_cache_two = self.device.GetClientCache('ClientOne') |
| 1863 self.assertEqual(client_cache_one, {'test': 1}) | 1877 self.assertEqual(client_cache_one, {'test': 1}) |
| 1864 self.assertEqual(client_cache_two, {'test': 1}) | 1878 self.assertEqual(client_cache_two, {'test': 1}) |
| 1865 self.device._ClearCache() | 1879 self.device._ClearCache() |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1927 self.call.device.WriteFile(mock.ANY, mock.ANY), | 1941 self.call.device.WriteFile(mock.ANY, mock.ANY), |
| 1928 (self.call.device.RunShellCommand( | 1942 (self.call.device.RunShellCommand( |
| 1929 ['source', mock_temp_file ], as_root=True)), | 1943 ['source', mock_temp_file ], as_root=True)), |
| 1930 self.call.adb.WaitForDevice()): | 1944 self.call.adb.WaitForDevice()): |
| 1931 self.device.RestartAdbd() | 1945 self.device.RestartAdbd() |
| 1932 | 1946 |
| 1933 | 1947 |
| 1934 if __name__ == '__main__': | 1948 if __name__ == '__main__': |
| 1935 logging.getLogger().setLevel(logging.DEBUG) | 1949 logging.getLogger().setLevel(logging.DEBUG) |
| 1936 unittest.main(verbosity=2) | 1950 unittest.main(verbosity=2) |
| OLD | NEW |