2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * Copyright (C) 2010 Pawel Hajdan (phajdan.jr@chromium.org)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include "LayoutTestController.h"
35 #include "DRTDevToolsAgent.h"
36 #include "TestShell.h"
37 #include "WebAnimationController.h"
38 #include "WebBindings.h"
39 #include "WebConsoleMessage.h"
41 #include "WebDeviceOrientation.h"
42 #include "WebDeviceOrientationClientMock.h"
43 #include "WebDocument.h"
44 #include "WebElement.h"
46 #include "WebGeolocationClientMock.h"
47 #include "WebIDBFactory.h"
48 #include "WebInputElement.h"
50 #include "WebNotificationPresenter.h"
51 #include "WebPermissions.h"
52 #include "WebScriptSource.h"
53 #include "WebSecurityPolicy.h"
54 #include "WebSettings.h"
56 #include "WebSpeechInputControllerMock.h"
59 #include "WebViewHost.h"
60 #include "webkit/support/webkit_support.h"
67 #include <wtf/text/WTFString.h>
70 #include <wtf/OwnArrayPtr.h>
73 using namespace WebCore;
74 using namespace WebKit;
77 LayoutTestController::LayoutTestController(TestShell* shell)
79 , m_closeRemainingWindows(false)
80 , m_deferMainResourceDataLoad(false)
81 , m_showDebugLayerTree(false)
83 , m_shouldStayOnPageAfterHandlingBeforeUnload(false)
86 // Initialize the map that associates methods of this class with the names
87 // they will use when called by JavaScript. The actual binding of those
88 // names to their methods will be done by calling bindToJavaScript() (defined
89 // by CppBoundClass, the parent to LayoutTestController).
90 bindMethod("addFileToPasteboardOnDrag", &LayoutTestController::addFileToPasteboardOnDrag);
91 bindMethod("addMockSpeechInputResult", &LayoutTestController::addMockSpeechInputResult);
92 bindMethod("addOriginAccessWhitelistEntry", &LayoutTestController::addOriginAccessWhitelistEntry);
93 bindMethod("addUserScript", &LayoutTestController::addUserScript);
94 bindMethod("addUserStyleSheet", &LayoutTestController::addUserStyleSheet);
95 bindMethod("clearAllDatabases", &LayoutTestController::clearAllDatabases);
96 bindMethod("closeWebInspector", &LayoutTestController::closeWebInspector);
97 bindMethod("counterValueForElementById", &LayoutTestController::counterValueForElementById);
98 bindMethod("disableImageLoading", &LayoutTestController::disableImageLoading);
99 bindMethod("display", &LayoutTestController::display);
100 bindMethod("displayInvalidatedRegion", &LayoutTestController::displayInvalidatedRegion);
101 bindMethod("dumpAsText", &LayoutTestController::dumpAsText);
102 bindMethod("dumpBackForwardList", &LayoutTestController::dumpBackForwardList);
103 bindMethod("dumpChildFramesAsText", &LayoutTestController::dumpChildFramesAsText);
104 bindMethod("dumpChildFrameScrollPositions", &LayoutTestController::dumpChildFrameScrollPositions);
105 bindMethod("dumpDatabaseCallbacks", &LayoutTestController::dumpDatabaseCallbacks);
106 bindMethod("dumpEditingCallbacks", &LayoutTestController::dumpEditingCallbacks);
107 bindMethod("dumpFrameLoadCallbacks", &LayoutTestController::dumpFrameLoadCallbacks);
108 bindMethod("dumpProgressFinishedCallback", &LayoutTestController::dumpProgressFinishedCallback);
109 bindMethod("dumpUserGestureInFrameLoadCallbacks", &LayoutTestController::dumpUserGestureInFrameLoadCallbacks);
110 bindMethod("dumpResourceLoadCallbacks", &LayoutTestController::dumpResourceLoadCallbacks);
111 bindMethod("dumpResourceResponseMIMETypes", &LayoutTestController::dumpResourceResponseMIMETypes);
112 bindMethod("dumpSelectionRect", &LayoutTestController::dumpSelectionRect);
113 bindMethod("dumpStatusCallbacks", &LayoutTestController::dumpWindowStatusChanges);
114 bindMethod("dumpTitleChanges", &LayoutTestController::dumpTitleChanges);
115 bindMethod("dumpPermissionClientCallbacks", &LayoutTestController::dumpPermissionClientCallbacks);
116 bindMethod("dumpCreateView", &LayoutTestController::dumpCreateView);
117 bindMethod("elementDoesAutoCompleteForElementWithId", &LayoutTestController::elementDoesAutoCompleteForElementWithId);
118 bindMethod("evaluateInWebInspector", &LayoutTestController::evaluateInWebInspector);
119 bindMethod("evaluateScriptInIsolatedWorld", &LayoutTestController::evaluateScriptInIsolatedWorld);
120 bindMethod("setIsolatedWorldSecurityOrigin", &LayoutTestController::setIsolatedWorldSecurityOrigin);
121 bindMethod("execCommand", &LayoutTestController::execCommand);
122 bindMethod("forceRedSelectionColors", &LayoutTestController::forceRedSelectionColors);
123 bindMethod("grantDesktopNotificationPermission", &LayoutTestController::grantDesktopNotificationPermission);
124 bindMethod("hasSpellingMarker", &LayoutTestController::hasSpellingMarker);
125 bindMethod("isCommandEnabled", &LayoutTestController::isCommandEnabled);
126 bindMethod("isPageBoxVisible", &LayoutTestController::isPageBoxVisible);
127 bindMethod("layerTreeAsText", &LayoutTestController::layerTreeAsText);
128 bindMethod("loseCompositorContext", &LayoutTestController::loseCompositorContext);
129 bindMethod("markerTextForListItem", &LayoutTestController::markerTextForListItem);
130 bindMethod("notifyDone", &LayoutTestController::notifyDone);
131 bindMethod("numberOfActiveAnimations", &LayoutTestController::numberOfActiveAnimations);
132 bindMethod("numberOfPages", &LayoutTestController::numberOfPages);
133 bindMethod("numberOfPendingGeolocationPermissionRequests", &LayoutTestController:: numberOfPendingGeolocationPermissionRequests);
134 bindMethod("objCIdentityIsEqual", &LayoutTestController::objCIdentityIsEqual);
135 bindMethod("overridePreference", &LayoutTestController::overridePreference);
136 bindMethod("pageNumberForElementById", &LayoutTestController::pageNumberForElementById);
137 bindMethod("pageProperty", &LayoutTestController::pageProperty);
138 bindMethod("pageSizeAndMarginsInPixels", &LayoutTestController::pageSizeAndMarginsInPixels);
139 bindMethod("pathToLocalResource", &LayoutTestController::pathToLocalResource);
140 bindMethod("pauseAnimationAtTimeOnElementWithId", &LayoutTestController::pauseAnimationAtTimeOnElementWithId);
141 bindMethod("pauseTransitionAtTimeOnElementWithId", &LayoutTestController::pauseTransitionAtTimeOnElementWithId);
142 bindMethod("queueBackNavigation", &LayoutTestController::queueBackNavigation);
143 bindMethod("queueForwardNavigation", &LayoutTestController::queueForwardNavigation);
144 bindMethod("queueLoadingScript", &LayoutTestController::queueLoadingScript);
145 bindMethod("queueLoad", &LayoutTestController::queueLoad);
146 bindMethod("queueLoadHTMLString", &LayoutTestController::queueLoadHTMLString);
147 bindMethod("queueNonLoadingScript", &LayoutTestController::queueNonLoadingScript);
148 bindMethod("queueReload", &LayoutTestController::queueReload);
149 bindMethod("removeOriginAccessWhitelistEntry", &LayoutTestController::removeOriginAccessWhitelistEntry);
150 bindMethod("repaintSweepHorizontally", &LayoutTestController::repaintSweepHorizontally);
151 bindMethod("resetPageVisibility", &LayoutTestController::resetPageVisibility);
152 bindMethod("resumeAnimations", &LayoutTestController::resumeAnimations);
153 bindMethod("sampleSVGAnimationForElementAtTime", &LayoutTestController::sampleSVGAnimationForElementAtTime);
154 bindMethod("setAcceptsEditing", &LayoutTestController::setAcceptsEditing);
155 bindMethod("setAllowDisplayOfInsecureContent", &LayoutTestController::setAllowDisplayOfInsecureContent);
156 bindMethod("setAllowFileAccessFromFileURLs", &LayoutTestController::setAllowFileAccessFromFileURLs);
157 bindMethod("setAllowRunningOfInsecureContent", &LayoutTestController::setAllowRunningOfInsecureContent);
158 bindMethod("setAllowUniversalAccessFromFileURLs", &LayoutTestController::setAllowUniversalAccessFromFileURLs);
159 bindMethod("setAlwaysAcceptCookies", &LayoutTestController::setAlwaysAcceptCookies);
160 bindMethod("setAuthorAndUserStylesEnabled", &LayoutTestController::setAuthorAndUserStylesEnabled);
161 bindMethod("setAutofilled", &LayoutTestController::setAutofilled);
162 bindMethod("setCanOpenWindows", &LayoutTestController::setCanOpenWindows);
163 bindMethod("setCloseRemainingWindowsWhenComplete", &LayoutTestController::setCloseRemainingWindowsWhenComplete);
164 bindMethod("setCustomPolicyDelegate", &LayoutTestController::setCustomPolicyDelegate);
165 bindMethod("setDatabaseQuota", &LayoutTestController::setDatabaseQuota);
166 bindMethod("setDeferMainResourceDataLoad", &LayoutTestController::setDeferMainResourceDataLoad);
167 bindMethod("setDomainRelaxationForbiddenForURLScheme", &LayoutTestController::setDomainRelaxationForbiddenForURLScheme);
168 bindMethod("setEditingBehavior", &LayoutTestController::setEditingBehavior);
169 bindMethod("setAudioData", &LayoutTestController::setAudioData);
170 bindMethod("setGeolocationPermission", &LayoutTestController::setGeolocationPermission);
171 bindMethod("setIconDatabaseEnabled", &LayoutTestController::setIconDatabaseEnabled);
172 bindMethod("setJavaScriptCanAccessClipboard", &LayoutTestController::setJavaScriptCanAccessClipboard);
173 bindMethod("setJavaScriptProfilingEnabled", &LayoutTestController::setJavaScriptProfilingEnabled);
174 bindMethod("setMinimumTimerInterval", &LayoutTestController::setMinimumTimerInterval);
175 bindMethod("setMockDeviceOrientation", &LayoutTestController::setMockDeviceOrientation);
176 bindMethod("setMockGeolocationError", &LayoutTestController::setMockGeolocationError);
177 bindMethod("setMockGeolocationPosition", &LayoutTestController::setMockGeolocationPosition);
178 bindMethod("setPageVisibility", &LayoutTestController::setPageVisibility);
179 bindMethod("setPluginsEnabled", &LayoutTestController::setPluginsEnabled);
180 bindMethod("setPopupBlockingEnabled", &LayoutTestController::setPopupBlockingEnabled);
181 bindMethod("setPOSIXLocale", &LayoutTestController::setPOSIXLocale);
182 bindMethod("setPrinting", &LayoutTestController::setPrinting);
183 bindMethod("setScrollbarPolicy", &LayoutTestController::setScrollbarPolicy);
184 bindMethod("setSelectTrailingWhitespaceEnabled", &LayoutTestController::setSelectTrailingWhitespaceEnabled);
185 bindMethod("setSmartInsertDeleteEnabled", &LayoutTestController::setSmartInsertDeleteEnabled);
186 bindMethod("setStopProvisionalFrameLoads", &LayoutTestController::setStopProvisionalFrameLoads);
187 bindMethod("setTabKeyCyclesThroughElements", &LayoutTestController::setTabKeyCyclesThroughElements);
188 bindMethod("setUserStyleSheetEnabled", &LayoutTestController::setUserStyleSheetEnabled);
189 bindMethod("setUserStyleSheetLocation", &LayoutTestController::setUserStyleSheetLocation);
190 bindMethod("setValueForUser", &LayoutTestController::setValueForUser);
191 bindMethod("setWillSendRequestClearHeader", &LayoutTestController::setWillSendRequestClearHeader);
192 bindMethod("setWillSendRequestReturnsNull", &LayoutTestController::setWillSendRequestReturnsNull);
193 bindMethod("setWillSendRequestReturnsNullOnRedirect", &LayoutTestController::setWillSendRequestReturnsNullOnRedirect);
194 bindMethod("setWindowIsKey", &LayoutTestController::setWindowIsKey);
195 bindMethod("setXSSAuditorEnabled", &LayoutTestController::setXSSAuditorEnabled);
196 bindMethod("setAsynchronousSpellCheckingEnabled", &LayoutTestController::setAsynchronousSpellCheckingEnabled);
197 bindMethod("showWebInspector", &LayoutTestController::showWebInspector);
198 bindMethod("simulateDesktopNotificationClick", &LayoutTestController::simulateDesktopNotificationClick);
199 bindMethod("startSpeechInput", &LayoutTestController::startSpeechInput);
200 bindMethod("suspendAnimations", &LayoutTestController::suspendAnimations);
201 bindMethod("testRepaint", &LayoutTestController::testRepaint);
202 bindMethod("waitForPolicyDelegate", &LayoutTestController::waitForPolicyDelegate);
203 bindMethod("waitUntilDone", &LayoutTestController::waitUntilDone);
204 bindMethod("windowCount", &LayoutTestController::windowCount);
205 bindMethod("setTextDirection", &LayoutTestController::setTextDirection);
206 bindMethod("setImagesAllowed", &LayoutTestController::setImagesAllowed);
207 bindMethod("setScriptsAllowed", &LayoutTestController::setScriptsAllowed);
208 bindMethod("setStorageAllowed", &LayoutTestController::setStorageAllowed);
209 bindMethod("setPluginsAllowed", &LayoutTestController::setPluginsAllowed);
211 // The following are stubs.
212 bindMethod("abortModal", &LayoutTestController::abortModal);
213 bindMethod("accessStoredWebScriptObject", &LayoutTestController::accessStoredWebScriptObject);
214 bindMethod("addDisallowedURL", &LayoutTestController::addDisallowedURL);
215 bindMethod("applicationCacheDiskUsageForOrigin", &LayoutTestController::applicationCacheDiskUsageForOrigin);
216 bindMethod("callShouldCloseOnWebView", &LayoutTestController::callShouldCloseOnWebView);
217 bindMethod("clearAllApplicationCaches", &LayoutTestController::clearAllApplicationCaches);
218 bindMethod("clearApplicationCacheForOrigin", &LayoutTestController::clearApplicationCacheForOrigin);
219 bindMethod("clearBackForwardList", &LayoutTestController::clearBackForwardList);
220 bindMethod("dumpAsWebArchive", &LayoutTestController::dumpAsWebArchive);
221 bindMethod("keepWebHistory", &LayoutTestController::keepWebHistory);
222 bindMethod("objCClassNameOf", &LayoutTestController::objCClassNameOf);
223 bindMethod("setApplicationCacheOriginQuota", &LayoutTestController::setApplicationCacheOriginQuota);
224 bindMethod("setCallCloseOnWebViews", &LayoutTestController::setCallCloseOnWebViews);
225 bindMethod("setMainFrameIsFirstResponder", &LayoutTestController::setMainFrameIsFirstResponder);
226 bindMethod("setPrivateBrowsingEnabled", &LayoutTestController::setPrivateBrowsingEnabled);
227 bindMethod("setUseDashboardCompatibilityMode", &LayoutTestController::setUseDashboardCompatibilityMode);
228 bindMethod("storeWebScriptObject", &LayoutTestController::storeWebScriptObject);
229 bindMethod("deleteAllLocalStorage", &LayoutTestController::deleteAllLocalStorage);
230 bindMethod("localStorageDiskUsageForOrigin", &LayoutTestController::localStorageDiskUsageForOrigin);
231 bindMethod("originsWithLocalStorage", &LayoutTestController::originsWithLocalStorage);
232 bindMethod("deleteLocalStorageForOrigin", &LayoutTestController::deleteLocalStorageForOrigin);
233 bindMethod("observeStorageTrackerNotifications", &LayoutTestController::observeStorageTrackerNotifications);
234 bindMethod("syncLocalStorage", &LayoutTestController::syncLocalStorage);
235 bindMethod("setShouldStayOnPageAfterHandlingBeforeUnload", &LayoutTestController::setShouldStayOnPageAfterHandlingBeforeUnload);
236 bindMethod("enableFixedLayoutMode", &LayoutTestController::enableFixedLayoutMode);
237 bindMethod("setFixedLayoutSize", &LayoutTestController::setFixedLayoutSize);
239 // The fallback method is called when an unknown method is invoked.
240 bindFallbackMethod(&LayoutTestController::fallbackMethod);
242 // Shared properties.
243 // globalFlag is used by a number of layout tests in
244 // LayoutTests\http\tests\security\dataURL.
245 bindProperty("globalFlag", &m_globalFlag);
246 // webHistoryItemCount is used by tests in LayoutTests\http\tests\history
247 bindProperty("webHistoryItemCount", &m_webHistoryItemCount);
248 bindProperty("titleTextDirection", &m_titleTextDirection);
249 bindProperty("platformName", &m_platformName);
252 LayoutTestController::~LayoutTestController()
256 LayoutTestController::WorkQueue::~WorkQueue()
261 void LayoutTestController::WorkQueue::processWorkSoon()
263 if (m_controller->m_shell->webViewHost()->topLoadingFrame())
266 if (!m_queue.isEmpty()) {
267 // We delay processing queued work to avoid recursion problems.
268 postTask(new WorkQueueTask(this));
269 } else if (!m_controller->m_waitUntilDone)
270 m_controller->m_shell->testFinished();
273 void LayoutTestController::WorkQueue::processWork()
275 TestShell* shell = m_controller->m_shell;
276 // Quit doing work once a load is in progress.
277 while (!m_queue.isEmpty()) {
278 bool startedLoad = m_queue.first()->run(shell);
279 delete m_queue.takeFirst();
284 if (!m_controller->m_waitUntilDone && !shell->webViewHost()->topLoadingFrame())
285 shell->testFinished();
288 void LayoutTestController::WorkQueue::reset()
291 while (!m_queue.isEmpty())
292 delete m_queue.takeFirst();
295 void LayoutTestController::WorkQueue::addWork(WorkItem* work)
301 m_queue.append(work);
304 void LayoutTestController::dumpAsText(const CppArgumentList& arguments, CppVariant* result)
307 m_generatePixelResults = false;
309 // Optional paramater, describing whether it's allowed to dump pixel results in dumpAsText mode.
310 if (arguments.size() > 0 && arguments[0].isBool())
311 m_generatePixelResults = arguments[0].value.boolValue;
316 void LayoutTestController::dumpDatabaseCallbacks(const CppArgumentList&, CppVariant* result)
318 // Do nothing; we don't use this flag anywhere for now
322 void LayoutTestController::dumpEditingCallbacks(const CppArgumentList&, CppVariant* result)
324 m_dumpEditingCallbacks = true;
328 void LayoutTestController::dumpBackForwardList(const CppArgumentList&, CppVariant* result)
330 m_dumpBackForwardList = true;
334 void LayoutTestController::dumpFrameLoadCallbacks(const CppArgumentList&, CppVariant* result)
336 m_dumpFrameLoadCallbacks = true;
340 void LayoutTestController::dumpProgressFinishedCallback(const CppArgumentList&, CppVariant* result)
342 m_dumpProgressFinishedCallback = true;
346 void LayoutTestController::dumpUserGestureInFrameLoadCallbacks(const CppArgumentList&, CppVariant* result)
348 m_dumpUserGestureInFrameLoadCallbacks = true;
352 void LayoutTestController::dumpResourceLoadCallbacks(const CppArgumentList&, CppVariant* result)
354 m_dumpResourceLoadCallbacks = true;
358 void LayoutTestController::dumpResourceResponseMIMETypes(const CppArgumentList&, CppVariant* result)
360 m_dumpResourceResponseMIMETypes = true;
364 void LayoutTestController::dumpChildFrameScrollPositions(const CppArgumentList&, CppVariant* result)
366 m_dumpChildFrameScrollPositions = true;
370 void LayoutTestController::dumpChildFramesAsText(const CppArgumentList&, CppVariant* result)
372 m_dumpChildFramesAsText = true;
376 void LayoutTestController::dumpWindowStatusChanges(const CppArgumentList&, CppVariant* result)
378 m_dumpWindowStatusChanges = true;
382 void LayoutTestController::dumpTitleChanges(const CppArgumentList&, CppVariant* result)
384 m_dumpTitleChanges = true;
388 void LayoutTestController::dumpPermissionClientCallbacks(const CppArgumentList&, CppVariant* result)
390 m_dumpPermissionClientCallbacks = true;
394 void LayoutTestController::dumpCreateView(const CppArgumentList&, CppVariant* result)
396 m_dumpCreateView = true;
400 void LayoutTestController::setAcceptsEditing(const CppArgumentList& arguments, CppVariant* result)
402 if (arguments.size() > 0 && arguments[0].isBool())
403 m_acceptsEditing = arguments[0].value.boolValue;
407 void LayoutTestController::waitUntilDone(const CppArgumentList&, CppVariant* result)
409 if (!webkit_support::BeingDebugged())
410 postDelayedTask(new NotifyDoneTimedOutTask(this), m_shell->layoutTestTimeout());
411 m_waitUntilDone = true;
415 void LayoutTestController::notifyDone(const CppArgumentList&, CppVariant* result)
417 // Test didn't timeout. Kill the timeout timer.
418 m_taskList.revokeAll();
420 completeNotifyDone(false);
424 void LayoutTestController::completeNotifyDone(bool isTimeout)
426 if (m_waitUntilDone && !m_shell->webViewHost()->topLoadingFrame() && m_workQueue.isEmpty()) {
428 m_shell->testTimedOut();
430 m_shell->testFinished();
432 m_waitUntilDone = false;
435 class WorkItemBackForward : public LayoutTestController::WorkItem {
437 WorkItemBackForward(int distance) : m_distance(distance) { }
438 bool run(TestShell* shell)
440 shell->goToOffset(m_distance);
441 return true; // FIXME: Did it really start a navigation?
448 void LayoutTestController::queueBackNavigation(const CppArgumentList& arguments, CppVariant* result)
450 if (arguments.size() > 0 && arguments[0].isNumber())
451 m_workQueue.addWork(new WorkItemBackForward(-arguments[0].toInt32()));
455 void LayoutTestController::queueForwardNavigation(const CppArgumentList& arguments, CppVariant* result)
457 if (arguments.size() > 0 && arguments[0].isNumber())
458 m_workQueue.addWork(new WorkItemBackForward(arguments[0].toInt32()));
462 class WorkItemReload : public LayoutTestController::WorkItem {
464 bool run(TestShell* shell)
471 void LayoutTestController::queueReload(const CppArgumentList&, CppVariant* result)
473 m_workQueue.addWork(new WorkItemReload);
477 class WorkItemLoadingScript : public LayoutTestController::WorkItem {
479 WorkItemLoadingScript(const string& script) : m_script(script) { }
480 bool run(TestShell* shell)
482 shell->webView()->mainFrame()->executeScript(WebScriptSource(WebString::fromUTF8(m_script)));
483 return true; // FIXME: Did it really start a navigation?
490 class WorkItemNonLoadingScript : public LayoutTestController::WorkItem {
492 WorkItemNonLoadingScript(const string& script) : m_script(script) { }
493 bool run(TestShell* shell)
495 shell->webView()->mainFrame()->executeScript(WebScriptSource(WebString::fromUTF8(m_script)));
503 void LayoutTestController::queueLoadingScript(const CppArgumentList& arguments, CppVariant* result)
505 if (arguments.size() > 0 && arguments[0].isString())
506 m_workQueue.addWork(new WorkItemLoadingScript(arguments[0].toString()));
510 void LayoutTestController::queueNonLoadingScript(const CppArgumentList& arguments, CppVariant* result)
512 if (arguments.size() > 0 && arguments[0].isString())
513 m_workQueue.addWork(new WorkItemNonLoadingScript(arguments[0].toString()));
517 class WorkItemLoad : public LayoutTestController::WorkItem {
519 WorkItemLoad(const WebURL& url, const WebString& target)
521 , m_target(target) { }
522 bool run(TestShell* shell)
524 shell->webViewHost()->loadURLForFrame(m_url, m_target);
525 return true; // FIXME: Did it really start a navigation?
533 void LayoutTestController::queueLoad(const CppArgumentList& arguments, CppVariant* result)
535 if (arguments.size() > 0 && arguments[0].isString()) {
536 // FIXME: Implement WebURL::resolve() and avoid GURL.
537 GURL currentURL = m_shell->webView()->mainFrame()->document().url();
538 GURL fullURL = currentURL.Resolve(arguments[0].toString());
541 if (arguments.size() > 1 && arguments[1].isString())
542 target = arguments[1].toString();
544 m_workQueue.addWork(new WorkItemLoad(fullURL, WebString::fromUTF8(target)));
549 class WorkItemLoadHTMLString : public LayoutTestController::WorkItem {
551 WorkItemLoadHTMLString(const std::string& html, const WebURL& baseURL)
553 , m_baseURL(baseURL) { }
554 WorkItemLoadHTMLString(const std::string& html, const WebURL& baseURL, const WebURL& unreachableURL)
557 , m_unreachableURL(unreachableURL) { }
558 bool run(TestShell* shell)
560 shell->webView()->mainFrame()->loadHTMLString(
561 WebKit::WebData(m_html.data(), m_html.length()), m_baseURL, m_unreachableURL);
568 WebURL m_unreachableURL;
571 void LayoutTestController::queueLoadHTMLString(const CppArgumentList& arguments, CppVariant* result)
573 if (arguments.size() > 0 && arguments[0].isString()) {
574 string html = arguments[0].toString();
575 WebURL baseURL(GURL(""));
576 if (arguments.size() > 1 && arguments[1].isString())
577 baseURL = WebURL(GURL(arguments[1].toString()));
578 if (arguments.size() > 2 && arguments[2].isString())
579 m_workQueue.addWork(new WorkItemLoadHTMLString(html, baseURL, WebURL(GURL(arguments[2].toString()))));
581 m_workQueue.addWork(new WorkItemLoadHTMLString(html, baseURL));
586 void LayoutTestController::objCIdentityIsEqual(const CppArgumentList& arguments, CppVariant* result)
588 if (arguments.size() < 2) {
589 // This is the best we can do to return an error.
593 result->set(arguments[0].isEqual(arguments[1]));
596 void LayoutTestController::reset()
599 m_shell->webView()->setZoomLevel(false, 0);
600 m_shell->webView()->setTabKeyCyclesThroughElements(true);
601 #if !OS(DARWIN) && !OS(WINDOWS) // Actually, TOOLKIT_GTK
602 // (Constants copied because we can't depend on the header that defined
603 // them from this file.)
604 m_shell->webView()->setSelectionColors(0xff1e90ff, 0xff000000, 0xffc8c8c8, 0xff323232);
606 m_shell->webView()->removeAllUserContent();
608 m_dumpAsText = false;
609 m_dumpAsAudio = false;
610 m_dumpCreateView = false;
611 m_dumpEditingCallbacks = false;
612 m_dumpFrameLoadCallbacks = false;
613 m_dumpProgressFinishedCallback = false;
614 m_dumpUserGestureInFrameLoadCallbacks = false;
615 m_dumpResourceLoadCallbacks = false;
616 m_dumpResourceResponseMIMETypes = false;
617 m_dumpBackForwardList = false;
618 m_dumpChildFrameScrollPositions = false;
619 m_dumpChildFramesAsText = false;
620 m_dumpWindowStatusChanges = false;
621 m_dumpSelectionRect = false;
622 m_dumpTitleChanges = false;
623 m_dumpPermissionClientCallbacks = false;
624 m_generatePixelResults = true;
625 m_acceptsEditing = true;
626 m_waitUntilDone = false;
627 m_canOpenWindows = false;
628 m_testRepaint = false;
629 m_sweepHorizontally = false;
630 m_shouldAddFileToPasteboard = false;
631 m_stopProvisionalFrameLoads = false;
632 m_deferMainResourceDataLoad = true;
633 m_globalFlag.set(false);
634 m_webHistoryItemCount.set(0);
635 m_titleTextDirection.set("ltr");
636 m_platformName.set("chromium");
637 m_userStyleSheetLocation = WebURL();
638 m_isPrinting = false;
640 webkit_support::SetAcceptAllCookies(false);
641 WebSecurityPolicy::resetOriginAccessWhitelists();
643 // Reset the default quota for each origin to 5MB
644 webkit_support::SetDatabaseQuota(5 * 1024 * 1024);
646 setlocale(LC_ALL, "");
648 if (m_closeRemainingWindows)
649 m_shell->closeRemainingWindows();
651 m_closeRemainingWindows = true;
653 m_taskList.revokeAll();
654 m_shouldStayOnPageAfterHandlingBeforeUnload = false;
657 void LayoutTestController::locationChangeDone()
659 m_webHistoryItemCount.set(m_shell->navigationEntryCount());
661 // No more new work after the first complete load.
662 m_workQueue.setFrozen(true);
664 if (!m_waitUntilDone)
665 m_workQueue.processWorkSoon();
668 void LayoutTestController::policyDelegateDone()
670 ASSERT(m_waitUntilDone);
671 m_shell->testFinished();
672 m_waitUntilDone = false;
675 void LayoutTestController::setCanOpenWindows(const CppArgumentList&, CppVariant* result)
677 m_canOpenWindows = true;
681 void LayoutTestController::setTabKeyCyclesThroughElements(const CppArgumentList& arguments, CppVariant* result)
683 if (arguments.size() > 0 && arguments[0].isBool())
684 m_shell->webView()->setTabKeyCyclesThroughElements(arguments[0].toBoolean());
688 void LayoutTestController::windowCount(const CppArgumentList&, CppVariant* result)
690 result->set(static_cast<int>(m_shell->windowCount()));
693 void LayoutTestController::setCloseRemainingWindowsWhenComplete(const CppArgumentList& arguments, CppVariant* result)
695 if (arguments.size() > 0 && arguments[0].isBool())
696 m_closeRemainingWindows = arguments[0].value.boolValue;
700 void LayoutTestController::setAlwaysAcceptCookies(const CppArgumentList& arguments, CppVariant* result)
702 if (arguments.size() > 0)
703 webkit_support::SetAcceptAllCookies(cppVariantToBool(arguments[0]));
707 void LayoutTestController::setAsynchronousSpellCheckingEnabled(const CppArgumentList& arguments, CppVariant* result)
709 if (arguments.size() > 0 && arguments[0].isBool())
710 m_shell->webView()->settings()->setAsynchronousSpellCheckingEnabled(cppVariantToBool(arguments[0]));
714 void LayoutTestController::showWebInspector(const CppArgumentList&, CppVariant* result)
716 m_shell->showDevTools();
720 void LayoutTestController::closeWebInspector(const CppArgumentList& args, CppVariant* result)
722 m_shell->closeDevTools();
726 void LayoutTestController::setWindowIsKey(const CppArgumentList& arguments, CppVariant* result)
728 if (arguments.size() > 0 && arguments[0].isBool())
729 m_shell->setFocus(m_shell->webView(), arguments[0].value.boolValue);
733 void LayoutTestController::setUserStyleSheetEnabled(const CppArgumentList& arguments, CppVariant* result)
735 if (arguments.size() > 0 && arguments[0].isBool()) {
736 m_shell->preferences()->userStyleSheetLocation = arguments[0].value.boolValue ? m_userStyleSheetLocation : WebURL();
737 m_shell->applyPreferences();
742 void LayoutTestController::setUserStyleSheetLocation(const CppArgumentList& arguments, CppVariant* result)
744 if (arguments.size() > 0 && arguments[0].isString()) {
745 m_userStyleSheetLocation = webkit_support::LocalFileToDataURL(
746 webkit_support::RewriteLayoutTestsURL(arguments[0].toString()));
747 m_shell->preferences()->userStyleSheetLocation = m_userStyleSheetLocation;
748 m_shell->applyPreferences();
753 void LayoutTestController::setAuthorAndUserStylesEnabled(const CppArgumentList& arguments, CppVariant* result)
755 if (arguments.size() > 0 && arguments[0].isBool()) {
756 m_shell->preferences()->authorAndUserStylesEnabled = arguments[0].value.boolValue;
757 m_shell->applyPreferences();
762 void LayoutTestController::execCommand(const CppArgumentList& arguments, CppVariant* result)
765 if (arguments.size() <= 0 || !arguments[0].isString())
768 std::string command = arguments[0].toString();
769 std::string value("");
770 // Ignore the second parameter (which is userInterface)
771 // since this command emulates a manual action.
772 if (arguments.size() >= 3 && arguments[2].isString())
773 value = arguments[2].toString();
775 // Note: webkit's version does not return the boolean, so neither do we.
776 m_shell->webView()->focusedFrame()->executeCommand(WebString::fromUTF8(command), WebString::fromUTF8(value));
779 void LayoutTestController::isCommandEnabled(const CppArgumentList& arguments, CppVariant* result)
781 if (arguments.size() <= 0 || !arguments[0].isString()) {
786 std::string command = arguments[0].toString();
787 bool rv = m_shell->webView()->focusedFrame()->isCommandEnabled(WebString::fromUTF8(command));
791 void LayoutTestController::setPopupBlockingEnabled(const CppArgumentList& arguments, CppVariant* result)
793 if (arguments.size() > 0 && arguments[0].isBool()) {
794 bool blockPopups = arguments[0].toBoolean();
795 m_shell->preferences()->javaScriptCanOpenWindowsAutomatically = !blockPopups;
796 m_shell->applyPreferences();
801 void LayoutTestController::setImagesAllowed(const CppArgumentList& arguments, CppVariant* result)
803 if (arguments.size() > 0 && arguments[0].isBool())
804 m_shell->webPermissions()->setImagesAllowed(arguments[0].toBoolean());
808 void LayoutTestController::setScriptsAllowed(const CppArgumentList& arguments, CppVariant* result)
810 if (arguments.size() > 0 && arguments[0].isBool())
811 m_shell->webPermissions()->setScriptsAllowed(arguments[0].toBoolean());
815 void LayoutTestController::setStorageAllowed(const CppArgumentList& arguments, CppVariant* result)
817 if (arguments.size() > 0 && arguments[0].isBool())
818 m_shell->webPermissions()->setStorageAllowed(arguments[0].toBoolean());
822 void LayoutTestController::setPluginsAllowed(const CppArgumentList& arguments, CppVariant* result)
824 if (arguments.size() > 0 && arguments[0].isBool())
825 m_shell->webPermissions()->setPluginsAllowed(arguments[0].toBoolean());
829 void LayoutTestController::setUseDashboardCompatibilityMode(const CppArgumentList&, CppVariant* result)
831 // We have no need to support Dashboard Compatibility Mode (mac-only)
835 void LayoutTestController::clearAllApplicationCaches(const CppArgumentList&, CppVariant* result)
837 // FIXME: Implement to support application cache quotas.
841 void LayoutTestController::clearApplicationCacheForOrigin(const CppArgumentList&, CppVariant* result)
843 // FIXME: Implement to support deleting all application cache for an origin.
847 void LayoutTestController::setApplicationCacheOriginQuota(const CppArgumentList&, CppVariant* result)
849 // FIXME: Implement to support application cache quotas.
853 void LayoutTestController::originsWithApplicationCache(const CppArgumentList&, CppVariant* result)
855 // FIXME: Implement to support getting origins that have application caches.
859 void LayoutTestController::applicationCacheDiskUsageForOrigin(const CppArgumentList&, CppVariant* result)
861 // FIXME: Implement to support getting disk usage by all application cache for an origin.
865 void LayoutTestController::setScrollbarPolicy(const CppArgumentList&, CppVariant* result)
868 // Currently only has a non-null implementation on QT.
872 void LayoutTestController::setCustomPolicyDelegate(const CppArgumentList& arguments, CppVariant* result)
874 if (arguments.size() > 0 && arguments[0].isBool()) {
875 bool enable = arguments[0].value.boolValue;
876 bool permissive = false;
877 if (arguments.size() > 1 && arguments[1].isBool())
878 permissive = arguments[1].value.boolValue;
879 m_shell->webViewHost()->setCustomPolicyDelegate(enable, permissive);
884 void LayoutTestController::waitForPolicyDelegate(const CppArgumentList&, CppVariant* result)
886 m_shell->webViewHost()->waitForPolicyDelegate();
887 m_waitUntilDone = true;
891 void LayoutTestController::setWillSendRequestClearHeader(const CppArgumentList& arguments, CppVariant* result)
893 if (arguments.size() > 0 && arguments[0].isString()) {
894 string header = arguments[0].toString();
896 m_shell->webViewHost()->addClearHeader(String::fromUTF8(header.c_str()));
901 void LayoutTestController::setWillSendRequestReturnsNullOnRedirect(const CppArgumentList& arguments, CppVariant* result)
903 if (arguments.size() > 0 && arguments[0].isBool())
904 m_shell->webViewHost()->setBlockRedirects(arguments[0].value.boolValue);
908 void LayoutTestController::setWillSendRequestReturnsNull(const CppArgumentList& arguments, CppVariant* result)
910 if (arguments.size() > 0 && arguments[0].isBool())
911 m_shell->webViewHost()->setRequestReturnNull(arguments[0].value.boolValue);
915 void LayoutTestController::pathToLocalResource(const CppArgumentList& arguments, CppVariant* result)
918 if (arguments.size() <= 0 || !arguments[0].isString())
921 string url = arguments[0].toString();
923 if (!url.find("/tmp/")) {
924 // We want a temp file.
925 const unsigned tempPrefixLength = 5;
926 size_t bufferSize = MAX_PATH;
927 OwnArrayPtr<WCHAR> tempPath = adoptArrayPtr(new WCHAR[bufferSize]);
928 DWORD tempLength = ::GetTempPathW(bufferSize, tempPath.get());
929 if (tempLength + url.length() - tempPrefixLength + 1 > bufferSize) {
930 bufferSize = tempLength + url.length() - tempPrefixLength + 1;
931 tempPath = adoptArrayPtr(new WCHAR[bufferSize]);
932 tempLength = GetTempPathW(bufferSize, tempPath.get());
933 ASSERT(tempLength < bufferSize);
935 string resultPath(WebString(tempPath.get(), tempLength).utf8());
936 resultPath.append(url.substr(tempPrefixLength));
937 result->set(resultPath);
942 // Some layout tests use file://// which we resolve as a UNC path. Normalize
943 // them to just file:///.
944 string lowerUrl = url;
945 transform(lowerUrl.begin(), lowerUrl.end(), lowerUrl.begin(), ::tolower);
946 while (!lowerUrl.find("file:////")) {
947 url = url.substr(0, 8) + url.substr(9);
948 lowerUrl = lowerUrl.substr(0, 8) + lowerUrl.substr(9);
950 result->set(webkit_support::RewriteLayoutTestsURL(url).spec());
953 void LayoutTestController::addFileToPasteboardOnDrag(const CppArgumentList&, CppVariant* result)
956 m_shouldAddFileToPasteboard = true;
959 void LayoutTestController::setStopProvisionalFrameLoads(const CppArgumentList&, CppVariant* result)
962 m_stopProvisionalFrameLoads = true;
965 void LayoutTestController::setSmartInsertDeleteEnabled(const CppArgumentList& arguments, CppVariant* result)
967 if (arguments.size() > 0 && arguments[0].isBool())
968 m_shell->webViewHost()->setSmartInsertDeleteEnabled(arguments[0].value.boolValue);
972 void LayoutTestController::setSelectTrailingWhitespaceEnabled(const CppArgumentList& arguments, CppVariant* result)
974 if (arguments.size() > 0 && arguments[0].isBool())
975 m_shell->webViewHost()->setSelectTrailingWhitespaceEnabled(arguments[0].value.boolValue);
979 bool LayoutTestController::pauseAnimationAtTimeOnElementWithId(const WebString& animationName, double time, const WebString& elementId)
981 WebFrame* webFrame = m_shell->webView()->mainFrame();
985 WebAnimationController* controller = webFrame->animationController();
989 WebElement element = webFrame->document().getElementById(elementId);
990 if (element.isNull())
992 return controller->pauseAnimationAtTime(element, animationName, time);
995 bool LayoutTestController::pauseTransitionAtTimeOnElementWithId(const WebString& propertyName, double time, const WebString& elementId)
997 WebFrame* webFrame = m_shell->webView()->mainFrame();
1001 WebAnimationController* controller = webFrame->animationController();
1005 WebElement element = webFrame->document().getElementById(elementId);
1006 if (element.isNull())
1008 return controller->pauseTransitionAtTime(element, propertyName, time);
1011 bool LayoutTestController::elementDoesAutoCompleteForElementWithId(const WebString& elementId)
1013 WebFrame* webFrame = m_shell->webView()->mainFrame();
1017 WebElement element = webFrame->document().getElementById(elementId);
1018 if (element.isNull() || !element.hasTagName("input"))
1021 WebInputElement inputElement = element.to<WebInputElement>();
1022 return inputElement.autoComplete();
1025 int LayoutTestController::numberOfActiveAnimations()
1027 WebFrame* webFrame = m_shell->webView()->mainFrame();
1031 WebAnimationController* controller = webFrame->animationController();
1035 return controller->numberOfActiveAnimations();
1038 void LayoutTestController::suspendAnimations()
1040 WebFrame* webFrame = m_shell->webView()->mainFrame();
1044 WebAnimationController* controller = webFrame->animationController();
1048 controller->suspendAnimations();
1051 void LayoutTestController::resumeAnimations()
1053 WebFrame* webFrame = m_shell->webView()->mainFrame();
1057 WebAnimationController* controller = webFrame->animationController();
1061 controller->resumeAnimations();
1064 void LayoutTestController::pauseAnimationAtTimeOnElementWithId(const CppArgumentList& arguments, CppVariant* result)
1067 if (arguments.size() > 2 && arguments[0].isString() && arguments[1].isNumber() && arguments[2].isString()) {
1068 WebString animationName = cppVariantToWebString(arguments[0]);
1069 double time = arguments[1].toDouble();
1070 WebString elementId = cppVariantToWebString(arguments[2]);
1071 result->set(pauseAnimationAtTimeOnElementWithId(animationName, time, elementId));
1075 void LayoutTestController::pauseTransitionAtTimeOnElementWithId(const CppArgumentList& arguments, CppVariant* result)
1078 if (arguments.size() > 2 && arguments[0].isString() && arguments[1].isNumber() && arguments[2].isString()) {
1079 WebString propertyName = cppVariantToWebString(arguments[0]);
1080 double time = arguments[1].toDouble();
1081 WebString elementId = cppVariantToWebString(arguments[2]);
1082 result->set(pauseTransitionAtTimeOnElementWithId(propertyName, time, elementId));
1086 void LayoutTestController::elementDoesAutoCompleteForElementWithId(const CppArgumentList& arguments, CppVariant* result)
1088 if (arguments.size() != 1 || !arguments[0].isString()) {
1092 WebString elementId = cppVariantToWebString(arguments[0]);
1093 result->set(elementDoesAutoCompleteForElementWithId(elementId));
1096 void LayoutTestController::numberOfActiveAnimations(const CppArgumentList&, CppVariant* result)
1098 result->set(numberOfActiveAnimations());
1101 void LayoutTestController::suspendAnimations(const CppArgumentList&, CppVariant* result)
1103 suspendAnimations();
1107 void LayoutTestController::resumeAnimations(const CppArgumentList&, CppVariant* result)
1113 void LayoutTestController::sampleSVGAnimationForElementAtTime(const CppArgumentList& arguments, CppVariant* result)
1115 if (arguments.size() != 3) {
1119 WebString animationId = cppVariantToWebString(arguments[0]);
1120 double time = arguments[1].toDouble();
1121 WebString elementId = cppVariantToWebString(arguments[2]);
1122 bool success = m_shell->webView()->mainFrame()->pauseSVGAnimation(animationId, time, elementId);
1123 result->set(success);
1126 void LayoutTestController::disableImageLoading(const CppArgumentList&, CppVariant* result)
1128 m_shell->preferences()->loadsImagesAutomatically = false;
1129 m_shell->applyPreferences();
1133 void LayoutTestController::setIconDatabaseEnabled(const CppArgumentList&, CppVariant* result)
1135 // We don't use the WebKit icon database.
1139 void LayoutTestController::callShouldCloseOnWebView(const CppArgumentList&, CppVariant* result)
1141 result->set(m_shell->webView()->dispatchBeforeUnloadEvent());
1144 void LayoutTestController::grantDesktopNotificationPermission(const CppArgumentList& arguments, CppVariant* result)
1146 if (arguments.size() != 1 || !arguments[0].isString()) {
1150 #if ENABLE(NOTIFICATIONS)
1151 m_shell->notificationPresenter()->grantPermission(cppVariantToWebString(arguments[0]));
1156 void LayoutTestController::simulateDesktopNotificationClick(const CppArgumentList& arguments, CppVariant* result)
1158 if (arguments.size() != 1 || !arguments[0].isString()) {
1162 #if ENABLE(NOTIFICATIONS)
1163 if (m_shell->notificationPresenter()->simulateClick(cppVariantToWebString(arguments[0])))
1170 void LayoutTestController::setDomainRelaxationForbiddenForURLScheme(const CppArgumentList& arguments, CppVariant* result)
1172 if (arguments.size() != 2 || !arguments[0].isBool() || !arguments[1].isString())
1174 m_shell->webView()->setDomainRelaxationForbidden(cppVariantToBool(arguments[0]), cppVariantToWebString(arguments[1]));
1177 void LayoutTestController::setDeferMainResourceDataLoad(const CppArgumentList& arguments, CppVariant* result)
1179 if (arguments.size() == 1)
1180 m_deferMainResourceDataLoad = cppVariantToBool(arguments[0]);
1184 // Unimplemented stubs
1187 void LayoutTestController::dumpAsWebArchive(const CppArgumentList& arguments, CppVariant* result)
1192 void LayoutTestController::setMainFrameIsFirstResponder(const CppArgumentList& arguments, CppVariant* result)
1197 void LayoutTestController::dumpSelectionRect(const CppArgumentList& arguments, CppVariant* result)
1199 m_dumpSelectionRect = true;
1203 void LayoutTestController::display(const CppArgumentList& arguments, CppVariant* result)
1205 WebViewHost* host = m_shell->webViewHost();
1206 const WebKit::WebSize& size = m_shell->webView()->size();
1207 WebRect rect(0, 0, size.width, size.height);
1208 host->updatePaintRect(rect);
1209 host->paintInvalidatedRegion();
1210 host->displayRepaintMask();
1214 void LayoutTestController::displayInvalidatedRegion(const CppArgumentList& arguments, CppVariant* result)
1216 WebViewHost* host = m_shell->webViewHost();
1217 host->paintInvalidatedRegion();
1218 host->displayRepaintMask();
1222 void LayoutTestController::testRepaint(const CppArgumentList&, CppVariant* result)
1224 m_testRepaint = true;
1228 void LayoutTestController::repaintSweepHorizontally(const CppArgumentList&, CppVariant* result)
1230 m_sweepHorizontally = true;
1234 void LayoutTestController::clearBackForwardList(const CppArgumentList& arguments, CppVariant* result)
1239 void LayoutTestController::keepWebHistory(const CppArgumentList& arguments, CppVariant* result)
1244 void LayoutTestController::storeWebScriptObject(const CppArgumentList& arguments, CppVariant* result)
1249 void LayoutTestController::accessStoredWebScriptObject(const CppArgumentList& arguments, CppVariant* result)
1254 void LayoutTestController::objCClassNameOf(const CppArgumentList& arguments, CppVariant* result)
1259 void LayoutTestController::addDisallowedURL(const CppArgumentList& arguments, CppVariant* result)
1264 void LayoutTestController::setCallCloseOnWebViews(const CppArgumentList& arguments, CppVariant* result)
1269 void LayoutTestController::setPrivateBrowsingEnabled(const CppArgumentList& arguments, CppVariant* result)
1274 void LayoutTestController::setJavaScriptCanAccessClipboard(const CppArgumentList& arguments, CppVariant* result)
1276 if (arguments.size() > 0 && arguments[0].isBool()) {
1277 m_shell->preferences()->javaScriptCanAccessClipboard = arguments[0].value.boolValue;
1278 m_shell->applyPreferences();
1283 void LayoutTestController::setXSSAuditorEnabled(const CppArgumentList& arguments, CppVariant* result)
1285 if (arguments.size() > 0 && arguments[0].isBool()) {
1286 m_shell->preferences()->XSSAuditorEnabled = arguments[0].value.boolValue;
1287 m_shell->applyPreferences();
1292 void LayoutTestController::evaluateScriptInIsolatedWorld(const CppArgumentList& arguments, CppVariant* result)
1294 if (arguments.size() >= 2 && arguments[0].isNumber() && arguments[1].isString()) {
1295 WebScriptSource source(cppVariantToWebString(arguments[1]));
1296 // This relies on the iframe focusing itself when it loads. This is a bit
1297 // sketchy, but it seems to be what other tests do.
1298 m_shell->webView()->focusedFrame()->executeScriptInIsolatedWorld(arguments[0].toInt32(), &source, 1, 1);
1303 void LayoutTestController::setIsolatedWorldSecurityOrigin(const CppArgumentList& arguments, CppVariant* result)
1307 if (arguments.size() != 2 || !arguments[0].isNumber() || !arguments[1].isString())
1310 m_shell->webView()->focusedFrame()->setIsolatedWorldSecurityOrigin(
1311 arguments[0].toInt32(),
1312 WebSecurityOrigin::createFromString(cppVariantToWebString(arguments[1])));
1315 void LayoutTestController::setAllowUniversalAccessFromFileURLs(const CppArgumentList& arguments, CppVariant* result)
1317 if (arguments.size() > 0 && arguments[0].isBool()) {
1318 m_shell->preferences()->allowUniversalAccessFromFileURLs = arguments[0].value.boolValue;
1319 m_shell->applyPreferences();
1324 void LayoutTestController::setAllowDisplayOfInsecureContent(const CppArgumentList& arguments, CppVariant* result)
1326 if (arguments.size() > 0 && arguments[0].isBool())
1327 m_shell->webPermissions()->setDisplayingInsecureContentAllowed(arguments[0].toBoolean());
1332 void LayoutTestController::setAllowFileAccessFromFileURLs(const CppArgumentList& arguments, CppVariant* result)
1334 if (arguments.size() > 0 && arguments[0].isBool()) {
1335 m_shell->preferences()->allowFileAccessFromFileURLs = arguments[0].value.boolValue;
1336 m_shell->applyPreferences();
1341 void LayoutTestController::setAllowRunningOfInsecureContent(const CppArgumentList& arguments, CppVariant* result)
1343 if (arguments.size() > 0 && arguments[0].isBool())
1344 m_shell->webPermissions()->setRunningInsecureContentAllowed(arguments[0].value.boolValue);
1349 // Need these conversions because the format of the value for booleans
1350 // may vary - for example, on mac "1" and "0" are used for boolean.
1351 bool LayoutTestController::cppVariantToBool(const CppVariant& value)
1354 return value.toBoolean();
1355 if (value.isNumber())
1356 return value.toInt32();
1357 if (value.isString()) {
1358 string valueString = value.toString();
1359 if (valueString == "true" || valueString == "1")
1361 if (valueString == "false" || valueString == "0")
1364 logErrorToConsole("Invalid value. Expected boolean value.");
1368 int32_t LayoutTestController::cppVariantToInt32(const CppVariant& value)
1370 if (value.isNumber())
1371 return value.toInt32();
1372 if (value.isString()) {
1373 string stringSource = value.toString();
1374 const char* source = stringSource.data();
1376 long number = strtol(source, &end, 10);
1377 if (end == source + stringSource.length() && number >= numeric_limits<int32_t>::min() && number <= numeric_limits<int32_t>::max())
1378 return static_cast<int32_t>(number);
1380 logErrorToConsole("Invalid value for preference. Expected integer value.");
1384 WebString LayoutTestController::cppVariantToWebString(const CppVariant& value)
1386 if (!value.isString()) {
1387 logErrorToConsole("Invalid value for preference. Expected string value.");
1390 return WebString::fromUTF8(value.toString());
1393 Vector<WebString> LayoutTestController::cppVariantToWebStringArray(const CppVariant& value)
1395 if (!value.isObject()) {
1396 logErrorToConsole("Invalid value for preference. Expected object value.");
1397 return Vector<WebString>();
1399 Vector<WebString> resultVector;
1400 Vector<string> stringVector = value.toStringVector();
1401 for (size_t i = 0; i < stringVector.size(); ++i)
1402 resultVector.append(WebString::fromUTF8(stringVector[i].c_str()));
1403 return resultVector;
1406 // Sets map based on scriptFontPairs, a collapsed vector of pairs of ISO 15924
1407 // four-letter script code and font such as:
1408 // { "Arab", "My Arabic Font", "Grek", "My Greek Font" }
1409 static void setFontMap(WebPreferences::ScriptFontFamilyMap& map, const Vector<WebString>& scriptFontPairs)
1413 while (i + 1 < scriptFontPairs.size()) {
1414 const WebString& script = scriptFontPairs[i++];
1415 const WebString& font = scriptFontPairs[i++];
1417 int32_t code = u_getPropertyValueEnum(UCHAR_SCRIPT, script.utf8().data());
1418 if (code >= 0 && code < USCRIPT_CODE_LIMIT)
1419 map.set(static_cast<int>(code), font);
1423 void LayoutTestController::overridePreference(const CppArgumentList& arguments, CppVariant* result)
1426 if (arguments.size() != 2 || !arguments[0].isString())
1429 string key = arguments[0].toString();
1430 CppVariant value = arguments[1];
1431 WebPreferences* prefs = m_shell->preferences();
1432 if (key == "WebKitStandardFont")
1433 prefs->standardFontFamily = cppVariantToWebString(value);
1434 else if (key == "WebKitFixedFont")
1435 prefs->fixedFontFamily = cppVariantToWebString(value);
1436 else if (key == "WebKitSerifFont")
1437 prefs->serifFontFamily = cppVariantToWebString(value);
1438 else if (key == "WebKitSansSerifFont")
1439 prefs->sansSerifFontFamily = cppVariantToWebString(value);
1440 else if (key == "WebKitCursiveFont")
1441 prefs->cursiveFontFamily = cppVariantToWebString(value);
1442 else if (key == "WebKitFantasyFont")
1443 prefs->fantasyFontFamily = cppVariantToWebString(value);
1444 else if (key == "WebKitStandardFontMap")
1445 setFontMap(prefs->standardFontMap, cppVariantToWebStringArray(value));
1446 else if (key == "WebKitFixedFontMap")
1447 setFontMap(prefs->fixedFontMap, cppVariantToWebStringArray(value));
1448 else if (key == "WebKitSerifFontMap")
1449 setFontMap(prefs->serifFontMap, cppVariantToWebStringArray(value));
1450 else if (key == "WebKitSansSerifFontMap")
1451 setFontMap(prefs->sansSerifFontMap, cppVariantToWebStringArray(value));
1452 else if (key == "WebKitCursiveFontMap")
1453 setFontMap(prefs->cursiveFontMap, cppVariantToWebStringArray(value));
1454 else if (key == "WebKitFantasyFontMap")
1455 setFontMap(prefs->fantasyFontMap, cppVariantToWebStringArray(value));
1456 else if (key == "WebKitDefaultFontSize")
1457 prefs->defaultFontSize = cppVariantToInt32(value);
1458 else if (key == "WebKitDefaultFixedFontSize")
1459 prefs->defaultFixedFontSize = cppVariantToInt32(value);
1460 else if (key == "WebKitMinimumFontSize")
1461 prefs->minimumFontSize = cppVariantToInt32(value);
1462 else if (key == "WebKitMinimumLogicalFontSize")
1463 prefs->minimumLogicalFontSize = cppVariantToInt32(value);
1464 else if (key == "WebKitDefaultTextEncodingName")
1465 prefs->defaultTextEncodingName = cppVariantToWebString(value);
1466 else if (key == "WebKitJavaScriptEnabled")
1467 prefs->javaScriptEnabled = cppVariantToBool(value);
1468 else if (key == "WebKitWebSecurityEnabled")
1469 prefs->webSecurityEnabled = cppVariantToBool(value);
1470 else if (key == "WebKitJavaScriptCanOpenWindowsAutomatically")
1471 prefs->javaScriptCanOpenWindowsAutomatically = cppVariantToBool(value);
1472 else if (key == "WebKitDisplayImagesKey")
1473 prefs->loadsImagesAutomatically = cppVariantToBool(value);
1474 else if (key == "WebKitPluginsEnabled")
1475 prefs->pluginsEnabled = cppVariantToBool(value);
1476 else if (key == "WebKitDOMPasteAllowedPreferenceKey")
1477 prefs->DOMPasteAllowed = cppVariantToBool(value);
1478 else if (key == "WebKitDeveloperExtrasEnabledPreferenceKey")
1479 prefs->developerExtrasEnabled = cppVariantToBool(value);
1480 else if (key == "WebKitShrinksStandaloneImagesToFit")
1481 prefs->shrinksStandaloneImagesToFit = cppVariantToBool(value);
1482 else if (key == "WebKitTextAreasAreResizable")
1483 prefs->textAreasAreResizable = cppVariantToBool(value);
1484 else if (key == "WebKitJavaEnabled")
1485 prefs->javaEnabled = cppVariantToBool(value);
1486 else if (key == "WebKitUsesPageCachePreferenceKey")
1487 prefs->usesPageCache = cppVariantToBool(value);
1488 else if (key == "WebKitJavaScriptCanAccessClipboard")
1489 prefs->javaScriptCanAccessClipboard = cppVariantToBool(value);
1490 else if (key == "WebKitXSSAuditorEnabled")
1491 prefs->XSSAuditorEnabled = cppVariantToBool(value);
1492 else if (key == "WebKitLocalStorageEnabledPreferenceKey")
1493 prefs->localStorageEnabled = cppVariantToBool(value);
1494 else if (key == "WebKitOfflineWebApplicationCacheEnabled")
1495 prefs->offlineWebApplicationCacheEnabled = cppVariantToBool(value);
1496 else if (key == "WebKitTabToLinksPreferenceKey")
1497 prefs->tabsToLinks = cppVariantToBool(value);
1498 else if (key == "WebKitWebGLEnabled")
1499 prefs->experimentalWebGLEnabled = cppVariantToBool(value);
1500 else if (key == "WebKitHyperlinkAuditingEnabled")
1501 prefs->hyperlinkAuditingEnabled = cppVariantToBool(value);
1502 else if (key == "WebKitEnableCaretBrowsing")
1503 prefs->caretBrowsingEnabled = cppVariantToBool(value);
1504 else if (key == "WebKitAllowDisplayingInsecureContent")
1505 prefs->allowDisplayOfInsecureContent = cppVariantToBool(value);
1506 else if (key == "WebKitAllowRunningInsecureContent")
1507 prefs->allowRunningOfInsecureContent = cppVariantToBool(value);
1508 else if (key == "WebKitHixie76WebSocketProtocolEnabled")
1509 prefs->hixie76WebSocketProtocolEnabled = cppVariantToBool(value);
1510 else if (key == "WebKitWebAudioEnabled") {
1511 ASSERT(cppVariantToBool(value));
1513 string message("Invalid name for preference: ");
1514 message.append(key);
1515 logErrorToConsole(message);
1517 m_shell->applyPreferences();
1520 void LayoutTestController::fallbackMethod(const CppArgumentList&, CppVariant* result)
1522 printf("CONSOLE MESSAGE: JavaScript ERROR: unknown method called on LayoutTestController\n");
1526 void LayoutTestController::addOriginAccessWhitelistEntry(const CppArgumentList& arguments, CppVariant* result)
1530 if (arguments.size() != 4 || !arguments[0].isString() || !arguments[1].isString()
1531 || !arguments[2].isString() || !arguments[3].isBool())
1534 WebKit::WebURL url(GURL(arguments[0].toString()));
1538 WebSecurityPolicy::addOriginAccessWhitelistEntry(
1540 cppVariantToWebString(arguments[1]),
1541 cppVariantToWebString(arguments[2]),
1542 arguments[3].toBoolean());
1545 void LayoutTestController::removeOriginAccessWhitelistEntry(const CppArgumentList& arguments, CppVariant* result)
1549 if (arguments.size() != 4 || !arguments[0].isString() || !arguments[1].isString()
1550 || !arguments[2].isString() || !arguments[3].isBool())
1553 WebKit::WebURL url(GURL(arguments[0].toString()));
1557 WebSecurityPolicy::removeOriginAccessWhitelistEntry(
1559 cppVariantToWebString(arguments[1]),
1560 cppVariantToWebString(arguments[2]),
1561 arguments[3].toBoolean());
1564 void LayoutTestController::clearAllDatabases(const CppArgumentList& arguments, CppVariant* result)
1567 webkit_support::ClearAllDatabases();
1570 void LayoutTestController::setDatabaseQuota(const CppArgumentList& arguments, CppVariant* result)
1573 if ((arguments.size() >= 1) && arguments[0].isNumber())
1574 webkit_support::SetDatabaseQuota(arguments[0].toInt32());
1577 void LayoutTestController::setPOSIXLocale(const CppArgumentList& arguments, CppVariant* result)
1580 if (arguments.size() == 1 && arguments[0].isString())
1581 setlocale(LC_ALL, arguments[0].toString().c_str());
1584 void LayoutTestController::counterValueForElementById(const CppArgumentList& arguments, CppVariant* result)
1587 if (arguments.size() < 1 || !arguments[0].isString())
1589 WebFrame* frame = m_shell->webView()->mainFrame();
1592 WebString counterValue = frame->counterValueForElementById(cppVariantToWebString(arguments[0]));
1593 if (counterValue.isNull())
1595 result->set(counterValue.utf8());
1598 // Parse a single argument. The method returns true if there is an argument that
1599 // is a number or if there is no argument at all. It returns false only if there
1600 // is some argument that is not a number. The value parameter is filled with the
1601 // parsed number, or given the default if there is no argument.
1602 static bool parseCppArgumentInt32(const CppArgumentList& arguments, int argIndex, int* value, int defaultValue)
1604 if (static_cast<int>(arguments.size()) > argIndex) {
1605 if (!arguments[argIndex].isNumber())
1607 *value = arguments[argIndex].toInt32();
1610 *value = defaultValue;
1614 static bool parsePageSizeParameters(const CppArgumentList& arguments,
1616 int* pageWidthInPixels,
1617 int* pageHeightInPixels)
1619 // WebKit is using the window width/height of DumpRenderTree as the
1620 // default value of the page size.
1621 // FIXME: share the default values with other ports.
1622 int argCount = static_cast<int>(arguments.size()) - argOffset;
1623 if (argCount && argCount != 2)
1625 if (!parseCppArgumentInt32(arguments, argOffset, pageWidthInPixels, 800)
1626 || !parseCppArgumentInt32(arguments, argOffset + 1, pageHeightInPixels, 600))
1631 static bool parsePageNumber(const CppArgumentList& arguments, int argOffset, int* pageNumber)
1633 if (static_cast<int>(arguments.size()) > argOffset + 1)
1635 if (!parseCppArgumentInt32(arguments, argOffset, pageNumber, 0))
1640 static bool parsePageNumberSizeMargins(const CppArgumentList& arguments, int argOffset,
1641 int* pageNumber, int* width, int* height,
1642 int* marginTop, int* marginRight, int* marginBottom, int* marginLeft)
1644 int argCount = static_cast<int>(arguments.size()) - argOffset;
1645 if (argCount && argCount != 7)
1647 if (!parseCppArgumentInt32(arguments, argOffset, pageNumber, 0)
1648 || !parseCppArgumentInt32(arguments, argOffset + 1, width, 0)
1649 || !parseCppArgumentInt32(arguments, argOffset + 2, height, 0)
1650 || !parseCppArgumentInt32(arguments, argOffset + 3, marginTop, 0)
1651 || !parseCppArgumentInt32(arguments, argOffset + 4, marginRight, 0)
1652 || !parseCppArgumentInt32(arguments, argOffset + 5, marginBottom, 0)
1653 || !parseCppArgumentInt32(arguments, argOffset + 6, marginLeft, 0))
1658 void LayoutTestController::setPrinting(const CppArgumentList& arguments, CppVariant* result)
1660 setIsPrinting(true);
1664 void LayoutTestController::pageNumberForElementById(const CppArgumentList& arguments, CppVariant* result)
1667 int pageWidthInPixels = 0;
1668 int pageHeightInPixels = 0;
1669 if (!parsePageSizeParameters(arguments, 1,
1670 &pageWidthInPixels, &pageHeightInPixels))
1672 if (!arguments[0].isString())
1674 WebFrame* frame = m_shell->webView()->mainFrame();
1677 result->set(frame->pageNumberForElementById(cppVariantToWebString(arguments[0]),
1678 static_cast<float>(pageWidthInPixels),
1679 static_cast<float>(pageHeightInPixels)));
1682 void LayoutTestController::pageSizeAndMarginsInPixels(const CppArgumentList& arguments, CppVariant* result)
1689 int marginRight = 0;
1690 int marginBottom = 0;
1692 if (!parsePageNumberSizeMargins(arguments, 0, &pageNumber, &width, &height, &marginTop, &marginRight, &marginBottom,
1696 WebFrame* frame = m_shell->webView()->mainFrame();
1699 WebSize pageSize(width, height);
1700 frame->pageSizeAndMarginsInPixels(pageNumber, pageSize, marginTop, marginRight, marginBottom, marginLeft);
1701 stringstream resultString;
1702 resultString << "(" << pageSize.width << ", " << pageSize.height << ") " << marginTop << " " << marginRight << " "
1703 << marginBottom << " " << marginLeft;
1704 result->set(resultString.str());
1707 void LayoutTestController::isPageBoxVisible(const CppArgumentList& arguments, CppVariant* result)
1711 if (!parsePageNumber(arguments, 0, &pageNumber))
1713 WebFrame* frame = m_shell->webView()->mainFrame();
1716 result->set(frame->isPageBoxVisible(pageNumber));
1719 void LayoutTestController::pageProperty(const CppArgumentList& arguments, CppVariant* result)
1723 if (!parsePageNumber(arguments, 1, &pageNumber))
1725 if (!arguments[0].isString())
1727 WebFrame* frame = m_shell->webView()->mainFrame();
1730 WebSize pageSize(800, 800);
1731 frame->printBegin(pageSize);
1732 result->set(frame->pageProperty(cppVariantToWebString(arguments[0]), pageNumber).utf8());
1736 void LayoutTestController::numberOfPages(const CppArgumentList& arguments, CppVariant* result)
1739 int pageWidthInPixels = 0;
1740 int pageHeightInPixels = 0;
1741 if (!parsePageSizeParameters(arguments, 0, &pageWidthInPixels, &pageHeightInPixels))
1744 WebFrame* frame = m_shell->webView()->mainFrame();
1747 WebSize size(pageWidthInPixels, pageHeightInPixels);
1748 int numberOfPages = frame->printBegin(size);
1750 result->set(numberOfPages);
1753 void LayoutTestController::numberOfPendingGeolocationPermissionRequests(const CppArgumentList& arguments, CppVariant* result)
1756 Vector<WebViewHost*> windowList = m_shell->windowList();
1757 int numberOfRequests = 0;
1758 for (size_t i = 0; i < windowList.size(); i++)
1759 numberOfRequests += windowList[i]->geolocationClientMock()->numberOfPendingPermissionRequests();
1760 result->set(numberOfRequests);
1763 void LayoutTestController::logErrorToConsole(const std::string& text)
1765 m_shell->webViewHost()->didAddMessageToConsole(
1766 WebConsoleMessage(WebConsoleMessage::LevelError, WebString::fromUTF8(text)),
1770 void LayoutTestController::setJavaScriptProfilingEnabled(const CppArgumentList& arguments, CppVariant* result)
1773 if (arguments.size() < 1 || !arguments[0].isBool())
1775 m_shell->drtDevToolsAgent()->setJavaScriptProfilingEnabled(arguments[0].toBoolean());
1778 void LayoutTestController::evaluateInWebInspector(const CppArgumentList& arguments, CppVariant* result)
1781 if (arguments.size() < 2 || !arguments[0].isNumber() || !arguments[1].isString())
1783 m_shell->drtDevToolsAgent()->evaluateInWebInspector(arguments[0].toInt32(), arguments[1].toString());
1786 void LayoutTestController::forceRedSelectionColors(const CppArgumentList& arguments, CppVariant* result)
1789 m_shell->webView()->setSelectionColors(0xffee0000, 0xff00ee00, 0xff000000, 0xffc0c0c0);
1792 void LayoutTestController::addUserScript(const CppArgumentList& arguments, CppVariant* result)
1795 if (arguments.size() < 3 || !arguments[0].isString() || !arguments[1].isBool() || !arguments[2].isBool())
1797 WebView::addUserScript(
1798 cppVariantToWebString(arguments[0]), WebVector<WebString>(),
1799 arguments[1].toBoolean() ? WebView::UserScriptInjectAtDocumentStart : WebView::UserScriptInjectAtDocumentEnd,
1800 arguments[2].toBoolean() ? WebView::UserContentInjectInAllFrames : WebView::UserContentInjectInTopFrameOnly);
1803 void LayoutTestController::addUserStyleSheet(const CppArgumentList& arguments, CppVariant* result)
1806 if (arguments.size() < 2 || !arguments[0].isString() || !arguments[1].isBool())
1808 WebView::addUserStyleSheet(
1809 cppVariantToWebString(arguments[0]), WebVector<WebString>(),
1810 arguments[1].toBoolean() ? WebView::UserContentInjectInAllFrames : WebView::UserContentInjectInTopFrameOnly,
1811 // Chromium defaults to InjectInSubsequentDocuments, but for compatibility
1812 // with the other ports' DRTs, we use UserStyleInjectInExistingDocuments.
1813 WebView::UserStyleInjectInExistingDocuments);
1816 void LayoutTestController::setEditingBehavior(const CppArgumentList& arguments, CppVariant* results)
1818 string key = arguments[0].toString();
1820 m_shell->preferences()->editingBehavior = WebSettings::EditingBehaviorMac;
1821 m_shell->applyPreferences();
1822 } else if (key == "win") {
1823 m_shell->preferences()->editingBehavior = WebSettings::EditingBehaviorWin;
1824 m_shell->applyPreferences();
1825 } else if (key == "unix") {
1826 m_shell->preferences()->editingBehavior = WebSettings::EditingBehaviorUnix;
1827 m_shell->applyPreferences();
1829 logErrorToConsole("Passed invalid editing behavior. Should be 'mac', 'win', or 'unix'.");
1832 void LayoutTestController::setMockDeviceOrientation(const CppArgumentList& arguments, CppVariant* result)
1835 if (arguments.size() < 6 || !arguments[0].isBool() || !arguments[1].isNumber() || !arguments[2].isBool() || !arguments[3].isNumber() || !arguments[4].isBool() || !arguments[5].isNumber())
1838 WebDeviceOrientation orientation(arguments[0].toBoolean(), arguments[1].toDouble(), arguments[2].toBoolean(), arguments[3].toDouble(), arguments[4].toBoolean(), arguments[5].toDouble());
1839 // Note that we only call setOrientation on the main page's mock since this is all that the
1840 // tests require. If necessary, we could get a list of WebViewHosts from the TestShell and
1841 // call setOrientation on each DeviceOrientationClientMock.
1842 m_shell->webViewHost()->deviceOrientationClientMock()->setOrientation(orientation);
1845 // FIXME: For greater test flexibility, we should be able to set each page's geolocation mock individually.
1846 // https://bugs.webkit.org/show_bug.cgi?id=52368
1847 void LayoutTestController::setGeolocationPermission(const CppArgumentList& arguments, CppVariant* result)
1850 if (arguments.size() < 1 || !arguments[0].isBool())
1852 Vector<WebViewHost*> windowList = m_shell->windowList();
1853 for (size_t i = 0; i < windowList.size(); i++)
1854 windowList[i]->geolocationClientMock()->setPermission(arguments[0].toBoolean());
1857 void LayoutTestController::setMockGeolocationPosition(const CppArgumentList& arguments, CppVariant* result)
1860 if (arguments.size() < 3 || !arguments[0].isNumber() || !arguments[1].isNumber() || !arguments[2].isNumber())
1862 Vector<WebViewHost*> windowList = m_shell->windowList();
1863 for (size_t i = 0; i < windowList.size(); i++)
1864 windowList[i]->geolocationClientMock()->setPosition(arguments[0].toDouble(), arguments[1].toDouble(), arguments[2].toDouble());
1867 void LayoutTestController::setMockGeolocationError(const CppArgumentList& arguments, CppVariant* result)
1870 if (arguments.size() < 2 || !arguments[0].isNumber() || !arguments[1].isString())
1872 Vector<WebViewHost*> windowList = m_shell->windowList();
1873 for (size_t i = 0; i < windowList.size(); i++)
1874 windowList[i]->geolocationClientMock()->setError(arguments[0].toInt32(), cppVariantToWebString(arguments[1]));
1877 void LayoutTestController::abortModal(const CppArgumentList& arguments, CppVariant* result)
1882 void LayoutTestController::addMockSpeechInputResult(const CppArgumentList& arguments, CppVariant* result)
1885 if (arguments.size() < 3 || !arguments[0].isString() || !arguments[1].isNumber() || !arguments[2].isString())
1888 if (WebSpeechInputControllerMock* controller = m_shell->webViewHost()->speechInputControllerMock())
1889 controller->addMockRecognitionResult(cppVariantToWebString(arguments[0]), arguments[1].toDouble(), cppVariantToWebString(arguments[2]));
1892 void LayoutTestController::startSpeechInput(const CppArgumentList& arguments, CppVariant* result)
1895 if (arguments.size() != 1)
1899 if (!WebBindings::getElement(arguments[0].value.objectValue, &element))
1902 WebInputElement* input = toWebInputElement(&element);
1906 if (!input->isSpeechInputEnabled())
1909 input->startSpeechInput();
1912 void LayoutTestController::layerTreeAsText(const CppArgumentList& args, CppVariant* result)
1914 result->set(m_shell->webView()->mainFrame()->layerTreeAsText(m_showDebugLayerTree).utf8());
1917 void LayoutTestController::loseCompositorContext(const CppArgumentList& args, CppVariant*)
1920 if (args.size() == 1 || !args[0].isNumber())
1923 numTimes = args[0].toInt32();
1924 m_shell->webView()->loseCompositorContext(numTimes);
1927 void LayoutTestController::markerTextForListItem(const CppArgumentList& args, CppVariant* result)
1930 if (!WebBindings::getElement(args[0].value.objectValue, &element))
1933 result->set(element.document().frame()->markerTextForListItem(element).utf8());
1936 void LayoutTestController::hasSpellingMarker(const CppArgumentList& arguments, CppVariant* result)
1938 if (arguments.size() < 2 || !arguments[0].isNumber() || !arguments[1].isNumber())
1940 result->set(m_shell->webView()->mainFrame()->selectionStartHasSpellingMarkerFor(arguments[0].toInt32(), arguments[1].toInt32()));
1943 void LayoutTestController::setMinimumTimerInterval(const CppArgumentList& arguments, CppVariant* result)
1946 if (arguments.size() < 1 || !arguments[0].isNumber())
1948 m_shell->webView()->settings()->setMinimumTimerInterval(arguments[0].toDouble());
1951 void LayoutTestController::setAutofilled(const CppArgumentList& arguments, CppVariant* result)
1954 if (arguments.size() != 2 || !arguments[1].isBool())
1958 if (!WebBindings::getElement(arguments[0].value.objectValue, &element))
1961 WebInputElement* input = toWebInputElement(&element);
1965 input->setAutofilled(arguments[1].value.boolValue);
1968 void LayoutTestController::setValueForUser(const CppArgumentList& arguments, CppVariant* result)
1971 if (arguments.size() != 2)
1975 if (!WebBindings::getElement(arguments[0].value.objectValue, &element))
1978 WebInputElement* input = toWebInputElement(&element);
1982 input->setValue(cppVariantToWebString(arguments[1]), true);
1985 void LayoutTestController::deleteAllLocalStorage(const CppArgumentList& arguments, CppVariant*)
1990 void LayoutTestController::localStorageDiskUsageForOrigin(const CppArgumentList& arguments, CppVariant*)
1995 void LayoutTestController::originsWithLocalStorage(const CppArgumentList& arguments, CppVariant*)
2000 void LayoutTestController::deleteLocalStorageForOrigin(const CppArgumentList& arguments, CppVariant*)
2005 void LayoutTestController::observeStorageTrackerNotifications(const CppArgumentList&, CppVariant*)
2010 void LayoutTestController::syncLocalStorage(const CppArgumentList&, CppVariant*)
2015 void LayoutTestController::setShouldStayOnPageAfterHandlingBeforeUnload(const CppArgumentList& arguments, CppVariant* result)
2017 if (arguments.size() == 1 && arguments[0].isBool())
2018 m_shouldStayOnPageAfterHandlingBeforeUnload = arguments[0].toBoolean();
2023 void LayoutTestController::enableFixedLayoutMode(const CppArgumentList& arguments, CppVariant* result)
2026 if (arguments.size() < 1 || !arguments[0].isBool())
2028 bool enableFixedLayout = arguments[0].toBoolean();
2029 m_shell->webView()->enableFixedLayoutMode(enableFixedLayout);
2032 void LayoutTestController::setFixedLayoutSize(const CppArgumentList& arguments, CppVariant* result)
2035 if (arguments.size() < 2 || !arguments[0].isNumber() || !arguments[1].isNumber())
2037 int width = arguments[0].toInt32();
2038 int height = arguments[1].toInt32();
2039 m_shell->webView()->setFixedLayoutSize(WebSize(width, height));
2042 void LayoutTestController::setPluginsEnabled(const CppArgumentList& arguments, CppVariant* result)
2044 if (arguments.size() > 0 && arguments[0].isBool()) {
2045 m_shell->preferences()->pluginsEnabled = arguments[0].toBoolean();
2046 m_shell->applyPreferences();
2051 void LayoutTestController::resetPageVisibility(const CppArgumentList& arguments, CppVariant* result)
2053 m_shell->webView()->setVisibilityState(WebPageVisibilityStateVisible, true);
2056 void LayoutTestController::setPageVisibility(const CppArgumentList& arguments, CppVariant* result)
2058 if (arguments.size() > 0 && arguments[0].isString()) {
2059 string newVisibility = arguments[0].toString();
2060 if (newVisibility == "visible")
2061 m_shell->webView()->setVisibilityState(WebPageVisibilityStateVisible, false);
2062 else if (newVisibility == "hidden")
2063 m_shell->webView()->setVisibilityState(WebPageVisibilityStateHidden, false);
2064 else if (newVisibility == "prerender")
2065 m_shell->webView()->setVisibilityState(WebPageVisibilityStatePrerender, false);
2069 void LayoutTestController::setTextDirection(const CppArgumentList& arguments, CppVariant* result)
2072 if (arguments.size() != 1 || !arguments[0].isString())
2075 // Map a direction name to a WebTextDirection value.
2076 std::string directionName = arguments[0].toString();
2077 WebKit::WebTextDirection direction;
2078 if (directionName == "auto")
2079 direction = WebKit::WebTextDirectionDefault;
2080 else if (directionName == "rtl")
2081 direction = WebKit::WebTextDirectionRightToLeft;
2082 else if (directionName == "ltr")
2083 direction = WebKit::WebTextDirectionLeftToRight;
2087 m_shell->webView()->setTextDirection(direction);
2090 void LayoutTestController::setAudioData(const CppArgumentList& arguments, CppVariant* result)
2094 if (arguments.size() < 1 || !arguments[0].isObject())
2097 // Check that passed-in object is, in fact, an ArrayBufferView.
2098 NPObject* npobject = NPVARIANT_TO_OBJECT(arguments[0]);
2101 if (!WebBindings::getArrayBufferView(npobject, &m_audioData))
2104 setShouldDumpAsAudio(true);