def test_processExist(self): for i in [('com.android.launcher', 549), ('com.fennec.android', None)]: a = MockAgent(self, commands=self.pscommands) d = mozdevice.DroidSUT("127.0.0.1", port=a.port) self.assertEqual(d.processExist(i[0]), i[1]) a.wait()
def test_init(self): """Tests DeviceManager initialization.""" a = MockAgent(self) d = mozdevice.DroidSUT("127.0.0.1", port=a.port, logLevel=mozlog.DEBUG) # all testing done in device's constructor a.wait()
def test_mkdirs(self): subTests = [ { 'cmds': [ ("isdir /mnt/sdcard/baz/boop", "FALSE"), ("isdir /mnt", "TRUE"), ("isdir /mnt/sdcard", "TRUE"), ("isdir /mnt/sdcard/baz", "FALSE"), ("mkdr /mnt/sdcard/baz", "/mnt/sdcard/baz successfully created"), ("isdir /mnt/sdcard/baz/boop", "FALSE"), ("mkdr /mnt/sdcard/baz/boop", "/mnt/sdcard/baz/boop successfully created") ], 'expectException': False }, { 'cmds': [ ("isdir /mnt/sdcard/baz/boop", "FALSE"), ("isdir /mnt", "TRUE"), ("isdir /mnt/sdcard", "TRUE"), ("isdir /mnt/sdcard/baz", "FALSE"), ("mkdr /mnt/sdcard/baz", "##AGENT-WARNING## Could not create the directory /mnt/sdcard/baz") ], 'expectException': True }, ] for subTest in subTests: a = MockAgent(self, commands = subTest['cmds']) exceptionThrown = False try: mozdevice.DroidSUT.debug = 4 d = mozdevice.DroidSUT("127.0.0.1", port=a.port) d.mkDirs("/mnt/sdcard/baz/boop/bip") except mozdevice.DMError, e: exceptionThrown = True self.assertEqual(exceptionThrown, subTest['expectException']) a.wait()
def test_mkdirs(self): subTests = [{'cmds': [('isdir /mnt/sdcard/baz/boop', 'FALSE'), ('isdir /mnt', 'TRUE'), ('isdir /mnt/sdcard', 'TRUE'), ('isdir /mnt/sdcard/baz', 'FALSE'), ('mkdr /mnt/sdcard/baz', '/mnt/sdcard/baz successfully created'), ('isdir /mnt/sdcard/baz/boop', 'FALSE'), ('mkdr /mnt/sdcard/baz/boop', '/mnt/sdcard/baz/boop successfully created')], 'expectException': False}, {'cmds': [('isdir /mnt/sdcard/baz/boop', 'FALSE'), ('isdir /mnt', 'TRUE'), ('isdir /mnt/sdcard', 'TRUE'), ('isdir /mnt/sdcard/baz', 'FALSE'), ('mkdr /mnt/sdcard/baz', '##AGENT-WARNING## Could not create the directory /mnt/sdcard/baz')], 'expectException': True}, ] for subTest in subTests: a = MockAgent(self, commands=subTest['cmds']) exceptionThrown = False try: d = mozdevice.DroidSUT('127.0.0.1', port=a.port, logLevel=mozlog.DEBUG) d.mkDirs('/mnt/sdcard/baz/boop/bip') except mozdevice.DMError: exceptionThrown = True self.assertEqual(exceptionThrown, subTest['expectException']) a.wait()
def test_mkdirs(self): subTests = [{'cmds': [('isdir /mnt/sdcard/baz/boop', 'FALSE'), ('info os', 'android'), ('isdir /mnt', 'TRUE'), ('isdir /mnt/sdcard', 'TRUE'), ('isdir /mnt/sdcard/baz', 'FALSE'), ('mkdr /mnt/sdcard/baz', '/mnt/sdcard/baz successfully created'), ('isdir /mnt/sdcard/baz/boop', 'FALSE'), ('mkdr /mnt/sdcard/baz/boop', '/mnt/sdcard/baz/boop successfully created')], 'expectException': False}, {'cmds': [('isdir /mnt/sdcard/baz/boop', 'FALSE'), ('info os', 'android'), ('isdir /mnt', 'TRUE'), ('isdir /mnt/sdcard', 'TRUE'), ('isdir /mnt/sdcard/baz', 'FALSE'), ('mkdr /mnt/sdcard/baz', "##AGENT-WARNING## " "Could not create the directory /mnt/sdcard/baz")], 'expectException': True}, ] for subTest in subTests: a = MockAgent(self, commands=subTest['cmds']) exceptionThrown = False try: d = mozdevice.DroidSUT('127.0.0.1', port=a.port, logLevel=logging.DEBUG) d.mkDirs('/mnt/sdcard/baz/boop/bip') except mozdevice.DMError: exceptionThrown = True self.assertEqual(exceptionThrown, subTest['expectException']) a.wait()
def test_init_err(self): """Tests error handling during initialization.""" a = MockAgent(self, start_commands=[("ver", "##AGENT-WARNING## No version")]) self.assertRaises( mozdevice.DMError, lambda: mozdevice.DroidSUT("127.0.0.1", port=a.port, logLevel=logging.DEBUG) ) a.wait()
def test_push_dir(self): pushfile = "1234ABCD" mdsum = hashlib.md5() mdsum.update(pushfile) expectedFileResponse = mdsum.hexdigest() tempdir = tempfile.mkdtemp() complex_path = os.path.join(tempdir, "baz") os.mkdir(complex_path) f = tempfile.NamedTemporaryFile(dir=complex_path) f.write(pushfile) f.flush() subTests = [ { 'cmds': [("isdir /mnt", "TRUE"), ("isdir /mnt/sdcard", "TRUE"), ("isdir /mnt/sdcard/baz", "TRUE"), ("isdir /mnt", "TRUE"), ("isdir /mnt/sdcard", "TRUE"), ("isdir /mnt/sdcard/baz", "TRUE"), ("push /mnt/sdcard//baz/%s %s" % (os.path.basename(f.name), len(pushfile)), expectedFileResponse)], 'expectException': False }, { 'cmds': [("isdir /mnt", "TRUE"), ("isdir /mnt/sdcard", "TRUE"), ("isdir /mnt/sdcard/baz", "TRUE"), ("isdir /mnt", "TRUE"), ("isdir /mnt/sdcard", "TRUE"), ("isdir /mnt/sdcard/baz", "TRUE"), ("push /mnt/sdcard//baz/%s %s" % (os.path.basename(f.name), len(pushfile)), "BADHASH")], 'expectException': True }, { 'cmds': [("isdir /mnt", "FALSE"), ("mkdr /mnt", "##AGENT-WARNING## Could not create the directory /mnt")], 'expectException': True }, ] for subTest in subTests: a = MockAgent(self, commands=subTest['cmds']) exceptionThrown = False try: mozdevice.DroidSUT.debug = 4 d = mozdevice.DroidSUT("127.0.0.1", port=a.port) d.pushDir(tempdir, "/mnt/sdcard") except mozdevice.DMError, e: exceptionThrown = True self.assertEqual(exceptionThrown, subTest['expectException']) a.wait()
def test_init_err(self): """Tests error handling during initialization.""" a = MockAgent(self, start_commands=[("ver", "##AGENT-WARNING## No version")]) self.assertRaises( mozdevice.DMError, lambda: mozdevice.DroidSUT( "127.0.0.1", port=a.port, logLevel=logging.DEBUG)) a.wait()
def test_mkdirs_on_root(self): cmds = [('isdir /', 'TRUE')] a = MockAgent(self, commands=cmds) d = mozdevice.DroidSUT('127.0.0.1', port=a.port, logLevel=mozlog.DEBUG) d.mkDirs('/foo') a.wait()
def test_init(self): """Tests DeviceManager initialization.""" a = MockAgent(self) mozdevice.DroidSUT.debug = 4 d = mozdevice.DroidSUT("127.0.0.1", port=a.port) # all testing done in device's constructor a.wait()
def test_mkdirs_on_root(self): cmds = [('isdir /', 'TRUE')] a = MockAgent(self, commands=cmds) d = mozdevice.DroidSUT('127.0.0.1', port=a.port, logLevel=logging.DEBUG) d.mkDirs('/foo') a.wait()
def test_processList(self): a = MockAgent(self, commands=self.pscommands) d = mozdevice.DroidSUT("127.0.0.1", port=a.port) pslist = d.getProcessList() self.assertEqual(len(pslist), 2) self.assertEqual(pslist[0], [549, 'com.android.launcher', 10029]) self.assertEqual(pslist[1], [1198, 'com.twitter.android', 10066]) a.wait()
def test_push_dir(self): pushfile = "1234ABCD" mdsum = hashlib.md5() mdsum.update(pushfile) expectedFileResponse = mdsum.hexdigest() tempdir = tempfile.mkdtemp() complex_path = os.path.join(tempdir, "baz") os.mkdir(complex_path) f = tempfile.NamedTemporaryFile(dir=complex_path) f.write(pushfile) f.flush() subTests = [ { "cmds": [ ("isdir /mnt/sdcard/baz", "TRUE"), ( "push /mnt/sdcard/baz/%s %s\r\n%s" % (os.path.basename(f.name), len(pushfile), pushfile), expectedFileResponse, ), ], "expectException": False, }, { "cmds": [ ("isdir /mnt/sdcard/baz", "TRUE"), ( "push /mnt/sdcard/baz/%s %s\r\n%s" % (os.path.basename(f.name), len(pushfile), pushfile), "BADHASH", ), ], "expectException": True, }, { "cmds": [ ("isdir /mnt/sdcard/baz", "FALSE"), ("isdir /mnt", "FALSE"), ("mkdr /mnt", "##AGENT-WARNING## Could not create the directory /mnt"), ], "expectException": True, }, ] for subTest in subTests: a = MockAgent(self, commands=subTest["cmds"]) exceptionThrown = False try: d = mozdevice.DroidSUT("127.0.0.1", port=a.port, logLevel=mozlog.DEBUG) d.pushDir(tempdir, "/mnt/sdcard") except mozdevice.DMError, e: exceptionThrown = True self.assertEqual(exceptionThrown, subTest["expectException"]) a.wait()
def test_init_err(self): """Tests error handling during initialization.""" cmds = [("testroot", "/mnt/sdcard"), ("isdir /mnt/sdcard/tests", "/mnt/sdcard/tests: No such file or directory\n"), ("isdir /mnt/sdcard/tests", "/mnt/sdcard/tests: No such file or directory\n"), ("mkdr /mnt/sdcard/tests", "/mnt/sdcard/tests successfully created"), ("ver", "SUTAgentAndroid Version 1.14")] a = MockAgent(self, start_commands = cmds) dm = mozdevice.DroidSUT("127.0.0.1", port=a.port, logLevel=mozlog.DEBUG) a.wait()
def test_timeout_normal(self): """Tests DeviceManager timeout, normal case.""" a = MockAgent(self, commands = [("isdir /mnt/sdcard/tests", "TRUE"), ("cd /mnt/sdcard/tests", ""), ("ls", "test.txt"), ("rm /mnt/sdcard/tests/test.txt", "Removed the file")]) d = mozdevice.DroidSUT("127.0.0.1", port=a.port, logLevel=mozlog.DEBUG) ret = d.removeFile('/mnt/sdcard/tests/test.txt') self.assertEqual(ret, None) # if we didn't throw an exception, we're ok a.wait()
def test_nouserserial(self): a = MockAgent(self, commands=[("ps", "10029 549 com.android.launcher\n" "10066 1198 com.twitter.android"), ("info sutuserinfo", ""), ("exec am start -W -n " "org.mozilla.fennec/.App -a " "android.intent.action.VIEW", "OK\nreturn code [0]")]) d = mozdevice.DroidSUT("127.0.0.1", port=a.port, logLevel=mozlog.DEBUG) d.launchFennec("org.mozilla.fennec") a.wait()
def test_nouserserial(self): a = MockAgent(self, commands = [("ps", "10029 549 com.android.launcher\n" "10066 1198 com.twitter.android"), ("info sutuserinfo", ""), ("exec am start -W -n " "org.mozilla.fennec/.App -a " "android.intent.action.VIEW", "OK\nreturn code [0]")]) d = mozdevice.DroidSUT("127.0.0.1", port=a.port, logLevel=mozlog.DEBUG) d.launchFennec("org.mozilla.fennec") a.wait()
def test_badProcessList(self): a = MockAgent(self, commands=self.bad_pscommands) d = mozdevice.DroidSUT("127.0.0.1", port=a.port) exceptionTriggered = False try: d.getProcessList() except mozdevice.DMError: exceptionTriggered = True self.assertTrue(exceptionTriggered) a.wait()
def test_timeout_timeout(self): """Tests DeviceManager timeout, timeout case.""" a = MockAgent(self, commands = [("isdir /mnt/sdcard/tests", "TRUE"), ("cd /mnt/sdcard/tests", ""), ("ls", "test.txt"), ("rm /mnt/sdcard/tests/test.txt", 0)]) d = mozdevice.DroidSUT("127.0.0.1", port=a.port, logLevel=mozlog.DEBUG) d.default_timeout = 1 exceptionThrown = False try: d.removeFile('/mnt/sdcard/tests/test.txt') except mozdevice.DMError: exceptionThrown = True self.assertEqual(exceptionThrown, True) a.wait()
def test_shell(self): """Tests shell command""" for cmd in [("exec foobar", False), ("execsu foobar", True)]: for retcode in [1, 2]: a = MockAgent(self, commands=[(cmd[0], "\nreturn code [%s]" % retcode)]) d = mozdevice.DroidSUT("127.0.0.1", port=a.port) exceptionThrown = False try: d.shellCheckOutput(["foobar"], root=cmd[1]) except mozdevice.DMError: exceptionThrown = True expectedException = retcode != 0 self.assertEqual(exceptionThrown, expectedException) a.wait()
def test_repeated_path_part(self): """ Ensure that all dirs are created when last path part also found earlier in the path (bug 826492). """ cmds = [('isdir /mnt/sdcard/foo', 'FALSE'), ('isdir /mnt', 'TRUE'), ('isdir /mnt/sdcard', 'TRUE'), ('isdir /mnt/sdcard/foo', 'FALSE'), ('mkdr /mnt/sdcard/foo', '/mnt/sdcard/foo successfully created')] a = MockAgent(self, commands=cmds) d = mozdevice.DroidSUT('127.0.0.1', port=a.port, logLevel=mozlog.DEBUG) d.mkDirs('/mnt/sdcard/foo/foo') a.wait()
def test_shell(self): """Tests shell command""" for cmd in [ ("exec foobar", False), ("execsu foobar", True) ]: for retcode in [ 1, 2 ]: a = MockAgent(self, commands=[(cmd[0], "\nreturn code [%s]" % retcode)]) d = mozdevice.DroidSUT("127.0.0.1", port=a.port) exceptionThrown = False try: d.shellCheckOutput(["foobar"], root=cmd[1]) except mozdevice.DMError: exceptionThrown = True expectedException = (retcode != 0) self.assertEqual(exceptionThrown, expectedException) a.wait()
def test_repeated_path_part(self): """ Ensure that all dirs are created when last path part also found earlier in the path (bug 826492). """ cmds = [ ("isdir /mnt/sdcard/foo", "FALSE"), ("isdir /mnt", "TRUE"), ("isdir /mnt/sdcard", "TRUE"), ("isdir /mnt/sdcard/foo", "FALSE"), ("mkdr /mnt/sdcard/foo", "/mnt/sdcard/foo successfully created"), ] a = MockAgent(self, commands=cmds) mozdevice.DroidSUT.debug = 4 d = mozdevice.DroidSUT("127.0.0.1", port=a.port) d.mkDirs("/mnt/sdcard/foo/foo") a.wait()
def test_push(self): pushfile = "1234ABCD" mdsum = hashlib.md5() mdsum.update(pushfile) expectedResponse = mdsum.hexdigest() # (good response, no exception), (bad response, exception) for response in [(expectedResponse, False), ("BADHASH", True)]: cmd = "push /mnt/sdcard/foobar %s\r\n%s" % (len(pushfile), pushfile) a = MockAgent(self, commands=[("isdir /mnt/sdcard", "TRUE"), (cmd, response[0])]) exceptionThrown = False with tempfile.NamedTemporaryFile() as f: try: f.write(pushfile) f.flush() d = mozdevice.DroidSUT("127.0.0.1", port=a.port) d.pushFile(f.name, "/mnt/sdcard/foobar") except mozdevice.DMError, e: exceptionThrown = True self.assertEqual(exceptionThrown, response[1]) a.wait()
def test_mkdirs(self): subTests = [ { 'cmds': [("isdir /mnt/sdcard/baz/boop", "FALSE"), ("isdir /mnt", "TRUE"), ("isdir /mnt/sdcard", "TRUE"), ("isdir /mnt/sdcard/baz", "FALSE"), ("mkdr /mnt/sdcard/baz", "/mnt/sdcard/baz successfully created"), ("isdir /mnt/sdcard/baz/boop", "FALSE"), ("mkdr /mnt/sdcard/baz/boop", "/mnt/sdcard/baz/boop successfully created")], 'expectException': False }, { 'cmds': [("isdir /mnt/sdcard/baz/boop", "FALSE"), ("isdir /mnt", "TRUE"), ("isdir /mnt/sdcard", "TRUE"), ("isdir /mnt/sdcard/baz", "FALSE"), ("mkdr /mnt/sdcard/baz", "##AGENT-WARNING## Could not create the directory /mnt/sdcard/baz" )], 'expectException': True }, ] for subTest in subTests: a = MockAgent(self, commands=subTest['cmds']) exceptionThrown = False try: mozdevice.DroidSUT.debug = 4 d = mozdevice.DroidSUT("127.0.0.1", port=a.port) d.mkDirs("/mnt/sdcard/baz/boop/bip") except mozdevice.DMError, e: exceptionThrown = True self.assertEqual(exceptionThrown, subTest['expectException']) a.wait()
def test_push(self): pushfile = "1234ABCD" mdsum = hashlib.md5() mdsum.update(pushfile) expectedResponse = mdsum.hexdigest() # (good response, no exception), (bad response, exception) for response in [ (expectedResponse, False), ("BADHASH", True) ]: cmd = "push /mnt/sdcard/foobar %s" % len(pushfile) a = MockAgent(self, commands = [("isdir /mnt/sdcard", "TRUE"), (cmd, response[0])]) exceptionThrown = False with tempfile.NamedTemporaryFile() as f: try: f.write(pushfile) f.flush() d = mozdevice.DroidSUT("127.0.0.1", port=a.port) d.pushFile(f.name, '/mnt/sdcard/foobar') except mozdevice.DMError, e: exceptionThrown = True self.assertEqual(exceptionThrown, response[1]) a.wait()