69
69
objectName="contextMenuMobile")
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()
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()
106
def _launch_application(self, path):
101
108
self.launch_webcontainer_app_with_local_http_server(
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()
114
def _setup_overlay_webview_context_menu(self, path):
115
overlay_path = "/with-overlay-link?path={}".format(path)
116
self._launch_application(overlay_path)
118
popup_controller = self.get_popup_controller()
119
animation_watcher = popup_controller.watch_signal(
120
'windowOverlayOpenAnimationDone()')
121
animation_signal_emission = animation_watcher.num_emissions
123
self._click_window_open()
126
lambda: len(self.get_popup_overlay_views()),
127
Eventually(Equals(1)))
129
lambda: animation_watcher.num_emissions,
130
Eventually(GreaterThan(animation_signal_emission)))
132
self.webview = self.get_popup_overlay_views()[0].select_single(
133
objectName="overlayWebview")
134
self.menu = self._open_context_menu(self.webview)
136
def _setup_webview_context_menu(self, path):
137
self._launch_application("/{}".format(path))
139
self.webview = self.get_oxide_webview()
140
self.menu = self._open_context_menu(self.webview)
109
143
class TestContextMenuLink(TestContextMenuBase):
112
super(TestContextMenuLink, self).setUp(path="/with-external-link")
113
self.assertThat(self.menu.get_title_label().text,
114
Equals("http://www.ubuntu.com/"))
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))
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))
127
def test_copy_link(self):
155
def _test_copy_link(self):
128
156
self.menu.click_action("CopyLinkContextualAction")
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")
164
class TestContextMenuLinkOverlayWebView(TestContextMenuLink):
167
super(TestContextMenuLinkOverlayWebView, self).setUp()
168
self._setup_overlay_webview_context_menu("with-external-link")
170
def test_open_link_(self):
171
self._test_open_link_()
173
def test_copy_link(self):
174
self._test_copy_link()
176
@testtools.skipIf(model() == "Desktop", "on devices only")
177
def test_share_link(self):
178
self._test_share_link()
181
class TestContextMenuLinkMainWebView(TestContextMenuLink):
184
super(TestContextMenuLinkMainWebView, self).setUp()
185
self._setup_webview_context_menu("with-external-link")
187
def test_open_link_(self):
188
self._test_open_link_()
190
def test_copy_link(self):
191
self._test_copy_link()
193
@testtools.skipIf(model() == "Desktop", "on devices only")
194
def test_share_link(self):
195
self._test_share_link()
131
198
class TestContextMenuImage(TestContextMenuBase):
134
super(TestContextMenuImage, self).setUp(path="/image")
135
self.assertThat(self.menu.get_title_label().text,
136
StartsWith(self.data_uri_prefix))
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")
206
class TestContextMenuImageMainWebview(TestContextMenuImage):
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))
214
def test_copy_image(self):
215
self._test_copy_image()
218
class TestContextMenuImageOverlayWebView(TestContextMenuImage):
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))
226
def test_copy_image(self):
227
self._test_copy_image()
144
230
class TestContextMenuImageAndLink(TestContextMenuBase):
147
super(TestContextMenuImageAndLink, self).setUp(path="/imagelink")
148
self.assertThat(self.menu.get_title_label().text,
149
StartsWith(self.data_uri_prefix))
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))
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))
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")
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")
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")
257
class TestContextMenuImageAndLinkMainWebView(TestContextMenuImageAndLink):
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))
265
def test_open_link_in_webbrowser(self):
266
self._test_open_link_in_webbrowser()
268
@testtools.skipIf(model() == "Desktop", "on devices only")
269
def test_share_link(self):
270
self._test_share_link()
272
def test_copy_link(self):
273
self._test_copy_link()
275
def test_copy_image(self):
276
self._test_copy_image()
279
class TestContextMenuImageAndLinkOverlayWebView(TestContextMenuImageAndLink):
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))
287
def test_open_link_in_webbrowser(self):
288
self._test_open_link_in_webbrowser()
290
@testtools.skipIf(model() == "Desktop", "on devices only")
291
def test_share_link(self):
292
self._test_share_link()
294
def test_copy_link(self):
295
self._test_copy_link()
297
def test_copy_image(self):
298
self._test_copy_image()
173
301
@testtools.skipIf(model() != "Desktop", "on desktop only")
174
302
class TestContextMenuTextArea(TestContextMenuBase):
177
super(TestContextMenuTextArea, self).setUp(path="/textarea")
178
self.assertThat(self.menu.get_title_label().visible, Equals(False))
180
def test_actions(self):
304
def _test_actions(self):
181
305
actions = ["SelectAll",
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)
319
class TestContextMenuTextAreaMainWebView(TestContextMenuTextArea):
322
super(TestContextMenuTextAreaMainWebView, self).setUp()
323
self._setup_webview_context_menu("textarea")
324
self.assertThat(self.menu.get_title_label().visible, Equals(False))
326
def test_actions(self):
330
class TestContextMenuTextAreaOverlayWebView(TestContextMenuTextArea):
333
super(TestContextMenuTextAreaOverlayWebView, self).setUp()
334
self._setup_overlay_webview_context_menu("textarea")
335
self.assertThat(self.menu.get_title_label().visible, Equals(False))
337
def test_actions(self):