~phablet-team/webbrowser-app/trunk

« back to all changes in this revision

Viewing changes to tests/autopilot/webapp_container/tests/test_context_menu.py

  • Committer: Olivier Tilloy
  • Date: 2016-03-10 05:56:42 UTC
  • mfrom: (1378 webbrowser-app)
  • mto: This revision was merged to the branch mainline in revision 1380.
  • Revision ID: olivier.tilloy@canonical.com-20160310055642-gcuwehtae8uq8hyr
Merge the latest changes from trunk and resolve conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from autopilot.platform import model
20
20
from autopilot.matchers import Eventually
21
21
import testtools
22
 
from testtools.matchers import Equals, StartsWith
 
22
from testtools.matchers import Equals, GreaterThan, StartsWith
23
23
 
24
24
from webapp_container.tests import WebappContainerTestCaseWithLocalContentBase
25
25
 
68
68
                ContextMenuMobile,
69
69
                objectName="contextMenuMobile")
70
70
 
71
 
    def _open_context_menu(self):
72
 
        webview = self.get_webview()
73
 
        x = webview.globalRect.x + webview.globalRect.width // 2
74
 
        y = webview.globalRect.y + webview.globalRect.height // 2
 
71
    def _open_context_menu(self, webview):
 
72
        gr = webview.globalRect
 
73
        x = gr.x + webview.width // 2
 
74
        y = gr.y + webview.height // 2
75
75
        self.pointing_device.move(x, y)
76
76
        if model() == 'Desktop':
77
77
            self.pointing_device.click(button=3)
95
95
            menu.click_cancel_action()
96
96
        menu.wait_until_destroyed()
97
97
 
98
 
    def setUp(self, path):
99
 
        super(TestContextMenuBase, self).setUp()
 
98
    def _click_window_open(self):
 
99
        webview = self.get_oxide_webview()
 
100
        gr = webview.globalRect
 
101
        self.pointing_device.move(
 
102
            gr.x + webview.width*3/4,
 
103
            gr.y + webview.height*3/4)
 
104
        self.pointing_device.click()
 
105
 
 
106
    def _launch_application(self, path):
100
107
        args = []
101
108
        self.launch_webcontainer_app_with_local_http_server(
102
109
            args,
103
110
            path,
104
111
            {'WEBAPP_CONTAINER_BLOCK_OPEN_URL_EXTERNALLY': '1'})
105
112
        self.get_webcontainer_window().visible.wait_for(True)
106
 
        self.menu = self._open_context_menu()
 
113
 
 
114
    def _setup_overlay_webview_context_menu(self, path):
 
115
        overlay_path = "/with-overlay-link?path={}".format(path)
 
116
        self._launch_application(overlay_path)
 
117
 
 
118
        popup_controller = self.get_popup_controller()
 
119
        animation_watcher = popup_controller.watch_signal(
 
120
            'windowOverlayOpenAnimationDone()')
 
121
        animation_signal_emission = animation_watcher.num_emissions
 
122
 
 
123
        self._click_window_open()
 
124
 
 
125
        self.assertThat(
 
126
            lambda: len(self.get_popup_overlay_views()),
 
127
            Eventually(Equals(1)))
 
128
        self.assertThat(
 
129
            lambda: animation_watcher.num_emissions,
 
130
            Eventually(GreaterThan(animation_signal_emission)))
 
131
 
 
132
        self.webview = self.get_popup_overlay_views()[0].select_single(
 
133
            objectName="overlayWebview")
 
134
        self.menu = self._open_context_menu(self.webview)
 
135
 
 
136
    def _setup_webview_context_menu(self, path):
 
137
        self._launch_application("/{}".format(path))
 
138
 
 
139
        self.webview = self.get_oxide_webview()
 
140
        self.menu = self._open_context_menu(self.webview)
107
141
 
108
142
 
109
143
class TestContextMenuLink(TestContextMenuBase):
110
144
 
111
 
    def setUp(self):
112
 
        super(TestContextMenuLink, self).setUp(path="/with-external-link")
113
 
        self.assertThat(self.menu.get_title_label().text,
114
 
                        Equals("http://www.ubuntu.com/"))
115
 
 
116
 
    def test_open_link_(self):
117
 
        main_webview = self.get_oxide_webview()
118
 
        signal = main_webview.watch_signal(
119
 
            'openExternalUrlTriggered(QString)')
 
145
    def _test_open_link_(self):
 
146
        signal = self.webview.watch_signal(
 
147
            'openUrlExternallyRequested(QString)')
120
148
        self.assertThat(signal.was_emitted, Equals(False))
121
149
 
