~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Tools/DumpRenderTree/qt/TestRunnerQt.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
 
3
 * Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions
 
7
 * are met:
 
8
 *
 
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.
 
17
 *
 
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.
 
28
 */
 
29
#include "config.h"
 
30
#include "TestRunnerQt.h"
 
31
 
 
32
#include "DumpRenderTreeQt.h"
 
33
#include "DumpRenderTreeSupportQt.h"
 
34
#include "WorkQueue.h"
 
35
#include "WorkQueueItemQt.h"
 
36
#include <QCoreApplication>
 
37
#include <QDir>
 
38
#include <QLocale>
 
39
#include <qwebsettings.h>
 
40
 
 
41
TestRunner::TestRunner(WebCore::DumpRenderTree* drt)
 
42
    : QObject()
 
43
    , m_drt(drt)
 
44
    , m_shouldTimeout(true)
 
45
    , m_timeout(30000)
 
46
{
 
47
    reset();
 
48
    DumpRenderTreeSupportQt::dumpNotification(true);
 
49
}
 
50
 
 
51
void TestRunner::reset()
 
52
{
 
53
    m_hasDumped = false;
 
54
    m_loadFinished = false;
 
55
    m_textDump = false;
 
56
    m_shouldDumpPixels = true;
 
57
    m_dumpBackForwardList = false;
 
58
    m_dumpChildrenAsText = false;
 
59
    m_dumpChildFrameScrollPositions = false;
 
60
    m_canOpenWindows = false;
 
61
    m_waitForDone = false;
 
62
    m_disallowIncreaseForApplicationCacheQuota = false;
 
63
    m_dumpTitleChanges = false;
 
64
    m_dumpDatabaseCallbacks = false;
 
65
    m_dumpApplicationCacheDelegateCallbacks = false;
 
66
    m_dumpStatusCallbacks = false;
 
67
    m_timeoutTimer.stop();
 
68
    m_topLoadingFrame = 0;
 
69
    m_waitForPolicy = false;
 
70
    m_handleErrorPages = false;
 
71
    m_webHistory = 0;
 
72
    m_globalFlag = false;
 
73
    m_userStyleSheetEnabled = false;
 
74
    m_desktopNotificationAllowedOrigins.clear();
 
75
    m_ignoreDesktopNotification = false;
 
76
    m_isGeolocationPermissionSet = false;
 
77
    m_isPrinting = false;
 
78
    m_geolocationPermission = false;
 
79
 
 
80
    DumpRenderTreeSupportQt::dumpEditingCallbacks(false);
 
81
    DumpRenderTreeSupportQt::dumpFrameLoader(false);
 
82
    DumpRenderTreeSupportQt::dumpProgressFinishedCallback(false);
 
83
    DumpRenderTreeSupportQt::dumpUserGestureInFrameLoader(false);
 
84
    DumpRenderTreeSupportQt::dumpResourceLoadCallbacks(false);
 
85
    DumpRenderTreeSupportQt::dumpResourceResponseMIMETypes(false);
 
86
    DumpRenderTreeSupportQt::dumpWillCacheResponseCallbacks(false);
 
87
    DumpRenderTreeSupportQt::setDeferMainResourceDataLoad(true);
 
88
    DumpRenderTreeSupportQt::setWillSendRequestReturnsNullOnRedirect(false);
 
89
    DumpRenderTreeSupportQt::setWillSendRequestReturnsNull(false);
 
90
    DumpRenderTreeSupportQt::setWillSendRequestClearHeaders(QStringList());
 
91
    DumpRenderTreeSupportQt::clearScriptWorlds();
 
92
    DumpRenderTreeSupportQt::setCustomPolicyDelegate(false, false);
 
93
    DumpRenderTreeSupportQt::dumpHistoryCallbacks(false);
 
94
    DumpRenderTreeSupportQt::dumpVisitedLinksCallbacks(false);
 
95
    DumpRenderTreeSupportQt::resetGeolocationMock(m_drt->webPage());
 
96
    setIconDatabaseEnabled(false);
 
97
    clearAllDatabases();
 
98
    // The default state for DRT is to block third-party cookies, mimicing the Mac port
 
99
    setAlwaysAcceptCookies(false);
 
100
    emit hidePage();
 
101
}
 
102
 
 
103
void TestRunner::processWork()
 
104
{
 
105
    // qDebug() << ">>>processWork";
 
106
 
 
107
    // if we didn't start a new load, then we finished all the commands, so we're ready to dump state
 
108
    if (WorkQueue::shared()->processWork() && !shouldWaitUntilDone()) {
 
109
        emit done();
 
110
        m_hasDumped = true;
 
111
    }
 
112
}
 
113
 
 
114
// Called on loadFinished on WebPage
 
115
void TestRunner::maybeDump(bool /*success*/)
 
116
{
 
117
 
 
118
    // This can happen on any of the http/tests/security/window-events-*.html tests, where the test opens
 
119
    // a new window, calls the unload and load event handlers on the window's page, and then immediately
 
120
    // issues a notifyDone. Needs investigation.
 
121
    if (!m_topLoadingFrame)
 
122
        return;
 
123
 
 
124
    // It is possible that we get called by windows created from the main page that have finished
 
125
    // loading, so we don't ASSERT here. At the moment we do not gather results from such windows,
 
126
    // but may need to in future.
 
127
    if (sender() != m_topLoadingFrame->page())
 
128
        return;
 
129
 
 
130
    m_loadFinished = true;
 
131
    // as the function is called on loadFinished, the test might
 
132
    // already have dumped and thus no longer be active, thus
 
133
    // bail out here.
 
134
    if (m_hasDumped)
 
135
        return;
 
136
 
 
137
    WorkQueue::shared()->setFrozen(true); // first complete load freezes the queue for the rest of this test
 
138
    if (WorkQueue::shared()->count())
 
139
        QTimer::singleShot(0, this, SLOT(processWork()));
 
140
    else if (!shouldWaitUntilDone()) {
 
141
        emit done();
 
142
        m_hasDumped = true;
 
143
    }
 
144
}
 
