summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRenato Filho <renato.filho@openbossa.org>2011-08-24 10:34:45 -0300
committerRenato Filho <renato.filho@openbossa.org>2011-08-24 18:39:24 -0300
commit321cd6235681318deca1267ddfedbd527d091bf0 (patch)
treea040d441e5b55454fb8e1803ec13d8c61f149e8c /tests
parent2fe55feabd4f98b585f21f6f49e46af10035be84 (diff)
downloadpyside-321cd6235681318deca1267ddfedbd527d091bf0.tar.gz
pyside-321cd6235681318deca1267ddfedbd527d091bf0.tar.xz
pyside-321cd6235681318deca1267ddfedbd527d091bf0.zip
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 f9b4663..5f0820d 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 0000000..26cdad8
--- /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()