Merge lp:~vrruiz/gallery-app/autopilot-app-class into lp:gallery-app

Proposed by Víctor R. Ruiz
Status: Needs review
Proposed branch: lp:~vrruiz/gallery-app/autopilot-app-class
Merge into: lp:gallery-app
Diff against target: 2084 lines (+720/-698)
9 files modified
tests/autopilot/gallery_app/__init__.py (+415/-0)
tests/autopilot/gallery_app/tests/__init__.py (+6/-280)
tests/autopilot/gallery_app/tests/test_album_editor.py (+34/-54)
tests/autopilot/gallery_app/tests/test_album_view.py (+55/-56)
tests/autopilot/gallery_app/tests/test_albums_view.py (+11/-19)
tests/autopilot/gallery_app/tests/test_events_view.py (+41/-53)
tests/autopilot/gallery_app/tests/test_photo_viewer.py (+102/-156)
tests/autopilot/gallery_app/tests/test_photos_view.py (+35/-48)
tests/autopilot/gallery_app/tests/test_picker_mode.py (+21/-32)
To merge this branch: bzr merge lp:~vrruiz/gallery-app/autopilot-app-class
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Leo Arias (community) Needs Fixing
Review via email: mp+222667@code.launchpad.net

Commit message

Create a class to drive the UI, and refactor test cases to use it.

Description of the change

Create a class to drive the UI, and refactor test cases to use it.

To post a comment you must log in.
Revision history for this message
Víctor R. Ruiz (vrruiz) wrote :

One thing to think about: the UI-driver methods were moved from the case classes to GalleryApp. The problem is that some of them use asserts, that make sense as part of tests, but not so much a pure UI test. Right now, it's not a big deal, because the test_case is a required argument to instantiate GalleryApp, but in the medium term, we won't have it.

Revision history for this message
Víctor R. Ruiz (vrruiz) wrote :

Another comment. The code is a not as elegant as it could be: lots of direct calls to the UI in the test cases. They probably can be refactored, but that wasn't the target of the present changes.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Leo Arias (elopio) wrote :

> One thing to think about: the UI-driver methods were moved from the case
> classes to GalleryApp. The problem is that some of them use asserts, that make
> sense as part of tests, but not so much a pure UI test. Right now, it's not a
> big deal, because the test_case is a required argument to instantiate
> GalleryApp, but in the medium term, we won't have it.

I think that's just what we want, move the assertions out of the helpers and into the tests.
Many assertions can be replaced by wait_for.

Revision history for this message
Leo Arias (elopio) wrote :

Victor, I'm sorry it took so long to make this review. You will likely have to merge with trunk now.
I'll try harder to make the reviews the same day. But next time I won't make soon a review you request please keep pinging me. I'll owe you a beer for every day you wait :)

For the gallery and apps developers: this change seeks to make it easier for us to test multiple applications at the same time. On its own, it just seems like a huge branch not really useful, and now you will have to call something like self.app.main_view instead of just self.main_view. But it makes a lot of sense when you see a test like this:

address_book = AddressBook.launch()
add_contact_page = address_book.main_view.go_to_add_contact()
add_contact_page.click_contact_image()
gallery_app = GalleryApp()
gallery_app.main_view.pick_image(...)
add_contact_page.main_view.fill_form(...)
add_contact_page.save()

For that we need to move the app helpers out of the test cases because there's no nice way to make a test case that inherits from both the base test cases in address book and gallery.

review: Needs Fixing
Revision history for this message
Leo Arias (elopio) wrote :

Sorry, about the comment:
This empty line is not needed.

I mean, the line between

from pkg_resources import resource_filename

and

from ubuntuuitoolkit import emulators as toolkit_emulators.

999. By Víctor R. Ruiz

Merge with trunk

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

Unmerged revisions

999. By Víctor R. Ruiz

Merge with trunk

998. By Víctor R. Ruiz

Autopilot: Refactor for app class pattern (test_picker_mode)

997. By Víctor R. Ruiz

Autopilot: Refactor for app class pattern (test_photos_view)

996. By Víctor R. Ruiz

Autopilot: Refactor for app class pattern (test_photo_viewer)

995. By Víctor R. Ruiz

Autopilot: Refactor for app class pattern (test_events_view)

994. By Víctor R. Ruiz

Autopilot: Refactor for app class pattern (test_album_view)

993. By Víctor R. Ruiz

Autopilot: Refactor for app class pattern (test_albums_view)

992. By Víctor R. Ruiz

Autopilot: Refactor for app class pattern (test_albums_view)

991. By Víctor R. Ruiz

Autopilot: Refactor for app class pattern (test_album_editor)

990. By Víctor R. Ruiz

