summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2014-06-02 12:08:48 +0200
committerWim Taymans <wtaymans@redhat.com>2014-09-05 17:26:05 +0200
commit84afd44e5f57b0b61bed6806be092bf6ca7b7f86 (patch)
tree6b7ca8030d0444b1999b1c7c313dcede054adf16 /tests
Initial commitHEADmaster
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am33
-rw-r--r--tests/testutil.py80
-rwxr-xr-xtests/world_view.py98
3 files changed, 211 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..ffafdee
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,33 @@
+include $(top_srcdir)/glib-tap.mk
+
+dogtail_tests = \
+ world_view.py
+
+TESTS_ENVIRONMENT += LC_ALL=C
+
+if ENABLE_DOGTAIL
+dist_test_scripts = $(dogtail_tests)
+dist_test_data = testutil.py
+
+CLEANFILES += *.pyc
+
+if ENABLE_COVERAGE
+lcov:
+ ( cd $(abs_top_builddir) ; $(TESTS_ENVIRONMENT) $(GJS) --coverage-output=$(abs_builddir) \
+ $(foreach source,$(wildcard $(abs_top_srcdir)/src/*.js),-C $(abs_top_srcdir)/src/$(notdir $(source))) \
+ $(abs_top_builddir)/src/org.gnome.GnomeMaxima.Application --gapplication-service ) & \
+ sleep 2 && TESTUTIL_DONT_START=1 $(MAKE) $(AM_MAKEFLAGS) check
+ $(GENHTML) $(builddir)/coverage.lcov
+
+clean-local:
+ rm -rf $(builddir)/src
+
+CLEANFILES += *.html *.png *.css coverage.lcov
+GITIGNOREFILES = src/
+endif
+
+else
+EXTRA_DIST += testutil.py $(dogtail_tests)
+endif
+
+include $(top_srcdir)/git.mk
diff --git a/tests/testutil.py b/tests/testutil.py
new file mode 100644
index 0000000..cb291d7
--- /dev/null
+++ b/tests/testutil.py
@@ -0,0 +1,80 @@
+# -*- mode: python -*-
+
+from gi.repository import GLib, Gio
+
+from dogtail.utils import isA11yEnabled, enableA11y
+if not isA11yEnabled():
+ enableA11y(True)
+
+from dogtail import tree
+from dogtail import utils
+from dogtail.predicate import *
+from dogtail.procedural import *
+
+import os, sys
+import subprocess
+
+APPLICATION_ID = "org.gnome.GnomeMaxima.Application"
+
+_bus = None
+
+class IsTextEqual(Predicate):
+ """Predicate subclass that looks for top-level windows"""
+ def __init__(self, text):
+ self.text = text
+
+ def satisfiedByNode(self, node):
+ try:
+ textIface = node.queryText()
+ #print textIface.getText(0, -1)
+ return textIface.getText(0, -1) == self.text
+ except NotImplementedError:
+ return False
+
+ def describeSearchResult(self):
+ return '%s text node' % self.text
+
+def _do_bus_call(method, params):
+ global _bus
+
+ if _bus == None:
+ _bus = Gio.bus_get_sync(Gio.BusType.SESSION)
+ _bus.call_sync(APPLICATION_ID, '/' + APPLICATION_ID.replace('.', '/'),
+ 'org.freedesktop.Application',
+ method, params, None,
+ Gio.DBusCallFlags.NONE,
+ -1, None)
+
+def start():
+ builddir = os.environ.get('G_TEST_BUILDDIR', None)
+ if builddir and not 'TESTUTIL_DONT_START' in os.environ:
+ subprocess.Popen([os.path.join(builddir, '..', 'src', APPLICATION_ID)],
+ cwd=os.path.join(builddir, '..'))
+ else:
+ _do_bus_call("Activate", GLib.Variant('(a{sv})', ([],)))
+ utils.doDelay(3)
+
+ app = tree.root.application(APPLICATION_ID)
+ focus.application(APPLICATION_ID)
+
+ return app
+
+def reset_settings():
+ # need to go through the parser because pygobject does not handle maybe types
+ parsed = GLib.Variant.parse(GLib.VariantType.new('av'),
+ "[<(uint32 1, <('Linate Airport', 'LIML', "
+ "false, @m(dd) (0.79296125100499293, "
+ "0.16202472640904275), @m(dd) (0.79354303905785273, "
+ "0.16057029118347829))>)>]")
+ settings.set_value("locations", parsed)
+
+def init():
+ global settings, _previous_locations
+
+ settings = Gio.Settings("org.gnome.GnomeMaxima.Application")
+ _previous_locations = settings.get_value("locations")
+ reset_settings()
+
+def fini():
+ settings.set_value("locations", _previous_locations)
+ _do_bus_call("ActivateAction", GLib.Variant('(sava{sv})', ('quit', [], [])))
diff --git a/tests/world_view.py b/tests/world_view.py
new file mode 100755
index 0000000..473b572
--- /dev/null
+++ b/tests/world_view.py
@@ -0,0 +1,98 @@
+#! /usr/bin/python
+
+from testutil import *
+
+from gi.repository import Gio, GLib
+
+import os, sys
+import pyatspi
+from dogtail import tree
+from dogtail import utils
+from dogtail.procedural import *
+
+def active(widget):
+ return widget.getState().contains(pyatspi.STATE_ARMED)
+def visible(widget):
+ return widget.getState().contains(pyatspi.STATE_VISIBLE)
+
+init()
+try:
+ app = start()
+
+ new_button = app.child('New')
+ back_button = app.child('Back')
+ delete_button = app.child('Delete')
+ select_button = app.child('Select')
+ done_button = app.child('Cancel')
+ world_view = app.child('World view')
+ city_view = app.child('City view')
+ content_view = app.child('Cities')
+ milan_icon = content_view.findChild(IsTextEqual('Milan'))
+
+ # basic state
+ assert new_button.showing
+ assert not back_button.showing
+ assert not delete_button.showing
+ assert select_button.showing
+ assert not done_button.showing
+ assert world_view.showing
+ assert content_view.showing
+ assert not city_view.showing
+
+ # selection mode
+ select_button.click()
+ assert not new_button.showing
+ assert not back_button.showing
+ assert delete_button.showing
+ assert not delete_button.sensitive
+ assert not select_button.showing
+ assert done_button.showing
+ assert world_view.showing
+ assert content_view.showing
+ assert not city_view.showing
+
+ # select one
+ milan_icon.click()
+ assert delete_button.sensitive
+ # unselect it
+ milan_icon.click()
+ assert not delete_button.sensitive
+
+ # back from selection mode
+ done_button.click()
+ assert new_button.showing
+ assert not back_button.showing
+ assert not delete_button.showing
+ assert select_button.showing
+ assert not done_button.showing
+ assert world_view.showing
+ assert content_view.showing
+ assert not city_view.showing
+
+ # back into selection mode, delete the only item
+ select_button.click()
+ milan_icon.click()
+ delete_button.click()
+ assert milan_icon.dead
+ placeholder = app.child('Add locations').parent
+ assert placeholder.showing
+ assert select_button.showing
+ assert not select_button.sensitive
+
+ # reset
+ reset_settings()
+ utils.doDelay(1)
+ milan_icon = content_view.findChild(IsTextEqual('Milan'))
+ assert not milan_icon.dead
+ # these two should be equivalend to milan_icon.showing,
+ # but for some reason they aren't
+ assert visible(milan_icon)
+ assert milan_icon.parent.showing
+
+finally:
+ fini()
+
+#type("gimp\n")
+#doDelay(2)
+#keyCombo("Escape")
+