145
 
 
146
void TestRunner::dumpAsText(bool shouldDumpPixels)
 
147
{
 
148
    m_textDump = true;
 
149
    m_shouldDumpPixels = shouldDumpPixels;
 
150
}
 
151
 
 
152
void TestRunner::waitUntilDone()
 
153
{
 
154
    //qDebug() << ">>>>waitForDone";
 
155
    m_waitForDone = true;
 
156
 
 
157
    if (!m_shouldTimeout)
 
158
        return;
 
159
 
 
160
    m_timeoutTimer.start(m_timeout, this);
 
161
}
 
162
 
 
163
void TestRunner::setViewModeMediaFeature(const QString& mode)
 
164
{
 
165
    m_drt->webPage()->setProperty("_q_viewMode", mode);
 
166
}
 
167
 
 
168
int TestRunner::webHistoryItemCount()
 
169
{
 
170
    if (!m_webHistory)
 
171
        return -1;
 
172
 
 
173
    // Subtract one here as our QWebHistory::count() includes the actual page,
 
174
    // which is not considered in the DRT tests.
 
175
    return m_webHistory->count() - 1;
 
176
}
 
177
 
 
178
void TestRunner::keepWebHistory()
 
179
{
 
180
    m_webHistory = m_drt->webPage()->history();
 
181
}
 
182
 
 
183
void TestRunner::notifyDone()
 
184
{
 
185
    qDebug() << ">>>>notifyDone";
 
186
 
 
187
    if (m_shouldTimeout && !m_timeoutTimer.isActive())
 
188
        return;
 
189
 
 
190
    m_timeoutTimer.stop();
 
191
    m_waitForDone = false;
 
192
 
 
193
    // If the page has not finished loading (i.e. loadFinished() has not been emitted) then
 
194
    // content created by the likes of document.write() JS methods will not be available yet.
 
195
    // When the page has finished loading, maybeDump above will dump the results now that we have
 
196
    // just set shouldWaitUntilDone to false.
 
197
    if (!m_loadFinished)
 
198
        return;
 
199
 
 
200
    emit done();
 
201
 
 
202
    // FIXME: investigate why always resetting these result in timeouts
 
203
    m_hasDumped = true;
 
204
    m_waitForPolicy = false;
 
205
}
 
206
 
 
207
int TestRunner::windowCount()
 
208
{
 
209
    return m_drt->windowCount();
 
210
}
 
211
 
 
212
void TestRunner::grantWebNotificationPermission(const QString& origin)
 
213
{
 
214
    QWebFrame* frame = m_drt->webPage()->mainFrame();
 
215
    m_drt->webPage()->setFeaturePermission(frame, QWebPage::Notifications, QWebPage::PermissionGrantedByUser);
 
216
    m_desktopNotificationAllowedOrigins.append(origin);
 
217
}
 
218
 
 
219
void TestRunner::ignoreLegacyWebNotificationPermissionRequests()
 
220
{
 
221
    m_ignoreDesktopNotification = true;
 
222
}
 
223
 
 
224
void TestRunner::denyWebNotificationPermission(const QString& origin)
 
225
{
 
226
    // FIXME: implement.
 
227
}
 
228
 
 
229
void TestRunner::removeAllWebNotificationPermissions()
 
230
{
 
231
    // FIXME: implement.
 
232
}
 
233
 
 
234
void TestRunner::simulateWebNotificationClick(const QWebElement& notification)
 
235
{
 
236
    // FIXME: implement.
 
237
}
 
238
 
 
239
void TestRunner::simulateLegacyWebNotificationClick(const QString& title)
 
240
{
 
241
    DumpRenderTreeSupportQt::simulateDesktopNotificationClick(title);
 
242
}
 
243
 
 
244
void TestRunner::display()
 
245
{
 
246
    DumpRenderTreeSupportQt::setTrackRepaintRects(m_topLoadingFrame, true);
 
247
    emit showPage();
 
248
}
 
249
 
 
250
void TestRunner::displayInvalidatedRegion()
 
251
{
 
252
    display();
 
253
}
 
254
 
 
255
void TestRunner::clearBackForwardList()
 
256
{
 
257
    m_drt->webPage()->history()->clear();
 
258
}
 
259
 
 
260
QString TestRunner::pathToLocalResource(const QString& url)
 
261
{
 
262
    QString localTmpUrl(QLatin1String("file:///tmp/LayoutTests"));
 
263
 
 
264
    // Translate a request for /tmp/LayoutTests to the repository LayoutTests directory.
 
265
    // Do not rely on a symlink to be created via the test runner, which will not work on Windows.
 
266
    if (url.startsWith(localTmpUrl)) {
 
267
        // DumpRenderTree lives in WebKit/WebKitBuild/<build_mode>/bin.
 
268
        // Translate from WebKit/WebKitBuild/Release/bin => WebKit/LayoutTests.
 
269
        QFileInfo layoutTestsRoot(QCoreApplication::applicationDirPath() + QLatin1String("/../../../LayoutTests/"));
 
270
        if (layoutTestsRoot.exists())
 
271
            return QLatin1String("file://") + layoutTestsRoot.absolutePath() + url.mid(localTmpUrl.length());
 
272
    }
 
273
 
 
274
    return url;
 
275
}
 
