def setUpClass(self):
        """
        set environment
        """
        super(ImageViewByWebBrowser, self).setUpClass()
        self.photos = get_photo_implement()
        self._qrcode = QRcode()
        self._chrome = ChromeExtendImpl()
        self.photos.rm_delete_photos()
        config = TestConfig()
        cfg_file = 'tests.tablet.artifactory.conf'
        cfg_arti = config.read(cfg_file, 'artifactory')
        config_handle = ConfigHandle()
        cfg_arti["location"] = config_handle.read_configuration(
            'artifactory', 'location', '/etc/oat/', 'sys.conf')

        cfg = config.read(cfg_file, 'qrcode_marked_image')
        arti = Artifactory(cfg_arti.get('location'))
        pic_name = cfg.get("q_webp")
        self.pic_name = pic_name.split("/")[-1]
        self.qrcode = cfg.get("q_webp_qrcode")
        file_path = arti.get(pic_name)
        self.photos.deploy_photo_content(local_file=file_path)
        self._chrome.launch()
        self._chrome.chrome_setup()
    def setUp(self):
        super(ComposeUI, self).setUp()
        self._test_name = __name__
        self.device = g_common_obj.get_device()
        print "[Setup]: %s" % self._test_name
        self._composeui = ComposeUiImpl()
        self._imageviewer = ImageDetails()
        self.photos = PhotosExtendImpl()
        self.photosImpl = get_photo_implement()
        self.qrcodeImpl = QRcode()
        g_common_obj.root_on_device()
        g_common_obj.remount_device()
        self.photosImpl.rm_delete_photos()
        self.photosImpl.refresh_sdcard()
        self.photos.clean()

        self.qrcode = "GIFPICTURE"
        config = TestConfig()
        cfg_file = 'tests.tablet.artifactory.conf'
        cfg_arti = config.read(cfg_file, 'artifactory')
        config_handle = ConfigHandle()
        cfg_arti["location"] = config_handle.read_configuration('artifactory', 'location', '/etc/oat/', 'sys.conf')

        cfg = config.read(cfg_file, 'qrcode_marked_image')
        self.qrcode = cfg.get("screenshot_edit_qrcode")
        print "[Debug] qrcode:%s" % (self.qrcode)
        arti = Artifactory(cfg_arti.get('location'))
        pic_name = cfg.get("screenshot_edit_image")
        file_path = arti.get(pic_name)
        g_common_obj.adb_cmd_common('push ' + file_path + ' /sdcard/Pictures')
        self.photosImpl.refresh_sdcard()
        special_actions.setup()
        self.photos.setup()
    def setUp(self):
        print "[Setup]:%s" % self.__class__.__name__
        super(ImageViewing, self).setUp()
        self.device = g_common_obj.get_device()
        self.photos = get_photo_implement()
        self.qrcodeImpl = QRcode()
        self.wallpaper = WallpaperImpl()

        self.photos.rm_delete_photos()
        self.photos.refresh_sdcard()

        self.qrcode = "GIFPICTURE"
        config = TestConfig()
        cfg_file = 'tests.tablet.artifactory.conf'
        cfg_arti = config.read(cfg_file, 'artifactory')
        config_handle = ConfigHandle()
        cfg_arti["location"] = config_handle.read_configuration(
            'artifactory', 'location', '/etc/oat/', 'sys.conf')

        cfg = config.read(cfg_file, 'qrcode_marked_image')
        self.qrcode = cfg.get("screenshot_imageview_qrcode")
        print "[Debug] qrcode:%s" % (self.qrcode)
        arti = Artifactory(cfg_arti.get('location'))
        pic_name = cfg.get("screenshot_imageview_image")
        file_path = arti.get(pic_name)
        g_common_obj.adb_cmd_common('push ' + file_path + ' /sdcard/Pictures')
        self.photos.refresh_sdcard()
class ImageViewing(UIATestBase):
    def setUp(self):
        print "[Setup]:%s" % self.__class__.__name__
        super(ImageViewing, self).setUp()
        self.device = g_common_obj.get_device()
        self.photos = get_photo_implement()
        self.qrcodeImpl = QRcode()
        self.wallpaper = WallpaperImpl()

        self.photos.rm_delete_photos()
        self.photos.refresh_sdcard()

        self.qrcode = "GIFPICTURE"
        config = TestConfig()
        cfg_file = 'tests.tablet.artifactory.conf'
        cfg_arti = config.read(cfg_file, 'artifactory')
        config_handle = ConfigHandle()
        cfg_arti["location"] = config_handle.read_configuration(
            'artifactory', 'location', '/etc/oat/', 'sys.conf')

        cfg = config.read(cfg_file, 'qrcode_marked_image')
        self.qrcode = cfg.get("screenshot_imageview_qrcode")
        print "[Debug] qrcode:%s" % (self.qrcode)
        arti = Artifactory(cfg_arti.get('location'))
        pic_name = cfg.get("screenshot_imageview_image")
        file_path = arti.get(pic_name)
        g_common_obj.adb_cmd_common('push ' + file_path + ' /sdcard/Pictures')
        self.photos.refresh_sdcard()

    def tearDown(self):
        print "[tearDown]:%s" % self.__class__.__name__
        self.photos.rm_delete_photos()
        self.photos.refresh_sdcard()
        super(ImageViewing, self).tearDown()

    def test_AppTransparency_ImageViewing(self):
        ''' refer TC test_AppTransparency_ImageViewing
        '''
        print "[RunTest]: %s" % self.__str__()
        self.photos.launch_photos_am()
        self.photos.open_a_picture()
        if self.device(
                resourceId=
                "com.google.android.apps.photos:id/photos_overflow_icon"):
            self.device(
                resourceId=
                "com.google.android.apps.photos:id/photos_overflow_icon"
            ).click.wait()
        if self.device(resourceId=
                       "com.google.android.apps.photos:id/actionbar_overflow"):
            self.device(
                resourceId="com.google.android.apps.photos:id/actionbar_overflow"
            ).click.wait()
        time.sleep(1)
        self.qrcodeImpl.verify_qrcode_marked_image(self.qrcode,
                                                   set_wallpaper=False)
        g_common_obj.assert_exp_happens()
        self.photos.stop_photos_am()
示例#5
0
class ImageViewByWebBrowser(UIATestBase):
    @classmethod
    def setUpClass(self):
        """
        set environment
        """
        super(ImageViewByWebBrowser, self).setUpClass()
        self.photos = get_photo_implement()
        self._qrcode = QRcode()
        self._chrome = ChromeExtendImpl()
        self.photos.rm_delete_photos()
        config = TestConfig()
        cfg_file = 'tests.tablet.artifactory.conf'
        cfg_arti = config.read(cfg_file, 'artifactory')
        config_handle = ConfigHandle()
        cfg_arti["location"] = config_handle.read_configuration(
            'artifactory', 'location', '/etc/oat/', 'sys.conf')
        cfg = config.read(cfg_file, 'qrcode_marked_image')
        arti = Artifactory(cfg_arti.get('location'))
        pic_name = cfg.get("bmp01")
        self.pic_name1 = pic_name.split("/")[-1]
        self.qrcode1 = cfg.get("bmp01_qrcode")
        file_path = arti.get(pic_name)
        self.photos.deploy_photo_content(local_file=file_path)

        pic_name = cfg.get("bmp02")
        self.pic_name2 = pic_name.split("/")[-1]
        self.qrcode2 = cfg.get("bmp02_qrcode")
        file_path = arti.get(pic_name)
        self.photos.deploy_photo_content(local_file=file_path)

        self._chrome.launch()
        self._chrome.chrome_setup()

    def setUp(self):
        super(ImageViewByWebBrowser, self).setUp()
        self._test_name = __name__
        print "[Setup]: %s" % self._test_name
        self._imageviewer = ImageDetails()

    def tearDown(self):
        print "[Teardown]: %s" % self._test_name
        super(ImageViewByWebBrowser, self).tearDown()
        self.photos.rm_delete_photos()

    def test_ImageView_ByWebBrowser_BMP(self):
        ''' refer TC test_ImageView_ByWebBrowser_BMP
        '''
        print "[RunTest]: %s" % self.__str__()
        pics = {self.pic_name1: self.qrcode1, self.pic_name2: self.qrcode2}
        for p in pics.keys():
            self._chrome.launch()
            self._chrome.open_website("file:///mnt/sdcard/Pictures/%s" % p)
            time.sleep(5)
            self.photos.refresh_sdcard()
            self.photos.open_image_command("/sdcard/Download/%s" % p)
            self._qrcode.verify_qrcode_marked_image(pics[p], False)
            g_common_obj.assert_exp_happens()
示例#6
0
 def setUp(self):
     super(ImageView, self).setUp()
     self._test_name = __name__
     print "[Setup]: %s" % self._test_name
     g_common_obj.root_on_device()
     self.d = g_common_obj.get_device()
     self.photosImpl = get_photo_implement()
     self.qr = QRcode()
     self.photosImpl.rm_delete_photos()
     self.photosImpl.stop_photos_am()
 def setUp(self):
     print "[Setup]:%s" % self.__class__.__name__
     super(VideoPlayback, self).setUp()
     self.photos = get_photo_implement()
     self.bench = Gfxbench()
     self._qr = QRcode()
     self.extend_photos = PhotosExtendImpl()
     self.remote_path = self.extend_photos.push_videos(count=1,
                                                       like='test_video_qr',
                                                       exts='.mp4')[0]
 def setUp(self):
     super(Fit, self).setUp()
     self._test_name = __name__
     print "[Setup]: %s" % self._test_name
     self.photos = get_photo_implement()
     self.d = g_common_obj.get_device()
     self.d.screen.on()
     self._qr = QRcode()
     self.extend_photos = PhotosExtendImpl()
     self.remote_path = self.extend_photos.push_videos(count=1, like='test_video_qr', exts='.mp4')[0]
     adb32.screen_rotation(0)
