2011-06-14 Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org>

        Reviewed by Andreas Kling.

        [Qt] tst_QWebFrame::overloadedSlots() fails
        https://bugs.webkit.org/show_bug.cgi?id=37319

        Increase the likeness that JSElements are converted to QWebElements. When hinted
        with QWebElement metatype, we qualify the conversion from JSElement as a "perfect
        match".

        The test was failing because the wrong slot was called, since the QWebElement
        match was taken as equal to the others and not chosen when the metacall happened.

        We also remove the implicit conversion between JSDocument (which is not an
        element) to QWebElement. The conversion only worked for calling slots, while
        without hint it returned a QVariantMap (as can be seen in domCycles test). It was
        added for supporting DRT, but since this change we can use it as QVariantMap and
        get the value for "documentElement".

        This patch is based on Noam Rosenthal original patch in the same bug.

        * bridge/qt/qt_runtime.cpp:
        (JSC::Bindings::hintForRealType):
        Extracted function to choose the metatype hint based on the JSValue type.  Add
        QWebElement metatype as a hint for JSElement objects, this way if no hint is
        provided, JSElement objects will always be converted to QWebElements.

        (JSC::Bindings::convertValueToQVariant):
        Use previous function. Identify the conversion between JSElement to QWebElement
        as a "perfect match" (dist = 0). And remove the implicit conversion when the hint
        is QWebElement metatype and we have a JSDocument.  Changed from JSHTMLElement to
        JSElement to cover the 'documentElement'.
2011-06-14  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>

        Reviewed by Andreas Kling.

        [Qt] tst_QWebFrame::overloadedSlots() fails
        https://bugs.webkit.org/show_bug.cgi?id=37319

        Since the implicit conversion was removed, change support functions of DRT to
        expect a QVariantMap instead of a QWebElement. This matches the exposed function
        in the controller, which takes 'document' and not 'document.documentElement'.

        And now that Element -> QWebElement is a perfect match, we must use QWebElement
        instead of QVariantMap, like in plainText().

        * WebCoreSupport/DumpRenderTreeSupportQt.h:
        * WebCoreSupport/DumpRenderTreeSupportQt.cpp:
        (DumpRenderTreeSupportQt::plainText): Fix to use QWebElement instead of
        QVariantMap when getting the startContainer. Also use QVariantMap directly,
        bridge will do conversion for us now.

        (getCoreDocumentFromVariantMap): Extracts the WebCore::Document* from the
        QVariantMap that Qt bridge gives us when 'document' is passed from JS.

        (DumpRenderTreeSupportQt::nodesFromRect): Use helper function.

        * tests/qwebframe/tst_qwebframe.cpp: Splitted the test domCycles() into two
        different tests. In practice, the original test just checked whether we could
        create a QVariantMap representing 'document' without infinite looping due to
        cycles in the DOM. This was more evident before since we haven't a conversion
        from JSElement to QWebElement, but from JSElement to QVariantMap.

        (tst_QWebFrame::documentHasDocumentElement): Evaluates 'document' and extracts
        'documentElement' from it. Compares to QWebFrame::documentElement().

        (tst_QWebFrame::documentAllHasDocumentElement): Look inside 'document.all' for
        the documentElement.

        (tst_QWebFrame::overloadedSlots): Remove expected failure and fix wrong comment.
2011-06-14  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>

        Reviewed by Andreas Kling.

        [Qt] tst_QWebFrame::overloadedSlots() fails
        https://bugs.webkit.org/show_bug.cgi?id=37319

        Since we don't implictly convert 'document' object to QWebElement
        in metacalls anymore, change the controller to expect QVariantMap instead.

        The method plainText() was updated to use QVariantMap as well to let the bridge
        do the conversion directly for us.

        * DumpRenderTree/qt/LayoutTestControllerQt.cpp:
        (LayoutTestController::nodesFromRect):
        * DumpRenderTree/qt/LayoutTestControllerQt.h:
        * DumpRenderTree/qt/PlainTextControllerQt.cpp:
        (PlainTextController::plainText):
        * DumpRenderTree/qt/PlainTextControllerQt.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@88796 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f415b6cf
