aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRenato Filho <renato.filho@openbossa.org>2011-08-24 10:34:45 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:54:47 -0300
commit544414cc0372d0f50c621f3785d43ba3a8c2cf04 (patch)
tree097b937d9804a6952d0cff668bc0525659fcd891 /tests
parentc31c7c60da668bc690dd0fde3659f64c7d5c5b9c (diff)
Created unit test for bug #959.
Reviewed by: Hugo Parente <hugo.lima@openbossa.org> Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/QtWebKit/CMakeLists.txt1
-rw-r--r--tests/QtWebKit/bug_959.py87
2 files changed, 88 insertions, 0 deletions
diff --git a/tests/QtWebKit/CMakeLists.txt b/tests/QtWebKit/CMakeLists.txt
index f9b466330..5f0820d31 100644
--- a/tests/QtWebKit/CMakeLists.txt
+++ b/tests/QtWebKit/CMakeLists.txt
@@ -2,6 +2,7 @@ PYSIDE_TEST(bug_448.py)
PYSIDE_TEST(bug_694.py)
PYSIDE_TEST(bug_803.py)
PYSIDE_TEST(bug_899.py)
+PYSIDE_TEST(bug_959.py)
PYSIDE_TEST(qvariantlist_property_test.py)
PYSIDE_TEST(qml_plugin_test.py)
PYSIDE_TEST(webpage_test.py)
diff --git a/tests/QtWebKit/bug_959.py b/tests/QtWebKit/bug_959.py
new file mode 100644
index 000000000..26cdad858
--- /dev/null
+++ b/tests/QtWebKit/bug_959.py
@@ -0,0 +1,87 @@
+from PySide.QtCore import QObject, Slot, QTimer
+from PySide.QtWebKit import QWebView, QWebPage
+
+import unittest
+from helper import UsesQApplication
+
+class JSFuncs(QObject):
+ functionID = -1
+ @Slot(unicode,result=unicode)
+ def slot_str_str(self, x):
+ print "slot_str_str(%r)"%x
+ JSFuncs.functionID = 0
+ return x.upper()
+
+ @Slot(unicode,result='QVariant')
+ def slot_str_list(self, x):
+ print "slot_str_list(%r)"%x
+ JSFuncs.functionID = 1
+ return [x, x]
+
+ @Slot('QStringList',result=unicode)
+ def slot_strlist_str(self, x):
+ print "slot_strlist_str(%r)"%x
+ JSFuncs.functionID = 2
+ return x[-1]
+
+ @Slot('QVariant',result=unicode)
+ def slot_variant_str(self, x):
+ print "slot_variant_str(%r)"%x
+ JSFuncs.functionID = 3
+ return unicode(x)
+
+ @Slot('QVariantList',result=unicode)
+ def slot_variantlist_str(self, x):
+ print "slot_variantlist_str(%r)"%x
+ JSFuncs.functionID = 4
+ return unicode(x[-1])
+
+ @Slot('QVariantMap',result=unicode)
+ def slot_variantmap_str(self, x):
+ print "slot_variantmap_str(%r)"%x
+ JSFuncs.functionID = 5
+ return unicode(x["foo"])
+
+
+
+PAGE_DATA = "data:text/html,<!doctype html><html><body onload='%s'></body></html>"
+FUNCTIONS_LIST = ['jsfuncs.slot_str_str("hello")',
+ 'jsfuncs.slot_str_list("hello")',
+ 'jsfuncs.slot_strlist_str(["hello","world"])',
+ 'jsfuncs.slot_variant_str("hello")',
+ 'jsfuncs.slot_variantlist_str(["hello","world"])',
+ 'jsfuncs.slot_variantmap_str({"foo": "bar"})']
+
+
+class TestJsCall(UsesQApplication):
+
+ @classmethod
+ def setUpClass(self):
+ super(TestJsCall, self).setUpClass()
+
+ def createInstance(self):
+ self._view = QWebView()
+ self._jsfuncs = JSFuncs()
+ JSFuncs.functionID = -1
+ self._view.page().mainFrame().addToJavaScriptWindowObject("jsfuncs", self._jsfuncs)
+ self._view.loadFinished[bool].connect(self.onLoadFinished)
+ self._view.load(PAGE_DATA % FUNCTIONS_LIST[self._functionID])
+ self._view.show()
+
+ def testJsCall(self):
+ self._functionID = 0
+ self.createInstance()
+ self.app.exec_()
+
+ def onLoadFinished(self, result):
+ self.assertEqual(self._functionID, JSFuncs.functionID)
+ if self._functionID == len(FUNCTIONS_LIST) - 1:
+ QTimer.singleShot(300, self.app.quit)
+ else:
+ #new test
+ self._functionID += 1
+ self.createInstance()
+
+
+if __name__ == "__main__":
+ unittest.main()