122
150
        self.menu.click_action("OpenLinkInWebBrowser")
124
152
        self.assertThat(lambda: signal.was_emitted, Eventually(Equals(True)))
125
153
        self.assertThat(signal.num_emissions, Equals(1))
126
154
 
127
 
    def test_copy_link(self):
 
155
    def _test_copy_link(self):
128
156
        self.menu.click_action("CopyLinkContextualAction")
129
157
 
 
158
    @testtools.skipIf(model() == "Desktop", "on devices only")
 
159
    def _test_share_link(self):
 
160
        self.menu.click_action("ShareContextualAction")
 
161
        self.app.wait_select_single("ContentShareDialog")
 
162
 
 
163
 
 
164
class TestContextMenuLinkOverlayWebView(TestContextMenuLink):
 
165
 
 
166
    def setUp(self):
 
167
        super(TestContextMenuLinkOverlayWebView, self).setUp()
 
168
        self._setup_overlay_webview_context_menu("with-external-link")
 
169
 
 
170
    def test_open_link_(self):
 
171
        self._test_open_link_()
 
172
 
 
173
    def test_copy_link(self):
 
174
        self._test_copy_link()
 
175
 
 
176
    @testtools.skipIf(model() == "Desktop", "on devices only")
 
177
    def test_share_link(self):
 
178
        self._test_share_link()
 
179
 
 
180
 
 
181
class TestContextMenuLinkMainWebView(TestContextMenuLink):
 
182
 
 
183
    def setUp(self):
 
184
        super(TestContextMenuLinkMainWebView, self).setUp()
 
185
        self._setup_webview_context_menu("with-external-link")
 
186
 
 
187
    def test_open_link_(self):
 
188
        self._test_open_link_()
 
189
 
 
190
    def test_copy_link(self):
 
191
        self._test_copy_link()
 
192
 
 
193
    @testtools.skipIf(model() == "Desktop", "on devices only")
 
194
    def test_share_link(self):
 
195
        self._test_share_link()
 
196
 
130
197
 
131
198
class TestContextMenuImage(TestContextMenuBase):
132
199
 
133
 
    def setUp(self):
134
 
        super(TestContextMenuImage, self).setUp(path="/image")
135
 
        self.assertThat(self.menu.get_title_label().text,
136
 
                        StartsWith(self.data_uri_prefix))
137
 
 
138
 
    def test_copy_image(self):
 
200
    def _test_copy_image(self):
139
201
        # There is no easy way to test the contents of the clipboard,
140
202
        # but we can at least verify that the context menu was dismissed.
141
203
        self.menu.click_action("CopyImageContextualAction")
142
204
 
143
205
 
 
206
class TestContextMenuImageMainWebview(TestContextMenuImage):
 
207
 
 
208
    def setUp(self):
 
209
        super(TestContextMenuImageMainWebview, self).setUp()
 
210
        self._setup_webview_context_menu("image")
 
211
        self.assertThat(self.menu.get_title_label().text,
 
212
                        StartsWith(self.data_uri_prefix))
 
213
 
 
214
    def test_copy_image(self):
 
215
        self._test_copy_image()
 
216
 
 
217
 
 
218
class TestContextMenuImageOverlayWebView(TestContextMenuImage):
 
219
 
 
220
    def setUp(self):
 
221
        super(TestContextMenuImageOverlayWebView, self).setUp()
 
222
        self._setup_overlay_webview_context_menu("image")
 
223
        self.assertThat(self.menu.get_title_label().text,
 
224
                        StartsWith(self.data_uri_prefix))
 
225
 
 
226
    def test_copy_image(self):
 
227
        self._test_copy_image()
 
228
 
 
229
 
144
230
class TestContextMenuImageAndLink(TestContextMenuBase):
145
231
 
146
 
    def setUp(self):
147
 
        super(TestContextMenuImageAndLink, self).setUp(path="/imagelink")
148
 
        self.assertThat(self.menu.get_title_label().text,
149
 
                        StartsWith(self.data_uri_prefix))
150
 
 
151
 
    def test_open_link_in_webbrowser(self):
152
 
        main_webview = self.get_oxide_webview()
153
 
        signal = main_webview.watch_signal(
154
 
            'openExternalUrlTriggered(QString)')
 
232
    def _test_open_link_in_webbrowser(self):
 
233
        signal = self.webview.watch_signal(
 
234
            'openUrlExternallyRequested(QString)')
155
235
        self.assertThat(signal.was_emitted, Equals(False))
156
236
 
157
237
        self.menu.click_action("OpenLinkInWebBrowser")
