Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Unified Diff: content/public/test/android/javatests/src/org/chromium/content/browser/test/util/MockLocationProvider.java

Issue 65273002: Add a mechanism to pause and resume geolocation requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove unsused CVC.isGeolocationActiveForTest API Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/public/test/android/javatests/src/org/chromium/content/browser/test/util/MockLocationProvider.java
diff --git a/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/MockLocationProvider.java b/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/MockLocationProvider.java
new file mode 100644
index 0000000000000000000000000000000000000000..147144fdb9ad6920f8fe4da96cfd5a8fd97ad8b8
--- /dev/null
+++ b/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/MockLocationProvider.java
@@ -0,0 +1,86 @@
+// Copyright (c) 2013 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.
+
+package org.chromium.content.browser.test.util;
+
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.Message;
+
+import org.chromium.content.browser.LocationProvider;
+import org.chromium.content.browser.LocationProviderFactory;
+
+public class MockLocationProvider implements LocationProviderFactory.LocationProviderImpl {
+ private boolean mIsRunning;
+ private Handler mHandler;
+ private HandlerThread mHandlerThread;
+ private static final Object mLock = new Object();
+
+ private static final int UPDATE_LOCATION = 100;
+
+ public MockLocationProvider() {
+ }
+
+ public void stopUpdates() {
+ if (mHandlerThread != null) {
+ mHandlerThread.quit();
+ }
+ }
+
+ @Override
+ public void start(boolean gpsEnabled) {
+ if (mHandlerThread == null) {
+ startMockLocationProviderThread();
+ }
+
+ if (mIsRunning) return;
bulach 2013/12/11 15:48:39 nit: would be clearer to move this check first.
benm (inactive) 2013/12/11 20:08:51 Done.
+ mIsRunning = true;
+ synchronized (mLock) {
+ mHandler.sendEmptyMessage(UPDATE_LOCATION);
+ }
+ }
+
+ @Override
+ public void stop() {
+ if (!mIsRunning) return;
+ mIsRunning = false;
+ synchronized (mLock) {
+ mHandler.removeMessages(UPDATE_LOCATION);
+ }
+ }
+
+ @Override
+ public boolean isRunning() {
+ return mIsRunning;
+ }
+
+ private void startMockLocationProviderThread() {
+ assert mHandlerThread == null;
+ assert mHandler == null;
+
+ mHandlerThread = new HandlerThread("MockLocationProviderImpl");
+ mHandlerThread.start();
+ mHandler = new Handler(mHandlerThread.getLooper()) {
+ @Override
+ public void handleMessage(Message msg) {
+ synchronized(mLock) {
+ if (msg.what == UPDATE_LOCATION) {
+ newLocation();
+ sendEmptyMessageDelayed(UPDATE_LOCATION, 250);
+ }
+ }
+ }
+ };
+ }
+
+ private void newLocation() {
+ LocationProvider.nativeNewLocationAvailable(
+ 0, 0, System.currentTimeMillis() / 1000.0,
+ false, 0,
+ true, 0.5,
+ false, 0,
+ false, 0);
+ }
+};
+

Powered by Google App Engine
This is Rietveld 408576698