class ComposeUI(UIATestBase):

    def setUp(self):
        super(ComposeUI, self).setUp()
        self._test_name = __name__
        self.device = g_common_obj.get_device()
        print "[Setup]: %s" % self._test_name
        self._composeui = ComposeUiImpl()
        self._imageviewer = ImageDetails()
        self.photos = PhotosExtendImpl()
        self.photosImpl = get_photo_implement()
        self.qrcodeImpl = QRcode()
        g_common_obj.root_on_device()
        g_common_obj.remount_device()
        self.photosImpl.rm_delete_photos()
        self.photosImpl.refresh_sdcard()
        self.photos.clean()

        self.qrcode = "GIFPICTURE"
        config = TestConfig()
        cfg_file = 'tests.tablet.artifactory.conf'
        cfg_arti = config.read(cfg_file, 'artifactory')
        config_handle = ConfigHandle()
        cfg_arti["location"] = config_handle.read_configuration('artifactory', 'location', '/etc/oat/', 'sys.conf')

        cfg = config.read(cfg_file, 'qrcode_marked_image')
        self.qrcode = cfg.get("screenshot_edit_qrcode")
        print "[Debug] qrcode:%s" % (self.qrcode)
        arti = Artifactory(cfg_arti.get('location'))
        pic_name = cfg.get("screenshot_edit_image")
        file_path = arti.get(pic_name)
        g_common_obj.adb_cmd_common('push ' + file_path + ' /sdcard/Pictures')
        self.photosImpl.refresh_sdcard()
        special_actions.setup()
        self.photos.setup()

    def tearDown(self):
        print "[Teardown]: %s" % self._test_name
        super(ComposeUI, self).tearDown()
        self.photosImpl.rm_delete_photos()
        self.photosImpl.refresh_sdcard()
        clearTmpDir()

    def test_screenshot_imageedit(self):
        ''' refer TC test_screenshot_imageedit
        '''
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.launch_photos_am()
        self._composeui.addeffects_check_screenshot()
        self.device.press.back()
        time.sleep(2)
        self.photosImpl.open_a_picture()
        self.qrcodeImpl.verify_qrcode_marked_image(self.qrcode, set_wallpaper=False)
        self.photosImpl.stop_photos_am()
示例#10
0
 def __init__(self):
     super(PhotosExtendImpl, self).__init__()
     self.configer = TestConfig()
     self.config = self.configer.read(self.config_file, "Photos")
     config_handle = ConfigHandle()
     self.config["artifactory_location"] = config_handle.read_configuration(
         'artifactory', 'location', '/etc/oat', 'sys.conf')
     self.dut_photos_dir = self.config.get("photos_dir")
     self.dut_video_dir = self.config.get("video_dir")
     self.arti = Artifactory(self.config.get("artifactory_location"))
     self._home = PhotosExtendImpl.HomeUI(self.d)
     self._view = PhotosExtendImpl.ViewUI(self.d)
     self.qrcodeImpl = QRcode()
示例#11
0
 def setUp(self):
     super(ComposeUI, self).setUp()
     self._test_name = __name__
     self.d = g_common_obj.get_device()
     print "[Setup]: %s" % self._test_name
     self.photos = get_photo_implement()
     self._qr = QRcode()
     #         self.photos.rm_delete_photos()
     #         self.photos.refresh_sdcard()
     #         self._composeui = ComposeUiImpl()
     #         self._composeui.init_local_video()
     self.extend_photos = PhotosExtendImpl()
     self.remote_path = self.extend_photos.push_videos(like='test_video_qr',
                                                       exts='.mp4')[0]
示例#12
0
class ComposeUI(UIATestBase):
    def setUp(self):
        super(ComposeUI, self).setUp()
        self._test_name = __name__
        print "[Setup]: %s" % self._test_name
        self.d = g_common_obj.get_device()
        #         self.photos = get_photo_implement()
        self._composeui = ComposeUiImpl()
        config_handle = ConfigHandle()
        result = config_handle.check_apps("com.mxtech.videoplayer.ad")
        if result == 0:
            self._composeui.install_apk('Mxplayer')
        self.d.screen.on()
        self._qr = QRcode()
        self.extend_photos = PhotosExtendImpl()
        self.remote_path = self.extend_photos.push_videos(
            count=1, like='test_video_qr_middle', exts='.mp4')[0]
        adb32.screen_rotation(0)

    def tearDown(self):
        print "[Teardown]: %s" % self._test_name
        super(ComposeUI, self).tearDown()
        os.remove("tmp.png")
        adb32.screen_rotation(0)

    def test_scaling_rotation_Video(self):
        ''' refer TC test_Scaling_Rotation_Video
        '''
        print "[RunTest]: %s" % self.__str__()
        self._composeui.play_video_command_mx(self.remote_path)
        time.sleep(2)
        if self.d(textContains="START OVER").exists:
            self.d(textContains="START OVER").click.wait()
        for i in [2, 1, 3, 0]:
            adb32.screen_rotation(i)
            time.sleep(1)
            if self.d(resourceId="com.mxtech.videoplayer.ad:id/ui_layout"
                      ).exists:
                self.d(resourceId="com.mxtech.videoplayer.ad:id/ui_layout"
                       ).pinch.Out(percent=120)
                time.sleep(2)
                assert self._qr.decode_image_qrcode(
                    self.d.screenshot("tmp.png")
                )[1] == "QRCODE_TEST_STRING", "The scaling of video playback failed!"
                self.d(resourceId="com.mxtech.videoplayer.ad:id/ui_layout"
                       ).pinch.In(percent=70, steps=5)
                time.sleep(2)
                assert self._qr.decode_image_qrcode(
                    self.d.screenshot("tmp.png")
                )[1] == "QRCODE_TEST_STRING", "The scaling of video playback failed!"
 def setUp(self):
     super(VideoPlayback, self).setUp()
     self._test_name = __name__
     self.device = g_common_obj.get_device()
     print "[Setup]: %s" % self._test_name
     #         g_common_obj.root_on_device()
     #         g_common_obj.remount_device()
     self.photos = get_photo_implement()
     self.photosImpl = PhotosExtendImpl()
     self._qr = QRcode()
     self.photos.rm_delete_photos()
     self.photos.refresh_sdcard()
     self.remote_path = self.photosImpl.push_videos(
         count=1, like='test_video_qr_bottom', exts='.mp4')[0]
     special_actions.setup()
class ComposeUI(UIATestBase):

    def setUp(self):
        super(ComposeUI, self).setUp()
        self._test_name = __name__
        print "[Setup]: %s" % self._test_name
        self._composeui = ComposeUiImpl()
        self.photos = get_photo_implement()
        self.qrcodeImpl = QRcode()
        self.photosImpl = get_photo_implement()
        self.photosImpl.rm_delete_photos()
        self.photosImpl.refresh_sdcard()
#         self.photos.clean()

        self.qrcode = "GIFPICTURE"
        config = TestConfig()
        cfg_file = 'tests.tablet.artifactory.conf'
        cfg_arti = config.read(cfg_file, 'artifactory')
        config_handle = ConfigHandle()
        cfg_arti["location"] = config_handle.read_configuration('artifactory', 'location', '/etc/oat/', 'sys.conf')

        cfg = config.read(cfg_file, 'qrcode_marked_image')
        self.qrcode = cfg.get("screenshot_imageview_qrcode")
        print "[Debug] qrcode:%s" % (self.qrcode)
        arti = Artifactory(cfg_arti.get('location'))
        pic_name = cfg.get("screenshot_imageview_image")
        file_path = arti.get(pic_name)
        g_common_obj.adb_cmd_common('push ' + file_path + ' /sdcard/Pictures')
        self.pic_path = '/sdcard/Pictures/' + os.path.basename(file_path)
        self.photosImpl.refresh_sdcard()
        special_actions.setup()

    def tearDown(self):
        print "[Teardown]: %s" % self._test_name
        super(ComposeUI, self).tearDown()
        self.photosImpl.rm_delete_photos()
        self.photosImpl.refresh_sdcard()

    def test_screenshot_imageviewing(self):
        ''' refer TC test_screenshot_imageviewing
        '''
        print "[RunTest]: %s" % self.__str__()
#         self.photosImpl.launch_photos_am()
#         self.photosImpl.open_a_picture()
        self.photos.open_image_command(self.pic_path)
        time.sleep(3)
        self.qrcodeImpl.verify_qrcode_marked_image(self.qrcode, set_wallpaper=False)
        self.photosImpl.stop_photos_am()
示例#15
0
 def setUp(self):
     super(ComposeUI, self).setUp()
     self._test_name = __name__
     print "[Setup]: %s" % self._test_name
     self.d = g_common_obj.get_device()
     #         self.photos = get_photo_implement()
     self._composeui = ComposeUiImpl()
     config_handle = ConfigHandle()
     result = config_handle.check_apps("com.mxtech.videoplayer.ad")
     if result == 0:
         self._composeui.install_apk('Mxplayer')
     self.d.screen.on()
     self._qr = QRcode()
     self.extend_photos = PhotosExtendImpl()
     self.remote_path = self.extend_photos.push_videos(
         count=1, like='test_video_qr_middle', exts='.mp4')[0]
     adb32.screen_rotation(0)
