Skip to content
Permalink
Browse files
[Qt] Don't use QSocketNotifier in the DRT for reading stdin
Reviewed by Simon Hausmann.

QSocketNotifier is not available on Windows. Instead we read
stdin synchronously after each test using signals and slots.

* DumpRenderTree/qt/DumpRenderTreeQt.cpp:
* DumpRenderTree/qt/DumpRenderTreeQt.h:
* DumpRenderTree/qt/main.cpp:

Canonical link: https://commits.webkit.org/44925@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@53526 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
torarnv committed Jan 20, 2010
1 parent 38d336c commit e8681479e14fd73e5bc08841b773a2e3ef43501b
Showing 4 changed files with 92 additions and 49 deletions.
@@ -1,3 +1,16 @@
2010-01-19 Tor Arne Vestbø <tor.arne.vestbo@nokia.com>

Reviewed by Simon Hausmann.

[Qt] Don't use QSocketNotifier in the DRT for reading stdin

QSocketNotifier is not available on Windows. Instead we read
stdin synchronously after each test using signals and slots.

* DumpRenderTree/qt/DumpRenderTreeQt.cpp:
* DumpRenderTree/qt/DumpRenderTreeQt.h:
* DumpRenderTree/qt/main.cpp:

2010-01-19 Adam Barth <abarth@webkit.org>

