~fboucault/camera-app/click_autopilot_add_deps

« back to all changes in this revision

Viewing changes to tests/autopilot/camera_app/tests/test_photo_editor.py

  • Committer: CI Train Bot
  • Author(s): Ugo Riboni
  • Date: 2015-02-04 20:35:40 UTC
  • mfrom: (425.7.13 camera-app-editor)
  • Revision ID: ci-train-bot@canonical.com-20150204203540-zdd2ut1x686tlirn
Add photo editor feature using the component from ubuntu-ui-extras. Fixes: #1368787

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
# Copyright 2014 Canonical
 
3
#
 
4
# This program is free software: you can redistribute it and/or modify it
 
5
# under the terms of the GNU General Public License version 3, as published
 
6
# by the Free Software Foundation.
 
7
 
 
8
"""Tests for the Camera photo editor"""
 
9
 
 
10
from testtools.matchers import Equals, NotEquals, GreaterThan, LessThan
 
11
from autopilot.matchers import Eventually
 
12
from autopilot.exceptions import StateNotFoundError
 
13
 
 
14
from camera_app.tests import CameraAppTestCase
 
15
 
 
16
import unittest
 
17
import os
 
18
from time import sleep
 
19
 
 
20
 
 
21
class TestCameraPhotoEditor(CameraAppTestCase):
 
22
    """Tests the main camera features"""
 
23
 
 
24
    """ This is needed to wait for the application to start.
 
25
        In the testfarm, the application may take some time to show up."""
 
26
    def setUp(self):
 
27
        super(TestCameraPhotoEditor, self).setUp()
 
28
        self.assertThat(
 
29
            self.main_window.get_qml_view().visible, Eventually(Equals(True)))
 
30
        self.pictures_dir = os.path.expanduser("~/Pictures/com.ubuntu.camera")
 
31
        self.videos_dir = os.path.expanduser("~/Videos/com.ubuntu.camera")
 
32
 
 
33
    def tearDown(self):
 
34
        super(TestCameraPhotoEditor, self).tearDown()
 
35
 
 
36
    def delete_all_media(self):
 
37
        picture_files = os.listdir(self.pictures_dir)
 
38
        for f in picture_files:
 
39
            os.remove(os.path.join(self.pictures_dir, f))
 
40
 
 
41
        video_files = os.listdir(self.videos_dir)
 
42
        for f in video_files:
 
43
            os.remove(os.path.join(self.videos_dir, f))
 
44
 
 
45
    def add_sample_photo(self):
 
46
        # add a fake photo to pictures_dir
 
47
        photo_path = os.path.join(self.pictures_dir, "fake_photo.jpg")
 
48
        with open(photo_path, 'a'):
 
49
            os.utime(photo_path, None)
 
50
 
 
51
    def select_first_photo(self):
 
52
        # select the first photo
 
53
        gallery = self.main_window.get_gallery()
 
54
        photo = gallery.wait_select_single(objectName="mediaItem0")
 
55
        self.pointing_device.move_to_object(photo)
 
56
 
 
57
        # do a long press to enter Multiselection mode
 
58
        self.pointing_device.press()
 
59
        sleep(1)
 
60
        self.pointing_device.release()
 
61
 
 
62
    """Tests swiping to the gallery and pressing the back button"""
 
63
    def test_editor_appears(self):
 
64
        viewfinder = self.main_window.get_viewfinder()
 
65
        gallery = self.main_window.get_gallery()
 
66
 
 
67
        self.main_window.swipe_to_gallery(self)
 
68
 
 
69
        self.assertThat(gallery.inView, Eventually(Equals(True)))
 
70
 
 
71
        # open actions drawer
 
72
        opt = gallery.wait_select_single(objectName="additionalActionsButton")
 
73
        self.pointing_device.move_to_object(opt)
 
74
        self.pointing_device.click()
 
75
 
 
76
        edit = gallery.wait_select_single(objectName="actionButtonEdit")
 
77
        self.pointing_device.move_to_object(edit)
 
78
        self.pointing_device.click()
 
79
 
 
80
        editor = gallery.wait_select_single(objectName="photoEditor")
 
81
        self.assertThat(editor.visible, Eventually(Equals(True)))
 
82
 
 
83
        undo = gallery.wait_select_single(objectName="undoButton")
 
84
        self.assertThat(undo.visible, Eventually(Equals(True)))
 
85
        self.assertThat(undo.enabled, Eventually(Equals(False)))
 
86
 
 
87
        redo = gallery.wait_select_single(objectName="redoButton")
 
88
        self.assertThat(redo.visible, Eventually(Equals(True)))
 
89
        self.assertThat(redo.enabled, Eventually(Equals(False)))
 
90
 
 
91
        back = gallery.wait_select_single(objectName="backButton")
 
92
        self.pointing_device.move_to_object(back)
 
93
        self.pointing_device.click()
 
94
 
 
95
        disappeared = False
 
96
        try:
 
97
            gallery.select_single(objectName="photoEditor")
 
98
        except StateNotFoundError:
 
99
            disappeared = True
 
100
        self.assertThat(disappeared, Equals(True))