示例#16
0
class ComposeUI(UIATestBase):
    def setUp(self):
        super(ComposeUI, self).setUp()
        self._test_name = __name__
        self.d = g_common_obj.get_device()
        print "[Setup]: %s" % self._test_name
        self.photos = get_photo_implement()
        self._qr = QRcode()
        #         self.photos.rm_delete_photos()
        #         self.photos.refresh_sdcard()
        #         self._composeui = ComposeUiImpl()
        #         self._composeui.init_local_video()
        self.extend_photos = PhotosExtendImpl()
        self.remote_path = self.extend_photos.push_videos(like='test_video_qr',
                                                          exts='.mp4')[0]

    def tearDown(self):
        print "[Teardown]: %s" % self._test_name
        #         super(ComposeUI, self).tearDown()
        #         self._composeui.delete_local_video()
        self.photos.rm_delete_photos()
        self.photos.refresh_sdcard()
        g_common_obj.stop_app_am("com.google.android.apps.photos")
        try:
            os.remove(".tmp.png")
        except OSError:
            pass

    def test_videoplayback_forwardrewind(self):
        ''' refer TC test_VideoPlayback_ForwardRewind
        '''
        print "[RunTest]: %s" % self.__str__()
        #         self.photos.launch_photos_am()
        print "---------------GFX_forwardrewind--------------"
        #         from testlib.graphics.screenshot_for_liverpt import take_screenshot_for_liverpt
        #         take_screenshot_for_liverpt()
        self.photos.play_video_command(self.remote_path)
        #         take_screenshot_for_liverpt()
        self.photos.slide_video_processbar_forward()
        #         take_screenshot_for_liverpt()
        assert self._qr.decode_image_qrcode(self.d.screenshot(
            ".tmp.png"))[1] == "QRCODE_TEST_STRING", "Video playback failed!"
        self.photos.slide_video_processbar_backward()
        assert self._qr.decode_image_qrcode(self.d.screenshot(
            ".tmp.png"))[1] == "QRCODE_TEST_STRING", "Video playback failed!"
示例#17
0
 def setUp(self):
     super(NotificationBar, self).setUp()
     self._test_name = __name__
     self.d = g_common_obj.get_device()
     self._qr = QRcode()
     self.photos = get_photo_implement()
     print "[Setup]: %s" % self._test_name
     config = TestConfig()
     cfg_file = 'tests.tablet.artifactory.conf'
     cfg_arti = config.read(cfg_file, 'artifactory')
     config_handle = ConfigHandle()
     cfg_arti["location"] = config_handle.read_configuration(
         'artifactory', 'location', '/etc/oat/', 'sys.conf')
     cfg = config.read(cfg_file, 'content_picture')
     arti = Artifactory(cfg_arti.get('location'))
     pic_name = cfg.get("qr_image")
     file_path = arti.get(pic_name)
     g_common_obj.adb_cmd_common('push ' + file_path + ' /sdcard/Pictures')
     self.pic_path = '/sdcard/Pictures/' + os.path.basename(file_path)
示例#18
0
class NotificationBar(UIATestBase):
    def setUp(self):
        super(NotificationBar, self).setUp()
        self._test_name = __name__
        self.d = g_common_obj.get_device()
        self._qr = QRcode()
        self.photos = get_photo_implement()
        print "[Setup]: %s" % self._test_name
        config = TestConfig()
        cfg_file = 'tests.tablet.artifactory.conf'
        cfg_arti = config.read(cfg_file, 'artifactory')
        config_handle = ConfigHandle()
        cfg_arti["location"] = config_handle.read_configuration(
            'artifactory', 'location', '/etc/oat/', 'sys.conf')
        cfg = config.read(cfg_file, 'content_picture')
        arti = Artifactory(cfg_arti.get('location'))
        pic_name = cfg.get("qr_image")
        file_path = arti.get(pic_name)
        g_common_obj.adb_cmd_common('push ' + file_path + ' /sdcard/Pictures')
        self.pic_path = '/sdcard/Pictures/' + os.path.basename(file_path)
#         self.systemui = SystemUiExtendImpl()
#         self.notifi_quick_settings = NotificationAndQuickSettingsImpl()
#         self.systemui.unlock_screen()

    def tearDown(self):
        print "[Teardown]: %s" % self._test_name
        #         g_common_obj.set_vertical_screen()
        #         super(NotificationBar, self).tearDown()
        self.d.press.home()
        self.photos.rm_delete_photos()
        self.photos.refresh_sdcard()
        try:
            os.remove(".tmp.png")
        except OSError:
            pass

    def test_Shadow_NotificationBar(self):
        """
        1. Open an image file with QR code in it, pull down the notification bar and then take a screenshot.
        2. Use qrtools to read the QR code from the screenshot.
        """
        self.d.orientation = "n"
        _result = []
        for _ in range(0, 3):
            self.photos.open_image_command(self.pic_path)
            time.sleep(2)
            if self.d.open.notification():
                time.sleep(2)
                _result.append(
                    self._qr.decode_image_qrcode(self.d.screenshot(".tmp.png"))
                    [1] == "QRCODE_TEST_STRING")
            if _result[0]:
                break
        print _result
        assert True in _result, "The notification bar is not transparent!"
    def setUp(self):
        print "[Setup]:%s" % self.__class__.__name__
        super(WallpaperSetGIFImageTest, self).setUp()

        self.photos = PhotosExtendImpl()
        self.camera = CameraExtendImpl()
        self.systemui = SystemUiExtendImpl()
        self.photosImpl = get_photo_implement()
        self.qrcodeImpl = QRcode()
        self.wallpaper = WallpaperImpl()

        self.systemui.unlock_screen()
        self.d.screen.on()
        self.d.press.menu()

        self.photos.clean()
        self.camera.clean()
        self.photosImpl.rm_delete_photos()
        self.photosImpl.refresh_sdcard()
        self.wallpaper.reset_wallpaper()

        self.qrcode = "GIFPICTURE"
        config = TestConfig()
        cfg_file = 'tests.tablet.artifactory.conf'
        cfg_arti = config.read(cfg_file, 'artifactory')
        config_handle = ConfigHandle()
        cfg_arti["location"] = config_handle.read_configuration(
            'artifactory', 'location', '/etc/oat/', 'sys.conf')

        cfg = config.read(cfg_file, 'qrcode_marked_image')
        arti = Artifactory(cfg_arti.get('location'))
        self.qrcode = cfg.get("imageviewing_qrcode")
        print "[Debug] qrcode:%s" % (self.qrcode)
        pic_name = cfg.get("imageviewing_image")
        file_path = arti.get(pic_name)
        g_common_obj.adb_cmd_common('push ' + file_path + ' /sdcard/Pictures')
        ImageDetails.set_workaround()

        self.photos.setup()

        self.mark_time = logcat.get_device_time_mark()
 def check_setphoto(self, contactor_name, qr_string):
     """check the photo whether be set
     """
     if self._device().scroll.to(text=contactor_name) == False:
         print "can not find the contacts!"
         return
     if not self._device(text=contactor_name).exists:
         self._device(scrollable=True).scroll.to(text=contactor_name)
         time.sleep(2)
     self._device(text=contactor_name).click()
     time.sleep(2)
     assert QRcode().decode_image_qrcode(g_common_obj.get_device().screenshot(".tmp.png"))[1] == qr_string, "Contactor image setting failed!"
    def setUp(self):
        print "[Setup]:%s" % self.__class__.__name__
        super(ImageViewingSuspendResumeByCommandTest, self).setUp()
        self.photos = PhotosExtendImpl()
        #         self.camera = CameraExtendImpl()
        self.systemui = SystemUiExtendImpl()
        self.photosImpl = get_photo_implement()
        self.qrcodeImpl = QRcode()
        self.device = g_common_obj.get_device()
        self.systemui.unlock_screen()
        self.device.screen.on()
        #         self.device.press.menu()
        self.photosImpl.rm_delete_photos()
        self.photosImpl.refresh_sdcard()
        self.photos.clean()
        #         self.camera.clean()

        self.qrcode = "QRCODE_TEST_STRING"
        config = TestConfig()
        cfg_file = 'tests.tablet.artifactory.conf'
        cfg_arti = config.read(cfg_file, 'artifactory')
        config_handle = ConfigHandle()
        cfg_arti["location"] = config_handle.read_configuration(
            'artifactory', 'location', '/etc/oat/', 'sys.conf')

        cfg = config.read(cfg_file, 'content_picture')
        self.qrcode = cfg.get("imageviewing_qrcode")
        print "[Debug] qrcode:%s" % (self.qrcode)
        arti = Artifactory(cfg_arti.get('location'))
        pic_name = cfg.get("qr_image")
        file_path = arti.get(pic_name)
        g_common_obj.adb_cmd_common('push ' + file_path + ' /sdcard/Pictures')
        self.photosImpl.refresh_sdcard()
        special_actions.setup()
        self.photosImpl.launch_photos_am()
        self.mark_time = logcat.get_device_time_mark()
class VideoPlayback(UIATestBase):
    def setUp(self):
        super(VideoPlayback, self).setUp()
        self._test_name = __name__
        self.device = g_common_obj.get_device()
        print "[Setup]: %s" % self._test_name
        #         g_common_obj.root_on_device()
        #         g_common_obj.remount_device()
        self.photos = get_photo_implement()
        self.photosImpl = PhotosExtendImpl()
        self._qr = QRcode()
        self.photos.rm_delete_photos()
        self.photos.refresh_sdcard()
        self.remote_path = self.photosImpl.push_videos(
            count=1, like='test_video_qr_bottom', exts='.mp4')[0]
        special_actions.setup()

    def tearDown(self):
        print "[Teardown]: %s" % self._test_name
        super(VideoPlayback, self).tearDown()
        self.photos.rm_delete_photos()
        self.photos.refresh_sdcard()
        try:
            os.remove(".tmp.png")
        except OSError:
            pass

    def test_AppTransparency_VideoPlayback(self):
        ''' refer TC test_AppTransparency_VideoPlayback
        '''
        print "[RunTest]: %s" % self.__str__()
        x, y = 0, self.device.info[
            'displayHeight'] / 2  # touch point for full screen playback.
        self.photos.play_video_command(self.remote_path)
        #         self.photos.launch_photos_am()
        #         self.photos.play_video()
        time.sleep(5)
        self.photos.pause_play_video()
        g_common_obj.adb_cmd_capture_msg("input touchscreen tap %s %s" %
                                         (x, y))
        time.sleep(5)
        assert self._qr.decode_image_qrcode(self.device.screenshot(".tmp.png"))[1] == "QRCODE_TEST_STRING",\
            "Video playback transparency test failed!"