276
 
 
277
void TestRunner::dumpEditingCallbacks()
 
278
{
 
279
    qDebug() << ">>>dumpEditingCallbacks";
 
280
    DumpRenderTreeSupportQt::dumpEditingCallbacks(true);
 
281
}
 
282
 
 
283
void TestRunner::dumpFrameLoadCallbacks()
 
284
{
 
285
    DumpRenderTreeSupportQt::dumpFrameLoader(true);
 
286
}
 
287
 
 
288
void TestRunner::dumpProgressFinishedCallback()
 
289
{
 
290
    DumpRenderTreeSupportQt::dumpProgressFinishedCallback(true);
 
291
}
 
292
 
 
293
void TestRunner::dumpUserGestureInFrameLoadCallbacks()
 
294
{
 
295
    DumpRenderTreeSupportQt::dumpUserGestureInFrameLoader(true);
 
296
}
 
297
 
 
298
void TestRunner::dumpResourceLoadCallbacks()
 
299
{
 
300
    DumpRenderTreeSupportQt::dumpResourceLoadCallbacks(true);
 
301
}
 
302
 
 
303
void TestRunner::dumpResourceResponseMIMETypes()
 
304
{
 
305
    DumpRenderTreeSupportQt::dumpResourceResponseMIMETypes(true);
 
306
}
 
307
 
 
308
void TestRunner::dumpWillCacheResponse()
 
309
{
 
310
    DumpRenderTreeSupportQt::dumpWillCacheResponseCallbacks(true);
 
311
}
 
312
 
 
313
void TestRunner::dumpHistoryCallbacks()
 
314
{
 
315
    DumpRenderTreeSupportQt::dumpHistoryCallbacks(true);
 
316
}
 
317
 
 
318
void TestRunner::setWillSendRequestReturnsNullOnRedirect(bool enabled)
 
319
{
 
320
    DumpRenderTreeSupportQt::setWillSendRequestReturnsNullOnRedirect(enabled);
 
321
}
 
322
 
 
323
void TestRunner::setWillSendRequestReturnsNull(bool enabled)
 
324
{
 
325
    DumpRenderTreeSupportQt::setWillSendRequestReturnsNull(enabled);
 
326
}
 
327
 
 
328
void TestRunner::setWillSendRequestClearHeader(const QStringList& headers)
 
329
{
 
330
    DumpRenderTreeSupportQt::setWillSendRequestClearHeaders(headers);
 
331
}
 
332
 
 
333
void TestRunner::setDeferMainResourceDataLoad(bool defer)
 
334
{
 
335
    DumpRenderTreeSupportQt::setDeferMainResourceDataLoad(defer);
 
336
}
 
337
 
 
338
void TestRunner::queueBackNavigation(int howFarBackward)
 
339
{
 
340
    //qDebug() << ">>>queueBackNavigation" << howFarBackward;
 
341
    for (int i = 0; i != howFarBackward; ++i)
 
342
        WorkQueue::shared()->queue(new BackItem(1, m_drt->webPage()));
 
343
}
 
344
 
 
345
void TestRunner::queueForwardNavigation(int howFarForward)
 
346
{
 
347
    //qDebug() << ">>>queueForwardNavigation" << howFarForward;
 
348
    for (int i = 0; i != howFarForward; ++i)
 
349
        WorkQueue::shared()->queue(new ForwardItem(1, m_drt->webPage()));
 
350
}
 
351
 
 
352
void TestRunner::queueLoad(const QString& url, const QString& target)
 
353
{
 
354
    //qDebug() << ">>>queueLoad" << url << target;
 
355
    QUrl mainResourceUrl = m_drt->webPage()->mainFrame()->url();
 
356
    QString absoluteUrl = mainResourceUrl.resolved(QUrl(url)).toEncoded();
 
357
    WorkQueue::shared()->queue(new LoadItem(absoluteUrl, target, m_drt->webPage()));
 
358
}
 
359
 
 
360
void TestRunner::queueLoadHTMLString(const QString& content, const QString& baseURL, const QString& failingURL)
 
361
{
 
362
    if (failingURL.isEmpty())
 
363
        WorkQueue::shared()->queue(new LoadHTMLStringItem(content, baseURL, m_drt->webPage()));
 
364
    else
 
365
        WorkQueue::shared()->queue(new LoadAlternateHTMLStringItem(content, baseURL, failingURL, m_drt->webPage()));
 
366
}
 
367
 
 
368
void TestRunner::queueReload()
 
369
{
 
370
    //qDebug() << ">>>queueReload";
 
371
    WorkQueue::shared()->queue(new ReloadItem(m_drt->webPage()));
 
372
}
 
373
 
 
374
void TestRunner::queueLoadingScript(const QString& script)
 
375
{
 
376
    //qDebug() << ">>>queueLoadingScript" << script;
 
377
    WorkQueue::shared()->queue(new LoadingScriptItem(script, m_drt->webPage()));
 
378
}
 
379
 
 
380
void TestRunner::queueNonLoadingScript(const QString& script)
 
381
{
 
382
    //qDebug() << ">>>queueNonLoadingScript" << script;
 
383
    WorkQueue::shared()->queue(new NonLoadingScriptItem(script, m_drt->webPage()));
 
384
}
 
385
 
 
386
void TestRunner::provisionalLoad()
 
