~elopio/gallery-app/revert_workaround-1302706-click_toolbar_button_failure

« back to all changes in this revision

Viewing changes to tests/autopilot/gallery_app/tests/test_album_view.py

  • Committer: Leo Arias
  • Date: 2015-05-15 08:05:23 UTC
  • mfrom: (954.1.241 gallery-app)
  • Revision ID: leo.arias@canonical.com-20150515080523-i2of3vr8h7dioj59
Now the toolbar object is not needed at all.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
 
# Copyright 2013 Canonical
 
2
# Copyright 2013-2015 Canonical
3
3
#
4
4
# This program is free software: you can redistribute it and/or modify it
5
5
# under the terms of the GNU General Public License version 3, as published
8
8
 
9
9
"""Tests the album view of the gallery app"""
10
10
 
11
 
from __future__ import absolute_import
12
 
 
13
11
from testtools.matchers import Equals, GreaterThan, LessThan
14
12
from autopilot.matchers import Eventually
15
13
 
16
14
from gallery_app.emulators.album_view import AlbumView
17
15
from gallery_app.emulators.albums_view import AlbumsView
18
16
from gallery_app.emulators.media_selector import MediaSelector
 
17
from gallery_app.emulators.photo_viewer import PhotoViewer
19
18
from gallery_app.emulators import album_editor
20
19
from gallery_app.tests import GalleryTestCase
21
20
 
 
21
import os
 
22
from time import sleep
22
23
from unittest import skip
23
24
 
24
25
 
37
38
    def media_selector(self):
38
39
        return MediaSelector(self.app)
39
40
 
 
41
    @property
 
42
    def photo_viewer(self):
 
43
        return PhotoViewer(self.app)
 
44
 
40
45
    def setUp(self):
41
46
        self.ARGS = []
42
47
        super(TestAlbumView, self).setUp()
43
48
        self.switch_to_albums_tab()
44
49
 
45
 
    def ensure_media_selector_is_fully_open(self):
46
 
        media_selector = self.media_selector.get_media_selector()
47
 
        self.assertThat(media_selector.opacity, Eventually(Equals(1.0)))
48
 
 
49
 
    def ensure_media_selector_is_fully_closed(self):
50
 
        loader = self.album_view.media_selector_loader()
51
 
        self.assertThat(loader.status, Eventually(Equals(0)))
52
 
 
53
50
    def test_album_view_open_photo(self):
54
 
        self.main_view.close_toolbar()
55
51
        self.open_first_album()
56
 
        self.main_view.close_toolbar()
57
52
        photo = self.album_view.get_first_photo()
58
 
        # workaround lp:1247698
59
 
        self.main_view.close_toolbar()
60
53
        self.click_item(photo)
61
 
        photo_view = self.album_view.get_album_photo_view()
 
54
        sleep(5)
 
55
        photo_view = self.main_view.wait_select_single("PopupPhotoViewer")
62
56
        self.assertThat(photo_view.visible, Eventually(Equals(True)))
63
 
        self.assertThat(photo_view.isPoppedUp, Eventually(Equals(True)))
64
57
 
65
58
    def test_album_view_flipping(self):
66
 
        self.main_view.close_toolbar()
67
 
 
68
59
        # For some reason here the album at position 0 in the autopilot list is
69
60
        # actually the second album, they seem to be returned in reverse order.
70
 
        self.open_album_at(0)
71
 
        self.main_view.close_toolbar()
 
61
        self.open_album_at(1)
72
62
 
73
 
        album = self.album_view.get_album_view()
74
63
        spread = self.album_view.get_spread_view()
75
64
 
76
 
        self.assertThat(album.animationRunning, Eventually(Equals(False)))
77
 
        self.assertThat(spread.viewingPage, Eventually(Equals(1)))
78
 
        self.main_view.close_toolbar()
79
 
 
80
 
        x, y, w, h = spread.globalRect
81
 
        mid_y = y + h / 2
82
 
        mid_x = x + w / 2
83
 
 
84
65
        # check that we can page to the cover and back (we check for lesser
85
66
        # than 1 because it can either be 0 if we are on a one page spread