class VideoPlayback(UIATestBase):
    @classmethod
    def setUpClass(cls):
        print "[setUpClass]: %s" % cls.__name__
        super(VideoPlayback, cls).setUpClass()
        cls.d = g_common_obj.get_device()
        g_common_obj.root_on_device()

    def setUp(self):
        print "[Setup]:%s" % self.__class__.__name__
        super(VideoPlayback, self).setUp()
        self.photos = get_photo_implement()
        self.bench = Gfxbench()
        self._qr = QRcode()
        self.extend_photos = PhotosExtendImpl()
        self.remote_path = self.extend_photos.push_videos(count=1,
                                                          like='test_video_qr',
                                                          exts='.mp4')[0]

    def tearDown(self):
        print "[tearDown]:%s" % self.__class__.__name__
        self.photos.rm_delete_photos()
        self.photos.refresh_sdcard()
        self.photos.stop_photos_am()
        try:
            os.remove(".tmp.png")
        except OSError:
            pass

    def test_AppSwitching(self):
        print "[RunTest]: %s" % self.__str__()
        self.photos.play_video_command(self.remote_path, 5)
        self.bench.setup()
        self.bench.run_test("ALU 2", 50000)
        time.sleep(10)
        self.photos.play_video_command(self.remote_path, 5)
        screen_temp = tempfile.mktemp(suffix='.png',
                                      prefix='screenshot_',
                                      dir='/tmp')
        g_common_obj.take_screenshot(screen_temp)
        ret, qrcode = self._qr.decode_image_qrcode(screen_temp)
        assert ret and qrcode == "QRCODE_TEST_STRING", "Video playback failed!"
class Fit(RenderAppTestBase):

    def setUp(self):
        super(Fit, self).setUp()
        self._test_name = __name__
        print "[Setup]: %s" % self._test_name
        self.photos = get_photo_implement()
        self.d = g_common_obj.get_device()
        self.d.screen.on()
        self._qr = QRcode()
        self.extend_photos = PhotosExtendImpl()
        self.remote_path = self.extend_photos.push_videos(count=1, like='test_video_qr', exts='.mp4')[0]
        adb32.screen_rotation(0)

    def tearDown(self):
        print "[Teardown]: %s" % self._test_name
        super(Fit, self).tearDown()
        self.photos.rm_delete_photos()
        self.photos.refresh_sdcard()
        g_common_obj.stop_app_am("com.google.android.apps.photos")
        try:
            os.remove(".tmp.png")
        except OSError:
            pass
        adb32.screen_rotation(0)

    def test_switch_portrait_landscape_apps_serval_times(self):
        ''' refer TC test_switch_portrait_landscape_apps_serval_times
        '''
        print "[RunTest]: %s" % self.__str__()
        n = 5
        self.photos.play_video_command(self.remote_path)
        while n > 0:
            for i in [2, 1, 3, 0]:
                adb32.screen_rotation(i)
                time.sleep(10)
                assert self._qr.decode_image_qrcode(self.d.screenshot(".tmp.png"))[1] == "QRCODE_TEST_STRING", "Video playback failed!"
            n = n - 1
示例#25
0
class PhotosExtendImpl(PhotosImpl):
    """ Photos uiautomator """

    config_file = 'tests.common.photos.conf'

    HostPhotoPagerActivity = "com.google.android.apps.photos.viewer.pager.HostPhotoPagerActivity"

    class HomeUI(object):
        """Home UI Elements"""
        def __init__(self, device):
            self.device = device

        @property
        def list_item(self):
            return self.device(className='android.view.View')

        @property
        def first_item(self):
            return self.device(
                resourceId="com.google.android.apps.plus:id/tile_row"
            )[0].child(index=0)

    class ViewUI(object):
        """View UI elements"""
        def __init__(self, device):
            self.device = device

        @property
        def play(self):
            return self.device(resourceId="com.google.android.apps.plus:"
                               "id/photo_view_pager")\
                .child(description="Play video")

        @property
        def is_video(self):
            return self.device(resourceId="com.google.android.apps.plus:"
                               "id/photo_view_pager")\
                .child(description="Play video")\
                .exists

        def show_more(self):
            if not self.device(description="More options").exists\
                    and not self.device(text="Help").exists:
                self.device().click()
            self.device(description="More options").click()

        @property
        def option_slideshow(self):
            self.show_more()
            return self.device(textContains="Slideshow")

        @property
        def option_set_as(self):
            self.show_more()
            return self.device(textContains="Set as")

    def __init__(self):
        super(PhotosExtendImpl, self).__init__()
        self.configer = TestConfig()
        self.config = self.configer.read(self.config_file, "Photos")
        config_handle = ConfigHandle()
        self.config["artifactory_location"] = config_handle.read_configuration(
            'artifactory', 'location', '/etc/oat', 'sys.conf')
        self.dut_photos_dir = self.config.get("photos_dir")
        self.dut_video_dir = self.config.get("video_dir")
        self.arti = Artifactory(self.config.get("artifactory_location"))
        self._home = PhotosExtendImpl.HomeUI(self.d)
        self._view = PhotosExtendImpl.ViewUI(self.d)
        self.qrcodeImpl = QRcode()

    def launch(self):
        """launch APP"""
        g_common_obj.launch_app_am(
            'com.google.android.apps.plus',
            'com.google.android.apps.photos.phone.PhotosHomeActivity')
        time.sleep(4)
        if self.d(text="Later").exists:
            self.d(text="Later").click()
            time.sleep(2)
        time.sleep(5)
        self.d.wait.update()

    def click_list_item(self, index):
        """click list item"""
        print "[Debug] click_list_item index:%s" % (index)
        self._home.list_item[index].click()

    def find_video(self):
        """find video item"""
        print "[Debug] find_video"
        for i in range(self._home.list_item.count):
            self._home.list_item[i].click()
            time.sleep(2)
            _, activity = SystemUi.get_current_focus()
            if activity != self.HostPhotoPagerActivity:
                continue
            if self._view.is_video:
                self.d.press.back()
                time.sleep(2)
                print "video index:%s" % (i)
                return i
            self.d.press.back()
        assert False, "There is no video items"

    def find_photo(self):
        print "[Debug] find_photo"
        for i in range(self._home.list_item.count):
            self._home.list_item[i].click()
            time.sleep(2)
            _, activity = SystemUi.get_current_focus()
            if activity != self.HostPhotoPagerActivity:
                continue
            if not self._view.is_video:
                self.d.press.back()
                time.sleep(2)
                print "photo index:%s" % (i)
                return i
            self.d.press.back()
        assert False, "There is no photo items"

    def setup(self):
        """setup environment"""
        self.launch()
        time.sleep(2)
        device = self.d
        if device(textContains="No thanks").exists:
            device(textContains="No thanks").click()

        special_actions.setup()

    def play_video(self, secs=None, timeout=None):
        """click play video"""

        print "[Debug] play_video"
        mark_time = logcat.get_device_time_mark()
        pre_dump = self.d.dump()
        pre_focus = SystemUi.get_current_focus()
        print pre_focus

        self._view.play.click.wait()
        if secs:
            time.sleep(secs)
        end_dump = self.d.dump()
        end_focus = SystemUi.get_current_focus()
        print end_focus

        seq_match = difflib.SequenceMatcher(None, pre_dump, end_dump)
        ratio = round(seq_match.ratio(), 2) * 100
        print "ratio:%s" % ratio

        if ratio == 100 and pre_focus == end_focus:
            assert False, "[FAILURE] Play video No any reply"
        if not secs:
            start_time = time.time()
            play_done = False
            while time.time() - start_time < timeout:
                time.sleep(10)
                if self._view.play.exists:
                    play_done = True
                    break
            assert play_done, "[FAILURE] Play video time out"

        errmsg = logcat.get_device_log(mark_time, filters='MediaPlayer:E *:S')
        assert not errmsg, "[FAILURE] Found Errors in Logcat during Play Video\n%s" % (
            errmsg)

    def check_video_icons(self):
        x = self.d.info.get("displayWidth")
        y = self.d.info.get("displayHeight")
        self.d.click(x / 2, y / 2)
        time.sleep(3)
        assert self.d(resourceId="com.google.android.apps.plus:id/videoplayer"
                      ).exists, "Video is not shown on the screen"

    def push_pictures(self, count=1, exts=None):
        remote_pictures = []
        pictures = self.configer.read(self.config_file, "Pictures")
        if exts:
            pictures = {
                k: v
                for k, v in pictures.iteritems() if v.lower().endswith(exts)
            }
        if count > len(pictures.items()):
            assert False, \
                "[FAILURE] There are not enough resource."

        for _, value in pictures.iteritems():
            pic_path = self.arti.get(value)
            ret = g_common_obj.push_file(pic_path, self.dut_photos_dir)
            remote_pictures.append(self.dut_video_dir + '/' +
                                   os.path.basename(pic_path))
            assert ret, 'Failed push %s' % (pic_path)
            count -= 1
            if count == 0:
                break

        cmd = \
            "am broadcast -a android.intent.action.MEDIA_MOUNTED -d file://%s"\
            % (self.dut_photos_dir)
        g_common_obj.adb_cmd_capture_msg(repr(cmd))
        print "[Debug] pushed %s" % (remote_pictures)
        return remote_pictures

    def push_qrcode_pictures(self, count=1, exts=None, mark_count=1):
        remote_pictures = []
        pictures = self.configer.read(self.config_file, "Pictures")
        if exts:
            pictures = {
                k: v
                for k, v in pictures.iteritems() if v.lower().endswith(exts)
            }
        if count > len(pictures.items()):
            assert False, \
                "[FAILURE] There are not enough resource."

        for _, value in pictures.iteritems():
            pic_path = self.arti.get(value)
            qrcode = id_generator()
            pic_path = self.qrcodeImpl.mark_image_qrcode(pic_path,
                                                         code=qrcode,
                                                         count=mark_count)
            ret = g_common_obj.push_file(pic_path, self.dut_photos_dir)

            remote_pictures.append({
                'qrcode':
                qrcode,
                'path':
                self.dut_video_dir + '/' + os.path.basename(pic_path)
            })
            assert ret, 'Failed push %s' % (pic_path)
            remove_temp_file(pic_path)
            count -= 1
            if count == 0:
                break

        cmd = \
            "am broadcast -a android.intent.action.MEDIA_MOUNTED -d file://%s"\
            % (self.dut_photos_dir)
        g_common_obj.adb_cmd_capture_msg(repr(cmd))
        print "[Debug] pushed %s" % (remote_pictures)
        return remote_pictures

    def push_specified_qrcode_pictures(self, count=1, exts=None, mark_count=1):
        remote_pictures = []
        pictures = self.configer.read(self.config_file, "Pictures")
        if exts:
            pictures = {
                k: v
                for k, v in pictures.iteritems() if v.lower().endswith(exts)
            }
        if count > len(pictures.items()):
            assert False, \
                "[FAILURE] There are not enough resource."

        for _, value in pictures.iteritems():
            pic_path = self.arti.get(value)
            qrcode = "ABCDEFGHIJ"
            pic_path = qrcode_obj.mark_image_qrcode(pic_path,
                                                    code=qrcode,
                                                    count=mark_count)
            ret = g_common_obj.push_file(pic_path, self.dut_photos_dir)

            remote_pictures.append({
                'qrcode':
                qrcode,
                'path':
                self.dut_video_dir + '/' + os.path.basename(pic_path)
            })
            assert ret, 'Failed push %s' % (pic_path)
            remove_temp_file(pic_path)
            count -= 1
            if count == 0:
                break

        cmd = \
            "am broadcast -a android.intent.action.MEDIA_MOUNTED -d file://%s"\
            % (self.dut_photos_dir)
        g_common_obj.adb_cmd_capture_msg(repr(cmd))
        print "[Debug] pushed %s" % (remote_pictures)
        return remote_pictures

    def push_videos(self, count=1, like=None, exts=None):
        remote_videos = []
        videos = self.configer.read(self.config_file, "Videos")
        if like:
            videos = {
                k: v
                for k, v in videos.iteritems()
                if v.lower().find(like.lower()) != -1
            }
        if exts:
            videos = {
                k: v
                for k, v in videos.iteritems() if v.lower().endswith(exts)
            }
