2 * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "DumpRenderTree.h"
36 #include "FrameView.h"
38 #include "FrameLoader.h"
39 #include "RenderTreeAsText.h"
40 #include "ChromeClientQt.h"
46 #include <QScrollArea>
47 #include <QApplication>
53 // Choose some default values.
54 const unsigned int maxViewWidth = 800;
55 const unsigned int maxViewHeight = 600;
57 DumpRenderTree::DumpRenderTree()
59 , m_client(new DumpRenderTreeClient())
63 // Initialize WebCore in Qt platform mode...
64 Page* page = new Page(new ChromeClientQt());
65 m_frame = new FrameQt(page, 0, m_client);
67 FrameView* view = new FrameView(m_frame);
68 view->setScrollbarsMode(ScrollbarAlwaysOff);
70 m_frame->setView(view);
71 view->setParentWidget(0 /* no toplevel widget */);
73 // Reverse calculations in QAbstractScrollArea::maximumViewportSize()
74 QScrollArea* area = qobject_cast<QScrollArea*>(m_frame->view()->qwidget());
76 unsigned int viewWidth = maxViewWidth + 2 * area->frameWidth();
77 unsigned int viewHeight = maxViewHeight + 2 * area->frameWidth();
79 area->resize(viewWidth, viewHeight);
81 // Read file containing to be skipped tests...
85 DumpRenderTree::~DumpRenderTree()
94 void DumpRenderTree::open()
97 m_stdin = new QTextStream(stdin, IO_ReadOnly);
100 m_notifier = new QSocketNotifier(STDIN_FILENO, QSocketNotifier::Read);
101 connect(m_notifier, SIGNAL(activated(int)), this, SLOT(readStdin(int)));
105 void DumpRenderTree::open(const KURL& url)
107 Q_ASSERT(url.isLocalFile());
109 // Ignore skipped tests
110 if (m_skipped.indexOf(url.path()) != -1) {
111 fprintf(stdout, "#EOF\n");
116 m_frame->client()->openURL(url);
118 // Simple poll mechanism, to find out when the page is loaded...
122 void DumpRenderTree::readStdin(int /* socket */)
124 // Read incoming data from stdin...
125 QString line = m_stdin->readLine();
127 open(KURL(line.toLatin1()));
130 void DumpRenderTree::readSkipFile()
132 Q_ASSERT(m_skipped.isEmpty());
134 QFile file("WebKitTools/DumpRenderTree/DumpRenderTree.qtproj/tests-skipped.txt");
135 if (!file.exists()) {
136 qFatal("Run DumpRenderTree from the source root directory!\n");
140 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
141 qFatal("Couldn't read skip file!\n");
145 QString testsPath = QDir::currentPath() + "/LayoutTests/";
146 while (!file.atEnd()) {
147 QByteArray line = file.readLine();
149 // Remove trailing line feed
153 if (line.isEmpty() || line.startsWith('#'))
156 m_skipped.append(testsPath + line);
160 void DumpRenderTree::checkLoaded()
162 if (m_frame->loader()->isComplete()) {
164 // Dump markup in single file mode...
165 DeprecatedString markup = createMarkup(m_frame->document());
166 fprintf(stdout, "Source:\n\n%s\n", markup.ascii());
169 // Dump render text...
170 DeprecatedString renderDump = externalRepresentation(m_frame->renderer());
171 fprintf(stdout, "%s#EOF\n", renderDump.ascii());
175 // Exit now in single file mode...
176 QApplication::exit();
179 QTimer::singleShot(10, this, SLOT(checkLoaded()));
182 FrameQt* DumpRenderTree::frame() const
189 #include "DumpRenderTree.moc"