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.

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

mercurial