Rubber stamped by Eric Seidel.
@@ -310,8 +310,8 @@ QObject* WebPage::createPlugin(const QString& classId, const QUrl& url, const QS
DumpRenderTree::DumpRenderTree()
: m_dumpPixels(false)
, m_stdin(0)
, m_notifier(0)
, m_enableTextOutput(false)
, m_singleFileMode(false)
{
qt_drt_overwritePluginDirectories();
QWebSettings::enablePersistentStorage();
@@ -359,20 +359,6 @@ DumpRenderTree::~DumpRenderTree()
{
delete m_mainView;
delete m_stdin;
delete m_notifier;
}

void DumpRenderTree::open()
{
if (!m_stdin) {
m_stdin = new QFile;
m_stdin->open(stdin, QFile::ReadOnly);
}

if (!m_notifier) {
m_notifier = new QSocketNotifier(STDIN_FILENO, QSocketNotifier::Read);
connect(m_notifier, SIGNAL(activated(int)), this, SLOT(readStdin(int)));
}
}

static void clearHistory(QWebPage* page)
@@ -458,20 +444,59 @@ void DumpRenderTree::open(const QUrl& aurl)
m_page->mainFrame()->load(url);
}

void DumpRenderTree::readStdin(int /* socket */)
void DumpRenderTree::readLine()
{
// Read incoming data from stdin...
QByteArray line = m_stdin->readLine();
if (line.endsWith('\n'))
line.truncate(line.size()-1);
//fprintf(stderr, "\n opening %s\n", line.constData());
if (line.isEmpty())
quit();
if (!m_stdin) {
m_stdin = new QFile;
m_stdin->open(stdin, QFile::ReadOnly);

if (!m_stdin->isReadable()) {
emit quit();
return;
}
}

if (line.startsWith("http:") || line.startsWith("https:"))
QByteArray line = m_stdin->readLine().trimmed();

if (line.isEmpty()) {
emit quit();
return;
}

processLine(QString::fromLocal8Bit(line.constData(), line.length()));
}

void DumpRenderTree::processLine(const QString &input)
{
QString line = input;

if (line.startsWith(QLatin1String("http:"))
|| line.startsWith(QLatin1String("https:"))
|| line.startsWith(QLatin1String("file:"))) {
open(QUrl(line));
else {
} else {
QFileInfo fi(line);

if (!fi.exists()) {
QDir currentDir = QDir::currentPath();

// Try to be smart about where the test is located
if (currentDir.dirName() == QLatin1String("LayoutTests"))
fi = QFileInfo(currentDir, line.replace(QRegExp(".*?LayoutTests/(.*)"), "\\1"));
else if (!line.contains(QLatin1String("LayoutTests")))
fi = QFileInfo(currentDir, line.prepend(QLatin1String("LayoutTests/")));

if (!fi.exists()) {
if (isSingleFileMode())
emit quit();
else
emit ready();

return;
}

}

open(QUrl::fromLocalFile(fi.absoluteFilePath()));
}

@@ -617,9 +642,7 @@ void DumpRenderTree::dump()

QWebFrame *mainFrame = m_page->mainFrame();

//fprintf(stderr, " Dumping\n");
if (!m_notifier) {
// Dump markup in single file mode...
if (isSingleFileMode()) {
QString markup = mainFrame->toHtml();
fprintf(stdout, "Source:\n\n%s\n", markup.toUtf8().constData());
}
@@ -697,8 +720,10 @@ void DumpRenderTree::dump()
fflush(stdout);
fflush(stderr);

if (!m_notifier)
quit(); // Exit now in single file mode...
if (isSingleFileMode())
emit quit();
else
emit ready();
}

void DumpRenderTree::titleChanged(const QString &s)
@@ -68,15 +68,15 @@ Q_OBJECT
DumpRenderTree();
virtual ~DumpRenderTree();

// Initialize in multi-file mode, used by run-webkit-tests.
void open();

// Initialize in single-file mode.
void open(const QUrl& url);

void setTextOutputEnabled(bool enable) { m_enableTextOutput = enable; }
bool isTextOutputEnabled() { return m_enableTextOutput; }

void setSingleFileMode(bool flag) { m_singleFileMode = flag; }
bool isSingleFileMode() { return m_singleFileMode; }

void setDumpPixels(bool);

void closeRemainingWindows();
@@ -100,7 +100,10 @@ Q_OBJECT

public Q_SLOTS:
void initJSObjects();
void readStdin(int);

void readLine();
void processLine(const QString&);

void dump();
void titleChanged(const QString &s);
void connectFrame(QWebFrame *frame);
@@ -109,6 +112,7 @@ public Q_SLOTS:

Q_SIGNALS:
void quit();
void ready();

private:
QString dumpFramesAsText(QWebFrame* frame);
@@ -126,10 +130,10 @@ public Q_SLOTS:
GCController* m_gcController;

QFile *m_stdin;
QSocketNotifier* m_notifier;

QList<QObject*> windows;
bool m_enableTextOutput;
bool m_singleFileMode;
};

class NetworkAccessManager : public QNetworkAccessManager {
@@ -40,6 +40,7 @@
#include <qwebsettings.h>
#include <qwebdatabase.h>
#include <qdesktopservices.h>
#include <qtimer.h>
#include <qwindowsstyle.h>

#ifdef Q_WS_X11
@@ -133,38 +134,38 @@ int main(int argc, char* argv[])

QStringList args = app.arguments();
if (args.count() < 2) {
qDebug() << "Usage: DumpRenderTree [-v] filename";
qDebug() << "Usage: DumpRenderTree [-v|--pixel-tests] filename";
exit(0);
}

// supress debug output from Qt if not started with -v
// Suppress debug output from Qt if not started with -v
if (!args.contains(QLatin1String("-v")))
qInstallMsgHandler(messageHandler);

WebCore::DumpRenderTree dumper;

if (args.contains("--pixel-tests"))
if (args.contains(QLatin1String("--pixel-tests")))
dumper.setDumpPixels(true);

QString dbDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation) + QDir::separator() + "qtwebkitdrt";
QWebSettings::setOfflineStoragePath(dbDir);
QWebDatabase::removeAllDatabases();

if (args.last() == QLatin1String("-")) {
dumper.open();
if (args.contains(QLatin1String("-"))) {
QObject::connect(&dumper, SIGNAL(ready()), &dumper, SLOT(readLine()), Qt::QueuedConnection);
QTimer::singleShot(0, &dumper, SLOT(readLine()));
} else {
if (!args.last().startsWith("/")
&& !args.last().startsWith("file:")
&& !args.last().startsWith("http:")
&& !args.last().startsWith("https:")) {
QString path = QDir::currentPath();
if (!path.endsWith('/'))
path.append('/');
args.last().prepend(path);
dumper.setSingleFileMode(true);
for (int i = 1; i < args.size(); ++i) {
if (!args.at(i).startsWith('-')) {
dumper.processLine(args.at(i));
break;
}
}
dumper.open(QUrl(args.last()));
}

return app.exec();

#ifdef Q_WS_X11
FcConfigSetCurrent(0);
#endif

0 comments on commit e868147

Please sign in to comment.