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

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

Issue 816543004: Update from https://crrev.com/308996 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/android/pylib/device/device_utils.py ('k') | build/android/pylib/device/intent.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """ 6 """
7 Unit tests for the contents of device_utils.py (mostly DeviceUtils). 7 Unit tests for the contents of device_utils.py (mostly DeviceUtils).
8 """ 8 """
9 9
10 # pylint: disable=C0321 10 # pylint: disable=C0321
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 def __exit__(self, exc_type, exc_val, exc_tb): 96 def __exit__(self, exc_type, exc_val, exc_tb):
97 pass 97 pass
98 98
99 99
100 class _PatchedFunction(object): 100 class _PatchedFunction(object):
101 def __init__(self, patched=None, mocked=None): 101 def __init__(self, patched=None, mocked=None):
102 self.patched = patched 102 self.patched = patched
103 self.mocked = mocked 103 self.mocked = mocked
104 104
105 105
106 class MockFileSystem(object):
107
108 @staticmethod
109 def osStatResult(
110 st_mode=None, st_ino=None, st_dev=None, st_nlink=None, st_uid=None,
111 st_gid=None, st_size=None, st_atime=None, st_mtime=None, st_ctime=None):
112 MockOSStatResult = collections.namedtuple('MockOSStatResult', [
113 'st_mode', 'st_ino', 'st_dev', 'st_nlink', 'st_uid', 'st_gid',
114 'st_size', 'st_atime', 'st_mtime', 'st_ctime'])
115 return MockOSStatResult(st_mode, st_ino, st_dev, st_nlink, st_uid, st_gid,
116 st_size, st_atime, st_mtime, st_ctime)
117
118 MOCKED_FUNCTIONS = [
119 ('os.listdir', []),
120 ('os.path.abspath', ''),
121 ('os.path.dirname', ''),
122 ('os.path.exists', False),
123 ('os.path.getsize', 0),
124 ('os.path.isdir', False),
125 ('os.stat', osStatResult.__func__()),
126 ('os.walk', []),
127 ]
128
129 def _get(self, mocked, path, default_val):
130 if self._verbose:
131 logging.debug('%s(%s)' % (mocked, path))
132 return (self.mock_file_info[path][mocked]
133 if path in self.mock_file_info
134 else default_val)
135
136 def _patched(self, target, default_val=None):
137 r = lambda f: self._get(target, f, default_val)
138 return _PatchedFunction(patched=mock.patch(target, side_effect=r))
139
140 def __init__(self, verbose=False):
141 self.mock_file_info = {}
142 self._patched_functions = [
143 self._patched(m, d) for m, d in type(self).MOCKED_FUNCTIONS]
144 self._verbose = verbose
145
146 def addMockFile(self, path, **kw):
147 self._addMockThing(path, False, **kw)
148
149 def addMockDirectory(self, path, **kw):
150 self._addMockThing(path, True, **kw)
151
152 def _addMockThing(self, path, is_dir, listdir=None, size=0, stat=None,
153 walk=None):
154 if listdir is None:
155 listdir = []
156 if stat is None:
157 stat = self.osStatResult()
158 if walk is None:
159 walk = []
160
161 dirname = os.sep.join(path.rstrip(os.sep).split(os.sep)[:-1])
162 if dirname and not dirname in self.mock_file_info:
163 self._addMockThing(dirname, True)
164
165 self.mock_file_info[path] = {
166 'os.listdir': listdir,
167 'os.path.abspath': path,
168 'os.path.dirname': dirname,
169 'os.path.exists': True,
170 'os.path.isdir': is_dir,
171 'os.path.getsize': size,
172 'os.stat': stat,
173 'os.walk': walk,
174 }
175
176 def __enter__(self):
177 for p in self._patched_functions:
178 p.mocked = p.patched.__enter__()
179
180 def __exit__(self, exc_type, exc_val, exc_tb):
181 for p in self._patched_functions:
182 p.patched.__exit__()
183
184
185 class DeviceUtilsOldImplTest(unittest.TestCase): 106 class DeviceUtilsOldImplTest(unittest.TestCase):
186 107
187 class AndroidCommandsCalls(object): 108 class AndroidCommandsCalls(object):
188 109
189 def __init__(self, test_case, cmd_ret, comp): 110 def __init__(self, test_case, cmd_ret, comp):
190 self._cmds = cmd_ret 111 self._cmds = cmd_ret
191 self._comp = comp 112 self._comp = comp
192 self._run_command = _PatchedFunction() 113 self._run_command = _PatchedFunction()
193 self._test_case = test_case 114 self._test_case = test_case
194 self._total_received = 0 115 self._total_received = 0
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 def testKillAll_sigterm(self): 651 def testKillAll_sigterm(self):
731 with self.assertCalls( 652 with self.assertCalls(
732 (self.call.adb.Shell('ps'), 653 (self.call.adb.Shell('ps'),
733 'USER PID PPID VSIZE RSS WCHAN PC NAME\n' 654 'USER PID PPID VSIZE RSS WCHAN PC NAME\n'
734 'u0_a1 1234 174 123456 54321 ffffffff 456789ab some.process\n'), 655 'u0_a1 1234 174 123456 54321 ffffffff 456789ab some.process\n'),
735 (self.call.adb.Shell('kill -15 1234'), '')): 656 (self.call.adb.Shell('kill -15 1234'), '')):
736 self.assertEquals(1, 657 self.assertEquals(1,
737 self.device.KillAll('some.process', signum=signal.SIGTERM)) 658 self.device.KillAll('some.process', signum=signal.SIGTERM))
738 659
739 660
740 class DeviceUtilsStartActivityTest(DeviceUtilsOldImplTest): 661 class DeviceUtilsStartActivityTest(DeviceUtilsNewImplTest):
741 662
742 def testStartActivity_actionOnly(self): 663 def testStartActivity_actionOnly(self):
743 test_intent = intent.Intent(action='android.intent.action.VIEW') 664 test_intent = intent.Intent(action='android.intent.action.VIEW')
744 with self.assertCalls( 665 with self.assertCall(
745 "adb -s 0123456789abcdef shell 'am start " 666 self.call.adb.Shell('am start '
746 "-a android.intent.action.VIEW'", 667 '-a android.intent.action.VIEW'),
747 'Starting: Intent { act=android.intent.action.VIEW }'): 668 'Starting: Intent { act=android.intent.action.VIEW }'):
748 self.device.StartActivity(test_intent) 669 self.device.StartActivity(test_intent)
749 670
750 def testStartActivity_success(self): 671 def testStartActivity_success(self):
751 test_intent = intent.Intent(action='android.intent.action.VIEW', 672 test_intent = intent.Intent(action='android.intent.action.VIEW',
752 package='this.is.a.test.package', 673 package='this.is.a.test.package',
753 activity='.Main') 674 activity='.Main')
754 with self.assertCalls( 675 with self.assertCall(
755 "adb -s 0123456789abcdef shell 'am start " 676 self.call.adb.Shell('am start '
756 "-a android.intent.action.VIEW " 677 '-a android.intent.action.VIEW '
757 "-n this.is.a.test.package/.Main'", 678 '-n this.is.a.test.package/.Main'),
758 'Starting: Intent { act=android.intent.action.VIEW }'): 679 'Starting: Intent { act=android.intent.action.VIEW }'):
759 self.device.StartActivity(test_intent) 680 self.device.StartActivity(test_intent)
760 681
761 def testStartActivity_failure(self): 682 def testStartActivity_failure(self):
762 test_intent = intent.Intent(action='android.intent.action.VIEW', 683 test_intent = intent.Intent(action='android.intent.action.VIEW',
763 package='this.is.a.test.package', 684 package='this.is.a.test.package',
764 activity='.Main') 685 activity='.Main')
765 with self.assertCalls( 686 with self.assertCall(
766 "adb -s 0123456789abcdef shell 'am start " 687 self.call.adb.Shell('am start '
767 "-a android.intent.action.VIEW " 688 '-a android.intent.action.VIEW '
768 "-n this.is.a.test.package/.Main'", 689 '-n this.is.a.test.package/.Main'),
769 'Error: Failed to start test activity'): 690 'Error: Failed to start test activity'):
770 with self.assertRaises(device_errors.CommandFailedError): 691 with self.assertRaises(device_errors.CommandFailedError):
771 self.device.StartActivity(test_intent) 692 self.device.StartActivity(test_intent)
772 693
773 def testStartActivity_blocking(self): 694 def testStartActivity_blocking(self):
774 test_intent = intent.Intent(action='android.intent.action.VIEW', 695 test_intent = intent.Intent(action='android.intent.action.VIEW',
775 package='this.is.a.test.package', 696 package='this.is.a.test.package',
776 activity='.Main') 697 activity='.Main')
777 with self.assertCalls( 698 with self.assertCall(
778 "adb -s 0123456789abcdef shell 'am start " 699 self.call.adb.Shell('am start '
779 "-a android.intent.action.VIEW " 700 '-W '
780 "-W " 701 '-a android.intent.action.VIEW '
781 "-n this.is.a.test.package/.Main'", 702 '-n this.is.a.test.package/.Main'),
782 'Starting: Intent { act=android.intent.action.VIEW }'): 703 'Starting: Intent { act=android.intent.action.VIEW }'):
783 self.device.StartActivity(test_intent, blocking=True) 704 self.device.StartActivity(test_intent, blocking=True)
784 705
785 def testStartActivity_withCategory(self): 706 def testStartActivity_withCategory(self):
786 test_intent = intent.Intent(action='android.intent.action.VIEW', 707 test_intent = intent.Intent(action='android.intent.action.VIEW',
787 package='this.is.a.test.package', 708 package='this.is.a.test.package',
788 activity='.Main', 709 activity='.Main',
789 category='android.intent.category.HOME') 710 category='android.intent.category.HOME')
790 with self.assertCalls( 711 with self.assertCall(
791 "adb -s 0123456789abcdef shell 'am start " 712 self.call.adb.Shell('am start '
792 "-a android.intent.action.VIEW " 713 '-a android.intent.action.VIEW '
793 "-c android.intent.category.HOME " 714 '-c android.intent.category.HOME '
794 "-n this.is.a.test.package/.Main'", 715 '-n this.is.a.test.package/.Main'),
795 'Starting: Intent { act=android.intent.action.VIEW }'): 716 'Starting: Intent { act=android.intent.action.VIEW }'):
796 self.device.StartActivity(test_intent) 717 self.device.StartActivity(test_intent)
797 718
798 def testStartActivity_withMultipleCategories(self): 719 def testStartActivity_withMultipleCategories(self):
799 # The new implementation will start the activity with all provided
800 # categories. The old one only uses the first category.
801 test_intent = intent.Intent(action='android.intent.action.VIEW', 720 test_intent = intent.Intent(action='android.intent.action.VIEW',
802 package='this.is.a.test.package', 721 package='this.is.a.test.package',
803 activity='.Main', 722 activity='.Main',
804 category=['android.intent.category.HOME', 723 category=['android.intent.category.HOME',
805 'android.intent.category.BROWSABLE']) 724 'android.intent.category.BROWSABLE'])
806 with self.assertCalls( 725 with self.assertCall(
807 "adb -s 0123456789abcdef shell 'am start " 726 self.call.adb.Shell('am start '
808 "-a android.intent.action.VIEW " 727 '-a android.intent.action.VIEW '
809 "-c android.intent.category.HOME " 728 '-c android.intent.category.HOME '
810 "-n this.is.a.test.package/.Main'", 729 '-c android.intent.category.BROWSABLE '
730 '-n this.is.a.test.package/.Main'),
811 'Starting: Intent { act=android.intent.action.VIEW }'): 731 'Starting: Intent { act=android.intent.action.VIEW }'):
812 self.device.StartActivity(test_intent) 732 self.device.StartActivity(test_intent)
813 733
814 def testStartActivity_withData(self): 734 def testStartActivity_withData(self):
815 test_intent = intent.Intent(action='android.intent.action.VIEW', 735 test_intent = intent.Intent(action='android.intent.action.VIEW',
816 package='this.is.a.test.package', 736 package='this.is.a.test.package',
817 activity='.Main', 737 activity='.Main',
818 data='http://www.google.com/') 738 data='http://www.google.com/')
819 with self.assertCalls( 739 with self.assertCall(
820 "adb -s 0123456789abcdef shell 'am start " 740 self.call.adb.Shell('am start '
821 "-a android.intent.action.VIEW " 741 '-a android.intent.action.VIEW '
822 "-n this.is.a.test.package/.Main " 742 '-d http://www.google.com/ '
823 "-d \"http://www.google.com/\"'", 743 '-n this.is.a.test.package/.Main'),
824 'Starting: Intent { act=android.intent.action.VIEW }'): 744 'Starting: Intent { act=android.intent.action.VIEW }'):
825 self.device.StartActivity(test_intent) 745 self.device.StartActivity(test_intent)
826 746
827 def testStartActivity_withStringExtra(self): 747 def testStartActivity_withStringExtra(self):
828 test_intent = intent.Intent(action='android.intent.action.VIEW', 748 test_intent = intent.Intent(action='android.intent.action.VIEW',
829 package='this.is.a.test.package', 749 package='this.is.a.test.package',
830 activity='.Main', 750 activity='.Main',
831 extras={'foo': 'test'}) 751 extras={'foo': 'test'})
832 with self.assertCalls( 752 with self.assertCall(
833 "adb -s 0123456789abcdef shell 'am start " 753 self.call.adb.Shell('am start '
834 "-a android.intent.action.VIEW " 754 '-a android.intent.action.VIEW '
835 "-n this.is.a.test.package/.Main " 755 '-n this.is.a.test.package/.Main '
836 "--es foo test'", 756 '--es foo test'),
837 'Starting: Intent { act=android.intent.action.VIEW }'): 757 'Starting: Intent { act=android.intent.action.VIEW }'):
838 self.device.StartActivity(test_intent) 758 self.device.StartActivity(test_intent)
839 759
840 def testStartActivity_withBoolExtra(self): 760 def testStartActivity_withBoolExtra(self):
841 test_intent = intent.Intent(action='android.intent.action.VIEW', 761 test_intent = intent.Intent(action='android.intent.action.VIEW',
842 package='this.is.a.test.package', 762 package='this.is.a.test.package',
843 activity='.Main', 763 activity='.Main',
844 extras={'foo': True}) 764 extras={'foo': True})
845 with self.assertCalls( 765 with self.assertCall(
846 "adb -s 0123456789abcdef shell 'am start " 766 self.call.adb.Shell('am start '
847 "-a android.intent.action.VIEW " 767 '-a android.intent.action.VIEW '
848 "-n this.is.a.test.package/.Main " 768 '-n this.is.a.test.package/.Main '
849 "--ez foo True'", 769 '--ez foo True'),
850 'Starting: Intent { act=android.intent.action.VIEW }'): 770 'Starting: Intent { act=android.intent.action.VIEW }'):
851 self.device.StartActivity(test_intent) 771 self.device.StartActivity(test_intent)
852 772
853 def testStartActivity_withIntExtra(self): 773 def testStartActivity_withIntExtra(self):
854 test_intent = intent.Intent(action='android.intent.action.VIEW', 774 test_intent = intent.Intent(action='android.intent.action.VIEW',
855 package='this.is.a.test.package', 775 package='this.is.a.test.package',
856 activity='.Main', 776 activity='.Main',
857 extras={'foo': 123}) 777 extras={'foo': 123})
858 with self.assertCalls( 778 with self.assertCall(
859 "adb -s 0123456789abcdef shell 'am start " 779 self.call.adb.Shell('am start '
860 "-a android.intent.action.VIEW " 780 '-a android.intent.action.VIEW '
861 "-n this.is.a.test.package/.Main " 781 '-n this.is.a.test.package/.Main '
862 "--ei foo 123'", 782 '--ei foo 123'),
863 'Starting: Intent { act=android.intent.action.VIEW }'): 783 'Starting: Intent { act=android.intent.action.VIEW }'):
864 self.device.StartActivity(test_intent) 784 self.device.StartActivity(test_intent)
865 785
866 def testStartActivity_withTraceFile(self): 786 def testStartActivity_withTraceFile(self):
867 test_intent = intent.Intent(action='android.intent.action.VIEW', 787 test_intent = intent.Intent(action='android.intent.action.VIEW',
868 package='this.is.a.test.package', 788 package='this.is.a.test.package',
869 activity='.Main') 789 activity='.Main')
870 with self.assertCalls( 790 with self.assertCall(
871 "adb -s 0123456789abcdef shell 'am start " 791 self.call.adb.Shell('am start '
872 "-a android.intent.action.VIEW " 792 '--start-profiler test_trace_file.out '
873 "-n this.is.a.test.package/.Main " 793 '-a android.intent.action.VIEW '
874 "--start-profiler test_trace_file.out'", 794 '-n this.is.a.test.package/.Main'),
875 'Starting: Intent { act=android.intent.action.VIEW }'): 795 'Starting: Intent { act=android.intent.action.VIEW }'):
876 self.device.StartActivity(test_intent, 796 self.device.StartActivity(test_intent,
877 trace_file_name='test_trace_file.out') 797 trace_file_name='test_trace_file.out')
878 798
879 def testStartActivity_withForceStop(self): 799 def testStartActivity_withForceStop(self):
880 test_intent = intent.Intent(action='android.intent.action.VIEW', 800 test_intent = intent.Intent(action='android.intent.action.VIEW',
881 package='this.is.a.test.package', 801 package='this.is.a.test.package',
882 activity='.Main') 802 activity='.Main')
883 with self.assertCalls( 803 with self.assertCall(
884 "adb -s 0123456789abcdef shell 'am start " 804 self.call.adb.Shell('am start '
885 "-a android.intent.action.VIEW " 805 '-S '
886 "-S " 806 '-a android.intent.action.VIEW '
887 "-n this.is.a.test.package/.Main'", 807 '-n this.is.a.test.package/.Main'),
888 'Starting: Intent { act=android.intent.action.VIEW }'): 808 'Starting: Intent { act=android.intent.action.VIEW }'):
889 self.device.StartActivity(test_intent, force_stop=True) 809 self.device.StartActivity(test_intent, force_stop=True)
890 810
891 def testStartActivity_withFlags(self): 811 def testStartActivity_withFlags(self):
892 test_intent = intent.Intent(action='android.intent.action.VIEW', 812 test_intent = intent.Intent(action='android.intent.action.VIEW',
893 package='this.is.a.test.package', 813 package='this.is.a.test.package',
894 activity='.Main', 814 activity='.Main',
895 flags='0x10000000') 815 flags='0x10000000')
896 with self.assertCalls( 816 with self.assertCall(
897 "adb -s 0123456789abcdef shell 'am start " 817 self.call.adb.Shell('am start '
898 "-a android.intent.action.VIEW " 818 '-a android.intent.action.VIEW '
899 "-n this.is.a.test.package/.Main " 819 '-n this.is.a.test.package/.Main '
900 "-f 0x10000000'", 820 '-f 0x10000000'),
901 'Starting: Intent { act=android.intent.action.VIEW }'): 821 'Starting: Intent { act=android.intent.action.VIEW }'):
902 self.device.StartActivity(test_intent) 822 self.device.StartActivity(test_intent)
903 823
904 824
905 class DeviceUtilsStartInstrumentationTest(DeviceUtilsNewImplTest): 825 class DeviceUtilsStartInstrumentationTest(DeviceUtilsNewImplTest):
906 826
907 def testStartInstrumentation_nothing(self): 827 def testStartInstrumentation_nothing(self):
908 with self.assertCalls( 828 with self.assertCalls(
909 self.call.device.RunShellCommand( 829 self.call.device.RunShellCommand(
910 ['am', 'instrument', 'test.package/.TestInstrumentation'], 830 ['am', 'instrument', 'test.package/.TestInstrumentation'],
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 with self.assertCall( 871 with self.assertCall(
952 self.call.adb.Shell('am broadcast -a test.package.with.an.INTENT'), 872 self.call.adb.Shell('am broadcast -a test.package.with.an.INTENT'),
953 'Broadcasting: Intent { act=test.package.with.an.INTENT } '): 873 'Broadcasting: Intent { act=test.package.with.an.INTENT } '):
954 self.device.BroadcastIntent(test_intent) 874 self.device.BroadcastIntent(test_intent)
955 875
956 def testBroadcastIntent_withExtra(self): 876 def testBroadcastIntent_withExtra(self):
957 test_intent = intent.Intent(action='test.package.with.an.INTENT', 877 test_intent = intent.Intent(action='test.package.with.an.INTENT',
958 extras={'foo': 'bar value'}) 878 extras={'foo': 'bar value'})
959 with self.assertCall( 879 with self.assertCall(
960 self.call.adb.Shell( 880 self.call.adb.Shell(
961 "am broadcast -a test.package.with.an.INTENT -e foo 'bar value'"), 881 "am broadcast -a test.package.with.an.INTENT --es foo 'bar value'"),
962 'Broadcasting: Intent { act=test.package.with.an.INTENT } '): 882 'Broadcasting: Intent { act=test.package.with.an.INTENT } '):
963 self.device.BroadcastIntent(test_intent) 883 self.device.BroadcastIntent(test_intent)
964 884
965 def testBroadcastIntent_withExtra_noValue(self): 885 def testBroadcastIntent_withExtra_noValue(self):
966 test_intent = intent.Intent(action='test.package.with.an.INTENT', 886 test_intent = intent.Intent(action='test.package.with.an.INTENT',
967 extras={'foo': None}) 887 extras={'foo': None})
968 with self.assertCall( 888 with self.assertCall(
969 self.call.adb.Shell( 889 self.call.adb.Shell(
970 'am broadcast -a test.package.with.an.INTENT -e foo'), 890 'am broadcast -a test.package.with.an.INTENT --esn foo'),
971 'Broadcasting: Intent { act=test.package.with.an.INTENT } '): 891 'Broadcasting: Intent { act=test.package.with.an.INTENT } '):
972 self.device.BroadcastIntent(test_intent) 892 self.device.BroadcastIntent(test_intent)
973 893
974 894
975 class DeviceUtilsGoHomeTest(DeviceUtilsOldImplTest): 895 class DeviceUtilsGoHomeTest(DeviceUtilsOldImplTest):
976 896
977 def testGoHome(self): 897 def testGoHome(self):
978 with self.assertCalls( 898 with self.assertCalls(
979 "adb -s 0123456789abcdef shell 'am start " 899 "adb -s 0123456789abcdef shell 'am start "
980 "-W " 900 "-W "
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
1438 def testGetPids_exactMatch(self): 1358 def testGetPids_exactMatch(self):
1439 with self.assertCall(self.call.adb.Shell('ps'), 1359 with self.assertCall(self.call.adb.Shell('ps'),
1440 'USER PID PPID VSIZE RSS WCHAN PC NAME\n' 1360 'USER PID PPID VSIZE RSS WCHAN PC NAME\n'
1441 'user 1000 100 1024 1024 ffffffff 00000000 not.exact.match\n' 1361 'user 1000 100 1024 1024 ffffffff 00000000 not.exact.match\n'
1442 'user 1234 100 1024 1024 ffffffff 00000000 exact.match\n'): 1362 'user 1234 100 1024 1024 ffffffff 00000000 exact.match\n'):
1443 self.assertEqual( 1363 self.assertEqual(
1444 {'not.exact.match': '1000', 'exact.match': '1234'}, 1364 {'not.exact.match': '1000', 'exact.match': '1234'},
1445 self.device.GetPids('exact.match')) 1365 self.device.GetPids('exact.match'))
1446 1366
1447 1367
1448 class DeviceUtilsTakeScreenshotTest(DeviceUtilsOldImplTest): 1368 class DeviceUtilsTakeScreenshotTest(DeviceUtilsNewImplTest):
1449 1369
1450 def testTakeScreenshot_fileNameProvided(self): 1370 def testTakeScreenshot_fileNameProvided(self):
1451 mock_fs = MockFileSystem() 1371 with self.assertCalls(
1452 mock_fs.addMockDirectory('/test/host') 1372 (mock.call.pylib.utils.device_temp_file.DeviceTempFile(
1453 mock_fs.addMockFile('/test/host/screenshot.png') 1373 self.adb, suffix='.png'),
1454 1374 MockTempFile('/tmp/path/temp-123.png')),
1455 with mock_fs: 1375 (self.call.adb.Shell('/system/bin/screencap -p /tmp/path/temp-123.png'),
1456 with self.assertCallsSequence( 1376 ''),
1457 cmd_ret=[ 1377 self.call.device.PullFile('/tmp/path/temp-123.png',
1458 (r"adb -s 0123456789abcdef shell 'echo \$EXTERNAL_STORAGE'", 1378 '/test/host/screenshot.png')):
1459 '/test/external/storage\r\n'), 1379 self.device.TakeScreenshot('/test/host/screenshot.png')
1460 (r"adb -s 0123456789abcdef shell '/system/bin/screencap -p \S+'",
1461 ''),
1462 (r"adb -s 0123456789abcdef shell ls \S+",
1463 '/test/external/storage/screenshot.png\r\n'),
1464 (r'adb -s 0123456789abcdef pull \S+ /test/host/screenshot.png',
1465 '100 B/s (100 B in 1.000s)\r\n'),
1466 (r"adb -s 0123456789abcdef shell 'rm -f \S+'", '')
1467 ],
1468 comp=re.match):
1469 self.device.TakeScreenshot('/test/host/screenshot.png')
1470 1380
1471 1381
1472 class DeviceUtilsGetIOStatsTest(DeviceUtilsOldImplTest): 1382 class DeviceUtilsGetIOStatsTest(DeviceUtilsOldImplTest):
1473 1383
1474 def testGetIOStats(self): 1384 def testGetIOStats(self):
1475 with self.assertCalls( 1385 with self.assertCalls(
1476 "adb -s 0123456789abcdef shell 'cat \"/proc/diskstats\" 2>/dev/null'", 1386 "adb -s 0123456789abcdef shell 'cat \"/proc/diskstats\" 2>/dev/null'",
1477 '179 0 mmcblk0 1 2 3 4 5 6 7 8 9 10 11\r\n'): 1387 '179 0 mmcblk0 1 2 3 4 5 6 7 8 9 10 11\r\n'):
1478 self.assertEqual( 1388 self.assertEqual(
1479 { 1389 {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1541 self.assertTrue( 1451 self.assertTrue(
1542 isinstance(device, device_utils.DeviceUtils) 1452 isinstance(device, device_utils.DeviceUtils)
1543 and serial == str(device), 1453 and serial == str(device),
1544 'Expected a DeviceUtils object with serial %s' % serial) 1454 'Expected a DeviceUtils object with serial %s' % serial)
1545 1455
1546 1456
1547 if __name__ == '__main__': 1457 if __name__ == '__main__':
1548 logging.getLogger().setLevel(logging.DEBUG) 1458 logging.getLogger().setLevel(logging.DEBUG)
1549 unittest.main(verbosity=2) 1459 unittest.main(verbosity=2)
1550 1460
OLDNEW
« no previous file with comments | « build/android/pylib/device/device_utils.py ('k') | build/android/pylib/device/intent.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698