testing/mozbase/mozdevice/tests/sut_pull.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 import hashlib
michael@0 6 import tempfile
michael@0 7 import os
michael@0 8
michael@0 9 class PullTest(unittest.TestCase):
michael@0 10
michael@0 11 def test_pull_success(self):
michael@0 12 for count in [ 1, 4, 1024, 2048 ]:
michael@0 13 cheeseburgers = ""
michael@0 14 for i in range(count):
michael@0 15 cheeseburgers += "cheeseburgers"
michael@0 16
michael@0 17 # pull file is kind of gross, make sure we can still execute commands after it's done
michael@0 18 remoteName = "/mnt/sdcard/cheeseburgers"
michael@0 19 a = MockAgent(self, commands = [("pull %s" % remoteName,
michael@0 20 "%s,%s\n%s" % (remoteName,
michael@0 21 len(cheeseburgers),
michael@0 22 cheeseburgers)),
michael@0 23 ("isdir /mnt/sdcard", "TRUE")])
michael@0 24
michael@0 25 d = mozdevice.DroidSUT("127.0.0.1", port=a.port,
michael@0 26 logLevel=mozlog.DEBUG)
michael@0 27 pulledData = d.pullFile("/mnt/sdcard/cheeseburgers")
michael@0 28 self.assertEqual(pulledData, cheeseburgers)
michael@0 29 d.dirExists('/mnt/sdcard')
michael@0 30
michael@0 31 def test_pull_failure(self):
michael@0 32
michael@0 33 # this test simulates only receiving a few bytes of what we expect
michael@0 34 # to be larger file
michael@0 35 remoteName = "/mnt/sdcard/cheeseburgers"
michael@0 36 a = MockAgent(self, commands = [("pull %s" % remoteName,
michael@0 37 "%s,15\n%s" % (remoteName,
michael@0 38 "cheeseburgh"))])
michael@0 39 d = mozdevice.DroidSUT("127.0.0.1", port=a.port,
michael@0 40 logLevel=mozlog.DEBUG)
michael@0 41 exceptionThrown = False
michael@0 42 try:
michael@0 43 d.pullFile("/mnt/sdcard/cheeseburgers")
michael@0 44 except mozdevice.DMError:
michael@0 45 exceptionThrown = True
michael@0 46 self.assertTrue(exceptionThrown)
michael@0 47
michael@0 48 if __name__ == '__main__':
michael@0 49 unittest.main()
michael@0 50
michael@0 51

mercurial