2011-06-14 Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org>
Reviewed by Andreas Kling.
[Qt] tst_QWebFrame::overloadedSlots() fails
https://bugs.webkit.org/show_bug.cgi?id=37319
Increase the likeness that JSElements are converted to QWebElements. When hinted
with QWebElement metatype, we qualify the conversion from JSElement as a "perfect
match".
The test was failing because the wrong slot was called, since the QWebElement
match was taken as equal to the others and not chosen when the metacall happened.
We also remove the implicit conversion between JSDocument (which is not an
element) to QWebElement. The conversion only worked for calling slots, while
without hint it returned a QVariantMap (as can be seen in domCycles test). It was
added for supporting DRT, but since this change we can use it as QVariantMap and
get the value for "documentElement".
This patch is based on Noam Rosenthal original patch in the same bug.
* bridge/qt/qt_runtime.cpp:
(JSC::Bindings::hintForRealType):
Extracted function to choose the metatype hint based on the JSValue type. Add
QWebElement metatype as a hint for JSElement objects, this way if no hint is
provided, JSElement objects will always be converted to QWebElements.
(JSC::Bindings::convertValueToQVariant):
Use previous function. Identify the conversion between JSElement to QWebElement
as a "perfect match" (dist = 0). And remove the implicit conversion when the hint
is QWebElement metatype and we have a JSDocument. Changed from JSHTMLElement to
JSElement to cover the 'documentElement'.
2011-06-14 Andreas Kling <kling@webkit.org>
Reviewed by Benjamin Poulain.
......
......@@ -182,6 +182,38 @@ static JSRealType valueRealType(ExecState* exec, JSValue val)
return String; // I don't know.
}
static QMetaType::Type hintForRealType(JSRealType type, JSObject* object)
{
switch (type) {
case Number:
return QMetaType::Double;
case Boolean:
return QMetaType::Bool;
case String:
return QMetaType::QString;
case Date:
return QMetaType::QDateTime;
case RegExp:
return QMetaType::QRegExp;
case Object:
if (object->inherits(&NumberObject::s_info))
return QMetaType::Double;
if (object->inherits(&BooleanObject::s_info))
return QMetaType::Bool;
if (object->inherits(&JSElement::s_info))
return static_cast<QMetaType::Type>(qMetaTypeId<QWebElement>());
return QMetaType::QVariantMap;
case QObj:
return QMetaType::QObjectStar;
case JSByteArray:
return QMetaType::QByteArray;
case Array:
case RTArray:
return QMetaType::QVariantList;
}
return QMetaType::QString;
}
QVariant convertValueToQVariant(ExecState*, JSValue, QMetaType::Type, int*, HashSet<JSObject*>*, int);
static QVariantMap convertValueToQVariantMap(ExecState* exec, JSObject* object, HashSet<JSObject*>* visitedObjects, int recursionLimit)
......@@ -241,44 +273,8 @@ QVariant convertValueToQVariant(ExecState* exec, JSValue value, QMetaType::Type
JSLock lock(SilenceAssertionsOnly);
JSRealType type = valueRealType(exec, value);
if (hint == QMetaType::Void) {
switch(type) {
case Number:
hint = QMetaType::Double;
break;
case Boolean:
hint = QMetaType::Bool;
break;
case String:
default:
hint = QMetaType::QString;
break;
case Date:
hint = QMetaType::QDateTime;
break;
case RegExp:
hint = QMetaType::QRegExp;
break;
case Object:
if (object->inherits(&NumberObject::s_info))
hint = QMetaType::Double;
else if (object->inherits(&BooleanObject::s_info))
hint = QMetaType::Bool;
else
hint = QMetaType::QVariantMap;
break;
case QObj:
hint = QMetaType::QObjectStar;
break;
case JSByteArray:
hint = QMetaType::QByteArray;
break;
case Array:
case RTArray:
hint = QMetaType::QVariantList;
break;
}
}
if (hint == QMetaType::Void)
hint = hintForRealType(type, object);
qConvDebug() << "convertValueToQVariant: jstype is " << type << ", hint is" << hint;
......@@ -778,12 +774,15 @@ QVariant convertValueToQVariant(ExecState* exec, JSValue value, QMetaType::Type
} else if (QtPixmapInstance::canHandle(static_cast<QMetaType::Type>(hint))) {
ret = QtPixmapInstance::variantFromObject(object, static_cast<QMetaType::Type>(hint));
} else if (hint == (QMetaType::Type) qMetaTypeId<QWebElement>()) {
if (object && object->inherits(&JSHTMLElement::s_info))
ret = QVariant::fromValue<QWebElement>(QtWebElementRuntime::create((static_cast<JSHTMLElement*>(object))->impl()));
else if (object && object->inherits(&JSDocument::s_info))
ret = QVariant::fromValue<QWebElement>(QtWebElementRuntime::create((static_cast<JSDocument*>(object))->impl()->documentElement()));
else
ret = QVariant::fromValue<QWebElement>(QWebElement());
if (object && object->inherits(&JSElement::s_info)) {
ret = QVariant::fromValue<QWebElement>(QtWebElementRuntime::create((static_cast<JSElement*>(object))->impl()));
dist = 0;
// Allow other objects to reach this one. This won't cause our algorithm to
// loop since when we find an Element we do not recurse.
visitedObjects->remove(object);
break;
}
ret = QVariant::fromValue<QWebElement>(QWebElement());
} else if (hint == (QMetaType::Type) qMetaTypeId<QDRTNode>()) {
if (object && object->inherits(&JSNode::s_info))
ret = QVariant::fromValue<QDRTNode>(QtDRTNodeRuntime::create((static_cast<JSNode*>(object))->impl()));
......
2011-06-14 Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org>
Reviewed by Andreas Kling.
[Qt] tst_QWebFrame::overloadedSlots() fails
https://bugs.webkit.org/show_bug.cgi?id=37319
Since the implicit conversion was removed, change support functions of DRT to
expect a QVariantMap instead of a QWebElement. This matches the exposed function
in the controller, which takes 'document' and not 'document.documentElement'.
And now that Element -> QWebElement is a perfect match, we must use QWebElement
instead of QVariantMap, like in plainText().
* WebCoreSupport/DumpRenderTreeSupportQt.h:
* WebCoreSupport/DumpRenderTreeSupportQt.cpp:
(DumpRenderTreeSupportQt::plainText): Fix to use QWebElement instead of
QVariantMap when getting the startContainer. Also use QVariantMap directly,
bridge will do conversion for us now.
(getCoreDocumentFromVariantMap): Extracts the WebCore::Document* from the
QVariantMap that Qt bridge gives us when 'document' is passed from JS.
(DumpRenderTreeSupportQt::nodesFromRect): Use helper function.
* tests/qwebframe/tst_qwebframe.cpp: Splitted the test domCycles() into two
different tests. In practice, the original test just checked whether we could
create a QVariantMap representing 'document' without infinite looping due to
cycles in the DOM. This was more evident before since we haven't a conversion
from JSElement to QWebElement, but from JSElement to QVariantMap.
(tst_QWebFrame::documentHasDocumentElement): Evaluates 'document' and extracts
'documentElement' from it. Compares to QWebFrame::documentElement().
(tst_QWebFrame::documentAllHasDocumentElement): Look inside 'document.all' for
the documentElement.
(tst_QWebFrame::overloadedSlots): Remove expected failure and fix wrong comment.
2011-06-14 Andreas Kling <kling@webkit.org>
Reviewed by Benjamin Poulain.
......
......@@ -974,23 +974,31 @@ void DumpRenderTreeSupportQt::simulateDesktopNotificationClick(const QString& ti
#endif
}
QString DumpRenderTreeSupportQt::plainText(const QVariant& range)
QString DumpRenderTreeSupportQt::plainText(const QVariantMap& range)
{
QMap<QString, QVariant> map = range.toMap();
QVariant startContainer = map.value(QLatin1String("startContainer"));
map = startContainer.toMap();
QVariant v = range.value(QLatin1String("startContainer"));
ASSERT(v.isValid());
QWebElement startContainer = qvariant_cast<QWebElement>(v);
return startContainer.toPlainText();
}
WebCore::Document* DumpRenderTreeSupportQt::getCoreDocumentFromVariantMap(const QVariantMap& document)
{
QVariant v = document.value(QLatin1String("documentElement"));
ASSERT(v.isValid());
QWebElement documentElement = qvariant_cast<QWebElement>(v);
WebCore::Element* element = documentElement.m_element;
if (!element)
return 0;
return map.value(QLatin1String("innerText")).toString();
return element->document();
}
QVariantList DumpRenderTreeSupportQt::nodesFromRect(const QWebElement& document, int x, int y, unsigned top, unsigned right, unsigned bottom, unsigned left, bool ignoreClipping)
QVariantList DumpRenderTreeSupportQt::nodesFromRect(const QVariantMap& document, int x, int y, unsigned top, unsigned right, unsigned bottom, unsigned left, bool ignoreClipping)
{
QVariantList res;
WebCore::Element* webElement = document.m_element;
if (!webElement)
return res;
Document* doc = webElement->document();
Document* doc = getCoreDocumentFromVariantMap(document);
if (!doc)
return res;
RefPtr<NodeList> nodes = doc->nodesFromRect(x, y, top, right, bottom, left, ignoreClipping);
......
......@@ -27,6 +27,7 @@
#include <QVariant>
namespace WebCore {
class Document;
class Text;
class Node;
}
......@@ -160,7 +161,7 @@ public:
static QString markerTextForListItem(const QWebElement& listItem);
static QVariantMap computedStyleIncludingVisitedInfo(const QWebElement& element);
static QString plainText(const QVariant& rng);
static QString plainText(const QVariantMap& range);
static void dumpFrameLoader(bool b);
static void dumpUserGestureInFrameLoader(bool b);
......@@ -198,7 +199,7 @@ public:
static void scalePageBy(QWebFrame*, float scale, const QPoint& origin);
static QVariantList nodesFromRect(const QWebElement& document, int x, int y, unsigned top, unsigned right, unsigned bottom, unsigned left, bool ignoreClipping);
static QVariantList nodesFromRect(const QVariantMap& document, int x, int y, unsigned top, unsigned right, unsigned bottom, unsigned left, bool ignoreClipping);
static QString responseMimeType(QWebFrame*);
static void clearOpener(QWebFrame*);
static void addURLToRedirect(const QString& origin, const QString& destination);
......@@ -218,6 +219,9 @@ public:
static QString layerTreeAsText(QWebFrame*);
static void injectInternalsObject(QWebFrame*);
private:
static WebCore::Document* getCoreDocumentFromVariantMap(const QVariantMap& document);
};
#endif
......@@ -612,7 +612,8 @@ private slots:
void symmetricUrl();
void progressSignal();
void urlChange();
void domCycles();
void documentHasDocumentElement();
void documentAllHasDocumentElement();
void requestedUrl();
void requestedUrlAfterSetAndLoadFailures();
void javaScriptWindowObjectCleared_data();
......@@ -2004,10 +2005,9 @@ void tst_QWebFrame::overloadedSlots()
QCOMPARE(m_myObject->qtFunctionInvoked(), 35);
*/
// should pick myOverloadedSlot(QRegExp)
// should pick myOverloadedSlot(QWebElement)
m_myObject->resetQtFunctionInvoked();
evalJS("myObject.myOverloadedSlot(document.body)");
QEXPECT_FAIL("", "https://bugs.webkit.org/show_bug.cgi?id=37319", Continue);
QCOMPARE(m_myObject->qtFunctionInvoked(), 36);
// should pick myOverloadedSlot(QObject*)
......@@ -2291,11 +2291,46 @@ void tst_QWebFrame::urlChange()
}
void tst_QWebFrame::domCycles()
void tst_QWebFrame::documentHasDocumentElement()
{
m_view->setHtml("<html><body></body></html>");
QVariant docVariant = m_page->mainFrame()->evaluateJavaScript("document");
QVERIFY(docVariant.isValid());
QCOMPARE(docVariant.type(), QVariant::Map);
QVariantMap document = docVariant.toMap();
QVariant docElementVariant = document.value("documentElement");
QVERIFY(docElementVariant.isValid());
QCOMPARE(docElementVariant.userType(), qMetaTypeId<QWebElement>());
QWebElement documentElement = qvariant_cast<QWebElement>(docElementVariant);
QVERIFY(!documentElement.isNull());
QCOMPARE(documentElement, m_page->mainFrame()->documentElement());
}
void tst_QWebFrame::documentAllHasDocumentElement()
{
m_view->setHtml("<html><body>");
QVariant v = m_page->mainFrame()->evaluateJavaScript("document");
QVERIFY(v.type() == QVariant::Map);
m_view->setHtml("<html><body></body></html>");
QVariant docVariant = m_page->mainFrame()->evaluateJavaScript("document");
QVariantMap document = docVariant.toMap();
QVariant allVariant = document.value("all");
QVERIFY(allVariant.isValid());
QCOMPARE(allVariant.type(), QVariant::Map);
QVariantMap all = allVariant.toMap();
bool foundDocumentElement = false;
foreach (QVariant v, all.values()) {
if (v.userType() != qMetaTypeId<QWebElement>())
continue;
QWebElement e = qvariant_cast<QWebElement>(v);
if (e == m_page->mainFrame()->documentElement()) {
foundDocumentElement = true;
break;
}
}
QVERIFY(foundDocumentElement);
}
class FakeReply : public QNetworkReply {
......
2011-06-14 Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org>
Reviewed by Andreas Kling.
[Qt] tst_QWebFrame::overloadedSlots() fails
https://bugs.webkit.org/show_bug.cgi?id=37319
Since we don't implictly convert 'document' object to QWebElement
in metacalls anymore, change the controller to expect QVariantMap instead.
The method plainText() was updated to use QVariantMap as well to let the bridge
do the conversion directly for us.
* DumpRenderTree/qt/LayoutTestControllerQt.cpp:
(LayoutTestController::nodesFromRect):
* DumpRenderTree/qt/LayoutTestControllerQt.h:
* DumpRenderTree/qt/PlainTextControllerQt.cpp:
(PlainTextController::plainText):
* DumpRenderTree/qt/PlainTextControllerQt.h:
2011-06-14 Andras Becsi <abecsi@webkit.org>
Reviewed by Csaba Osztrogonác.
......
......@@ -909,7 +909,7 @@ bool LayoutTestController::hasSpellingMarker(int, int)
return false;
}
QVariantList LayoutTestController::nodesFromRect(const QWebElement& document, int x, int y, unsigned top, unsigned right, unsigned bottom, unsigned left, bool ignoreClipping)
QVariantList LayoutTestController::nodesFromRect(const QVariantMap& document, int x, int y, unsigned top, unsigned right, unsigned bottom, unsigned left, bool ignoreClipping)
{
return DumpRenderTreeSupportQt::nodesFromRect(document, x, y, top, right, bottom, left, ignoreClipping);
}
......
......@@ -236,7 +236,7 @@ public slots:
void abortModal() {}
bool hasSpellingMarker(int from, int length);
QVariantList nodesFromRect(const QWebElement& document, int x, int y, unsigned top, unsigned right, unsigned bottom, unsigned left, bool ignoreClipping);
QVariantList nodesFromRect(const QVariantMap& document, int x, int y, unsigned top, unsigned right, unsigned bottom, unsigned left, bool ignoreClipping);
void addURLToRedirect(const QString& origin, const QString& destination);
......
......@@ -38,7 +38,7 @@ PlainTextController::PlainTextController(QWebPage* parent)
{
}
QString PlainTextController::plainText(const QVariant& range)
QString PlainTextController::plainText(const QVariantMap& range)
{
return DumpRenderTreeSupportQt::plainText(range);
}
......@@ -41,7 +41,7 @@ public:
PlainTextController(QWebPage* parent);
public slots:
QString plainText(const QVariant& range);
QString plainText(const QVariantMap& range);
};
#endif // PlainTextControllerQt_h
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment