⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tst_qwebframe.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/*    Copyright (C) 2008,2009 Nokia Corporation and/or its subsidiary(-ies)    This library is free software; you can redistribute it and/or    modify it under the terms of the GNU Library General Public    License as published by the Free Software Foundation; either    version 2 of the License, or (at your option) any later version.    This library is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    Library General Public License for more details.    You should have received a copy of the GNU Library General Public License    along with this library; see the file COPYING.LIB.  If not, write to    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,    Boston, MA 02110-1301, USA.*/#include <QtTest/QtTest>#include <qwebpage.h>#include <qwidget.h>#include <qwebview.h>#include <qwebframe.h>#include <qwebhistory.h>#include <QAbstractItemView>#include <QApplication>#include <QComboBox>#include <QRegExp>#include <QNetworkRequest>//TESTED_CLASS=//TESTED_FILES=// Task 160192/** * Starts an event loop that runs until the given signal is received. Optionally the event loop * can return earlier on a timeout. * * \return \p true if the requested signal was received *         \p false on timeout */static bool waitForSignal(QObject* obj, const char* signal, int timeout = 0){    QEventLoop loop;    QObject::connect(obj, signal, &loop, SLOT(quit()));    QTimer timer;    QSignalSpy timeoutSpy(&timer, SIGNAL(timeout()));    if (timeout > 0) {        QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));        timer.setSingleShot(true);        timer.start(timeout);    }    loop.exec();    return timeoutSpy.isEmpty();}/* Mostly a test for the JavaScript related parts of QWebFrame */struct CustomType {    QString string;};Q_DECLARE_METATYPE(CustomType)Q_DECLARE_METATYPE(QBrush*)Q_DECLARE_METATYPE(QObjectList)Q_DECLARE_METATYPE(QList<int>)Q_DECLARE_METATYPE(Qt::BrushStyle)Q_DECLARE_METATYPE(QVariantList)Q_DECLARE_METATYPE(QVariantMap)class MyQObject : public QObject{    Q_OBJECT    Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty)    Q_PROPERTY(QVariant variantProperty READ variantProperty WRITE setVariantProperty)    Q_PROPERTY(QVariantList variantListProperty READ variantListProperty WRITE setVariantListProperty)    Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty)    Q_PROPERTY(QStringList stringListProperty READ stringListProperty WRITE setStringListProperty)    Q_PROPERTY(QByteArray byteArrayProperty READ byteArrayProperty WRITE setByteArrayProperty)    Q_PROPERTY(QBrush brushProperty READ brushProperty WRITE setBrushProperty)    Q_PROPERTY(double hiddenProperty READ hiddenProperty WRITE setHiddenProperty SCRIPTABLE false)    Q_PROPERTY(int writeOnlyProperty WRITE setWriteOnlyProperty)    Q_PROPERTY(int readOnlyProperty READ readOnlyProperty)    Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut)    Q_PROPERTY(CustomType propWithCustomType READ propWithCustomType WRITE setPropWithCustomType)    Q_ENUMS(Policy Strategy)    Q_FLAGS(Ability)public:    enum Policy {        FooPolicy = 0,        BarPolicy,        BazPolicy    };    enum Strategy {        FooStrategy = 10,        BarStrategy,        BazStrategy    };    enum AbilityFlag {        NoAbility  = 0x000,        FooAbility = 0x001,        BarAbility = 0x080,        BazAbility = 0x200,        AllAbility = FooAbility | BarAbility | BazAbility    };    Q_DECLARE_FLAGS(Ability, AbilityFlag)    MyQObject(QObject* parent = 0)        : QObject(parent),            m_intValue(123),            m_variantValue(QLatin1String("foo")),            m_variantListValue(QVariantList() << QVariant(123) << QVariant(QLatin1String("foo"))),            m_stringValue(QLatin1String("bar")),            m_stringListValue(QStringList() << QLatin1String("zig") << QLatin1String("zag")),            m_brushValue(QColor(10, 20, 30, 40)),            m_hiddenValue(456.0),            m_writeOnlyValue(789),            m_readOnlyValue(987),            m_qtFunctionInvoked(-1) { }    ~MyQObject() { }    int intProperty() const {        return m_intValue;    }    void setIntProperty(int value) {        m_intValue = value;    }    QVariant variantProperty() const {        return m_variantValue;    }    void setVariantProperty(const QVariant &value) {        m_variantValue = value;    }    QVariantList variantListProperty() const {        return m_variantListValue;    }    void setVariantListProperty(const QVariantList &value) {        m_variantListValue = value;    }    QString stringProperty() const {        return m_stringValue;    }    void setStringProperty(const QString &value) {        m_stringValue = value;    }    QStringList stringListProperty() const {        return m_stringListValue;    }    void setStringListProperty(const QStringList &value) {        m_stringListValue = value;    }    QByteArray byteArrayProperty() const {        return m_byteArrayValue;    }    void setByteArrayProperty(const QByteArray &value) {        m_byteArrayValue = value;    }    QBrush brushProperty() const {        return m_brushValue;    }    Q_INVOKABLE void setBrushProperty(const QBrush &value) {        m_brushValue = value;    }    double hiddenProperty() const {        return m_hiddenValue;    }    void setHiddenProperty(double value) {        m_hiddenValue = value;    }    int writeOnlyProperty() const {        return m_writeOnlyValue;    }    void setWriteOnlyProperty(int value) {        m_writeOnlyValue = value;    }    int readOnlyProperty() const {        return m_readOnlyValue;    }    QKeySequence shortcut() const {        return m_shortcut;    }    void setShortcut(const QKeySequence &seq) {        m_shortcut = seq;    }    CustomType propWithCustomType() const {        return m_customType;    }    void setPropWithCustomType(const CustomType &c) {        m_customType = c;    }    int qtFunctionInvoked() const {        return m_qtFunctionInvoked;    }    QVariantList qtFunctionActuals() const {        return m_actuals;    }    void resetQtFunctionInvoked() {        m_qtFunctionInvoked = -1;        m_actuals.clear();    }    Q_INVOKABLE void myInvokable() {        m_qtFunctionInvoked = 0;    }    Q_INVOKABLE void myInvokableWithIntArg(int arg) {        m_qtFunctionInvoked = 1;        m_actuals << arg;    }    Q_INVOKABLE void myInvokableWithLonglongArg(qlonglong arg) {        m_qtFunctionInvoked = 2;        m_actuals << arg;    }    Q_INVOKABLE void myInvokableWithFloatArg(float arg) {        m_qtFunctionInvoked = 3;        m_actuals << arg;    }    Q_INVOKABLE void myInvokableWithDoubleArg(double arg) {        m_qtFunctionInvoked = 4;        m_actuals << arg;    }    Q_INVOKABLE void myInvokableWithStringArg(const QString &arg) {        m_qtFunctionInvoked = 5;        m_actuals << arg;    }    Q_INVOKABLE void myInvokableWithIntArgs(int arg1, int arg2) {        m_qtFunctionInvoked = 6;        m_actuals << arg1 << arg2;    }    Q_INVOKABLE int myInvokableReturningInt() {        m_qtFunctionInvoked = 7;        return 123;    }    Q_INVOKABLE qlonglong myInvokableReturningLongLong() {        m_qtFunctionInvoked = 39;        return 456;    }    Q_INVOKABLE QString myInvokableReturningString() {        m_qtFunctionInvoked = 8;        return QLatin1String("ciao");    }    Q_INVOKABLE void myInvokableWithIntArg(int arg1, int arg2) { // overload        m_qtFunctionInvoked = 9;        m_actuals << arg1 << arg2;    }    Q_INVOKABLE void myInvokableWithEnumArg(Policy policy) {        m_qtFunctionInvoked = 10;        m_actuals << policy;    }    Q_INVOKABLE void myInvokableWithQualifiedEnumArg(MyQObject::Policy policy) {        m_qtFunctionInvoked = 36;        m_actuals << policy;    }    Q_INVOKABLE Policy myInvokableReturningEnum() {        m_qtFunctionInvoked = 37;        return BazPolicy;    }    Q_INVOKABLE MyQObject::Policy myInvokableReturningQualifiedEnum() {        m_qtFunctionInvoked = 38;        return BazPolicy;    }    Q_INVOKABLE QVector<int> myInvokableReturningVectorOfInt() {        m_qtFunctionInvoked = 11;        return QVector<int>();    }    Q_INVOKABLE void myInvokableWithVectorOfIntArg(const QVector<int> &) {        m_qtFunctionInvoked = 12;    }    Q_INVOKABLE QObject* myInvokableReturningQObjectStar() {        m_qtFunctionInvoked = 13;        return this;    }    Q_INVOKABLE QObjectList myInvokableWithQObjectListArg(const QObjectList &lst) {        m_qtFunctionInvoked = 14;        m_actuals << qVariantFromValue(lst);        return lst;    }    Q_INVOKABLE QVariant myInvokableWithVariantArg(const QVariant &v) {        m_qtFunctionInvoked = 15;        m_actuals << v;        return v;    }    Q_INVOKABLE QVariantMap myInvokableWithVariantMapArg(const QVariantMap &vm) {        m_qtFunctionInvoked = 16;        m_actuals << vm;        return vm;    }    Q_INVOKABLE QList<int> myInvokableWithListOfIntArg(const QList<int> &lst) {        m_qtFunctionInvoked = 17;        m_actuals << qVariantFromValue(lst);        return lst;    }    Q_INVOKABLE QObject* myInvokableWithQObjectStarArg(QObject* obj) {        m_qtFunctionInvoked = 18;        m_actuals << qVariantFromValue(obj);        return obj;    }    Q_INVOKABLE QBrush myInvokableWithQBrushArg(const QBrush &brush) {        m_qtFunctionInvoked = 19;        m_actuals << qVariantFromValue(brush);        return brush;    }    Q_INVOKABLE void myInvokableWithBrushStyleArg(Qt::BrushStyle style) {        m_qtFunctionInvoked = 43;        m_actuals << qVariantFromValue(style);    }    Q_INVOKABLE void myInvokableWithVoidStarArg(void* arg) {        m_qtFunctionInvoked = 44;        m_actuals << qVariantFromValue(arg);    }    Q_INVOKABLE void myInvokableWithAmbiguousArg(int arg) {        m_qtFunctionInvoked = 45;        m_actuals << qVariantFromValue(arg);    }    Q_INVOKABLE void myInvokableWithAmbiguousArg(uint arg) {        m_qtFunctionInvoked = 46;        m_actuals << qVariantFromValue(arg);    }    Q_INVOKABLE void myInvokableWithDefaultArgs(int arg1, const QString &arg2 = "") {        m_qtFunctionInvoked = 47;        m_actuals << qVariantFromValue(arg1) << qVariantFromValue(arg2);    }    Q_INVOKABLE QObject& myInvokableReturningRef() {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -