WebKit/qt/tests/qwebframe/tst_qwebframe.cpp
branchRCL_3
changeset 1 9d347b658349
parent 0 4f2f89ce4247
--- a/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp	Fri Sep 17 09:02:29 2010 +0300
+++ b/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp	Fri Sep 17 09:07:27 2010 +0300
@@ -37,6 +37,7 @@
 #include <qsslerror.h>
 #endif
 #include "../util.h"
+#include "../WebCoreSupport/DumpRenderTreeSupportQt.h"
 
 struct CustomType {
     QString string;
@@ -570,9 +571,11 @@
     void cleanup();
 
 private slots:
+    void getSetDynamicProperty();
+    void getSetDynamicProperty_data();
+    void getSetChildren();
+    void getSetChildren_data();
     void getSetStaticProperty();
-    void getSetDynamicProperty();
-    void getSetChildren();
     void callQtInvokable();
     void connectAndDisconnect();
     void classEnums();
@@ -668,6 +671,10 @@
         evalJS("delete retvalue; delete typevalue");
         return ret;
     }
+    void garbageCollectJS()
+    {
+        DumpRenderTreeSupportQt::garbageCollectorCollect();
+    }
     QObject* firstChildByClassName(QObject* parent, const char* className) {
         const QObjectList & children = parent->children();
         foreach (QObject* child, children) {
@@ -944,6 +951,8 @@
 
 void tst_QWebFrame::getSetDynamicProperty()
 {
+    QFETCH(bool, garbageCollect);
+
     // initially the object does not have the property
     // In WebKit, RuntimeObjects do not inherit Object, so don't have hasOwnProperty
 
@@ -955,11 +964,34 @@
     //QCOMPARE(evalJS("myObject.hasOwnProperty('dynamicProperty')"), sTrue);
     QCOMPARE(evalJS("typeof myObject.dynamicProperty != 'undefined'"), sTrue);
     QCOMPARE(evalJS("myObject.dynamicProperty == 123"), sTrue);
+    if( garbageCollect ) {
+        garbageCollectJS();
+        QCOMPARE(evalJS("typeof myObject.dynamicProperty != 'undefined'"), sTrue);
+    }
 
     // property change in script should be reflected in C++
     QCOMPARE(evalJS("myObject.dynamicProperty = 'foo';"
                     "myObject.dynamicProperty"), QLatin1String("foo"));
     QCOMPARE(m_myObject->property("dynamicProperty").toString(), QLatin1String("foo"));
+    if( garbageCollect ) {
+        garbageCollectJS();
+        QCOMPARE(m_myObject->property("dynamicProperty").toString(), QLatin1String("foo"));
+    }
+
+    // add a dynamic property in C++ to another QObject
+    QObject* propertyObject = new QObject(m_myObject);
+    QCOMPARE(m_myObject->setProperty("dynamicObjectProperty", qVariantFromValue(propertyObject)), false);
+    QCOMPARE(evalJS("typeof myObject.dynamicObjectProperty != 'undefined'"), sTrue);
+    evalJS("myObject.dynamicObjectProperty.jsProperty = 123");
+    QCOMPARE(evalJS("myObject.dynamicObjectProperty.jsProperty == 123"), sTrue);
+    if( garbageCollect ) {
+        garbageCollectJS();
+        QCOMPARE(evalJS("typeof myObject.dynamicObjectProperty != 'undefined'"), sTrue);
+        QCOMPARE(evalJS("myObject.dynamicObjectProperty.jsProperty == 123"), sTrue);
+    }
+    QCOMPARE(m_myObject->setProperty("dynamicObjectProperty", QVariant()), false);
+    delete propertyObject;
+    QCOMPARE(evalJS("typeof myObject.dynamicObjectProperty == 'undefined'"), sTrue);
 
     // delete the property (XFAIL - can't delete properties)
     QEXPECT_FAIL("", "can't delete properties", Continue);
@@ -970,10 +1002,21 @@
     //    QCOMPARE(evalJS("myObject.hasOwnProperty('dynamicProperty')"), sFalse);
     QCOMPARE(evalJS("typeof myObject.dynamicProperty"), sUndefined);
     */
+
+    evalJS("myObject.dynamicProperty = undefined");
+}
+
+void tst_QWebFrame::getSetDynamicProperty_data()
+{
+    QTest::addColumn<bool>("garbageCollect");
+    QTest::newRow("with garbageCollect") << true;
+    QTest::newRow("without garbageCollect") << false;
 }
 
 void tst_QWebFrame::getSetChildren()
 {
+    QFETCH(bool, garbageCollect);
+
     // initially the object does not have the child
     // (again, no hasOwnProperty)
 
@@ -985,12 +1028,27 @@
     child->setObjectName("child");
 //  QCOMPARE(evalJS("myObject.hasOwnProperty('child')"), sTrue);
     QCOMPARE(evalJS("typeof myObject.child != 'undefined'"), sTrue);
+    evalJS("myObject.child.jsProperty = 123");
+    QCOMPARE(evalJS("myObject.child.jsProperty == 123"), sTrue);
+
+    if( garbageCollect ) {
+        garbageCollectJS();
+        QCOMPARE(evalJS("typeof myObject.child != 'undefined'"), sTrue);
+        QCOMPARE(evalJS("myObject.child.jsProperty == 123"), sTrue);
+    }
 
     // add a grandchild
     MyQObject* grandChild = new MyQObject(child);
     grandChild->setObjectName("grandChild");
 //  QCOMPARE(evalJS("myObject.child.hasOwnProperty('grandChild')"), sTrue);
     QCOMPARE(evalJS("typeof myObject.child.grandChild != 'undefined'"), sTrue);
+    evalJS("myObject.child.grandChild.jsProperty = 123");
+    evalJS("myObject.child.grandChild.jsProperty = 123");
+    if( garbageCollect ) {
+        garbageCollectJS();
+        QCOMPARE(evalJS("typeof myObject.child.grandChild != 'undefined'"), sTrue);
+        QCOMPARE(evalJS("myObject.child.grandChild.jsProperty == 123"), sTrue);
+    }
 
     // delete grandchild
     delete grandChild;
@@ -1001,6 +1059,18 @@
     delete child;
 //  QCOMPARE(evalJS("myObject.hasOwnProperty('child')"), sFalse);
     QCOMPARE(evalJS("typeof myObject.child == 'undefined'"), sTrue);
+    if( garbageCollect ) {
+        garbageCollectJS();
+        QCOMPARE(evalJS("typeof myObject.child == 'undefined'"), sTrue);
+    }
+}
+
+
+void tst_QWebFrame::getSetChildren_data()
+{
+    QTest::addColumn<bool>("garbageCollect");
+    QTest::newRow("with garbageCollect") << true;
+    QTest::newRow("without garbageCollect") << false;
 }
 
 Q_DECLARE_METATYPE(QVector<int>)
@@ -1667,7 +1737,7 @@
     m_myObject->emitMySignal();
     QCOMPARE(m_myObject->qtFunctionInvoked(), 20);
     evalJS("myObject = null");
-    evalJS("gc()");
+    garbageCollectJS();
     m_myObject->resetQtFunctionInvoked();
     m_myObject->emitMySignal();
     QCOMPARE(m_myObject->qtFunctionInvoked(), 20);