2010-05-19 Marcus Bulach <bulach@chromium.org>
Reviewed by Steve Block.
[chromium] Adds supports for layout tests using GeolocationServiceMock.
https://bugs.webkit.org/show_bug.cgi?id=39081
Allows injection of GeolocationServiceMock factory.
Tests: existing fast/dom/Geolocation/*
* platform/GeolocationService.cpp:
(WebCore::GeolocationService::useMock):
(WebCore::GeolocationService::useMockFactory):
* platform/GeolocationService.h:
* platform/chromium/GeolocationServiceChromium.cpp:
(WebCore::GeolocationServiceChromium::GeolocationServiceChromium):
2010-05-19 Marcus Bulach <bulach@chromium.org>
Reviewed by Steve Block.
[chromium] Adds supports for layout tests using GeolocationServiceMock.
https://bugs.webkit.org/show_bug.cgi?id=39081
Allows injection of GeolocationServiceMock factory.
Tests: existing fast/dom/Geolocation/*
* WebKit.gyp:
* public/WebGeolocationServiceMock.h: Added.
* src/WebGeolocationServiceMock.cpp: Added.
(WebCore::GeolocationServiceChromiumMock::create):
(WebCore::GeolocationServiceChromiumMock::GeolocationServiceChromiumMock):
(WebCore::GeolocationServiceChromiumMock::startUpdating):
(WebCore::GeolocationServiceChromiumMock::stopUpdating):
(WebCore::GeolocationServiceChromiumMock::lastPosition):
(WebCore::GeolocationServiceChromiumMock::lastError):
(WebCore::GeolocationServiceChromiumMock::geolocationServicePositionChanged):
(WebCore::GeolocationServiceChromiumMock::geolocationServiceErrorOccurred):
(WebKit::WebGeolocationServiceMock::setMockGeolocationPosition):
(WebKit::WebGeolocationServiceMock::setMockGeolocationError):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@59772 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 07a7ae0..2b2573e 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,21 @@
+2010-05-19 Marcus Bulach <bulach@chromium.org>
+
+ Reviewed by Steve Block.
+
+ [chromium] Adds supports for layout tests using GeolocationServiceMock.
+ https://bugs.webkit.org/show_bug.cgi?id=39081
+
+ Allows injection of GeolocationServiceMock factory.
+
+ Tests: existing fast/dom/Geolocation/*
+
+ * platform/GeolocationService.cpp:
+ (WebCore::GeolocationService::useMock):
+ (WebCore::GeolocationService::useMockFactory):
+ * platform/GeolocationService.h:
+ * platform/chromium/GeolocationServiceChromium.cpp:
+ (WebCore::GeolocationServiceChromium::GeolocationServiceChromium):
+
2010-05-19 Justin Schuh <jschuh@chromium.org>
Reviewed by Adam Barth.
diff --git a/WebCore/platform/GeolocationService.cpp b/WebCore/platform/GeolocationService.cpp
index 4676006..e2ce5e5 100644
--- a/WebCore/platform/GeolocationService.cpp
+++ b/WebCore/platform/GeolocationService.cpp
@@ -44,6 +44,8 @@
GeolocationService::FactoryFunction* GeolocationService::s_factoryFunction = &createGeolocationServiceNull;
#endif
+GeolocationService::FactoryFunction* GeolocationService::s_mockFactoryFunction = &GeolocationServiceMock::create;
+
GeolocationService* GeolocationService::create(GeolocationServiceClient* client)
{
return (*s_factoryFunction)(client);
@@ -52,7 +54,12 @@
#if ENABLE(GEOLOCATION)
void GeolocationService::useMock()
{
- s_factoryFunction = &GeolocationServiceMock::create;
+ s_factoryFunction = s_mockFactoryFunction;
+}
+
+void GeolocationService::setCustomMockFactory(FactoryFunction f)
+{
+ s_mockFactoryFunction = f;
}
GeolocationService::GeolocationService(GeolocationServiceClient* client)
diff --git a/WebCore/platform/GeolocationService.h b/WebCore/platform/GeolocationService.h
index 4390496..1585f65 100644
--- a/WebCore/platform/GeolocationService.h
+++ b/WebCore/platform/GeolocationService.h
@@ -60,6 +60,8 @@
void errorOccurred();
static void useMock();
+ typedef GeolocationService* (FactoryFunction)(GeolocationServiceClient*);
+ static void setCustomMockFactory(FactoryFunction);
protected:
GeolocationService(GeolocationServiceClient*);
@@ -68,8 +70,8 @@
private:
GeolocationServiceClient* m_geolocationServiceClient;
- typedef GeolocationService* (FactoryFunction)(GeolocationServiceClient*);
static FactoryFunction* s_factoryFunction;
+ static FactoryFunction* s_mockFactoryFunction;
};
} // namespace WebCore
diff --git a/WebCore/platform/chromium/GeolocationServiceChromium.cpp b/WebCore/platform/chromium/GeolocationServiceChromium.cpp
index 4402fe4..9333999 100644
--- a/WebCore/platform/chromium/GeolocationServiceChromium.cpp
+++ b/WebCore/platform/chromium/GeolocationServiceChromium.cpp
@@ -37,7 +37,7 @@
GeolocationServiceChromium::GeolocationServiceChromium(GeolocationServiceClient* c)
: GeolocationService(c),
- m_geolocation(reinterpret_cast<Geolocation*>(c)),
+ m_geolocation(static_cast<Geolocation*>(c)),
m_geolocationServiceBridge(ChromiumBridge::createGeolocationServiceBridge(this)),
m_lastError(PositionError::create(PositionError::POSITION_UNAVAILABLE, ""))
{
diff --git a/WebKit/chromium/ChangeLog b/WebKit/chromium/ChangeLog
index a433938..dac3b2f 100644
--- a/WebKit/chromium/ChangeLog
+++ b/WebKit/chromium/ChangeLog
@@ -1,3 +1,27 @@
+2010-05-19 Marcus Bulach <bulach@chromium.org>
+
+ Reviewed by Steve Block.
+
+ [chromium] Adds supports for layout tests using GeolocationServiceMock.
+ https://bugs.webkit.org/show_bug.cgi?id=39081
+
+ Allows injection of GeolocationServiceMock factory.
+ Tests: existing fast/dom/Geolocation/*
+
+ * WebKit.gyp:
+ * public/WebGeolocationServiceMock.h: Added.
+ * src/WebGeolocationServiceMock.cpp: Added.
+ (WebCore::GeolocationServiceChromiumMock::create):
+ (WebCore::GeolocationServiceChromiumMock::GeolocationServiceChromiumMock):
+ (WebCore::GeolocationServiceChromiumMock::startUpdating):
+ (WebCore::GeolocationServiceChromiumMock::stopUpdating):
+ (WebCore::GeolocationServiceChromiumMock::lastPosition):
+ (WebCore::GeolocationServiceChromiumMock::lastError):
+ (WebCore::GeolocationServiceChromiumMock::geolocationServicePositionChanged):
+ (WebCore::GeolocationServiceChromiumMock::geolocationServiceErrorOccurred):
+ (WebKit::WebGeolocationServiceMock::setMockGeolocationPosition):
+ (WebKit::WebGeolocationServiceMock::setMockGeolocationError):
+
2010-05-17 Jeremy Orlow <jorlow@chromium.org>
Reviewed by Darin Fisher.
diff --git a/WebKit/chromium/WebKit.gyp b/WebKit/chromium/WebKit.gyp
index 01e3a39..24748f8 100644
--- a/WebKit/chromium/WebKit.gyp
+++ b/WebKit/chromium/WebKit.gyp
@@ -126,6 +126,7 @@
'public/WebFormElement.h',
'public/WebGeolocationService.h',
'public/WebGeolocationServiceBridge.h',
+ 'public/WebGeolocationServiceMock.h',
'public/WebGlyphCache.h',
'public/WebGLES2Context.h',
'public/WebGraphicsContext3D.h',
@@ -337,6 +338,7 @@
'src/WebFrameImpl.h',
'src/WebGeolocationServiceBridgeImpl.cpp',
'src/WebGeolocationServiceBridgeImpl.h',
+ 'src/WebGeolocationServiceMock.cpp',
'src/WebGlyphCache.cpp',
'src/WebGraphicsContext3D.cpp',
'src/WebGraphicsContext3DDefaultImpl.cpp',
diff --git a/WebKit/chromium/public/WebGeolocationServiceMock.h b/WebKit/chromium/public/WebGeolocationServiceMock.h
new file mode 100644
index 0000000..5f9bc56
--- /dev/null
+++ b/WebKit/chromium/public/WebGeolocationServiceMock.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2010, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebGeolocationServiceMock_h
+#define WebGeolocationServiceMock_h
+
+namespace WebKit {
+
+class WebString;
+
+class WebGeolocationServiceMock {
+public:
+ static void setMockGeolocationPosition(double latitude, double longitude, double accuracy);
+ static void setMockGeolocationError(int errorCode, const WebString& message);
+};
+
+} // namespace WebKit
+
+#endif // WebGeolocationServiceMock_h
diff --git a/WebKit/chromium/src/WebGeolocationServiceMock.cpp b/WebKit/chromium/src/WebGeolocationServiceMock.cpp
new file mode 100644
index 0000000..fef74e6
--- /dev/null
+++ b/WebKit/chromium/src/WebGeolocationServiceMock.cpp
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebGeolocationServiceMock.h"
+
+#include "GeolocationService.h"
+#include "GeolocationServiceChromium.h"
+#include "GeolocationServiceMock.h"
+#include "WebString.h"
+#include <wtf/CurrentTime.h>
+
+#if ENABLE(GEOLOCATION)
+
+using WebCore::Coordinates;
+using WebCore::Frame;
+using WebCore::Geolocation;
+using WebCore::GeolocationServiceBridge;
+using WebCore::GeolocationServiceChromium;
+using WebCore::GeolocationServiceClient;
+using WebCore::GeolocationServiceMock;
+using WebCore::Geoposition;
+using WebCore::PositionError;
+using WebCore::PositionOptions;
+using WebCore::String;
+
+namespace WebCore {
+class GeolocationServiceChromiumMock : public GeolocationServiceChromium, public GeolocationServiceClient {
+public:
+ static GeolocationService* create(GeolocationServiceClient*);
+ virtual bool startUpdating(PositionOptions*);
+ virtual void stopUpdating();
+ virtual Geoposition* lastPosition() const;
+ virtual PositionError* lastError() const;
+
+ virtual void geolocationServicePositionChanged(GeolocationService*);
+ virtual void geolocationServiceErrorOccurred(GeolocationService*);
+
+private:
+ explicit GeolocationServiceChromiumMock(GeolocationServiceClient*);
+
+ GeolocationServiceClient* m_geolocationServiceClient;
+ OwnPtr<GeolocationService> m_geolocationServiceMock;
+};
+
+GeolocationService* GeolocationServiceChromiumMock::create(GeolocationServiceClient* geolocationServiceClient)
+{
+ return new GeolocationServiceChromiumMock(geolocationServiceClient);
+}
+
+GeolocationServiceChromiumMock::GeolocationServiceChromiumMock(GeolocationServiceClient* geolocationServiceClient)
+ : GeolocationServiceChromium(geolocationServiceClient),
+ m_geolocationServiceClient(geolocationServiceClient)
+{
+ m_geolocationServiceMock.set(GeolocationServiceMock::create(this));
+}
+
+bool GeolocationServiceChromiumMock::startUpdating(PositionOptions* positionOptions)
+{
+ GeolocationServiceChromium::startUpdating(positionOptions);
+ return m_geolocationServiceMock->startUpdating(positionOptions);
+}
+
+void GeolocationServiceChromiumMock::stopUpdating()
+{
+ GeolocationServiceChromium::stopUpdating();
+ m_geolocationServiceMock->stopUpdating();
+}
+
+Geoposition* GeolocationServiceChromiumMock::lastPosition() const
+{
+ return m_geolocationServiceMock->lastPosition();
+}
+
+PositionError* GeolocationServiceChromiumMock::lastError() const
+{
+ return m_geolocationServiceMock->lastError();
+}
+
+void GeolocationServiceChromiumMock::geolocationServicePositionChanged(GeolocationService* geolocationService)
+{
+ ASSERT_UNUSED(geolocationService, geolocationService == m_geolocationServiceMock);
+ m_geolocationServiceClient->geolocationServicePositionChanged(this);
+
+}
+
+void GeolocationServiceChromiumMock::geolocationServiceErrorOccurred(GeolocationService* geolocationService)
+{
+ ASSERT_UNUSED(geolocationService, geolocationService == m_geolocationServiceMock);
+ m_geolocationServiceClient->geolocationServiceErrorOccurred(this);
+}
+
+} // namespace WebCore
+
+namespace WebKit {
+
+void WebGeolocationServiceMock::setMockGeolocationPosition(double latitude, double longitude, double accuracy)
+{
+ WebCore::GeolocationService::setCustomMockFactory(&WebCore::GeolocationServiceChromiumMock::create);
+ RefPtr<Geoposition> geoposition = Geoposition::create(Coordinates::create(latitude, longitude, false, 0, accuracy, true, 0, false, 0, false, 0), currentTime() * 1000.0);
+ GeolocationServiceMock::setPosition(geoposition);
+}
+
+void WebGeolocationServiceMock::setMockGeolocationError(int errorCode, const WebString& message)
+{
+ WebCore::GeolocationService::setCustomMockFactory(&WebCore::GeolocationServiceChromiumMock::create);
+ RefPtr<PositionError> positionError = PositionError::create(static_cast<PositionError::ErrorCode>(errorCode), message);
+ GeolocationServiceMock::setError(positionError);
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(GEOLOCATION)