| Index: content/public/android/javatests/src/org/chromium/content/browser/DeviceSensorsTest.java
|
| diff --git a/content/public/android/javatests/src/org/chromium/content/browser/DeviceMotionAndOrientationTest.java b/content/public/android/javatests/src/org/chromium/content/browser/DeviceSensorsTest.java
|
| similarity index 55%
|
| rename from content/public/android/javatests/src/org/chromium/content/browser/DeviceMotionAndOrientationTest.java
|
| rename to content/public/android/javatests/src/org/chromium/content/browser/DeviceSensorsTest.java
|
| index 95a28abc7019e5d74fbfa3846f23d34d9e1a878b..98bc3ff354bed7b2f5841b995825c82da310dca2 100644
|
| --- a/content/public/android/javatests/src/org/chromium/content/browser/DeviceMotionAndOrientationTest.java
|
| +++ b/content/public/android/javatests/src/org/chromium/content/browser/DeviceSensorsTest.java
|
| @@ -16,205 +16,205 @@ import java.util.HashSet;
|
| import java.util.Set;
|
|
|
| /**
|
| - * Test suite for DeviceMotionAndOrientation.
|
| + * Test suite for DeviceSensors.
|
| */
|
| -public class DeviceMotionAndOrientationTest extends AndroidTestCase {
|
| +public class DeviceSensorsTest extends AndroidTestCase {
|
|
|
| - private DeviceMotionAndOrientationForTests mDeviceMotionAndOrientation;
|
| + private DeviceSensorsForTests mDeviceSensors;
|
| private MockSensorManager mMockSensorManager;
|
|
|
| @Override
|
| public void setUp() throws Exception {
|
| super.setUp();
|
| mMockSensorManager = new MockSensorManager();
|
| - mDeviceMotionAndOrientation = DeviceMotionAndOrientationForTests.getInstance(getContext());
|
| - mDeviceMotionAndOrientation.setSensorManagerProxy(mMockSensorManager);
|
| + mDeviceSensors = DeviceSensorsForTests.getInstance(getContext());
|
| + mDeviceSensors.setSensorManagerProxy(mMockSensorManager);
|
| }
|
|
|
| @SmallTest
|
| public void testRegisterSensorsDeviceMotion() {
|
| - boolean start = mDeviceMotionAndOrientation.start(0,
|
| - DeviceMotionAndOrientation.DEVICE_MOTION, 100);
|
| + boolean start = mDeviceSensors.start(0,
|
| + DeviceSensors.DEVICE_MOTION, 100);
|
|
|
| assertTrue(start);
|
| assertTrue("should contain all motion sensors",
|
| - mDeviceMotionAndOrientation.mActiveSensors.containsAll(
|
| - DeviceMotionAndOrientation.DEVICE_MOTION_SENSORS));
|
| - assertTrue(mDeviceMotionAndOrientation.mDeviceMotionIsActive);
|
| - assertFalse(mDeviceMotionAndOrientation.mDeviceOrientationIsActive);
|
| + mDeviceSensors.mActiveSensors.containsAll(
|
| + DeviceSensors.DEVICE_MOTION_SENSORS));
|
| + assertTrue(mDeviceSensors.mDeviceMotionIsActive);
|
| + assertFalse(mDeviceSensors.mDeviceOrientationIsActive);
|
|
|
| - assertEquals(DeviceMotionAndOrientation.DEVICE_MOTION_SENSORS.size(),
|
| + assertEquals(DeviceSensors.DEVICE_MOTION_SENSORS.size(),
|
| mMockSensorManager.numRegistered);
|
| assertEquals(0, mMockSensorManager.numUnRegistered);
|
| - assertEquals(DeviceMotionAndOrientation.DEVICE_MOTION_SENSORS.size(),
|
| - mDeviceMotionAndOrientation.getNumberActiveDeviceMotionSensors());
|
| + assertEquals(DeviceSensors.DEVICE_MOTION_SENSORS.size(),
|
| + mDeviceSensors.getNumberActiveDeviceMotionSensors());
|
| }
|
|
|
| @SmallTest
|
| public void testRegisterSensorsDeviceOrientation() {
|
| - boolean start = mDeviceMotionAndOrientation.start(0,
|
| - DeviceMotionAndOrientation.DEVICE_ORIENTATION, 100);
|
| + boolean start = mDeviceSensors.start(0,
|
| + DeviceSensors.DEVICE_ORIENTATION, 100);
|
|
|
| assertTrue(start);
|
| assertTrue("should contain all orientation sensors",
|
| - mDeviceMotionAndOrientation.mActiveSensors.containsAll(
|
| - DeviceMotionAndOrientation.DEVICE_ORIENTATION_SENSORS));
|
| - assertFalse(mDeviceMotionAndOrientation.mDeviceMotionIsActive);
|
| - assertTrue(mDeviceMotionAndOrientation.mDeviceOrientationIsActive);
|
| + mDeviceSensors.mActiveSensors.containsAll(
|
| + DeviceSensors.DEVICE_ORIENTATION_SENSORS));
|
| + assertFalse(mDeviceSensors.mDeviceMotionIsActive);
|
| + assertTrue(mDeviceSensors.mDeviceOrientationIsActive);
|
|
|
| - assertEquals(DeviceMotionAndOrientation.DEVICE_ORIENTATION_SENSORS.size(),
|
| + assertEquals(DeviceSensors.DEVICE_ORIENTATION_SENSORS.size(),
|
| mMockSensorManager.numRegistered);
|
| assertEquals(0, mMockSensorManager.numUnRegistered);
|
| }
|
|
|
| @SmallTest
|
| public void testRegisterSensorsDeviceMotionAndOrientation() {
|
| - boolean startOrientation = mDeviceMotionAndOrientation.start(0,
|
| - DeviceMotionAndOrientation.DEVICE_ORIENTATION, 100);
|
| - boolean startMotion = mDeviceMotionAndOrientation.start(0,
|
| - DeviceMotionAndOrientation.DEVICE_MOTION, 100);
|
| + boolean startOrientation = mDeviceSensors.start(0,
|
| + DeviceSensors.DEVICE_ORIENTATION, 100);
|
| + boolean startMotion = mDeviceSensors.start(0,
|
| + DeviceSensors.DEVICE_MOTION, 100);
|
|
|
| assertTrue(startOrientation);
|
| assertTrue(startMotion);
|
| assertTrue("should contain all motion sensors",
|
| - mDeviceMotionAndOrientation.mActiveSensors.containsAll(
|
| - DeviceMotionAndOrientation.DEVICE_MOTION_SENSORS));
|
| + mDeviceSensors.mActiveSensors.containsAll(
|
| + DeviceSensors.DEVICE_MOTION_SENSORS));
|
| assertTrue("should contain all orientation sensors",
|
| - mDeviceMotionAndOrientation.mActiveSensors.containsAll(
|
| - DeviceMotionAndOrientation.DEVICE_ORIENTATION_SENSORS));
|
| + mDeviceSensors.mActiveSensors.containsAll(
|
| + DeviceSensors.DEVICE_ORIENTATION_SENSORS));
|
|
|
| Set<Integer> union = new HashSet<Integer>(
|
| - DeviceMotionAndOrientation.DEVICE_ORIENTATION_SENSORS);
|
| - union.addAll(DeviceMotionAndOrientation.DEVICE_MOTION_SENSORS);
|
| + DeviceSensors.DEVICE_ORIENTATION_SENSORS);
|
| + union.addAll(DeviceSensors.DEVICE_MOTION_SENSORS);
|
|
|
| - assertEquals(union.size(), mDeviceMotionAndOrientation.mActiveSensors.size());
|
| - assertTrue(mDeviceMotionAndOrientation.mDeviceMotionIsActive);
|
| - assertTrue(mDeviceMotionAndOrientation.mDeviceOrientationIsActive);
|
| + assertEquals(union.size(), mDeviceSensors.mActiveSensors.size());
|
| + assertTrue(mDeviceSensors.mDeviceMotionIsActive);
|
| + assertTrue(mDeviceSensors.mDeviceOrientationIsActive);
|
| assertEquals(union.size(), mMockSensorManager.numRegistered);
|
| assertEquals(0, mMockSensorManager.numUnRegistered);
|
| - assertEquals(DeviceMotionAndOrientation.DEVICE_MOTION_SENSORS.size(),
|
| - mDeviceMotionAndOrientation.getNumberActiveDeviceMotionSensors());
|
| + assertEquals(DeviceSensors.DEVICE_MOTION_SENSORS.size(),
|
| + mDeviceSensors.getNumberActiveDeviceMotionSensors());
|
| }
|
|
|
| @SmallTest
|
| public void testUnregisterSensorsDeviceMotion() {
|
| - mDeviceMotionAndOrientation.start(0, DeviceMotionAndOrientation.DEVICE_MOTION, 100);
|
| - mDeviceMotionAndOrientation.stop(DeviceMotionAndOrientation.DEVICE_MOTION);
|
| + mDeviceSensors.start(0, DeviceSensors.DEVICE_MOTION, 100);
|
| + mDeviceSensors.stop(DeviceSensors.DEVICE_MOTION);
|
|
|
| assertTrue("should contain no sensors",
|
| - mDeviceMotionAndOrientation.mActiveSensors.isEmpty());
|
| - assertFalse(mDeviceMotionAndOrientation.mDeviceMotionIsActive);
|
| - assertFalse(mDeviceMotionAndOrientation.mDeviceOrientationIsActive);
|
| - assertEquals(DeviceMotionAndOrientation.DEVICE_MOTION_SENSORS.size(),
|
| + mDeviceSensors.mActiveSensors.isEmpty());
|
| + assertFalse(mDeviceSensors.mDeviceMotionIsActive);
|
| + assertFalse(mDeviceSensors.mDeviceOrientationIsActive);
|
| + assertEquals(DeviceSensors.DEVICE_MOTION_SENSORS.size(),
|
| mMockSensorManager.numUnRegistered);
|
| - assertEquals(0, mDeviceMotionAndOrientation.getNumberActiveDeviceMotionSensors());
|
| + assertEquals(0, mDeviceSensors.getNumberActiveDeviceMotionSensors());
|
| }
|
|
|
| @SmallTest
|
| public void testUnregisterSensorsDeviceOrientation() {
|
| - mDeviceMotionAndOrientation.start(0, DeviceMotionAndOrientation.DEVICE_ORIENTATION, 100);
|
| - mDeviceMotionAndOrientation.stop(DeviceMotionAndOrientation.DEVICE_ORIENTATION);
|
| + mDeviceSensors.start(0, DeviceSensors.DEVICE_ORIENTATION, 100);
|
| + mDeviceSensors.stop(DeviceSensors.DEVICE_ORIENTATION);
|
|
|
| assertTrue("should contain no sensors",
|
| - mDeviceMotionAndOrientation.mActiveSensors.isEmpty());
|
| - assertFalse(mDeviceMotionAndOrientation.mDeviceMotionIsActive);
|
| - assertFalse(mDeviceMotionAndOrientation.mDeviceOrientationIsActive);
|
| - assertEquals(DeviceMotionAndOrientation.DEVICE_ORIENTATION_SENSORS.size(),
|
| + mDeviceSensors.mActiveSensors.isEmpty());
|
| + assertFalse(mDeviceSensors.mDeviceMotionIsActive);
|
| + assertFalse(mDeviceSensors.mDeviceOrientationIsActive);
|
| + assertEquals(DeviceSensors.DEVICE_ORIENTATION_SENSORS.size(),
|
| mMockSensorManager.numUnRegistered);
|
| }
|
|
|
| @SmallTest
|
| public void testUnRegisterSensorsDeviceMotionAndOrientation() {
|
| - mDeviceMotionAndOrientation.start(0, DeviceMotionAndOrientation.DEVICE_ORIENTATION, 100);
|
| - mDeviceMotionAndOrientation.start(0, DeviceMotionAndOrientation.DEVICE_MOTION, 100);
|
| - mDeviceMotionAndOrientation.stop(DeviceMotionAndOrientation.DEVICE_MOTION);
|
| + mDeviceSensors.start(0, DeviceSensors.DEVICE_ORIENTATION, 100);
|
| + mDeviceSensors.start(0, DeviceSensors.DEVICE_MOTION, 100);
|
| + mDeviceSensors.stop(DeviceSensors.DEVICE_MOTION);
|
|
|
| assertTrue("should contain all orientation sensors",
|
| - mDeviceMotionAndOrientation.mActiveSensors.containsAll(
|
| - DeviceMotionAndOrientation.DEVICE_ORIENTATION_SENSORS));
|
| + mDeviceSensors.mActiveSensors.containsAll(
|
| + DeviceSensors.DEVICE_ORIENTATION_SENSORS));
|
|
|
| - Set<Integer> diff = new HashSet<Integer>(DeviceMotionAndOrientation.DEVICE_MOTION_SENSORS);
|
| - diff.removeAll(DeviceMotionAndOrientation.DEVICE_ORIENTATION_SENSORS);
|
| + Set<Integer> diff = new HashSet<Integer>(DeviceSensors.DEVICE_MOTION_SENSORS);
|
| + diff.removeAll(DeviceSensors.DEVICE_ORIENTATION_SENSORS);
|
|
|
| assertEquals(diff.size(), mMockSensorManager.numUnRegistered);
|
|
|
| - mDeviceMotionAndOrientation.stop(DeviceMotionAndOrientation.DEVICE_ORIENTATION);
|
| + mDeviceSensors.stop(DeviceSensors.DEVICE_ORIENTATION);
|
|
|
| assertTrue("should contain no sensors",
|
| - mDeviceMotionAndOrientation.mActiveSensors.isEmpty());
|
| - assertEquals(diff.size() + DeviceMotionAndOrientation.DEVICE_ORIENTATION_SENSORS.size(),
|
| + mDeviceSensors.mActiveSensors.isEmpty());
|
| + assertEquals(diff.size() + DeviceSensors.DEVICE_ORIENTATION_SENSORS.size(),
|
| mMockSensorManager.numUnRegistered);
|
| - assertEquals(0, mDeviceMotionAndOrientation.getNumberActiveDeviceMotionSensors());
|
| + assertEquals(0, mDeviceSensors.getNumberActiveDeviceMotionSensors());
|
| }
|
|
|
| @SmallTest
|
| public void testSensorChangedgotOrientation() {
|
| - boolean startOrientation = mDeviceMotionAndOrientation.start(0,
|
| - DeviceMotionAndOrientation.DEVICE_ORIENTATION, 100);
|
| + boolean startOrientation = mDeviceSensors.start(0,
|
| + DeviceSensors.DEVICE_ORIENTATION, 100);
|
|
|
| assertTrue(startOrientation);
|
| - assertTrue(mDeviceMotionAndOrientation.mDeviceOrientationIsActive);
|
| + assertTrue(mDeviceSensors.mDeviceOrientationIsActive);
|
|
|
| float alpha = (float) Math.PI / 4;
|
| float[] values = {0, 0, (float) Math.sin(alpha / 2), (float) Math.cos(alpha / 2), -1};
|
| - mDeviceMotionAndOrientation.sensorChanged(Sensor.TYPE_ROTATION_VECTOR, values);
|
| - mDeviceMotionAndOrientation.verifyCalls("gotOrientation");
|
| - mDeviceMotionAndOrientation.verifyValuesEpsilon(Math.toDegrees(alpha), 0, 0);
|
| + mDeviceSensors.sensorChanged(Sensor.TYPE_ROTATION_VECTOR, values);
|
| + mDeviceSensors.verifyCalls("gotOrientation");
|
| + mDeviceSensors.verifyValuesEpsilon(Math.toDegrees(alpha), 0, 0);
|
| }
|
|
|
| @SmallTest
|
| public void testSensorChangedgotAccelerationIncludingGravity() {
|
| - mDeviceMotionAndOrientation.start(0, DeviceMotionAndOrientation.DEVICE_MOTION, 100);
|
| + mDeviceSensors.start(0, DeviceSensors.DEVICE_MOTION, 100);
|
|
|
| float[] values = {1, 2, 3};
|
| - mDeviceMotionAndOrientation.sensorChanged(Sensor.TYPE_ACCELEROMETER, values);
|
| - mDeviceMotionAndOrientation.verifyCalls("gotAccelerationIncludingGravity");
|
| - mDeviceMotionAndOrientation.verifyValues(1, 2, 3);
|
| + mDeviceSensors.sensorChanged(Sensor.TYPE_ACCELEROMETER, values);
|
| + mDeviceSensors.verifyCalls("gotAccelerationIncludingGravity");
|
| + mDeviceSensors.verifyValues(1, 2, 3);
|
| }
|
|
|
| @SmallTest
|
| public void testSensorChangedgotAcceleration() {
|
| - mDeviceMotionAndOrientation.start(0, DeviceMotionAndOrientation.DEVICE_MOTION, 100);
|
| + mDeviceSensors.start(0, DeviceSensors.DEVICE_MOTION, 100);
|
|
|
| float[] values = {1, 2, 3};
|
| - mDeviceMotionAndOrientation.sensorChanged(Sensor.TYPE_LINEAR_ACCELERATION, values);
|
| - mDeviceMotionAndOrientation.verifyCalls("gotAcceleration");
|
| - mDeviceMotionAndOrientation.verifyValues(1, 2, 3);
|
| + mDeviceSensors.sensorChanged(Sensor.TYPE_LINEAR_ACCELERATION, values);
|
| + mDeviceSensors.verifyCalls("gotAcceleration");
|
| + mDeviceSensors.verifyValues(1, 2, 3);
|
| }
|
|
|
| @SmallTest
|
| public void testSensorChangedgotRotationRate() {
|
| - mDeviceMotionAndOrientation.start(0, DeviceMotionAndOrientation.DEVICE_MOTION, 100);
|
| + mDeviceSensors.start(0, DeviceSensors.DEVICE_MOTION, 100);
|
|
|
| float[] values = {1, 2, 3};
|
| - mDeviceMotionAndOrientation.sensorChanged(Sensor.TYPE_GYROSCOPE, values);
|
| - mDeviceMotionAndOrientation.verifyCalls("gotRotationRate");
|
| - mDeviceMotionAndOrientation.verifyValues(1, 2, 3);
|
| + mDeviceSensors.sensorChanged(Sensor.TYPE_GYROSCOPE, values);
|
| + mDeviceSensors.verifyCalls("gotRotationRate");
|
| + mDeviceSensors.verifyValues(1, 2, 3);
|
| }
|
|
|
| @SmallTest
|
| public void testSensorChangedgotOrientationAndAcceleration() {
|
| - boolean startOrientation = mDeviceMotionAndOrientation.start(0,
|
| - DeviceMotionAndOrientation.DEVICE_ORIENTATION, 100);
|
| - boolean startMotion = mDeviceMotionAndOrientation.start(0,
|
| - DeviceMotionAndOrientation.DEVICE_MOTION, 100);
|
| + boolean startOrientation = mDeviceSensors.start(0,
|
| + DeviceSensors.DEVICE_ORIENTATION, 100);
|
| + boolean startMotion = mDeviceSensors.start(0,
|
| + DeviceSensors.DEVICE_MOTION, 100);
|
|
|
| assertTrue(startOrientation);
|
| assertTrue(startMotion);
|
| - assertTrue(mDeviceMotionAndOrientation.mDeviceMotionIsActive);
|
| - assertTrue(mDeviceMotionAndOrientation.mDeviceOrientationIsActive);
|
| + assertTrue(mDeviceSensors.mDeviceMotionIsActive);
|
| + assertTrue(mDeviceSensors.mDeviceOrientationIsActive);
|
|
|
| float alpha = (float) Math.PI / 4;
|
| float[] values = {0, 0, (float) Math.sin(alpha / 2), (float) Math.cos(alpha / 2), -1};
|
| - mDeviceMotionAndOrientation.sensorChanged(Sensor.TYPE_ROTATION_VECTOR, values);
|
| - mDeviceMotionAndOrientation.verifyCalls("gotOrientation");
|
| - mDeviceMotionAndOrientation.verifyValuesEpsilon(Math.toDegrees(alpha), 0, 0);
|
| + mDeviceSensors.sensorChanged(Sensor.TYPE_ROTATION_VECTOR, values);
|
| + mDeviceSensors.verifyCalls("gotOrientation");
|
| + mDeviceSensors.verifyValuesEpsilon(Math.toDegrees(alpha), 0, 0);
|
|
|
| float[] values2 = {1, 2, 3};
|
| - mDeviceMotionAndOrientation.sensorChanged(Sensor.TYPE_ACCELEROMETER, values2);
|
| - mDeviceMotionAndOrientation.verifyCalls("gotOrientation" +
|
| + mDeviceSensors.sensorChanged(Sensor.TYPE_ACCELEROMETER, values2);
|
| + mDeviceSensors.verifyCalls("gotOrientation" +
|
| "gotAccelerationIncludingGravity");
|
| - mDeviceMotionAndOrientation.verifyValues(1, 2, 3);
|
| + mDeviceSensors.verifyValues(1, 2, 3);
|
| }
|
|
|
|
|
| @@ -302,7 +302,7 @@ public class DeviceMotionAndOrientationTest extends AndroidTestCase {
|
| float[] R = new float[9];
|
| double[] values = new double[3];
|
| SensorManager.getRotationMatrix(R, null, gravity, magnetic);
|
| - mDeviceMotionAndOrientation.computeDeviceOrientationFromRotationMatrix(R, values);
|
| + mDeviceSensors.computeDeviceOrientationFromRotationMatrix(R, values);
|
|
|
| assertEquals(expectedAngles.length, values.length);
|
| final double epsilon = 0.001;
|
| @@ -314,19 +314,19 @@ public class DeviceMotionAndOrientationTest extends AndroidTestCase {
|
|
|
| // -- End Tests for correct Device Orientation angles.
|
|
|
| - private static class DeviceMotionAndOrientationForTests extends DeviceMotionAndOrientation {
|
| + private static class DeviceSensorsForTests extends DeviceSensors {
|
|
|
| private double value1 = 0;
|
| private double value2 = 0;
|
| private double value3 = 0;
|
| private String mCalls = "";
|
|
|
| - private DeviceMotionAndOrientationForTests(Context context) {
|
| + private DeviceSensorsForTests(Context context) {
|
| super(context);
|
| }
|
|
|
| - static DeviceMotionAndOrientationForTests getInstance(Context context) {
|
| - return new DeviceMotionAndOrientationForTests(context);
|
| + static DeviceSensorsForTests getInstance(Context context) {
|
| + return new DeviceSensorsForTests(context);
|
| }
|
|
|
| private void verifyValues(double v1, double v2, double v3) {
|
| @@ -379,7 +379,7 @@ public class DeviceMotionAndOrientationTest extends AndroidTestCase {
|
| }
|
|
|
| private static class MockSensorManager implements
|
| - DeviceMotionAndOrientation.SensorManagerProxy {
|
| + DeviceSensors.SensorManagerProxy {
|
|
|
| private int numRegistered = 0;
|
| private int numUnRegistered = 0;
|
|
|