| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef WEBKIT_TOOLS_TEST_SHELL_TEST_GEOLOCATION_SERVICE_H_ | |
| 6 #define WEBKIT_TOOLS_TEST_SHELL_TEST_GEOLOCATION_SERVICE_H_ | |
| 7 | |
| 8 #include "base/id_map.h" | |
| 9 #include "base/timer.h" | |
| 10 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationService.h" | |
| 11 | |
| 12 namespace WebKit { | |
| 13 class WebURL; | |
| 14 } // namespace WebKit | |
| 15 | |
| 16 // This class short-circuits the browser side of Geolocation permission | |
| 17 // management: instead of going all the way up to GeolocationPermissionContext, | |
| 18 // InfoBar, GeolocationContentSettingsMap, etc., we send a pre-arranged response | |
| 19 // here. The flow is basically: | |
| 20 // | |
| 21 // 1. LayoutTestController::setGeolocationPermission is exposed to JS, | |
| 22 // which then calls TestGeolocationService::SetGeolocationPermission(). This | |
| 23 // response will be used for all subsequent geolocation requests. | |
| 24 // | |
| 25 // 2. WebKit::WebGeolocationServiceBridge attaches to us via attachBridge(), and | |
| 26 // eventually calls requestPermissionForFrame(). | |
| 27 // | |
| 28 // 3. We then callback into it, setting its permission (we yield the callstack | |
| 29 // using a timer since WebKit doesn't expect the response to be synchronous). | |
| 30 // | |
| 31 // Note: WebKit provides a mock for position and error updates. For browser-side | |
| 32 // and end-to-end tests, check geolocation_browsertest.cc and | |
| 33 // geolocation_permission_context_unittest.cc. | |
| 34 class TestGeolocationService : public WebKit::WebGeolocationService { | |
| 35 public: | |
| 36 TestGeolocationService(); | |
| 37 virtual ~TestGeolocationService(); | |
| 38 | |
| 39 void SetGeolocationPermission(bool allowed); | |
| 40 | |
| 41 virtual void requestPermissionForFrame(int bridgeId, | |
| 42 const WebKit::WebURL& url); | |
| 43 | |
| 44 virtual int attachBridge(WebKit::WebGeolocationServiceBridge* bridge); | |
| 45 virtual void detachBridge(int bridgeId); | |
| 46 | |
| 47 private: | |
| 48 void TryToSendPermissions(); | |
| 49 void SendPermission(); | |
| 50 | |
| 51 // Holds the value of |allowed| in most recent SetGeolocationPermission call. | |
| 52 bool allowed_; | |
| 53 // Remains false until the first SetGeolocationPermission call. | |
| 54 bool permission_set_; | |
| 55 | |
| 56 IDMap<WebKit::WebGeolocationServiceBridge> bridges_map_; | |
| 57 | |
| 58 base::OneShotTimer<TestGeolocationService> permission_timer_; | |
| 59 | |
| 60 // In-order vector of pending bridge IDs. Is not pumped by | |
| 61 // TryToSendPermissions until the first call to SetGeolocationPermission. | |
| 62 std::vector<int> pending_permissions_; | |
| 63 | |
| 64 DISALLOW_COPY_AND_ASSIGN(TestGeolocationService); | |
| 65 }; | |
| 66 | |
| 67 #endif // WEBKIT_TOOLS_TEST_SHELL_TEST_GEOLOCATION_SERVICE_H_ | |
| OLD | NEW |