WebKit/qt/tests/qwebframe/tst_qwebframe.cpp
branchRCL_3
changeset 1 9d347b658349
parent 0 4f2f89ce4247
equal deleted inserted replaced
0:4f2f89ce4247 1:9d347b658349
    35 #include <QNetworkReply>
    35 #include <QNetworkReply>
    36 #ifndef QT_NO_OPENSSL
    36 #ifndef QT_NO_OPENSSL
    37 #include <qsslerror.h>
    37 #include <qsslerror.h>
    38 #endif
    38 #endif
    39 #include "../util.h"
    39 #include "../util.h"
       
    40 #include "../WebCoreSupport/DumpRenderTreeSupportQt.h"
    40 
    41 
    41 struct CustomType {
    42 struct CustomType {
    42     QString string;
    43     QString string;
    43 };
    44 };
    44 Q_DECLARE_METATYPE(CustomType)
    45 Q_DECLARE_METATYPE(CustomType)
   568 public slots:
   569 public slots:
   569     void init();
   570     void init();
   570     void cleanup();
   571     void cleanup();
   571 
   572 
   572 private slots:
   573 private slots:
       
   574     void getSetDynamicProperty();
       
   575     void getSetDynamicProperty_data();
       
   576     void getSetChildren();
       
   577     void getSetChildren_data();
   573     void getSetStaticProperty();
   578     void getSetStaticProperty();
   574     void getSetDynamicProperty();
       
   575     void getSetChildren();
       
   576     void callQtInvokable();
   579     void callQtInvokable();
   577     void connectAndDisconnect();
   580     void connectAndDisconnect();
   578     void classEnums();
   581     void classEnums();
   579     void classConstructor();
   582     void classConstructor();
   580     void overrideInvokable();
   583     void overrideInvokable();
   666             type = sUndefined;
   669             type = sUndefined;
   667         }
   670         }
   668         evalJS("delete retvalue; delete typevalue");
   671         evalJS("delete retvalue; delete typevalue");
   669         return ret;
   672         return ret;
   670     }
   673     }
       
   674     void garbageCollectJS()
       
   675     {
       
   676         DumpRenderTreeSupportQt::garbageCollectorCollect();
       
   677     }
   671     QObject* firstChildByClassName(QObject* parent, const char* className) {
   678     QObject* firstChildByClassName(QObject* parent, const char* className) {
   672         const QObjectList & children = parent->children();
   679         const QObjectList & children = parent->children();
   673         foreach (QObject* child, children) {
   680         foreach (QObject* child, children) {
   674             if (!strcmp(child->metaObject()->className(), className)) {
   681             if (!strcmp(child->metaObject()->className(), className)) {
   675                 return child;
   682                 return child;
   942     QCOMPARE(evalJS("String(myObject.objectStarProperty) != 'null'"), sTrue);
   949     QCOMPARE(evalJS("String(myObject.objectStarProperty) != 'null'"), sTrue);
   943 }
   950 }
   944 
   951 
   945 void tst_QWebFrame::getSetDynamicProperty()
   952 void tst_QWebFrame::getSetDynamicProperty()
   946 {
   953 {
       
   954     QFETCH(bool, garbageCollect);
       
   955 
   947     // initially the object does not have the property
   956     // initially the object does not have the property
   948     // In WebKit, RuntimeObjects do not inherit Object, so don't have hasOwnProperty
   957     // In WebKit, RuntimeObjects do not inherit Object, so don't have hasOwnProperty
   949 
   958 
   950     //QCOMPARE(evalJS("myObject.hasOwnProperty('dynamicProperty')"), sFalse);
   959     //QCOMPARE(evalJS("myObject.hasOwnProperty('dynamicProperty')"), sFalse);
   951     QCOMPARE(evalJS("typeof myObject.dynamicProperty"), sUndefined);
   960     QCOMPARE(evalJS("typeof myObject.dynamicProperty"), sUndefined);
   953     // add a dynamic property in C++
   962     // add a dynamic property in C++
   954     QCOMPARE(m_myObject->setProperty("dynamicProperty", 123), false);
   963     QCOMPARE(m_myObject->setProperty("dynamicProperty", 123), false);
   955     //QCOMPARE(evalJS("myObject.hasOwnProperty('dynamicProperty')"), sTrue);
   964     //QCOMPARE(evalJS("myObject.hasOwnProperty('dynamicProperty')"), sTrue);
   956     QCOMPARE(evalJS("typeof myObject.dynamicProperty != 'undefined'"), sTrue);
   965     QCOMPARE(evalJS("typeof myObject.dynamicProperty != 'undefined'"), sTrue);
   957     QCOMPARE(evalJS("myObject.dynamicProperty == 123"), sTrue);
   966     QCOMPARE(evalJS("myObject.dynamicProperty == 123"), sTrue);
       
   967     if( garbageCollect ) {
       
   968         garbageCollectJS();
       
   969         QCOMPARE(evalJS("typeof myObject.dynamicProperty != 'undefined'"), sTrue);
       
   970     }
   958 
   971 
   959     // property change in script should be reflected in C++
   972     // property change in script should be reflected in C++
   960     QCOMPARE(evalJS("myObject.dynamicProperty = 'foo';"
   973     QCOMPARE(evalJS("myObject.dynamicProperty = 'foo';"
   961                     "myObject.dynamicProperty"), QLatin1String("foo"));
   974                     "myObject.dynamicProperty"), QLatin1String("foo"));
   962     QCOMPARE(m_myObject->property("dynamicProperty").toString(), QLatin1String("foo"));
   975     QCOMPARE(m_myObject->property("dynamicProperty").toString(), QLatin1String("foo"));
       
   976     if( garbageCollect ) {
       
   977         garbageCollectJS();
       
   978         QCOMPARE(m_myObject->property("dynamicProperty").toString(), QLatin1String("foo"));
       
   979     }
       
   980 
       
   981     // add a dynamic property in C++ to another QObject
       
   982     QObject* propertyObject = new QObject(m_myObject);
       
   983     QCOMPARE(m_myObject->setProperty("dynamicObjectProperty", qVariantFromValue(propertyObject)), false);
       
   984     QCOMPARE(evalJS("typeof myObject.dynamicObjectProperty != 'undefined'"), sTrue);
       
   985     evalJS("myObject.dynamicObjectProperty.jsProperty = 123");
       
   986     QCOMPARE(evalJS("myObject.dynamicObjectProperty.jsProperty == 123"), sTrue);
       
   987     if( garbageCollect ) {
       
   988         garbageCollectJS();
       
   989         QCOMPARE(evalJS("typeof myObject.dynamicObjectProperty != 'undefined'"), sTrue);
       
   990         QCOMPARE(evalJS("myObject.dynamicObjectProperty.jsProperty == 123"), sTrue);
       
   991     }
       
   992     QCOMPARE(m_myObject->setProperty("dynamicObjectProperty", QVariant()), false);
       
   993     delete propertyObject;
       
   994     QCOMPARE(evalJS("typeof myObject.dynamicObjectProperty == 'undefined'"), sTrue);
   963 
   995 
   964     // delete the property (XFAIL - can't delete properties)
   996     // delete the property (XFAIL - can't delete properties)
   965     QEXPECT_FAIL("", "can't delete properties", Continue);
   997     QEXPECT_FAIL("", "can't delete properties", Continue);
   966     QCOMPARE(evalJS("delete myObject.dynamicProperty"), sTrue);
   998     QCOMPARE(evalJS("delete myObject.dynamicProperty"), sTrue);
   967     /*
   999     /*
   968     QCOMPARE(m_myObject->property("dynamicProperty").isValid(), false);
  1000     QCOMPARE(m_myObject->property("dynamicProperty").isValid(), false);
   969     QCOMPARE(evalJS("typeof myObject.dynamicProperty"), sUndefined);
  1001     QCOMPARE(evalJS("typeof myObject.dynamicProperty"), sUndefined);
   970     //    QCOMPARE(evalJS("myObject.hasOwnProperty('dynamicProperty')"), sFalse);
  1002     //    QCOMPARE(evalJS("myObject.hasOwnProperty('dynamicProperty')"), sFalse);
   971     QCOMPARE(evalJS("typeof myObject.dynamicProperty"), sUndefined);
  1003     QCOMPARE(evalJS("typeof myObject.dynamicProperty"), sUndefined);
   972     */
  1004     */
       
  1005 
       
  1006     evalJS("myObject.dynamicProperty = undefined");
       
  1007 }
       
  1008 
       
  1009 void tst_QWebFrame::getSetDynamicProperty_data()
       
  1010 {
       
  1011     QTest::addColumn<bool>("garbageCollect");
       
  1012     QTest::newRow("with garbageCollect") << true;
       
  1013     QTest::newRow("without garbageCollect") << false;
   973 }
  1014 }
   974 
  1015 
   975 void tst_QWebFrame::getSetChildren()
  1016 void tst_QWebFrame::getSetChildren()
   976 {
  1017 {
       
  1018     QFETCH(bool, garbageCollect);
       
  1019 
   977     // initially the object does not have the child
  1020     // initially the object does not have the child
   978     // (again, no hasOwnProperty)
  1021     // (again, no hasOwnProperty)
   979 
  1022 
   980     //QCOMPARE(evalJS("myObject.hasOwnProperty('child')"), sFalse);
  1023     //QCOMPARE(evalJS("myObject.hasOwnProperty('child')"), sFalse);
   981     QCOMPARE(evalJS("typeof myObject.child"), sUndefined);
  1024     QCOMPARE(evalJS("typeof myObject.child"), sUndefined);
   983     // add a child
  1026     // add a child
   984     MyQObject* child = new MyQObject(m_myObject);
  1027     MyQObject* child = new MyQObject(m_myObject);
   985     child->setObjectName("child");
  1028     child->setObjectName("child");
   986 //  QCOMPARE(evalJS("myObject.hasOwnProperty('child')"), sTrue);
  1029 //  QCOMPARE(evalJS("myObject.hasOwnProperty('child')"), sTrue);
   987     QCOMPARE(evalJS("typeof myObject.child != 'undefined'"), sTrue);
  1030     QCOMPARE(evalJS("typeof myObject.child != 'undefined'"), sTrue);
       
  1031     evalJS("myObject.child.jsProperty = 123");
       
  1032     QCOMPARE(evalJS("myObject.child.jsProperty == 123"), sTrue);
       
  1033 
       
  1034     if( garbageCollect ) {
       
  1035         garbageCollectJS();
       
  1036         QCOMPARE(evalJS("typeof myObject.child != 'undefined'"), sTrue);
       
  1037         QCOMPARE(evalJS("myObject.child.jsProperty == 123"), sTrue);
       
  1038     }
   988 
  1039 
   989     // add a grandchild
  1040     // add a grandchild
   990     MyQObject* grandChild = new MyQObject(child);
  1041     MyQObject* grandChild = new MyQObject(child);
   991     grandChild->setObjectName("grandChild");
  1042     grandChild->setObjectName("grandChild");
   992 //  QCOMPARE(evalJS("myObject.child.hasOwnProperty('grandChild')"), sTrue);
  1043 //  QCOMPARE(evalJS("myObject.child.hasOwnProperty('grandChild')"), sTrue);
   993     QCOMPARE(evalJS("typeof myObject.child.grandChild != 'undefined'"), sTrue);
  1044     QCOMPARE(evalJS("typeof myObject.child.grandChild != 'undefined'"), sTrue);
       
  1045     evalJS("myObject.child.grandChild.jsProperty = 123");
       
  1046     evalJS("myObject.child.grandChild.jsProperty = 123");
       
  1047     if( garbageCollect ) {
       
  1048         garbageCollectJS();
       
  1049         QCOMPARE(evalJS("typeof myObject.child.grandChild != 'undefined'"), sTrue);
       
  1050         QCOMPARE(evalJS("myObject.child.grandChild.jsProperty == 123"), sTrue);
       
  1051     }
   994 
  1052 
   995     // delete grandchild
  1053     // delete grandchild
   996     delete grandChild;
  1054     delete grandChild;
   997 //  QCOMPARE(evalJS("myObject.child.hasOwnProperty('grandChild')"), sFalse);
  1055 //  QCOMPARE(evalJS("myObject.child.hasOwnProperty('grandChild')"), sFalse);
   998     QCOMPARE(evalJS("typeof myObject.child.grandChild == 'undefined'"), sTrue);
  1056     QCOMPARE(evalJS("typeof myObject.child.grandChild == 'undefined'"), sTrue);
   999 
  1057 
  1000     // delete child
  1058     // delete child
  1001     delete child;
  1059     delete child;
  1002 //  QCOMPARE(evalJS("myObject.hasOwnProperty('child')"), sFalse);
  1060 //  QCOMPARE(evalJS("myObject.hasOwnProperty('child')"), sFalse);
  1003     QCOMPARE(evalJS("typeof myObject.child == 'undefined'"), sTrue);
  1061     QCOMPARE(evalJS("typeof myObject.child == 'undefined'"), sTrue);
       
  1062     if( garbageCollect ) {
       
  1063         garbageCollectJS();
       
  1064         QCOMPARE(evalJS("typeof myObject.child == 'undefined'"), sTrue);
       
  1065     }
       
  1066 }
       
  1067 
       
  1068 
       
  1069 void tst_QWebFrame::getSetChildren_data()
       
  1070 {
       
  1071     QTest::addColumn<bool>("garbageCollect");
       
  1072     QTest::newRow("with garbageCollect") << true;
       
  1073     QTest::newRow("without garbageCollect") << false;
  1004 }
  1074 }
  1005 
  1075 
  1006 Q_DECLARE_METATYPE(QVector<int>)
  1076 Q_DECLARE_METATYPE(QVector<int>)
  1007 Q_DECLARE_METATYPE(QVector<double>)
  1077 Q_DECLARE_METATYPE(QVector<double>)
  1008 Q_DECLARE_METATYPE(QVector<QString>)
  1078 Q_DECLARE_METATYPE(QVector<QString>)
  1665     QCOMPARE(evalJS("myObject.mySignal.connect(myObject.mySlot)"), sUndefined);
  1735     QCOMPARE(evalJS("myObject.mySignal.connect(myObject.mySlot)"), sUndefined);
  1666     m_myObject->resetQtFunctionInvoked();
  1736     m_myObject->resetQtFunctionInvoked();
  1667     m_myObject->emitMySignal();
  1737     m_myObject->emitMySignal();
  1668     QCOMPARE(m_myObject->qtFunctionInvoked(), 20);
  1738     QCOMPARE(m_myObject->qtFunctionInvoked(), 20);
  1669     evalJS("myObject = null");
  1739     evalJS("myObject = null");
  1670     evalJS("gc()");
  1740     garbageCollectJS();
  1671     m_myObject->resetQtFunctionInvoked();
  1741     m_myObject->resetQtFunctionInvoked();
  1672     m_myObject->emitMySignal();
  1742     m_myObject->emitMySignal();
  1673     QCOMPARE(m_myObject->qtFunctionInvoked(), 20);
  1743     QCOMPARE(m_myObject->qtFunctionInvoked(), 20);
  1674 }
  1744 }
  1675 
  1745