387
{
 
388
    QWebFrame* frame = qobject_cast<QWebFrame*>(sender());
 
389
    if (!m_topLoadingFrame && !m_hasDumped)
 
390
        m_topLoadingFrame = frame;
 
391
}
 
392
 
 
393
void TestRunner::timerEvent(QTimerEvent *ev)
 
394
{
 
395
    if (ev->timerId() == m_timeoutTimer.timerId()) {
 
396
        const char* message = "FAIL: Timed out waiting for notifyDone to be called\n";
 
397
        fprintf(stderr, "%s", message);
 
398
        fprintf(stdout, "%s", message);
 
399
        notifyDone();
 
400
    } else
 
401
        QObject::timerEvent(ev);
 
402
}
 
403
 
 
404
QString TestRunner::encodeHostName(const QString& host)
 
405
{
 
406
    QString encoded = QString::fromLatin1(QUrl::toAce(host + QLatin1String(".no")));
 
407
    encoded.truncate(encoded.length() - 3); // strip .no
 
408
    return encoded;
 
409
}
 
410
 
 
411
QString TestRunner::decodeHostName(const QString& host)
 
412
{
 
413
    QString decoded = QUrl::fromAce(host.toLatin1() + QByteArray(".no"));
 
414
    decoded.truncate(decoded.length() - 3);
 
415
    return decoded;
 
416
}
 
417
 
 
418
void TestRunner::closeWebInspector()
 
419
{
 
420
    DumpRenderTreeSupportQt::webInspectorClose(m_drt->webPage());
 
421
    m_drt->webPage()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, false);
 
422
}
 
423
 
 
424
void TestRunner::setDeveloperExtrasEnabled(bool enabled)
 
425
{
 
426
    m_drt->webPage()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, enabled);
 
427
}
 
428
 
 
429
void TestRunner::setAsynchronousSpellCheckingEnabled(bool)
 
430
{
 
431
    // FIXME: Implement this.
 
432
}
 
433
 
 
434
void TestRunner::showWebInspector()
 
435
{
 
436
    m_drt->webPage()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
 
437
    DumpRenderTreeSupportQt::webInspectorShow(m_drt->webPage());
 
438
}
 
439
 
 
440
void TestRunner::evaluateInWebInspector(long callId, const QString& script)
 
441
{
 
442
    DumpRenderTreeSupportQt::webInspectorExecuteScript(m_drt->webPage(), callId, script);
 
443
}
 
444
 
 
445
void TestRunner::setFrameFlatteningEnabled(bool enabled)
 
446
{
 
447
    DumpRenderTreeSupportQt::setFrameFlatteningEnabled(m_drt->webPage(), enabled);
 
448
}
 
449
 
 
450
void TestRunner::goBack()
 
451
{
 
452
    DumpRenderTreeSupportQt::goBack(m_drt->webPage());
 
453
}
 
454
 
 
455
void TestRunner::setDefersLoading(bool flag)
 
456
{
 
457
    DumpRenderTreeSupportQt::setDefersLoading(m_drt->webPage(), flag);
 
458
}
 
459
 
 
460
void TestRunner::setAllowUniversalAccessFromFileURLs(bool enabled)
 
461
{
 
462
    m_drt->webPage()->settings()->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls, enabled);
 
463
}
 
464
 
 
465
void TestRunner::setAllowFileAccessFromFileURLs(bool enabled)
 
466
{
 
467
    m_drt->webPage()->settings()->setAttribute(QWebSettings::LocalContentCanAccessFileUrls, enabled);
 
468
}
 
469
 
 
470
void TestRunner::setAppCacheMaximumSize(unsigned long long quota)
 
471
{
 
472
    m_drt->webPage()->settings()->setOfflineWebApplicationCacheQuota(quota);
 
473
}
 
474
 
 
475
void TestRunner::setAutofilled(const QWebElement& element, bool isAutofilled)
 
476
{
 
477
    return DumpRenderTreeSupportQt::setAutofilled(element, isAutofilled);
 
478
}
 
479
 
 
480
void TestRunner::setValueForUser(const QWebElement& element, const QString& value)
 
481
{
 
482
    DumpRenderTreeSupportQt::setValueForUser(element, value);
 
483
}
 
484
 
 
485
void TestRunner::setFixedContentsSize(int width, int height)
 
486
{
 
487
    m_topLoadingFrame->page()->setPreferredContentsSize(QSize(width, height));
 
488
}
 
489
 
 
490
void TestRunner::setPrivateBrowsingEnabled(bool enable)
 
491
{
 
492
    m_drt->webPage()->settings()->setAttribute(QWebSettings::PrivateBrowsingEnabled, enable);
 
493
}
 
494
 
 
495
void TestRunner::setSpatialNavigationEnabled(bool enable)
 
496
{
 
497
    m_drt->webPage()->settings()->setAttribute(QWebSettings::SpatialNavigationEnabled, enable);
 
498
}
 
499
 
 
500
void TestRunner::setPopupBlockingEnabled(bool enable)
 
501
{
 
502
    m_drt->webPage()->settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, !enable);
 
503
}
 
504
 
 
505
void TestRunner::setPluginsEnabled(bool flag)
 
506
{
 
507
    // FIXME: Implement
 
508
}
 
509
 
 
510
void TestRunner::setPOSIXLocale(const QString& locale)
 
