Bug 1239964 - [mozdevice] Expose screen recorder capabilites draft
authorJohan Lorenzo <jlorenzo@mozilla.com>
Fri, 15 Jan 2016 17:08:06 +0100
changeset 322014 be4cf500b3d652fc0be679161eb8e70a49cedbb5
parent 322013 54c17e1ad2dae3ffaa7e7055b4d5afde8b4a196e
child 513015 ec319195eae4ff80785ecf01d059757832437f44
push id9510
push userjlorenzo@mozilla.com
push dateFri, 15 Jan 2016 16:08:21 +0000
bugs1239964
milestone46.0a1
Bug 1239964 - [mozdevice] Expose screen recorder capabilites
testing/mozbase/mozdevice/adb_tests/test_devicemanagerADB.py
testing/mozbase/mozdevice/mozdevice/devicemanagerADB.py
--- a/testing/mozbase/mozdevice/adb_tests/test_devicemanagerADB.py
+++ b/testing/mozbase/mozdevice/adb_tests/test_devicemanagerADB.py
@@ -161,16 +161,28 @@ class TestFileOperations(DeviceManagerAD
         self.dm.pushFile(self.tempLocalFile, self.tempRemoteSystemFile)
         self.assertTrue(self.dm.fileExists(self.tempRemoteSystemFile))
         self.dm.removeFile(self.tempRemoteSystemFile)
         self.assertFalse(self.dm.fileExists(self.tempRemoteSystemFile))
         self.dm.shell(['mount', '-r', '-o', 'remount', '/system'], out)
         out.close()
         self.assertTrue(find_mount_permissions(self.dm, "/system") == "ro")
 
+    def test_record_and_video(self):
+        video_remote_location = '/sdcard/screenrecord.mp4'
+        video_local_location = os.path.join("tempDir", "tempvideo.mp4")
+
+        self.dm.startScreenRecord(remoteLocation=video_remote_location)
+        self.dm.stopScreenRecord()
+
+        self.dm.getFile(remoteFile=video_remote_location, localFile=video_local_location)
+        video_file_size = os.path.getsize(video_remote_location)
+
+        self.assertGreater(video_file_size, 0)
+
 
 class TestOther(DeviceManagerADBTestCase):
     def test_get_list_of_processes(self):
         self.assertEquals(type(self.dm.getProcessList()), list)
 
     def test_get_current_time(self):
         self.assertEquals(type(self.dm.getCurrentTime()), int)
 
--- a/testing/mozbase/mozdevice/mozdevice/devicemanagerADB.py
+++ b/testing/mozbase/mozdevice/mozdevice/devicemanagerADB.py
@@ -4,16 +4,17 @@
 
 import logging
 import re
 import os
 import shutil
 import tempfile
 import time
 import traceback
+import signal
 
 from devicemanager import DeviceManager, DMError
 from mozprocess import ProcessHandler
 import mozfile
 
 
 class DeviceManagerADB(DeviceManager):
     """
@@ -643,16 +644,25 @@ class DeviceManagerADB(DeviceManager):
                     self._checkCmd(["shell", "chmod", mask, remoteEntry], timeout=self.short_timeout)
                     self._logger.info("chmod %s" % remoteEntry)
             self._checkCmd(["shell", "chmod", mask, remoteDir], timeout=self.short_timeout)
             self._logger.debug("chmod %s" % remoteDir)
         else:
             self._checkCmd(["shell", "chmod", mask, remoteDir.strip()], timeout=self.short_timeout)
             self._logger.debug("chmod %s" % remoteDir.strip())
 
+    def startScreenRecord(self, remoteLocation='/sdcard/screenrecord.mp4'):
+        self.shell(cmd='screenrecord %s' % remoteLocation,
+                   outputfile='/dev/null')
+
+    def stopScreenRecord(self):
+        self.killProcess(appname='screenrecord',
+                         sig=signal.SIGINT  # video file gets corrupted if using another signal
+                         )
+
     def _verifyADB(self):
         """
         Check to see if adb itself can be executed.
         """
         if self._adbPath != 'adb':
             if not os.access(self._adbPath, os.X_OK):
                 raise DMError("invalid adb path, or adb not executable: %s" % self._adbPath)