Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(685)

Side by Side Diff: sync/android/javatests/src/org/chromium/sync/notifier/InvalidationControllerTest.java

Issue 13109002: [Sync] Move Android enabled types logic into native (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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.sync.notifier; 5 package org.chromium.sync.notifier;
6 6
7 import android.accounts.Account; 7 import android.accounts.Account;
8 import android.app.Activity; 8 import android.app.Activity;
9 import android.content.ComponentName; 9 import android.content.ComponentName;
10 import android.content.Context; 10 import android.content.Context;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 assertFalse(listenerCallbackCalled.get()); 145 assertFalse(listenerCallbackCalled.get());
146 146
147 // Ensure we get a callback, which means we have registered for them. 147 // Ensure we get a callback, which means we have registered for them.
148 ActivityStatus.onStateChange(new Activity(), ActivityStatus.RESUMED); 148 ActivityStatus.onStateChange(new Activity(), ActivityStatus.RESUMED);
149 assertTrue(listenerCallbackCalled.get()); 149 assertTrue(listenerCallbackCalled.get());
150 } 150 }
151 151
152 @SmallTest 152 @SmallTest
153 @Feature({"Sync"}) 153 @Feature({"Sync"})
154 public void testRegisterForSpecificTypes() { 154 public void testRegisterForSpecificTypes() {
155 final String controllerFlag = "resolveModelTypes"; 155 InvalidationController controller = new InvalidationController(mContext) ;
156 final ModelTypeResolver resolver = new ModelTypeResolver() {
157 @Override
158 public Set<ModelType> resolveModelTypes(Set<ModelType> modelTypes) {
159 mContext.setFlag(controllerFlag);
160 return modelTypes;
161 }
162 };
163 InvalidationController controller = new InvalidationController(mContext) {
164 @Override
165 ModelTypeResolver getModelTypeResolver() {
166 return resolver;
167 }
168 };
169 Account account = new Account("test@example.com", "bogus"); 156 Account account = new Account("test@example.com", "bogus");
170 controller.setRegisteredTypes(account, false, 157 controller.setRegisteredTypes(account, false,
171 Sets.newHashSet(ModelType.BOOKMARK, ModelType.SESSION)); 158 Sets.newHashSet(ModelType.BOOKMARK, ModelType.SESSION));
172 assertEquals(1, mContext.getNumStartedIntents()); 159 assertEquals(1, mContext.getNumStartedIntents());
173 160
174 // Validate destination. 161 // Validate destination.
175 Intent intent = mContext.getStartedIntent(0); 162 Intent intent = mContext.getStartedIntent(0);
176 validateIntentComponent(intent); 163 validateIntentComponent(intent);
177 assertEquals(IntentProtocol.ACTION_REGISTER, intent.getAction()); 164 assertEquals(IntentProtocol.ACTION_REGISTER, intent.getAction());
178 165
179 // Validate account. 166 // Validate account.
180 Account intentAccount = intent.getParcelableExtra(IntentProtocol.EXTRA_A CCOUNT); 167 Account intentAccount = intent.getParcelableExtra(IntentProtocol.EXTRA_A CCOUNT);
181 assertEquals(account, intentAccount); 168 assertEquals(account, intentAccount);
182 169
183 // Validate registered types. 170 // Validate registered types.
184 Set<String> expectedTypes = 171 Set<String> expectedTypes =
185 Sets.newHashSet(ModelType.BOOKMARK.name(), ModelType.SESSION.nam e()); 172 Sets.newHashSet(ModelType.BOOKMARK.name(), ModelType.SESSION.nam e());
186 Set<String> actualTypes = Sets.newHashSet(); 173 Set<String> actualTypes = Sets.newHashSet();
187 actualTypes.addAll(intent.getStringArrayListExtra(IntentProtocol.EXTRA_R EGISTERED_TYPES)); 174 actualTypes.addAll(intent.getStringArrayListExtra(IntentProtocol.EXTRA_R EGISTERED_TYPES));
188 assertEquals(expectedTypes, actualTypes); 175 assertEquals(expectedTypes, actualTypes);
189 assertTrue(mContext.isFlagSet(controllerFlag));
190 } 176 }
191 177
192 @SmallTest 178 @SmallTest
193 @Feature({"Sync"}) 179 @Feature({"Sync"})
194 public void testRegisterForAllTypes() { 180 public void testRegisterForAllTypes() {
195 Account account = new Account("test@example.com", "bogus"); 181 Account account = new Account("test@example.com", "bogus");
196 mController.setRegisteredTypes(account, true, 182 mController.setRegisteredTypes(account, true,
197 Sets.newHashSet(ModelType.BOOKMARK, ModelType.SESSION)); 183 Sets.newHashSet(ModelType.BOOKMARK, ModelType.SESSION));
198 assertEquals(1, mContext.getNumStartedIntents()); 184 assertEquals(1, mContext.getNumStartedIntents());
199 185
(...skipping 16 matching lines...) Expand all
216 @SmallTest 202 @SmallTest
217 @Feature({"Sync"}) 203 @Feature({"Sync"})
218 public void testRefreshShouldReadValuesFromDiskWithSpecificTypes() { 204 public void testRefreshShouldReadValuesFromDiskWithSpecificTypes() {
219 // Store some preferences for ModelTypes and account. We are using the h elper class 205 // Store some preferences for ModelTypes and account. We are using the h elper class
220 // for this, so we don't have to deal with low-level details such as pre ference keys. 206 // for this, so we don't have to deal with low-level details such as pre ference keys.
221 InvalidationPreferences invalidationPreferences = new InvalidationPrefer ences(mContext); 207 InvalidationPreferences invalidationPreferences = new InvalidationPrefer ences(mContext);
222 InvalidationPreferences.EditContext edit = invalidationPreferences.edit( ); 208 InvalidationPreferences.EditContext edit = invalidationPreferences.edit( );
223 Set<String> storedModelTypes = new HashSet<String>(); 209 Set<String> storedModelTypes = new HashSet<String>();
224 storedModelTypes.add(ModelType.BOOKMARK.name()); 210 storedModelTypes.add(ModelType.BOOKMARK.name());
225 storedModelTypes.add(ModelType.TYPED_URL.name()); 211 storedModelTypes.add(ModelType.TYPED_URL.name());
212 Set<ModelType> refreshedTypes = new HashSet<ModelType>();
213 refreshedTypes.add(ModelType.BOOKMARK);
214 refreshedTypes.add(ModelType.TYPED_URL);
226 invalidationPreferences.setSyncTypes(edit, storedModelTypes); 215 invalidationPreferences.setSyncTypes(edit, storedModelTypes);
227 Account storedAccount = AccountManagerHelper.createAccountFromName("test @gmail.com"); 216 Account storedAccount = AccountManagerHelper.createAccountFromName("test @gmail.com");
228 invalidationPreferences.setAccount(edit, storedAccount); 217 invalidationPreferences.setAccount(edit, storedAccount);
229 invalidationPreferences.commit(edit); 218 invalidationPreferences.commit(edit);
230 219
231 // Ensure all calls to {@link InvalidationController#setRegisteredTypes} store values 220 // Ensure all calls to {@link InvalidationController#setRegisteredTypes} store values
232 // we can inspect in the test. 221 // we can inspect in the test.
233 final AtomicReference<Account> resultAccount = new AtomicReference<Accou nt>(); 222 final AtomicReference<Account> resultAccount = new AtomicReference<Accou nt>();
234 final AtomicBoolean resultAllTypes = new AtomicBoolean(); 223 final AtomicBoolean resultAllTypes = new AtomicBoolean();
235 final AtomicReference<Set<ModelType>> resultTypes = new AtomicReference< Set<ModelType>>(); 224 final AtomicReference<Set<ModelType>> resultTypes = new AtomicReference< Set<ModelType>>();
236 InvalidationController controller = new InvalidationController(mContext) { 225 InvalidationController controller = new InvalidationController(mContext) {
237 @Override 226 @Override
238 public void setRegisteredTypes( 227 public void setRegisteredTypes(
239 Account account, boolean allTypes, Set<ModelType> types) { 228 Account account, boolean allTypes, Set<ModelType> types) {
240 resultAccount.set(account); 229 resultAccount.set(account);
241 resultAllTypes.set(allTypes); 230 resultAllTypes.set(allTypes);
242 resultTypes.set(types); 231 resultTypes.set(types);
243 } 232 }
244 }; 233 };
245 234
246 // Execute the test. 235 // Execute the test.
247 controller.refreshRegisteredTypes(); 236 controller.refreshRegisteredTypes(refreshedTypes);
248 237
249 // Validate the values. 238 // Validate the values.
250 assertEquals(storedAccount, resultAccount.get()); 239 assertEquals(storedAccount, resultAccount.get());
251 assertEquals(false, resultAllTypes.get()); 240 assertEquals(false, resultAllTypes.get());
252 assertEquals(ModelType.syncTypesToModelTypes(storedModelTypes), resultTy pes.get()); 241 assertEquals(ModelType.syncTypesToModelTypes(storedModelTypes), resultTy pes.get());
253 } 242 }
254 243
255 @SmallTest 244 @SmallTest
256 @Feature({"Sync"}) 245 @Feature({"Sync"})
257 public void testRefreshShouldReadValuesFromDiskWithAllTypes() { 246 public void testRefreshShouldReadValuesFromDiskWithAllTypes() {
(...skipping 18 matching lines...) Expand all
276 @Override 265 @Override
277 public void setRegisteredTypes( 266 public void setRegisteredTypes(
278 Account account, boolean allTypes, Set<ModelType> types) { 267 Account account, boolean allTypes, Set<ModelType> types) {
279 resultAccount.set(account); 268 resultAccount.set(account);
280 resultAllTypes.set(allTypes); 269 resultAllTypes.set(allTypes);
281 resultTypes.set(types); 270 resultTypes.set(types);
282 } 271 }
283 }; 272 };
284 273
285 // Execute the test. 274 // Execute the test.
286 controller.refreshRegisteredTypes(); 275 controller.refreshRegisteredTypes(new HashSet<ModelType>());
287 276
288 // Validate the values. 277 // Validate the values.
289 assertEquals(storedAccount, resultAccount.get()); 278 assertEquals(storedAccount, resultAccount.get());
290 assertEquals(true, resultAllTypes.get()); 279 assertEquals(true, resultAllTypes.get());
291 } 280 }
292 281
293 @SmallTest 282 @SmallTest
294 @Feature({"Sync"}) 283 @Feature({"Sync"})
295 public void testGetContractAuthority() throws Exception { 284 public void testGetContractAuthority() throws Exception {
296 assertEquals(mContext.getPackageName(), mController.getContractAuthority ()); 285 assertEquals(mContext.getPackageName(), mController.getContractAuthority ());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 Intent getStartedIntent(int idx) { 324 Intent getStartedIntent(int idx) {
336 return startedIntents.get(idx); 325 return startedIntents.get(idx);
337 } 326 }
338 327
339 @Override 328 @Override
340 public PackageManager getPackageManager() { 329 public PackageManager getPackageManager() {
341 return getBaseContext().getPackageManager(); 330 return getBaseContext().getPackageManager();
342 } 331 }
343 } 332 }
344 } 333 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698