511
{
 
512
    QLocale qlocale(locale);
 
513
    QLocale::setDefault(qlocale);
 
514
 
515
 
 
516
void TestRunner::setWindowIsKey(bool isKey)
 
517
{
 
518
    m_drt->switchFocus(isKey);
 
519
}
 
520
 
 
521
void TestRunner::setMainFrameIsFirstResponder(bool isFirst)
 
522
{
 
523
    //FIXME: only need this for the moment: https://bugs.webkit.org/show_bug.cgi?id=32990
 
524
}
 
525
 
 
526
void TestRunner::setJavaScriptCanAccessClipboard(bool enable)
 
527
{
 
528
    m_drt->webPage()->settings()->setAttribute(QWebSettings::JavascriptCanAccessClipboard, enable);
 
529
}
 
530
 
 
531
void TestRunner::setXSSAuditorEnabled(bool enable)
 
532
{
 
533
    // Set XSSAuditingEnabled globally so that windows created by the test inherit it too.
 
534
    // resetSettings() will call this to reset the page and global setting to false again.
 
535
    // Needed by http/tests/security/xssAuditor/link-opens-new-window.html
 
536
    QWebSettings* globalSettings = QWebSettings::globalSettings();
 
537
    globalSettings->setAttribute(QWebSettings::XSSAuditingEnabled, enable);
 
538
    m_drt->webPage()->settings()->setAttribute(QWebSettings::XSSAuditingEnabled, enable);
 
539
}
 
540
 
 
541
bool TestRunner::pauseAnimationAtTimeOnElementWithId(const QString& animationName,
 
542
                                                               double time,
 
543
                                                               const QString& elementId)
 
544
{
 
545
    QWebFrame* frame = m_drt->webPage()->mainFrame();
 
546
    Q_ASSERT(frame);
 
547
    return DumpRenderTreeSupportQt::pauseAnimation(frame, animationName, time, elementId);
 
548
}
 
549
 
 
550
bool TestRunner::pauseTransitionAtTimeOnElementWithId(const QString& propertyName,
 
551
                                                                double time,
 
552
                                                                const QString& elementId)
 
553
{
 
554
    QWebFrame* frame = m_drt->webPage()->mainFrame();
 
555
    Q_ASSERT(frame);
 
556
    return DumpRenderTreeSupportQt::pauseTransitionOfProperty(frame, propertyName, time, elementId);
 
557
}
 
558
 
 
559
unsigned TestRunner::numberOfActiveAnimations() const
 
560
{
 
561
    QWebFrame* frame = m_drt->webPage()->mainFrame();
 
562
    Q_ASSERT(frame);
 
563
    return DumpRenderTreeSupportQt::numberOfActiveAnimations(frame);
 
564
}
 
565
 
 
566
void TestRunner::disableImageLoading()
 
567
{
 
568
    m_drt->webPage()->settings()->setAttribute(QWebSettings::AutoLoadImages, false);
 
569
}
 
570
 
 
571
void TestRunner::dispatchPendingLoadRequests()
 
572
{
 
573
    // FIXME: Implement for testing fix for 6727495
 
574
}
 
575
 
 
576
void TestRunner::clearAllApplicationCaches()
 
577
{
 
578
    DumpRenderTreeSupportQt::clearAllApplicationCaches();
 
579
}
 
580
 
 
581
void TestRunner::clearApplicationCacheForOrigin(const QString& url)
 
582
{
 
583
    // FIXME: Implement to support deleting all application caches for an origin.
 
584
}
 
585
 
 
586
long long TestRunner::localStorageDiskUsageForOrigin(const QString& originIdentifier)
 
587
{
 
588
    // FIXME: Implement to support getting disk usage in bytes for an origin.
 
589
    return 0;
 
590
}
 
591
 
 
592
void TestRunner::setApplicationCacheOriginQuota(unsigned long long quota)
 
593
{
 
594
    if (!m_topLoadingFrame)
 
595
        return;
 
596
    m_topLoadingFrame->securityOrigin().setApplicationCacheQuota(quota);
 
597
}
 
598
 
 
599
long long TestRunner::applicationCacheDiskUsageForOrigin(const QString& origin)
 
600
{
 
601
    // FIXME: Implement to support getting disk usage by all application caches for an origin.
 
602
    return 0;
 
603
}
 
604
 
 
605
QStringList TestRunner::originsWithApplicationCache()
 
606
{
 
607
    // FIXME: Implement to get origins that have application caches.
 
608
    return QStringList();
 
609
}
 
610
 
 
611
void TestRunner::setCacheModel(int model)
 
612
{
 
613
    // qwebsetting doesn't have matched setting yet :
 
614
    // WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER
 
615
    // WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER
 
616
    // WEBKIT_CACHE_MODEL_WEB_BROWSER
 
617
 
 
618
    // FIXME: Implement.
 
619
}
 
620
 
 
621
void TestRunner::setDatabaseQuota(int size)
 
622
{
 
623
    if (!m_topLoadingFrame)
 
624
        return;
 
625
    m_topLoadingFrame->securityOrigin().setDatabaseQuota(size);
 
626
}
 
627
 
 
628
void TestRunner::clearAllDatabases()
 
629
{
 
630
    QWebDatabase::removeAllDatabases();
 
631
}
 
632
 
 
633
void TestRunner::addOriginAccessWhitelistEntry(const QString& sourceOrigin, const QString& destinationProtocol, const QString& destinationHost, bool allowDestinationSubdomains)
 
634
{
 
635
    DumpRenderTreeSupportQt::whiteListAccessFromOrigin(sourceOrigin, destinationProtocol, destinationHost, allowDestinationSubdomains);
 
636
}
 
637
 
 
638
void TestRunner::removeOriginAccessWhitelistEntry(const QString& sourceOrigin, const QString& destinationProtocol, const QString& destinationHost, bool allowDestinationSubdomains)
 
639
{
 
640
    DumpRenderTreeSupportQt::removeWhiteListAccessFromOrigin(sourceOrigin, destinationProtocol, destinationHost, allowDestinationSubdomains);
 
641
}
 
642
 
 
643
void TestRunner::setCustomPolicyDelegate(bool enabled, bool permissive)
 
644
{
 
645
    DumpRenderTreeSupportQt::setCustomPolicyDelegate(enabled, permissive);
 
646
}
 
647
 
 
648
void TestRunner::waitForPolicyDelegate()
 
649
{
 
650
    setCustomPolicyDelegate(true);
 
651
    m_waitForPolicy = true;
 
652
    waitUntilDone();
 
653
}
 
654
 
 
655
void TestRunner::overridePreference(const QString& name, const QVariant& value)
 
656
{
 
657
    QWebSettings* settings = m_topLoadingFrame->page()->settings();
 
658
 
 
659
    if (name == "WebKitJavaScriptEnabled")
 
660
        settings->setAttribute(QWebSettings::JavascriptEnabled, value.toBool());
 
661
    else if (name == "WebKitTabToLinksPreferenceKey")
 
662
        settings->setAttribute(QWebSettings::LinksIncludedInFocusChain, value.toBool());
 
663
    else if (name == "WebKitOfflineWebApplicationCacheEnabled")
 
664
        settings->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, value.toBool());
 
665
    else if (name == "WebKitDefaultFontSize")
 
666
        settings->setFontSize(QWebSettings::DefaultFontSize, value.toInt());
 
667
    else if (name == "WebKitUsesPageCachePreferenceKey")
 
668
        QWebSettings::setMaximumPagesInCache(value.toInt());
 
669
    else if (name == "WebKitEnableCaretBrowsing")
 
670
        setCaretBrowsingEnabled(value.toBool());
 
671
    else if (name == "WebKitPluginsEnabled")
 
672
        settings->setAttribute(QWebSettings::PluginsEnabled, value.toBool());
 
673
    else if (name == "WebKitWebGLEnabled")
 
674
        settings->setAttribute(QWebSettings::WebGLEnabled, value.toBool());
 
675
    else if (name == "WebKitCSSRegionsEnabled")
 
676
        settings->setAttribute(QWebSettings::CSSRegionsEnabled, value.toBool());
 
677
    else if (name == "WebKitCSSGridLayoutEnabled")
 
678
        settings->setAttribute(QWebSettings::CSSGridLayoutEnabled, value.toBool());
 
679
    else if (name == "WebKitHyperlinkAuditingEnabled")
 
680
        settings->setAttribute(QWebSettings::HyperlinkAuditingEnabled, value.toBool());
 
681
    else if (name == "WebKitAcceleratedCompositingEnabled")
 
682
        settings->setAttribute(QWebSettings::AcceleratedCompositingEnabled, value.toBool());
 
683
    else if (name == "WebKitDisplayImagesKey")
 
684
        settings->setAttribute(QWebSettings::AutoLoadImages, value.toBool());
 
685
    else
 
686
        printf("ERROR: TestRunner::overridePreference() does not support the '%s' preference\n",
 
687
            name.toLatin1().data());
 
688
}
 