159
239
        self.assertThat(lambda: signal.was_emitted, Eventually(Equals(True)))
160
240
        self.assertThat(signal.num_emissions, Equals(1))
161
241
 
162
 
    def test_copy_link(self):
 
242
    def _test_share_link(self):
 
243
        self.menu.click_action("ShareContextualAction")
 
244
        self.app.wait_select_single("ContentShareDialog")
 
245
 
 
246
    def _test_copy_link(self):
163
247
        # There is no easy way to test the contents of the clipboard,
164
248
        # but we can at least verify that the context menu was dismissed.
165
249
        self.menu.click_action("CopyLinkContextualAction")
166
250
 
167
 
    def test_copy_image(self):
 
251
    def _test_copy_image(self):
168
252
        # There is no easy way to test the contents of the clipboard,
169
253
        # but we can at least verify that the context menu was dismissed.
170
254
        self.menu.click_action("CopyImageContextualAction")
171
255
 
172
256
 
 
257
class TestContextMenuImageAndLinkMainWebView(TestContextMenuImageAndLink):
 
258
 
 
259
    def setUp(self):
 
260
        super(TestContextMenuImageAndLinkMainWebView, self).setUp()
 
261
        self._setup_webview_context_menu("imagelink")
 
262
        self.assertThat(self.menu.get_title_label().text,
 
263
                        StartsWith(self.data_uri_prefix))
 
264
 
 
265
    def test_open_link_in_webbrowser(self):
 
266
        self._test_open_link_in_webbrowser()
 
267
 
 
268
    @testtools.skipIf(model() == "Desktop", "on devices only")
 
269
    def test_share_link(self):
 
270
        self._test_share_link()
 
271
 
 
272
    def test_copy_link(self):
 
273
        self._test_copy_link()
 
274
 
 
275
    def test_copy_image(self):
 
276
        self._test_copy_image()
 
277
 
 
278
 
 
279
class TestContextMenuImageAndLinkOverlayWebView(TestContextMenuImageAndLink):
 
280
 
 
281
    def setUp(self):
 
282
        super(TestContextMenuImageAndLinkOverlayWebView, self).setUp()
 
283
        self._setup_overlay_webview_context_menu("imagelink")
 
284
        self.assertThat(self.menu.get_title_label().text,
 
285
                        StartsWith(self.data_uri_prefix))
 
286
 
 
287
    def test_open_link_in_webbrowser(self):
 
288
        self._test_open_link_in_webbrowser()
 
289
 
 
290
    @testtools.skipIf(model() == "Desktop", "on devices only")
 
291
    def test_share_link(self):
 
292
        self._test_share_link()
 
293
 
 
294
    def test_copy_link(self):
 
295
        self._test_copy_link()
 
296
 
 
297
    def test_copy_image(self):
 
298
        self._test_copy_image()
 
299
 
 
300
 
173
301
@testtools.skipIf(model() != "Desktop", "on desktop only")
174
302
class TestContextMenuTextArea(TestContextMenuBase):
175
303
 
176
 
    def setUp(self):
177
 
        super(TestContextMenuTextArea, self).setUp(path="/textarea")
178
 
        self.assertThat(self.menu.get_title_label().visible, Equals(False))
179
 
 
180
 
    def test_actions(self):
 
304
    def _test_actions(self):
181
305
        actions = ["SelectAll",
182
306
                   "Cut",
183
307
                   "Undo",
188
312
                   "Erase"]
189
313
        for action in actions:
190
314
            self.menu.click_action("{}ContextualAction".format(action))
191
 
            self.menu = self._open_context_menu()
 
315
            webview = self.get_webview()
 
316
            self.menu = self._open_context_menu(webview)
 
317
 
 
318
 
 
319
class TestContextMenuTextAreaMainWebView(TestContextMenuTextArea):
 
320
 
 
321
    def setUp(self):
 
322
        super(TestContextMenuTextAreaMainWebView, self).setUp()
 
323
        self._setup_webview_context_menu("textarea")
 
324
        self.assertThat(self.menu.get_title_label().visible, Equals(False))
 
325
 
 
326
    def test_actions(self):
 
327
        self._test_actions()
 
328
 
 
329
 
 
330
class TestContextMenuTextAreaOverlayWebView(TestContextMenuTextArea):
 
331
 
 
332
    def setUp(self):
 
333
        super(TestContextMenuTextAreaOverlayWebView, self).setUp()
 
334
        self._setup_overlay_webview_context_menu("textarea")
 
335
        self.assertThat(self.menu.get_title_label().visible, Equals(False))
 
336
 
 
337
    def test_actions(self):
 
338
        self._test_actions()