86
67
        # or -1 if we are on a two page spread, for example on desktop)
87
 
        self.pointing_device.drag(mid_x - mid_x / 2, mid_y, x + w - 10, mid_y)
88
 
        animview = self.album_view.get_animated_album_view()
 
68
        self.album_view.swipe_page_left(1)
89
69
        self.assertThat(spread.viewingPage, Eventually(LessThan(1)))
90
 
        self.pointing_device.drag(mid_x + mid_x / 2, mid_y, x + 10, mid_y)
91
 
        animview = self.album_view.get_animated_album_view()
 
70
        self.album_view.swipe_page_right(0)
92
71
        self.assertThat(spread.viewingPage, Eventually(Equals(1)))
93
72
 
94
73
        # drag to next page and check we have flipped away from page 1
95
74
        # can't check precisely for page 2 because depending on form factor
96
75
        # and orientation we might be displaying two pages at the same time
97
 
        self.pointing_device.drag(mid_x + mid_x / 2, mid_y, x + 10, mid_y)
98
 
        self.assertThat(album.animationRunning, Eventually(Equals(False)))
 
76
        self.album_view.swipe_page_right(1)
99
77
        self.assertThat(spread.viewingPage, Eventually(GreaterThan(1)))
100
78
 
101
79
    def test_add_photo(self):
102
 
        self.main_view.close_toolbar()
103
80
        self.open_first_album()
104
81
        num_photos_start = self.album_view.number_of_photos()
105
82
        self.assertThat(num_photos_start, Equals(1))
106
83
 
 
84
        # should click away of any photo to toggle header
 
85
        photo = self.album_view.get_first_photo()
 
86
        x, y, w, h = photo.globalRect
 
87
        self.pointing_device.move(x + 40, y + h + 40)
 
88
        self.pointing_device.click()
 
89
 
107
90
        # open media selector but cancel
108
 
        self.main_view.open_toolbar().click_button("addButton")
109
 
        self.ensure_media_selector_is_fully_open()
 
91
        self.main_view.get_header().click_action_button("addButton")
 
92
        self.media_selector.ensure_fully_open()
110
93
 
111
 
        self.main_view.get_toolbar().click_custom_button("cancelButton")
112
 
        self.ensure_media_selector_is_fully_closed()
 
94
        self.main_view.get_header().click_custom_back_button()
 
95
        sleep(1)
113
96
 
114
97
        num_photos = self.album_view.number_of_photos()
115
98
        self.assertThat(num_photos, Equals(num_photos_start))
116
99
 
117
100
        # open media selector and add a photo
118
 
        self.main_view.open_toolbar().click_button("addButton")
119
 
        self.ensure_media_selector_is_fully_open()
 
101
        self.main_view.get_header().click_action_button("addButton")
 
102
        self.media_selector.ensure_fully_open()
120
103
 
121
104
        photo = self.media_selector.get_second_photo()
122
 
        self.click_item(photo)
123
 
        self.main_view.get_toolbar().click_custom_button("addButton")
 
105
        checkbox = photo.select_single(objectName="selectionCheckbox")
 
106
        self.click_item(checkbox)
 
107
        self.main_view.get_header().click_action_button("addButton")
124
108
 
125
109
        self.assertThat(
126
110
            lambda: self.album_view.number_of_photos(),
127
111
            Eventually(Equals(num_photos_start + 1)))
128
112
 
129
 
    @skip("UnicodeEncodeError: 'ascii' codec can't encode character u'xa2'")
 
113
    def test_remove_photo_from_album(self):
 
114
        self.open_first_album()
 
115
        num_photos_start = self.album_view.number_of_photos()
 
116
        self.assertThat(num_photos_start, Equals(1))
 
117
 
 
118
        path = self.album_view.click_first_photo()
 
119
 
 
120
        self.assertThat(lambda: os.path.exists(path),
 
121
                        Eventually(Equals(True)))
 
122
 
 
123
        photo_view = self.album_view.get_album_photo_view()
 
124
        self.assertThat(photo_view.visible, Eventually(Equals(True)))
 
125
 
 
126
        self.main_view.get_header().click_action_button("deleteButton")
 
127
        self.album_view.click_remove_from_album_remove_button()
 
