diff options
Diffstat (limited to 'Tools/DumpRenderTree/qt/DumpRenderTreeQt.cpp')
-rwxr-xr-x | Tools/DumpRenderTree/qt/DumpRenderTreeQt.cpp | 127 |
1 files changed, 94 insertions, 33 deletions
diff --git a/Tools/DumpRenderTree/qt/DumpRenderTreeQt.cpp b/Tools/DumpRenderTree/qt/DumpRenderTreeQt.cpp index dea0edbc0..c0c285353 100755 --- a/Tools/DumpRenderTree/qt/DumpRenderTreeQt.cpp +++ b/Tools/DumpRenderTree/qt/DumpRenderTreeQt.cpp @@ -35,10 +35,12 @@ #include "DumpRenderTreeQt.h" #include "DumpRenderTreeSupportQt.h" #include "EventSenderQt.h" -#include "GCControllerQt.h" +#include "GCController.h" #include "InitWebCoreQt.h" #include "InitWebKitQt.h" +#include "JSStringRefQt.h" #include "QtTestSupport.h" +#include "TestRunner.h" #include "TestRunnerQt.h" #include "TextInputControllerQt.h" #include "testplugin.h" @@ -72,7 +74,7 @@ #include <unistd.h> #endif -namespace WebCore { +using namespace WebCore; const int databaseDefaultQuota = 5 * 1024 * 1024; @@ -192,10 +194,7 @@ void WebPage::resetSettings() m_drt->testRunner()->setCaretBrowsingEnabled(false); m_drt->testRunner()->setAuthorAndUserStylesEnabled(true); - m_drt->testRunner()->setFrameFlatteningEnabled(false); - m_drt->testRunner()->setSmartInsertDeleteEnabled(true); - m_drt->testRunner()->setSelectTrailingWhitespaceEnabled(false); - m_drt->testRunner()->setDefersLoading(false); + m_drt->jscTestRunner()->setDefersLoading(false); // globalSettings must be reset explicitly. m_drt->testRunner()->setXSSAuditorEnabled(false); @@ -203,7 +202,7 @@ void WebPage::resetSettings() QWebSettings::setMaximumPagesInCache(0); // reset to default settings()->setUserStyleSheetUrl(QUrl()); // reset to default - DumpRenderTreeSupportQt::setMinimumTimerInterval(handle(), DumpRenderTreeSupportQt::defaultMinimumTimerInterval()); + DumpRenderTreeSupportQt::setSeamlessIFramesEnabled(true); DumpRenderTreeSupportQt::resetInternalsObject(mainFrame()->handle()); @@ -384,6 +383,8 @@ WebViewGraphicsBased::WebViewGraphicsBased(QWidget* parent) scene()->addItem(m_item); } +static DumpRenderTree *s_instance = 0; + DumpRenderTree::DumpRenderTree() : m_dumpPixelsForAllTests(false) , m_stdin(0) @@ -392,6 +393,9 @@ DumpRenderTree::DumpRenderTree() , m_graphicsBased(false) , m_persistentStoragePath(QString(getenv("DUMPRENDERTREE_TEMP"))) { + ASSERT(!s_instance); + s_instance = this; + QByteArray viewMode = getenv("QT_DRT_WEBVIEW_MODE"); if (viewMode == "graphics") setGraphicsBased(true); @@ -423,7 +427,7 @@ DumpRenderTree::DumpRenderTree() DumpRenderTreeSupportQt::webPageSetGroupName(pageAdapter(), "org.webkit.qt.DumpRenderTree"); m_mainView->setContextMenuPolicy(Qt::NoContextMenu); - m_mainView->resize(QSize(TestRunner::maxViewWidth, TestRunner::maxViewHeight)); + m_mainView->resize(QSize(TestRunner::viewWidth, TestRunner::viewHeight)); // clean up cache by resetting quota. qint64 quota = webPage()->settings()->offlineWebApplicationCacheQuota(); @@ -431,7 +435,7 @@ DumpRenderTree::DumpRenderTree() // create our controllers. This has to be done before connectFrame, // as it exports there to the JavaScript DOM window. - m_controller = new TestRunner(this); + m_controller = new TestRunnerQt(this); connect(m_controller, SIGNAL(showPage()), this, SLOT(showPage())); connect(m_controller, SIGNAL(hidePage()), this, SLOT(hidePage())); @@ -441,7 +445,7 @@ DumpRenderTree::DumpRenderTree() connect(m_controller, SIGNAL(done()), this, SLOT(dump())); m_eventSender = new EventSender(m_page); m_textInputController = new TextInputController(m_page); - m_gcController = new GCController(m_page); + m_gcController.reset(new GCController()); // now connect our different signals connect(m_page, SIGNAL(frameCreated(QWebFrame *)), @@ -484,6 +488,12 @@ DumpRenderTree::~DumpRenderTree() fclose(stderr); delete m_mainView; delete m_stdin; + s_instance = 0; +} + +DumpRenderTree* DumpRenderTree::instance() +{ + return s_instance; } static void clearHistory(QWebPage* page) @@ -525,6 +535,8 @@ void DumpRenderTree::resetToConsistentStateBeforeTesting(const QUrl& url) // of the DRT. m_controller->reset(); + m_jscController = TestRunner::create(url.toString().toStdString(), m_expectedHash.toStdString()); + // reset mouse clicks counter m_eventSender->resetClickCount(); @@ -606,15 +618,15 @@ void DumpRenderTree::open(const QUrl& url) testRunner()->showWebInspector(); if (isDumpAsTextTest(url)) - testRunner()->dumpAsText(); + m_jscController->setDumpAsText(true); if (isGlobalHistoryTest(url)) testRunner()->dumpHistoryCallbacks(); // W3C SVG tests expect to be 480x360 bool isW3CTest = url.toString().contains("svg/W3C-SVG-1.1"); - int width = isW3CTest ? 480 : TestRunner::maxViewWidth; - int height = isW3CTest ? 360 : TestRunner::maxViewHeight; + int width = isW3CTest ? TestRunner::w3cSVGViewWidth : TestRunner::viewWidth; + int height = isW3CTest ? TestRunner::w3cSVGViewHeight : TestRunner::viewHeight; m_mainView->resize(QSize(width, height)); m_page->setPreferredContentsSize(QSize()); m_page->setViewportSize(QSize(width, height)); @@ -720,6 +732,8 @@ void DumpRenderTree::processLine(const QString &input) open(QUrl::fromLocalFile(fi.absoluteFilePath())); } + if (command.timeout > 0) + setTimeout(command.timeout); fflush(stdout); } @@ -734,10 +748,51 @@ void DumpRenderTree::initJSObjects() { QWebFrame *frame = qobject_cast<QWebFrame*>(sender()); Q_ASSERT(frame); + + JSContextRef context = 0; + JSObjectRef window = 0; + + DumpRenderTreeSupportQt::getJSWindowObject(frame->handle(), &context, &window); + frame->addToJavaScriptWindowObject(QLatin1String("testRunner"), m_controller); frame->addToJavaScriptWindowObject(QLatin1String("eventSender"), m_eventSender); frame->addToJavaScriptWindowObject(QLatin1String("textInputController"), m_textInputController); - frame->addToJavaScriptWindowObject(QLatin1String("GCController"), m_gcController); + m_gcController->makeWindowObject(context, window, 0); + + if (m_jscController) { + JSObjectRef dummyWindow = JSObjectMake(context, 0, 0); + m_jscController->makeWindowObject(context, dummyWindow, 0); + JSRetainPtr<JSStringRef> testRunnerName(Adopt, JSStringCreateWithUTF8CString("testRunner")); + JSValueRef wrappedTestRunner = JSObjectGetProperty(context, dummyWindow, testRunnerName.get(), 0); + JSRetainPtr<JSStringRef> helperScript(Adopt, JSStringCreateWithUTF8CString("(function() {\n" + " function bind(fun, thisArg) {\n" + " return function() {\n" + " return fun.apply(thisArg, Array.prototype.slice.call(arguments));\n" + " }\n" + " }\n" + "for (var prop in this.jscBasedTestRunner) {\n" + " var pd = Object.getOwnPropertyDescriptor(this.qtBasedTestRunner, prop);\n" + " if (pd !== undefined) continue;\n" + " pd = Object.getOwnPropertyDescriptor(this.jscBasedTestRunner, prop);\n" + " this.qtBasedTestRunner[prop] = bind(this.jscBasedTestRunner[prop], this.jscBasedTestRunner);\n" + "}\n" + "}).apply(this)\n")); + + JSRetainPtr<JSStringRef> qtBasedTestRunnerName(Adopt, JSStringCreateWithUTF8CString("qtBasedTestRunner")); + JSRetainPtr<JSStringRef> jscBasedTestRunnerName(Adopt, JSStringCreateWithUTF8CString("jscBasedTestRunner")); + + JSObjectRef args = JSObjectMake(context, 0, 0); + JSObjectSetProperty(context, args, qtBasedTestRunnerName.get(), JSObjectGetProperty(context, window, testRunnerName.get(), 0), 0, 0); + JSObjectSetProperty(context, args, jscBasedTestRunnerName.get(), wrappedTestRunner, 0, 0); + + JSValueRef ex = 0; + JSEvaluateScript(context, helperScript.get(), args, 0, 0, &ex); + if (ex) { + JSRetainPtr<JSStringRef> msg(Adopt, JSValueToStringCopy(context, ex, 0)); + fprintf(stderr, "Error evaluating TestRunner setup-script: %s\n", qPrintable(JSStringCopyQString(msg.get()))); + } + } + DumpRenderTreeSupportQt::injectInternalsObject(frame->handle()); } @@ -768,7 +823,7 @@ QString DumpRenderTree::dumpFrameScrollPosition(QWebFrame* frame) result.append(QString("scrolled to %1,%2\n").arg(pos.x()).arg(pos.y())); } - if (m_controller->shouldDumpChildFrameScrollPositions()) { + if (m_jscController->dumpChildFrameScrollPositions()) { QList<QWebFrame*> children = frame->childFrames(); for (int i = 0; i < children.size(); ++i) result += dumpFrameScrollPosition(children.at(i)); @@ -793,7 +848,7 @@ QString DumpRenderTree::dumpFramesAsText(QWebFrame* frame) result.append(innerText); result.append(QLatin1String("\n")); - if (m_controller->shouldDumpChildrenAsText()) { + if (m_jscController->dumpChildFramesAsText()) { QList<QWebFrame *> children = frame->childFrames(); for (int i = 0; i < children.size(); ++i) result += dumpFramesAsText(children.at(i)); @@ -880,7 +935,7 @@ QString DumpRenderTree::dumpBackForwardList(QWebPage* page) static const char *methodNameStringForFailedTest(TestRunner *controller) { const char *errorMessage; - if (controller->shouldDumpAsText()) + if (controller->dumpAsText()) errorMessage = "[documentElement innerText]"; // FIXME: Add when we have support //else if (controller->dumpDOMAsWebArchive()) @@ -908,38 +963,46 @@ void DumpRenderTree::dump() QString mimeType = DumpRenderTreeSupportQt::responseMimeType(mainFrame->handle()); if (mimeType == "text/plain") - m_controller->dumpAsText(); + m_jscController->setDumpAsText(true); // Dump render text... QString resultString; - if (m_controller->shouldDumpAsText()) + QString resultContentType = "text/plain"; + QByteArray resultData; + if (m_controller->shouldDumpAsAudio()) { + resultContentType = "audio/wav"; + resultData = m_controller->audioData(); + } else if (m_jscController->dumpAsText()) resultString = dumpFramesAsText(mainFrame); else { resultString = DumpRenderTreeSupportQt::frameRenderTreeDump(mainFrame->handle()); resultString += dumpFrameScrollPosition(mainFrame); } if (!resultString.isEmpty()) { - fprintf(stdout, "Content-Type: text/plain\n"); + fprintf(stdout, "Content-Type: %s\n", resultContentType.toUtf8().constData()); fprintf(stdout, "%s", resultString.toUtf8().constData()); - if (m_controller->shouldDumpBackForwardList()) { + if (m_jscController->dumpBackForwardList()) { fprintf(stdout, "%s", dumpBackForwardList(webPage()).toUtf8().constData()); foreach (QObject* widget, windows) { QWebPage* page = qobject_cast<QWebPage*>(widget->findChild<QWebPage*>()); fprintf(stdout, "%s", dumpBackForwardList(page).toUtf8().constData()); } } - + } else if (!resultData.isEmpty()) { + fprintf(stdout, "Content-Type: %s\n", resultContentType.toUtf8().constData()); + fprintf(stdout, "Content-Transfer-Encoding: base64\n"); + fprintf(stdout, "%s", resultData.toBase64().constData()); } else - printf("ERROR: nil result from %s", methodNameStringForFailedTest(m_controller)); + printf("ERROR: nil result from %s", methodNameStringForFailedTest(m_jscController.get())); // signal end of text block fputs("#EOF\n", stdout); fputs("#EOF\n", stderr); - if (m_dumpPixelsForCurrentTest && m_controller->shouldDumpPixels()) { + if (m_dumpPixelsForCurrentTest && m_jscController->generatePixelResults()) { QImage image; - if (!m_controller->isPrinting()) { + if (!m_jscController->isPrinting()) { image = QImage(m_page->viewportSize(), QImage::Format_ARGB32); image.fill(Qt::white); QPainter painter(&image); @@ -1020,7 +1083,7 @@ void DumpRenderTree::dump() void DumpRenderTree::titleChanged(const QString &s) { - if (m_controller->shouldDumpTitleChanges()) + if (m_jscController->dumpTitleChanges()) printf("TITLE CHANGED: '%s'\n", s.toUtf8().data()); } @@ -1033,7 +1096,7 @@ void DumpRenderTree::connectFrame(QWebFrame *frame) void DumpRenderTree::dumpDatabaseQuota(QWebFrame* frame, const QString& dbName) { - if (!m_controller->shouldDumpDatabaseCallbacks()) + if (!m_jscController->dumpDatabaseCallbacks()) return; QWebSecurityOrigin origin = frame->securityOrigin(); printf("UI DELEGATE DATABASE CALLBACK: exceededDatabaseQuotaForSecurityOrigin:{%s, %s, %i} database:%s\n", @@ -1046,7 +1109,7 @@ void DumpRenderTree::dumpDatabaseQuota(QWebFrame* frame, const QString& dbName) void DumpRenderTree::dumpApplicationCacheQuota(QWebSecurityOrigin* origin, quint64 defaultOriginQuota, quint64 totalSpaceNeeded) { - if (m_controller->shouldDumpApplicationCacheDelegateCallbacks()) { + if (m_jscController->dumpApplicationCacheDelegateCallbacks()) { // For example, numbers from 30000 - 39999 will output as 30000. // Rounding up or down not really matter for these tests. It's // sufficient to just get a range of 10000 to determine if we were @@ -1060,7 +1123,7 @@ void DumpRenderTree::dumpApplicationCacheQuota(QWebSecurityOrigin* origin, quint ); } - if (m_controller->shouldDisallowIncreaseForApplicationCacheQuota()) + if (m_jscController->disallowIncreaseForApplicationCacheQuota()) return; origin->setApplicationCacheQuota(defaultOriginQuota); @@ -1068,7 +1131,7 @@ void DumpRenderTree::dumpApplicationCacheQuota(QWebSecurityOrigin* origin, quint void DumpRenderTree::statusBarMessage(const QString& message) { - if (!m_controller->shouldDumpStatusCallbacks()) + if (!m_jscController->dumpStatusCallbacks()) return; printf("UI DELEGATE STATUS CALLBACK: setStatusText:%s\n", message.toUtf8().constData()); @@ -1076,7 +1139,7 @@ void DumpRenderTree::statusBarMessage(const QString& message) QWebPage *DumpRenderTree::createWindow() { - if (!m_controller->canOpenWindows()) + if (!m_jscController->canOpenWindows()) return 0; // Create a dummy container object to track the page in DRT. @@ -1163,5 +1226,3 @@ void DumpRenderTree::setShouldTimeout(bool flag) { m_controller->setShouldTimeout(flag); } - -} |