1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
# Copyright 2014 Canonical
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.
8
"""Tests for the Camera photo editor"""
10
from testtools.matchers import Equals, NotEquals, GreaterThan, LessThan
11
from autopilot.matchers import Eventually
12
from autopilot.exceptions import StateNotFoundError
14
from camera_app.tests import CameraAppTestCase
18
from time import sleep
21
class TestCameraPhotoEditor(CameraAppTestCase):
22
"""Tests the main camera features"""
24
""" This is needed to wait for the application to start.
25
In the testfarm, the application may take some time to show up."""
27
super(TestCameraPhotoEditor, self).setUp()
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")
34
super(TestCameraPhotoEditor, self).tearDown()
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))
41
video_files = os.listdir(self.videos_dir)
43
os.remove(os.path.join(self.videos_dir, f))
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)
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)
57
# do a long press to enter Multiselection mode
58
self.pointing_device.press()
60
self.pointing_device.release()
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()
67
self.main_window.swipe_to_gallery(self)
69
self.assertThat(gallery.inView, Eventually(Equals(True)))
72
opt = gallery.wait_select_single(objectName="additionalActionsButton")
73
self.pointing_device.move_to_object(opt)
74
self.pointing_device.click()
76
edit = gallery.wait_select_single(objectName="actionButtonEdit")
77
self.pointing_device.move_to_object(edit)
78
self.pointing_device.click()
80
editor = gallery.wait_select_single(objectName="photoEditor")
81
self.assertThat(editor.visible, Eventually(Equals(True)))
83
undo = gallery.wait_select_single(objectName="undoButton")
84
self.assertThat(undo.visible, Eventually(Equals(True)))
85
self.assertThat(undo.enabled, Eventually(Equals(False)))
87
redo = gallery.wait_select_single(objectName="redoButton")
88
self.assertThat(redo.visible, Eventually(Equals(True)))
89
self.assertThat(redo.enabled, Eventually(Equals(False)))
91
back = gallery.wait_select_single(objectName="backButton")
92
self.pointing_device.move_to_object(back)
93
self.pointing_device.click()
97
gallery.select_single(objectName="photoEditor")
98
except StateNotFoundError:
100
self.assertThat(disappeared, Equals(True))