diff options
author | bulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-26 09:21:28 +0000 |
---|---|---|
committer | bulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-26 09:21:28 +0000 |
commit | 596d43bc788a3cea4f86a485691236265fe775e3 (patch) | |
tree | 1c2186f12c54b67d33d610ee96c2f4f37128d54e /webkit | |
parent | fb2774c6110e4de7c1d04175edb9b0ee23ba5cec (diff) | |
download | chromium_src-596d43bc788a3cea4f86a485691236265fe775e3.zip chromium_src-596d43bc788a3cea4f86a485691236265fe775e3.tar.gz chromium_src-596d43bc788a3cea4f86a485691236265fe775e3.tar.bz2 |
Adds Geolocation support for TestShell.
This is the evil twin of DRT:
https://bugs.webkit.org/show_bug.cgi?id=39440
(depends on https://bugs.webkit.org/show_bug.cgi?id=39081).
TEST=existing layout tests fast/dom/Geolocation/*
BUG=36451
Review URL: http://codereview.chromium.org/2094003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48260 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/tools/test_shell/layout_test_controller.cc | 30 | ||||
-rw-r--r-- | webkit/tools/test_shell/layout_test_controller.h | 8 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_geolocation_service.cc | 46 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_geolocation_service.h | 61 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell.gypi | 2 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_webkit_init.h | 6 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_webview_delegate.cc | 15 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_webview_delegate.h | 9 |
8 files changed, 174 insertions, 3 deletions
diff --git a/webkit/tools/test_shell/layout_test_controller.cc b/webkit/tools/test_shell/layout_test_controller.cc index 085af08..62f7414 100644 --- a/webkit/tools/test_shell/layout_test_controller.cc +++ b/webkit/tools/test_shell/layout_test_controller.cc @@ -16,6 +16,7 @@ #include "base/utf_string_conversions.h" #include "third_party/WebKit/WebKit/chromium/public/WebConsoleMessage.h" #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" +#include "third_party/WebKit/WebKit/chromium/public/WebGeolocationServiceMock.h" #include "third_party/WebKit/WebKit/chromium/public/WebKit.h" #include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h" #include "third_party/WebKit/WebKit/chromium/public/WebSecurityPolicy.h" @@ -170,6 +171,10 @@ LayoutTestController::LayoutTestController(TestShell* shell) : BindMethod("evaluateInWebInspector", &LayoutTestController::evaluateInWebInspector); BindMethod("forceRedSelectionColors", &LayoutTestController::forceRedSelectionColors); + BindMethod("setGeolocationPermission", &LayoutTestController::setGeolocationPermission); + BindMethod("setMockGeolocationPosition", &LayoutTestController::setMockGeolocationPosition); + BindMethod("setMockGeolocationError", &LayoutTestController::setMockGeolocationError); + // The fallback method is called when an unknown method is invoked. BindFallbackMethod(&LayoutTestController::fallbackMethod); @@ -1285,3 +1290,28 @@ void LayoutTestController::addUserStyleSheet(const CppArgumentList& args, return; shell_->webView()->addUserStyleSheet(WebString::fromUTF8(args[0].ToString())); } + +void LayoutTestController::setGeolocationPermission(const CppArgumentList& args, + CppVariant* result) { + if (args.size() < 1 || !args[0].isBool()) + return; + shell_->delegate()->SetGeolocationPermission(args[0].ToBoolean()); +} + +void LayoutTestController::setMockGeolocationPosition( + const CppArgumentList& args, CppVariant* result) { + if (args.size() < 3 || + !args[0].isNumber() || !args[1].isNumber() || !args[2].isNumber()) + return; + WebKit::WebGeolocationServiceMock::setMockGeolocationPosition( + args[0].ToDouble(), args[1].ToDouble(), args[2].ToDouble()); +} + +void LayoutTestController::setMockGeolocationError(const CppArgumentList& args, + CppVariant* result) { + if (args.size() < 2 || + !args[0].isInt32() || !args[1].isString()) + return; + WebKit::WebGeolocationServiceMock::setMockGeolocationError( + args[0].ToInt32(), WebString::fromUTF8(args[1].ToString())); +} diff --git a/webkit/tools/test_shell/layout_test_controller.h b/webkit/tools/test_shell/layout_test_controller.h index 4c614ab..5a6c42f 100644 --- a/webkit/tools/test_shell/layout_test_controller.h +++ b/webkit/tools/test_shell/layout_test_controller.h @@ -268,6 +268,14 @@ class LayoutTestController : public CppBoundClass { void addUserScript(const CppArgumentList& args, CppVariant* result); void addUserStyleSheet(const CppArgumentList& args, CppVariant* result); + // Geolocation related functions. + void setGeolocationPermission(const CppArgumentList& args, + CppVariant* result); + void setMockGeolocationPosition(const CppArgumentList& args, + CppVariant* result); + void setMockGeolocationError(const CppArgumentList& args, + CppVariant* result); + public: // The following methods are not exposed to JavaScript. void SetWorkQueueFrozen(bool frozen) { work_queue_.set_frozen(frozen); } diff --git a/webkit/tools/test_shell/test_geolocation_service.cc b/webkit/tools/test_shell/test_geolocation_service.cc new file mode 100644 index 0000000..50fe369 --- /dev/null +++ b/webkit/tools/test_shell/test_geolocation_service.cc @@ -0,0 +1,46 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/tools/test_shell/test_geolocation_service.h" + +#include "third_party/WebKit/WebKit/chromium/public/WebGeolocationServiceBridge.h" + +TestGeolocationService::TestGeolocationService() + : allowed_(false) { +} + +TestGeolocationService::~TestGeolocationService() { + +} + +void TestGeolocationService::SetGeolocationPermission(bool allowed) { + allowed_ = allowed; +} + +void TestGeolocationService::requestPermissionForFrame( + int bridgeId, const WebKit::WebURL& url) { + pending_permissions_.push_back(std::make_pair(bridgeId, allowed_)); + permission_timer_.Start(base::TimeDelta::FromMilliseconds(0), + this, &TestGeolocationService::SendPermission); +} + +int TestGeolocationService::attachBridge( + WebKit::WebGeolocationServiceBridge* bridge) { + return bridges_map_.Add(bridge); +} + +void TestGeolocationService::detachBridge(int bridgeId) { + bridges_map_.Remove(bridgeId); +} + +void TestGeolocationService::SendPermission() { + for (std::vector<std::pair<int, bool> >::const_iterator i = + pending_permissions_.begin(); i != pending_permissions_.end(); ++i) { + WebKit::WebGeolocationServiceBridge* bridge = + bridges_map_.Lookup(i->first); + DCHECK(bridge); + bridge->setIsAllowed(i->second); + } + pending_permissions_.clear(); +} diff --git a/webkit/tools/test_shell/test_geolocation_service.h b/webkit/tools/test_shell/test_geolocation_service.h new file mode 100644 index 0000000..0a0a145 --- /dev/null +++ b/webkit/tools/test_shell/test_geolocation_service.h @@ -0,0 +1,61 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WEBKIT_TOOLS_TEST_SHELL_TEST_GEOLOCATION_SERVICE_H_ +#define WEBKIT_TOOLS_TEST_SHELL_TEST_GEOLOCATION_SERVICE_H_ + +#include "base/id_map.h" +#include "base/timer.h" +#include "third_party/WebKit/WebKit/chromium/public/WebGeolocationService.h" + +namespace WebKit { +class WebURL; +} // namespace WebKit + +// This class short-circuits the browser side of Geolocation permission +// management: instead of going all the way up to GeolocationPermissionContext, +// InfoBar, GeolocationContentSettingsMap, etc., we send a pre-arranged response +// here. The flow is basically: +// +// 1. LayoutTestController::setGeolocationPermission is exposed to JS, +// which then calls TestGeolocationService::SetGeolocationPermission(). This +// response will be used for all subsequent geolocation requests. +// +// 2. WebKit::WebGeolocationServiceBridge attaches to us via attachBridge(), and +// eventually calls requestPermissionForFrame(). +// +// 3. We then callback into it, setting its permission (we yield the callstack +// using a timer since WebKit doesn't expect the response to be synchronous). +// +// Note: WebKit provides a mock for position and error updates. For browser-side +// and end-to-end tests, check geolocation_browsertest.cc and +// geolocation_permission_context_unittest.cc. +class TestGeolocationService : public WebKit::WebGeolocationService { + public: + TestGeolocationService(); + virtual ~TestGeolocationService(); + + void SetGeolocationPermission(bool allowed); + + virtual void requestPermissionForFrame(int bridgeId, + const WebKit::WebURL& url); + + virtual int attachBridge(WebKit::WebGeolocationServiceBridge* bridge); + virtual void detachBridge(int bridgeId); + + private: + void SendPermission(); + + bool allowed_; + + IDMap<WebKit::WebGeolocationServiceBridge> bridges_map_; + + base::OneShotTimer<TestGeolocationService> permission_timer_; + + std::vector<std::pair<int, bool> > pending_permissions_; + + DISALLOW_COPY_AND_ASSIGN(TestGeolocationService); +}; + +#endif // WEBKIT_TOOLS_TEST_SHELL_TEST_GEOLOCATION_SERVICE_H_ diff --git a/webkit/tools/test_shell/test_shell.gypi b/webkit/tools/test_shell/test_shell.gypi index 15eec91..5b83a349 100644 --- a/webkit/tools/test_shell/test_shell.gypi +++ b/webkit/tools/test_shell/test_shell.gypi @@ -72,6 +72,8 @@ 'plain_text_controller.cc', 'plain_text_controller.h', 'resource.h', + 'test_geolocation_service.cc', + 'test_geolocation_service.h', 'test_navigation_controller.cc', 'test_navigation_controller.h', 'test_shell.cc', diff --git a/webkit/tools/test_shell/test_shell_webkit_init.h b/webkit/tools/test_shell/test_shell_webkit_init.h index cdcdb31..cc66afc 100644 --- a/webkit/tools/test_shell/test_shell_webkit_init.h +++ b/webkit/tools/test_shell/test_shell_webkit_init.h @@ -15,6 +15,7 @@ #include "net/base/file_stream.h" #include "third_party/WebKit/WebKit/chromium/public/WebData.h" #include "third_party/WebKit/WebKit/chromium/public/WebDatabase.h" +#include "third_party/WebKit/WebKit/chromium/public/WebGeolocationServiceMock.h" #include "third_party/WebKit/WebKit/chromium/public/WebGraphicsContext3D.h" #include "third_party/WebKit/WebKit/chromium/public/WebIndexedDatabase.h" #include "third_party/WebKit/WebKit/chromium/public/WebKit.h" @@ -76,9 +77,8 @@ class TestShellWebKitInit : public webkit_glue::WebKitClientImpl { WebKit::WebRuntimeFeatures::enableMediaPlayer( PathService::Get(base::DIR_MODULE, &module_path) && media::InitializeMediaLibrary(module_path)); - // TODO(joth): Make a dummy geolocation service implemenation for - // test_shell, and set this to true. http://crbug.com/36451 - WebKit::WebRuntimeFeatures::enableGeolocation(false); + + WebKit::WebRuntimeFeatures::enableGeolocation(true); // Construct and initialize an appcache system for this scope. // A new empty temp directory is created to house any cached diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc index 82e7907..c4f0ccb 100644 --- a/webkit/tools/test_shell/test_webview_delegate.cc +++ b/webkit/tools/test_shell/test_webview_delegate.cc @@ -60,6 +60,7 @@ #include "webkit/tools/test_shell/mock_spellcheck.h" #include "webkit/tools/test_shell/notification_presenter.h" #include "webkit/tools/test_shell/simple_appcache_system.h" +#include "webkit/tools/test_shell/test_geolocation_service.h" #include "webkit/tools/test_shell/test_navigation_controller.h" #include "webkit/tools/test_shell/test_shell.h" #include "webkit/tools/test_shell/test_web_worker.h" @@ -627,6 +628,10 @@ WebNotificationPresenter* TestWebViewDelegate::notificationPresenter() { return shell_->notification_presenter(); } +WebKit::WebGeolocationService* TestWebViewDelegate::geolocationService() { + return GetTestGeolocationService(); +} + // WebWidgetClient ----------------------------------------------------------- void TestWebViewDelegate::didInvalidateRect(const WebRect& rect) { @@ -1144,6 +1149,10 @@ void TestWebViewDelegate::WaitForPolicyDelegate() { policy_delegate_should_notify_done_ = true; } +void TestWebViewDelegate::SetGeolocationPermission(bool allowed) { + GetTestGeolocationService()->SetGeolocationPermission(allowed); +} + // Private methods ----------------------------------------------------------- void TestWebViewDelegate::UpdateAddressBar(WebView* webView) { @@ -1264,6 +1273,12 @@ std::wstring TestWebViewDelegate::GetFrameDescription(WebFrame* webframe) { } } +TestGeolocationService* TestWebViewDelegate::GetTestGeolocationService() { + if (!test_geolocation_service_.get()) + test_geolocation_service_.reset(new TestGeolocationService); + return test_geolocation_service_.get(); +} + void TestWebViewDelegate::set_fake_window_rect(const WebRect& rect) { fake_rect_ = rect; using_fake_rect_ = true; diff --git a/webkit/tools/test_shell/test_webview_delegate.h b/webkit/tools/test_shell/test_webview_delegate.h index 35c8b3cf..ccb3dd5 100644 --- a/webkit/tools/test_shell/test_webview_delegate.h +++ b/webkit/tools/test_shell/test_webview_delegate.h @@ -45,6 +45,7 @@ struct WebPreferences; class GURL; +class TestGeolocationService; class TestShell; class WebWidgetHost; @@ -135,6 +136,7 @@ class TestWebViewDelegate : public WebKit::WebViewClient, virtual void focusAccessibilityObject( const WebKit::WebAccessibilityObject& object); virtual WebKit::WebNotificationPresenter* notificationPresenter(); + virtual WebKit::WebGeolocationService* geolocationService(); // WebKit::WebWidgetClient virtual void didInvalidateRect(const WebKit::WebRect& rect); @@ -307,6 +309,8 @@ class TestWebViewDelegate : public WebKit::WebViewClient, edit_command_value_.clear(); } + void SetGeolocationPermission(bool allowed); + private: // Called the title of the page changes. @@ -351,6 +355,9 @@ class TestWebViewDelegate : public WebKit::WebViewClient, // Get a string suitable for dumping a frame to the console. std::wstring GetFrameDescription(WebKit::WebFrame* webframe); + // Returns a TestGeolocationService owned by this delegate. + TestGeolocationService* GetTestGeolocationService(); + // Causes navigation actions just printout the intended navigation instead // of taking you to the page. This is used for cases like mailto, where you // don't actually want to open the mail program. @@ -427,6 +434,8 @@ class TestWebViewDelegate : public WebKit::WebViewClient, // The mock spellchecker used in TestWebViewDelegate::spellCheck(). MockSpellCheck mock_spellcheck_; + scoped_ptr<TestGeolocationService> test_geolocation_service_; + DISALLOW_COPY_AND_ASSIGN(TestWebViewDelegate); }; |