From dbdd2da378a2c3d2baf2524694cb6e25419f8818 Mon Sep 17 00:00:00 2001 From: Steve Block Date: Fri, 18 May 2012 17:58:24 +0100 Subject: Hook up client-based Geolocation mock This simply involves updating GeolocationMock, which is called by DRT from Java, to call the GeolocationClientMock via GeolocationManager, rather than the old GeolocationServiceMock. Note that GeolocationClientMock is tied to a specific page, whereas GeolocationServiceMock had static methods, so we need to pass the WebViewCore from Java. We can now safely exclude the non-client-based files from the build. We pass all Geolocation LayoutTests, except for permission-denied-already-[error|success].html, which are flaky due to https://bugs.webkit.org/show_bug.cgi?id=87033. See corresponding framework change I6d88d5dce5c2148812b191a5b452718bf0854aeb. Bug: 6511338 Change-Id: Ib74a3c05991593e75c3138415d4ac0bf0c9aefa9 --- Source/WebCore/Android.mk | 2 - .../android/WebCoreSupport/GeolocationManager.cpp | 43 +++++++++++++- .../android/WebCoreSupport/GeolocationManager.h | 11 +++- Source/WebKit/android/jni/MockGeolocation.cpp | 67 +++++++++++++--------- 4 files changed, 91 insertions(+), 32 deletions(-) diff --git a/Source/WebCore/Android.mk b/Source/WebCore/Android.mk index 6457835..f4f9bca 100644 --- a/Source/WebCore/Android.mk +++ b/Source/WebCore/Android.mk @@ -546,7 +546,6 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \ platform/FileChooser.cpp \ platform/FileStream.cpp \ platform/FileSystem.cpp \ - platform/GeolocationService.cpp \ platform/KURL.cpp \ platform/KURLGoogle.cpp \ platform/KillRingNone.cpp \ @@ -756,7 +755,6 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \ \ platform/mock/DeviceOrientationClientMock.cpp \ platform/mock/GeolocationClientMock.cpp \ - platform/mock/GeolocationServiceMock.cpp \ platform/mock/SpeechInputClientMock.cpp \ \ platform/network/AuthenticationChallengeBase.cpp \ diff --git a/Source/WebKit/android/WebCoreSupport/GeolocationManager.cpp b/Source/WebKit/android/WebCoreSupport/GeolocationManager.cpp index 8d0d6b5..cbf399d 100644 --- a/Source/WebKit/android/WebCoreSupport/GeolocationManager.cpp +++ b/Source/WebKit/android/WebCoreSupport/GeolocationManager.cpp @@ -29,22 +29,27 @@ #include "GeolocationClientImpl.h" #include "WebViewCore.h" +#include #include #include #include +#include using WebCore::GeolocationClient; +using WebCore::GeolocationClientMock; namespace android { GeolocationManager::GeolocationManager(WebViewCore* webViewCore) - : m_webViewCore(webViewCore) + : m_useMock(false) + , m_webViewCore(webViewCore) { } GeolocationClient* GeolocationManager::client() const { - // TODO: Return the mock client when appropriate. See http://b/6511338. + if (m_useMock) + return mockClient(); return realClient(); } @@ -76,6 +81,30 @@ void GeolocationManager::provideRealClientPermissionState(WTF::String origin, bo m_realClient->providePermissionState(origin, allow, remember); } +void GeolocationManager::setUseMock() +{ + m_useMock = true; + m_mockClient.clear(); +} + +void GeolocationManager::setMockPosition(PassRefPtr position) +{ + ASSERT(m_useMock); + mockClient()->setPosition(position); +} + +void GeolocationManager::setMockError(PassRefPtr error) +{ + ASSERT(m_useMock); + mockClient()->setError(error); +} + +void GeolocationManager::setMockPermission(bool allowed) +{ + ASSERT(m_useMock); + mockClient()->setPermission(allowed); +} + GeolocationClientImpl* GeolocationManager::realClient() const { if (!m_realClient) @@ -83,4 +112,14 @@ GeolocationClientImpl* GeolocationManager::realClient() const return m_realClient.get(); } +GeolocationClientMock* GeolocationManager::mockClient() const +{ + ASSERT(m_useMock); + if (!m_mockClient) { + m_mockClient.set(new GeolocationClientMock); + m_mockClient->setController(m_webViewCore->mainFrame()->page()->geolocationController()); + } + return m_mockClient.get(); +} + } // namespace android diff --git a/Source/WebKit/android/WebCoreSupport/GeolocationManager.h b/Source/WebKit/android/WebCoreSupport/GeolocationManager.h index 707cf6f..6459db1 100644 --- a/Source/WebKit/android/WebCoreSupport/GeolocationManager.h +++ b/Source/WebKit/android/WebCoreSupport/GeolocationManager.h @@ -28,6 +28,7 @@ #include "GeolocationClientImpl.h" +#include #include #include @@ -45,7 +46,6 @@ class WebViewCore; // may be either the real implementation or a mock. It also handles setting the // data on the mock client. This class is owned by WebViewCore and exists to // keep cruft out of that class. -// TODO: Add support for mock. See b/6511338. class GeolocationManager { public: GeolocationManager(WebViewCore*); @@ -59,11 +59,20 @@ public: void resetRealClientTemporaryPermissionStates(); void provideRealClientPermissionState(WTF::String origin, bool allow, bool remember); + // Sets use of the Geolocation mock client. Also resets that client. + void setUseMock(); + void setMockPosition(PassRefPtr); + void setMockError(PassRefPtr); + void setMockPermission(bool allowed); + private: GeolocationClientImpl* realClient() const; + WebCore::GeolocationClientMock* mockClient() const; + bool m_useMock; WebViewCore* m_webViewCore; mutable OwnPtr m_realClient; + mutable OwnPtr m_mockClient; }; } // namespace android diff --git a/Source/WebKit/android/jni/MockGeolocation.cpp b/Source/WebKit/android/jni/MockGeolocation.cpp index 250953f..164c37d 100755 --- a/Source/WebKit/android/jni/MockGeolocation.cpp +++ b/Source/WebKit/android/jni/MockGeolocation.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2009, The Android Open Source Project + * Copyright 2012, The Android Open Source Project * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -23,19 +23,16 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -// The functions in this file are used to configure the mock GeolocationService +// The functions in this file are used to configure the mock Geolocation client // for the LayoutTests. #include "config.h" -#include "Coordinates.h" -#include "GeolocationServiceMock.h" -#include "Geoposition.h" -#include "JavaSharedClient.h" -#include "PositionError.h" -#include "WebCoreJni.h" -#include -#include +#include "WebViewCore.h" + +#include +#include +#include "ScopedLocalRef.h" #include using namespace WebCore; @@ -44,30 +41,46 @@ namespace android { static const char* javaMockGeolocationClass = "android/webkit/MockGeolocation"; -static void setPosition(JNIEnv* env, jobject, double latitude, double longitude, double accuracy) +WebViewCore* getWebViewCore(JNIEnv* env, jobject webViewCore) +{ + ScopedLocalRef webViewCoreClass(env, env->FindClass("android/webkit/WebViewCore")); + jfieldID nativeClassField = env->GetFieldID(webViewCoreClass.get(), "mNativeClass", "I"); + return reinterpret_cast(env->GetIntField(webViewCore, nativeClassField)); +} + +static void setUseMock(JNIEnv* env, jobject, jobject webViewCore) +{ + getWebViewCore(env, webViewCore)->geolocationManager()->setUseMock(); +} + +static void setPosition(JNIEnv* env, jobject, jobject webViewCore, double latitude, double longitude, double accuracy) +{ + getWebViewCore(env, webViewCore)->geolocationManager()->setMockPosition(GeolocationPosition::create(WTF::currentTime(), + latitude, + longitude, + accuracy, + false, 0.0, // altitude, + false, 0.0, // altitudeAccuracy, + false, 0.0, // heading + false, 0.0)); // speed +} + +static void setError(JNIEnv* env, jobject, jobject webViewCore, int code, jstring message) { - RefPtr coordinates = Coordinates::create(latitude, - longitude, - false, 0.0, // altitude, - accuracy, - false, 0.0, // altitudeAccuracy, - false, 0.0, // heading - false, 0.0); // speed - RefPtr position = Geoposition::create(coordinates.release(), WTF::currentTimeMS()); - GeolocationServiceMock::setPosition(position.release()); + GeolocationError::ErrorCode codeEnum = static_cast(code); + getWebViewCore(env, webViewCore)->geolocationManager()->setMockError(GeolocationError::create(codeEnum, jstringToWtfString(env, message))); } -static void setError(JNIEnv* env, jobject, int code, jstring message) +static void setPermission(JNIEnv* env, jobject, jobject webViewCore, bool allow) { - PositionError::ErrorCode codeEnum = static_cast(code); - String messageString = jstringToWtfString(env, message); - RefPtr error = PositionError::create(codeEnum, messageString); - GeolocationServiceMock::setError(error.release()); + getWebViewCore(env, webViewCore)->geolocationManager()->setMockPermission(allow); } static JNINativeMethod gMockGeolocationMethods[] = { - { "nativeSetPosition", "(DDD)V", (void*) setPosition }, - { "nativeSetError", "(ILjava/lang/String;)V", (void*) setError } + { "nativeSetUseMock", "(Landroid/webkit/WebViewCore;)V", (void*) setUseMock }, + { "nativeSetPosition", "(Landroid/webkit/WebViewCore;DDD)V", (void*) setPosition }, + { "nativeSetError", "(Landroid/webkit/WebViewCore;ILjava/lang/String;)V", (void*) setError }, + { "nativeSetPermission", "(Landroid/webkit/WebViewCore;Z)V", (void*) setPermission }, }; int registerMockGeolocation(JNIEnv* env) -- cgit v1.1