@@ -0,0 +1,65 @@
1+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2+#
3+# Unity - Indicators Autopilot Test Suite
4+# Copyright (C) 2013 Canonical
5+#
6+# This program is free software: you can redistribute it and/or modify
7+# it under the terms of the GNU General Public License as published by
8+# the Free Software Foundation, either version 3 of the License, or
9+# (at your option) any later version.
10+#
11+# This program is distributed in the hope that it will be useful,
12+# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+# GNU General Public License for more details.
15+#
16+# You should have received a copy of the GNU General Public License
17+# along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
19+from __future__ import absolute_import
20+
21+from autopilot.input import Pointer, Touch
22+
23+from unity8.shell.tests import UnityTestCase
24+
25+
26+# TODO: submit to autopilot.introspection.types.Rectangle
27+def get_center(global_rect):
28+ """Returns (x, y) representing the center of a globalRect."""
29+ return (global_rect[0]+int(global_rect[2]/2),
30+ global_rect[1]+int(global_rect[3]/2))
31+
32+
33+class IndicatorBaseTestCase(UnityTestCase):
34+
35+ def setUp(self):
36+ super(IndicatorBaseTestCase, self).setUp()
37+ self.pointer = Pointer(Touch.create())
38+
39+ # Because some tests are manually manipulating the finger, we want to
40+ # cleanup if the test fails, but we don't want to fail with an exception if
41+ # we don't.
42+ def _maybe_release_finger(self):
43+ """Only release the finger if it is in fact down."""
44+ if self.touch._touch_finger is not None:
45+ self.touch.release()
46+
47+ def swipe_to_open_indicator(self, indicator_widget, window):
48+ """Swipe to open the indicator, wait until it's open."""
49+ start_x, start_y = get_center(indicator_widget.globalRect)
50+ end_x = start_x
51+ end_y = window.height
52+ self.pointer.drag(start_x, start_y,
53+ end_x, end_y)
54+ self.addCleanup(self._maybe_release_finger)
55+ # TODO: assert that the indicator page opened
56+
57+ def swipe_to_close_indicator(self, indicator_widget, window):
58+ """Swipe to close the indicator, wait until it's closed."""
59+ end_x, end_y = get_center(indicator_widget.globalRect)
60+ start_x = end_x
61+ start_y = window.height
62+ self.pointer.drag(start_x, start_y,
63+ end_x, end_y)
64+ self.addCleanup(self._maybe_release_finger)
65+ # TODO: assert that the indicator page closed