128
 
 
129
        self.assertThat(lambda: self.album_view.number_of_photos(),
 
130
                        Eventually(Equals(num_photos_start - 1)))
 
131
 
 
132
        self.assertThat(lambda: os.path.exists(path),
 
133
                        Eventually(Equals(True)))
 
134
 
 
135
    def test_remove_photo_from_album_and_delete(self):
 
136
        self.open_first_album()
 
137
        num_photos_start = self.album_view.number_of_photos()
 
138
        self.assertThat(num_photos_start, Equals(1))
 
139
 
 
140
        path = self.album_view.click_first_photo()
 
141
 
 
142
        self.assertThat(lambda: os.path.exists(path),
 
143
                        Eventually(Equals(True)))
 
144
 
 
145
        photo_view = self.album_view.get_album_photo_view()
 
146
        self.assertThat(photo_view.visible, Eventually(Equals(True)))
 
147
 
 
148
        self.main_view.get_header().click_action_button("deleteButton")
 
149
        self.album_view.click_remove_from_album_delete_button()
 
150
 
 
151
        self.assertThat(lambda: self.album_view.number_of_photos(),
 
152
                        Eventually(Equals(num_photos_start - 1)))
 
153
 
 
154
        self.assertThat(lambda: os.path.exists(path),
 
155
                        Eventually(Equals(False)))
 
156
 
 
157
    def test_cancel_remove_photo_from_album(self):
 
158
        self.open_first_album()
 
159
        num_photos_start = self.album_view.number_of_photos()
 
160
        self.assertThat(num_photos_start, Equals(1))
 
161
 
 
162
        path = self.album_view.click_first_photo()
 
163
 
 
164
        self.assertThat(lambda: os.path.exists(path),
 
165
                        Eventually(Equals(True)))
 
166
 
 
167
        photo_view = self.album_view.get_album_photo_view()
 
168
        self.assertThat(photo_view.visible, Eventually(Equals(True)))
 
169
 
 
170
        self.main_view.get_header().click_action_button("deleteButton")
 
171
        self.album_view.click_remove_from_album_cancel_button()
 
172
 
 
173
        self.main_view.get_header().click_custom_back_button()
 
174
 
 
175
        self.assertThat(lambda: self.album_view.number_of_photos(),
 
176
                        Eventually(Equals(num_photos_start)))
 
177
 
 
178
        self.assertThat(lambda: os.path.exists(path),
 
179
                        Eventually(Equals(True)))
 
180
 
130
181
    def test_add_photo_to_new_album(self):
131
 
        self.main_view.open_toolbar().click_button("addButton")
 
182
        self.main_view.get_header().click_action_button("addButton")
132
183
        self.ui_update()
133
184
 
134
 
        editor = self.app.select_single(album_editor.AlbumEditorAnimated)
 
185
        editor = self.app.select_single(album_editor.AlbumEditor)
135
186
        editor.ensure_fully_open()
136
 
        self.main_view.close_toolbar()
137
187
        editor.close()
138
188
 
139
 
        self.open_first_album()
140
 
        self.main_view.close_toolbar()
141
189
        num_photos_start = self.album_view.number_of_photos()
142
190
        self.assertThat(num_photos_start, Equals(0))
143
191
 
144
192
        plus = self.album_view.get_plus_icon_empty_album()
145
 
        # workaround lp:1247698
146
 
        self.main_view.close_toolbar()
147
193
        self.click_item(plus)
148
 
        self.ensure_media_selector_is_fully_open()
 
194
        self.media_selector.ensure_fully_open()
149
195
 
150
196
        photo = self.media_selector.get_second_photo()
151
 
        self.click_item(photo)
152
 
        self.main_view.get_toolbar().click_custom_button("addButton")
 
197
        checkbox = photo.select_single(objectName="selectionCheckbox")
 
198
        self.click_item(checkbox)
 
199
        self.main_view.get_header().click_action_button("addButton")
153
200
 
 
201
        self.open_first_album()
154
202
        self.assertThat(
155
203
            lambda: self.album_view.number_of_photos(),
156
204
            Eventually(Equals(num_photos_start + 1)))