Merge lp:~phablet-team/camera-app/refactor-and-fix-editor-tests into lp:camera-app

Proposed by Ugo Riboni
Status: Merged
Approved by: Florian Boucault
Approved revision: 537
Merged at revision: 534
Proposed branch: lp:~phablet-team/camera-app/refactor-and-fix-editor-tests
Merge into: lp:camera-app
Diff against target: 479 lines (+171/-117)
7 files modified
tests/autopilot/camera_app/data/__init__.py (+6/-0)
tests/autopilot/camera_app/emulators/main_window.py (+4/-2)
tests/autopilot/camera_app/emulators/panel.py (+4/-3)
tests/autopilot/camera_app/tests/__init__.py (+30/-0)
tests/autopilot/camera_app/tests/test_capture.py (+5/-2)
tests/autopilot/camera_app/tests/test_gallery_view.py (+63/-73)
tests/autopilot/camera_app/tests/test_photo_editor.py (+59/-37)
To merge this branch: bzr merge lp:~phablet-team/camera-app/refactor-and-fix-editor-tests
Reviewer Review Type Date Requested Status
Florian Boucault (community) Approve
PS Jenkins bot continuous-integration Needs Fixing
Review via email: mp+250931@code.launchpad.net

Commit message

Refactor camera editor tests, make them work even if UI extras are not installed, and add a test for the edit button being disabled when on a video

Description of the change

Refactor camera editor tests, make them work even if UI extras are not installed, and add a test for the edit button being disabled when on a video

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
527. By Ugo Riboni

Fix very random bug on dragging the panel by maximizing the speed of drag

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
528. By Ugo Riboni

Prevent failure when removing config file if it does not exist

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
529. By Ugo Riboni

Merge lp:~canonical-platform-qa/camera-app/close-panel-helper-fix to group more fixes in one review

530. By Ugo Riboni

Explicit rate parameter in calls to drag

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
531. By Ugo Riboni

When possible prefer adding sample media in advance of launching the app than taking actual pictures or videos

532. By Ugo Riboni

Make sure we don't fail if for any reason there are subdirectories while we try to clean the media directory

533. By Ugo Riboni

Merge changes from trunk

534. By Ugo Riboni

Fix missing parameter on call

535. By Ugo Riboni

Minimize swipe speed when switching to gallery view and back as it seems to be necessary to fix the problem in combination with previous changes

536. By Ugo Riboni

Ensure environment is clean of other media when running tests

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
537. By Ugo Riboni

Ensure editor tests have photo or video present before starting the test, or they will not be picked up

Revision history for this message
Florian Boucault (fboucault) wrote :