689
 
 
690
void TestRunner::setUserStyleSheetLocation(const QString& url)
 
691
{
 
692
    QByteArray urlData = pathToLocalResource(url).toLatin1();
 
693
    m_userStyleSheetLocation = QUrl::fromEncoded(urlData, QUrl::StrictMode);
 
694
 
 
695
    if (m_userStyleSheetEnabled)
 
696
        setUserStyleSheetEnabled(true);
 
697
}
 
698
 
 
699
void TestRunner::setCaretBrowsingEnabled(bool value)
 
700
{
 
701
    DumpRenderTreeSupportQt::setCaretBrowsingEnabled(m_drt->webPage(), value);
 
702
}
 
703
 
 
704
void TestRunner::setAuthorAndUserStylesEnabled(bool value)
 
705
{
 
706
    DumpRenderTreeSupportQt::setAuthorAndUserStylesEnabled(m_drt->webPage(), value);
 
707
}
 
708
 
 
709
void TestRunner::setUserStyleSheetEnabled(bool enabled)
 
710
{
 
711
    m_userStyleSheetEnabled = enabled;
 
712
 
 
713
    if (enabled)
 
714
        m_drt->webPage()->settings()->setUserStyleSheetUrl(m_userStyleSheetLocation);
 
715
    else
 
716
        m_drt->webPage()->settings()->setUserStyleSheetUrl(QUrl());
 
717
}
 
718
 
 
719
void TestRunner::setDomainRelaxationForbiddenForURLScheme(bool forbidden, const QString& scheme)
 
720
{
 
721
    DumpRenderTreeSupportQt::setDomainRelaxationForbiddenForURLScheme(forbidden, scheme);
 
722
}
 
723
 
 
724
int TestRunner::workerThreadCount()
 
725
{
 
726
    return DumpRenderTreeSupportQt::workerThreadCount();
 
727
}
 
728
 
 
729
bool TestRunner::callShouldCloseOnWebView()
 
730
{
 
731
    return DumpRenderTreeSupportQt::shouldClose(m_drt->webPage()->mainFrame());
 
732
}
 
733
 
 
734
void TestRunner::setScrollbarPolicy(const QString& orientation, const QString& policy)
 
