diff options
Diffstat (limited to 'sources/pyside2/tests/QtWebKit')
-rw-r--r-- | sources/pyside2/tests/QtWebKit/CMakeLists.txt | 11 | ||||
-rw-r--r-- | sources/pyside2/tests/QtWebKit/bug_448.py | 47 | ||||
-rw-r--r-- | sources/pyside2/tests/QtWebKit/bug_694.py | 78 | ||||
-rw-r--r-- | sources/pyside2/tests/QtWebKit/bug_803.py | 46 | ||||
-rw-r--r-- | sources/pyside2/tests/QtWebKit/bug_899.py | 64 | ||||
-rw-r--r-- | sources/pyside2/tests/QtWebKit/bug_959.py | 128 | ||||
-rw-r--r-- | sources/pyside2/tests/QtWebKit/fox.html | 7 | ||||
-rw-r--r-- | sources/pyside2/tests/QtWebKit/qml_plugin_test.py | 88 | ||||
-rw-r--r-- | sources/pyside2/tests/QtWebKit/qmlplugin/dummy.pys | 1 | ||||
-rw-r--r-- | sources/pyside2/tests/QtWebKit/qmlplugin/index.html | 5 | ||||
-rw-r--r-- | sources/pyside2/tests/QtWebKit/qvariantlist_property_test.py | 71 | ||||
-rw-r--r-- | sources/pyside2/tests/QtWebKit/shouldInterruptjavascript_test.py | 56 | ||||
-rw-r--r-- | sources/pyside2/tests/QtWebKit/webframe_test.py | 62 | ||||
-rw-r--r-- | sources/pyside2/tests/QtWebKit/webpage_test.py | 88 | ||||
-rw-r--r-- | sources/pyside2/tests/QtWebKit/webview_test.py | 94 |
15 files changed, 846 insertions, 0 deletions
diff --git a/sources/pyside2/tests/QtWebKit/CMakeLists.txt b/sources/pyside2/tests/QtWebKit/CMakeLists.txt new file mode 100644 index 000000000..7fab64773 --- /dev/null +++ b/sources/pyside2/tests/QtWebKit/CMakeLists.txt @@ -0,0 +1,11 @@ +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(shouldInterruptjavascript_test.py) +PYSIDE_TEST(webpage_test.py) +PYSIDE_TEST(webview_test.py) +PYSIDE_TEST(webframe_test.py) diff --git a/sources/pyside2/tests/QtWebKit/bug_448.py b/sources/pyside2/tests/QtWebKit/bug_448.py new file mode 100644 index 000000000..2c50bd166 --- /dev/null +++ b/sources/pyside2/tests/QtWebKit/bug_448.py @@ -0,0 +1,47 @@ +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +'''Test cases for bug: http://bugs.openbossa.org/show_bug.cgi?id=448''' + +import unittest +import sys + +from PySide2.QtWidgets import QApplication +from PySide2.QtWebKit import QWebView + +class Bug448(unittest.TestCase): + def onError(self, erros): + pass + + def testReturnOwnership(self): + app = QApplication(sys.argv) + webview = QWebView() + webview.page().networkAccessManager().sslErrors.connect(self.onError) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtWebKit/bug_694.py b/sources/pyside2/tests/QtWebKit/bug_694.py new file mode 100644 index 000000000..f59c08b04 --- /dev/null +++ b/sources/pyside2/tests/QtWebKit/bug_694.py @@ -0,0 +1,78 @@ +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +import sys +import unittest +from PySide2.QtCore import * +from PySide2.QtWidgets import * +from PySide2.QtWebKit import * + +class ErrorPage (QWebPage): + + def __init__(self): + QWebPage.__init__(self) + self.rcv_extension = None + self.rcv_url = None + self.rcv_url_copy = None + self.rcv_option_type = None + self.rcv_output_type = None + + + def supportsExtension(self, extension): + return extension == QWebPage.ErrorPageExtension + + def extension(self, extension, option, output): + self.rcv_extension = extension + self.rcv_url = option.url + self.rcv_url_copy = QUrl(option.url) + self.rcv_option_type = type(option) + self.rcv_output_type = type(output) + return True + +class TestWebPageExtension(unittest.TestCase): + def testIt(self): + app = QApplication([]) + ep = ErrorPage() + view = QWebView() + view.setPage(ep) + view.load("foo://bar") # Some malformmed url + view.show() + + # If the timeout is 0 the webpage isn't even loaded on Qt4.6-i386, so we use 100 :-) + QTimer.singleShot(100, app.quit) + app.exec_() + + self.assertEqual(ep.rcv_extension, QWebPage.ErrorPageExtension) + self.assertRaises(RuntimeError, ep.rcv_url.__str__) + + self.assertEqual(ep.rcv_url_copy, "foo://bar") + self.assertEqual(ep.rcv_option_type, QWebPage.ErrorPageExtensionOption) + self.assertEqual(ep.rcv_output_type, QWebPage.ErrorPageExtensionReturn) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtWebKit/bug_803.py b/sources/pyside2/tests/QtWebKit/bug_803.py new file mode 100644 index 000000000..23b670f9c --- /dev/null +++ b/sources/pyside2/tests/QtWebKit/bug_803.py @@ -0,0 +1,46 @@ +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +import unittest +from PySide2.QtWidgets import * +from PySide2.QtWebKit import * + +class TestBug803 (unittest.TestCase): + + def testIt(self): + app = QApplication([]) + page = QWebPage() + frame = page.mainFrame() + frame.setHtml("<html><head></head><body><p>1</p><p>2</p></body></html>") + elems = frame.findAllElements("p") + self.assertEqual(len(elems), 2) + self.assertEqual(elems[0].toPlainText(), "1") + self.assertEqual(elems[1].toPlainText(), "2") + +if __name__ == "__main__": + unittest.main() diff --git a/sources/pyside2/tests/QtWebKit/bug_899.py b/sources/pyside2/tests/QtWebKit/bug_899.py new file mode 100644 index 000000000..edd705c8e --- /dev/null +++ b/sources/pyside2/tests/QtWebKit/bug_899.py @@ -0,0 +1,64 @@ +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +import unittest +from PySide2.QtCore import Property, QObject +from PySide2.QtWebKit import QWebView +from helper import TimedQApplication + +class TestLambdaPropery(TimedQApplication): + + def testBug899(self): + html = ''' + <html><body> + <script type="text/javascript"> + document.write("<p>"+py_obj.list1+"</p>") + document.write("<p>"+py_obj.list2+"</p>") + </script> + </body></html> + ''' + + class Obj(object): + list1 = ['foo', 'bar', 'baz'] + list2 = ['fi', 'fo', 'fum'] + + obj = Obj() + + wrapper_dict = {} + for name in ('list1', 'list2'): + getter = lambda arg=None, name=name: getattr(obj, name) + wrapper_dict[name] = Property('QVariantList', getter) + wrapper = type('PyObj', (QObject,), wrapper_dict) + + view = QWebView() + view.page().mainFrame().addToJavaScriptWindowObject('py_obj', wrapper()) + view.setHtml(html) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtWebKit/bug_959.py b/sources/pyside2/tests/QtWebKit/bug_959.py new file mode 100644 index 000000000..22f217bee --- /dev/null +++ b/sources/pyside2/tests/QtWebKit/bug_959.py @@ -0,0 +1,128 @@ +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +from PySide2.QtCore import QObject, Slot, QTimer +from PySide2.QtWebKit import QWebView +from PySide2.QtWidgets import QApplication +from PySide2 import QtCore + +import sys +import unittest + +from helper import UsesQApplication + +functionID = -1 +currentWebView = None + +class JSFuncs(QObject): + @Slot(str,result=str) + def slot_str_str(self, x): + global functionID + functionID = 0 + return x.upper() + + @Slot(str,result='QVariant') + def slot_str_list(self, x): + global functionID + functionID = 1 + return [x, x] + + @Slot('QStringList',result=str) + def slot_strlist_str(self, x): + global functionID + functionID = 2 + return x[-1] + + @Slot('QVariant',result=str) + def slot_variant_str(self, x): + global functionID + functionID = 3 + return str(x) + + @Slot('QVariantList',result=str) + def slot_variantlist_str(self, x): + global functionID + functionID = 4 + return str(x[-1]) + + @Slot('QVariantMap',result=str) + def slot_variantmap_str(self, x): + global functionID + functionID = 5 + return str(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"})'] + + +def onLoadFinished( result ): + QTimer.singleShot( 100, createNextWebView ) + +def createNextWebView(): + global functionID + + nListCount = len(FUNCTIONS_LIST) - 1 + functionID = functionID + 1 + print functionID + + if functionID < nListCount: + createWebView( functionID ) + else: + QTimer.singleShot(300, QApplication.instance().quit) + + +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() diff --git a/sources/pyside2/tests/QtWebKit/fox.html b/sources/pyside2/tests/QtWebKit/fox.html new file mode 100644 index 000000000..da873b1cc --- /dev/null +++ b/sources/pyside2/tests/QtWebKit/fox.html @@ -0,0 +1,7 @@ +<html> +<title>Title</title> +<meta name="description" content="PySide Test METADATA." /> +<body> +<p>The quick <b>brown</b> fox <i>jumps</i> over the lazy dog.</p> +</body> +</html> diff --git a/sources/pyside2/tests/QtWebKit/qml_plugin_test.py b/sources/pyside2/tests/QtWebKit/qml_plugin_test.py new file mode 100644 index 000000000..d7e855ce8 --- /dev/null +++ b/sources/pyside2/tests/QtWebKit/qml_plugin_test.py @@ -0,0 +1,88 @@ +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +import os +import sys +import unittest + +from PySide2.QtCore import QUrl, QTimer +from PySide2.QtWidgets import QApplication, QLabel +from PySide2.QtWebKit import QWebPluginFactory, QWebView, QWebSettings + +from helper import UsesQApplication + +class PluginFactory(QWebPluginFactory): + + def plugins(self): + plugins = [] + + mime = self.MimeType() + mime.name = 'DummyFile' + mime.fileExtensions = ['.pys'] + + plugin = self.Plugin() + plugin.name = 'DummyPlugin' + plugin.mimeTypes = [mime] + + plugins.append(plugin) + + return plugins + + def create(self, mimeType, url, argumentNames, argumentValues): + if mimeType != 'application/x-dummy': + return None + + for name, value in zip(argumentNames, argumentValues): + if name == 'text': + text = value + else: + text = "Webkit plugins!" + + widget = QLabel(text) + return widget + +class TestPlugin(UsesQApplication): + + def testPlugin(self): + view = QWebView() + fac = PluginFactory() + view.page().setPluginFactory(fac) + QWebSettings.globalSettings().setAttribute(QWebSettings.PluginsEnabled, True) + + view.load(QUrl(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'qmlplugin', 'index.html'))) + + view.resize(840, 600) + view.show() + + QTimer.singleShot(500, self.app.quit) + + self.app.exec_() + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtWebKit/qmlplugin/dummy.pys b/sources/pyside2/tests/QtWebKit/qmlplugin/dummy.pys new file mode 100644 index 000000000..0b7469da4 --- /dev/null +++ b/sources/pyside2/tests/QtWebKit/qmlplugin/dummy.pys @@ -0,0 +1 @@ +Foobar! diff --git a/sources/pyside2/tests/QtWebKit/qmlplugin/index.html b/sources/pyside2/tests/QtWebKit/qmlplugin/index.html new file mode 100644 index 000000000..db0d6b5b2 --- /dev/null +++ b/sources/pyside2/tests/QtWebKit/qmlplugin/index.html @@ -0,0 +1,5 @@ +<html><body> + <h1>Custom Plugin</h1> + <object type="application/x-dummy" data="./dummy.pys" text="My text"> + </object> +</body></html> diff --git a/sources/pyside2/tests/QtWebKit/qvariantlist_property_test.py b/sources/pyside2/tests/QtWebKit/qvariantlist_property_test.py new file mode 100644 index 000000000..c33b2d1fe --- /dev/null +++ b/sources/pyside2/tests/QtWebKit/qvariantlist_property_test.py @@ -0,0 +1,71 @@ +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +import unittest +from PySide2.QtCore import Property, QObject +from PySide2.QtWebKit import QWebView +from helper import TimedQApplication + +class TestLoadFinished(TimedQApplication): + + def setUp(self): + TimedQApplication.setUp(self, timeout=1000) + + def tearDown(self): + TimedQApplication.tearDown(self) + + def testQVariantListProperty(self): + class Obj(object): + list = ['foo', 'bar', 'baz'] + + obj = Obj() + + wrapper_dict = {} + for name in ['list']: + getter = lambda arg=None, name=name: getattr(obj, name) + wrapper_dict[name] = Property('QVariantList', getter) + wrapper = type('PyObj', (QObject,), wrapper_dict) + + view = QWebView() + frame = view.page().mainFrame() + frame.addToJavaScriptWindowObject('py_obj', wrapper()) + + html = ''' + <html><body> + <script type="text/javascript"> + document.write(py_obj.list) + </script> + </body></html> + ''' + view.setHtml(html) + view.show() + self.app.exec_() + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtWebKit/shouldInterruptjavascript_test.py b/sources/pyside2/tests/QtWebKit/shouldInterruptjavascript_test.py new file mode 100644 index 000000000..7c9763f2e --- /dev/null +++ b/sources/pyside2/tests/QtWebKit/shouldInterruptjavascript_test.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +import unittest +from PySide2 import QtCore, QtWebKit + +from helper import UsesQApplication + +class QWebPageHeadless(QtWebKit.QWebPage): + # FIXME: This is not working, the slot is not overriden! + # http://doc.qt.nokia.com/4.7-snapshot/qwebpage.html#shouldInterruptJavaScript + @QtCore.Slot() + def shouldInterruptJavaScript(self): + self._interrupted = True + QtCore.QTimer.singleShot(300, self._app.quit) + return True + +class TestSlotOverride(UsesQApplication): + def testFunctionCall(self): + page = QWebPageHeadless() + page._interrupted = False + page._app = self.app + page.mainFrame().setHtml('<script>while(1);</script>') + self.app.exec_() + self.assertTrue(page._interrupted) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtWebKit/webframe_test.py b/sources/pyside2/tests/QtWebKit/webframe_test.py new file mode 100644 index 000000000..e82ae5279 --- /dev/null +++ b/sources/pyside2/tests/QtWebKit/webframe_test.py @@ -0,0 +1,62 @@ +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +import unittest +import sys + +from PySide2.QtCore import QObject, SIGNAL, QUrl +from PySide2.QtWebKit import * +from PySide2.QtNetwork import QNetworkRequest + +from helper import adjust_filename, UsesQApplication + + + +class TestWebFrame(UsesQApplication): + def load_finished(self, ok): + self.assertTrue(ok) + page = self.view.page() + self.assertTrue(page) + frame = page.mainFrame() + self.assertTrue(frame) + meta = frame.metaData() + self.assertEqual(meta['description'], ['PySide Test METADATA.']) + self.app.quit() + + def testMetaData(self): + self.view = QWebView() + QObject.connect(self.view, SIGNAL('loadFinished(bool)'), + self.load_finished) + url = QUrl.fromLocalFile(adjust_filename('fox.html', __file__)) + self.view.setUrl(url) + self.app.exec_() + + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside2/tests/QtWebKit/webpage_test.py b/sources/pyside2/tests/QtWebKit/webpage_test.py new file mode 100644 index 000000000..1abb6be49 --- /dev/null +++ b/sources/pyside2/tests/QtWebKit/webpage_test.py @@ -0,0 +1,88 @@ +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +'''Test cases for QWebPage''' + +import unittest + +from PySide2.QtCore import QObject, SIGNAL, QUrl +from PySide2.QtWebKit import QWebPage +from PySide2.QtNetwork import QNetworkAccessManager + +from helper import adjust_filename, TimedQApplication + +#Define a global timeout because TimedQApplication uses a singleton! +#Use a value big enough to run all the tests. +TIMEOUT = 1000 + +class TestFindText(TimedQApplication): + '''Test cases for finding text''' + + def setUp(self): + TimedQApplication.setUp(self, timeout=TIMEOUT) + self.page = QWebPage() + QObject.connect(self.page, SIGNAL('loadFinished(bool)'), + self.load_finished) + self.called = False + + def tearDown(self): + #Release resources + del self.page + self.called = False + TimedQApplication.tearDown(self) + + def testFindSelectText(self): + url = QUrl.fromLocalFile(adjust_filename('fox.html', __file__)) + self.page.mainFrame().load(url) + self.app.exec_() + self.assertTrue(self.called) + + def load_finished(self, ok): + #Callback to check if load was successful + if ok: + self.called = True + self.assertTrue(self.page.findText('fox')) + self.assertEqual(self.page.selectedText(), 'fox') + self.app.quit() + +class SetNetworkAccessManagerCase(TimedQApplication): + + def setUp(self): + TimedQApplication.setUp(self, timeout=TIMEOUT) + + def testSetNetworkAccessManager(self): + page = QWebPage() + manager = QNetworkAccessManager() + page.setNetworkAccessManager(manager) + + def testNetWorkAccessManager(self): + page = QWebPage() + a = page.networkAccessManager() + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtWebKit/webview_test.py b/sources/pyside2/tests/QtWebKit/webview_test.py new file mode 100644 index 000000000..f6c82e045 --- /dev/null +++ b/sources/pyside2/tests/QtWebKit/webview_test.py @@ -0,0 +1,94 @@ +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +'''Test cases for QWebView''' + +import unittest +import py3kcompat as py3k +import sys + +from PySide2.QtCore import QObject, SIGNAL, QUrl +from PySide2.QtWebKit import QWebPage, QWebView +from PySide2.QtNetwork import QNetworkRequest + +from helper import adjust_filename, TimedQApplication + + +class testWebPage(QWebPage): + def sayMyName(self): + return 'testWebPage' + +class TestLoadFinished(TimedQApplication): + '''Test case for signal QWebView.loadFinished(bool)''' + + def setUp(self): + #Acquire resources + TimedQApplication.setUp(self, timeout=1000) + self.view = QWebView() + QObject.connect(self.view, SIGNAL('loadFinished(bool)'), + self.load_finished) + self.called = False + + def tearDown(self): + #Release resources + del self.view + self.called = False + TimedQApplication.tearDown(self) + + def testLoadFinishedFromFile(self): + url = QUrl.fromLocalFile(adjust_filename('fox.html', __file__)) + self.view.setUrl(url) + self.app.exec_() + + self.assertTrue(self.called) + + def testSetPageAndGetPage(self): + twp = testWebPage() + self.view.setPage(twp) + del twp + p = self.view.page() + self.assertEqual(p.sayMyName(), 'testWebPage') + + # Setting the same webpage should not incref the python obj + refCount = sys.getrefcount(p) + self.view.setPage(p) + self.assertEqual(sys.getrefcount(p), refCount) + + # Changing the webpage obj should decref the old one + twp2 = testWebPage() + self.view.setPage(twp2) + self.assertEqual(sys.getrefcount(p), refCount - 1) + + def load_finished(self, ok): + #Callback to check if load was successful + self.app.quit() + if ok: + self.called = True + +if __name__ == '__main__': + unittest.main() |