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

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

Issue 1222313015: Manual partial update from from https://crrev.com/337502 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """ 6 """
7 Unit tests for the contents of device_utils.py (mostly DeviceUtils). 7 Unit tests for the contents of device_utils.py (mostly DeviceUtils).
8 """ 8 """
9 9
10 # pylint: disable=C0321 10 # pylint: disable=C0321
11 # pylint: disable=W0212 11 # pylint: disable=W0212
12 # pylint: disable=W0613 12 # pylint: disable=W0613
13 13
14 import collections 14 import collections
15 import datetime 15 import datetime
16 import logging 16 import logging
17 import os 17 import os
18 import re 18 import re
19 import sys 19 import sys
20 import unittest 20 import unittest
21 21
22 from pylib import android_commands 22 from pylib import android_commands
23 from pylib import cmd_helper 23 from pylib import cmd_helper
24 from pylib import constants 24 from pylib import constants
25 from pylib import device_signal 25 from pylib import device_signal
26 from pylib.device import adb_wrapper 26 from pylib.device import adb_wrapper
27 from pylib.device import device_errors 27 from pylib.device import device_errors
28 from pylib.device import device_utils 28 from pylib.device import device_utils
29 from pylib.device import intent 29 from pylib.device import intent
30 from pylib.sdk import split_select
30 from pylib.utils import mock_calls 31 from pylib.utils import mock_calls
31 32
32 # RunCommand from third_party/android_testrunner/run_command.py is mocked 33 # RunCommand from third_party/android_testrunner/run_command.py is mocked
33 # below, so its path needs to be in sys.path. 34 # below, so its path needs to be in sys.path.
34 sys.path.append(os.path.join( 35 sys.path.append(os.path.join(
35 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) 36 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner'))
36 37
37 sys.path.append(os.path.join( 38 sys.path.append(os.path.join(
38 constants.DIR_SOURCE_ROOT, 'third_party', 'pymock')) 39 constants.DIR_SOURCE_ROOT, 'third_party', 'pymock'))
39 import mock # pylint: disable=F0401 40 import mock # pylint: disable=F0401
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 self.call.adb.Shell('echo $EXTERNAL_STORAGE'), '/fake/storage/path\n'): 304 self.call.adb.Shell('echo $EXTERNAL_STORAGE'), '/fake/storage/path\n'):
304 self.assertEquals('/fake/storage/path', 305 self.assertEquals('/fake/storage/path',
305 self.device.GetExternalStoragePath()) 306 self.device.GetExternalStoragePath())
306 307
307 def testGetExternalStoragePath_fails(self): 308 def testGetExternalStoragePath_fails(self):
308 with self.assertCall(self.call.adb.Shell('echo $EXTERNAL_STORAGE'), '\n'): 309 with self.assertCall(self.call.adb.Shell('echo $EXTERNAL_STORAGE'), '\n'):
309 with self.assertRaises(device_errors.CommandFailedError): 310 with self.assertRaises(device_errors.CommandFailedError):
310 self.device.GetExternalStoragePath() 311 self.device.GetExternalStoragePath()
311 312
312 313
313 class DeviceUtilsGetApplicationPathTest(DeviceUtilsTest): 314 class DeviceUtilsGetApplicationPathsTest(DeviceUtilsTest):
314 315
315 def testGetApplicationPath_exists(self): 316 def testGetApplicationPaths_exists(self):
316 with self.assertCalls( 317 with self.assertCalls(
317 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'), 318 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'),
318 (self.call.adb.Shell('pm path android'), 319 (self.call.adb.Shell('pm path android'),
319 'package:/path/to/android.apk\n')): 320 'package:/path/to/android.apk\n')):
320 self.assertEquals('/path/to/android.apk', 321 self.assertEquals(['/path/to/android.apk'],
321 self.device.GetApplicationPath('android')) 322 self.device.GetApplicationPaths('android'))
322 323
323 def testGetApplicationPath_notExists(self): 324 def testGetApplicationPaths_notExists(self):
324 with self.assertCalls( 325 with self.assertCalls(
325 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'), 326 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'),
326 (self.call.adb.Shell('pm path not.installed.app'), '')): 327 (self.call.adb.Shell('pm path not.installed.app'), '')):
327 self.assertEquals(None, 328 self.assertEquals([],
328 self.device.GetApplicationPath('not.installed.app')) 329 self.device.GetApplicationPaths('not.installed.app'))
329 330
330 def testGetApplicationPath_fails(self): 331 def testGetApplicationPaths_fails(self):
331 with self.assertCalls( 332 with self.assertCalls(
332 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'), 333 (self.call.adb.Shell('getprop ro.build.version.sdk'), '19\n'),
333 (self.call.adb.Shell('pm path android'), 334 (self.call.adb.Shell('pm path android'),
334 self.CommandError('ERROR. Is package manager running?\n'))): 335 self.CommandError('ERROR. Is package manager running?\n'))):
335 with self.assertRaises(device_errors.CommandFailedError): 336 with self.assertRaises(device_errors.CommandFailedError):
336 self.device.GetApplicationPath('android') 337 self.device.GetApplicationPaths('android')
338
339
340 class DeviceUtilsGetApplicationDataDirectoryTest(DeviceUtilsTest):
341
342 def testGetApplicationDataDirectory_exists(self):
343 with self.assertCall(
344 self.call.device._RunPipedShellCommand(
345 'pm dump foo.bar.baz | grep dataDir='),
346 ['dataDir=/data/data/foo.bar.baz']):
347 self.assertEquals(
348 '/data/data/foo.bar.baz',
349 self.device.GetApplicationDataDirectory('foo.bar.baz'))
350
351 def testGetApplicationDataDirectory_notExists(self):
352 with self.assertCall(
353 self.call.device._RunPipedShellCommand(
354 'pm dump foo.bar.baz | grep dataDir='),
355 self.ShellError()):
356 self.assertIsNone(self.device.GetApplicationDataDirectory('foo.bar.baz'))
337 357
338 358
339 @mock.patch('time.sleep', mock.Mock()) 359 @mock.patch('time.sleep', mock.Mock())
340 class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsTest): 360 class DeviceUtilsWaitUntilFullyBootedTest(DeviceUtilsTest):
341 361
342 def testWaitUntilFullyBooted_succeedsNoWifi(self): 362 def testWaitUntilFullyBooted_succeedsNoWifi(self):
343 with self.assertCalls( 363 with self.assertCalls(
344 self.call.adb.WaitForDevice(), 364 self.call.adb.WaitForDevice(),
345 # sd_card_ready 365 # sd_card_ready
346 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), 366 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'),
347 (self.call.adb.Shell('test -d /fake/storage/path'), ''), 367 (self.call.adb.Shell('test -d /fake/storage/path'), ''),
348 # pm_ready 368 # pm_ready
349 (self.call.device.GetApplicationPath('android'), 369 (self.call.device.GetApplicationPaths('android'),
350 'package:/some/fake/path'), 370 ['package:/some/fake/path']),
351 # boot_completed 371 # boot_completed
352 (self.call.device.GetProp('sys.boot_completed'), '1')): 372 (self.call.device.GetProp('sys.boot_completed'), '1')):
353 self.device.WaitUntilFullyBooted(wifi=False) 373 self.device.WaitUntilFullyBooted(wifi=False)
354 374
355 def testWaitUntilFullyBooted_succeedsWithWifi(self): 375 def testWaitUntilFullyBooted_succeedsWithWifi(self):
356 with self.assertCalls( 376 with self.assertCalls(
357 self.call.adb.WaitForDevice(), 377 self.call.adb.WaitForDevice(),
358 # sd_card_ready 378 # sd_card_ready
359 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), 379 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'),
360 (self.call.adb.Shell('test -d /fake/storage/path'), ''), 380 (self.call.adb.Shell('test -d /fake/storage/path'), ''),
361 # pm_ready 381 # pm_ready
362 (self.call.device.GetApplicationPath('android'), 382 (self.call.device.GetApplicationPaths('android'),
363 'package:/some/fake/path'), 383 ['package:/some/fake/path']),
364 # boot_completed 384 # boot_completed
365 (self.call.device.GetProp('sys.boot_completed'), '1'), 385 (self.call.device.GetProp('sys.boot_completed'), '1'),
366 # wifi_enabled 386 # wifi_enabled
367 (self.call.adb.Shell('dumpsys wifi'), 387 (self.call.adb.Shell('dumpsys wifi'),
368 'stuff\nWi-Fi is enabled\nmore stuff\n')): 388 'stuff\nWi-Fi is enabled\nmore stuff\n')):
369 self.device.WaitUntilFullyBooted(wifi=True) 389 self.device.WaitUntilFullyBooted(wifi=True)
370 390
371 def testWaitUntilFullyBooted_deviceNotInitiallyAvailable(self): 391 def testWaitUntilFullyBooted_deviceNotInitiallyAvailable(self):
372 with self.assertCalls( 392 with self.assertCalls(
373 self.call.adb.WaitForDevice(), 393 self.call.adb.WaitForDevice(),
374 # sd_card_ready 394 # sd_card_ready
375 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()), 395 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()),
376 # sd_card_ready 396 # sd_card_ready
377 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()), 397 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()),
378 # sd_card_ready 398 # sd_card_ready
379 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()), 399 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()),
380 # sd_card_ready 400 # sd_card_ready
381 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()), 401 (self.call.device.GetExternalStoragePath(), self.AdbCommandError()),
382 # sd_card_ready 402 # sd_card_ready
383 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), 403 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'),
384 (self.call.adb.Shell('test -d /fake/storage/path'), ''), 404 (self.call.adb.Shell('test -d /fake/storage/path'), ''),
385 # pm_ready 405 # pm_ready
386 (self.call.device.GetApplicationPath('android'), 406 (self.call.device.GetApplicationPaths('android'),
387 'package:/some/fake/path'), 407 ['package:/some/fake/path']),
388 # boot_completed 408 # boot_completed
389 (self.call.device.GetProp('sys.boot_completed'), '1')): 409 (self.call.device.GetProp('sys.boot_completed'), '1')):
390 self.device.WaitUntilFullyBooted(wifi=False) 410 self.device.WaitUntilFullyBooted(wifi=False)
391 411
392 def testWaitUntilFullyBooted_sdCardReadyFails_noPath(self): 412 def testWaitUntilFullyBooted_sdCardReadyFails_noPath(self):
393 with self.assertCalls( 413 with self.assertCalls(
394 self.call.adb.WaitForDevice(), 414 self.call.adb.WaitForDevice(),
395 # sd_card_ready 415 # sd_card_ready
396 (self.call.device.GetExternalStoragePath(), self.CommandError())): 416 (self.call.device.GetExternalStoragePath(), self.CommandError())):
397 with self.assertRaises(device_errors.CommandFailedError): 417 with self.assertRaises(device_errors.CommandFailedError):
(...skipping 15 matching lines...) Expand all
413 with self.assertRaises(device_errors.CommandTimeoutError): 433 with self.assertRaises(device_errors.CommandTimeoutError):
414 self.device.WaitUntilFullyBooted(wifi=False) 434 self.device.WaitUntilFullyBooted(wifi=False)
415 435
416 def testWaitUntilFullyBooted_devicePmFails(self): 436 def testWaitUntilFullyBooted_devicePmFails(self):
417 with self.assertCalls( 437 with self.assertCalls(
418 self.call.adb.WaitForDevice(), 438 self.call.adb.WaitForDevice(),
419 # sd_card_ready 439 # sd_card_ready
420 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), 440 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'),
421 (self.call.adb.Shell('test -d /fake/storage/path'), ''), 441 (self.call.adb.Shell('test -d /fake/storage/path'), ''),
422 # pm_ready 442 # pm_ready
423 (self.call.device.GetApplicationPath('android'), self.CommandError()), 443 (self.call.device.GetApplicationPaths('android'), self.CommandError()),
424 # pm_ready 444 # pm_ready
425 (self.call.device.GetApplicationPath('android'), self.CommandError()), 445 (self.call.device.GetApplicationPaths('android'), self.CommandError()),
426 # pm_ready 446 # pm_ready
427 (self.call.device.GetApplicationPath('android'), self.TimeoutError())): 447 (self.call.device.GetApplicationPaths('android'), self.TimeoutError())):
428 with self.assertRaises(device_errors.CommandTimeoutError): 448 with self.assertRaises(device_errors.CommandTimeoutError):
429 self.device.WaitUntilFullyBooted(wifi=False) 449 self.device.WaitUntilFullyBooted(wifi=False)
430 450
431 def testWaitUntilFullyBooted_bootFails(self): 451 def testWaitUntilFullyBooted_bootFails(self):
432 with self.assertCalls( 452 with self.assertCalls(
433 self.call.adb.WaitForDevice(), 453 self.call.adb.WaitForDevice(),
434 # sd_card_ready 454 # sd_card_ready
435 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), 455 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'),
436 (self.call.adb.Shell('test -d /fake/storage/path'), ''), 456 (self.call.adb.Shell('test -d /fake/storage/path'), ''),
437 # pm_ready 457 # pm_ready
438 (self.call.device.GetApplicationPath('android'), 458 (self.call.device.GetApplicationPaths('android'),
439 'package:/some/fake/path'), 459 ['package:/some/fake/path']),
440 # boot_completed 460 # boot_completed
441 (self.call.device.GetProp('sys.boot_completed'), '0'), 461 (self.call.device.GetProp('sys.boot_completed'), '0'),
442 # boot_completed 462 # boot_completed
443 (self.call.device.GetProp('sys.boot_completed'), '0'), 463 (self.call.device.GetProp('sys.boot_completed'), '0'),
444 # boot_completed 464 # boot_completed
445 (self.call.device.GetProp('sys.boot_completed'), self.TimeoutError())): 465 (self.call.device.GetProp('sys.boot_completed'), self.TimeoutError())):
446 with self.assertRaises(device_errors.CommandTimeoutError): 466 with self.assertRaises(device_errors.CommandTimeoutError):
447 self.device.WaitUntilFullyBooted(wifi=False) 467 self.device.WaitUntilFullyBooted(wifi=False)
448 468
449 def testWaitUntilFullyBooted_wifiFails(self): 469 def testWaitUntilFullyBooted_wifiFails(self):
450 with self.assertCalls( 470 with self.assertCalls(
451 self.call.adb.WaitForDevice(), 471 self.call.adb.WaitForDevice(),
452 # sd_card_ready 472 # sd_card_ready
453 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'), 473 (self.call.device.GetExternalStoragePath(), '/fake/storage/path'),
454 (self.call.adb.Shell('test -d /fake/storage/path'), ''), 474 (self.call.adb.Shell('test -d /fake/storage/path'), ''),
455 # pm_ready 475 # pm_ready
456 (self.call.device.GetApplicationPath('android'), 476 (self.call.device.GetApplicationPaths('android'),
457 'package:/some/fake/path'), 477 ['package:/some/fake/path']),
458 # boot_completed 478 # boot_completed
459 (self.call.device.GetProp('sys.boot_completed'), '1'), 479 (self.call.device.GetProp('sys.boot_completed'), '1'),
460 # wifi_enabled 480 # wifi_enabled
461 (self.call.adb.Shell('dumpsys wifi'), 'stuff\nmore stuff\n'), 481 (self.call.adb.Shell('dumpsys wifi'), 'stuff\nmore stuff\n'),
462 # wifi_enabled 482 # wifi_enabled
463 (self.call.adb.Shell('dumpsys wifi'), 'stuff\nmore stuff\n'), 483 (self.call.adb.Shell('dumpsys wifi'), 'stuff\nmore stuff\n'),
464 # wifi_enabled 484 # wifi_enabled
465 (self.call.adb.Shell('dumpsys wifi'), self.TimeoutError())): 485 (self.call.adb.Shell('dumpsys wifi'), self.TimeoutError())):
466 with self.assertRaises(device_errors.CommandTimeoutError): 486 with self.assertRaises(device_errors.CommandTimeoutError):
467 self.device.WaitUntilFullyBooted(wifi=True) 487 self.device.WaitUntilFullyBooted(wifi=True)
(...skipping 25 matching lines...) Expand all
493 self.call.device.WaitUntilFullyBooted(wifi=True)): 513 self.call.device.WaitUntilFullyBooted(wifi=True)):
494 self.device.Reboot(block=True, wifi=True) 514 self.device.Reboot(block=True, wifi=True)
495 515
496 516
497 class DeviceUtilsInstallTest(DeviceUtilsTest): 517 class DeviceUtilsInstallTest(DeviceUtilsTest):
498 518
499 def testInstall_noPriorInstall(self): 519 def testInstall_noPriorInstall(self):
500 with self.assertCalls( 520 with self.assertCalls(
501 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), 521 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'),
502 'this.is.a.test.package'), 522 'this.is.a.test.package'),
503 (self.call.device.GetApplicationPath('this.is.a.test.package'), None), 523 (self.call.device.GetApplicationPaths('this.is.a.test.package'), []),
504 self.call.adb.Install('/fake/test/app.apk', reinstall=False)): 524 self.call.adb.Install('/fake/test/app.apk', reinstall=False)):
505 self.device.Install('/fake/test/app.apk', retries=0) 525 self.device.Install('/fake/test/app.apk', retries=0)
506 526
507 def testInstall_differentPriorInstall(self): 527 def testInstall_differentPriorInstall(self):
508 with self.assertCalls( 528 with self.assertCalls(
509 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), 529 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'),
510 'this.is.a.test.package'), 530 'this.is.a.test.package'),
511 (self.call.device.GetApplicationPath('this.is.a.test.package'), 531 (self.call.device.GetApplicationPaths('this.is.a.test.package'),
512 '/fake/data/app/this.is.a.test.package.apk'), 532 ['/fake/data/app/this.is.a.test.package.apk']),
513 (self.call.device._GetChangedFilesImpl( 533 (self.call.device._GetChangedAndStaleFiles(
514 '/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk'), 534 '/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk'),
515 [('/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk')]), 535 ([('/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk')],
536 [])),
516 self.call.adb.Uninstall('this.is.a.test.package'), 537 self.call.adb.Uninstall('this.is.a.test.package'),
517 self.call.adb.Install('/fake/test/app.apk', reinstall=False)): 538 self.call.adb.Install('/fake/test/app.apk', reinstall=False)):
518 self.device.Install('/fake/test/app.apk', retries=0) 539 self.device.Install('/fake/test/app.apk', retries=0)
519 540
520 def testInstall_differentPriorInstall_reinstall(self): 541 def testInstall_differentPriorInstall_reinstall(self):
521 with self.assertCalls( 542 with self.assertCalls(
522 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), 543 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'),
523 'this.is.a.test.package'), 544 'this.is.a.test.package'),
524 (self.call.device.GetApplicationPath('this.is.a.test.package'), 545 (self.call.device.GetApplicationPaths('this.is.a.test.package'),
525 '/fake/data/app/this.is.a.test.package.apk'), 546 ['/fake/data/app/this.is.a.test.package.apk']),
526 (self.call.device._GetChangedFilesImpl( 547 (self.call.device._GetChangedAndStaleFiles(
527 '/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk'), 548 '/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk'),
528 [('/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk')]), 549 ([('/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk')],
550 [])),
529 self.call.adb.Install('/fake/test/app.apk', reinstall=True)): 551 self.call.adb.Install('/fake/test/app.apk', reinstall=True)):
530 self.device.Install('/fake/test/app.apk', reinstall=True, retries=0) 552 self.device.Install('/fake/test/app.apk', reinstall=True, retries=0)
531 553
532 def testInstall_identicalPriorInstall(self): 554 def testInstall_identicalPriorInstall(self):
533 with self.assertCalls( 555 with self.assertCalls(
534 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), 556 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'),
535 'this.is.a.test.package'), 557 'this.is.a.test.package'),
536 (self.call.device.GetApplicationPath('this.is.a.test.package'), 558 (self.call.device.GetApplicationPaths('this.is.a.test.package'),
537 '/fake/data/app/this.is.a.test.package.apk'), 559 ['/fake/data/app/this.is.a.test.package.apk']),
538 (self.call.device._GetChangedFilesImpl( 560 (self.call.device._GetChangedAndStaleFiles(
539 '/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk'), 561 '/fake/test/app.apk', '/fake/data/app/this.is.a.test.package.apk'),
540 [])): 562 ([], []))):
541 self.device.Install('/fake/test/app.apk', retries=0) 563 self.device.Install('/fake/test/app.apk', retries=0)
542 564
543 def testInstall_fails(self): 565 def testInstall_fails(self):
544 with self.assertCalls( 566 with self.assertCalls(
545 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'), 567 (mock.call.pylib.utils.apk_helper.GetPackageName('/fake/test/app.apk'),
546 'this.is.a.test.package'), 568 'this.is.a.test.package'),
547 (self.call.device.GetApplicationPath('this.is.a.test.package'), None), 569 (self.call.device.GetApplicationPaths('this.is.a.test.package'), []),
548 (self.call.adb.Install('/fake/test/app.apk', reinstall=False), 570 (self.call.adb.Install('/fake/test/app.apk', reinstall=False),
549 self.CommandError('Failure\r\n'))): 571 self.CommandError('Failure\r\n'))):
550 with self.assertRaises(device_errors.CommandFailedError): 572 with self.assertRaises(device_errors.CommandFailedError):
551 self.device.Install('/fake/test/app.apk', retries=0) 573 self.device.Install('/fake/test/app.apk', retries=0)
552 574
575 class DeviceUtilsInstallSplitApkTest(DeviceUtilsTest):
576
577 def testInstallSplitApk_noPriorInstall(self):
578 with self.assertCalls(
579 (self.call.device._CheckSdkLevel(21)),
580 (mock.call.pylib.sdk.split_select.SelectSplits(
581 self.device, 'base.apk',
582 ['split1.apk', 'split2.apk', 'split3.apk']),
583 ['split2.apk']),
584 (mock.call.pylib.utils.apk_helper.GetPackageName('base.apk'),
585 'this.is.a.test.package'),
586 (self.call.device.GetApplicationPaths('this.is.a.test.package'), []),
587 (self.call.adb.InstallMultiple(
588 ['base.apk', 'split2.apk'], partial=None, reinstall=False))):
589 self.device.InstallSplitApk('base.apk',
590 ['split1.apk', 'split2.apk', 'split3.apk'], retries=0)
591
592 def testInstallSplitApk_partialInstall(self):
593 with self.assertCalls(
594 (self.call.device._CheckSdkLevel(21)),
595 (mock.call.pylib.sdk.split_select.SelectSplits(
596 self.device, 'base.apk',
597 ['split1.apk', 'split2.apk', 'split3.apk']),
598 ['split2.apk']),
599 (mock.call.pylib.utils.apk_helper.GetPackageName('base.apk'),
600 'test.package'),
601 (self.call.device.GetApplicationPaths('test.package'),
602 ['base-on-device.apk', 'split2-on-device.apk']),
603 (mock.call.pylib.utils.md5sum.CalculateDeviceMd5Sums(
604 ['base-on-device.apk', 'split2-on-device.apk'], self.device),
605 {'base-on-device.apk': 'AAA', 'split2-on-device.apk': 'BBB'}),
606 (mock.call.pylib.utils.md5sum.CalculateHostMd5Sums(
607 ['base.apk', 'split2.apk']),
608 {'base.apk': 'AAA', 'split2.apk': 'CCC'}),
609 (self.call.adb.InstallMultiple(
610 ['split2.apk'], partial='test.package', reinstall=True))):
611 self.device.InstallSplitApk('base.apk',
612 ['split1.apk', 'split2.apk', 'split3.apk'], reinstall=True, retries=0)
613
553 614
554 class DeviceUtilsRunShellCommandTest(DeviceUtilsTest): 615 class DeviceUtilsRunShellCommandTest(DeviceUtilsTest):
555 616
556 def setUp(self): 617 def setUp(self):
557 super(DeviceUtilsRunShellCommandTest, self).setUp() 618 super(DeviceUtilsRunShellCommandTest, self).setUp()
558 self.device.NeedsSU = mock.Mock(return_value=False) 619 self.device.NeedsSU = mock.Mock(return_value=False)
559 620
560 def testRunShellCommand_commandAsList(self): 621 def testRunShellCommand_commandAsList(self):
561 with self.assertCall(self.call.adb.Shell('pm list packages'), ''): 622 with self.assertCall(self.call.adb.Shell('pm list packages'), ''):
562 self.device.RunShellCommand(['pm', 'list', 'packages']) 623 self.device.RunShellCommand(['pm', 'list', 'packages'])
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 'Starting: Intent { act=android.intent.action.VIEW }'): 1026 'Starting: Intent { act=android.intent.action.VIEW }'):
966 self.device.StartActivity(test_intent) 1027 self.device.StartActivity(test_intent)
967 1028
968 1029
969 class DeviceUtilsStartInstrumentationTest(DeviceUtilsTest): 1030 class DeviceUtilsStartInstrumentationTest(DeviceUtilsTest):
970 1031
971 def testStartInstrumentation_nothing(self): 1032 def testStartInstrumentation_nothing(self):
972 with self.assertCalls( 1033 with self.assertCalls(
973 self.call.device.RunShellCommand( 1034 self.call.device.RunShellCommand(
974 ['am', 'instrument', 'test.package/.TestInstrumentation'], 1035 ['am', 'instrument', 'test.package/.TestInstrumentation'],
975 check_return=True)): 1036 check_return=True, large_output=True)):
976 self.device.StartInstrumentation( 1037 self.device.StartInstrumentation(
977 'test.package/.TestInstrumentation', 1038 'test.package/.TestInstrumentation',
978 finish=False, raw=False, extras=None) 1039 finish=False, raw=False, extras=None)
979 1040
980 def testStartInstrumentation_finish(self): 1041 def testStartInstrumentation_finish(self):
981 with self.assertCalls( 1042 with self.assertCalls(
982 (self.call.device.RunShellCommand( 1043 (self.call.device.RunShellCommand(
983 ['am', 'instrument', '-w', 'test.package/.TestInstrumentation'], 1044 ['am', 'instrument', '-w', 'test.package/.TestInstrumentation'],
984 check_return=True), 1045 check_return=True, large_output=True),
985 ['OK (1 test)'])): 1046 ['OK (1 test)'])):
986 output = self.device.StartInstrumentation( 1047 output = self.device.StartInstrumentation(
987 'test.package/.TestInstrumentation', 1048 'test.package/.TestInstrumentation',
988 finish=True, raw=False, extras=None) 1049 finish=True, raw=False, extras=None)
989 self.assertEquals(['OK (1 test)'], output) 1050 self.assertEquals(['OK (1 test)'], output)
990 1051
991 def testStartInstrumentation_raw(self): 1052 def testStartInstrumentation_raw(self):
992 with self.assertCalls( 1053 with self.assertCalls(
993 self.call.device.RunShellCommand( 1054 self.call.device.RunShellCommand(
994 ['am', 'instrument', '-r', 'test.package/.TestInstrumentation'], 1055 ['am', 'instrument', '-r', 'test.package/.TestInstrumentation'],
995 check_return=True)): 1056 check_return=True, large_output=True)):
996 self.device.StartInstrumentation( 1057 self.device.StartInstrumentation(
997 'test.package/.TestInstrumentation', 1058 'test.package/.TestInstrumentation',
998 finish=False, raw=True, extras=None) 1059 finish=False, raw=True, extras=None)
999 1060
1000 def testStartInstrumentation_extras(self): 1061 def testStartInstrumentation_extras(self):
1001 with self.assertCalls( 1062 with self.assertCalls(
1002 self.call.device.RunShellCommand( 1063 self.call.device.RunShellCommand(
1003 ['am', 'instrument', '-e', 'foo', 'Foo', '-e', 'bar', 'Bar', 1064 ['am', 'instrument', '-e', 'foo', 'Foo', '-e', 'bar', 'Bar',
1004 'test.package/.TestInstrumentation'], 1065 'test.package/.TestInstrumentation'],
1005 check_return=True)): 1066 check_return=True, large_output=True)):
1006 self.device.StartInstrumentation( 1067 self.device.StartInstrumentation(
1007 'test.package/.TestInstrumentation', 1068 'test.package/.TestInstrumentation',
1008 finish=False, raw=False, extras={'foo': 'Foo', 'bar': 'Bar'}) 1069 finish=False, raw=False, extras={'foo': 'Foo', 'bar': 'Bar'})
1009 1070
1010 1071
1011 class DeviceUtilsBroadcastIntentTest(DeviceUtilsTest): 1072 class DeviceUtilsBroadcastIntentTest(DeviceUtilsTest):
1012 1073
1013 def testBroadcastIntent_noExtras(self): 1074 def testBroadcastIntent_noExtras(self):
1014 test_intent = intent.Intent(action='test.package.with.an.INTENT') 1075 test_intent = intent.Intent(action='test.package.with.an.INTENT')
1015 with self.assertCall( 1076 with self.assertCall(
(...skipping 15 matching lines...) Expand all
1031 extras={'foo': None}) 1092 extras={'foo': None})
1032 with self.assertCall( 1093 with self.assertCall(
1033 self.call.adb.Shell( 1094 self.call.adb.Shell(
1034 'am broadcast -a test.package.with.an.INTENT --esn foo'), 1095 'am broadcast -a test.package.with.an.INTENT --esn foo'),
1035 'Broadcasting: Intent { act=test.package.with.an.INTENT } '): 1096 'Broadcasting: Intent { act=test.package.with.an.INTENT } '):
1036 self.device.BroadcastIntent(test_intent) 1097 self.device.BroadcastIntent(test_intent)
1037 1098
1038 1099
1039 class DeviceUtilsGoHomeTest(DeviceUtilsTest): 1100 class DeviceUtilsGoHomeTest(DeviceUtilsTest):
1040 1101
1041 def testGoHome(self): 1102 def testGoHome_popupsExist(self):
1042 with self.assertCall( 1103 with self.assertCalls(
1043 self.call.adb.Shell('am start -W -a android.intent.action.MAIN ' 1104 (self.call.device.RunShellCommand(
1044 '-c android.intent.category.HOME'), 1105 ['dumpsys', 'window', 'windows'], check_return=True,
1045 'Starting: Intent { act=android.intent.action.MAIN }\r\n'): 1106 large_output=True), []),
1107 (self.call.device.RunShellCommand(
1108 ['am', 'start', '-W', '-a', 'android.intent.action.MAIN',
1109 '-c', 'android.intent.category.HOME'], check_return=True),
1110 'Starting: Intent { act=android.intent.action.MAIN }\r\n'''),
1111 (self.call.device.RunShellCommand(
1112 ['dumpsys', 'window', 'windows'], check_return=True,
1113 large_output=True), []),
1114 (self.call.device.RunShellCommand(
1115 ['input', 'keyevent', '66'], check_return=True)),
1116 (self.call.device.RunShellCommand(
1117 ['input', 'keyevent', '4'], check_return=True)),
1118 (self.call.device.RunShellCommand(
1119 ['dumpsys', 'window', 'windows'], check_return=True,
1120 large_output=True),
1121 ['mCurrentFocus Launcher'])):
1046 self.device.GoHome() 1122 self.device.GoHome()
1047 1123
1124 def testGoHome_willRetry(self):
1125 with self.assertCalls(
1126 (self.call.device.RunShellCommand(
1127 ['dumpsys', 'window', 'windows'], check_return=True,
1128 large_output=True), []),
1129 (self.call.device.RunShellCommand(
1130 ['am', 'start', '-W', '-a', 'android.intent.action.MAIN',
1131 '-c', 'android.intent.category.HOME'], check_return=True),
1132 'Starting: Intent { act=android.intent.action.MAIN }\r\n'''),
1133 (self.call.device.RunShellCommand(
1134 ['dumpsys', 'window', 'windows'], check_return=True,
1135 large_output=True), []),
1136 (self.call.device.RunShellCommand(
1137 ['input', 'keyevent', '66'], check_return=True,)),
1138 (self.call.device.RunShellCommand(
1139 ['input', 'keyevent', '4'], check_return=True)),
1140 (self.call.device.RunShellCommand(
1141 ['dumpsys', 'window', 'windows'], check_return=True,
1142 large_output=True), []),
1143 (self.call.device.RunShellCommand(
1144 ['input', 'keyevent', '66'], check_return=True)),
1145 (self.call.device.RunShellCommand(
1146 ['input', 'keyevent', '4'], check_return=True)),
1147 (self.call.device.RunShellCommand(
1148 ['dumpsys', 'window', 'windows'], check_return=True,
1149 large_output=True),
1150 self.TimeoutError())):
1151 with self.assertRaises(device_errors.CommandTimeoutError):
1152 self.device.GoHome()
1153
1154 def testGoHome_alreadyFocused(self):
1155 with self.assertCall(
1156 self.call.device.RunShellCommand(
1157 ['dumpsys', 'window', 'windows'], check_return=True,
1158 large_output=True),
1159 ['mCurrentFocus Launcher']):
1160 self.device.GoHome()
1161
1162 def testGoHome_alreadyFocusedAlternateCase(self):
1163 with self.assertCall(
1164 self.call.device.RunShellCommand(
1165 ['dumpsys', 'window', 'windows'], check_return=True,
1166 large_output=True),
1167 [' mCurrentFocus .launcher/.']):
1168 self.device.GoHome()
1169
1170 def testGoHome_obtainsFocusAfterGoingHome(self):
1171 with self.assertCalls(
1172 (self.call.device.RunShellCommand(
1173 ['dumpsys', 'window', 'windows'], check_return=True,
1174 large_output=True), []),
1175 (self.call.device.RunShellCommand(
1176 ['am', 'start', '-W', '-a', 'android.intent.action.MAIN',
1177 '-c', 'android.intent.category.HOME'], check_return=True),
1178 'Starting: Intent { act=android.intent.action.MAIN }\r\n'''),
1179 (self.call.device.RunShellCommand(
1180 ['dumpsys', 'window', 'windows'], check_return=True,
1181 large_output=True),
1182 ['mCurrentFocus Launcher'])):
1183 self.device.GoHome()
1048 1184
1049 class DeviceUtilsForceStopTest(DeviceUtilsTest): 1185 class DeviceUtilsForceStopTest(DeviceUtilsTest):
1050 1186
1051 def testForceStop(self): 1187 def testForceStop(self):
1052 with self.assertCall( 1188 with self.assertCall(
1053 self.call.adb.Shell('am force-stop this.is.a.test.package'), 1189 self.call.adb.Shell('am force-stop this.is.a.test.package'),
1054 ''): 1190 ''):
1055 self.device.ForceStop('this.is.a.test.package') 1191 self.device.ForceStop('this.is.a.test.package')
1056 1192
1057 1193
1058 class DeviceUtilsClearApplicationStateTest(DeviceUtilsTest): 1194 class DeviceUtilsClearApplicationStateTest(DeviceUtilsTest):
1059 1195
1060 def testClearApplicationState_packageDoesntExist(self): 1196 def testClearApplicationState_packageDoesntExist(self):
1061 with self.assertCalls( 1197 with self.assertCalls(
1062 (self.call.adb.Shell('getprop ro.build.version.sdk'), '17\n'), 1198 (self.call.adb.Shell('getprop ro.build.version.sdk'), '17\n'),
1063 (self.call.device.GetApplicationPath('this.package.does.not.exist'), 1199 (self.call.device.GetApplicationPaths('this.package.does.not.exist'),
1064 None)): 1200 [])):
1065 self.device.ClearApplicationState('this.package.does.not.exist') 1201 self.device.ClearApplicationState('this.package.does.not.exist')
1066 1202
1067 def testClearApplicationState_packageDoesntExistOnAndroidJBMR2OrAbove(self): 1203 def testClearApplicationState_packageDoesntExistOnAndroidJBMR2OrAbove(self):
1068 with self.assertCalls( 1204 with self.assertCalls(
1069 (self.call.adb.Shell('getprop ro.build.version.sdk'), '18\n'), 1205 (self.call.adb.Shell('getprop ro.build.version.sdk'), '18\n'),
1070 (self.call.adb.Shell('pm clear this.package.does.not.exist'), 1206 (self.call.adb.Shell('pm clear this.package.does.not.exist'),
1071 'Failed\r\n')): 1207 'Failed\r\n')):
1072 self.device.ClearApplicationState('this.package.does.not.exist') 1208 self.device.ClearApplicationState('this.package.does.not.exist')
1073 1209
1074 def testClearApplicationState_packageExists(self): 1210 def testClearApplicationState_packageExists(self):
1075 with self.assertCalls( 1211 with self.assertCalls(
1076 (self.call.adb.Shell('getprop ro.build.version.sdk'), '17\n'), 1212 (self.call.adb.Shell('getprop ro.build.version.sdk'), '17\n'),
1077 (self.call.device.GetApplicationPath('this.package.exists'), 1213 (self.call.device.GetApplicationPaths('this.package.exists'),
1078 '/data/app/this.package.exists.apk'), 1214 ['/data/app/this.package.exists.apk']),
1079 (self.call.adb.Shell('pm clear this.package.exists'), 1215 (self.call.adb.Shell('pm clear this.package.exists'),
1080 'Success\r\n')): 1216 'Success\r\n')):
1081 self.device.ClearApplicationState('this.package.exists') 1217 self.device.ClearApplicationState('this.package.exists')
1082 1218
1083 def testClearApplicationState_packageExistsOnAndroidJBMR2OrAbove(self): 1219 def testClearApplicationState_packageExistsOnAndroidJBMR2OrAbove(self):
1084 with self.assertCalls( 1220 with self.assertCalls(
1085 (self.call.adb.Shell('getprop ro.build.version.sdk'), '18\n'), 1221 (self.call.adb.Shell('getprop ro.build.version.sdk'), '18\n'),
1086 (self.call.adb.Shell('pm clear this.package.exists'), 1222 (self.call.adb.Shell('pm clear this.package.exists'),
1087 'Success\r\n')): 1223 'Success\r\n')):
1088 self.device.ClearApplicationState('this.package.exists') 1224 self.device.ClearApplicationState('this.package.exists')
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
1700 devices = device_utils.DeviceUtils.HealthyDevices() 1836 devices = device_utils.DeviceUtils.HealthyDevices()
1701 self.assertEquals(1, len(devices)) 1837 self.assertEquals(1, len(devices))
1702 self.assertTrue(isinstance(devices[0], device_utils.DeviceUtils)) 1838 self.assertTrue(isinstance(devices[0], device_utils.DeviceUtils))
1703 self.assertEquals('0123456789abcdef', devices[0].adb.GetDeviceSerial()) 1839 self.assertEquals('0123456789abcdef', devices[0].adb.GetDeviceSerial())
1704 1840
1705 1841
1706 if __name__ == '__main__': 1842 if __name__ == '__main__':
1707 logging.getLogger().setLevel(logging.DEBUG) 1843 logging.getLogger().setLevel(logging.DEBUG)
1708 unittest.main(verbosity=2) 1844 unittest.main(verbosity=2)
1709 1845
OLDNEW
« no previous file with comments | « build/android/pylib/device/device_utils_device_test.py ('k') | build/android/pylib/gtest/filter/cc_unittests_disabled » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698