735
{
 
736
    Qt::Orientation o;
 
737
    Qt::ScrollBarPolicy p;
 
738
 
 
739
    if (orientation == "vertical")
 
740
        o = Qt::Vertical;
 
741
    else if (orientation == "horizontal")
 
742
        o = Qt::Horizontal;
 
743
    else
 
744
        return;
 
745
 
 
746
    if (policy == "on")
 
747
        p = Qt::ScrollBarAlwaysOn;
 
748
    else if (policy == "auto")
 
749
        p = Qt::ScrollBarAsNeeded;
 
750
    else if (policy == "off")
 
751
        p = Qt::ScrollBarAlwaysOff;
 
752
    else
 
753
        return;
 
754
 
 
755
    m_drt->webPage()->mainFrame()->setScrollBarPolicy(o, p);
 
756
}
 
757
 
 
758
void TestRunner::setSmartInsertDeleteEnabled(bool enable)
 
759
{
 
760
    DumpRenderTreeSupportQt::setSmartInsertDeleteEnabled(m_drt->webPage(), enable);
 
761
}
 
762
 
 
763
void TestRunner::setSelectTrailingWhitespaceEnabled(bool enable)
 
764
{
 
765
    DumpRenderTreeSupportQt::setSelectTrailingWhitespaceEnabled(m_drt->webPage(), enable);
 
766
}
 
767
 
 
768
void TestRunner::execCommand(const QString& name, const QString& value)
 
769
{
 
770
    DumpRenderTreeSupportQt::executeCoreCommandByName(m_drt->webPage(), name, value);
 
771
}
 
772
 
 
773
bool TestRunner::isCommandEnabled(const QString& name) const
 
774
{
 
775
    return DumpRenderTreeSupportQt::isCommandEnabled(m_drt->webPage(), name);
 
776
}
 
777
 
 
778
bool TestRunner::findString(const QString& string, const QStringList& optionArray)
 
779
{
 
780
    return DumpRenderTreeSupportQt::findString(m_drt->webPage(), string, optionArray);
 
781
}
 
782
 
 
783
QString TestRunner::markerTextForListItem(const QWebElement& listItem)
 
784
{
 
785
    return DumpRenderTreeSupportQt::markerTextForListItem(listItem);
 
786
}
 
787
 
 
788
QVariantMap TestRunner::computedStyleIncludingVisitedInfo(const QWebElement& element) const
 
789
{
 
790
    return DumpRenderTreeSupportQt::computedStyleIncludingVisitedInfo(element);
 
791
}
 
792
 
 
793
bool TestRunner::elementDoesAutoCompleteForElementWithId(const QString& elementId)
 
794
{
 
795
    return DumpRenderTreeSupportQt::elementDoesAutoCompleteForElementWithId(m_drt->webPage()->mainFrame(), elementId);
 
796
}
 
797
 
 
798
void TestRunner::authenticateSession(const QString&, const QString&, const QString&)
 
799
{
 
800
    // FIXME: If there is a concept per-session (per-process) credential storage, the credentials should be added to it for later use.
 
801
}
 
802
 
 
803
void TestRunner::setIconDatabaseEnabled(bool enable)
 
804
{
 
805
    if (enable && !m_drt->persistentStoragePath().isEmpty())
 
806
        QWebSettings::setIconDatabasePath(m_drt->persistentStoragePath());
 
807
    else
 
808
        QWebSettings::setIconDatabasePath(QString());
 
809
}
 
810
 
 
811
void TestRunner::setMockDeviceOrientation(bool canProvideAlpha, double alpha, bool canProvideBeta, double beta, bool canProvideGamma, double gamma)
 
812
{
 
813
    QList<WebCore::WebPage*> pages = m_drt->getAllPages();
 
814
    foreach (WebCore::WebPage* page, pages)
 
815
        DumpRenderTreeSupportQt::setMockDeviceOrientation(page, canProvideAlpha, alpha, canProvideBeta, beta, canProvideGamma, gamma);
 
816
}
 
817
 
 
818
void TestRunner::setGeolocationPermission(bool allow)
 
819
{
 
820
    setGeolocationPermissionCommon(allow);
 
821
    QList<WebCore::WebPage*> pages = m_drt->getAllPages();
 
822
    foreach (WebCore::WebPage* page, pages)
 
823
        DumpRenderTreeSupportQt::setMockGeolocationPermission(page, allow);
 
824
}
 
825
 
 
826
int TestRunner::numberOfPendingGeolocationPermissionRequests()
 
827
{
 
828
    int pendingPermissionCount = 0;
 
829
    QList<WebCore::WebPage*> pages = m_drt->getAllPages();
 
830
    foreach (WebCore::WebPage* page, pages)
 
831
        pendingPermissionCount += DumpRenderTreeSupportQt::numberOfPendingGeolocationPermissionRequests(page);
 
832
 
 
833
    return pendingPermissionCount;
 
834
}
 
835
 
 
836
void TestRunner::setGeolocationPermissionCommon(bool allow)
 
837
{
 
838
     m_isGeolocationPermissionSet = true;
 
839
     m_geolocationPermission = allow;
 
840
}
 
841
 
 
842
void TestRunner::setMockGeolocationPositionUnavailableError(const QString& message)
 
843
{
 
844
    QList<WebCore::WebPage*> pages = m_drt->getAllPages();
 
845
    foreach (WebCore::WebPage* page, pages)
 
846
        DumpRenderTreeSupportQt::setMockGeolocationPositionUnavailableError(page, message);
 
847
}
 
848
 
 
849
void TestRunner::setMockGeolocationPosition(double latitude, double longitude, double accuracy)
 
850
{
 
851
    QList<WebCore::WebPage*> pages = m_drt->getAllPages();
 
852
    foreach (WebCore::WebPage* page, pages)
 
853
        DumpRenderTreeSupportQt::setMockGeolocationPosition(page, latitude, longitude, accuracy);
 
854
}
 