#         if like and exts:
#             videos = { k:v for k, v in videos.iteritems() if os.path.basename(v) == like + exts }

        if count > len(videos.items()):
            assert False, \
                '[FAILURE] The video is not in config file ' + self.config_file

        for _, value in videos.iteritems():
            pic_path = self.arti.get(value)
            ret = g_common_obj.push_file(
                pic_path,
                self.dut_video_dir + '/' + os.path.basename(pic_path))
            assert ret, 'Failed push %s' % (pic_path)
            remote_videos.append(self.dut_video_dir + '/' +
                                 os.path.basename(pic_path))
            count -= 1
            if count == 0:
                break

        cmd = \
            "am broadcast -a android.intent.action.MEDIA_MOUNTED -d file://%s"\
            % (self.dut_video_dir)
        g_common_obj.adb_cmd_capture_msg(repr(cmd))
        print "[Debug] pushed %s" % (remote_videos)
        return remote_videos

    def slideshow(self, duration):
        print "[Debug] slideshow"
        pre_screen = tempfile.mktemp(suffix='.png',
                                     prefix='screen_',
                                     dir='/tmp')
        end_screen = tempfile.mktemp(suffix='.png',
                                     prefix='screen_',
                                     dir='/tmp')

        def action():
            self._home.first_item.click()
            self.d.wait.update()
            self._view.option_slideshow.click()

        action()
        start_time = time.time()
        self.d.screenshot(pre_screen)
        while time.time() - start_time < duration:
            time.sleep(6)
            self.d.wait.idle(timeout=3000)
            self.d.screenshot(end_screen)
            if filecmp.cmp(pre_screen, end_screen):
                self.d.press.back()
                action()
            self.d.wait.idle(timeout=3000)
            self.d.screenshot(pre_screen)
        self.d.press.back()

    def setwallpaper(self):
        print "[Debug] setwallpaper"
        if self.d(text="More options").exists:
            self.d(text="More options").click()
        self._view.option_set_as.click()
        if self.d(text='More').exists:
            self.d(text='More').click()
            time.sleep(1)
        self.d(text='Wallpaper').click()
        time.sleep(3)
        self.d(text='Set wallpaper').click()
        time.sleep(3)
        if self.d(text="Set wallpaper").exists:
            self.d(text='Set wallpaper').click()
            time.sleep(6)

    def verify_wallpaper(self, qrcode):
        home_screen = tempfile.mktemp(suffix='.png',
                                      prefix='screen_',
                                      dir='/tmp')
        self.d.press.home()
        time.sleep(1)
        self.d.screenshot(home_screen)
        _, decode = qrcode_obj.decode_image_qrcode(home_screen)
        print "[Debug] verify_wallpaper qrcode:%s decode:%s" % (qrcode, decode)
        assert decode == qrcode, \
            "[FAILURE] Failed verify wallpaper qrcode:%s decode:%s" % (qrcode, decode)
        remove_temp_file(home_screen)

    def verify_imageview(self):
        home_screen = tempfile.mktemp(suffix='.png',
                                      prefix='screen_',
                                      dir='/tmp')
        decode = ''

        for _ in range(10):
            self.d.screenshot(home_screen)
            ret, decode = qrcode_obj.decode_image_qrcode(home_screen)
            print "[Debug]", ret, decode

            if ret is False or decode == 'NULL':
                special_actions.zoom_in()
                continue
            break

        remove_temp_file(home_screen)
        return decode

    def clean(self):
        for each in [self.dut_photos_dir, self.dut_video_dir]:
            cmd = \
                "rm -rf %s/*; sync; "\
                "am broadcast -a android.intent.action.MEDIA_MOUNTED -d file://%s"\
                % (each, each)
            g_common_obj.adb_cmd_capture_msg(repr(cmd))
        special_actions.clean()
