[BlackBerry] DumpRenderTreeSupport: update the set position methods
[WebKit-https.git] / Source / WebKit / blackberry / WebKitSupport / DumpRenderTreeSupport.cpp
1 /*
2  * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
3  * Copyright (C) 2012 Apple Inc. All Rights Reserved.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19
20 #include "config.h"
21 #include "DumpRenderTreeSupport.h"
22
23 #include "CSSComputedStyleDeclaration.h"
24 #include "DeviceOrientationClientMock.h"
25 #include "DeviceOrientationController.h"
26 #include "DeviceOrientationData.h"
27 #include "Frame.h"
28 #include "GeolocationClientMock.h"
29 #include "GeolocationController.h"
30 #include "GeolocationError.h"
31 #include "GeolocationPosition.h"
32 #include "JSCSSStyleDeclaration.h"
33 #include "JSElement.h"
34 #include "Page.h"
35 #include "WebPage_p.h"
36 #include "bindings/js/GCController.h"
37 #include <JavaScriptCore/APICast.h>
38 #include <wtf/CurrentTime.h>
39
40 using namespace BlackBerry::WebKit;
41 using namespace WebCore;
42 using namespace JSC;
43
44 bool DumpRenderTreeSupport::s_linksIncludedInTabChain = true;
45
46 GeolocationClientMock* toGeolocationClientMock(GeolocationClient* client)
47 {
48     ASSERT(isRunningDrt());
49     return static_cast<GeolocationClientMock*>(client);
50 }
51
52 DumpRenderTreeSupport::DumpRenderTreeSupport()
53 {
54 }
55
56 DumpRenderTreeSupport::~DumpRenderTreeSupport()
57 {
58 }
59
60 Page* DumpRenderTreeSupport::corePage(WebPage* webPage)
61 {
62     return WebPagePrivate::core(webPage);
63 }
64
65 int DumpRenderTreeSupport::javaScriptObjectsCount()
66 {
67     return JSDOMWindowBase::commonJSGlobalData()->heap.globalObjectCount();
68 }
69
70 void DumpRenderTreeSupport::garbageCollectorCollect()
71 {
72     gcController().garbageCollectNow();
73 }
74
75 void DumpRenderTreeSupport::garbageCollectorCollectOnAlternateThread(bool waitUntilDone)
76 {
77     gcController().garbageCollectOnAlternateThreadForDebugging(waitUntilDone);
78 }
79
80 void DumpRenderTreeSupport::setLinksIncludedInFocusChain(bool enabled)
81 {
82     s_linksIncludedInTabChain = enabled;
83 }
84
85 bool DumpRenderTreeSupport::linksIncludedInFocusChain()
86 {
87     return s_linksIncludedInTabChain;
88 }
89
90 int DumpRenderTreeSupport::numberOfPendingGeolocationPermissionRequests(WebPage* webPage)
91 {
92     GeolocationClientMock* mockClient = toGeolocationClientMock(GeolocationController::from(corePage(webPage))->client());
93     return mockClient->numberOfPendingPermissionRequests();
94 }
95
96 void DumpRenderTreeSupport::resetGeolocationMock(WebPage* webPage)
97 {
98     GeolocationClientMock* mockClient = toGeolocationClientMock(GeolocationController::from(corePage(webPage))->client());
99     mockClient->reset();
100 }
101
102 void DumpRenderTreeSupport::setMockGeolocationPositionUnavailableError(WebPage* webPage, const String message)
103 {
104     GeolocationClientMock* mockClient = static_cast<GeolocationClientMock*>(GeolocationController::from(corePage(webPage))->client());
105     mockClient->setPositionUnavailableError(message);
106 }
107
108 void DumpRenderTreeSupport::setMockGeolocationPermission(WebPage* webPage, bool allowed)
109 {
110     GeolocationClientMock* mockClient = toGeolocationClientMock(GeolocationController::from(corePage(webPage))->client());
111     mockClient->setPermission(allowed);
112 }
113
114 void DumpRenderTreeSupport::setMockGeolocationPosition(WebPage* webPage, double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed)
115 {
116     GeolocationClientMock* mockClient = toGeolocationClientMock(GeolocationController::from(corePage(webPage))->client());
117     mockClient->setPosition(GeolocationPosition::create(currentTime(), latitude, longitude, accuracy, providesAltitude, altitude, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed));
118 }
119
120 void DumpRenderTreeSupport::scalePageBy(WebPage* webPage, float scaleFactor, float x, float y)
121 {
122     corePage(webPage)->setPageScaleFactor(scaleFactor, IntPoint(x, y));
123 }
124
125 JSValueRef DumpRenderTreeSupport::computedStyleIncludingVisitedInfo(JSContextRef context, JSValueRef value)
126 {
127     ExecState* exec = toJS(context);
128     JSLockHolder lock(exec);
129     if (!value)
130         return JSValueMakeUndefined(context);
131     JSValue jsValue = toJS(exec, value);
132     if (!jsValue.inherits(&JSElement::s_info))
133         return JSValueMakeUndefined(context);
134     JSElement* jsElement = static_cast<JSElement*>(asObject(jsValue));
135     Element* element = jsElement->impl();
136     RefPtr<CSSComputedStyleDeclaration> style = CSSComputedStyleDeclaration::create(element, true);
137     return toRef(exec, toJS(exec, jsElement->globalObject(), style.get()));
138 }
139
140 #if ENABLE(DEVICE_ORIENTATION)
141 DeviceOrientationClientMock* toDeviceOrientationClientMock(DeviceOrientationClient* client)
142 {
143     return static_cast<DeviceOrientationClientMock*>(client);
144 }
145 #endif
146
147 void DumpRenderTreeSupport::setMockDeviceOrientation(BlackBerry::WebKit::WebPage* webPage, bool canProvideAlpha, double alpha, bool canProvideBeta, double beta, bool canProvideGamma, double gamma)
148 {
149 #if ENABLE(DEVICE_ORIENTATION)
150     Page* page = corePage(webPage);
151     DeviceOrientationClientMock* mockClient = toDeviceOrientationClientMock(DeviceOrientationController::from(page)->client());
152     mockClient->setOrientation(DeviceOrientationData::create(canProvideAlpha, alpha, canProvideBeta, beta, canProvideGamma, gamma));
153 #endif
154 }