1a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block/* 2a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block * Copyright (C) 2009 The Android Open Source Project 3a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block * 4a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block * Licensed under the Apache License, Version 2.0 (the "License"); 5a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block * you may not use this file except in compliance with the License. 6a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block * You may obtain a copy of the License at 7a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block * 8a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block * http://www.apache.org/licenses/LICENSE-2.0 9a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block * 10a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block * Unless required by applicable law or agreed to in writing, software 11a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block * distributed under the License is distributed on an "AS IS" BASIS, 12a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block * See the License for the specific language governing permissions and 14a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block * limitations under the License. 15a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block */ 16a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block 17a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Blockpackage android.webkit; 18a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block 19a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block/** 20a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block * This class is simply a container for the methods used to configure WebKit's 21a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block * mock Geolocation service for use in LayoutTests. 220691ad50ca6b7a2968a0b95e1e9bb7228dd47d65Grace Kloba * @hide 23a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block */ 24a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Blockpublic final class MockGeolocation { 25a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block 26a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block // Global instance of a MockGeolocation 27a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block private static MockGeolocation sMockGeolocation; 28a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block 29a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block /** 30a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block * Set the position for the mock Geolocation service. 31a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block */ 32a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block public void setPosition(double latitude, double longitude, double accuracy) { 33a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block // This should only ever be called on the WebKit thread. 34a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block nativeSetPosition(latitude, longitude, accuracy); 35a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block } 36a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block 37a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block /** 38a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block * Set the error for the mock Geolocation service. 39a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block */ 40a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block public void setError(int code, String message) { 41a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block // This should only ever be called on the WebKit thread. 42a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block nativeSetError(code, message); 43a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block } 44a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block 45a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block /** 46a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block * Get the global instance of MockGeolocation. 47a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block * @return The global MockGeolocation instance. 48a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block */ 49a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block public static MockGeolocation getInstance() { 50a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block if (sMockGeolocation == null) { 51a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block sMockGeolocation = new MockGeolocation(); 52a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block } 53a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block return sMockGeolocation; 54a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block } 55a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block 56a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block // Native functions 57a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block private static native void nativeSetPosition(double latitude, double longitude, double accuracy); 58a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block private static native void nativeSetError(int code, String message); 59a8dfe24da014b52d7ae93c3fbd7a8b88ec336572Steve Block} 60