summaryrefslogtreecommitdiffstats
path: root/testing/mozbase/mozdevice/tests/sut_mkdir.py
blob: bacaae3243b09542e1f1d25871ecaf0bf4facc35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/

import mozdevice
import logging
import unittest
from sut import MockAgent


class MkDirsTest(unittest.TestCase):

    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_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'),
                ('info os', 'android'),
                ('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=logging.DEBUG)
        d.mkDirs('/mnt/sdcard/foo/foo')
        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()


if __name__ == '__main__':
    unittest.main()