This file is indexed.

/usr/lib/python3/dist-packages/notes_app/tests/test_parts.py is in notes-app-autopilot 1.4+14.10.20140711-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
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
# Copyright 2013 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.

"""Tests for Notes app"""

from __future__ import absolute_import

from testtools.matchers import Equals
from autopilot.matchers import Eventually
from autopilot.platform import model

from notes_app.tests import NotesTestCaseBaseWithHTTPServer

import sqlite3


class TestFocus(NotesTestCaseBaseWithHTTPServer):
    """Tests focusing notes"""

    """ This is needed to wait for the application to start.
        In the testfarm, the application may take some time to show up."""
    def setUp(self):
        self.start_server()
        # Setup the database before starting the app
        self.setup_db()
        super(TestFocus, self).setUp()

    def setup_db(self):
        note_data = """{ "elements" : [
            {"content":"foobar","type":"text"},
            {"content":"%s/image.png","type":"image"}
        ]}""" % self.base_url
        path = self.ensure_db()
        conn = sqlite3.connect(path)
        cursor = conn.cursor()
        cursor.execute("DELETE FROM notes")
        cursor.execute("INSERT INTO notes (date, note) "
                       "VALUES ('2013-04-07', '" + note_data + "')")
        conn.commit()
        conn.close()

    def get_loader_item(self, loader, obj_type):
        self.assertThat(loader.progress, Eventually(Equals(1)))
        children = loader.get_children_by_type(obj_type)
        self.assertThat(len(children), Equals(1))
        return children[0]

    def _collapse_note(self, note):
        """Collapse a note by clicking outside of it."""
        x, y, width, height = note.globalRect
        self.pointing_device.move(x + width // 2, y + height + 20)
        self.pointing_device.click()
        self.assert_note_eventually_collapsed(note)

    def test_parts_focus(self):
        note = self.main_window.get_notes()[0]

        # Expand the note
        self.pointing_device.click_object(note)
        self.assert_note_eventually_expanded(note)

        # Verify that the note we inserted has the right parts
        parts = self.main_window.get_note_parts(note)
        self.assertThat(len(parts), Equals(2))

        text = self.get_loader_item(parts[0], "TextDelegate")
        image = self.get_loader_item(parts[1], "ImageDelegate")

        # Clicking on the upper half of the image should focus the first
        # text area
        part_x, part_y, part_w, part_h = image.globalRect
        self.pointing_device.move(part_x + part_w / 2, part_y + 1)
        self.pointing_device.click()
        self.assert_osk_eventually_shown()
        self.assertThat(text.activeFocus, Eventually(Equals(True)))

        # Clicking on the lower half of the image should create a new text
        # area below the image and focus it
        self.pointing_device.move(part_x + part_w / 2, part_y + part_h - 1)
        self.pointing_device.click()
        self.assert_osk_eventually_hidden()
        # On the phone input focus is lost when the OSK appears so
        # we click the input box to gain focus again. LP: #1204084
        if model() != 'Desktop':
            self.pointing_device.click()
        self.assertThat(text.activeFocus, Eventually(Equals(False)))

        parts = self.main_window.get_note_parts(note)
        self.assertThat(len(parts), Equals(3))

        new_text = self.get_loader_item(parts[2], "TextDelegate")
        self.assertThat(new_text.activeFocus, Eventually(Equals(True)))

    def test_parts_delete_when_empty(self):
        note = self.main_window.get_notes()[0]

        # Expand the note
        self.pointing_device.click_object(note)
        self.assert_note_eventually_expanded(note)

        # Click on the lower half of the image to create the new text part
        parts = self.main_window.get_note_parts(note)
        image = self.get_loader_item(parts[1], "ImageDelegate")
        part_x, part_y, part_w, part_h = image.globalRect
        self.pointing_device.move(part_x + part_w / 2, part_y + part_h - 1)
        self.pointing_device.click()
        self.assertThat(
            lambda: len(self.main_window.get_note_parts(note)),
            Eventually(Equals(3)))
        self.assert_osk_eventually_shown()

        # Now verify that clicking on the upper part of the image will cause
        # the new text to be deleted because it was empty
        empty_part = self.main_window.get_note_parts(note)[-1]
        self.pointing_device.move(part_x + part_w / 2, part_y + 1)
        self.pointing_device.click()
        empty_part.wait_until_destroyed()

    def test_parts_delete_empty_header(self):
        note = self.main_window.get_notes()[0]

        # Expand the note
        self.pointing_device.click_object(note)
        self.assert_note_eventually_expanded(note)

        # Click on the lower half of the image to create the new text part
        parts = self.main_window.get_note_parts(note)
        image = self.get_loader_item(parts[1], "ImageDelegate")
        part_x, part_y, part_w, part_h = image.globalRect
        self.pointing_device.move(part_x + part_w / 2, part_y + part_h - 1)
        self.pointing_device.click()
        self.assertThat(
            lambda: len(self.main_window.get_note_parts(note)),
            Eventually(Equals(3)))
        self.assert_osk_eventually_shown()

        # Now verify that clicking outside of a note (thus collapsing the
        # expanded note) will still cause the new part to disappear
        empty_part = self.main_window.get_note_parts(note)[-1]
        self._collapse_note(note)
        self.assert_note_eventually_collapsed(note)
        empty_part.wait_until_destroyed()

    def test_parts_no_delete_with_text(self):
        note = self.main_window.get_notes()[0]

        # Expand the note
        self.pointing_device.click_object(note)
        self.assert_note_eventually_expanded(note)

        # Click on the lower half of the image to create the new text part
        parts = self.main_window.get_note_parts(note)
        image = self.get_loader_item(parts[1], "ImageDelegate")
        part_x, part_y, part_w, part_h = image.globalRect
        self.pointing_device.move(part_x + part_w / 2, part_y + part_h - 1)
        self.pointing_device.click()
        self.assertThat(
            lambda: len(self.main_window.get_note_parts(note)),
            Eventually(Equals(3)))

        # Verify that after typing something in the note will cause it to stay
        # when unfocusing
        self.keyboard.type("Some text", delay=self.TYPING_DELAY)
        self._collapse_note(note)
        self.assert_note_eventually_collapsed(note)
        self.assertThat(
            lambda: len(self.main_window.get_note_parts(note)),
            Eventually(Equals(3)))