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.test.UiThreadTest; | 8 import android.test.UiThreadTest; |
8 import android.test.InstrumentationTestCase; | 9 import android.test.InstrumentationTestCase; |
9 import android.test.suitebuilder.annotation.SmallTest; | 10 import android.test.suitebuilder.annotation.SmallTest; |
10 | 11 |
11 import org.chromium.base.ActivityStatus; | 12 import org.chromium.base.ActivityStatus; |
12 import org.chromium.base.test.util.Feature; | 13 import org.chromium.base.test.util.Feature; |
13 | 14 |
14 /** | 15 /** |
15 * Test suite for LocationProvider. | 16 * Test suite for LocationProvider. |
16 */ | 17 */ |
17 public class LocationProviderTest extends InstrumentationTestCase { | 18 public class LocationProviderTest extends InstrumentationTestCase { |
| 19 private Activity mActivity; |
18 private LocationProvider mLocationProvider; | 20 private LocationProvider mLocationProvider; |
19 | 21 |
20 @Override | 22 @Override |
21 public void setUp() { | 23 public void setUp() { |
| 24 mActivity = new Activity(); |
22 mLocationProvider = LocationProvider.create(getInstrumentation().getTarg
etContext()); | 25 mLocationProvider = LocationProvider.create(getInstrumentation().getTarg
etContext()); |
23 } | 26 } |
24 | 27 |
25 /** | 28 /** |
26 * Verify a normal start/stop call pair without any activity pauses. | 29 * Verify a normal start/stop call pair without any activity pauses. |
27 */ | 30 */ |
28 @SmallTest | 31 @SmallTest |
29 @UiThreadTest | 32 @UiThreadTest |
30 @Feature({"Location"}) | 33 @Feature({"Location"}) |
31 public void testStartStop() throws Exception { | 34 public void testStartStop() throws Exception { |
| 35 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.RESUMED
); |
32 mLocationProvider.start(false); | 36 mLocationProvider.start(false); |
33 assertTrue("Should be running", mLocationProvider.isRunning()); | 37 assertTrue("Should be running", mLocationProvider.isRunning()); |
34 mLocationProvider.stop(); | 38 mLocationProvider.stop(); |
35 assertFalse("Should have stopped", mLocationProvider.isRunning()); | 39 assertFalse("Should have stopped", mLocationProvider.isRunning()); |
36 } | 40 } |
37 | 41 |
38 /** | 42 /** |
39 * Verify a start/upgrade/stop call sequence without any activity pauses. | 43 * Verify a start/upgrade/stop call sequence without any activity pauses. |
40 */ | 44 */ |
41 @SmallTest | 45 @SmallTest |
42 @UiThreadTest | 46 @UiThreadTest |
43 @Feature({"Location"}) | 47 @Feature({"Location"}) |
44 public void testStartUpgradeStop() throws Exception { | 48 public void testStartUpgradeStop() throws Exception { |
| 49 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.RESUMED
); |
45 mLocationProvider.start(false); | 50 mLocationProvider.start(false); |
46 assertTrue("Should be running", mLocationProvider.isRunning()); | 51 assertTrue("Should be running", mLocationProvider.isRunning()); |
47 mLocationProvider.start(true); | 52 mLocationProvider.start(true); |
48 assertTrue("Should be running", mLocationProvider.isRunning()); | 53 assertTrue("Should be running", mLocationProvider.isRunning()); |
49 mLocationProvider.stop(); | 54 mLocationProvider.stop(); |
50 assertFalse("Should have stopped", mLocationProvider.isRunning()); | 55 assertFalse("Should have stopped", mLocationProvider.isRunning()); |
51 } | 56 } |
52 | 57 |
53 /** | 58 /** |
54 * Verify that pausing the activity stops location listener and when | 59 * Verify that pausing the activity stops location listener and when |
55 * activity resumes it restarts listening. | 60 * activity resumes it restarts listening. |
56 */ | 61 */ |
57 @SmallTest | 62 @SmallTest |
58 @UiThreadTest | 63 @UiThreadTest |
59 @Feature({"Location"}) | 64 @Feature({"Location"}) |
60 public void testStartPauseResumeStop() throws Exception { | 65 public void testStartPauseResumeStop() throws Exception { |
| 66 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.RESUMED
); |
61 mLocationProvider.start(false); | 67 mLocationProvider.start(false); |
62 assertTrue("Should be running", mLocationProvider.isRunning()); | 68 assertTrue("Should be running", mLocationProvider.isRunning()); |
63 ActivityStatus.onStateChange(null, ActivityStatus.PAUSED); | 69 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.PAUSED)
; |
64 assertFalse("Should have paused", mLocationProvider.isRunning()); | 70 assertFalse("Should have paused", mLocationProvider.isRunning()); |
65 ActivityStatus.onStateChange(null, ActivityStatus.RESUMED); | 71 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.RESUMED
); |
66 assertTrue("Should have resumed", mLocationProvider.isRunning()); | 72 assertTrue("Should have resumed", mLocationProvider.isRunning()); |
67 mLocationProvider.stop(); | 73 mLocationProvider.stop(); |
68 assertFalse("Should have stopped", mLocationProvider.isRunning()); | 74 assertFalse("Should have stopped", mLocationProvider.isRunning()); |
69 } | 75 } |
70 | 76 |
71 /** | 77 /** |
72 * Verify that calling start when the activity is paused doesn't start liste
ning | 78 * Verify that calling start when the activity is paused doesn't start liste
ning |
73 * for location updates until activity resumes. | 79 * for location updates until activity resumes. |
74 */ | 80 */ |
75 @SmallTest | 81 @SmallTest |
76 @UiThreadTest | 82 @UiThreadTest |
77 @Feature({"Location"}) | 83 @Feature({"Location"}) |
78 public void testPauseStartResumeStop() throws Exception { | 84 public void testPauseStartResumeStop() throws Exception { |
79 ActivityStatus.onStateChange(null, ActivityStatus.PAUSED); | 85 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.PAUSED)
; |
80 mLocationProvider.start(false); | 86 mLocationProvider.start(false); |
81 assertFalse("Should not be running", mLocationProvider.isRunning()); | 87 assertFalse("Should not be running", mLocationProvider.isRunning()); |
82 ActivityStatus.onStateChange(null, ActivityStatus.RESUMED); | 88 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.RESUMED
); |
83 assertTrue("Should have resumed", mLocationProvider.isRunning()); | 89 assertTrue("Should have resumed", mLocationProvider.isRunning()); |
84 mLocationProvider.stop(); | 90 mLocationProvider.stop(); |
85 assertFalse("Should have stopped", mLocationProvider.isRunning()); | 91 assertFalse("Should have stopped", mLocationProvider.isRunning()); |
| 92 } |
| 93 |
| 94 /** |
| 95 * Verify that calling start when the activity is stopped doesn't start list
ening |
| 96 * for location updates until activity resumes. |
| 97 */ |
| 98 @SmallTest |
| 99 @UiThreadTest |
| 100 @Feature({"Location"}) |
| 101 public void testPauseStopStartResumeStop() throws Exception { |
| 102 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.STOPPED
); |
| 103 mLocationProvider.start(false); |
| 104 assertFalse("Should not be running", mLocationProvider.isRunning()); |
| 105 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.RESUMED
); |
| 106 assertTrue("Should have resumed", mLocationProvider.isRunning()); |
| 107 mLocationProvider.stop(); |
| 108 assertFalse("Should have stopped", mLocationProvider.isRunning()); |
86 } | 109 } |
87 | 110 |
88 /** | 111 /** |
89 * Verify that upgrading when paused works as expected. | 112 * Verify that upgrading when paused works as expected. |
90 */ | 113 */ |
91 @SmallTest | 114 @SmallTest |
92 @UiThreadTest | 115 @UiThreadTest |
93 @Feature({"Location"}) | 116 @Feature({"Location"}) |
94 public void testStartPauseUpgradeResumeStop() throws Exception { | 117 public void testStartPauseUpgradeResumeStop() throws Exception { |
| 118 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.RESUMED
); |
95 mLocationProvider.start(false); | 119 mLocationProvider.start(false); |
96 assertTrue("Should be running", mLocationProvider.isRunning()); | 120 assertTrue("Should be running", mLocationProvider.isRunning()); |
97 ActivityStatus.onStateChange(null, ActivityStatus.PAUSED); | 121 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.PAUSED)
; |
98 assertFalse("Should have paused", mLocationProvider.isRunning()); | 122 assertFalse("Should have paused", mLocationProvider.isRunning()); |
99 mLocationProvider.start(true); | 123 mLocationProvider.start(true); |
100 assertFalse("Should be paused", mLocationProvider.isRunning()); | 124 assertFalse("Should be paused", mLocationProvider.isRunning()); |
101 ActivityStatus.onStateChange(null, ActivityStatus.RESUMED); | 125 ActivityStatus.onStateChangeForTesting(mActivity, ActivityStatus.RESUMED
); |
102 assertTrue("Should have resumed", mLocationProvider.isRunning()); | 126 assertTrue("Should have resumed", mLocationProvider.isRunning()); |
103 mLocationProvider.stop(); | 127 mLocationProvider.stop(); |
104 assertFalse("Should have stopped", mLocationProvider.isRunning()); | 128 assertFalse("Should have stopped", mLocationProvider.isRunning()); |
105 } | 129 } |
106 } | 130 } |
OLD | NEW |