All tests green on krillin RTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'tests/autopilot/camera_app/data'
2=== added file 'tests/autopilot/camera_app/data/__init__.py'
3--- tests/autopilot/camera_app/data/__init__.py 1970-01-01 00:00:00 +0000
4+++ tests/autopilot/camera_app/data/__init__.py 2015-03-11 09:25:45 +0000
5@@ -0,0 +1,6 @@
6+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
7+# Copyright 2015 Canonical
8+#
9+# This program is free software: you can redistribute it and/or modify it
10+# under the terms of the GNU General Public License version 3, as published
11+# by the Free Software Foundation.
12
13=== added file 'tests/autopilot/camera_app/data/sample.jpg'
14Binary files tests/autopilot/camera_app/data/sample.jpg 1970-01-01 00:00:00 +0000 and tests/autopilot/camera_app/data/sample.jpg 2015-03-11 09:25:45 +0000 differ
15=== added file 'tests/autopilot/camera_app/data/sample.mp4'
16Binary files tests/autopilot/camera_app/data/sample.mp4 1970-01-01 00:00:00 +0000 and tests/autopilot/camera_app/data/sample.mp4 2015-03-11 09:25:45 +0000 differ
17=== modified file 'tests/autopilot/camera_app/emulators/main_window.py'
18--- tests/autopilot/camera_app/emulators/main_window.py 2015-01-27 17:36:59 +0000
19+++ tests/autopilot/camera_app/emulators/main_window.py 2015-03-11 09:25:45 +0000
20@@ -5,6 +5,8 @@
21 # under the terms of the GNU General Public License version 3, as published
22 # by the Free Software Foundation.
23
24+import sys
25+
26 from camera_app.emulators.panel import Panel
27 from autopilot.matchers import Eventually
28 from testtools.matchers import Equals
29@@ -141,7 +143,7 @@
30 tx = x + (w // 2)
31 ty = y + (h // 2)
32
33- testCase.pointing_device.drag(tx, ty, (tx - main_view.width // 2), ty)
34+ testCase.pointing_device.drag(tx, ty, x, ty, rate=1)
35 viewfinder = self.get_viewfinder()
36 testCase.assertThat(viewfinder.inView, Eventually(Equals(False)))
37
38@@ -152,6 +154,6 @@
39 tx = x + (w // 2)
40 ty = y + (h // 2)
41
42- testCase.pointing_device.drag(tx, ty, (tx + main_view.width // 2), ty)
43+ testCase.pointing_device.drag(tx, ty, (tx + main_view.width // 2), ty, rate=1)
44 viewfinder = self.get_viewfinder()
45 testCase.assertThat(viewfinder.inView, Eventually(Equals(True)))
46
47=== modified file 'tests/autopilot/camera_app/emulators/panel.py'
48--- tests/autopilot/camera_app/emulators/panel.py 2014-12-10 17:47:57 +0000
49+++ tests/autopilot/camera_app/emulators/panel.py 2015-03-11 09:25:45 +0000
50@@ -6,6 +6,7 @@
51 # by the Free Software Foundation.
52
53 import logging
54+import sys
55
56 from autopilot import logging as autopilot_logging
57 from camera_app.emulators.baseemulator import CameraCustomProxyObjectBase
58@@ -38,7 +39,7 @@
59 start_y = y + self.height - 1
60 stop_y = y
61
62- self.pointing_device.drag(line_x, start_y, line_x, stop_y)
63+ self.pointing_device.drag(line_x, start_y, line_x, stop_y, rate=sys.maxsize)
64
65 @autopilot_logging.log_action(logger.info)
66 def close(self):
67@@ -51,8 +52,8 @@
68
69 def _drag_to_close(self):
70 x, y, _, _ = self.globalRect
71- line_x = x
72+ line_x = x + self.width - 1
73 start_y = y
74 stop_y = y + self.height - 1
75
76- self.pointing_device.drag(line_x, start_y, line_x, stop_y)
77+ self.pointing_device.drag(line_x, start_y, line_x, stop_y, rate=sys.maxsize)
78
79=== modified file 'tests/autopilot/camera_app/tests/__init__.py'
80--- tests/autopilot/camera_app/tests/__init__.py 2014-11-17 14:27:25 +0000
81+++ tests/autopilot/camera_app/tests/__init__.py 2015-03-11 09:25:45 +0000
82@@ -9,10 +9,15 @@
83
84 import os
85 import time
86+import shutil
87+from time import sleep
88+from pkg_resources import resource_filename
89
90 from autopilot.input import Mouse, Touch, Pointer
91 from autopilot.platform import model
92 from autopilot.testcase import AutopilotTestCase
93+from autopilot.matchers import Eventually
94+from testtools.matchers import Equals
95
96 from camera_app.emulators.main_window import MainWindow
97 from camera_app.emulators.baseemulator import CameraCustomProxyObjectBase
98@@ -32,6 +37,10 @@
99 local_location = "../../camera-app"
100 deb_location = '/usr/bin/camera-app'
101
102+ pictures_dir = os.path.expanduser("~/Pictures/com.ubuntu.camera")
103+ videos_dir = os.path.expanduser("~/Videos/com.ubuntu.camera")
104+ sample_dir = resource_filename('camera_app', 'data')
105+
106 def setUp(self):
107 self.pointing_device = Pointer(self.input_device_class.create())
108 super(CameraAppTestCase, self).setUp()
109@@ -79,3 +88,24 @@
110 @property
111 def main_window(self):
112 return MainWindow(self.app)
113+
114+ def delete_all_media(self):
115+ picture_files = os.listdir(self.pictures_dir)
116+ for f in picture_files:
117+ f = os.path.join(self.pictures_dir, f)
118+ if os.path.isfile(f):
119+ os.remove(f)
120+
121+ video_files = os.listdir(self.videos_dir)
122+ for f in video_files:
123+ f = os.path.join(self.videos_dir, f)
124+ if os.path.isfile(f):
125+ os.remove(f)
126+
127+ def add_sample_photo(self):
128+ shutil.copyfile(os.path.join(self.sample_dir, "sample.jpg"),
129+ os.path.join(self.pictures_dir, "sample.jpg"))
130+
131+ def add_sample_video(self):
132+ shutil.copyfile(os.path.join(self.sample_dir, "sample.mp4"),
133+ os.path.join(self.videos_dir, "sample.mp4"))
134
135=== modified file 'tests/autopilot/camera_app/tests/test_capture.py'
136--- tests/autopilot/camera_app/tests/test_capture.py 2015-01-20 12:33:39 +0000
137+++ tests/autopilot/camera_app/tests/test_capture.py 2015-03-11 09:25:45 +0000
138@@ -28,7 +28,8 @@
139 def setUp(self):
140 # Remove configuration file where knowledge of the photo roll hint's necessity is stored
141 config_file = os.path.expanduser("~/.config/com.ubuntu.camera/com.ubuntu.camera.conf")
142- os.remove(config_file)
143+ if os.path.exists(config_file):
144+ os.remove(config_file)
145
146 super(TestCapture, self).setUp()
147
148@@ -199,7 +200,9 @@
149 def delete_all_photos(self):
150 picture_files = os.listdir(self.pictures_dir)
151 for f in picture_files:
152- os.remove(os.path.join(self.pictures_dir, f))
153+ f = os.path.join(self.pictures_dir, f)
154+ if os.path.isfile(f):
155+ os.remove(os.path.join(self.pictures_dir, f))
156
157 def get_first_picture(self, timeout=10):
158 pictures = []
159
160=== modified file 'tests/autopilot/camera_app/tests/test_gallery_view.py'
161--- tests/autopilot/camera_app/tests/test_gallery_view.py 2015-02-18 14:23:02 +0000
162+++ tests/autopilot/camera_app/tests/test_gallery_view.py 2015-03-11 09:25:45 +0000
163@@ -16,24 +16,8 @@
164 import os
165 from time import sleep
166
167-
168-class TestCameraGalleryView(CameraAppTestCase):
169- """Tests the main camera features"""
170-
171- """ This is needed to wait for the application to start.
172- In the testfarm, the application may take some time to show up."""
173- def setUp(self):
174- super(TestCameraGalleryView, self).setUp()
175- self.assertThat(
176- self.main_window.get_qml_view().visible, Eventually(Equals(True)))
177- self.pictures_dir = os.path.expanduser("~/Pictures/com.ubuntu.camera")
178- self.videos_dir = os.path.expanduser("~/Videos/com.ubuntu.camera")
179-
180- def tearDown(self):
181- super(TestCameraGalleryView, self).tearDown()
182-
183+class TestCameraGalleryViewMixin(object):
184 def move_from_slideshow_to_photogrid(self):
185- # make sure we move from slideshow to photogrid view
186 gallery = self.main_window.get_gallery()
187
188 slideshow_view = gallery.wait_select_single("SlideshowView")
189@@ -52,39 +36,6 @@
190 self.assertThat(slideshow_view.visible, Eventually(Equals(False)))
191 self.assertThat(photogrid_view.visible, Eventually(Equals(True)))
192
193- def delete_all_media(self):
194- picture_files = os.listdir(self.pictures_dir)
195- for f in picture_files:
196- f = os.path.join(self.pictures_dir, f)
197- if os.path.isfile(f):
198- os.remove(f)
199-
200- video_files = os.listdir(self.videos_dir)
201- for f in video_files:
202- f = os.path.join(self.videos_dir, f)
203- if os.path.isfile(f):
204- os.remove(f)
205-
206- def add_sample_photo(self):
207- self.main_window.swipe_to_viewfinder(self)
208- exposure_button = self.main_window.get_exposure_button()
209- self.assertThat(exposure_button.enabled, Eventually(Equals(True)))
210- self.pointing_device.move_to_object(exposure_button)
211- self.pointing_device.click()
212-
213- def add_sample_video(self):
214- self.main_window.swipe_to_viewfinder(self)
215- video_button = self.main_window.get_record_control()
216- self.pointing_device.move_to_object(video_button)
217- self.pointing_device.click()
218-
219- exposure_button = self.main_window.get_exposure_button()
220- self.assertThat(exposure_button.enabled, Eventually(Equals(True)))
221- self.pointing_device.move_to_object(exposure_button)
222- self.pointing_device.click()
223- sleep(3)
224- self.pointing_device.click()
225-
226 def select_first_photo(self):
227 # select the first photo
228 gallery = self.main_window.get_gallery()
229@@ -96,6 +47,18 @@
230 sleep(1)
231 self.pointing_device.release()
232
233+class TestCameraGalleryView(CameraAppTestCase, TestCameraGalleryViewMixin):
234+ """Tests the camera gallery view without media already present"""
235+
236+ def setUp(self):
237+ self.delete_all_media()
238+ super(TestCameraGalleryView, self).setUp()
239+ self.assertThat(
240+ self.main_window.get_qml_view().visible, Eventually(Equals(True)))
241+
242+ def tearDown(self):
243+ super(TestCameraGalleryView, self).tearDown()
244+
245 """Tests swiping to the gallery and pressing the back button"""
246 def test_swipe_to_gallery(self):
247 viewfinder = self.main_window.get_viewfinder()
248@@ -120,7 +83,6 @@
249
250 """Tests swiping to the gallery/photo roll with no media in it"""
251 def test_swipe_to_empty_gallery(self):
252- self.delete_all_media()
253 viewfinder = self.main_window.get_viewfinder()
254 gallery = self.main_window.get_gallery()
255
256@@ -133,14 +95,31 @@
257
258 self.assertThat(hint.visible, Eventually(Equals(True)))
259
260- self.add_sample_photo()
261+ # Take a picture and verify that the no media hint disappears
262+ self.main_window.swipe_to_viewfinder(self)
263+ exposure_button = self.main_window.get_exposure_button()
264+ self.assertThat(exposure_button.enabled, Eventually(Equals(True)))
265+ self.pointing_device.move_to_object(exposure_button)
266+ self.pointing_device.click()
267
268 self.assertThat(hint.visible, Eventually(Equals(False)))
269
270+class TestCameraGalleryViewWithVideo(TestCameraGalleryViewMixin, CameraAppTestCase):
271+ """Tests the camera gallery view with video already present"""
272+
273+ def setUp(self):
274+ self.delete_all_media()
275+ self.add_sample_video()
276+
277+ super(TestCameraGalleryViewWithVideo, self).setUp()
278+ self.assertThat(
279+ self.main_window.get_qml_view().visible, Eventually(Equals(True)))
280+
281+ def tearDown(self):
282+ super(TestCameraGalleryViewWithVideo, self).tearDown()
283+
284 """Tests the thumnails for video load correctly in slideshow view"""
285 def test_video_thumbnails(self):
286- self.add_sample_video()
287- self.delete_all_media()
288 viewfinder = self.main_window.get_viewfinder()
289 gallery = self.main_window.get_gallery()
290
291@@ -152,29 +131,22 @@
292 spinner = gallery.wait_select_single("ActivityIndicator")
293 self.assertThat(spinner.running, Eventually(Equals(False)))
294
295- """Tests entering/leaving multiselection mode in the photogrid view"""
296- def test_multiselection_mode(self):
297+class TestCameraGalleryViewWithPhoto(TestCameraGalleryViewMixin, CameraAppTestCase):
298+ """Tests the camera gallery view with photo already present"""
299+
300+ def setUp(self):
301+ self.delete_all_media()
302 self.add_sample_photo()
303- self.main_window.swipe_to_gallery(self)
304- self.move_from_slideshow_to_photogrid()
305- self.select_first_photo()
306-
307- # exit the multiselection mode
308- gallery = self.main_window.get_gallery()
309- back_button = gallery.wait_select_single(objectName="backButton")
310- self.pointing_device.move_to_object(back_button)
311- self.pointing_device.click()
312-
313- slideshow_view = gallery.wait_select_single("SlideshowView")
314- photogrid_view = gallery.wait_select_single("PhotogridView")
315-
316- self.assertThat(slideshow_view.visible, Eventually(Equals(False)))
317- self.assertThat(photogrid_view.visible, Eventually(Equals(True)))
318+
319+ super(TestCameraGalleryViewWithPhoto, self).setUp()
320+ self.assertThat(
321+ self.main_window.get_qml_view().visible, Eventually(Equals(True)))
322+
323+ def tearDown(self):
324+ super(TestCameraGalleryViewWithPhoto, self).tearDown()
325
326 """Test deleting photo from multiselection"""
327 def test_delete_photo_from_multiselection(self):
328- self.delete_all_media()
329- self.add_sample_photo()
330 self.main_window.swipe_to_gallery(self)
331 self.move_from_slideshow_to_photogrid()
332 self.select_first_photo()
333@@ -197,3 +169,21 @@
334
335 hint = self.main_window.get_no_media_hint()
336 self.assertThat(hint.visible, Eventually(Equals(True)))
337+
338+ """Tests entering/leaving multiselection mode in the photogrid view"""
339+ def test_multiselection_mode(self):
340+ self.main_window.swipe_to_gallery(self)
341+ self.move_from_slideshow_to_photogrid()
342+ self.select_first_photo()
343+
344+ # exit the multiselection mode
345+ gallery = self.main_window.get_gallery()
346+ back_button = gallery.wait_select_single(objectName="backButton")
347+ self.pointing_device.move_to_object(back_button)
348+ self.pointing_device.click()
349+
350+ slideshow_view = gallery.wait_select_single("SlideshowView")
351+ photogrid_view = gallery.wait_select_single("PhotogridView")
352+
353+ self.assertThat(slideshow_view.visible, Eventually(Equals(False)))
354+ self.assertThat(photogrid_view.visible, Eventually(Equals(True)))
355
356=== modified file 'tests/autopilot/camera_app/tests/test_photo_editor.py'
357--- tests/autopilot/camera_app/tests/test_photo_editor.py 2014-12-16 13:26:28 +0000
358+++ tests/autopilot/camera_app/tests/test_photo_editor.py 2015-03-11 09:25:45 +0000
359@@ -18,49 +18,23 @@
360 from time import sleep
361
362
363-class TestCameraPhotoEditor(CameraAppTestCase):
364- """Tests the main camera features"""
365+class TestCameraPhotoEditorWithPhoto(CameraAppTestCase):
366+ """Tests photo editor when a photo is present"""
367
368- """ This is needed to wait for the application to start.
369- In the testfarm, the application may take some time to show up."""
370 def setUp(self):
371- super(TestCameraPhotoEditor, self).setUp()
372+ self.delete_all_media()
373+ self.add_sample_photo()
374+
375+ super(TestCameraPhotoEditorWithPhoto, self).setUp()
376 self.assertThat(
377 self.main_window.get_qml_view().visible, Eventually(Equals(True)))
378- self.pictures_dir = os.path.expanduser("~/Pictures/com.ubuntu.camera")
379- self.videos_dir = os.path.expanduser("~/Videos/com.ubuntu.camera")
380
381 def tearDown(self):
382- super(TestCameraPhotoEditor, self).tearDown()
383-
384- def delete_all_media(self):
385- picture_files = os.listdir(self.pictures_dir)
386- for f in picture_files:
387- os.remove(os.path.join(self.pictures_dir, f))
388-
389- video_files = os.listdir(self.videos_dir)
390- for f in video_files:
391- os.remove(os.path.join(self.videos_dir, f))
392-
393- def add_sample_photo(self):
394- # add a fake photo to pictures_dir
395- photo_path = os.path.join(self.pictures_dir, "fake_photo.jpg")
396- with open(photo_path, 'a'):
397- os.utime(photo_path, None)
398-
399- def select_first_photo(self):
400- # select the first photo
401- gallery = self.main_window.get_gallery()
402- photo = gallery.wait_select_single(objectName="mediaItem0")
403- self.pointing_device.move_to_object(photo)
404-
405- # do a long press to enter Multiselection mode
406- self.pointing_device.press()
407- sleep(1)
408- self.pointing_device.release()
409-
410- """Tests swiping to the gallery and pressing the back button"""
411+ super(TestCameraPhotoEditorWithPhoto, self).tearDown()
412+
413+ """Tests editor opening and closing correctly for pictures"""
414 def test_editor_appears(self):
415+
416 viewfinder = self.main_window.get_viewfinder()
417 gallery = self.main_window.get_gallery()
418
419@@ -73,7 +47,15 @@
420 self.pointing_device.move_to_object(opt)
421 self.pointing_device.click()
422
423- edit = gallery.wait_select_single(objectName="actionButtonEdit")
424+ # If the editor button is not there when in the gallery view, then
425+ # we are not on a system that has the UI extras package installed or has
426+ # an older version than the one we need. Skip the test in this case.
427+ try:
428+ edit = gallery.wait_select_single(objectName="actionButtonEdit")
429+ except:
430+ return
431+
432+ self.assertThat(edit.enabled, Eventually(Equals(True)))
433 self.pointing_device.move_to_object(edit)
434 self.pointing_device.click()
435
436@@ -98,3 +80,43 @@
437 except StateNotFoundError:
438 disappeared = True
439 self.assertThat(disappeared, Equals(True))
440+
441+class TestCameraPhotoEditorWithVideo(CameraAppTestCase):
442+ """Tests photo editor when a video is present"""
443+
444+ def setUp(self):
445+ self.delete_all_media()
446+ self.add_sample_video()
447+
448+ super(TestCameraPhotoEditorWithVideo, self).setUp()
449+ self.assertThat(
450+ self.main_window.get_qml_view().visible, Eventually(Equals(True)))
451+
452+ def tearDown(self):
453+ super(TestCameraPhotoEditorWithVideo, self).tearDown()
454+
455+ """Tests editor not being available for videos"""
456+ def test_editor_not_on_videos(self):
457+ self.add_sample_video()
458+
459+ viewfinder = self.main_window.get_viewfinder()
460+ gallery = self.main_window.get_gallery()
461+
462+ self.main_window.swipe_to_gallery(self)
463+
464+ self.assertThat(gallery.inView, Eventually(Equals(True)))
465+
466+ # open actions drawer
467+ opt = gallery.wait_select_single(objectName="additionalActionsButton")
468+ self.pointing_device.move_to_object(opt)
469+ self.pointing_device.click()
470+
471+ # If the editor button is not there when in the gallery view, then
472+ # we are not on a system that has the UI extras package installed or has
473+ # an older version than the one we need. Skip the test in this case.
474+ try:
475+ edit = gallery.wait_select_single(objectName="actionButtonEdit")
476+ except:
477+ return
478+
479+ self.assertThat(edit.enabled, Equals(False))

Subscribers

People subscribed via source and target branches