This file is indexed.

/usr/lib/python3/dist-packages/webapp_container/tests/test_context_menu.py is in webapp-container-autopilot 0.23+16.04.20160413-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
#
# Copyright 2015-2016 Canonical
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import time

from autopilot.platform import model
from autopilot.matchers import Eventually
import testtools
from testtools.matchers import Equals, GreaterThan, StartsWith

from webapp_container.tests import WebappContainerTestCaseWithLocalContentBase

import ubuntuuitoolkit as uitk


class ContextMenuBase(uitk.UbuntuUIToolkitCustomProxyObjectBase):
    def get_title_label(self):
        return self.select_single(objectName="titleLabel")

    def get_visible_actions(self):
        return self.select_many("Empty", visible=True)

    def get_action(self, objectName):
        name = objectName + "_item"
        return self.select_single("Empty", objectName=name)

    def click_action(self, objectName):
        name = objectName + "_item"
        action = self.select_single("Empty", visible=True,
                                    enabled=True, objectName=name)
        self.pointing_device.click_object(action)
        self.wait_until_destroyed()


class ContextMenuWide(ContextMenuBase):
    pass


class ContextMenuMobile(ContextMenuBase):
    def click_cancel_action(self):
        action = self.select_single("Empty", objectName="cancelAction")
        self.pointing_device.click_object(action)


class TestContextMenuBase(WebappContainerTestCaseWithLocalContentBase):
    data_uri_prefix = "data:image/png;base64,"

    def _get_context_menu(self):
        if self.get_webcontainer_webview().wide:
            return self.app.wait_select_single(
                ContextMenuWide,
                objectName="contextMenuWide")
        else:
            return self.app.wait_select_single(
                ContextMenuMobile,
                objectName="contextMenuMobile")

    def _open_context_menu(self, webview):
        gr = webview.globalRect
        x = gr.x + webview.width // 2
        y = gr.y + webview.height // 2
        self.pointing_device.move(x, y)
        if model() == 'Desktop':
            self.pointing_device.click(button=3)
        else:
            self.pointing_device.press()
            time.sleep(1.5)
            self.pointing_device.release()
        return self._get_context_menu()

    def _dismiss_context_menu(self, menu):
        if self.get_webcontainer_webview().wide:
            # Dismiss by clicking outside of the menu
            webview_rect = self.get_webview().globalRect
            actions = menu.get_visible_actions()
            outside_x = (webview_rect.x + actions[0].globalRect.x) // 2
            outside_y = webview_rect.y + webview_rect.height // 2
            self.pointing_device.move(outside_x, outside_y)
            self.pointing_device.click()
        else:
            # Dismiss by clicking the cancel action
            menu.click_cancel_action()
        menu.wait_until_destroyed()

    def _click_window_open(self):
        webview = self.get_oxide_webview()
        gr = webview.globalRect
        self.pointing_device.move(
            gr.x + webview.width*3/4,
            gr.y + webview.height*3/4)
        self.pointing_device.click()

    def _launch_application(self, path):
        args = []
        self.launch_webcontainer_app_with_local_http_server(
            args,
            path,
            {'WEBAPP_CONTAINER_BLOCK_OPEN_URL_EXTERNALLY': '1'})
        self.get_webcontainer_window().visible.wait_for(True)

    def _setup_overlay_webview_context_menu(self, path):
        overlay_path = "/with-overlay-link?path={}".format(path)
        self._launch_application(overlay_path)

        popup_controller = self.get_popup_controller()
        animation_watcher = popup_controller.watch_signal(
            'windowOverlayOpenAnimationDone()')
        animation_signal_emission = animation_watcher.num_emissions

        self._click_window_open()

        self.assertThat(
            lambda: len(self.get_popup_overlay_views()),
            Eventually(Equals(1)))
        self.assertThat(
            lambda: animation_watcher.num_emissions,
            Eventually(GreaterThan(animation_signal_emission)))

        self.webview = self.get_popup_overlay_views()[0].select_single(
            objectName="overlayWebview")
        self.menu = self._open_context_menu(self.webview)

    def _setup_webview_context_menu(self, path):
        self._launch_application("/{}".format(path))

        self.webview = self.get_oxide_webview()
        self.menu = self._open_context_menu(self.webview)


class TestContextMenuLink(TestContextMenuBase):

    def _test_open_link_(self):
        signal = self.webview.watch_signal(
            'openUrlExternallyRequested(QString)')
        self.assertThat(signal.was_emitted, Equals(False))

        self.menu.click_action("OpenLinkInWebBrowser")

        self.assertThat(lambda: signal.was_emitted, Eventually(Equals(True)))
        self.assertThat(signal.num_emissions, Equals(1))

    def _test_copy_link(self):
        self.menu.click_action("CopyLinkContextualAction")

    @testtools.skipIf(model() == "Desktop", "on devices only")
    def _test_share_link(self):
        self.menu.click_action("ShareContextualAction")
        self.app.wait_select_single("ContentShareDialog")


class TestContextMenuLinkOverlayWebView(TestContextMenuLink):

    def setUp(self):
        super(TestContextMenuLinkOverlayWebView, self).setUp()
        self._setup_overlay_webview_context_menu("with-external-link")

    def test_open_link_(self):
        self._test_open_link_()

    def test_copy_link(self):
        self._test_copy_link()

    @testtools.skipIf(model() == "Desktop", "on devices only")
    def test_share_link(self):
        self._test_share_link()


