|
1 /* |
|
2 * Copyright (C) 2006 Trolltech ASA |
|
3 * |
|
4 * Redistribution and use in source and binary forms, with or without |
|
5 * modification, are permitted provided that the following conditions |
|
6 * are met: |
|
7 * |
|
8 * 1. Redistributions of source code must retain the above copyright |
|
9 * notice, this list of conditions and the following disclaimer. |
|
10 * 2. Redistributions in binary form must reproduce the above copyright |
|
11 * notice, this list of conditions and the following disclaimer in the |
|
12 * documentation and/or other materials provided with the distribution. |
|
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
|
14 * its contributors may be used to endorse or promote products derived |
|
15 * from this software without specific prior written permission. |
|
16 * |
|
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
|
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
|
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
|
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
|
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
27 */ |
|
28 #include <jsobjects.h> |
|
29 #include <qwebpage.h> |
|
30 #include <qwebframe.h> |
|
31 #include <qevent.h> |
|
32 #include <qapplication.h> |
|
33 |
|
34 #include "DumpRenderTree.h" |
|
35 |
|
36 class HackWebFrame : public QWebFrame |
|
37 { |
|
38 public: |
|
39 void mousePressEvent(QMouseEvent *e) { |
|
40 QWebFrame::mousePressEvent(e); |
|
41 } |
|
42 void mouseReleaseEvent(QMouseEvent *e) { |
|
43 QWebFrame::mouseReleaseEvent(e); |
|
44 } |
|
45 void mouseMoveEvent(QMouseEvent *e) { |
|
46 QWebFrame::mouseMoveEvent(e); |
|
47 } |
|
48 |
|
49 protected: |
|
50 HackWebFrame(QWebPage *parent, QWebFrameData *frameData) : QWebFrame(parent, frameData) {} |
|
51 HackWebFrame(QWebFrame *parent, QWebFrameData *frameData) : QWebFrame(parent, frameData) {} |
|
52 ~HackWebFrame() {} |
|
53 }; |
|
54 |
|
55 LayoutTestController::LayoutTestController(WebCore::DumpRenderTree *drt) |
|
56 : QObject() |
|
57 , m_drt(drt) |
|
58 { |
|
59 m_timeoutTimer = 0; |
|
60 reset(); |
|
61 } |
|
62 |
|
63 void LayoutTestController::reset() |
|
64 { |
|
65 m_isLoading = true; |
|
66 m_textDump = false; |
|
67 m_dumpChildrenAsText = false; |
|
68 m_canOpenWindows = false; |
|
69 m_waitForDone = false; |
|
70 m_dumpTitleChanges = false; |
|
71 if (m_timeoutTimer) { |
|
72 killTimer(m_timeoutTimer); |
|
73 m_timeoutTimer = 0; |
|
74 } |
|
75 m_topLoadingFrame = 0; |
|
76 } |
|
77 |
|
78 void LayoutTestController::maybeDump(bool ok) |
|
79 { |
|
80 QWebFrame *frame = qobject_cast<QWebFrame*>(sender()); |
|
81 if (frame != m_topLoadingFrame) |
|
82 return; |
|
83 |
|
84 m_topLoadingFrame = 0; |
|
85 |
|
86 if (!shouldWaitUntilDone()) { |
|
87 emit done(); |
|
88 m_isLoading = false; |
|
89 } |
|
90 } |
|
91 |
|
92 void LayoutTestController::waitUntilDone() |
|
93 { |
|
94 //qDebug() << ">>>>waitForDone"; |
|
95 m_waitForDone = true; |
|
96 m_timeoutTimer = startTimer(5000); |
|
97 } |
|
98 |
|
99 void LayoutTestController::notifyDone() |
|
100 { |
|
101 //qDebug() << ">>>>notifyDone"; |
|
102 if (!m_timeoutTimer) |
|
103 return; |
|
104 killTimer(m_timeoutTimer); |
|
105 m_timeoutTimer = 0; |
|
106 emit done(); |
|
107 m_isLoading = false; |
|
108 } |
|
109 |
|
110 int LayoutTestController::windowCount() |
|
111 { |
|
112 return m_drt->windowCount(); |
|
113 } |
|
114 |
|
115 void LayoutTestController::clearBackForwardList() |
|
116 { |
|
117 m_drt->webPage()->history().clear(); |
|
118 } |
|
119 |
|
120 |
|
121 void LayoutTestController::dumpEditingCallbacks() |
|
122 { |
|
123 //qDebug() << ">>>dumpEditingCallbacks"; |
|
124 } |
|
125 |
|
126 void LayoutTestController::queueReload() |
|
127 { |
|
128 //qDebug() << ">>>queueReload"; |
|
129 } |
|
130 |
|
131 void LayoutTestController::provisionalLoad() |
|
132 { |
|
133 QWebFrame *frame = qobject_cast<QWebFrame*>(sender()); |
|
134 if (!m_topLoadingFrame && m_isLoading) |
|
135 m_topLoadingFrame = frame; |
|
136 } |
|
137 |
|
138 void LayoutTestController::timerEvent(QTimerEvent *) |
|
139 { |
|
140 qDebug() << ">>>>>>>>>>>>> timeout"; |
|
141 notifyDone(); |
|
142 } |
|
143 |
|
144 QString LayoutTestController::encodeHostName(const QString &host) |
|
145 { |
|
146 QString encoded = QString::fromLatin1(QUrl::toAce(host + QLatin1String(".no"))); |
|
147 encoded.truncate(encoded.length() - 3); // strip .no |
|
148 return encoded; |
|
149 } |
|
150 |
|
151 QString LayoutTestController::decodeHostName(const QString &host) |
|
152 { |
|
153 QString decoded = QUrl::fromAce(host.toLatin1() + QByteArray(".no")); |
|
154 decoded.truncate(decoded.length() - 3); |
|
155 return decoded; |
|
156 } |
|
157 |
|
158 |
|
159 EventSender::EventSender(QWebPage *parent) |
|
160 : QObject(parent) |
|
161 { |
|
162 m_page = parent; |
|
163 } |
|
164 |
|
165 void EventSender::mouseDown() |
|
166 { |
|
167 QWebFrame *frame = frameUnderMouse(); |
|
168 // qDebug() << "EventSender::mouseDown" << frame; |
|
169 if (!frame) |
|
170 return; |
|
171 QMouseEvent event(QEvent::MouseButtonPress, m_mousePos - frame->pos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); |
|
172 static_cast<HackWebFrame *>(frame)->mousePressEvent(&event); |
|
173 } |
|
174 |
|
175 void EventSender::mouseUp() |
|
176 { |
|
177 QWebFrame *frame = frameUnderMouse(); |
|
178 // qDebug() << "EventSender::mouseUp" << frame; |
|
179 if (!frame) |
|
180 return; |
|
181 QMouseEvent event(QEvent::MouseButtonRelease, m_mousePos - frame->pos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); |
|
182 static_cast<HackWebFrame *>(frame)->mouseReleaseEvent(&event); |
|
183 } |
|
184 |
|
185 void EventSender::mouseMoveTo(int x, int y) |
|
186 { |
|
187 QWebFrame *frame = frameUnderMouse(); |
|
188 // qDebug() << "EventSender::mouseMoveTo" << x << y; |
|
189 m_mousePos = QPoint(x, y); |
|
190 QMouseEvent event(QEvent::MouseMove, m_mousePos - frame->pos(), Qt::NoButton, Qt::NoButton, Qt::NoModifier); |
|
191 static_cast<HackWebFrame *>(frame)->mouseMoveEvent(&event); |
|
192 } |
|
193 |
|
194 void EventSender::leapForward(int ms) |
|
195 { |
|
196 m_timeLeap += ms; |
|
197 qDebug() << "EventSender::leapForward" << ms; |
|
198 } |
|
199 |
|
200 void EventSender::keyDown(const QString &string, const QStringList &modifiers) |
|
201 { |
|
202 qDebug() << "EventSender::keyDown" << string << modifiers; |
|
203 } |
|
204 |
|
205 QWebFrame *EventSender::frameUnderMouse() const |
|
206 { |
|
207 QWebFrame *frame = m_page->mainFrame(); |
|
208 |
|
209 redo: |
|
210 QList<QWebFrame*> children = frame->childFrames(); |
|
211 for (int i = 0; i < children.size(); ++i) { |
|
212 if (children.at(i)->geometry().contains(m_mousePos)) { |
|
213 frame = children.at(i); |
|
214 goto redo; |
|
215 } |
|
216 } |
|
217 if (frame->geometry().contains(m_mousePos)) |
|
218 return frame; |
|
219 return 0; |
|
220 } |