2 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
3 * Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/
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.
30 #include "LayoutTestControllerQt.h"
31 #include "DumpRenderTreeSupportQt.h"
33 #include "DumpRenderTreeQt.h"
34 #include "WorkQueue.h"
35 #include "WorkQueueItemQt.h"
36 #include <QCoreApplication>
39 #include <qwebsettings.h>
41 LayoutTestController::LayoutTestController(WebCore::DumpRenderTree* drt)
45 qRegisterMetaType<QWebElement>("QWebElement");
47 DumpRenderTreeSupportQt::dumpNotification(true);
50 void LayoutTestController::reset()
53 m_loadFinished = false;
55 m_dumpBackForwardList = false;
56 m_dumpChildrenAsText = false;
57 m_dumpChildFrameScrollPositions = false;
58 m_canOpenWindows = false;
59 m_waitForDone = false;
60 m_disallowIncreaseForApplicationCacheQuota = false;
61 m_dumpTitleChanges = false;
62 m_dumpDatabaseCallbacks = false;
63 m_dumpApplicationCacheDelegateCallbacks = false;
64 m_dumpStatusCallbacks = false;
65 m_timeoutTimer.stop();
66 m_topLoadingFrame = 0;
67 m_waitForPolicy = false;
68 m_handleErrorPages = false;
71 m_userStyleSheetEnabled = false;
72 m_desktopNotificationAllowedOrigins.clear();
73 m_ignoreDesktopNotification = false;
74 m_isGeolocationPermissionSet = false;
76 m_geolocationPermission = false;
78 DumpRenderTreeSupportQt::dumpEditingCallbacks(false);
79 DumpRenderTreeSupportQt::dumpFrameLoader(false);
80 DumpRenderTreeSupportQt::dumpProgressFinishedCallback(false);
81 DumpRenderTreeSupportQt::dumpUserGestureInFrameLoader(false);
82 DumpRenderTreeSupportQt::dumpResourceLoadCallbacks(false);
83 DumpRenderTreeSupportQt::dumpResourceResponseMIMETypes(false);
84 DumpRenderTreeSupportQt::setDeferMainResourceDataLoad(true);
85 DumpRenderTreeSupportQt::setWillSendRequestReturnsNullOnRedirect(false);
86 DumpRenderTreeSupportQt::setWillSendRequestReturnsNull(false);
87 DumpRenderTreeSupportQt::setWillSendRequestClearHeaders(QStringList());
88 DumpRenderTreeSupportQt::clearScriptWorlds();
89 DumpRenderTreeSupportQt::setCustomPolicyDelegate(false, false);
90 DumpRenderTreeSupportQt::dumpHistoryCallbacks(false);
91 DumpRenderTreeSupportQt::dumpVisitedLinksCallbacks(false);
92 DumpRenderTreeSupportQt::resetGeolocationMock(m_drt->webPage());
93 setIconDatabaseEnabled(false);
95 #if QT_VERSION >= 0x040800
96 // The default state for DRT is to block third-party cookies, mimicing the Mac port
97 setAlwaysAcceptCookies(false);
102 void LayoutTestController::processWork()
104 // qDebug() << ">>>processWork";
106 // if we didn't start a new load, then we finished all the commands, so we're ready to dump state
107 if (WorkQueue::shared()->processWork() && !shouldWaitUntilDone()) {
113 // Called on loadFinished on WebPage
114 void LayoutTestController::maybeDump(bool /*success*/)
117 // This can happen on any of the http/tests/security/window-events-*.html tests, where the test opens
118 // a new window, calls the unload and load event handlers on the window's page, and then immediately
119 // issues a notifyDone. Needs investigation.
120 if (!m_topLoadingFrame)
123 // It is possible that we get called by windows created from the main page that have finished
124 // loading, so we don't ASSERT here. At the moment we do not gather results from such windows,
125 // but may need to in future.
126 if (sender() != m_topLoadingFrame->page())
129 m_loadFinished = true;
130 // as the function is called on loadFinished, the test might
131 // already have dumped and thus no longer be active, thus
136 WorkQueue::shared()->setFrozen(true); // first complete load freezes the queue for the rest of this test
137 if (WorkQueue::shared()->count())
138 QTimer::singleShot(0, this, SLOT(processWork()));
139 else if (!shouldWaitUntilDone()) {
145 void LayoutTestController::waitUntilDone()
147 //qDebug() << ">>>>waitForDone";
148 m_waitForDone = true;
149 m_timeoutTimer.start(30000, this);
152 QString LayoutTestController::counterValueForElementById(const QString& id)
154 return DumpRenderTreeSupportQt::counterValueForElementById(m_drt->webPage()->mainFrame(), id);
157 void LayoutTestController::setViewModeMediaFeature(const QString& mode)
159 m_drt->webPage()->setProperty("_q_viewMode", mode);
162 int LayoutTestController::webHistoryItemCount()
167 // Subtract one here as our QWebHistory::count() includes the actual page,
168 // which is not considered in the DRT tests.
169 return m_webHistory->count() - 1;
172 void LayoutTestController::keepWebHistory()
174 m_webHistory = m_drt->webPage()->history();
177 void LayoutTestController::notifyDone()
179 qDebug() << ">>>>notifyDone";
181 if (!m_timeoutTimer.isActive())
184 m_timeoutTimer.stop();
185 m_waitForDone = false;
187 // If the page has not finished loading (i.e. loadFinished() has not been emitted) then
188 // content created by the likes of document.write() JS methods will not be available yet.
189 // When the page has finished loading, maybeDump above will dump the results now that we have
190 // just set shouldWaitUntilDone to false.
196 // FIXME: investigate why always resetting these result in timeouts
198 m_waitForPolicy = false;
201 int LayoutTestController::windowCount()
203 return m_drt->windowCount();
206 void LayoutTestController::grantDesktopNotificationPermission(const QString& origin)
208 QWebFrame* frame = m_drt->webPage()->mainFrame();
209 m_drt->webPage()->setFeaturePermission(frame, QWebPage::Notifications, QWebPage::PermissionGrantedByUser);
210 m_desktopNotificationAllowedOrigins.append(origin);
213 void LayoutTestController::ignoreDesktopNotificationPermissionRequests()
215 m_ignoreDesktopNotification = true;
218 bool LayoutTestController::checkDesktopNotificationPermission(const QString& origin)
220 return !m_ignoreDesktopNotification && m_desktopNotificationAllowedOrigins.contains(origin);
223 void LayoutTestController::simulateDesktopNotificationClick(const QString& title)
225 DumpRenderTreeSupportQt::simulateDesktopNotificationClick(title);
228 void LayoutTestController::display()
233 void LayoutTestController::displayInvalidatedRegion()
238 void LayoutTestController::clearBackForwardList()
240 m_drt->webPage()->history()->clear();
243 QString LayoutTestController::pathToLocalResource(const QString& url)
245 QString localTmpUrl(QLatin1String("file:///tmp/LayoutTests"));
247 // Translate a request for /tmp/LayoutTests to the repository LayoutTests directory.
248 // Do not rely on a symlink to be created via the test runner, which will not work on Windows.
249 if (url.startsWith(localTmpUrl)) {
250 // DumpRenderTree lives in WebKit/WebKitBuild/<build_mode>/bin.
251 // Translate from WebKit/WebKitBuild/Release/bin => WebKit/LayoutTests.
252 QFileInfo layoutTestsRoot(QCoreApplication::applicationDirPath() + QLatin1String("/../../../LayoutTests/"));
253 if (layoutTestsRoot.exists())
254 return QLatin1String("file://") + layoutTestsRoot.absolutePath() + url.mid(localTmpUrl.length());
260 void LayoutTestController::dumpConfigurationForViewport(int deviceDPI, int deviceWidth, int deviceHeight, int availableWidth, int availableHeight)
262 QString res = DumpRenderTreeSupportQt::viewportAsText(m_drt->webPage(), deviceDPI, QSize(deviceWidth, deviceHeight), QSize(availableWidth, availableHeight));
263 fputs(qPrintable(res), stdout);
266 void LayoutTestController::dumpEditingCallbacks()
268 qDebug() << ">>>dumpEditingCallbacks";
269 DumpRenderTreeSupportQt::dumpEditingCallbacks(true);
272 void LayoutTestController::dumpFrameLoadCallbacks()
274 DumpRenderTreeSupportQt::dumpFrameLoader(true);
277 void LayoutTestController::dumpProgressFinishedCallback()
279 DumpRenderTreeSupportQt::dumpProgressFinishedCallback(true);
282 void LayoutTestController::dumpUserGestureInFrameLoadCallbacks()
284 DumpRenderTreeSupportQt::dumpUserGestureInFrameLoader(true);
287 void LayoutTestController::dumpResourceLoadCallbacks()
289 DumpRenderTreeSupportQt::dumpResourceLoadCallbacks(true);
292 void LayoutTestController::dumpResourceResponseMIMETypes()
294 DumpRenderTreeSupportQt::dumpResourceResponseMIMETypes(true);
297 void LayoutTestController::dumpHistoryCallbacks()
299 DumpRenderTreeSupportQt::dumpHistoryCallbacks(true);
302 void LayoutTestController::setWillSendRequestReturnsNullOnRedirect(bool enabled)
304 DumpRenderTreeSupportQt::setWillSendRequestReturnsNullOnRedirect(enabled);
307 void LayoutTestController::setWillSendRequestReturnsNull(bool enabled)
309 DumpRenderTreeSupportQt::setWillSendRequestReturnsNull(enabled);
312 void LayoutTestController::setWillSendRequestClearHeader(const QStringList& headers)
314 DumpRenderTreeSupportQt::setWillSendRequestClearHeaders(headers);
317 void LayoutTestController::setDeferMainResourceDataLoad(bool defer)
319 DumpRenderTreeSupportQt::setDeferMainResourceDataLoad(defer);
322 void LayoutTestController::queueBackNavigation(int howFarBackward)
324 //qDebug() << ">>>queueBackNavigation" << howFarBackward;
325 for (int i = 0; i != howFarBackward; ++i)
326 WorkQueue::shared()->queue(new BackItem(1, m_drt->webPage()));
329 void LayoutTestController::queueForwardNavigation(int howFarForward)
331 //qDebug() << ">>>queueForwardNavigation" << howFarForward;
332 for (int i = 0; i != howFarForward; ++i)
333 WorkQueue::shared()->queue(new ForwardItem(1, m_drt->webPage()));
336 void LayoutTestController::queueLoad(const QString& url, const QString& target)
338 //qDebug() << ">>>queueLoad" << url << target;
339 QUrl mainResourceUrl = m_drt->webPage()->mainFrame()->url();
340 QString absoluteUrl = mainResourceUrl.resolved(QUrl(url)).toEncoded();
341 WorkQueue::shared()->queue(new LoadItem(absoluteUrl, target, m_drt->webPage()));
344 void LayoutTestController::queueLoadHTMLString(const QString& content, const QString& baseURL, const QString& failingURL)
346 if (failingURL.isEmpty())
347 WorkQueue::shared()->queue(new LoadHTMLStringItem(content, baseURL, m_drt->webPage()));
349 WorkQueue::shared()->queue(new LoadAlternateHTMLStringItem(content, baseURL, failingURL, m_drt->webPage()));
352 void LayoutTestController::queueReload()
354 //qDebug() << ">>>queueReload";
355 WorkQueue::shared()->queue(new ReloadItem(m_drt->webPage()));
358 void LayoutTestController::queueLoadingScript(const QString& script)
360 //qDebug() << ">>>queueLoadingScript" << script;
361 WorkQueue::shared()->queue(new LoadingScriptItem(script, m_drt->webPage()));
364 void LayoutTestController::queueNonLoadingScript(const QString& script)
366 //qDebug() << ">>>queueNonLoadingScript" << script;
367 WorkQueue::shared()->queue(new NonLoadingScriptItem(script, m_drt->webPage()));
370 void LayoutTestController::provisionalLoad()
372 QWebFrame* frame = qobject_cast<QWebFrame*>(sender());
373 if (!m_topLoadingFrame && !m_hasDumped)
374 m_topLoadingFrame = frame;
377 void LayoutTestController::timerEvent(QTimerEvent *ev)
379 if (ev->timerId() == m_timeoutTimer.timerId()) {
380 const char* message = "FAIL: Timed out waiting for notifyDone to be called\n";
381 fprintf(stderr, "%s", message);
382 fprintf(stdout, "%s", message);
385 QObject::timerEvent(ev);
388 QString LayoutTestController::encodeHostName(const QString& host)
390 QString encoded = QString::fromLatin1(QUrl::toAce(host + QLatin1String(".no")));
391 encoded.truncate(encoded.length() - 3); // strip .no
395 QString LayoutTestController::decodeHostName(const QString& host)
397 QString decoded = QUrl::fromAce(host.toLatin1() + QByteArray(".no"));
398 decoded.truncate(decoded.length() - 3);
402 void LayoutTestController::setMediaType(const QString& type)
404 DumpRenderTreeSupportQt::setMediaType(m_drt->webPage()->mainFrame(), type);
407 void LayoutTestController::closeWebInspector()
409 DumpRenderTreeSupportQt::webInspectorClose(m_drt->webPage());
410 m_drt->webPage()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, false);
413 void LayoutTestController::setDeveloperExtrasEnabled(bool enabled)
415 m_drt->webPage()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, enabled);
418 void LayoutTestController::setAsynchronousSpellCheckingEnabled(bool)
420 // FIXME: Implement this.
423 void LayoutTestController::showWebInspector()
425 m_drt->webPage()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
426 DumpRenderTreeSupportQt::webInspectorShow(m_drt->webPage());
429 void LayoutTestController::evaluateInWebInspector(long callId, const QString& script)
431 DumpRenderTreeSupportQt::webInspectorExecuteScript(m_drt->webPage(), callId, script);
434 void LayoutTestController::setFrameFlatteningEnabled(bool enabled)
436 DumpRenderTreeSupportQt::setFrameFlatteningEnabled(m_drt->webPage(), enabled);
439 void LayoutTestController::goBack()
441 DumpRenderTreeSupportQt::goBack(m_drt->webPage());
444 void LayoutTestController::setDefersLoading(bool flag)
446 DumpRenderTreeSupportQt::setDefersLoading(m_drt->webPage(), flag);
449 void LayoutTestController::setAllowUniversalAccessFromFileURLs(bool enabled)
451 m_drt->webPage()->settings()->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls, enabled);
454 void LayoutTestController::setAllowFileAccessFromFileURLs(bool enabled)
456 m_drt->webPage()->settings()->setAttribute(QWebSettings::LocalContentCanAccessFileUrls, enabled);
459 void LayoutTestController::setAppCacheMaximumSize(unsigned long long quota)
461 m_drt->webPage()->settings()->setOfflineWebApplicationCacheQuota(quota);
464 void LayoutTestController::setAutofilled(const QWebElement& element, bool isAutofilled)
466 return DumpRenderTreeSupportQt::setAutofilled(element, isAutofilled);
469 void LayoutTestController::setJavaScriptProfilingEnabled(bool enable)
471 setDeveloperExtrasEnabled(enable);
472 DumpRenderTreeSupportQt::setJavaScriptProfilingEnabled(m_topLoadingFrame, enable);
475 void LayoutTestController::setValueForUser(const QWebElement& element, const QString& value)
477 DumpRenderTreeSupportQt::setValueForUser(element, value);
480 void LayoutTestController::setFixedContentsSize(int width, int height)
482 m_topLoadingFrame->page()->setPreferredContentsSize(QSize(width, height));
485 void LayoutTestController::setPrivateBrowsingEnabled(bool enable)
487 m_drt->webPage()->settings()->setAttribute(QWebSettings::PrivateBrowsingEnabled, enable);
490 void LayoutTestController::setSpatialNavigationEnabled(bool enable)
492 m_drt->webPage()->settings()->setAttribute(QWebSettings::SpatialNavigationEnabled, enable);
495 void LayoutTestController::setPopupBlockingEnabled(bool enable)
497 m_drt->webPage()->settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, !enable);
500 void LayoutTestController::setPluginsEnabled(bool flag)
505 void LayoutTestController::setPOSIXLocale(const QString& locale)
507 QLocale qlocale(locale);
508 QLocale::setDefault(qlocale);
511 void LayoutTestController::setWindowIsKey(bool isKey)
513 m_drt->switchFocus(isKey);
516 void LayoutTestController::setMainFrameIsFirstResponder(bool isFirst)
518 //FIXME: only need this for the moment: https://bugs.webkit.org/show_bug.cgi?id=32990
521 void LayoutTestController::setJavaScriptCanAccessClipboard(bool enable)
523 m_drt->webPage()->settings()->setAttribute(QWebSettings::JavascriptCanAccessClipboard, enable);
526 void LayoutTestController::setXSSAuditorEnabled(bool enable)
528 // Set XSSAuditingEnabled globally so that windows created by the test inherit it too.
529 // resetSettings() will call this to reset the page and global setting to false again.
530 // Needed by http/tests/security/xssAuditor/link-opens-new-window.html
531 QWebSettings* globalSettings = QWebSettings::globalSettings();
532 globalSettings->setAttribute(QWebSettings::XSSAuditingEnabled, enable);
533 m_drt->webPage()->settings()->setAttribute(QWebSettings::XSSAuditingEnabled, enable);
536 bool LayoutTestController::pauseAnimationAtTimeOnElementWithId(const QString& animationName,
538 const QString& elementId)
540 QWebFrame* frame = m_drt->webPage()->mainFrame();
542 return DumpRenderTreeSupportQt::pauseAnimation(frame, animationName, time, elementId);
545 bool LayoutTestController::pauseTransitionAtTimeOnElementWithId(const QString& propertyName,
547 const QString& elementId)
549 QWebFrame* frame = m_drt->webPage()->mainFrame();
551 return DumpRenderTreeSupportQt::pauseTransitionOfProperty(frame, propertyName, time, elementId);
554 bool LayoutTestController::sampleSVGAnimationForElementAtTime(const QString& animationId,
556 const QString& elementId)
558 QWebFrame* frame = m_drt->webPage()->mainFrame();
560 return DumpRenderTreeSupportQt::pauseSVGAnimation(frame, animationId, time, elementId);
563 unsigned LayoutTestController::numberOfActiveAnimations() const
565 QWebFrame* frame = m_drt->webPage()->mainFrame();
567 return DumpRenderTreeSupportQt::numberOfActiveAnimations(frame);
570 void LayoutTestController::suspendAnimations() const
572 QWebFrame* frame = m_drt->webPage()->mainFrame();
574 DumpRenderTreeSupportQt::suspendAnimations(frame);
577 void LayoutTestController::resumeAnimations() const
579 QWebFrame* frame = m_drt->webPage()->mainFrame();
581 DumpRenderTreeSupportQt::resumeAnimations(frame);
584 void LayoutTestController::disableImageLoading()
586 m_drt->webPage()->settings()->setAttribute(QWebSettings::AutoLoadImages, false);
589 void LayoutTestController::dispatchPendingLoadRequests()
591 // FIXME: Implement for testing fix for 6727495
594 void LayoutTestController::clearAllApplicationCaches()
596 DumpRenderTreeSupportQt::clearAllApplicationCaches();
599 void LayoutTestController::clearApplicationCacheForOrigin(const QString& url)
601 // FIXME: Implement to support deleting all application caches for an origin.
604 long long LayoutTestController::localStorageDiskUsageForOrigin(const QString& originIdentifier)
606 // FIXME: Implement to support getting disk usage in bytes for an origin.
610 void LayoutTestController::setApplicationCacheOriginQuota(unsigned long long quota)
612 if (!m_topLoadingFrame)
614 m_topLoadingFrame->securityOrigin().setApplicationCacheQuota(quota);
617 long long LayoutTestController::applicationCacheDiskUsageForOrigin(const QString& origin)
619 // FIXME: Implement to support getting disk usage by all application caches for an origin.
623 QStringList LayoutTestController::originsWithApplicationCache()
625 // FIXME: Implement to get origins that have application caches.
626 return QStringList();
629 void LayoutTestController::setCacheModel(int model)
631 // qwebsetting doesn't have matched setting yet :
632 // WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER
633 // WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER
634 // WEBKIT_CACHE_MODEL_WEB_BROWSER
639 void LayoutTestController::setDatabaseQuota(int size)
641 if (!m_topLoadingFrame)
643 m_topLoadingFrame->securityOrigin().setDatabaseQuota(size);
646 void LayoutTestController::clearAllDatabases()
648 QWebDatabase::removeAllDatabases();
651 void LayoutTestController::addOriginAccessWhitelistEntry(const QString& sourceOrigin, const QString& destinationProtocol, const QString& destinationHost, bool allowDestinationSubdomains)
653 DumpRenderTreeSupportQt::whiteListAccessFromOrigin(sourceOrigin, destinationProtocol, destinationHost, allowDestinationSubdomains);
656 void LayoutTestController::removeOriginAccessWhitelistEntry(const QString& sourceOrigin, const QString& destinationProtocol, const QString& destinationHost, bool allowDestinationSubdomains)
658 DumpRenderTreeSupportQt::removeWhiteListAccessFromOrigin(sourceOrigin, destinationProtocol, destinationHost, allowDestinationSubdomains);
661 void LayoutTestController::setCustomPolicyDelegate(bool enabled, bool permissive)
663 DumpRenderTreeSupportQt::setCustomPolicyDelegate(enabled, permissive);
666 void LayoutTestController::waitForPolicyDelegate()
668 setCustomPolicyDelegate(true);
669 m_waitForPolicy = true;
673 void LayoutTestController::overridePreference(const QString& name, const QVariant& value)
675 QWebSettings* settings = m_topLoadingFrame->page()->settings();
677 if (name == "WebKitJavaScriptEnabled")
678 settings->setAttribute(QWebSettings::JavascriptEnabled, value.toBool());
679 else if (name == "WebKitTabToLinksPreferenceKey")
680 settings->setAttribute(QWebSettings::LinksIncludedInFocusChain, value.toBool());
681 else if (name == "WebKitOfflineWebApplicationCacheEnabled")
682 settings->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, value.toBool());
683 else if (name == "WebKitDefaultFontSize")
684 settings->setFontSize(QWebSettings::DefaultFontSize, value.toInt());
685 else if (name == "WebKitUsesPageCachePreferenceKey")
686 QWebSettings::setMaximumPagesInCache(value.toInt());
687 else if (name == "WebKitEnableCaretBrowsing")
688 setCaretBrowsingEnabled(value.toBool());
689 else if (name == "WebKitPluginsEnabled")
690 settings->setAttribute(QWebSettings::PluginsEnabled, value.toBool());
691 else if (name == "WebKitWebGLEnabled")
692 settings->setAttribute(QWebSettings::WebGLEnabled, value.toBool());
693 else if (name == "WebKitHyperlinkAuditingEnabled")
694 settings->setAttribute(QWebSettings::HyperlinkAuditingEnabled, value.toBool());
696 printf("ERROR: LayoutTestController::overridePreference() does not support the '%s' preference\n",
697 name.toLatin1().data());
700 void LayoutTestController::setUserStyleSheetLocation(const QString& url)
702 QByteArray urlData = pathToLocalResource(url).toLatin1();
703 m_userStyleSheetLocation = QUrl::fromEncoded(urlData, QUrl::StrictMode);
705 if (m_userStyleSheetEnabled)
706 setUserStyleSheetEnabled(true);
709 void LayoutTestController::setCaretBrowsingEnabled(bool value)
711 DumpRenderTreeSupportQt::setCaretBrowsingEnabled(m_drt->webPage(), value);
714 void LayoutTestController::setAuthorAndUserStylesEnabled(bool value)
716 DumpRenderTreeSupportQt::setAuthorAndUserStylesEnabled(m_drt->webPage(), value);
719 void LayoutTestController::setUserStyleSheetEnabled(bool enabled)
721 m_userStyleSheetEnabled = enabled;
724 m_drt->webPage()->settings()->setUserStyleSheetUrl(m_userStyleSheetLocation);
726 m_drt->webPage()->settings()->setUserStyleSheetUrl(QUrl());
729 void LayoutTestController::setDomainRelaxationForbiddenForURLScheme(bool forbidden, const QString& scheme)
731 DumpRenderTreeSupportQt::setDomainRelaxationForbiddenForURLScheme(forbidden, scheme);
734 int LayoutTestController::workerThreadCount()
736 return DumpRenderTreeSupportQt::workerThreadCount();
739 int LayoutTestController::pageNumberForElementById(const QString& id, float width, float height)
741 // If no size specified, webpage viewport size is used
742 if (!width && !height) {
743 width = m_drt->webPage()->viewportSize().width();
744 height = m_drt->webPage()->viewportSize().height();
747 return DumpRenderTreeSupportQt::pageNumberForElementById(m_drt->webPage()->mainFrame(), id, width, height);
750 int LayoutTestController::numberOfPages(float width, float height)
752 return DumpRenderTreeSupportQt::numberOfPages(m_drt->webPage()->mainFrame(), width, height);
755 bool LayoutTestController::callShouldCloseOnWebView()
757 return DumpRenderTreeSupportQt::shouldClose(m_drt->webPage()->mainFrame());
760 void LayoutTestController::setScrollbarPolicy(const QString& orientation, const QString& policy)
763 Qt::ScrollBarPolicy p;
765 if (orientation == "vertical")
767 else if (orientation == "horizontal")
773 p = Qt::ScrollBarAlwaysOn;
774 else if (policy == "auto")
775 p = Qt::ScrollBarAsNeeded;
776 else if (policy == "off")
777 p = Qt::ScrollBarAlwaysOff;
781 m_drt->webPage()->mainFrame()->setScrollBarPolicy(o, p);
784 void LayoutTestController::setSmartInsertDeleteEnabled(bool enable)
786 DumpRenderTreeSupportQt::setSmartInsertDeleteEnabled(m_drt->webPage(), enable);
789 void LayoutTestController::setSelectTrailingWhitespaceEnabled(bool enable)
791 DumpRenderTreeSupportQt::setSelectTrailingWhitespaceEnabled(m_drt->webPage(), enable);
794 void LayoutTestController::execCommand(const QString& name, const QString& value)
796 DumpRenderTreeSupportQt::executeCoreCommandByName(m_drt->webPage(), name, value);
799 bool LayoutTestController::isCommandEnabled(const QString& name) const
801 return DumpRenderTreeSupportQt::isCommandEnabled(m_drt->webPage(), name);
804 bool LayoutTestController::findString(const QString& string, const QStringList& optionArray)
806 return DumpRenderTreeSupportQt::findString(m_drt->webPage(), string, optionArray);
809 QString LayoutTestController::markerTextForListItem(const QWebElement& listItem)
811 return DumpRenderTreeSupportQt::markerTextForListItem(listItem);
814 QVariantMap LayoutTestController::computedStyleIncludingVisitedInfo(const QWebElement& element) const
816 return DumpRenderTreeSupportQt::computedStyleIncludingVisitedInfo(element);
819 bool LayoutTestController::elementDoesAutoCompleteForElementWithId(const QString& elementId)
821 return DumpRenderTreeSupportQt::elementDoesAutoCompleteForElementWithId(m_drt->webPage()->mainFrame(), elementId);
824 void LayoutTestController::authenticateSession(const QString&, const QString&, const QString&)
826 // FIXME: If there is a concept per-session (per-process) credential storage, the credentials should be added to it for later use.
829 void LayoutTestController::setIconDatabaseEnabled(bool enable)
831 if (enable && !m_drt->persistentStoragePath().isEmpty())
832 QWebSettings::setIconDatabasePath(m_drt->persistentStoragePath());
834 QWebSettings::setIconDatabasePath(QString());
837 void LayoutTestController::setEditingBehavior(const QString& editingBehavior)
839 DumpRenderTreeSupportQt::setEditingBehavior(m_drt->webPage(), editingBehavior);
842 void LayoutTestController::setMockDeviceOrientation(bool canProvideAlpha, double alpha, bool canProvideBeta, double beta, bool canProvideGamma, double gamma)
844 DumpRenderTreeSupportQt::setMockDeviceOrientation(canProvideAlpha, alpha, canProvideBeta, beta, canProvideGamma, gamma);
847 void LayoutTestController::setGeolocationPermission(bool allow)
849 setGeolocationPermissionCommon(allow);
850 QList<WebCore::WebPage*> pages = m_drt->getAllPages();
851 foreach (WebCore::WebPage* page, pages)
852 DumpRenderTreeSupportQt::setMockGeolocationPermission(page, allow);
855 int LayoutTestController::numberOfPendingGeolocationPermissionRequests()
857 int pendingPermissionCount = 0;
858 QList<WebCore::WebPage*> pages = m_drt->getAllPages();
859 foreach (WebCore::WebPage* page, pages)
860 pendingPermissionCount += DumpRenderTreeSupportQt::numberOfPendingGeolocationPermissionRequests(page);
862 return pendingPermissionCount;
865 void LayoutTestController::setGeolocationPermissionCommon(bool allow)
867 m_isGeolocationPermissionSet = true;
868 m_geolocationPermission = allow;
871 void LayoutTestController::setMockGeolocationError(int code, const QString& message)
873 QList<WebCore::WebPage*> pages = m_drt->getAllPages();
874 foreach (WebCore::WebPage* page, pages)
875 DumpRenderTreeSupportQt::setMockGeolocationError(page, code, message);
878 void LayoutTestController::setMockGeolocationPosition(double latitude, double longitude, double accuracy)
880 QList<WebCore::WebPage*> pages = m_drt->getAllPages();
881 foreach (WebCore::WebPage* page, pages)
882 DumpRenderTreeSupportQt::setMockGeolocationPosition(page, latitude, longitude, accuracy);
885 void LayoutTestController::addMockSpeechInputResult(const QString& result, double confidence, const QString& language)
887 // FIXME: Implement for speech input layout tests.
888 // See https://bugs.webkit.org/show_bug.cgi?id=39485.
891 void LayoutTestController::startSpeechInput(const QString& inputElement)
893 // FIXME: Implement for speech input layout tests.
894 // See https://bugs.webkit.org/show_bug.cgi?id=39485.
897 void LayoutTestController::evaluateScriptInIsolatedWorld(int worldID, const QString& script)
899 DumpRenderTreeSupportQt::evaluateScriptInIsolatedWorld(m_drt->webPage()->mainFrame(), worldID, script);
902 bool LayoutTestController::isPageBoxVisible(int pageIndex)
904 return DumpRenderTreeSupportQt::isPageBoxVisible(m_drt->webPage()->mainFrame(), pageIndex);
907 QString LayoutTestController::pageSizeAndMarginsInPixels(int pageIndex, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft)
909 return DumpRenderTreeSupportQt::pageSizeAndMarginsInPixels(m_drt->webPage()->mainFrame(), pageIndex,
910 width, height, marginTop, marginRight, marginBottom, marginLeft);
913 QString LayoutTestController::pageProperty(const QString& propertyName, int pageNumber)
915 return DumpRenderTreeSupportQt::pageProperty(m_drt->webPage()->mainFrame(), propertyName, pageNumber);
918 void LayoutTestController::addUserStyleSheet(const QString& sourceCode)
920 DumpRenderTreeSupportQt::addUserStyleSheet(m_drt->webPage(), sourceCode);
923 void LayoutTestController::removeAllVisitedLinks()
925 QWebHistory* history = m_drt->webPage()->history();
927 DumpRenderTreeSupportQt::dumpVisitedLinksCallbacks(true);
930 bool LayoutTestController::hasSpellingMarker(int, int)
936 QVariantList LayoutTestController::nodesFromRect(const QWebElement& document, int x, int y, unsigned top, unsigned right, unsigned bottom, unsigned left, bool ignoreClipping)
938 return DumpRenderTreeSupportQt::nodesFromRect(document, x, y, top, right, bottom, left, ignoreClipping);
941 void LayoutTestController::addURLToRedirect(const QString& origin, const QString& destination)
943 DumpRenderTreeSupportQt::addURLToRedirect(origin, destination);
946 void LayoutTestController::setMinimumTimerInterval(double minimumTimerInterval)
948 DumpRenderTreeSupportQt::setMinimumTimerInterval(m_drt->webPage(), minimumTimerInterval);
951 void LayoutTestController::originsWithLocalStorage()
956 void LayoutTestController::deleteAllLocalStorage()
961 void LayoutTestController::deleteLocalStorageForOrigin(const QString& originIdentifier)
966 void LayoutTestController::observeStorageTrackerNotifications(unsigned number)
971 void LayoutTestController::syncLocalStorage()
976 QString LayoutTestController::layerTreeAsText()
978 return DumpRenderTreeSupportQt::layerTreeAsText(m_drt->webPage()->mainFrame());
981 void LayoutTestController::setTextDirection(const QString& directionName)
983 if (directionName == "auto")
984 m_drt->webPage()->triggerAction(QWebPage::SetTextDirectionDefault);
985 else if (directionName == "rtl")
986 m_drt->webPage()->triggerAction(QWebPage::SetTextDirectionRightToLeft);
987 else if (directionName == "ltr")
988 m_drt->webPage()->triggerAction(QWebPage::SetTextDirectionLeftToRight);
991 #if QT_VERSION >= 0x040800
992 void LayoutTestController::setAlwaysAcceptCookies(bool accept)
994 QWebSettings* globalSettings = QWebSettings::globalSettings();
996 globalSettings->setThirdPartyCookiePolicy(QWebSettings::AlwaysAllowThirdPartyCookies);
998 // This matches the Safari third-party cookie blocking policy tested in third-party-cookie-relaxing.html
999 globalSettings->setThirdPartyCookiePolicy(QWebSettings::AllowThirdPartyWithExistingCookies);
1003 void LayoutTestController::setAlwaysBlockCookies(bool block)
1005 QWebSettings* globalSettings = QWebSettings::globalSettings();
1007 globalSettings->setThirdPartyCookiePolicy(QWebSettings::AlwaysBlockThirdPartyCookies);
1009 globalSettings->setThirdPartyCookiePolicy(QWebSettings::AlwaysAllowThirdPartyCookies);
1013 const unsigned LayoutTestController::maxViewWidth = 800;
1014 const unsigned LayoutTestController::maxViewHeight = 600;