Autopilot: Refactoring for app class pattern

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/autopilot/gallery_app/__init__.py'
--- tests/autopilot/gallery_app/__init__.py 2013-03-19 13:04:59 +0000
+++ tests/autopilot/gallery_app/__init__.py 2014-07-02 14:17:44 +0000
@@ -6,3 +6,418 @@
6# by the Free Software Foundation.6# by the Free Software Foundation.
77
8"""Autopilot tests and emulators for gallery - top level package."""8"""Autopilot tests and emulators for gallery - top level package."""
9
10import os
11import logging
12import shutil
13import signal
14
15from time import sleep
16
17from testtools.matchers import Equals, NotEquals, GreaterThan, Is
18from autopilot.matchers import Eventually
19from autopilot.platform import model
20from autopilot.introspection import get_proxy_object_for_existing_process
21from pkg_resources import resource_filename
22
23from ubuntuuitoolkit import emulators as toolkit_emulators
24
25from gallery_app.emulators import main_screen
26from gallery_app.emulators.album_editor import AlbumEditor
27from gallery_app.emulators.album_view import AlbumView
28from gallery_app.emulators.albums_view import AlbumsView
29from gallery_app.emulators.events_view import EventsView
30from gallery_app.emulators.gallery_utils import GalleryUtils
31from gallery_app.emulators.media_selector import MediaSelector
32from gallery_app.emulators.media_viewer import MediaViewer
33from gallery_app.emulators.photo_viewer import PhotoViewer
34from gallery_app.emulators.photos_view import PhotosView
35from gallery_app.emulators.picker_screen import PickerScreen
36
37logger = logging.getLogger(__name__)
38
39
40class EnvironmentTypes:
41 installed = "installed"
42 local = "local"
43 click = "click"
44
45
46class GalleryApp():
47 """A class to drive the UI of the gallery-app."""
48
49 sample_file_source = "/sample01.jpg"
50 local_location = "../src/gallery-app"
51 tap_press_time = 1
52
53 _db = '~/.local/share/com.ubuntu.gallery/gallery-app/' \
54 'database/gallery.sqlite'
55 _thumbs = '~/.cache/com.ubuntu.gallery/gallery-app/thumbnails'
56
57 _default_sample_destination_dir = "/tmp/gallery-ap_sd"
58 sample_destination_dir = ""
59
60 args = []
61 app = None
62
63 def __init__(self, test_case, args=[]):
64 """Constructor
65
66 :param test_case: An AutopilotTestCase object. This is required
67 to be able to launch the application.
68
69 """
70 # Start app
71 self.args = args
72 self.test_case = test_case
73 env_type = self._get_environment_launch_type()
74 self.configure_sample_files(env_type)
75 self.launch_gallery_app(env_type)
76
77 def __del__(self):
78 """Destructor"""
79 shutil.rmtree(self.sample_destination_dir)
80
81 @property
82 def gallery_utils(self):
83 return GalleryUtils(self.app)
84
85 @property
86 def main_view(self):
87 return self.app.select_single(main_screen.MainScreen)
88
89 @property
90 def album_editor(self):
91 return self.app.select_single(AlbumEditor)
92
93 @property
94 def album_view(self):
95 return AlbumView(self.app)
96
97 @property
98 def albums_view(self):
99 return AlbumsView(self.app)
100
101 @property
102 def events_view(self):
103 return EventsView(self.app)
104
105 @property
106 def media_selector(self):
107 return MediaSelector(self.app)
108
109 @property
110 def media_view(self):
111 return self.app.select_single(MediaViewer)
112
113 @property
114 def photo_viewer(self):
115 return PhotoViewer(self.app)
116
117 @property
118 def photos_view(self):
119 return PhotosView(self.app)
120
121 @property
122 def picker_view(self):
123 return self.app.select_single(PickerScreen)
124
125 def _get_environment_launch_type(self):
126 """Returns the type of the environment in which to setup and launch
127 gallery-app.
128
129 """
130 # Lets assume we are installed system wide if this file is somewhere
131 # in /usr
132 if os.path.realpath(__file__).startswith("/usr/"):
133 return EnvironmentTypes.installed
134 if model() == 'Desktop':
135 return EnvironmentTypes.installed
136 else:
137 if os.path.exists(self.local_location):
138 return EnvironmentTypes.local
139 else:
140 return EnvironmentTypes.click
141
142 def _get_sample_destination_dir(self, env_type):
143 if env_type == EnvironmentTypes.click:
144 pic_dir = os.path.expanduser("~/Pictures")
145 pic_bak_dir = pic_dir + '.apbak'
146 # Only save and restore if it previously existed
147 if os.path.exists(pic_dir):
148 shutil.move(pic_dir, pic_bak_dir)
149 self.addCleanup(
150 logger.debug, "Restoring backed up pics to %s" % pic_dir)
151 self.addCleanup(shutil.move, pic_bak_dir, pic_dir)
152 return pic_dir
153 else:
154 return self._default_sample_destination_dir
155
156 def configure_db(self):
157 db = os.path.expanduser(self._db)
158 db_bak = db + '.apbak'
159 # Only save and restore if it previously existed
160 if os.path.exists(db):
161 shutil.move(db, db_bak)
162 self.addCleanup(shutil.move, db_bak, db)
163 if not os.path.exists(os.path.dirname(db)):
164 os.makedirs(os.path.dirname(db))
165 mock_db = os.path.join(self.sample_destination_dir, '.database',
166 'gallery_confined.sqlite')
167 shutil.move(mock_db, db)
168
169 def configure_thumbnails(self):
170 thumbs = os.path.expanduser(self._thumbs)
171 thumbs_bak = thumbs + '.apbak'
172 # Only save and restore if it previously existed
173 if os.path.exists(thumbs):
174 shutil.move(thumbs, thumbs_bak)
175 self.addCleanup(shutil.move, thumbs_bak, thumbs)
176 if not os.path.exists(os.path.dirname(thumbs)):
177 os.makedirs(os.path.dirname(thumbs))
178 mock_thumbs = os.path.join(self.sample_destination_dir, '.thumbnails')
179 shutil.move(mock_thumbs, thumbs)
180
181 def configure_sample_files(self, env_type):
182 self.sample_dir = resource_filename('gallery_app', 'data')
183 self.sample_destination_dir = \
184 self._get_sample_destination_dir(env_type)
185 if (os.path.exists(self.sample_destination_dir)):
186 shutil.rmtree(self.sample_destination_dir)
187 ## FIXME self.assertFalse(os.path.exists(self.sample_destination_dir))
188
189 self.sample_file = os.path.join(
190 self.sample_destination_dir,
191 "sample04.jpg"
192 )
193
194 default_data_dir = os.path.join(
195 self.sample_dir,
196 "default")
197 shutil.copytree(default_data_dir, self.sample_destination_dir)
198 ## FIXME self.assertTrue(os.path.isfile(self.sample_file))
199
200 self.sample_file_source = \
201 default_data_dir + self.sample_file_source
202
203 if env_type == EnvironmentTypes.click:
204 self.configure_db()
205 self.configure_thumbnails()
206
207 def do_reset_config(self):
208 config = os.path.expanduser(
209 os.path.join("~", ".config", "gallery-app.conf"))
210 if os.path.exists(config):
211 os.remove(config)
212
213 @property
214 def pointing_device(self):
215 """Return pointing device"""
216 return toolkit_emulators.get_pointing_device()
217
218 def launch_gallery_app(self, env_type):
219 """Launch"""
220 if env_type == EnvironmentTypes.installed:
221 self.launch_test_installed()
222 elif env_type == EnvironmentTypes.local:
223 self.launch_test_local()
224 elif env_type == EnvironmentTypes.click:
225 self.launch_test_click()
226 else:
227 raise ValueError("Unknown environment type: %s", env_type)
228
229 def launch_test_local(self):
230 logger.debug("Launching local gallery-app binary.")
231 self.args.append(self.sample_destination_dir)
232 self.app = self.test_case.launch_test_application(
233 self.local_location,
234 *self.args,
235 emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
236
237 def launch_test_installed(self):
238 if model() == 'Desktop':
239 logger.debug(
240 "Launching installed gallery-app binary for desktop."
241 )
242 self.args.append(self.sample_destination_dir)
243 self.app = self.test_case.launch_test_application(
244 "gallery-app",
245 *self.args,
246 emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
247 else:
248 logger.debug(
249 "Launching installed gallery-app binary for device."
250 )
251 self.args.append("--desktop_file_hint="
252 "/usr/share/applications/gallery-app.desktop")
253 self.args.append(self.sample_destination_dir)
254 self.app = self.test_case.launch_test_application(
255 "gallery-app",
256 *self.args,
257 app_type='qt',
258 emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
259
260 def launch_test_click(self):
261 """
262 Since this test runs under confinement, the only location photos
263 are searchable in is ~/Pictures.
264 """
265 logger.debug("Launching gallery-app via click package.")
266 self.app = self.test_case.launch_click_package(
267 package_id="com.ubuntu.gallery",
268 app_uris=' '.join(self.args),
269 emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
270
271 def ui_update(self):
272 """ Gives the program the time to update the UI"""
273 sleep(0.1)
274
275 def click_item(self, item, delay=0.1):
276 """Does a mouse click on the passed item, and moved the mouse there
277 before"""
278 # In jenkins test may fail because we don't wait before clicking the
279 # target so we add a little delay before click.
280 if model() == 'Desktop' and delay <= 0.25:
281 delay = 0.25
282
283 self.pointing_device.move_to_object(item)
284 sleep(delay)
285 self.pointing_device.click()
286
287 def tap_item(self, item):
288 """Does a long mouse press on the passed item, and moved the mouse
289 there before"""
290 self.pointing_device.move_to_object(item)
291 self.pointing_device.press()
292 sleep(1)
293 self.pointing_device.release()
294
295 def switch_to_albums_tab(self):
296 self.main_view.switch_to_tab("albumsTab")
297
298 albums_loader = self.gallery_utils.get_albums_viewer_loader()
299 self.test_case.assertThat(albums_loader.progress, Eventually(Equals(1)))
300
301 # The next check assumes that at least one album is available
302 # Check if the albums are availabe - they need some time to load.
303 self.test_case.assertThat(lambda: len(self.gallery_utils.get_all_albums()),
304 Eventually(GreaterThan(0)))
305 self.ensure_tabs_dont_move()
306
307 def ensure_tabs_dont_move(self):
308 # FIXME find a (functional) way to test if the tabs still move
309 sleep(1)
310
311 def open_album_at(self, position):
312 album = self.album_view.get_album_at(position)
313 # workaround lp:1247698
314 self.main_view.close_toolbar()
315 self.click_item(album)
316 self.ensure_view_is_fully_open()
317
318 def open_first_album(self):
319 self.open_album_at(-1)
320
321 def get_delete_dialog(self):
322 """Raises StateNotFoundError if get_delete_dialog fails."""
323 delete_dialog = self.gallery_utils.get_delete_dialog()
324 return delete_dialog
325
326 def edit_first_album(self):
327 """Edit first album."""
328 first_album = self.gallery_utils.get_first_album()
329 # workaround lp:1247698
330 self.main_view.close_toolbar()
331 self.tap_item(first_album)
332 edit_button = self.gallery_utils.get_edit_album_button()
333 self.click_item(edit_button)
334
335 def ensure_view_is_fully_open(self):
336 view = self.album_view.get_album_view()
337 self.test_case.assertThat(view.visible, Eventually(Equals(True)))
338
339 def ensure_app_has_quit(self):
340 """Terminate as gracefully as possible the application and ensure
341 that it has fully quit before returning"""
342
343 if model() == "Desktop":
344 # On desktop to cleanly quit an app we just do the
345 # equivalent of clicking on the close button in the window.
346 self.keyboard.press_and_release("Alt+F4")
347 else:
348 # On unity8 at the moment we have no clean way to close the app.
349 # So we ask the shell first to show the home, unfocusing our app,
350 # which will save its state. Then we simply send it a SIGTERM to
351 # force it to quit.
352 # See bug https://bugs.launchpad.net/unity8/+bug/1261720 for more
353 # details.
354 from unity8 import process_helpers
355 pid = process_helpers._get_unity_pid()
356 unity8 = get_proxy_object_for_existing_process(pid)
357 shell = unity8.select_single("Shell")
358 shell.slots.showHome()
359 self.test_case.assertThat(shell.currentFocusedAppId,
360 Eventually(NotEquals("gallery-app"))) # FIXME
361 self.app.process.send_signal(signal.SIGTERM)
362
363 # Either way, we wait for the underlying process to be fully finished.
364 self.app.process.wait()
365 self.test_case.assertIsNotNone(self.app.process.returncode) # FIXME
366
367 def get_events_view(self):
368 return self.app.wait_select_single("EventsOverview",
369 objectName="organicEventView")
370
371 def enable_select_mode(self):
372 self.main_view.open_toolbar().click_button("selectButton")
373
374 def delete_one_picture(self):
375 self.main_view.open_toolbar().click_button("deleteButton")
376 self.get_delete_dialog()
377 delete_item = self.photo_viewer.get_delete_popover_delete_item()
378 self.click_item(delete_item)
379 self.ensure_closed_delete_dialog()
380
381 def open_first_photo(self):
382 self.test_case.assertThat(
383 lambda: self.events_view.number_of_photos_in_events(),
384 Eventually(GreaterThan(0))
385 )
386
387 # workaround lp:1247698
388 # toolbar needs to be gone to click on an image.
389 self.main_view.close_toolbar()
390
391 self.events_view.click_photo(self.sample_file)
392
393 photo_viewer_loader = self.photo_viewer.get_main_photo_viewer_loader()
394 self.test_case.assertThat(photo_viewer_loader.loaded, Eventually(Equals(True)))
395 sleep(1)
396 photo_viewer = self.photo_viewer.get_main_photo_viewer()
397 self.test_case.assertThat(photo_viewer.visible, Eventually(Equals(True)))
398
399 def ensure_closed_delete_dialog(self):
400 self.test_case.assertThat(self.photo_viewer.delete_dialog_shown,
401 Eventually(Is(False)))
402
403 def click_edit_button(self):
404 self.main_view.open_toolbar().click_button("editButton")
405 edit_dialog = self.photo_viewer.get_photo_edit_dialog()
406 self.test_case.assertThat(edit_dialog.visible, (Eventually(Equals(True))))
407 self.test_case.assertThat(edit_dialog.opacity, (Eventually(Equals(1))))
408
409 def switch_to_photos_tab(self):
410 self.main_view.switch_to_tab("photosTab")
411 self.ensure_tabs_dont_move()
412
413 def click_first_photo(self):
414 photo = self.photos_view.get_first_photo_in_photos_view()
415 self.click_item(photo)
416
417 def select_first_event_media(self):
418 first_media = self.picker_view.first_media_in_events_view()
419 self.click_item(first_media)
420
421 def select_first_grid_media(self):
422 first_media = self.picker_view.first_media_in_events_view()
423 self.click_item(first_media)
9424
=== modified file 'tests/autopilot/gallery_app/tests/__init__.py'
--- tests/autopilot/gallery_app/tests/__init__.py 2014-06-10 18:54:21 +0000
+++ tests/autopilot/gallery_app/tests/__init__.py 2014-07-02 14:17:44 +0000
@@ -7,304 +7,30 @@
77
8"""gallery autopilot tests."""8"""gallery autopilot tests."""
99
10import os10from time import sleep
11import logging
12import shutil
13import signal
1411
15from testtools.matchers import Equals, NotEquals, GreaterThan12from testtools.matchers import Equals
16from autopilot.matchers import Eventually13from autopilot.matchers import Eventually
17from autopilot.platform import model
18from autopilot.testcase import AutopilotTestCase14from autopilot.testcase import AutopilotTestCase
19from autopilot.introspection import get_proxy_object_for_existing_process15
20from pkg_resources import resource_filename16from gallery_app import GalleryApp
21
22from ubuntuuitoolkit import emulators as toolkit_emulators
23from gallery_app.emulators import main_screen
24from gallery_app.emulators.gallery_utils import GalleryUtils
25
26from time import sleep
27
28logger = logging.getLogger(__name__)
29
30
31class EnvironmentTypes:
32 installed = "installed"
33 local = "local"
34 click = "click"
3517
3618
37class GalleryTestCase(AutopilotTestCase):19class GalleryTestCase(AutopilotTestCase):
38
39 """A common test case class that provides several useful methods for20 """A common test case class that provides several useful methods for
40 gallery tests."""21 gallery tests."""
4122
42 sample_file_source = "/sample01.jpg"
43 tap_press_time = 1
44 local_location = "../../src/gallery-app"
45
46 _db = '~/.local/share/com.ubuntu.gallery/gallery-app/' \
47 'database/gallery.sqlite'
48 _thumbs = '~/.cache/com.ubuntu.gallery/gallery-app/thumbnails'
49
50 _default_sample_destination_dir = "/tmp/gallery-ap_sd"
51
52 ARGS = []23 ARGS = []
5324
54 @property
55 def gallery_utils(self):
56 return GalleryUtils(self.app)
57
58 @property
59 def main_view(self):
60 return self.app.select_single(main_screen.MainScreen)
61
62 def _get_environment_launch_type(self):
63 """Returns the type of the environment in which to setup and launch
64 gallery-app.
65
66 """
67 # Lets assume we are installed system wide if this file is somewhere
68 # in /usr
69 if os.path.realpath(__file__).startswith("/usr/"):
70 return EnvironmentTypes.installed
71 if model() == 'Desktop':
72 return EnvironmentTypes.installed
73 else:
74 if os.path.exists(self.local_location):
75 return EnvironmentTypes.local
76 else:
77 return EnvironmentTypes.click
78
79 def _get_sample_destination_dir(self, env_type):
80 if env_type == EnvironmentTypes.click:
81 pic_dir = os.path.expanduser("~/Pictures")
82 pic_bak_dir = pic_dir + '.apbak'
83 # Only save and restore if it previously existed
84 if os.path.exists(pic_dir):
85 shutil.move(pic_dir, pic_bak_dir)
86 self.addCleanup(
87 logger.debug, "Restoring backed up pics to %s" % pic_dir)
88 self.addCleanup(shutil.move, pic_bak_dir, pic_dir)
89 return pic_dir
90 else:
91 return self._default_sample_destination_dir
92
93 def configure_db(self):
94 db = os.path.expanduser(self._db)
95 db_bak = db + '.apbak'
96 # Only save and restore if it previously existed
97 if os.path.exists(db):
98 shutil.move(db, db_bak)
99 self.addCleanup(shutil.move, db_bak, db)
100 if not os.path.exists(os.path.dirname(db)):
101 os.makedirs(os.path.dirname(db))
102 mock_db = os.path.join(self.sample_destination_dir, '.database',
103 'gallery_confined.sqlite')
104 shutil.move(mock_db, db)
105
106 def configure_thumbnails(self):
107 thumbs = os.path.expanduser(self._thumbs)
108 thumbs_bak = thumbs + '.apbak'
109 # Only save and restore if it previously existed
110 if os.path.exists(thumbs):
111 shutil.move(thumbs, thumbs_bak)
112 self.addCleanup(shutil.move, thumbs_bak, thumbs)
113 if not os.path.exists(os.path.dirname(thumbs)):
114 os.makedirs(os.path.dirname(thumbs))
115 mock_thumbs = os.path.join(self.sample_destination_dir, '.thumbnails')
116 shutil.move(mock_thumbs, thumbs)
117
118 def configure_sample_files(self, env_type):
119 self.sample_dir = resource_filename('gallery_app', 'data')
120 self.sample_destination_dir = \
121 self._get_sample_destination_dir(env_type)
122 if (os.path.exists(self.sample_destination_dir)):
123 shutil.rmtree(self.sample_destination_dir)
124 self.assertFalse(os.path.exists(self.sample_destination_dir))
125
126 self.sample_file = os.path.join(
127 self.sample_destination_dir,
128 "sample04.jpg"
129 )
130
131 default_data_dir = os.path.join(
132 self.sample_dir,
133 "default")
134 shutil.copytree(default_data_dir, self.sample_destination_dir)
135 self.assertTrue(os.path.isfile(self.sample_file))
136
137 self.sample_file_source = \
138 default_data_dir + self.sample_file_source
139
140 if env_type == EnvironmentTypes.click:
141 self.configure_db()
142 self.configure_thumbnails()
143
144 def do_reset_config(self):
145 config = os.path.expanduser(
146 os.path.join("~", ".config", "gallery-app.conf"))
147 if os.path.exists(config):
148 os.remove(config)
149
150 def setUp(self):25 def setUp(self):
151 self.pointing_device = toolkit_emulators.get_pointing_device()
152 super(GalleryTestCase, self).setUp()26 super(GalleryTestCase, self).setUp()
15327
154 env_type = self._get_environment_launch_type()28 self.gallery_app = GalleryApp(self, self.ARGS)
155 self.configure_sample_files(env_type)
156
157 self.launch_gallery_app(env_type)
158
159 self.addCleanup(shutil.rmtree, self.sample_destination_dir)
160 self.addCleanup(logger.debug,
161 "Deleting %s" % self.sample_destination_dir)
16229
163 """ This is needed to wait for the application to start.30 """ This is needed to wait for the application to start.
164 In the testfarm, the application may take some time to show up."""31 In the testfarm, the application may take some time to show up."""
165 self.assertThat(self.gallery_utils.get_qml_view().visible,32 self.assertThat(self.gallery_app.gallery_utils.get_qml_view().visible,
166 Eventually(Equals(True)))33 Eventually(Equals(True)))
167 """FIXME somehow on the server gallery sometimes is not fully started34 """FIXME somehow on the server gallery sometimes is not fully started
168 for switching to the albums view. Therefore this hack of sleeping"""35 for switching to the albums view. Therefore this hack of sleeping"""
169 sleep(2)36 sleep(2)
170
171 def launch_gallery_app(self, env_type):
172 if env_type == EnvironmentTypes.installed:
173 self.launch_test_installed()
174 elif env_type == EnvironmentTypes.local:
175 self.launch_test_local()
176 elif env_type == EnvironmentTypes.click:
177 self.launch_test_click()
178 else:
179 raise ValueError("Unknown environment type: %s", env_type)
180
181 def launch_test_local(self):
182 logger.debug("Launching local gallery-app binary.")
183 self.ARGS.append(self.sample_destination_dir)
184 self.app = self.launch_test_application(
185 self.local_location,
186 *self.ARGS,
187 emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
188
189 def launch_test_installed(self):
190 if model() == 'Desktop':
191 logger.debug(
192 "Launching installed gallery-app binary for desktop."
193 )
194 self.ARGS.append(self.sample_destination_dir)
195 self.app = self.launch_test_application(
196 "gallery-app",
197 *self.ARGS,
198 emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
199 else:
200 logger.debug(
201 "Launching installed gallery-app binary for device."
202 )
203 self.ARGS.append("--desktop_file_hint="
204 "/usr/share/applications/gallery-app.desktop")
205 self.ARGS.append(self.sample_destination_dir)
206 self.app = self.launch_test_application(
207 "gallery-app",
208 *self.ARGS,
209 app_type='qt',
210 emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
211
212 def launch_test_click(self):
213 '''
214 Since this test runs under confinement, the only location photos
215 are searchable in is ~/Pictures.
216 '''
217 logger.debug("Launching gallery-app via click package.")
218 self.app = self.launch_click_package(
219 package_id="com.ubuntu.gallery",
220 app_uris=' '.join(self.ARGS),
221 emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
222
223 def ui_update(self):
224 """ Gives the program the time to update the UI"""
225 sleep(0.1)
226
227 def click_item(self, item, delay=0.1):
228 """Does a mouse click on the passed item, and moved the mouse there
229 before"""
230 # In jenkins test may fail because we don't wait before clicking the
231 # target so we add a little delay before click.
232 if model() == 'Desktop' and delay <= 0.25:
233 delay = 0.25
234
235 self.pointing_device.move_to_object(item)
236 sleep(delay)
237 self.pointing_device.click()
238
239 def tap_item(self, item):
240 """Does a long mouse press on the passed item, and moved the mouse
241 there before"""
242 self.pointing_device.move_to_object(item)
243 self.pointing_device.press()
244 sleep(1)
245 self.pointing_device.release()
246
247 def switch_to_albums_tab(self):
248 self.main_view.switch_to_tab("albumsTab")
249
250 albums_loader = self.gallery_utils.get_albums_viewer_loader()
251 self.assertThat(albums_loader.progress, Eventually(Equals(1)))
252
253 # The next check assumes that at least one album is available
254 # Check if the albums are availabe - they need some time to load.
255 self.assertThat(lambda: len(self.gallery_utils.get_all_albums()),
256 Eventually(GreaterThan(0)))
257 self.ensure_tabs_dont_move()
258
259 def ensure_tabs_dont_move(self):
260 # FIXME find a (functional) way to test if the tabs still move
261 sleep(1)
262
263 def open_album_at(self, position):
264 album = self.album_view.get_album_at(position)
265 # workaround lp:1247698
266 self.main_view.close_toolbar()
267 self.click_item(album)
268 self.ensure_view_is_fully_open()
269
270 def open_first_album(self):
271 self.open_album_at(-1)
272
273 def ensure_view_is_fully_open(self):
274 view = self.album_view.get_album_view()
275 self.assertThat(view.visible, Eventually(Equals(True)))
276
277 def ensure_app_has_quit(self):
278 """Terminate as gracefully as possible the application and ensure
279 that it has fully quit before returning"""
280
281 if model() == "Desktop":
282 # On desktop to cleanly quit an app we just do the
283 # equivalent of clicking on the close button in the window.
284 self.keyboard.press_and_release("Alt+F4")
285 else:
286 # On unity8 at the moment we have no clean way to close the app.
287 # So we ask the shell first to show the home, unfocusing our app,
288 # which will save its state. Then we simply send it a SIGTERM to
289 # force it to quit.
290 # See bug https://bugs.launchpad.net/unity8/+bug/1261720 for more
291 # details.
292 from unity8 import process_helpers
293 pid = process_helpers._get_unity_pid()
294 unity8 = get_proxy_object_for_existing_process(pid)
295 shell = unity8.select_single("Shell")
296 shell.slots.showHome()
297 self.assertThat(shell.currentFocusedAppId,
298 Eventually(NotEquals("gallery-app")))
299 self.app.process.send_signal(signal.SIGTERM)
300
301 # Either way, we wait for the underlying process to be fully finished.
302 self.app.process.wait()
303 self.assertIsNotNone(self.app.process.returncode)
304
305 def get_delete_dialog(self):
306 """Raises StateNotFoundError if get_delete_dialog fails."""
307 delete_dialog = self.gallery_utils.get_delete_dialog()
308 self.assertThat(delete_dialog.visible, Eventually(Equals(True)))
309 self.assertThat(delete_dialog.opacity, Eventually(Equals(1)))
310 return delete_dialog
31137
=== modified file 'tests/autopilot/gallery_app/tests/test_album_editor.py'
--- tests/autopilot/gallery_app/tests/test_album_editor.py 2014-06-10 19:00:23 +0000
+++ tests/autopilot/gallery_app/tests/test_album_editor.py 2014-07-02 14:17:44 +0000
@@ -11,9 +11,7 @@
11from testtools.matchers import Equals11from testtools.matchers import Equals
12from autopilot.matchers import Eventually12from autopilot.matchers import Eventually
1313
14from gallery_app.emulators.album_view import AlbumView14from gallery_app import GalleryApp
15from gallery_app.emulators.media_selector import MediaSelector
16from gallery_app.emulators import album_editor
17from gallery_app.tests import GalleryTestCase15from gallery_app.tests import GalleryTestCase
1816
19from time import sleep17from time import sleep
@@ -21,34 +19,17 @@
21class TestAlbumEditor(GalleryTestCase):19class TestAlbumEditor(GalleryTestCase):
22 """Tests the album editor of the gallery app"""20 """Tests the album editor of the gallery app"""
2321
24 @property
25 def album_view(self):
26 return AlbumView(self.app)
27
28 @property
29 def media_selector(self):
30 return MediaSelector(self.app)
31
32 def setUp(self):22 def setUp(self):
33 self.ARGS = []
34 super(TestAlbumEditor, self).setUp()23 super(TestAlbumEditor, self).setUp()
35 self.switch_to_albums_tab()24 self.gallery_app.switch_to_albums_tab()
36 self.main_view.close_toolbar()25 self.gallery_app.main_view.close_toolbar()
37 self.edit_first_album()26 self.gallery_app.edit_first_album()
3827 editor = self.gallery_app.album_editor
39 def edit_first_album(self):
40 first_album = self.gallery_utils.get_first_album()
41 # workaround lp:1247698
42 self.main_view.close_toolbar()
43 self.tap_item(first_album)
44 edit_button = self.gallery_utils.get_edit_album_button()
45 self.click_item(edit_button)
46 editor = self.app.select_single(album_editor.AlbumEditor)
47 editor.ensure_fully_open()28 editor.ensure_fully_open()
4829
49 def test_album_title_fields(self):30 def test_album_title_fields(self):
50 """tests the title and sub title"""31 """tests the title and sub title"""
51 editor = self.app.select_single(album_editor.AlbumEditor)32 editor = self.gallery_app.album_editor
52 title_field = editor.album_title_entry_field()33 title_field = editor.album_title_entry_field()
53 subtitle_field = editor.album_subtitle_entry_field()34 subtitle_field = editor.album_subtitle_entry_field()
5435
@@ -59,7 +40,7 @@
59 self.assertThat(subtitle_field.text, Eventually(Equals(text)))40 self.assertThat(subtitle_field.text, Eventually(Equals(text)))
6041
61 # workaround lp:124769842 # workaround lp:1247698
62 self.main_view.close_toolbar()43 self.gallery_app.main_view.close_toolbar()
63 editor.click_title_field()44 editor.click_title_field()
64 self.assertThat(title_field.activeFocus, Eventually(Equals(True)))45 self.assertThat(title_field.activeFocus, Eventually(Equals(True)))
65 self.keyboard.press_and_release("Ctrl+a")46 self.keyboard.press_and_release("Ctrl+a")
@@ -80,61 +61,60 @@
80 def test_add_photo(self):61 def test_add_photo(self):
81 """Tests adding a photo using the media selector"""62 """Tests adding a photo using the media selector"""
82 # first open, but cancel before adding a photo63 # first open, but cancel before adding a photo
83 editor = self.app.select_single(album_editor.AlbumEditor)64 editor = self.gallery_app.album_editor
84 # workaround lp:124769865 # workaround lp:1247698
85 self.main_view.close_toolbar()66 self.gallery_app.main_view.close_toolbar()
86 editor.add_photos()67 editor.add_photos()
87 self.media_selector.ensure_fully_open()68 self.gallery_app.media_selector.ensure_fully_open()
8869
89 sleep(5)70 sleep(5)
90 self.main_view.get_toolbar().click_custom_button("cancelButton")71 self.gallery_app.main_view.get_toolbar().click_custom_button("cancelButton")
91 editor.ensure_fully_closed()72 editor.ensure_fully_closed()
9273
93 self.main_view.close_toolbar()74 self.gallery_app.main_view.close_toolbar()
94 self.open_first_album()75 self.gallery_app.open_first_album()
95 num_photos_start = self.album_view.number_of_photos()76 num_photos_start = self.gallery_app.album_view.number_of_photos()
96 self.assertThat(num_photos_start, Equals(1))77 self.assertThat(num_photos_start, Equals(1))
97 self.main_view.open_toolbar().click_button("backButton")78 self.gallery_app.main_view.open_toolbar().click_button("backButton")
98 self.album_view.ensure_album_view_fully_closed()79 self.gallery_app.album_view.ensure_album_view_fully_closed()
9980
100 # now open to add a photo81 # now open to add a photo
101 self.main_view.close_toolbar()82 self.gallery_app.main_view.close_toolbar()
102 self.edit_first_album()83 self.gallery_app.edit_first_album()
103 editor = self.app.select_single(album_editor.AlbumEditor)84 editor = self.gallery_app.album_editor
104 # workaround lp:124769885 # workaround lp:1247698
105 self.main_view.close_toolbar()86 self.gallery_app.main_view.close_toolbar()
106 editor.add_photos()87 self.gallery_app.album_editor.add_photos()
107 self.media_selector.ensure_fully_open()88 self.media_selector.ensure_fully_open()
10889
109 photo = self.media_selector.get_second_photo()90 photo = self.media_selector.get_second_photo()
110 self.click_item(photo)91 self.gallery_app.click_item(photo)
111 self.main_view.get_toolbar().click_custom_button("addButton")92 self.gallery_app.main_view.get_toolbar().click_custom_button("addButton")
112 editor = self.app.select_single(album_editor.AlbumEditor)93 self.gallery_app.album_editor.ensure_fully_closed()
113 editor.ensure_fully_closed()
11494
115 self.main_view.close_toolbar()95 self.gallery_app.main_view.close_toolbar()
116 self.open_first_album()96 self.gallery_app.open_first_album()
117 num_photos = self.album_view.number_of_photos()97 num_photos = self.gallery_app.album_view.number_of_photos()
118 self.assertThat(num_photos, Equals(num_photos_start + 1))98 self.assertThat(num_photos, Equals(num_photos_start + 1))
11999
120 def test_cover_image(self):100 def test_cover_image(self):
121 """Test to change the album cover image"""101 """Test to change the album cover image"""
122 editor = self.app.select_single(album_editor.AlbumEditor)102 editor = self.gallery_app.album_editor
123 cover_image = editor.album_cover_image()103 cover_image = editor.album_cover_image()
124 self.assertThat(104 self.assertThat(
125 cover_image.source.endswith("album-cover-default-large.png"),105 cover_image.source.endswith("album-cover-default-large.png"),
126 Equals(True))106 Equals(True))
127 self.main_view.close_toolbar()107 self.gallery_app.main_view.close_toolbar()
128108
129 # click somewhere rather at the bottom of the cover109 # click somewhere rather at the bottom of the cover
130 # workaround lp:1247698110 # workaround lp:1247698
131 self.main_view.close_toolbar()111 self.gallery_app.main_view.close_toolbar()
132 x, y, w, h = cover_image.globalRect112 x, y, w, h = cover_image.globalRect
133 self.pointing_device.move(x + int(w / 2), y + h - int(h / 10))113 self.gallery_app.pointing_device.move(x + int(w / 2), y + h - int(h / 10))
134 self.pointing_device.click()114 self.gallery_app.pointing_device.click()
135115
136 green_item = self.gallery_utils.get_cover_menu_item("Green")116 green_item = self.gallery_app.gallery_utils.get_cover_menu_item("Green")
137 self.click_item(green_item)117 self.gallery_app.click_item(green_item)
138118
139 self.assertThat(lambda: cover_image.source.endswith(119 self.assertThat(lambda: cover_image.source.endswith(
140 "album-cover-green-large.png"), Eventually(Equals(True)))120 "album-cover-green-large.png"), Eventually(Equals(True)))
141121
=== modified file 'tests/autopilot/gallery_app/tests/test_album_view.py'
--- tests/autopilot/gallery_app/tests/test_album_view.py 2014-06-12 16:42:04 +0000
+++ tests/autopilot/gallery_app/tests/test_album_view.py 2014-07-02 14:17:44 +0000
@@ -15,7 +15,6 @@
15from gallery_app.emulators.albums_view import AlbumsView15from gallery_app.emulators.albums_view import AlbumsView
16from gallery_app.emulators.media_selector import MediaSelector16from gallery_app.emulators.media_selector import MediaSelector
17from gallery_app.emulators.photo_viewer import PhotoViewer17from gallery_app.emulators.photo_viewer import PhotoViewer
18from gallery_app.emulators import album_editor
19from gallery_app.tests import GalleryTestCase18from gallery_app.tests import GalleryTestCase
2019
21import os20import os
@@ -43,72 +42,72 @@
43 return PhotoViewer(self.app)42 return PhotoViewer(self.app)
4443
45 def setUp(self):44 def setUp(self):
46 self.ARGS = []45 self.args = []
47 super(TestAlbumView, self).setUp()46 super(TestAlbumView, self).setUp()
48 self.switch_to_albums_tab()47 self.gallery_app.switch_to_albums_tab()
4948
50 def test_album_view_open_photo(self):49 def test_album_view_open_photo(self):
51 self.main_view.close_toolbar()50 self.gallery_app.main_view.close_toolbar()
52 self.open_first_album()51 self.gallery_app.open_first_album()
53 self.main_view.close_toolbar()52 self.gallery_app.main_view.close_toolbar()
54 photo = self.album_view.get_first_photo()53 photo = self.gallery_app.album_view.get_first_photo()
55 # workaround lp:124769854 # workaround lp:1247698
56 self.main_view.close_toolbar()55 self.gallery_app.main_view.close_toolbar()
57 self.click_item(photo)56 self.gallery_app.click_item(photo)
58 sleep(5)57 sleep(5)
59 photo_view = self.main_view.wait_select_single("PopupPhotoViewer")58 photo_view = self.gallery_app.main_view.wait_select_single("PopupPhotoViewer")
60 self.assertThat(photo_view.visible, Eventually(Equals(True)))59 self.assertThat(photo_view.visible, Eventually(Equals(True)))
6160
62 def test_album_view_flipping(self):61 def test_album_view_flipping(self):
63 self.main_view.close_toolbar()62 self.gallery_app.main_view.close_toolbar()
6463
65 # For some reason here the album at position 0 in the autopilot list is64 # For some reason here the album at position 0 in the autopilot list is
66 # actually the second album, they seem to be returned in reverse order.65 # actually the second album, they seem to be returned in reverse order.
67 self.open_album_at(0)66 self.gallery_app.open_album_at(0)
68 self.main_view.close_toolbar()67 self.gallery_app.main_view.close_toolbar()
6968
70 spread = self.album_view.get_spread_view()69 spread = self.gallery_app.album_view.get_spread_view()
7170
72 # check that we can page to the cover and back (we check for lesser71 # check that we can page to the cover and back (we check for lesser
73 # than 1 because it can either be 0 if we are on a one page spread72 # than 1 because it can either be 0 if we are on a one page spread
74 # or -1 if we are on a two page spread, for example on desktop)73 # or -1 if we are on a two page spread, for example on desktop)
75 self.album_view.swipe_page_left(1)74 self.gallery_app.album_view.swipe_page_left(1)
76 self.assertThat(spread.viewingPage, Eventually(LessThan(1)))75 self.assertThat(spread.viewingPage, Eventually(LessThan(1)))
77 self.album_view.swipe_page_right(0)76 self.gallery_app.album_view.swipe_page_right(0)
78 self.assertThat(spread.viewingPage, Eventually(Equals(1)))77 self.assertThat(spread.viewingPage, Eventually(Equals(1)))
7978
80 # drag to next page and check we have flipped away from page 179 # drag to next page and check we have flipped away from page 1
81 # can't check precisely for page 2 because depending on form factor80 # can't check precisely for page 2 because depending on form factor
82 # and orientation we might be displaying two pages at the same time81 # and orientation we might be displaying two pages at the same time
83 self.album_view.swipe_page_right(1)82 self.gallery_app.album_view.swipe_page_right(1)
84 self.assertThat(spread.viewingPage, Eventually(GreaterThan(1)))83 self.assertThat(spread.viewingPage, Eventually(GreaterThan(1)))
8584
86 def test_add_photo(self):85 def test_add_photo(self):
87 self.main_view.close_toolbar()86 self.gallery_app.main_view.close_toolbar()
88 self.open_first_album()87 self.gallery_app.open_first_album()
89 num_photos_start = self.album_view.number_of_photos()88 num_photos_start = self.gallery_app.album_view.number_of_photos()
90 self.assertThat(num_photos_start, Equals(1))89 self.assertThat(num_photos_start, Equals(1))
9190
92 # open media selector but cancel91 # open media selector but cancel
93 self.main_view.open_toolbar().click_button("addButton")92 self.gallery_app.main_view.open_toolbar().click_button("addButton")
94 self.media_selector.ensure_fully_open()93 self.gallery_app.media_selector.ensure_fully_open()
9594
96 self.main_view.get_toolbar().click_custom_button("cancelButton")95 self.gallery_app.main_view.get_toolbar().click_custom_button("cancelButton")
97 sleep(1)96 sleep(1)
9897
99 num_photos = self.album_view.number_of_photos()98 num_photos = self.gallery_app.album_view.number_of_photos()
100 self.assertThat(num_photos, Equals(num_photos_start))99 self.assertThat(num_photos, Equals(num_photos_start))
101100
102 # open media selector and add a photo101 # open media selector and add a photo
103 self.main_view.open_toolbar().click_button("addButton")102 self.gallery_app.main_view.open_toolbar().click_button("addButton")
104 self.media_selector.ensure_fully_open()103 self.gallery_app.media_selector.ensure_fully_open()
105104
106 photo = self.media_selector.get_second_photo()105 photo = self.gallery_app.media_selector.get_second_photo()
107 self.click_item(photo)106 self.gallery_app.click_item(photo)
108 self.main_view.get_toolbar().click_custom_button("addButton")107 self.gallery_app.main_view.get_toolbar().click_custom_button("addButton")
109108
110 self.assertThat(109 self.assertThat(
111 lambda: self.album_view.number_of_photos(),110 lambda: self.gallery_app.album_view.number_of_photos(),
112 Eventually(Equals(num_photos_start + 1)))111 Eventually(Equals(num_photos_start + 1)))
113112
114 def test_remove_photo_from_album(self):113 def test_remove_photo_from_album(self):
@@ -183,57 +182,57 @@
183 Eventually(Equals(True)))182 Eventually(Equals(True)))
184183
185 def test_add_photo_to_new_album(self):184 def test_add_photo_to_new_album(self):
186 self.main_view.open_toolbar().click_button("addButton")185 self.gallery_app.main_view.open_toolbar().click_button("addButton")
187 self.ui_update()186 self.gallery_app.ui_update()
188187
189 editor = self.app.select_single(album_editor.AlbumEditor)188 editor = self.gallery_app.album_editor
190 editor.ensure_fully_open()189 editor.ensure_fully_open()
191 self.main_view.close_toolbar()190 self.gallery_app.main_view.close_toolbar()
192 editor.close()191 editor.close()
193192
194 self.open_first_album()193 self.gallery_app.open_first_album()
195 self.main_view.close_toolbar()194 self.gallery_app.main_view.close_toolbar()
196 num_photos_start = self.album_view.number_of_photos()195 num_photos_start = self.gallery_app.album_view.number_of_photos()
197 self.assertThat(num_photos_start, Equals(0))196 self.assertThat(num_photos_start, Equals(0))
198197
199 plus = self.album_view.get_plus_icon_empty_album()198 plus = self.gallery_app.album_view.get_plus_icon_empty_album()
200 # workaround lp:1247698199 # workaround lp:1247698
201 self.main_view.close_toolbar()200 self.gallery_app.main_view.close_toolbar()
202 self.click_item(plus)201 self.gallery_app.click_item(plus)
203 self.media_selector.ensure_fully_open()202 self.gallery_app.media_selector.ensure_fully_open()
204203
205 photo = self.media_selector.get_second_photo()204 photo = self.gallery_app.media_selector.get_second_photo()
206 self.click_item(photo)205 self.gallery_app.click_item(photo)
207 self.main_view.get_toolbar().click_custom_button("addButton")206 self.gallery_app.main_view.get_toolbar().click_custom_button("addButton")
208207
209 self.assertThat(208 self.assertThat(
210 lambda: self.album_view.number_of_photos(),209 lambda: self.gallery_app.album_view.number_of_photos(),
211 Eventually(Equals(num_photos_start + 1)))210 Eventually(Equals(num_photos_start + 1)))
212211
213 @skip("Temporarily disable as it fails in some cases, supposedly due to "212 @skip("Temporarily disable as it fails in some cases, supposedly due to "
214 "problems with the infrastructure")213 "problems with the infrastructure")
215 def test_save_state(self):214 def test_save_state(self):
216 self.main_view.close_toolbar()215 self.gallery_app.main_view.close_toolbar()
217 self.open_first_album()216 self.gallery_app.open_first_album()
218217
219 id = self.album_view.get_album_view().albumId218 id = self.gallery_app.album_view.get_album_view().albumId
220219
221 self.ensure_app_has_quit()220 self.gallery_app.ensure_app_has_quit()
222 self.start_app()221 self.start_app()
223222
224 view = self.album_view.get_album_view()223 view = self.gallery_app.album_view.get_album_view()
225 self.assertThat(view.visible, Eventually(Equals(True)))224 self.assertThat(view.visible, Eventually(Equals(True)))
226 self.assertThat(view.albumId, Eventually(Equals(id)))225 self.assertThat(view.albumId, Eventually(Equals(id)))
227226
228 @skip("Temporarily disable as it fails in some cases, supposedly due to "227 @skip("Temporarily disable as it fails in some cases, supposedly due to "
229 "problems with the infrastructure")228 "problems with the infrastructure")
230 def test_no_save_state_on_back(self):229 def test_no_save_state_on_back(self):
231 self.main_view.close_toolbar()230 self.gallery_app.main_view.close_toolbar()
232 self.open_first_album()231 self.gallery_app.open_first_album()
233 self.main_view.open_toolbar().click_button("backButton")232 self.gallery_app.main_view.open_toolbar().click_button("backButton")
234233
235 self.ensure_app_has_quit()234 self.ensure_app_has_quit()
236 self.start_app()235 self.start_app()
237236
238 view = self.album_view.get_animated_album_view()237 view = self.gallery_app.album_view.get_animated_album_view()
239 self.assertThat(view.isOpen, Equals(False))238 self.assertThat(view.isOpen, Equals(False))
240239
=== modified file 'tests/autopilot/gallery_app/tests/test_albums_view.py'
--- tests/autopilot/gallery_app/tests/test_albums_view.py 2014-05-20 15:19:35 +0000
+++ tests/autopilot/gallery_app/tests/test_albums_view.py 2014-07-02 14:17:44 +0000
@@ -13,8 +13,6 @@
13from autopilot.platform import model13from autopilot.platform import model
1414
15from gallery_app.tests import GalleryTestCase15from gallery_app.tests import GalleryTestCase
16from gallery_app.emulators.albums_view import AlbumsView
17from gallery_app.emulators import album_editor
1816
19from os import environ as env17from os import environ as env
2018
@@ -22,13 +20,7 @@
22class TestAlbumsView(GalleryTestCase):20class TestAlbumsView(GalleryTestCase):
23 envDesktopMode = None21 envDesktopMode = None
2422
25 @property
26 def albums_view(self):
27 return AlbumsView(self.app)
28
29 def setUp(self):23 def setUp(self):
30 self.ARGS = []
31
32 self.envDesktopMode = env.get("DESKTOP_MODE")24 self.envDesktopMode = env.get("DESKTOP_MODE")
3325
34 if model() == "Desktop":26 if model() == "Desktop":
@@ -37,7 +29,7 @@
37 env["DESKTOP_MODE"] = "0"29 env["DESKTOP_MODE"] = "0"
3830
39 super(TestAlbumsView, self).setUp()31 super(TestAlbumsView, self).setUp()
40 self.switch_to_albums_tab()32 self.gallery_app.switch_to_albums_tab()
4133
42 def tearDown(self):34 def tearDown(self):
43 if self.envDesktopMode:35 if self.envDesktopMode:
@@ -49,10 +41,10 @@
4941
50 def test_add_album(self):42 def test_add_album(self):
51 """Add one album, and checks if the number of albums went up by one"""43 """Add one album, and checks if the number of albums went up by one"""
52 albums = self.albums_view.number_of_albums_in_albums_view()44 albums = self.gallery_app.albums_view.number_of_albums_in_albums_view()
53 self.main_view.open_toolbar().click_button("addButton")45 self.gallery_app.main_view.open_toolbar().click_button("addButton")
54 self.assertThat(46 self.assertThat(
55 lambda: self.albums_view.number_of_albums_in_albums_view(),47 lambda: self.gallery_app.albums_view.number_of_albums_in_albums_view(),
56 Eventually(Equals(albums+1))48 Eventually(Equals(albums+1))
57 )49 )
5850
@@ -60,20 +52,20 @@
60 """Add one album, cancel it and checks if the number of albums does52 """Add one album, cancel it and checks if the number of albums does
61 not change53 not change
62 """54 """
63 albums = self.albums_view.number_of_albums_in_albums_view()55 albums = self.gallery_app.albums_view.number_of_albums_in_albums_view()
64 self.main_view.open_toolbar().click_button("addButton")56 self.gallery_app.main_view.open_toolbar().click_button("addButton")
65 editor = self.app.select_single(album_editor.AlbumEditor)57 editor = self.gallery_app.album_editor
66 editor.ensure_fully_open()58 editor.ensure_fully_open()
67 self.main_view.get_toolbar().click_custom_button("cancelButton")59 self.gallery_app.main_view.get_toolbar().click_custom_button("cancelButton")
68 self.assertThat(60 self.assertThat(
69 lambda: self.albums_view.number_of_albums_in_albums_view(),61 lambda: self.gallery_app.albums_view.number_of_albums_in_albums_view(),
70 Eventually(Equals(albums))62 Eventually(Equals(albums))
71 )63 )
7264
73 # Check if Camera Button is not visible at Desktop mode65 # Check if Camera Button is not visible at Desktop mode
74 def test_camera_button_visible(self):66 def test_camera_button_visible(self):
75 self.main_view.open_toolbar()67 self.gallery_app.main_view.open_toolbar()
76 toolbar = self.main_view.get_toolbar()68 toolbar = self.gallery_app.main_view.get_toolbar()
77 cameraButton = toolbar.select_single(69 cameraButton = toolbar.select_single(
78 "ActionItem",70 "ActionItem",
79 objectName="cameraButton"71 objectName="cameraButton"
8072
=== modified file 'tests/autopilot/gallery_app/tests/test_events_view.py'
--- tests/autopilot/gallery_app/tests/test_events_view.py 2014-06-16 13:46:21 +0000
+++ tests/autopilot/gallery_app/tests/test_events_view.py 2014-07-02 14:17:44 +0000
@@ -13,7 +13,6 @@
13from autopilot.platform import model13from autopilot.platform import model
1414
15from gallery_app.tests import GalleryTestCase15from gallery_app.tests import GalleryTestCase
16from gallery_app.emulators.events_view import EventsView
1716
18from os import environ as env17from os import environ as env
19from os.path import exists18from os.path import exists
@@ -24,12 +23,8 @@
24 """Tests the main gallery features"""23 """Tests the main gallery features"""
25 envDesktopMode = None24 envDesktopMode = None
2625
27 @property
28 def events_view(self):
29 return EventsView(self.app)
30
31 def setUp(self):26 def setUp(self):
32 self.ARGS = []27 self.args = []
3328
34 self.envDesktopMode = env.get("DESKTOP_MODE")29 self.envDesktopMode = env.get("DESKTOP_MODE")
3530
@@ -41,9 +36,9 @@
41 # This is needed to wait for the application to start.36 # This is needed to wait for the application to start.
42 # In the testfarm, the application may take some time to show up.37 # In the testfarm, the application may take some time to show up.
43 super(TestEventsView, self).setUp()38 super(TestEventsView, self).setUp()
44 self.main_view.switch_to_tab("eventsTab")39 self.gallery_app.main_view.switch_to_tab("eventsTab")
45 """Wait for the data to be loaded and displayed"""40 """Wait for the data to be loaded and displayed"""
46 self.assertThat(lambda: self.events_view.number_of_events(),41 self.assertThat(lambda: self.gallery_app.events_view.number_of_events(),
47 Eventually(GreaterThan(0)))42 Eventually(GreaterThan(0)))
4843
49 def tearDown(self):44 def tearDown(self):
@@ -54,77 +49,70 @@
5449
55 super(TestEventsView, self).tearDown()50 super(TestEventsView, self).tearDown()
5651
57 def get_events_view(self):
58 return self.app.wait_select_single("EventsOverview",
59 objectName="organicEventView")
60
61 def enable_select_mode(self):
62 self.main_view.open_toolbar().click_button("selectButton")
63
64 def test_select_button_cancel(self):52 def test_select_button_cancel(self):
65 """Clicking the cancel button after clicking the select button must53 """Clicking the cancel button after clicking the select button must
66 hide the toolbar automatically."""54 hide the toolbar automatically."""
67 events_view = self.get_events_view()55 events_view = self.gallery_app.get_events_view()
68 self.assertFalse(events_view.inSelectionMode)56 self.assertFalse(events_view.inSelectionMode)
6957
70 self.enable_select_mode()58 self.gallery_app.enable_select_mode()
71 self.assertTrue(events_view.inSelectionMode)59 self.assertTrue(events_view.inSelectionMode)
7260
73 self.main_view.get_toolbar().click_custom_button("cancelButton")61 self.gallery_app.main_view.get_toolbar().click_custom_button("cancelButton")
7462
75 toolbar = self.main_view.get_toolbar()63 toolbar = self.gallery_app.main_view.get_toolbar()
76 self.assertThat(toolbar.opened, Eventually(Equals(False)))64 self.assertThat(toolbar.opened, Eventually(Equals(False)))
77 self.assertFalse(events_view.inSelectionMode)65 self.assertFalse(events_view.inSelectionMode)
7866
79 def test_delete_a_photo(self):67 def test_delete_a_photo(self):
80 """Selecting a photo must make the delete button clickable."""68 """Selecting a photo must make the delete button clickable."""
81 self.assertThat(lambda: exists(self.sample_file),69 self.assertThat(lambda: exists(self.gallery_app.sample_file),
82 Eventually(Equals(True)))70 Eventually(Equals(True)))
8371
84 self.enable_select_mode()72 self.gallery_app.enable_select_mode()
85 self.events_view.click_photo(self.sample_file)73 self.gallery_app.events_view.click_photo(self.gallery_app.sample_file)
86 self.main_view.open_toolbar().click_button("deleteButton")74 self.gallery_app.main_view.open_toolbar().click_button("deleteButton")
87 self.assertThat(self.gallery_utils.delete_dialog_shown,75 self.assertThat(self.gallery_app.gallery_utils.delete_dialog_shown,
88 Eventually(Is(True)))76 Eventually(Is(True)))
8977
90 self.gallery_utils.click_delete_dialog_cancel_button()78 self.gallery_app.gallery_utils.click_delete_dialog_cancel_button()
91 self.assertThat(self.gallery_utils.delete_dialog_shown,79 self.assertThat(self.gallery_app.gallery_utils.delete_dialog_shown,
92 Eventually(Is(False)))80 Eventually(Is(False)))
9381
94 self.assertThat(lambda: exists(self.sample_file),82 self.assertThat(lambda: exists(self.gallery_app.sample_file),
95 Eventually(Equals(True)))83 Eventually(Equals(True)))
9684
97 self.main_view.open_toolbar().click_button("deleteButton")85 self.gallery_app.main_view.open_toolbar().click_button("deleteButton")
98 self.assertThat(self.gallery_utils.delete_dialog_shown,86 self.assertThat(self.gallery_app.gallery_utils.delete_dialog_shown,
99 Eventually(Is(True)))87 Eventually(Is(True)))
10088
101 self.gallery_utils.click_delete_dialog_delete_button()89 self.gallery_app.gallery_utils.click_delete_dialog_delete_button()
102 self.assertThat(self.gallery_utils.delete_dialog_shown,90 self.assertThat(self.gallery_app.gallery_utils.delete_dialog_shown,
103 Eventually(Is(False)))91 Eventually(Is(False)))
10492
105 self.assertThat(lambda: exists(self.sample_file),93 self.assertThat(lambda: exists(self.gallery_app.sample_file),
106 Eventually(Equals(False)))94 Eventually(Equals(False)))
10795
108 def test_adding_a_video(self):96 def test_adding_a_video(self):
109 if model() == "Desktop":97 if model() == "Desktop":
110 before = self.events_view.get_event(0)98 before = self.gallery_app.events_view.get_event(0)
111 video_file = "video.mp4"99 video_file = "video.mp4"
112 shutil.copyfile(self.sample_dir+"/option01/"+video_file,100 shutil.copyfile(self.gallery_app.sample_dir+"/option01/"+video_file,
113 self.sample_destination_dir+"/"+video_file)101 self.gallery_app.sample_destination_dir+"/"+video_file)
114 video_file = "video.mkv"102 video_file = "video.mkv"
115 shutil.copyfile(self.sample_dir+"/option01/"+video_file,103 shutil.copyfile(self.gallery_app.sample_dir+"/option01/"+video_file,
116 self.sample_destination_dir+"/"+video_file)104 self.gallery_app.sample_destination_dir+"/"+video_file)
117 after = self.events_view.get_event(0)105 after = self.gallery_app.events_view.get_event(0)
118 self.assertThat(lambda: str(after),106 self.assertThat(lambda: str(after),
119 Eventually(NotEquals(str(before))))107 Eventually(NotEquals(str(before))))
120 self.assertThat(108 self.assertThat(
121 lambda: self.events_view.number_of_photos_in_events(),109 lambda: self.gallery_app.events_view.number_of_photos_in_events(),
122 Eventually(Equals(4)))110 Eventually(Equals(4)))
123111
124 # Check if Camera Button is not visible at Desktop mode112 # Check if Camera Button is not visible at Desktop mode
125 def test_camera_button_visible(self):113 def test_camera_button_visible(self):
126 self.main_view.open_toolbar()114 self.gallery_app.main_view.open_toolbar()
127 toolbar = self.main_view.get_toolbar()115 toolbar = self.gallery_app.main_view.get_toolbar()
128 cameraButton = toolbar.select_single(116 cameraButton = toolbar.select_single(
129 "ActionItem",117 "ActionItem",
130 objectName="cameraButton"118 objectName="cameraButton"
131119
=== modified file 'tests/autopilot/gallery_app/tests/test_photo_viewer.py'
--- tests/autopilot/gallery_app/tests/test_photo_viewer.py 2014-05-20 15:19:35 +0000
+++ tests/autopilot/gallery_app/tests/test_photo_viewer.py 2014-07-02 14:17:44 +0000
@@ -8,12 +8,9 @@
88
9"""Tests the Photo editor of the gallery app."""9"""Tests the Photo editor of the gallery app."""
1010
11from testtools.matchers import Equals, NotEquals, GreaterThan, Is11from testtools.matchers import Equals, NotEquals
12from autopilot.matchers import Eventually12from autopilot.matchers import Eventually
1313
14from gallery_app.emulators.photo_viewer import PhotoViewer
15from gallery_app.emulators.media_viewer import MediaViewer
16from gallery_app.emulators.events_view import EventsView
17from gallery_app.tests import GalleryTestCase14from gallery_app.tests import GalleryTestCase
1815
19import os16import os
@@ -26,38 +23,11 @@
2623
2724
28class TestPhotoViewerBase(GalleryTestCase):25class TestPhotoViewerBase(GalleryTestCase):
29 @property
30 def photo_viewer(self):
31 return PhotoViewer(self.app)
32
33 @property
34 def events_view(self):
35 return EventsView(self.app)
36
37 def setUp(self):26 def setUp(self):
38 self.ARGS = []
39 super(TestPhotoViewerBase, self).setUp()27 super(TestPhotoViewerBase, self).setUp()
40 self.main_view.switch_to_tab("eventsTab")28 self.gallery_app.main_view.switch_to_tab("eventsTab")
41 self.open_first_photo()29 self.gallery_app.open_first_photo()
42 self.main_view.open_toolbar()30 self.gallery_app.main_view.open_toolbar()
43
44 def open_first_photo(self):
45 self.assertThat(
46 lambda: self.events_view.number_of_photos_in_events(),
47 Eventually(GreaterThan(0))
48 )
49
50 # workaround lp:1247698
51 # toolbar needs to be gone to click on an image.
52 self.main_view.close_toolbar()
53
54 self.events_view.click_photo(self.sample_file)
55
56 photo_viewer_loader = self.photo_viewer.get_main_photo_viewer_loader()
57 self.assertThat(photo_viewer_loader.loaded, Eventually(Equals(True)))
58 sleep(1)
59 photo_viewer = self.photo_viewer.get_main_photo_viewer()
60 self.assertThat(photo_viewer.visible, Eventually(Equals(True)))
6131
6232
63class TestPhotoViewer(TestPhotoViewerBase):33class TestPhotoViewer(TestPhotoViewerBase):
@@ -67,15 +37,15 @@
67 def test_save_state(self):37 def test_save_state(self):
68 """Quitting the app once a photo has been opened will return38 """Quitting the app once a photo has been opened will return
69 to that same photo on restart"""39 to that same photo on restart"""
70 path = self.photo_viewer.get_photo_component().select_single(40 path = self.gallery_app.photo_viewer.get_photo_component().select_single(
71 "QQuickImage").source41 "QQuickImage").source
7242
73 self.ensure_app_has_quit()43 self.ensure_app_has_quit()
74 self.start_app()44 self.start_app()
7545
76 photo_viewer = self.photo_viewer.get_main_photo_viewer()46 photo_viewer = self.gallery_app.photo_viewer.get_main_photo_viewer()
77 self.assertThat(photo_viewer.visible, Eventually(Equals(True)))47 self.assertThat(photo_viewer.visible, Eventually(Equals(True)))
78 new_path = self.photo_viewer.get_photo_component().select_single(48 new_path = self.gallery_app.photo_viewer.get_photo_component().select_single(
79 "QQuickImage").source49 "QQuickImage").source
8050
81 self.assertThat(path, Equals(new_path))51 self.assertThat(path, Equals(new_path))
@@ -85,76 +55,59 @@
85 def test_no_save_state_on_back(self):55 def test_no_save_state_on_back(self):
86 """Quitting the app once a photo has been opened and then closed56 """Quitting the app once a photo has been opened and then closed
87 will not reopen a photo on restart"""57 will not reopen a photo on restart"""
88 self.main_view.open_toolbar().click_button("backButton")58 self.gallery_app.main_view.open_toolbar().click_button("backButton")
8959
90 self.ensure_app_has_quit()60 self.ensure_app_has_quit()
91 self.start_app()61 self.start_app()
9262
93 photo_viewer_loader = self.photo_viewer.get_main_photo_viewer_loader()63 photo_viewer_loader = self.gallery_app.photo_viewer.get_main_photo_viewer_loader()
94 self.assertThat(photo_viewer_loader.source, Equals(""))64 self.assertThat(photo_viewer_loader.source, Equals(""))
9565
96 def get_delete_dialog(self):
97 delete_dialog = self.photo_viewer.get_delete_dialog()
98 self.assertThat(delete_dialog.visible, Eventually(Equals(True)))
99 self.assertThat(delete_dialog.opacity, Eventually(Equals(1)))
100 return delete_dialog
101
102 def ensure_closed_delete_dialog(self):
103 self.assertThat(self.photo_viewer.delete_dialog_shown,
104 Eventually(Is(False)))
105
106 def test_nav_bar_back_button(self):66 def test_nav_bar_back_button(self):
107 """Clicking the back button must close the photo."""67 """Clicking the back button must close the photo."""
108 self.main_view.open_toolbar().click_button("backButton")68 self.gallery_app.main_view.open_toolbar().click_button("backButton")
109 photo_viewer = self.photo_viewer.get_main_photo_viewer()69 photo_viewer = self.gallery_app.photo_viewer.get_main_photo_viewer()
110 self.assertThat(photo_viewer.visible, Eventually(Equals(False)))70 self.assertThat(photo_viewer.visible, Eventually(Equals(False)))
11171
112 def delete_one_picture(self):
113 self.main_view.open_toolbar().click_button("deleteButton")
114 self.get_delete_dialog()
115 delete_item = self.photo_viewer.get_delete_popover_delete_item()
116 self.click_item(delete_item)
117 self.ensure_closed_delete_dialog()
118
119 def test_photo_delete_works(self):72 def test_photo_delete_works(self):
120 """Clicking the trash button must show the delete dialog."""73 """Clicking the trash button must show the delete dialog."""
121 self.main_view.open_toolbar().click_button("deleteButton")74 self.gallery_app.main_view.open_toolbar().click_button("deleteButton")
122 self.get_delete_dialog()75 self.gallery_app.get_delete_dialog()
12376
124 photo_viewer = self.photo_viewer.get_main_photo_viewer()77 photo_viewer = self.gallery_app.photo_viewer.get_main_photo_viewer()
12578
126 cancel_item = self.photo_viewer.get_delete_popover_cancel_item()79 cancel_item = self.gallery_app.photo_viewer.get_delete_popover_cancel_item()
127 self.click_item(cancel_item)80 self.gallery_app.click_item(cancel_item)
128 self.ensure_closed_delete_dialog()81 self.gallery_app.ensure_closed_delete_dialog()
12982
130 self.assertThat(lambda: os.path.exists(self.sample_file),83 self.assertThat(lambda: os.path.exists(self.gallery_app.sample_file),
131 Eventually(Equals(True)))84 Eventually(Equals(True)))
13285
133 self.delete_one_picture()86 self.gallery_app.delete_one_picture()
134 self.assertThat(lambda: os.path.exists(self.sample_file),87 self.assertThat(lambda: os.path.exists(self.gallery_app.sample_file),
135 Eventually(Equals(False)))88 Eventually(Equals(False)))
13689
137 # Delete all other pictures and make sure the photo viewer closes90 # Delete all other pictures and make sure the photo viewer closes
138 self.delete_one_picture()91 self.gallery_app.delete_one_picture()
139 self.delete_one_picture()92 self.gallery_app.delete_one_picture()
140 self.delete_one_picture()93 self.gallery_app.delete_one_picture()
141 self.delete_one_picture()94 self.gallery_app.delete_one_picture()
14295
143 self.assertThat(photo_viewer.visible, Eventually(Equals(False)))96 self.assertThat(photo_viewer.visible, Eventually(Equals(False)))
14497
145 def test_nav_bar_album_picker_button(self):98 def test_nav_bar_album_picker_button(self):
146 """Clicking the album picker must show the picker dialog."""99 """Clicking the album picker must show the picker dialog."""
147 self.main_view.open_toolbar().click_button("addButton")100 self.gallery_app.main_view.open_toolbar().click_button("addButton")
148 album_picker = self.photo_viewer.get_popup_album_picker()101 album_picker = self.gallery_app.photo_viewer.get_popup_album_picker()
149 self.assertThat(album_picker.visible, Eventually(Equals(True)))102 self.assertThat(album_picker.visible, Eventually(Equals(True)))
150103
151 def test_double_click_zoom(self):104 def test_double_click_zoom(self):
152 """Double clicking an opened photo must zoom it."""105 """Double clicking an opened photo must zoom it."""
153 opened_photo = self.photo_viewer.get_photo_component()106 opened_photo = self.gallery_app.photo_viewer.get_photo_component()
154107
155 self.pointing_device.move_to_object(opened_photo)108 self.gallery_app.pointing_device.move_to_object(opened_photo)
156 self.pointing_device.click()109 self.gallery_app.pointing_device.click()
157 self.pointing_device.click()110 self.gallery_app.pointing_device.click()
158111
159 self.assertThat(112 self.assertThat(
160 opened_photo.isZoomAnimationInProgress,113 opened_photo.isZoomAnimationInProgress,
@@ -162,8 +115,8 @@
162 )115 )
163 self.assertThat(opened_photo.fullyZoomed, Eventually(Equals(True)))116 self.assertThat(opened_photo.fullyZoomed, Eventually(Equals(True)))
164117
165 self.pointing_device.click()118 self.gallery_app.pointing_device.click()
166 self.pointing_device.click()119 self.gallery_app.pointing_device.click()
167120
168 self.assertThat(121 self.assertThat(
169 opened_photo.isZoomAnimationInProgress,122 opened_photo.isZoomAnimationInProgress,
@@ -173,26 +126,26 @@
173126
174 def test_swipe_change_image(self):127 def test_swipe_change_image(self):
175 """Swiping left and right on a photo should move to another photo"""128 """Swiping left and right on a photo should move to another photo"""
176 list = self.photo_viewer.get_photos_list()129 list = self.gallery_app.photo_viewer.get_photos_list()
177 self.assertThat(list.currentIndex, Eventually(Equals(0)))130 self.assertThat(list.currentIndex, Eventually(Equals(0)))
178131
179 # Slide left should move to the next image132 # Slide left should move to the next image
180 x, y, w, h = list.globalRect133 x, y, w, h = list.globalRect
181 mid_y = y + h // 2134 mid_y = y + h // 2
182 mid_x = x + w // 2135 mid_x = x + w // 2
183 self.pointing_device.drag(mid_x, mid_y, x + 10, mid_y)136 self.gallery_app.pointing_device.drag(mid_x, mid_y, x + 10, mid_y)
184137
185 self.assertThat(list.moving, Eventually(Equals(False)))138 self.assertThat(list.moving, Eventually(Equals(False)))
186 self.assertThat(list.currentIndex, Eventually(Equals(1)))139 self.assertThat(list.currentIndex, Eventually(Equals(1)))
187140
188 # Slide right should get us back to the start141 # Slide right should get us back to the start
189 self.pointing_device.drag(mid_x, mid_y, x + w - 10, mid_y)142 self.gallery_app.pointing_device.drag(mid_x, mid_y, x + w - 10, mid_y)
190143
191 self.assertThat(list.moving, Eventually(Equals(False)))144 self.assertThat(list.moving, Eventually(Equals(False)))
192 self.assertThat(list.currentIndex, Eventually(Equals(0)))145 self.assertThat(list.currentIndex, Eventually(Equals(0)))
193146
194 # Slide right again shouldn't go anywhere147 # Slide right again shouldn't go anywhere
195 self.pointing_device.drag(mid_x, mid_y, x + w - 10, mid_y)148 self.gallery_app.pointing_device.drag(mid_x, mid_y, x + w - 10, mid_y)
196149
197 self.assertThat(list.moving, Eventually(Equals(False)))150 self.assertThat(list.moving, Eventually(Equals(False)))
198 self.assertThat(list.currentIndex, Eventually(Equals(0)))151 self.assertThat(list.currentIndex, Eventually(Equals(0)))
@@ -202,98 +155,91 @@
202155
203 def setUp(self):156 def setUp(self):
204 super(TestPhotoEditor, self).setUp()157 super(TestPhotoEditor, self).setUp()
205 self.click_edit_button()158 self.gallery_app.click_edit_button()
206 self.media_view = self.app.select_single(MediaViewer)
207
208 def click_edit_button(self):
209 self.main_view.open_toolbar().click_button("editButton")
210 edit_dialog = self.photo_viewer.get_photo_edit_dialog()
211 self.assertThat(edit_dialog.visible, (Eventually(Equals(True))))
212 self.assertThat(edit_dialog.opacity, (Eventually(Equals(1))))
213159
214 def test_photo_editor_crop(self):160 def test_photo_editor_crop(self):
215 """Cropping a photo must crop it."""161 """Cropping a photo must crop it."""
216 old_file_size = os.path.getsize(self.sample_file)162 old_file_size = os.path.getsize(self.gallery_app.sample_file)
217163
218 crop_box = self.photo_viewer.get_crop_interactor()164 crop_box = self.gallery_app.photo_viewer.get_crop_interactor()
219 item_width = crop_box.width165 item_width = crop_box.width
220 item_height = crop_box.height166 item_height = crop_box.height
221167
222 self.photo_viewer.click_crop_item()168 self.gallery_app.photo_viewer.click_crop_item()
223169
224 self.assertThat(crop_box.state, Eventually(Equals("shown")))170 self.assertThat(crop_box.state, Eventually(Equals("shown")))
225 self.assertThat(crop_box.opacity, Eventually(Equals(1)))171 self.assertThat(crop_box.opacity, Eventually(Equals(1)))
226172
227 crop_corner = self.photo_viewer.get_top_left_crop_corner()173 crop_corner = self.gallery_app.photo_viewer.get_top_left_crop_corner()
228 x, y, h, w = crop_corner.globalRect174 x, y, h, w = crop_corner.globalRect
229 x = x + w // 2175 x = x + w // 2
230 y = y + h // 2176 y = y + h // 2
231 self.pointing_device.drag(x, y,177 self.gallery_app.pointing_device.drag(x, y,
232 x + item_width // 2, y + item_height // 2)178 x + item_width // 2, y + item_height // 2)
233179
234 # wait for animation being finished180 # wait for animation being finished
235 crop_overlay = self.photo_viewer.get_crop_overlay()181 crop_overlay = self.gallery_app.photo_viewer.get_crop_overlay()
236 self.assertThat(crop_overlay.interpolationFactor,182 self.assertThat(crop_overlay.interpolationFactor,
237 Eventually(Equals(1.0)))183 Eventually(Equals(1.0)))
238184
239 crop_button = self.photo_viewer.get_crop_overlays_crop_icon()185 crop_button = self.gallery_app.photo_viewer.get_crop_overlays_crop_icon()
240 self.click_item(crop_button)186 self.gallery_app.click_item(crop_button)
241 self.media_view.ensure_spinner_not_running()187 self.gallery_app.media_view.ensure_spinner_not_running()
242188
243 # wait for new photo being set/reloaded, so saving thumbnailing etc.189 # wait for new photo being set/reloaded, so saving thumbnailing etc.
244 # is done190 # is done
245 edit_preview = self.photo_viewer.get_edit_preview()191 edit_preview = self.gallery_app.photo_viewer.get_edit_preview()
246 new_source = "image://thumbnailer/" + self.sample_file192 new_source = "image://thumbnailer/" + self.gallery_app.sample_file
247193
248 self.assertThat(edit_preview.source, Eventually(Equals(new_source)))194 self.assertThat(edit_preview.source, Eventually(Equals(new_source)))
249195
250 new_file_size = os.path.getsize(self.sample_file)196 new_file_size = os.path.getsize(self.gallery_app.sample_file)
251 self.assertThat(old_file_size > new_file_size, Equals(True))197 self.assertThat(old_file_size > new_file_size, Equals(True))
252198
253 def test_photo_editor_rotate(self):199 def test_photo_editor_rotate(self):
254 """Makes sure that the photo editor inside the photo viewer works using200 """Makes sure that the photo editor inside the photo viewer works using
255 the rotate function"""201 the rotate function"""
256 opened_photo = self.photo_viewer.get_opened_photo()202 opened_photo = self.gallery_app.photo_viewer.get_opened_photo()
257 item_height = opened_photo.height203 item_height = opened_photo.height
258204
259 def is_landscape():205 def is_landscape():
260 return opened_photo.paintedWidth > opened_photo.paintedHeight206 return opened_photo.paintedWidth > opened_photo.paintedHeight
261 self.assertThat(is_landscape(), Equals(True))207 self.assertThat(is_landscape(), Equals(True))
262208
263 self.photo_viewer.click_rotate_item()209 self.gallery_app.photo_viewer.click_rotate_item()
264 self.media_view.ensure_spinner_not_running()210 self.gallery_app.media_view.ensure_spinner_not_running()
265211
266 self.assertThat(opened_photo.paintedHeight,212 self.assertThat(opened_photo.paintedHeight,
267 Eventually(Equals(item_height)))213 Eventually(Equals(item_height)))
268 self.assertThat(lambda: is_landscape(),214 self.assertThat(lambda: is_landscape(),
269 Eventually(Equals(False)))215 Eventually(Equals(False)))
270216
271 self.main_view.open_toolbar()217 self.gallery_app.main_view.open_toolbar()
272 self.click_edit_button()218 self.gallery_app.click_edit_button()
273 self.photo_viewer.click_undo_item()219 self.gallery_app.photo_viewer.click_undo_item()
274 self.media_view.ensure_spinner_not_running()220 self.gallery_app.media_view.ensure_spinner_not_running()
275221
276 self.assertThat(opened_photo.paintedHeight,222 self.assertThat(opened_photo.paintedHeight,
277 Eventually(NotEquals(item_height)))223 Eventually(NotEquals(item_height)))
278 self.assertThat(lambda: is_landscape(),224 self.assertThat(lambda: is_landscape(),
279 Eventually(Equals(True)))225 Eventually(Equals(True)))
280226
281 self.main_view.open_toolbar()227 self.gallery_app.main_view.open_toolbar()
282 self.click_edit_button()228 self.gallery_app.click_edit_button()
283 self.photo_viewer.click_redo_item()229 self.gallery_app.photo_viewer.click_redo_item()
284 self.media_view.ensure_spinner_not_running()230 self.gallery_app.media_view.ensure_spinner_not_running()
285231
286 self.assertThat(opened_photo.paintedHeight,232 self.assertThat(opened_photo.paintedHeight,
287 Eventually(Equals(item_height)))233 Eventually(Equals(item_height)))
288 is_landscape = opened_photo.paintedWidth > opened_photo.paintedHeight234 is_landscape = opened_photo.paintedWidth > opened_photo.paintedHeight
289 self.assertThat(is_landscape, Equals(False))235 self.assertThat(is_landscape, Equals(False))
290236
291 self.main_view.open_toolbar()237 self.gallery_app.main_view.open_toolbar()
292 self.click_edit_button()238 self.gallery_app.click_edit_button()
293 self.photo_viewer.click_rotate_item()239 self.gallery_app.photo_viewer.click_rotate_item()
294 self.main_view.open_toolbar()240 self.gallery_app.main_view.open_toolbar()
295 self.click_edit_button()241 self.gallery_app.click_edit_button()
296 self.photo_viewer.click_revert_item()242 self.gallery_app.photo_viewer.click_revert_item()
297243
298 self.assertThat(opened_photo.paintedHeight,244 self.assertThat(opened_photo.paintedHeight,
299 Eventually(NotEquals(item_height)))245 Eventually(NotEquals(item_height)))
@@ -307,66 +253,66 @@
307 sleep(1)253 sleep(1)
308254
309 def test_photo_editor_redo_undo_revert_enhance_states(self):255 def test_photo_editor_redo_undo_revert_enhance_states(self):
310 undo_item = self.photo_viewer.get_undo_menu_item()256 undo_item = self.gallery_app.photo_viewer.get_undo_menu_item()
311 redo_item = self.photo_viewer.get_redo_menu_item()257 redo_item = self.gallery_app.photo_viewer.get_redo_menu_item()
312 revert_item = self.photo_viewer.get_revert_menu_item()258 revert_item = self.gallery_app.photo_viewer.get_revert_menu_item()
313259
314 self.assertThat(undo_item.enabled, Eventually(Equals(False)))260 self.assertThat(undo_item.enabled, Eventually(Equals(False)))
315 self.assertThat(redo_item.enabled, Eventually(Equals(False)))261 self.assertThat(redo_item.enabled, Eventually(Equals(False)))
316 self.assertThat(revert_item.enabled, Eventually(Equals(False)))262 self.assertThat(revert_item.enabled, Eventually(Equals(False)))
317263
318 self.photo_viewer.click_rotate_item()264 self.gallery_app.photo_viewer.click_rotate_item()
319 self.media_view.ensure_spinner_not_running()265 self.gallery_app.media_view.ensure_spinner_not_running()
320266
321 self.click_edit_button()267 self.gallery_app.click_edit_button()
322 undo_item = self.photo_viewer.get_undo_menu_item()268 undo_item = self.gallery_app.photo_viewer.get_undo_menu_item()
323 redo_item = self.photo_viewer.get_redo_menu_item()269 redo_item = self.gallery_app.photo_viewer.get_redo_menu_item()
324 revert_item = self.photo_viewer.get_revert_menu_item()270 revert_item = self.gallery_app.photo_viewer.get_revert_menu_item()
325271
326 self.assertThat(undo_item.enabled, Eventually(Equals(True)))272 self.assertThat(undo_item.enabled, Eventually(Equals(True)))
327 self.assertThat(redo_item.enabled, Eventually(Equals(False)))273 self.assertThat(redo_item.enabled, Eventually(Equals(False)))
328 self.assertThat(revert_item.enabled, Eventually(Equals(True)))274 self.assertThat(revert_item.enabled, Eventually(Equals(True)))
329275
330 self.photo_viewer.click_undo_item()276 self.gallery_app.photo_viewer.click_undo_item()
331 self.media_view.ensure_spinner_not_running()277 self.gallery_app.media_view.ensure_spinner_not_running()
332278
333 self.click_edit_button()279 self.gallery_app.click_edit_button()
334 undo_item = self.photo_viewer.get_undo_menu_item()280 undo_item = self.gallery_app.photo_viewer.get_undo_menu_item()
335 redo_item = self.photo_viewer.get_redo_menu_item()281 redo_item = self.gallery_app.photo_viewer.get_redo_menu_item()
336 revert_item = self.photo_viewer.get_revert_menu_item()282 revert_item = self.gallery_app.photo_viewer.get_revert_menu_item()
337283
338 self.assertThat(undo_item.enabled, Eventually(Equals(False)))284 self.assertThat(undo_item.enabled, Eventually(Equals(False)))
339 self.assertThat(redo_item.enabled, Eventually(Equals(True)))285 self.assertThat(redo_item.enabled, Eventually(Equals(True)))
340 self.assertThat(revert_item.enabled, Eventually(Equals(False)))286 self.assertThat(revert_item.enabled, Eventually(Equals(False)))
341287
342 self.photo_viewer.click_redo_item()288 self.gallery_app.photo_viewer.click_redo_item()
343 self.media_view.ensure_spinner_not_running()289 self.gallery_app.media_view.ensure_spinner_not_running()
344290
345 self.click_edit_button()291 self.gallery_app.click_edit_button()
346 undo_item = self.photo_viewer.get_undo_menu_item()292 undo_item = self.gallery_app.photo_viewer.get_undo_menu_item()
347 redo_item = self.photo_viewer.get_redo_menu_item()293 redo_item = self.gallery_app.photo_viewer.get_redo_menu_item()
348 revert_item = self.photo_viewer.get_revert_menu_item()294 revert_item = self.gallery_app.photo_viewer.get_revert_menu_item()
349295
350 self.assertThat(undo_item.enabled, Eventually(Equals(True)))296 self.assertThat(undo_item.enabled, Eventually(Equals(True)))
351 self.assertThat(redo_item.enabled, Eventually(Equals(False)))297 self.assertThat(redo_item.enabled, Eventually(Equals(False)))
352 self.assertThat(revert_item.enabled, Eventually(Equals(True)))298 self.assertThat(revert_item.enabled, Eventually(Equals(True)))
353299
354 self.photo_viewer.click_revert_item()300 self.gallery_app.photo_viewer.click_revert_item()
355 self.media_view.ensure_spinner_not_running()301 self.gallery_app.media_view.ensure_spinner_not_running()
356302
357 self.click_edit_button()303 self.gallery_app.click_edit_button()
358 undo_item = self.photo_viewer.get_undo_menu_item()304 undo_item = self.gallery_app.photo_viewer.get_undo_menu_item()
359 redo_item = self.photo_viewer.get_redo_menu_item()305 redo_item = self.gallery_app.photo_viewer.get_redo_menu_item()
360 revert_item = self.photo_viewer.get_revert_menu_item()306 revert_item = self.gallery_app.photo_viewer.get_revert_menu_item()
361307
362 self.assertThat(undo_item.enabled, Eventually(Equals(True)))308 self.assertThat(undo_item.enabled, Eventually(Equals(True)))
363 self.assertThat(redo_item.enabled, Eventually(Equals(False)))309 self.assertThat(redo_item.enabled, Eventually(Equals(False)))
364 self.assertThat(revert_item.enabled, Eventually(Equals(False)))310 self.assertThat(revert_item.enabled, Eventually(Equals(False)))
365311
366 self.photo_viewer.click_enhance_item()312 self.gallery_app.photo_viewer.click_enhance_item()
367 self.media_view.ensure_spinner_not_running()313 self.gallery_app.media_view.ensure_spinner_not_running()
368314
369 self.click_edit_button()315 self.gallery_app.click_edit_button()
370316
371 revert_item = self.photo_viewer.get_revert_menu_item()317 revert_item = self.gallery_app.photo_viewer.get_revert_menu_item()
372 self.assertThat(lambda: revert_item.enabled, Eventually(Equals(True)))318 self.assertThat(lambda: revert_item.enabled, Eventually(Equals(True)))
373319
=== modified file 'tests/autopilot/gallery_app/tests/test_photos_view.py'
--- tests/autopilot/gallery_app/tests/test_photos_view.py 2014-05-20 20:59:52 +0000
+++ tests/autopilot/gallery_app/tests/test_photos_view.py 2014-07-02 14:17:44 +0000
@@ -14,7 +14,6 @@
14from autopilot.platform import model14from autopilot.platform import model
1515
16from gallery_app.tests import GalleryTestCase16from gallery_app.tests import GalleryTestCase
17from gallery_app.emulators.photos_view import PhotosView
1817
19from time import sleep18from time import sleep
20from os import environ as env19from os import environ as env
@@ -24,12 +23,8 @@
24class TestPhotosView(GalleryTestCase):23class TestPhotosView(GalleryTestCase):
25 envDesktopMode = None24 envDesktopMode = None
2625
27 @property
28 def photos_view(self):
29 return PhotosView(self.app)
30
31 def setUp(self):26 def setUp(self):
32 self.ARGS = []27 self.args = []
33 self.envDesktopMode = env.get("DESKTOP_MODE")28 self.envDesktopMode = env.get("DESKTOP_MODE")
3429
35 if model() == "Desktop":30 if model() == "Desktop":
@@ -38,7 +33,7 @@
38 env["DESKTOP_MODE"] = "0"33 env["DESKTOP_MODE"] = "0"
3934
40 super(TestPhotosView, self).setUp()35 super(TestPhotosView, self).setUp()
41 self.switch_to_photos_tab()36 self.gallery_app.switch_to_photos_tab()
4237
43 def tearDown(self):38 def tearDown(self):
44 if self.envDesktopMode:39 if self.envDesktopMode:
@@ -48,82 +43,74 @@
4843
49 super(TestPhotosView, self).tearDown()44 super(TestPhotosView, self).tearDown()
5045
51 def switch_to_photos_tab(self):
52 self.main_view.switch_to_tab("photosTab")
53 self.ensure_tabs_dont_move()
54
55 def click_first_photo(self):
56 photo = self.photos_view.get_first_photo_in_photos_view()
57 self.click_item(photo)
58
59 def test_open_photo(self):46 def test_open_photo(self):
60 self.main_view.close_toolbar()47 self.gallery_app.main_view.close_toolbar()
61 self.click_first_photo()48 self.gallery_app.click_first_photo()
62 sleep(5)49 sleep(5)
63 photo_viewer = self.photos_view.get_main_photo_viewer()50 photo_viewer = self.gallery_app.photos_view.get_main_photo_viewer()
64 self.assertThat(photo_viewer.visible, Eventually(Equals(True)))51 self.assertThat(photo_viewer.visible, Eventually(Equals(True)))
6552
66 def test_select_button_cancel(self):53 def test_select_button_cancel(self):
67 """Clicking the cancel button after clicking the select button must54 """Clicking the cancel button after clicking the select button must
68 hide the toolbar automatically."""55 hide the toolbar automatically."""
69 photos_overview = self.app.select_single("PhotosOverview")56 photos_overview = self.gallery_app.app.select_single("PhotosOverview")
70 self.assertFalse(photos_overview.inSelectionMode)57 self.assertFalse(photos_overview.inSelectionMode)
7158
72 self.main_view.open_toolbar().click_button("selectButton")59 self.gallery_app.main_view.open_toolbar().click_button("selectButton")
73 self.assertTrue(photos_overview.inSelectionMode)60 self.assertTrue(photos_overview.inSelectionMode)
7461
75 self.main_view.open_toolbar().click_custom_button("cancelButton")62 self.gallery_app.main_view.open_toolbar().click_custom_button("cancelButton")
7663
77 toolbar = self.main_view.get_toolbar()64 toolbar = self.gallery_app.main_view.get_toolbar()
78 self.assertThat(toolbar.opened, Eventually(Equals(False)))65 self.assertThat(toolbar.opened, Eventually(Equals(False)))
79 self.assertFalse(photos_overview.inSelectionMode)66 self.assertFalse(photos_overview.inSelectionMode)
8067
81 first_photo = self.photos_view.get_first_photo_in_photos_view()68 first_photo = self.gallery_app.photos_view.get_first_photo_in_photos_view()
82 self.tap_item(first_photo)69 self.gallery_app.tap_item(first_photo)
83 self.assertTrue(photos_overview.inSelectionMode)70 self.assertTrue(photos_overview.inSelectionMode)
8471
85 def test_delete_photo_dialog_appears(self):72 def test_delete_photo_dialog_appears(self):
86 """Selecting a photo must make the delete button clickable."""73 """Selecting a photo must make the delete button clickable."""
87 self.main_view.open_toolbar().click_button("selectButton")74 self.gallery_app.main_view.open_toolbar().click_button("selectButton")
88 self.click_first_photo()75 self.gallery_app.click_first_photo()
89 self.main_view.open_toolbar().click_button("deleteButton")76 self.gallery_app.main_view.open_toolbar().click_button("deleteButton")
9077
91 self.assertThat(self.gallery_utils.delete_dialog_shown,78 self.assertThat(self.gallery_app.gallery_utils.delete_dialog_shown,
92 Eventually(Is(True)))79 Eventually(Is(True)))
9380
94 cancel_item = self.photos_view.get_delete_dialog_cancel_button()81 cancel_item = self.gallery_app.photos_view.get_delete_dialog_cancel_button()
95 self.click_item(cancel_item)82 self.gallery_app.click_item(cancel_item)
96 self.assertThat(self.gallery_utils.delete_dialog_shown,83 self.assertThat(self.gallery_app.gallery_utils.delete_dialog_shown,
97 Eventually(Is(False)))84 Eventually(Is(False)))
9885
99 def test_delete_a_photo(self):86 def test_delete_a_photo(self):
100 """Must be able to select a photo and use the dialog to delete it."""87 """Must be able to select a photo and use the dialog to delete it."""
101 number_of_photos = self.photos_view.number_of_photos()88 number_of_photos = self.gallery_app.photos_view.number_of_photos()
102 self.main_view.open_toolbar().click_button("selectButton")89 self.gallery_app.main_view.open_toolbar().click_button("selectButton")
103 self.click_first_photo()90 self.gallery_app.click_first_photo()
104 self.main_view.open_toolbar().click_button("deleteButton")91 self.gallery_app.main_view.open_toolbar().click_button("deleteButton")
10592
106 self.assertThat(self.gallery_utils.delete_dialog_shown,93 self.assertThat(self.gallery_app.gallery_utils.delete_dialog_shown,
107 Eventually(Is(True)))94 Eventually(Is(True)))
10895
109 self.main_view.open_toolbar().click_button("deleteButton")96 self.gallery_app.main_view.open_toolbar().click_button("deleteButton")
11097
111 delete_item = self.photos_view.get_delete_dialog_delete_button()98 delete_item = self.gallery_app.photos_view.get_delete_dialog_delete_button()
112 self.click_item(delete_item)99 self.gallery_app.click_item(delete_item)
113 self.assertThat(100 self.assertThat(
114 self.gallery_utils.delete_dialog_shown,101 self.gallery_app.gallery_utils.delete_dialog_shown,
115 Eventually(Is(False))102 Eventually(Is(False))
116 )103 )
117104
118 self.assertThat(lambda: self.photos_view.number_of_photos(),105 self.assertThat(lambda: self.gallery_app.photos_view.number_of_photos(),
119 Eventually(Equals(number_of_photos - 1)))106 Eventually(Equals(number_of_photos - 1)))
120107
121 @unittest.skip("Temporarily disable as it fails in some cases, "108 @unittest.skip("Temporarily disable as it fails in some cases, "
122 "supposedly due to problems with the infrastructure")109 "supposedly due to problems with the infrastructure")
123 def test_save_state(self):110 def test_save_state(self):
124 self.switch_to_photos_tab()111 self.gallery_app.switch_to_photos_tab()
125112
126 tabs = self.main_view.select_single("Tabs")113 tabs = self.gallery_app.main_view.select_single("Tabs")
127 tab = tabs.get_current_tab()114 tab = tabs.get_current_tab()
128 self.assertThat(tab.objectName, Equals("photosTab"))115 self.assertThat(tab.objectName, Equals("photosTab"))
129 index = tab.index116 index = tab.index
@@ -131,7 +118,7 @@
131 self.ensure_app_has_quit()118 self.ensure_app_has_quit()
132 self.start_app()119 self.start_app()
133120
134 tabs = self.main_view.select_single("Tabs")121 tabs = self.gallery_app.main_view.select_single("Tabs")
135 tab = tabs.get_current_tab()122 tab = tabs.get_current_tab()
136 self.assertThat(tabs.selectedTabIndex, Eventually(Equals(index)))123 self.assertThat(tabs.selectedTabIndex, Eventually(Equals(index)))
137 self.assertThat(tab.objectName, Equals("photosTab"))124 self.assertThat(tab.objectName, Equals("photosTab"))
@@ -141,8 +128,8 @@
141 'Key based tests only make sense on Desktop'128 'Key based tests only make sense on Desktop'
142 )129 )
143 def test_toggle_fullscreen(self):130 def test_toggle_fullscreen(self):
144 self.switch_to_photos_tab()131 self.gallery_app.switch_to_photos_tab()
145 view = self.main_view132 view = self.gallery_app.main_view
146 self.assertThat(view.fullScreen, Eventually(Equals(False)))133 self.assertThat(view.fullScreen, Eventually(Equals(False)))
147 self.keyboard.press_and_release('F11')134 self.keyboard.press_and_release('F11')
148 self.assertThat(view.fullScreen, Eventually(Equals(True)))135 self.assertThat(view.fullScreen, Eventually(Equals(True)))
@@ -157,8 +144,8 @@
157144
158 # Check if Camera Button is not visible at Desktop mode145 # Check if Camera Button is not visible at Desktop mode
159 def test_camera_button_visible(self):146 def test_camera_button_visible(self):
160 self.main_view.open_toolbar()147 self.gallery_app.main_view.open_toolbar()
161 toolbar = self.main_view.get_toolbar()148 toolbar = self.gallery_app.main_view.get_toolbar()
162 cameraButton = toolbar.select_single(149 cameraButton = toolbar.select_single(
163 "ActionItem",150 "ActionItem",
164 objectName="cameraButton"151 objectName="cameraButton"
165152
=== modified file 'tests/autopilot/gallery_app/tests/test_picker_mode.py'
--- tests/autopilot/gallery_app/tests/test_picker_mode.py 2014-05-21 16:02:19 +0000
+++ tests/autopilot/gallery_app/tests/test_picker_mode.py 2014-07-02 14:17:44 +0000
@@ -11,54 +11,43 @@
11from testtools.matchers import Equals11from testtools.matchers import Equals
12from autopilot.matchers import Eventually12from autopilot.matchers import Eventually
1313
14from gallery_app.emulators.picker_screen import PickerScreen14from gallery_app import GalleryApp
15from gallery_app.tests import GalleryTestCase15from gallery_app.tests import GalleryTestCase
16
16import unittest17import unittest
1718
18from unittest import skip19from unittest import skip
1920
20class TestPickerMode(GalleryTestCase):21class TestPickerMode(GalleryTestCase):
2122
22 @property
23 def picker_view(self):
24 return self.app.select_single(PickerScreen)
25
26 def setUp(self):23 def setUp(self):
27 self.ARGS.append("--pick-mode")24 self.args.append("--pick-mode")
28 super(TestPickerMode, self).setUp()25 super(TestPickerMode, self).setUp()
2926
30 def select_first_event_media(self):
31 first_media = self.picker_view.first_media_in_events_view()
32 self.click_item(first_media)
33
34 def select_first_grid_media(self):
35 first_media = self.picker_view.first_media_in_events_view()
36 self.click_item(first_media)
37
38 @unittest.skip("Temporarily disable as it fails in some cases, "27 @unittest.skip("Temporarily disable as it fails in some cases, "
39 "supposedly due to problems with the infrastructure")28 "supposedly due to problems with the infrastructure")
40 def test_pick_first_photo(self):29 def test_pick_first_photo(self):
41 """Check if the button enabled state follows the selection"""30 """Check if the button enabled state follows the selection"""
42 pick_button = self.picker_view.pick_button()31 pick_button = self.gallery_app.picker_view.pick_button()
43 self.assertThat(pick_button.enabled, Eventually(Equals(False)))32 self.assertThat(pick_button.enabled, Eventually(Equals(False)))
44 first_events_media = self.picker_view.first_media_in_events_view()33 first_events_media = self.gallery_app.picker_view.first_media_in_events_view()
45 self.assertThat(34 self.assertThat(
46 first_events_media.isSelected,35 first_events_media.isSelected,
47 Eventually(Equals(False))36 Eventually(Equals(False))
48 )37 )
4938
50 self.select_first_event_media()39 self.gallery_app.select_first_event_media()
5140
52 pick_button = self.picker_view.pick_button()41 pick_button = self.gallery_app.picker_view.pick_button()
53 self.assertThat(pick_button.enabled, Eventually(Equals(True)))42 self.assertThat(pick_button.enabled, Eventually(Equals(True)))
54 self.assertThat(43 self.assertThat(
55 first_events_media.isSelected,44 first_events_media.isSelected,
56 Eventually(Equals(True))45 Eventually(Equals(True))
57 )46 )
5847
59 self.select_first_event_media()48 self.gallery_app.select_first_event_media()
6049
61 pick_button = self.picker_view.pick_button()50 pick_button = self.gallery_app.picker_view.pick_button()
62 self.assertThat(pick_button.enabled, Eventually(Equals(False)))51 self.assertThat(pick_button.enabled, Eventually(Equals(False)))
63 self.assertThat(52 self.assertThat(
64 first_events_media.isSelected,53 first_events_media.isSelected,
@@ -68,14 +57,14 @@
68 @skip("Temporarily disable as it fails in some cases")57 @skip("Temporarily disable as it fails in some cases")
69 def test_pick_named_photo(self):58 def test_pick_named_photo(self):
70 """Select a named photo and press Pick button."""59 """Select a named photo and press Pick button."""
71 self.picker_view.switch_to_tab('photosTab')60 self.gallery_app.picker_view.switch_to_tab('photosTab')
72 pick_button = self.picker_view.pick_button()61 pick_button = self.gallery_app.picker_view.pick_button()
73 self.assertFalse(pick_button.enabled)62 self.assertFalse(pick_button.enabled)
7463
75 # create the image location path based on sample location64 # create the image location path based on sample location
76 image_path = 'image://thumbnailer/{}/sample02.jpg'.format(65 image_path = 'image://thumbnailer/{}/sample02.jpg'.format(
77 self.sample_destination_dir)66 self.sample_destination_dir)
78 self.picker_view.select_named_photo(image_path)67 self.gallery_app.picker_view.select_named_photo(image_path)
7968
80 self.assertTrue(pick_button.enabled)69 self.assertTrue(pick_button.enabled)
81 self.click_item(pick_button)70 self.click_item(pick_button)
@@ -84,38 +73,38 @@
84 "supposedly due to problems with the infrastructure")73 "supposedly due to problems with the infrastructure")
85 def test_selection_synchronisation(self):74 def test_selection_synchronisation(self):
86 """Checks if the selection is the same for both views"""75 """Checks if the selection is the same for both views"""
87 first_events_media = self.picker_view.first_media_in_events_view()76 first_events_media = self.gallery_app.picker_view.first_media_in_events_view()
88 self.assertThat(77 self.assertThat(
89 first_events_media.isSelected,78 first_events_media.isSelected,
90 Eventually(Equals(False))79 Eventually(Equals(False))
91 )80 )
9281
93 self.select_first_event_media()82 self.gallery_app.select_first_event_media()
94 self.assertThat(83 self.assertThat(
95 first_events_media.isSelected,84 first_events_media.isSelected,
96 Eventually(Equals(True))85 Eventually(Equals(True))
97 )86 )
9887
99 self.picker_view.switch_to_next_tab()88 self.gallery_app.picker_view.switch_to_next_tab()
10089
101 first_grid_media = self.picker_view.first_media_in_grid_view()90 first_grid_media = self.gallery_app.picker_view.first_media_in_grid_view()
102 self.assertThat(first_grid_media.isSelected, Eventually(Equals(True)))91 self.assertThat(first_grid_media.isSelected, Eventually(Equals(True)))
10392
104 @unittest.skip("Temporarily disable as it fails in some cases, "93 @unittest.skip("Temporarily disable as it fails in some cases, "
105 "supposedly due to problems with the infrastructure")94 "supposedly due to problems with the infrastructure")
106 def test_save_picker_state(self):95 def test_save_picker_state(self):
107 self.picker_view.switch_to_tab("photosTab")96 self.gallery_app.picker_view.switch_to_tab("photosTab")
108 self.ensure_tabs_dont_move()97 self.gallery_app.ensure_tabs_dont_move()
10998
110 tabs = self.picker_view.select_single("Tabs")99 tabs = self.gallery_app.picker_view.select_single("Tabs")
111 tab = tabs.get_current_tab()100 tab = tabs.get_current_tab()
112 self.assertThat(tab.objectName, Equals("photosTab"))101 self.assertThat(tab.objectName, Equals("photosTab"))
113 index = tab.index102 index = tab.index
114103
115 self.ensure_app_has_quit()104 self.gallery_app.ensure_app_has_quit()
116 self.start_app()105 self.start_app()
117106
118 tabs = self.picker_view.select_single("Tabs")107 tabs = self.gallery_app.picker_view.select_single("Tabs")
119 tab = tabs.get_current_tab()108 tab = tabs.get_current_tab()
120 self.assertThat(tabs.selectedTabIndex, Eventually(Equals(index)))109 self.assertThat(tabs.selectedTabIndex, Eventually(Equals(index)))
121 self.assertThat(tab.objectName, Equals("photosTab"))110 self.assertThat(tab.objectName, Equals("photosTab"))

Subscribers

People subscribed via source and target branches