| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.test.UiThreadTest; | 8 import android.test.UiThreadTest; |
| 9 import android.test.InstrumentationTestCase; | 9 import android.test.InstrumentationTestCase; |
| 10 import android.test.suitebuilder.annotation.SmallTest; | 10 import android.test.suitebuilder.annotation.SmallTest; |
| 11 | 11 |
| 12 import org.chromium.base.ActivityStatus; | |
| 13 import org.chromium.base.test.util.Feature; | 12 import org.chromium.base.test.util.Feature; |
| 14 | 13 |
| 15 /** | 14 /** |
| 16 * Test suite for LocationProvider. | 15 * Test suite for LocationProvider. |
| 17 */ | 16 */ |
| 18 public class LocationProviderTest extends InstrumentationTestCase { | 17 public class LocationProviderTest extends InstrumentationTestCase { |
| 19 private Activity mActivity; | 18 private Activity mActivity; |
| 20 private LocationProvider mLocationProvider; | 19 private LocationProvider mLocationProvider; |
| 21 | 20 |
| 22 @Override | 21 @Override |
| 23 public void setUp() { | 22 public void setUp() { |
| 24 mActivity = new Activity(); | 23 mActivity = new Activity(); |
| 25 mLocationProvider = LocationProvider.create(getInstrumentation().getTarg
etContext()); | 24 mLocationProvider = LocationProvider.create(getInstrumentation().getTarg
etContext()); |
| 26 } | 25 } |
| 27 | 26 |
| 28 /** | 27 /** |
| 29 * Verify a normal start/stop call pair without any activity pauses. | 28 * Verify a normal start/stop call pair without any activity pauses. |
| 30 */ | 29 */ |
| 31 @SmallTest | 30 @SmallTest |
| 32 @UiThreadTest | 31 @UiThreadTest |
| 33 @Feature({"Location"}) | 32 @Feature({"Location"}) |
| 34 public void testStartStop() throws Exception { | 33 public void testStartStop() throws Exception { |
| 35 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.RESUMED
); | |
| 36 mLocationProvider.start(false); | 34 mLocationProvider.start(false); |
| 37 assertTrue("Should be running", mLocationProvider.isRunning()); | 35 assertTrue("Should be running", mLocationProvider.isRunning()); |
| 38 mLocationProvider.stop(); | 36 mLocationProvider.stop(); |
| 39 assertFalse("Should have stopped", mLocationProvider.isRunning()); | 37 assertFalse("Should have stopped", mLocationProvider.isRunning()); |
| 40 } | 38 } |
| 41 | 39 |
| 42 /** | 40 /** |
| 43 * Verify a start/upgrade/stop call sequence without any activity pauses. | 41 * Verify a start/upgrade/stop call sequence without any activity pauses. |
| 44 */ | 42 */ |
| 45 @SmallTest | 43 @SmallTest |
| 46 @UiThreadTest | 44 @UiThreadTest |
| 47 @Feature({"Location"}) | 45 @Feature({"Location"}) |
| 48 public void testStartUpgradeStop() throws Exception { | 46 public void testStartUpgradeStop() throws Exception { |
| 49 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.RESUMED
); | |
| 50 mLocationProvider.start(false); | 47 mLocationProvider.start(false); |
| 51 assertTrue("Should be running", mLocationProvider.isRunning()); | 48 assertTrue("Should be running", mLocationProvider.isRunning()); |
| 52 mLocationProvider.start(true); | 49 mLocationProvider.start(true); |
| 53 assertTrue("Should be running", mLocationProvider.isRunning()); | 50 assertTrue("Should be running", mLocationProvider.isRunning()); |
| 54 mLocationProvider.stop(); | 51 mLocationProvider.stop(); |
| 55 assertFalse("Should have stopped", mLocationProvider.isRunning()); | 52 assertFalse("Should have stopped", mLocationProvider.isRunning()); |
| 56 } | 53 } |
| 57 | |
| 58 /** | |
| 59 * Verify that pausing the activity stops location listener and when | |
| 60 * activity resumes it restarts listening. | |
| 61 */ | |
| 62 @SmallTest | |
| 63 @UiThreadTest | |
| 64 @Feature({"Location"}) | |
| 65 public void testStartPauseResumeStop() throws Exception { | |
| 66 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.RESUMED
); | |
| 67 mLocationProvider.start(false); | |
| 68 assertTrue("Should be running", mLocationProvider.isRunning()); | |
| 69 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.PAUSED)
; | |
| 70 assertFalse("Should have paused", mLocationProvider.isRunning()); | |
| 71 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.RESUMED
); | |
| 72 assertTrue("Should have resumed", mLocationProvider.isRunning()); | |
| 73 mLocationProvider.stop(); | |
| 74 assertFalse("Should have stopped", mLocationProvider.isRunning()); | |
| 75 } | |
| 76 | |
| 77 /** | |
| 78 * Verify that calling start when the activity is paused doesn't start liste
ning | |
| 79 * for location updates until activity resumes. | |
| 80 */ | |
| 81 @SmallTest | |
| 82 @UiThreadTest | |
| 83 @Feature({"Location"}) | |
| 84 public void testPauseStartResumeStop() throws Exception { | |
| 85 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.PAUSED)
; | |
| 86 mLocationProvider.start(false); | |
| 87 assertFalse("Should not be running", mLocationProvider.isRunning()); | |
| 88 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.RESUMED
); | |
| 89 assertTrue("Should have resumed", mLocationProvider.isRunning()); | |
| 90 mLocationProvider.stop(); | |
| 91 assertFalse("Should have stopped", mLocationProvider.isRunning()); | |
| 92 } | |
| 93 | |
| 94 /** | |
| 95 * Verify that calling start when the activity is being created doesn't star
t listening | |
| 96 * for location updates until activity resumes. | |
| 97 */ | |
| 98 @SmallTest | |
| 99 @UiThreadTest | |
| 100 @Feature({"Location"}) | |
| 101 public void testCreatedStartedStartResumeStop() throws Exception { | |
| 102 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.CREATED
); | |
| 103 mLocationProvider.start(false); | |
| 104 assertFalse("Should not be running", mLocationProvider.isRunning()); | |
| 105 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.STARTED
); | |
| 106 mLocationProvider.start(false); | |
| 107 assertFalse("Should not be running", mLocationProvider.isRunning()); | |
| 108 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.RESUMED
); | |
| 109 assertTrue("Should have resumed", mLocationProvider.isRunning()); | |
| 110 mLocationProvider.stop(); | |
| 111 assertFalse("Should have stopped", mLocationProvider.isRunning()); | |
| 112 } | |
| 113 | |
| 114 /** | |
| 115 * Verify that calling start when the activity is being created then immedia
tely paused doesn't | |
| 116 * start listening for location updates until activity resumes. | |
| 117 */ | |
| 118 @SmallTest | |
| 119 @UiThreadTest | |
| 120 @Feature({"Location"}) | |
| 121 public void testCreatedStartedStartPausedResumeStop() throws Exception { | |
| 122 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.CREATED
); | |
| 123 mLocationProvider.start(false); | |
| 124 assertFalse("Should not be running", mLocationProvider.isRunning()); | |
| 125 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.STARTED
); | |
| 126 mLocationProvider.start(false); | |
| 127 assertFalse("Should not be running", mLocationProvider.isRunning()); | |
| 128 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.PAUSED)
; | |
| 129 assertFalse("Should not be running", mLocationProvider.isRunning()); | |
| 130 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.RESUMED
); | |
| 131 assertTrue("Should have resumed", mLocationProvider.isRunning()); | |
| 132 mLocationProvider.stop(); | |
| 133 assertFalse("Should have stopped", mLocationProvider.isRunning()); | |
| 134 } | |
| 135 | |
| 136 /** | |
| 137 * Verify that calling start when the activity is stopped doesn't start list
ening | |
| 138 * for location updates until activity resumes. | |
| 139 */ | |
| 140 @SmallTest | |
| 141 @UiThreadTest | |
| 142 @Feature({"Location"}) | |
| 143 public void testStopStartResumeStop() throws Exception { | |
| 144 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.STOPPED
); | |
| 145 mLocationProvider.start(false); | |
| 146 assertFalse("Should not be running", mLocationProvider.isRunning()); | |
| 147 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.RESUMED
); | |
| 148 assertTrue("Should have resumed", mLocationProvider.isRunning()); | |
| 149 mLocationProvider.stop(); | |
| 150 assertFalse("Should have stopped", mLocationProvider.isRunning()); | |
| 151 } | |
| 152 | |
| 153 /** | |
| 154 * Verify that upgrading when paused works as expected. | |
| 155 */ | |
| 156 @SmallTest | |
| 157 @UiThreadTest | |
| 158 @Feature({"Location"}) | |
| 159 public void testStartPauseUpgradeResumeStop() throws Exception { | |
| 160 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.RESUMED
); | |
| 161 mLocationProvider.start(false); | |
| 162 assertTrue("Should be running", mLocationProvider.isRunning()); | |
| 163 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.PAUSED)
; | |
| 164 assertFalse("Should have paused", mLocationProvider.isRunning()); | |
| 165 mLocationProvider.start(true); | |
| 166 assertFalse("Should be paused", mLocationProvider.isRunning()); | |
| 167 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.RESUMED
); | |
| 168 assertTrue("Should have resumed", mLocationProvider.isRunning()); | |
| 169 mLocationProvider.stop(); | |
| 170 assertFalse("Should have stopped", mLocationProvider.isRunning()); | |
| 171 } | |
| 172 } | 54 } |
| OLD | NEW |