@SmallTest @Feature({"Sync"}) public void testStart() throws Exception { mController.start(); assertEquals(1, mContext.getNumStartedIntents()); Intent intent = mContext.getStartedIntent(0); validateIntentComponent(intent); assertNull(intent.getExtras()); }
@SmallTest @Feature({"Sync"}) public void testResumingMainActivity() throws Exception { // Resuming main activity should trigger a start if sync is enabled. setupSync(true); mController.onActivityStateChange(ActivityStatus.RESUMED); assertEquals(1, mContext.getNumStartedIntents()); Intent intent = mContext.getStartedIntent(0); validateIntentComponent(intent); assertNull(intent.getExtras()); }
@SmallTest @Feature({"Sync"}) public void testStop() throws Exception { mController.stop(); assertEquals(1, mContext.getNumStartedIntents()); Intent intent = mContext.getStartedIntent(0); validateIntentComponent(intent); assertEquals(1, intent.getExtras().size()); assertTrue(intent.hasExtra(IntentProtocol.EXTRA_STOP)); assertTrue(intent.getBooleanExtra(IntentProtocol.EXTRA_STOP, false)); }
@SmallTest @Feature({"Sync"}) public void testPausingMainActivity() throws Exception { // Resuming main activity should trigger a stop if sync is enabled. setupSync(true); mController.onActivityStateChange(ActivityStatus.PAUSED); assertEquals(1, mContext.getNumStartedIntents()); Intent intent = mContext.getStartedIntent(0); validateIntentComponent(intent); assertEquals(1, intent.getExtras().size()); assertTrue(intent.hasExtra(IntentProtocol.EXTRA_STOP)); assertTrue(intent.getBooleanExtra(IntentProtocol.EXTRA_STOP, false)); }
@SmallTest @Feature({"Sync"}) public void testResumingMainActivityWithSyncDisabled() throws Exception { // Resuming main activity should NOT trigger a start if sync is disabled. setupSync(false); mController.onActivityStateChange(ActivityStatus.RESUMED); assertEquals(0, mContext.getNumStartedIntents()); }
@SmallTest @Feature({"Sync"}) public void testRegisterForSpecificTypes() { final String controllerFlag = "resolveModelTypes"; final ModelTypeResolver resolver = new ModelTypeResolver() { @Override public Set<ModelType> resolveModelTypes(Set<ModelType> modelTypes) { mContext.setFlag(controllerFlag); return modelTypes; } }; InvalidationController controller = new InvalidationController(mContext) { @Override ModelTypeResolver getModelTypeResolver() { return resolver; } }; Account account = new Account("*****@*****.**", "bogus"); controller.setRegisteredTypes( account, false, Sets.newHashSet(ModelType.BOOKMARK, ModelType.SESSION)); assertEquals(1, mContext.getNumStartedIntents()); // Validate destination. Intent intent = mContext.getStartedIntent(0); validateIntentComponent(intent); assertEquals(IntentProtocol.ACTION_REGISTER, intent.getAction()); // Validate account. Account intentAccount = intent.getParcelableExtra(IntentProtocol.EXTRA_ACCOUNT); assertEquals(account, intentAccount); // Validate registered types. Set<String> expectedTypes = Sets.newHashSet(ModelType.BOOKMARK.name(), ModelType.SESSION.name()); Set<String> actualTypes = Sets.newHashSet(); actualTypes.addAll(intent.getStringArrayListExtra(IntentProtocol.EXTRA_REGISTERED_TYPES)); assertEquals(expectedTypes, actualTypes); assertTrue(mContext.isFlagSet(controllerFlag)); }
@SmallTest @Feature({"Sync"}) public void testRegisterForAllTypes() { Account account = new Account("*****@*****.**", "bogus"); mController.setRegisteredTypes( account, true, Sets.newHashSet(ModelType.BOOKMARK, ModelType.SESSION)); assertEquals(1, mContext.getNumStartedIntents()); // Validate destination. Intent intent = mContext.getStartedIntent(0); validateIntentComponent(intent); assertEquals(IntentProtocol.ACTION_REGISTER, intent.getAction()); // Validate account. Account intentAccount = intent.getParcelableExtra(IntentProtocol.EXTRA_ACCOUNT); assertEquals(account, intentAccount); // Validate registered types. Set<String> expectedTypes = Sets.newHashSet(ModelType.ALL_TYPES_TYPE); Set<String> actualTypes = Sets.newHashSet(); actualTypes.addAll(intent.getStringArrayListExtra(IntentProtocol.EXTRA_REGISTERED_TYPES)); assertEquals(expectedTypes, actualTypes); }
@SmallTest @Feature({"Sync"}) public void testGetContractAuthority() throws Exception { assertEquals(mContext.getPackageName(), mController.getContractAuthority()); }