855
 
 
856
void TestRunner::addMockSpeechInputResult(const QString& result, double confidence, const QString& language)
 
857
{
 
858
    // FIXME: Implement for speech input layout tests.
 
859
    // See https://bugs.webkit.org/show_bug.cgi?id=39485.
 
860
}
 
861
 
 
862
void TestRunner::setMockSpeechInputDumpRect(bool flag)
 
863
{
 
864
    // FIXME: Implement for speech input layout tests.
 
865
    // See https://bugs.webkit.org/show_bug.cgi?id=39485.
 
866
}
 
867
 
 
868
void TestRunner::startSpeechInput(const QString& inputElement)
 
869
{
 
870
    // FIXME: Implement for speech input layout tests.
 
871
    // See https://bugs.webkit.org/show_bug.cgi?id=39485.
 
872
}
 
873
 
 
874
void TestRunner::evaluateScriptInIsolatedWorldAndReturnValue(int worldID, const QString& script)
 
875
{
 
876
    // FIXME: Implement.
 
877
}
 
878
 
 
879
void TestRunner::evaluateScriptInIsolatedWorld(int worldID, const QString& script)
 
880
{
 
881
    DumpRenderTreeSupportQt::evaluateScriptInIsolatedWorld(m_drt->webPage()->mainFrame(), worldID, script);
 
882
}
 
883
 
 
884
void TestRunner::addUserStyleSheet(const QString& sourceCode)
 
885
{
 
886
    DumpRenderTreeSupportQt::addUserStyleSheet(m_drt->webPage(), sourceCode);
 
887
}
 
888
 
 
889
void TestRunner::removeAllVisitedLinks()
 
890
{
 
891
    QWebHistory* history = m_drt->webPage()->history();
 
892
    history->clear();
 
893
    DumpRenderTreeSupportQt::dumpVisitedLinksCallbacks(true);
 
894
}
 
895
 
 
896
void TestRunner::addURLToRedirect(const QString& origin, const QString& destination)
 
897
{
 
898
    DumpRenderTreeSupportQt::addURLToRedirect(origin, destination);
 
899
}
 
900
 
 
901
void TestRunner::setMinimumTimerInterval(double minimumTimerInterval)
 
902
{
 
903
    DumpRenderTreeSupportQt::setMinimumTimerInterval(m_drt->webPage(), minimumTimerInterval);
 
904
}
 
905
 
 
906
void TestRunner::originsWithLocalStorage()
 
907
{
 
908
    // FIXME: Implement.
 
909
}
 
910
 
 
911
void TestRunner::deleteAllLocalStorage()
 
912
{
 
913
    // FIXME: Implement.
 
914
}
 
915
 
 
916
void TestRunner::deleteLocalStorageForOrigin(const QString& originIdentifier)
 
917
{
 
918
    // FIXME: Implement.
 
919
}
 
920
 
 
921
void TestRunner::observeStorageTrackerNotifications(unsigned number)
 
922
{
 
923
    // FIXME: Implement.
 
924
}
 
925
 
 
926
void TestRunner::syncLocalStorage()
 
927
{
 
928
    // FIXME: Implement.
 
929
}
 
930
 
 
931
void TestRunner::resetPageVisibility()
 
932
{
 
933
    // FIXME: Implement this.
 
934
}
 
935
 
 
936
void TestRunner::setPageVisibility(const char*)
 
937
{
 
938
    // FIXME: Implement this.
 
939
}
 
940
 
 
941
void TestRunner::setAutomaticLinkDetectionEnabled(bool)
 
942
{
 
943
    // FIXME: Implement this.
 
944
}
 
945
 
 
946
void TestRunner::setTextDirection(const QString& directionName)
 
947
{
 
948
    if (directionName == "auto")
 
949
        m_drt->webPage()->triggerAction(QWebPage::SetTextDirectionDefault);
 
950
    else if (directionName == "rtl")
 
951
        m_drt->webPage()->triggerAction(QWebPage::SetTextDirectionRightToLeft);
 
952
    else if (directionName == "ltr")
 
953
        m_drt->webPage()->triggerAction(QWebPage::SetTextDirectionLeftToRight);
 
954
}
 
955
 
 
956
void TestRunner::setAlwaysAcceptCookies(bool accept)
 
957
{
 
958
    QWebSettings* globalSettings = QWebSettings::globalSettings();
 
959
    if (accept)
 
960
        globalSettings->setThirdPartyCookiePolicy(QWebSettings::AlwaysAllowThirdPartyCookies);
 
961
    else {
 
962
        // This matches the Safari third-party cookie blocking policy tested in third-party-cookie-relaxing.html
 
963
        globalSettings->setThirdPartyCookiePolicy(QWebSettings::AllowThirdPartyWithExistingCookies);
 
964
    }
 
965
}
 
966
 
 
967
void TestRunner::setAlwaysBlockCookies(bool block)
 
968
{
 
969
    QWebSettings* globalSettings = QWebSettings::globalSettings();
 
970
    if (block)
 
971
        globalSettings->setThirdPartyCookiePolicy(QWebSettings::AlwaysBlockThirdPartyCookies);
 
972
    else
 
973
        globalSettings->setThirdPartyCookiePolicy(QWebSettings::AlwaysAllowThirdPartyCookies);
 
974
}
 
975
 
 
976
const unsigned TestRunner::maxViewWidth = 800;
 
977
const unsigned TestRunner::maxViewHeight = 600;