OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.chrome.browser.precache; | 5 package org.chromium.chrome.browser.precache; |
6 | 6 |
| 7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E
ND_DEVICE; |
| 8 |
7 import android.content.Context; | 9 import android.content.Context; |
8 import android.test.suitebuilder.annotation.SmallTest; | 10 import android.test.suitebuilder.annotation.SmallTest; |
9 | 11 |
10 import org.chromium.base.ThreadUtils; | 12 import org.chromium.base.ThreadUtils; |
11 import org.chromium.base.test.util.Feature; | 13 import org.chromium.base.test.util.Feature; |
| 14 import org.chromium.base.test.util.Restriction; |
12 import org.chromium.chrome.browser.preferences.privacy.PrivacyPreferencesManager
; | 15 import org.chromium.chrome.browser.preferences.privacy.PrivacyPreferencesManager
; |
13 import org.chromium.chrome.browser.sync.ProfileSyncService; | 16 import org.chromium.chrome.browser.sync.ProfileSyncService; |
14 import org.chromium.content.browser.test.NativeLibraryTestBase; | 17 import org.chromium.content.browser.test.NativeLibraryTestBase; |
15 | 18 |
16 import java.util.EnumSet; | 19 import java.util.EnumSet; |
17 import java.util.concurrent.Callable; | 20 import java.util.concurrent.Callable; |
18 | 21 |
19 /** | 22 /** |
20 * Unit tests for {@link PrecacheLauncher}. | 23 * Unit tests for {@link PrecacheLauncher}. |
21 * | 24 * |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 } | 102 } |
100 | 103 |
101 @Override | 104 @Override |
102 protected void tearDown() throws Exception { | 105 protected void tearDown() throws Exception { |
103 ProfileSyncService.overrideForTests(null); | 106 ProfileSyncService.overrideForTests(null); |
104 PrecacheServiceLauncher.setIsPrecachingEnabled(getTargetContext(), false
); | 107 PrecacheServiceLauncher.setIsPrecachingEnabled(getTargetContext(), false
); |
105 super.tearDown(); | 108 super.tearDown(); |
106 } | 109 } |
107 | 110 |
108 @SmallTest | 111 @SmallTest |
| 112 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
109 @Feature({"Precache"}) | 113 @Feature({"Precache"}) |
110 public void testUpdateEnabled_SyncNotReady_ThenDisabled() { | 114 public void testUpdateEnabled_SyncNotReady_ThenDisabled() { |
111 mLauncher.updateEnabled(getTargetContext()); | 115 mLauncher.updateEnabled(getTargetContext()); |
112 waitUntilUiThreadIdle(); | 116 waitUntilUiThreadIdle(); |
113 | 117 |
114 assertEquals(false, isPrecachingEnabled()); | 118 assertEquals(false, isPrecachingEnabled()); |
115 assertEquals(EnumSet.of(FailureReason.SYNC_NOT_INITIALIZED, | 119 assertEquals(EnumSet.of(FailureReason.SYNC_NOT_INITIALIZED, |
116 FailureReason.PRERENDER_PRIVACY_PREFERENCE_NOT_ENAB
LED, | 120 FailureReason.PRERENDER_PRIVACY_PREFERENCE_NOT_ENAB
LED, |
117 FailureReason.NATIVE_SHOULD_RUN_IS_FALSE), | 121 FailureReason.NATIVE_SHOULD_RUN_IS_FALSE), |
118 failureReasons()); | 122 failureReasons()); |
119 | 123 |
120 setSyncInitialized(true); | 124 setSyncInitialized(true); |
121 assertEquals(false, isPrecachingEnabled()); | 125 assertEquals(false, isPrecachingEnabled()); |
122 assertEquals(EnumSet.of(FailureReason.NATIVE_SHOULD_RUN_IS_FALSE), failu
reReasons()); | 126 assertEquals(EnumSet.of(FailureReason.NATIVE_SHOULD_RUN_IS_FALSE), failu
reReasons()); |
123 } | 127 } |
124 | 128 |
125 @SmallTest | 129 @SmallTest |
| 130 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
126 @Feature({"Precache"}) | 131 @Feature({"Precache"}) |
127 public void testUpdateEnabled_SyncNotReady_ThenEnabled() { | 132 public void testUpdateEnabled_SyncNotReady_ThenEnabled() { |
128 mLauncher.updateEnabled(getTargetContext()); | 133 mLauncher.updateEnabled(getTargetContext()); |
129 waitUntilUiThreadIdle(); | 134 waitUntilUiThreadIdle(); |
130 | 135 |
131 assertEquals(false, isPrecachingEnabled()); | 136 assertEquals(false, isPrecachingEnabled()); |
132 assertEquals(EnumSet.of(FailureReason.SYNC_NOT_INITIALIZED, | 137 assertEquals(EnumSet.of(FailureReason.SYNC_NOT_INITIALIZED, |
133 FailureReason.PRERENDER_PRIVACY_PREFERENCE_NOT_ENAB
LED, | 138 FailureReason.PRERENDER_PRIVACY_PREFERENCE_NOT_ENAB
LED, |
134 FailureReason.NATIVE_SHOULD_RUN_IS_FALSE), | 139 FailureReason.NATIVE_SHOULD_RUN_IS_FALSE), |
135 failureReasons()); | 140 failureReasons()); |
136 | 141 |
137 mLauncher.setShouldRun(true); | 142 mLauncher.setShouldRun(true); |
138 setSyncInitialized(true); | 143 setSyncInitialized(true); |
139 assertEquals(true, isPrecachingEnabled()); | 144 assertEquals(true, isPrecachingEnabled()); |
140 assertEquals(EnumSet.noneOf(FailureReason.class), failureReasons()); | 145 assertEquals(EnumSet.noneOf(FailureReason.class), failureReasons()); |
141 } | 146 } |
142 | 147 |
143 @SmallTest | 148 @SmallTest |
| 149 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
144 @Feature({"Precache"}) | 150 @Feature({"Precache"}) |
145 public void testUpdateEnabled_Disabled_ThenEnabled() { | 151 public void testUpdateEnabled_Disabled_ThenEnabled() { |
146 setSyncInitialized(true); | 152 setSyncInitialized(true); |
147 mLauncher.updateEnabled(getTargetContext()); | 153 mLauncher.updateEnabled(getTargetContext()); |
148 waitUntilUiThreadIdle(); | 154 waitUntilUiThreadIdle(); |
149 | 155 |
150 assertEquals(false, isPrecachingEnabled()); | 156 assertEquals(false, isPrecachingEnabled()); |
151 assertEquals(EnumSet.of(FailureReason.NATIVE_SHOULD_RUN_IS_FALSE), failu
reReasons()); | 157 assertEquals(EnumSet.of(FailureReason.NATIVE_SHOULD_RUN_IS_FALSE), failu
reReasons()); |
152 | 158 |
153 mLauncher.setShouldRun(true); | 159 mLauncher.setShouldRun(true); |
154 assertEquals(true, isPrecachingEnabled()); | 160 assertEquals(true, isPrecachingEnabled()); |
155 assertEquals(EnumSet.noneOf(FailureReason.class), failureReasons()); | 161 assertEquals(EnumSet.noneOf(FailureReason.class), failureReasons()); |
156 } | 162 } |
157 | 163 |
158 @SmallTest | 164 @SmallTest |
| 165 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
159 @Feature({"Precache"}) | 166 @Feature({"Precache"}) |
160 public void testUpdateEnabled_Enabled_ThenDisabled() { | 167 public void testUpdateEnabled_Enabled_ThenDisabled() { |
161 mLauncher.setShouldRun(true); | 168 mLauncher.setShouldRun(true); |
162 setSyncInitialized(true); | 169 setSyncInitialized(true); |
163 mLauncher.updateEnabled(getTargetContext()); | 170 mLauncher.updateEnabled(getTargetContext()); |
164 waitUntilUiThreadIdle(); | 171 waitUntilUiThreadIdle(); |
165 | 172 |
166 assertEquals(true, isPrecachingEnabled()); | 173 assertEquals(true, isPrecachingEnabled()); |
167 assertEquals(EnumSet.noneOf(FailureReason.class), failureReasons()); | 174 assertEquals(EnumSet.noneOf(FailureReason.class), failureReasons()); |
168 | 175 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 /** Notify listeners that sync preferences have changed. This is run by setS
houldRun. */ | 216 /** Notify listeners that sync preferences have changed. This is run by setS
houldRun. */ |
210 private void notifySyncChanged() { | 217 private void notifySyncChanged() { |
211 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 218 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
212 @Override | 219 @Override |
213 public void run() { | 220 public void run() { |
214 mSync.syncStateChanged(); | 221 mSync.syncStateChanged(); |
215 } | 222 } |
216 }); | 223 }); |
217 } | 224 } |
218 } | 225 } |
OLD | NEW |