michael@0: from sut import MockAgent michael@0: import mozdevice michael@0: import unittest michael@0: michael@0: class PsTest(unittest.TestCase): michael@0: michael@0: pscommands = [('ps', michael@0: "10029 549 com.android.launcher\n" michael@0: "10066 1198 com.twitter.android")] michael@0: michael@0: bad_pscommands = [('ps', michael@0: "abcdef 549 com.android.launcher\n" michael@0: "10066 1198 com.twitter.android")] michael@0: michael@0: def test_processList(self): michael@0: a = MockAgent(self, michael@0: commands=self.pscommands) michael@0: d = mozdevice.DroidSUT("127.0.0.1", port=a.port) michael@0: pslist = d.getProcessList() michael@0: self.assertEqual(len(pslist), 2) michael@0: self.assertEqual(pslist[0], [549, 'com.android.launcher', 10029]) michael@0: self.assertEqual(pslist[1], [1198, 'com.twitter.android', 10066]) michael@0: michael@0: a.wait() michael@0: michael@0: def test_badProcessList(self): michael@0: a = MockAgent(self, michael@0: commands=self.bad_pscommands) michael@0: d = mozdevice.DroidSUT("127.0.0.1", port=a.port) michael@0: exceptionTriggered = False michael@0: try: michael@0: d.getProcessList() michael@0: except mozdevice.DMError: michael@0: exceptionTriggered = True michael@0: michael@0: self.assertTrue(exceptionTriggered) michael@0: michael@0: a.wait() michael@0: michael@0: def test_processExist(self): michael@0: for i in [('com.android.launcher', 549), michael@0: ('com.fennec.android', None)]: michael@0: a = MockAgent(self, commands=self.pscommands) michael@0: d = mozdevice.DroidSUT("127.0.0.1", port=a.port) michael@0: self.assertEqual(d.processExist(i[0]), i[1]) michael@0: a.wait() michael@0: michael@0: if __name__ == '__main__': michael@0: unittest.main()