diff options
author | Stefan Landvogt <stefan@valvesoftware.com> | 2013-06-28 15:27:56 -0700 |
---|---|---|
committer | John Ehresman <jpe@wingware.com> | 2013-06-29 20:13:54 +0200 |
commit | 3683caf30ca60b273070d9f7e50cf2c2efc7e110 (patch) | |
tree | e5c3123ff73e7d64b55950bf91a5a264802a29e1 /tests | |
parent | c707a7cadd08792d8f9dc23d83fc9a27ba7a7656 (diff) |
Fix PYSIDE-61
The original author of the test did not know how to create
one webview after the other after one webview finished loading,
so the old approach segfaulted, because it tried to access variables
that were already freed.
The new approach simply creates webviews with a timer after the
previous webview finished loading. It is also using UsesQApplication
instead of creatig the qApp manually.
Change-Id: I871e7a238398d96e110e89872634a9c5f3b5bc12
Reviewed-by: John Ehresman <jpe@wingware.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/QtWebKit/bug_959.py | 64 |
1 files changed, 37 insertions, 27 deletions
diff --git a/tests/QtWebKit/bug_959.py b/tests/QtWebKit/bug_959.py index e3cc36cd1..bc23a3cef 100644 --- a/tests/QtWebKit/bug_959.py +++ b/tests/QtWebKit/bug_959.py @@ -1,10 +1,15 @@ from PySide.QtCore import QObject, Slot, QTimer from PySide.QtWebKit import QWebView +from PySide.QtGui import QApplication +from PySide import QtCore +import sys import unittest + from helper import UsesQApplication functionID = -1 +currentWebView = None class JSFuncs(QObject): @Slot(str,result=str) @@ -54,37 +59,42 @@ FUNCTIONS_LIST = ['jsfuncs.slot_str_str("hello")', 'jsfuncs.slot_variantmap_str({"foo": "bar"})'] -class TestJsCall(UsesQApplication): +def onLoadFinished( result ): + QTimer.singleShot( 100, createNextWebView ) - @classmethod - def setUpClass(self): - super(TestJsCall, self).setUpClass() +def createNextWebView(): + global functionID - def createInstance(self): - global functionID - self._view = QWebView() - self._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_() + nListCount = len(FUNCTIONS_LIST) - 1 + functionID = functionID + 1 + print functionID + + if functionID < nListCount: + createWebView( functionID ) + else: + QTimer.singleShot(300, QApplication.instance().quit) - def onLoadFinished(self, result): - global functionID - self.assertEqual(self._functionID, functionID) - if self._functionID == (len(FUNCTIONS_LIST) - 1): - QTimer.singleShot(300, self.app.quit) - else: - #new test - self._functionID += 1 - self.createInstance() +def createWebView( nIndex ): + global functionID + global currentWebView + + functionID = nIndex + currentWebView = QWebView() + currentWebView._jsfuncs = JSFuncs() + currentWebView.page().mainFrame().addToJavaScriptWindowObject("jsfuncs", currentWebView._jsfuncs) + QObject.connect( currentWebView, QtCore.SIGNAL('loadFinished( bool )'), onLoadFinished ) + currentWebView.load(PAGE_DATA % FUNCTIONS_LIST[ nIndex ]) + currentWebView.show() + +class Bug959(UsesQApplication): + + def testJavaScriptInWebViewForCrash( self ): + # wait for the webview load to be finished before creating the next webview + # don't create the webview inside of onLoadFinished + # also call onLoadFinished with the correct number of variables + createNextWebView() + self.app.exec_() if __name__ == "__main__": unittest.main() |