testing/mozbase/mozdevice/tests/sut_basic.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 from sut import MockAgent
michael@0 2 import mozdevice
michael@0 3 import mozlog
michael@0 4 import unittest
michael@0 5
michael@0 6 class BasicTest(unittest.TestCase):
michael@0 7
michael@0 8 def test_init(self):
michael@0 9 """Tests DeviceManager initialization."""
michael@0 10 a = MockAgent(self)
michael@0 11
michael@0 12 d = mozdevice.DroidSUT("127.0.0.1", port=a.port, logLevel=mozlog.DEBUG)
michael@0 13 # all testing done in device's constructor
michael@0 14 a.wait()
michael@0 15
michael@0 16 def test_init_err(self):
michael@0 17 """Tests error handling during initialization."""
michael@0 18 cmds = [("testroot", "/mnt/sdcard"),
michael@0 19 ("isdir /mnt/sdcard/tests", "/mnt/sdcard/tests: No such file or directory\n"),
michael@0 20 ("isdir /mnt/sdcard/tests", "/mnt/sdcard/tests: No such file or directory\n"),
michael@0 21 ("mkdr /mnt/sdcard/tests", "/mnt/sdcard/tests successfully created"),
michael@0 22 ("ver", "SUTAgentAndroid Version 1.14")]
michael@0 23 a = MockAgent(self, start_commands = cmds)
michael@0 24 dm = mozdevice.DroidSUT("127.0.0.1", port=a.port, logLevel=mozlog.DEBUG)
michael@0 25 a.wait()
michael@0 26
michael@0 27 def test_timeout_normal(self):
michael@0 28 """Tests DeviceManager timeout, normal case."""
michael@0 29 a = MockAgent(self, commands = [("isdir /mnt/sdcard/tests", "TRUE"),
michael@0 30 ("cd /mnt/sdcard/tests", ""),
michael@0 31 ("ls", "test.txt"),
michael@0 32 ("rm /mnt/sdcard/tests/test.txt",
michael@0 33 "Removed the file")])
michael@0 34 d = mozdevice.DroidSUT("127.0.0.1", port=a.port, logLevel=mozlog.DEBUG)
michael@0 35 ret = d.removeFile('/mnt/sdcard/tests/test.txt')
michael@0 36 self.assertEqual(ret, None) # if we didn't throw an exception, we're ok
michael@0 37 a.wait()
michael@0 38
michael@0 39 def test_timeout_timeout(self):
michael@0 40 """Tests DeviceManager timeout, timeout case."""
michael@0 41 a = MockAgent(self, commands = [("isdir /mnt/sdcard/tests", "TRUE"),
michael@0 42 ("cd /mnt/sdcard/tests", ""),
michael@0 43 ("ls", "test.txt"),
michael@0 44 ("rm /mnt/sdcard/tests/test.txt", 0)])
michael@0 45 d = mozdevice.DroidSUT("127.0.0.1", port=a.port, logLevel=mozlog.DEBUG)
michael@0 46 d.default_timeout = 1
michael@0 47 exceptionThrown = False
michael@0 48 try:
michael@0 49 d.removeFile('/mnt/sdcard/tests/test.txt')
michael@0 50 except mozdevice.DMError:
michael@0 51 exceptionThrown = True
michael@0 52 self.assertEqual(exceptionThrown, True)
michael@0 53 a.should_stop = True
michael@0 54 a.wait()
michael@0 55
michael@0 56 def test_shell(self):
michael@0 57 """Tests shell command"""
michael@0 58 for cmd in [ ("exec foobar", False), ("execsu foobar", True) ]:
michael@0 59 for retcode in [ 1, 2 ]:
michael@0 60 a = MockAgent(self, commands=[(cmd[0],
michael@0 61 "\nreturn code [%s]" % retcode)])
michael@0 62 d = mozdevice.DroidSUT("127.0.0.1", port=a.port)
michael@0 63 exceptionThrown = False
michael@0 64 try:
michael@0 65 d.shellCheckOutput(["foobar"], root=cmd[1])
michael@0 66 except mozdevice.DMError:
michael@0 67 exceptionThrown = True
michael@0 68 expectedException = (retcode != 0)
michael@0 69 self.assertEqual(exceptionThrown, expectedException)
michael@0 70
michael@0 71 a.wait()
michael@0 72
michael@0 73 if __name__ == '__main__':
michael@0 74 unittest.main()

mercurial