示例#26
0
class ImageView(UIATestBase):

    PHOTO_PATH = "/sdcard/Pictures"
    VIDEO_PATH = "/sdcard/Movies"
    ACCEPTABLE_VALUE = 5

    def setUp(self):
        super(ImageView, self).setUp()
        self._test_name = __name__
        print "[Setup]: %s" % self._test_name
        g_common_obj.root_on_device()
        self.d = g_common_obj.get_device()
        self.photosImpl = get_photo_implement()
        self.qr = QRcode()
        self.photosImpl.rm_delete_photos()
        self.photosImpl.stop_photos_am()

    def tearDown(self):
        print "[Teardown]: %s" % self._test_name
        super(ImageView, self).tearDown()
        self.photosImpl.rm_delete_photos()
        remove_aosp_launcher()

    def test_MoreThan10JPEGImagesOfDifferentResolution(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("PicturesFolder",
                                                 "jpg_10resolution",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            for _ in range(9):
                self.d().swipe.left(steps=10)
                time.sleep(2)
        except:
            raise Exception("Test failed!")

    def test_MoreThan10BMPImages(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("PicturesFolder",
                                                 "bmp_10resolution",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            for _ in range(9):
                self.d().swipe.left(steps=10)
                time.sleep(2)
        except:
            raise Exception("Test failed!")

    def test_MoreThan10BMPImagesOfDifferentResolution(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("PicturesFolder",
                                                 "bmp_10resolution",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            for _ in range(9):
                self.d().swipe.left(steps=10)
                time.sleep(2)
        except:
            raise Exception("Test failed!")

    def test_MoreThan10GIFImagesOfDifferentResolution(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("PicturesFolder",
                                                 "gif_10resolution",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            for _ in range(9):
                self.d().swipe.left(steps=10)
                time.sleep(2)
        except:
            raise Exception("Test failed!")

    def test_MoreThan10PNGImagesOfDifferentResolution(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("PicturesFolder",
                                                 "png_10resolution",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            for _ in range(9):
                self.d().swipe.left(steps=10)
                time.sleep(2)
        except:
            raise Exception("Test failed!")

    def test_MoreThan10PNGImages(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("PicturesFolder",
                                                 "png_10resolution",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            for _ in range(9):
                self.d().swipe.left(steps=10)
                time.sleep(2)
        except:
            raise Exception("Test failed!")

    def test_MoreThan10WBMPImagesOfDifferentResolution(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("PicturesFolder",
                                                 "wbmp_10resolution",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            for _ in range(9):
                self.d().swipe.left(steps=10)
                time.sleep(2)
        except:
            raise Exception("Test failed!")

    def test_MoreThan10WEBPImagesOfDifferentResolution(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("PicturesFolder",
                                                 "webp_10resolution",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            for _ in range(9):
                self.d().swipe.left(steps=10)
                time.sleep(2)
        except:
            raise Exception("Test failed!")

    def test_AddDisplayEffect_DragProgressBar(self):
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_004",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        allEffects = PARENT_EFFECTS + LIGHT_CHILD_EFFECTS + COLOR_CHILD_EFFECTS
        useEffects = []
        loopNum = 5
        for _ in range(loopNum):
            index = random.randint(0, len(allEffects) - 1)
            useEffects.append(allEffects[index])
        useEffects.sort()
        for useEffect in useEffects:
            MinOrMax = [0, 100]
            index = random.randint(0, len(MinOrMax) - 1)
            effectVolume = MinOrMax[index]
            self.photosImpl.change_display_effect(effType=useEffect,
                                                  effVol=effectVolume)
        self.photosImpl.save_changes()
        assert self.photosImpl.check_saved_pic_result(picPath=self.PHOTO_PATH) >= self.ACCEPTABLE_VALUE,\
            "Failed! No effects on the saving pic."

    def test_ImageEdit_AddSaturationEffect(self):
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_004",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        # ---------------Grag to left or right---------------
        index = random.randint(0, 1)
        if index == 0:
            effectVolume = random.randint(0, 49)
        else:
            effectVolume = random.randint(50, 100)
        self.photosImpl.change_display_effect(effType='Saturation',
                                              effVol=effectVolume)
        self.photosImpl.save_changes()
        assert self.photosImpl.check_saved_pic_result(picPath=self.PHOTO_PATH) > 0, \
            "Failed! No effects on the saving pic."

    def test_ImageEdit_AddShadowEffect(self):
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_004",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        # ---------------Grag to left or right---------------
        effectVolume = [0, 100][random.randint(0, 1)]
        self.photosImpl.change_display_effect(effType='Shadows',
                                              effVol=effectVolume)
        self.photosImpl.save_changes()
        assert self.photosImpl.check_saved_pic_result(picPath=self.PHOTO_PATH) >= self.ACCEPTABLE_VALUE, \
            "Failed! No effects on the saving pic."

    def test_ImageEdit_AddVignetteEffect_BlueImageEditingAndSwitching(self):
        from testlib.graphics.extend_systemui_impl import SystemUiExtendImpl
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_blue",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        settings_pkgName = "com.android.settings"
        g_common_obj.adb_cmd_capture_msg(
            "am start %s" % settings_pkgName)  # launch settings app previously
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        self.photosImpl.change_display_effect(effType='Vignette', effVol=100)
        SystemUiExtendImpl().switch_recent_app(name='Settings')
        SystemUiExtendImpl().switch_recent_app(name='Photos')
        time.sleep(2)
        self.photosImpl.save_changes()
        assert self.photosImpl.check_saved_pic_result(picPath=self.PHOTO_PATH) >= self.ACCEPTABLE_VALUE, \
            "Failed! No effects on the saving pic."

    def test_ImageEdit_BMP_CancelEdit(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures", "picture_001",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            self.photosImpl.change_display_effect(effVol=100)
            self.photosImpl.undo_edit()
        except:
            raise Exception("Test failed!")

    def test_ImageEdit_BMP_Zoom_ByGesture(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures", "picture_001",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            self.photosImpl.pic_zoom_out(300)
        except:
            raise Exception("Test failed!")

    def test_ImageEdit_EditPNGImage_CancelEdit(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures", "picture_004",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            self.photosImpl.change_display_effect(effVol=100)
            self.photosImpl.undo_edit()
        except:
            raise Exception("Test failed!")

    def test_ImageEdit_GIF_Zoom_ByGesture(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures", "picture_002",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            self.photosImpl.pic_zoom_in(300)
        except:
            raise Exception("Test failed!")

    def test_ImageEdit_JPEG_Rotate_LeftRight(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures", "picture_003",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            self.photosImpl.click_crop_tools()
            time.sleep(1)
            for _ in range(4):
                self.photosImpl.rotate_90_degrees()
                time.sleep(.5)
        except:
            raise Exception("Test failed!")

    def test_ImageEdit_JPG_Rotate(self):
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_003",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        self.photosImpl.click_crop_tools()
        time.sleep(1)
        # --------Rotate left or right--------
        i = [1, 3][random.randint(0, 1)]
        for _ in range(i):
            self.photosImpl.rotate_90_degrees()
        self.photosImpl.save_picture_after_rotation()
        assert self.photosImpl.check_saved_pic_result(picPath=self.PHOTO_PATH) >= self.ACCEPTABLE_VALUE, \
            "Failed! No effects on the saving pic."

    def test_ImageEdit_JPG_Zoom_ByBoth(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures", "picture_003",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            self.photosImpl.view_a_picture_fullscreen()
            self.photosImpl.pic_zoom_in(300)
            self.photosImpl.pic_zoom_out(300)
        except:
            raise Exception("Test failed!")

    def test_ImageEdit_PNG_AddShadowEffect_2MBImage(self):
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_004",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        self.photosImpl.change_display_effect(effType='Shadows', effVol=100)
        self.photosImpl.save_changes()
        assert self.photosImpl.check_saved_pic_result(picPath=self.PHOTO_PATH) >= self.ACCEPTABLE_VALUE, \
            "Failed! No effects on the saving pic."

    def test_ImageEdit_PNG_Rotate(self):
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_004",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        self.photosImpl.click_crop_tools()
        time.sleep(1)
        # --------Rotate left or right--------
        i = [1, 3][random.randint(0, 1)]
        for _ in range(i):
            self.photosImpl.rotate_90_degrees()
        self.photosImpl.save_picture_after_rotation()
        assert self.photosImpl.check_saved_pic_result(picPath=self.PHOTO_PATH) >= self.ACCEPTABLE_VALUE, \
            "Failed! No effects on the saving pic."

    def test_ImageEdit_PNG_SaveEdit(self):
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_004",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        self.photosImpl.change_display_effect(effVol=100)
        self.photosImpl.save_changes()
        assert self.photosImpl.check_saved_pic_result(picPath=self.PHOTO_PATH) >= self.ACCEPTABLE_VALUE, \
            "Failed! No effects on the saving pic."

    def test_ImageEdit_PNG_Zoom_ByGesture(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures", "picture_004",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            self.photosImpl.pic_zoom_out(300)
        except:
            raise Exception("Test failed!")

    def test_ImageEdit_Rotate90degree_SaveImage(self):
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_blue",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        self.photosImpl.click_crop_tools()
        time.sleep(1)
        self.photosImpl.rotate_90_degrees()
        self.photosImpl.save_picture_after_rotation()
        assert self.photosImpl.check_saved_pic_result(picPath=self.PHOTO_PATH) > 0, \
            "Failed! No effects on the saving pic."

    def test_ImageEdit_WBMP_Rotate(self):
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_006",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        self.photosImpl.click_crop_tools()
        time.sleep(1)
        # --------Rotate left or right--------
        i = [1, 3][random.randint(0, 1)]
        for _ in range(i):
            self.photosImpl.rotate_90_degrees()
        self.photosImpl.save_picture_after_rotation()
        assert self.photosImpl.check_saved_pic_result_by_screenshot(self.PHOTO_PATH) >= self.ACCEPTABLE_VALUE, \
            "Failed! No effects on the saving pic."

    def test_ImageEdit_WEBP_Rotate(self):
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_007",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        self.photosImpl.click_crop_tools()
        time.sleep(1)
        # --------Rotate left or right--------
        i = [1, 3][random.randint(0, 1)]
        for _ in range(i):
            self.photosImpl.rotate_90_degrees()
        self.photosImpl.save_picture_after_rotation()
        assert self.photosImpl.check_saved_pic_result_by_screenshot(self.PHOTO_PATH) >= self.ACCEPTABLE_VALUE, \
            "Failed! No effects on the saving pic."

    def test_ImageEdit_WEBP_Zoom_ByGesture(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures", "picture_007",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            self.photosImpl.pic_zoom_in(300)
        except:
            raise Exception("Test failed!")

    def test_ImageEdit_BWeffect_MoreThan5MB(self):
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_morethan5mb",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        for eff in ['Whites', 'Blacks']:
            self.photosImpl.change_display_effect(effType=eff, effVol=100)
        self.photosImpl.save_changes()
        assert self.photosImpl.check_saved_pic_result(picPath=self.PHOTO_PATH) >= self.ACCEPTABLE_VALUE, \
            "Failed! No effects on the saving pic."

    def test_ImageEdit_BMP_Check4M(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures", "picture_bmp4mb",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            self.photosImpl.view_a_picture_fullscreen()
        except:
            raise Exception("Test failed!")

    def test_imagedelete_press_menu_select_photo_delete(self):
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_bmp4mb",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        bef_del = self.photosImpl.check_pic_number(self.PHOTO_PATH)
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        self.photosImpl.delete_a_picture()
        aft_del = self.photosImpl.check_pic_number(self.PHOTO_PATH)
        assert bef_del != aft_del, "Fail to delete pic!"

    def test_imageedit_blueimage_addvignetteeffect(self):
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_blue",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        self.photosImpl.change_display_effect(effType='Vignette', effVol=100)
        self.photosImpl.save_changes()
        assert self.photosImpl.check_saved_pic_result(picPath=self.PHOTO_PATH) >= self.ACCEPTABLE_VALUE, \
            "Failed! No effects on the saving pic."

    def test_ImageEdit_WBMP_Zoom_ByBoth(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures", "picture_006",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            self.photosImpl.view_a_picture_fullscreen()
            self.photosImpl.pic_zoom_in(300)
            self.photosImpl.pic_zoom_out(300)
        except:
            raise Exception("Test failed!")

    def test_imageedit_addeffects_setwallpaper(self):
        print "[RunTest]: %s" % self.__str__()
        if "com.android.launcher3" not in pkgmgr.get_packages():
            launch_aosp_home()
        self.photosImpl.deploy_photo_content("Pictures", "picture_004",
                                             self.PHOTO_PATH)
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        self.photosImpl.change_display_effect(effType='Vignette', effVol=100)
        self.photosImpl.save_changes()
        self.photosImpl.click_crop_tools()
        self.photosImpl.rotate_right_45_degrees()
        self.photosImpl.save_picture_after_rotation()
        org_image = self.photosImpl.only_pull_saved_pic(self.PHOTO_PATH)
        out_image = self.qr.mark_image_qrcode(str(org_image))
        self.photosImpl.stop_photos_am()
        self.photosImpl.rm_delete_photos()
        self.photosImpl.deploy_photo_content(directory=self.PHOTO_PATH,
                                             local_file=out_image)
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        self.photosImpl.set_picture_as_wallpaper()
        self.qr.verify_qrcode_marked_image(qrcode="9876543210",
                                           set_wallpaper=True)

    def test_imageedit_addstraighteneffect_lessthan20kb(self):
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_blue",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        self.photosImpl.click_crop_tools()
        time.sleep(1)
        # --------Rotate left or right--------
        i = [1, 3][random.randint(0, 1)]
        for _ in range(i):
            self.photosImpl.rotate_90_degrees()
        self.photosImpl.save_picture_after_rotation()
        assert self.photosImpl.check_saved_pic_result(picPath=self.PHOTO_PATH) > 0, \
            "Failed! No effects on the saving pic."

    def test_MoreThan1000Images(self):
        from testlib.graphics.common import busybox_obj
        from testlib.util.config import TestConfig

        print "[RunTest]: %s" % self.__str__()
        # Prepare for 1000 imgs.
        self.photosImpl.deploy_photo_content("Pictures",
                                             "picture_morethan1000",
                                             self.PHOTO_PATH)
        pics = TestConfig().read(
            CONFIG_FILE, "Pictures").get("picture_morethan1000").split('/')[-1]
        busybox_obj.setup()
        cmd = "busybox tar xvf %s/%s -C %s" % (self.PHOTO_PATH, pics,
                                               self.PHOTO_PATH)
        chk_cmd = "\'ls %s/1000/ | grep -c png\'" % self.PHOTO_PATH
        clean_cmd = "rm -rf %s/%s" % (self.PHOTO_PATH, pics)
        busybox_obj.adb_busybox_cmd(cmd)
        rst = 0
        while rst != 1000:
            rst = int(g_common_obj.adb_cmd_capture_msg(chk_cmd))
            time.sleep(5)
        else:
            print "1000 pic prepared."
        g_common_obj.adb_cmd_capture_msg(clean_cmd)
        time.sleep(3)
        self.photosImpl.refresh_sdcard()
        time.sleep(10)
        try:
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture('1000')
            self.d.press.back()
            _index = random.randint(1, 30)
            sw_num = random.randint(1, 5)
            for i in range(sw_num):
                self.d().swipe.up()
                time.sleep(1)
            self.d(index=_index).click.wait()
        except:
            raise Exception("Test failed!")

    def test_ImageEdit_Add_Effect_Rotate(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures", "picture_004",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            self.photosImpl.change_display_effect(effType='Vignette',
                                                  effVol=80)
            adb32.screen_rotation(1)
            adb32.screen_rotation(0)
        except:
            raise Exception("Test failed!")
        finally:
            adb32.screen_rotation(0)

    def test_ImageEdit_AddStraightenEffect(self):
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_004",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        self.photosImpl.click_crop_tools()
        self.photosImpl.rotate_right_45_degrees()
        self.photosImpl.save_picture_after_rotation()
        assert self.photosImpl.check_saved_pic_result(picPath=self.PHOTO_PATH) > self.ACCEPTABLE_VALUE, \
            "Failed! No effects on the saving pic."

    def test_ImageEdit_AddVignetteEffect(self):
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_004",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        self.photosImpl.change_display_effect(effType='Vignette', effVol=80)
        self.photosImpl.save_changes()
        assert self.photosImpl.check_saved_pic_result(picPath=self.PHOTO_PATH) >= self.ACCEPTABLE_VALUE, \
            "Failed! No effects on the saving pic."

    def test_ImageEdit_BMP_Check1K(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures", "picture_bmp1k",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
        except:
            raise Exception("Test failed!")

    def test_ImageEdit_BMP_Crop(self):
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_001",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        self.photosImpl.click_crop_tools()
        self.photosImpl.rotate_right_45_degrees()
        self.photosImpl.save_picture_after_rotation()
        assert self.photosImpl.check_saved_pic_result_by_screenshot(self.PHOTO_PATH) > self.ACCEPTABLE_VALUE, \
            "Failed! No effects on the saving pic."

    def test_ImageEdit_BMP_SaveEdit(self):
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_001",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        self.photosImpl.change_display_effect(effType='Vignette', effVol=88)
        self.photosImpl.save_changes()
        assert self.photosImpl.check_saved_pic_result_by_screenshot(self.PHOTO_PATH) > self.ACCEPTABLE_VALUE, \
            "Failed! No effects on the saving pic."

    def test_ImageEdit_CorpUprightRectangular(self):
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_004",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        self.photosImpl.click_crop_tools()
        self.photosImpl.crop_to_center(start_corner="left_bottom")
        self.photosImpl.save_picture_after_rotation()
        assert self.photosImpl.check_saved_pic_result(picPath=self.PHOTO_PATH) >= self.ACCEPTABLE_VALUE, \
            "Failed! No effects on the saving pic."

    def test_ImageEdit_CropMoreThan8times_Rotate(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures", "picture_004",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            self.photosImpl.click_crop_tools()
            for i in range(9):
                self.photosImpl.rotate_90_degrees()
                time.sleep(.5)
            self.photosImpl.save_picture_after_rotation()
            assert self.photosImpl.check_saved_pic_result(picPath=self.PHOTO_PATH) > 0, \
                "Failed! No effects on the saving pic."
        except:
            raise Exception("Test failed in round 1.")
        self.photosImpl.rm_delete_photos()

        try:
            adb32.screen_rotation(1)
            self.photosImpl.deploy_photo_content("Pictures", "picture_004",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            self.photosImpl.click_crop_tools()
            for i in range(9):
                self.photosImpl.rotate_90_degrees()
                time.sleep(.5)
            self.photosImpl.save_picture_after_rotation()
            assert self.photosImpl.check_saved_pic_result(picPath=self.PHOTO_PATH) > 0, \
                "Failed! No effects on the saving pic."
        except:
            raise Exception("Test failed in round 2.")
        finally:
            adb32.screen_rotation(0)

    def test_ImageEdit_JPG_1K_Check(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures", "picture_jpg1k",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
        except:
            raise Exception("Test failed!")

    def test_ImageEdit_JPG_2M_Check(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures", "picture_jpg2m",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
        except:
            raise Exception("Test failed!")

    def test_ImageEdit_JPG_CancelEdit(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures", "picture_003",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            self.photosImpl.change_display_effect(effVol=100)
            self.photosImpl.undo_edit()
        except:
            raise Exception("Test failed!")

    def test_ImageEdit_JPG_Crop(self):
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_003",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        self.photosImpl.click_crop_tools()
        self.photosImpl.crop_to_center(start_corner="left_top")
        self.photosImpl.save_picture_after_rotation()
        assert self.photosImpl.check_saved_pic_result(picPath=self.PHOTO_PATH) >= self.ACCEPTABLE_VALUE, \
            "Failed! No effects on the saving pic."

    def test_ImageEdit_JPG_SaveEdit(self):
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_003",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        self.photosImpl.change_display_effect(effType='Vignette', effVol=22)
        self.photosImpl.save_changes()
        assert self.photosImpl.check_saved_pic_result(picPath=self.PHOTO_PATH) >= self.ACCEPTABLE_VALUE, \
            "Failed! No effects on the saving pic."

    def test_ImageEdit_PanoramicImage_AddEffect(self):
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_panoramic",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        self.photosImpl.change_display_effect(effType='Warmth', effVol=77)
        self.photosImpl.save_changes()
        assert self.photosImpl.check_saved_pic_result(picPath=self.PHOTO_PATH) >= self.ACCEPTABLE_VALUE, \
            "Failed! No effects on the saving pic."

    def test_ImageEdit_PersonFaceImage2MB_AddBWOrSharpnessEffects(self):
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_face",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        self.photosImpl.change_display_effect(effType='Blacks', effVol=99)
        self.photosImpl.change_display_effect(effType='Whites', effVol=99)
        self.photosImpl.save_changes()
        assert self.photosImpl.check_saved_pic_result(picPath=self.PHOTO_PATH) >= self.ACCEPTABLE_VALUE, \
            "Failed! No effects on the saving pic."

    def test_ImageEdit_PNG_Crop(self):
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_004",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        self.photosImpl.click_crop_tools()
        self.photosImpl.crop_to_center(start_corner="right_top")
        self.photosImpl.save_picture_after_rotation()
        assert self.photosImpl.check_saved_pic_result(picPath=self.PHOTO_PATH) >= self.ACCEPTABLE_VALUE, \
            "Failed! No effects on the saving pic."

    def test_ImageEdit_Rotate_Left(self):
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_004",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        self.photosImpl.click_crop_tools()
        self.photosImpl.rotate_90_degrees()
        self.photosImpl.save_picture_after_rotation()
        assert self.photosImpl.check_saved_pic_result(picPath=self.PHOTO_PATH) >= self.ACCEPTABLE_VALUE, \
            "Failed! No effects on the saving pic."

    def test_ImageEdit_Rotate_Right(self):
        print "[RunTest]: %s" % self.__str__()
        self.photosImpl.deploy_photo_content("Pictures", "picture_004",
                                             self.PHOTO_PATH)
        self.photosImpl.refresh_sdcard()
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        self.photosImpl.click_crop_tools()
        for i in range(3):
            self.photosImpl.rotate_90_degrees()
            time.sleep(.5)
        self.photosImpl.save_picture_after_rotation()
        assert self.photosImpl.check_saved_pic_result(picPath=self.PHOTO_PATH) >= self.ACCEPTABLE_VALUE, \
            "Failed! No effects on the saving pic."

    def test_ImageEdit_ThumbMD_All_Rotate(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("PicturesFolder",
                                                 "jpg_10resolution",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            adb32.screen_rotation(1)
        except:
            raise Exception("Test failed!")
        finally:
            adb32.screen_rotation(0)

    def test_ImageEdit_ThumbMD_One_Rotate(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures", "picture_004",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            adb32.screen_rotation(1)
        except:
            raise Exception("Test failed!")
        finally:
            adb32.screen_rotation(0)

    def test_ImageView_Webp_Check(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures", "picture_007",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
        except:
            raise Exception("Test failed!")

    def test_ImageView_Webp_Thumbnail_LPCheck(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures", "picture_webp2m",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            self.photosImpl.view_a_picture_fullscreen()
        except:
            raise Exception("Test failed!")

    def test_ImageView_Wbmp_2K_Check(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures", "picture_wbmp2k",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
        except:
            raise Exception("Test failed!")

    def test_ImageView_Wbmp_300K_Check(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures",
                                                 "picture_wbmp300k",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
        except:
            raise Exception("Test failed!")

    def test_ImageView_Webp_1K_Check(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures", "picture_webp1k",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
        except:
            raise Exception("Test failed!")

    def test_ImageView_Webp_2M_Check(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures", "picture_webp2m",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
        except:
            raise Exception("Test failed!")

    def test_ImageEdit_BMP_Check8M(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures", "picture_bmp8mb",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
        except:
            raise Exception("Test failed!")

    def test_ImageEdit_PNG_AllTransParent_Check(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures",
                                                 "picture_transparent",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
        except:
            raise Exception("Test failed!")

    def test_MoreThan10GIFImages(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("PicturesFolder",
                                                 "gif_10resolution",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            self.photosImpl.view_a_picture_fullscreen()
            for _ in range(9):
                self.d().swipe.left(steps=10)
                time.sleep(2)
        except:
            raise Exception("Test failed!")

    def test_MoreThan10JPEGImages(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("PicturesFolder",
                                                 "jpg_10resolution",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            self.photosImpl.view_a_picture_fullscreen()
            for _ in range(9):
                self.d().swipe.left(steps=10)
                time.sleep(2)
        except:
            raise Exception("Test failed!")

    def test_ImageView_Thumbnail_Mode(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures", "picture_005",
                                                 self.PHOTO_PATH)
            self.photosImpl.refresh_sdcard()
            self.photosImpl.launch_photos_am()
        except:
            raise Exception("Test failed!")

    def test_ImageZoom_JPEG(self):
        print "[RunTest]: %s" % self.__str__()
        try:
            self.photosImpl.deploy_photo_content("Pictures", "picture_004",
                                                 self.PHOTO_PATH)
            self.photosImpl.launch_photos_am()
            self.photosImpl.open_a_picture()
            self.photosImpl.pic_zoom_out(30)
        except:
            raise Exception("Test failed!")
class WallpaperSetBMPImageTest(UIATestBase):
    @classmethod
    def setUpClass(cls):
        print "[setUpClass]: %s" % cls.__name__
        super(WallpaperSetBMPImageTest, cls).setUpClass()
        cls.d = g_common_obj.get_device()
        g_common_obj.root_on_device()
#         g_common_obj.remount_device()

    def setUp(self):
        print "[Setup]:%s" % self.__class__.__name__
        super(WallpaperSetBMPImageTest, self).setUp()

        self.photos = PhotosExtendImpl()
        self.camera = CameraExtendImpl()
        self.systemui = SystemUiExtendImpl()
        self.photosImpl = get_photo_implement()
        self.qrcodeImpl = QRcode()
        #         self.wallpaper = WallpaperImpl()
        #         self.systemui.unlock_screen()
        #         self.d.screen.on()
        #         self.d.press.menu()

        self.photos.clean()
        self.camera.clean()
        #         self.photosImpl.rm_delete_photos()
        #         self.photosImpl.refresh_sdcard()
        #         self.wallpaper.reset_wallpaper()

        self.qrcode = "GIFPICTURE"
        config = TestConfig()
        cfg_file = 'tests.tablet.artifactory.conf'
        cfg_arti = config.read(cfg_file, 'artifactory')
        config_handle = ConfigHandle()
        cfg_arti["location"] = config_handle.read_configuration(
            'artifactory', 'location', '/etc/oat/', 'sys.conf')

        cfg = config.read(cfg_file, 'qrcode_marked_image')
        self.qrcode = cfg.get("wallpaperset_bmp_qrcode")
        print "[Debug] qrcode:%s" % (self.qrcode)
        arti = Artifactory(cfg_arti.get('location'))
        pic_name = cfg.get("wallpaperset_bmp_image")
        file_path = arti.get(pic_name)
        g_common_obj.adb_cmd_common('push ' + file_path + ' /sdcard/Pictures')
        self.photosImpl.refresh_sdcard()
        special_actions.setup()

        self.mark_time = logcat.get_device_time_mark()

    def tearDown(self):
        print "[tearDown]:%s" % self.__class__.__name__
        self.photosImpl.rm_delete_photos()
        self.photosImpl.refresh_sdcard()
        #         fatal_msg = logcat.get_device_log(self.mark_time, filters='*:F')
        #         assert len(fatal_msg) == 0,\
        #             "occurred Fatal error during testing:\n%s" % (fatal_msg)
        super(WallpaperSetBMPImageTest, self).tearDown()

    @classmethod
    def tearDownClass(cls):
        print "[tearDownClass]: %s" % cls.__name__
        super(WallpaperSetBMPImageTest, cls).tearDownClass()

    def test_WallpaperSet_BMPImage(self):
        """
        test_WallpaperSet_BMPImage

        Steps:
        1. Open a BMP picture by Gallery app
        BMP image display is OK.
        2. Select "Set as..." Wallpaper option and crop the picture
        Select wallpaper option and crop the picture are OK.
        3. Back the home UI to check the wallpaer after setting
        The BMP picture can set as wallpaper successfully. DUT has no crash or freeze.
        """
        print "[RunTest]: %s" % self.__str__()

        print """[Step] 1. Open a BMP picture by Gallery app
            BMP image display is OK."""
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        print """[Step] 2. Select "Set as..." Wallpaper option and crop the picture
            Select wallpaper option and crop the picture are OK."""
        self.photosImpl.set_picture_as_wallpaper()
        print """[Step] 3. Back the home UI to check the wallpaer after setting
            The BMP picture can set as wallpaper successfully. DUT has no crash or freeze."""
        self.qrcodeImpl.verify_qrcode_marked_image(self.qrcode)
class ImageViewingSuspendResumeByCommandTest(PhotoTestBase):
    def setUp(self):
        print "[Setup]:%s" % self.__class__.__name__
        super(ImageViewingSuspendResumeByCommandTest, self).setUp()
        self.photos = PhotosExtendImpl()
        #         self.camera = CameraExtendImpl()
        self.systemui = SystemUiExtendImpl()
        self.photosImpl = get_photo_implement()
        self.qrcodeImpl = QRcode()
        self.device = g_common_obj.get_device()
        self.systemui.unlock_screen()
        self.device.screen.on()
        #         self.device.press.menu()
        self.photosImpl.rm_delete_photos()
        self.photosImpl.refresh_sdcard()
        self.photos.clean()
        #         self.camera.clean()

        self.qrcode = "QRCODE_TEST_STRING"
        config = TestConfig()
        cfg_file = 'tests.tablet.artifactory.conf'
        cfg_arti = config.read(cfg_file, 'artifactory')
        config_handle = ConfigHandle()
        cfg_arti["location"] = config_handle.read_configuration(
            'artifactory', 'location', '/etc/oat/', 'sys.conf')

        cfg = config.read(cfg_file, 'content_picture')
        self.qrcode = cfg.get("imageviewing_qrcode")
        print "[Debug] qrcode:%s" % (self.qrcode)
        arti = Artifactory(cfg_arti.get('location'))
        pic_name = cfg.get("qr_image")
        file_path = arti.get(pic_name)
        g_common_obj.adb_cmd_common('push ' + file_path + ' /sdcard/Pictures')
        self.photosImpl.refresh_sdcard()
        special_actions.setup()
        self.photosImpl.launch_photos_am()
        self.mark_time = logcat.get_device_time_mark()

    def tearDown(self):
        print "[tearDown]:%s" % self.__class__.__name__
        self.photosImpl.rm_delete_photos()
        self.photosImpl.refresh_sdcard()
        #         fatal_msg = logcat.get_device_log(self.mark_time, filters='*:F')
        #         assert len(fatal_msg) == 0,\
        #             "occurred Fatal error during testing:\n%s" % (fatal_msg)
        super(ImageViewingSuspendResumeByCommandTest, self).tearDown()
        try:
            os.remove(".tmp.png")
        except OSError:
            pass

    @classmethod
    def tearDownClass(cls):
        print "[tearDownClass]: %s" % cls.__name__
        super(ImageViewingSuspendResumeByCommandTest, cls).tearDownClass()

    def test_ImageViewing_SuspendResumeByCommand_20times(self):
        """
        test_ImageViewing_SuspendResumeByCommand_20times

        Steps:
        1. Launch Photos app to view an image.
        Image viewed in Photos app.
        2. Launch a terminal/CMD and input command "adb shell input keyevent KEYCODE_POWER" to suspend/resume the devices for 20 times.
        No error & hung up & panic occur.
        """
        print "[RunTest]: %s" % self.__str__()

        print """[Step] 1. Launch Photos app to view an image.
        Image viewed in Photos app."""
        self.photosImpl.launch_photos_am()
        self.photosImpl.open_a_picture()
        #         self.qrcodeImpl.verify_qrcode_marked_image(self.qrcode,set_wallpaper=False)
        print """[Step] 2. Launch a terminal/CMD and input command "adb shell input keyevent KEYCODE_POWER" to suspend/resume the devices for 20 times.
        No error & hung up & panic occur."""
        #         cmd_power = "input keyevent KEYCODE_POWER"
        #         cmd_menu = "input keyevent KEYCODE_MENU"
        for i in range(1, 21):
            print "[Debug] %s times" % (i)
            #             g_common_obj.adb_cmd(cmd_power)
            #             time.sleep(1)
            #             assert not is_device_screen_on(), "[FAILURE] Failed suspend device"
            self.device.wakeup()
            time.sleep(3)
            #             g_common_obj.adb_cmd(cmd_power)
            #             g_common_obj.adb_cmd(cmd_menu)
            #             time.sleep(1)
            #             assert is_device_screen_on(), "[FAILURE] Failed resume device"
            #             self.qrcodeImpl.verify_qrcode_marked_image(self.qrcode,set_wallpaper=False)
            assert self.qrcodeImpl.decode_image_qrcode(self.device.screenshot(".tmp.png"))[1] == "QRCODE_TEST_STRING",\
                "Imageviewing failed after resuming DUT in test cycle %s" % (i)
            time.sleep(1)
            self.device.sleep()
            time.sleep(3)