OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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.InstrumentationTestCase; | 8 import android.test.InstrumentationTestCase; |
9 import android.test.UiThreadTest; | 9 import android.test.UiThreadTest; |
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 LocationProviderAdapter 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 = |
| 25 LocationProviderAdapter.create(getInstrumentation().getTargetCon
text()); |
26 } | 26 } |
27 | 27 |
28 /** | 28 /** |
29 * Verify a normal start/stop call pair without any activity pauses. | 29 * Verify a normal start/stop call pair without any activity pauses. |
30 */ | 30 */ |
31 @SmallTest | 31 @SmallTest |
32 @UiThreadTest | 32 @UiThreadTest |
33 @Feature({"Location"}) | 33 @Feature({"Location"}) |
34 public void testStartStop() throws Exception { | 34 public void testStartStop() throws Exception { |
35 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.RESUMED
); | |
36 mLocationProvider.start(false); | 35 mLocationProvider.start(false); |
37 assertTrue("Should be running", mLocationProvider.isRunning()); | 36 assertTrue("Should be running", mLocationProvider.isRunning()); |
38 mLocationProvider.stop(); | 37 mLocationProvider.stop(); |
39 assertFalse("Should have stopped", mLocationProvider.isRunning()); | 38 assertFalse("Should have stopped", mLocationProvider.isRunning()); |
40 } | 39 } |
41 | 40 |
42 /** | 41 /** |
43 * Verify a start/upgrade/stop call sequence without any activity pauses. | 42 * Verify a start/upgrade/stop call sequence without any activity pauses. |
44 */ | 43 */ |
45 @SmallTest | 44 @SmallTest |
46 @UiThreadTest | 45 @UiThreadTest |
47 @Feature({"Location"}) | 46 @Feature({"Location"}) |
48 public void testStartUpgradeStop() throws Exception { | 47 public void testStartUpgradeStop() throws Exception { |
49 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.RESUMED
); | |
50 mLocationProvider.start(false); | 48 mLocationProvider.start(false); |
51 assertTrue("Should be running", mLocationProvider.isRunning()); | 49 assertTrue("Should be running", mLocationProvider.isRunning()); |
52 mLocationProvider.start(true); | 50 mLocationProvider.start(true); |
53 assertTrue("Should be running", mLocationProvider.isRunning()); | 51 assertTrue("Should be running", mLocationProvider.isRunning()); |
54 mLocationProvider.stop(); | 52 mLocationProvider.stop(); |
55 assertFalse("Should have stopped", mLocationProvider.isRunning()); | 53 assertFalse("Should have stopped", mLocationProvider.isRunning()); |
56 } | 54 } |
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 } | 55 } |
OLD | NEW |