class TestContextMenuLinkMainWebView(TestContextMenuLink):

    def setUp(self):
        super(TestContextMenuLinkMainWebView, self).setUp()
        self._setup_webview_context_menu("with-external-link")

    def test_open_link_(self):
        self._test_open_link_()

    def test_copy_link(self):
        self._test_copy_link()

    @testtools.skipIf(model() == "Desktop", "on devices only")
    def test_share_link(self):
        self._test_share_link()


class TestContextMenuImage(TestContextMenuBase):

    def _test_copy_image(self):
        # There is no easy way to test the contents of the clipboard,
        # but we can at least verify that the context menu was dismissed.
        self.menu.click_action("CopyImageContextualAction")


class TestContextMenuImageMainWebview(TestContextMenuImage):

    def setUp(self):
        super(TestContextMenuImageMainWebview, self).setUp()
        self._setup_webview_context_menu("image")
        self.assertThat(self.menu.get_title_label().text,
                        StartsWith(self.data_uri_prefix))

    def test_copy_image(self):
        self._test_copy_image()


class TestContextMenuImageOverlayWebView(TestContextMenuImage):

    def setUp(self):
        super(TestContextMenuImageOverlayWebView, self).setUp()
        self._setup_overlay_webview_context_menu("image")
        self.assertThat(self.menu.get_title_label().text,
                        StartsWith(self.data_uri_prefix))

    def test_copy_image(self):
        self._test_copy_image()


class TestContextMenuImageAndLink(TestContextMenuBase):

    def _test_open_link_in_webbrowser(self):
        signal = self.webview.watch_signal(
            'openUrlExternallyRequested(QString)')
        self.assertThat(signal.was_emitted, Equals(False))

        self.menu.click_action("OpenLinkInWebBrowser")

        self.assertThat(lambda: signal.was_emitted, Eventually(Equals(True)))
        self.assertThat(signal.num_emissions, Equals(1))

    def _test_share_link(self):
        self.menu.click_action("ShareContextualAction")
        self.app.wait_select_single("ContentShareDialog")

    def _test_copy_link(self):
        # There is no easy way to test the contents of the clipboard,
        # but we can at least verify that the context menu was dismissed.
        self.menu.click_action("CopyLinkContextualAction")

    def _test_copy_image(self):
        # There is no easy way to test the contents of the clipboard,
        # but we can at least verify that the context menu was dismissed.
        self.menu.click_action("CopyImageContextualAction")


class TestContextMenuImageAndLinkMainWebView(TestContextMenuImageAndLink):

    def setUp(self):
        super(TestContextMenuImageAndLinkMainWebView, self).setUp()
        self._setup_webview_context_menu("imagelink")
        self.assertThat(self.menu.get_title_label().text,
                        StartsWith(self.data_uri_prefix))

    def test_open_link_in_webbrowser(self):
        self._test_open_link_in_webbrowser()

    @testtools.skipIf(model() == "Desktop", "on devices only")
    def test_share_link(self):
        self._test_share_link()

    def test_copy_link(self):
        self._test_copy_link()

    def test_copy_image(self):
        self._test_copy_image()


class TestContextMenuImageAndLinkOverlayWebView(TestContextMenuImageAndLink):

    def setUp(self):
        super(TestContextMenuImageAndLinkOverlayWebView, self).setUp()
        self._setup_overlay_webview_context_menu("imagelink")
        self.assertThat(self.menu.get_title_label().text,
                        StartsWith(self.data_uri_prefix))

    def test_open_link_in_webbrowser(self):
        self._test_open_link_in_webbrowser()

    @testtools.skipIf(model() == "Desktop", "on devices only")
    def test_share_link(self):
        self._test_share_link()

    def test_copy_link(self):
        self._test_copy_link()

    def test_copy_image(self):
        self._test_copy_image()


class TestContextMenuTextArea(TestContextMenuBase):

    def _test_actions(self):
        actions = ["SelectAll",
                   "Cut",
                   "Undo",
                   "Redo",
                   "Paste",
                   "SelectAll",
                   "Copy",
                   "Erase"]
        for action in actions:
            self.menu.click_action("{}ContextualAction".format(action))
            webview = self.get_webview()
            self.menu = self._open_context_menu(webview)


@testtools.skipIf(model() != "Desktop", "on desktop only")
class TestContextMenuTextAreaMainWebView(TestContextMenuTextArea):

    def setUp(self):
        super(TestContextMenuTextAreaMainWebView, self).setUp()
        self._setup_webview_context_menu("textarea")
        self.assertThat(self.menu.get_title_label().visible, Equals(False))

    def test_actions(self):
        self._test_actions()


@testtools.skipIf(model() != "Desktop", "on desktop only")
class TestContextMenuTextAreaOverlayWebView(TestContextMenuTextArea):

    def setUp(self):
        super(TestContextMenuTextAreaOverlayWebView, self).setUp()
        self._setup_overlay_webview_context_menu("textarea")
        self.assertThat(self.menu.get_title_label().visible, Equals(False))

    def test_actions(self):
        self._test_actions()