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

Side by Side Diff: chrome/android/junit/src/org/chromium/chrome/browser/invalidation/InvalidationControllerTest.java

Issue 2872743003: Change AccountManagerHelper initialization
Patch Set: Created 3 years, 7 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 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.invalidation; 5 package org.chromium.chrome.browser.invalidation;
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.Context; 9 import android.content.Context;
10 import android.content.Intent; 10 import android.content.Intent;
11 import android.content.pm.ApplicationInfo; 11 import android.content.pm.ApplicationInfo;
12 import android.content.pm.PackageInfo; 12 import android.content.pm.PackageInfo;
13 import android.os.Bundle; 13 import android.os.Bundle;
14 14
15 import org.junit.After;
16 import org.junit.Assert; 15 import org.junit.Assert;
17 import org.junit.Before; 16 import org.junit.Before;
17 import org.junit.BeforeClass;
18 import org.junit.Test; 18 import org.junit.Test;
19 import org.junit.runner.RunWith; 19 import org.junit.runner.RunWith;
20 import org.robolectric.Robolectric; 20 import org.robolectric.Robolectric;
21 import org.robolectric.Shadows; 21 import org.robolectric.Shadows;
22 import org.robolectric.annotation.Config; 22 import org.robolectric.annotation.Config;
23 import org.robolectric.res.builder.RobolectricPackageManager; 23 import org.robolectric.res.builder.RobolectricPackageManager;
24 import org.robolectric.shadows.ShadowActivity; 24 import org.robolectric.shadows.ShadowActivity;
25 import org.robolectric.shadows.ShadowLooper; 25 import org.robolectric.shadows.ShadowLooper;
26 26
27 import org.chromium.base.ActivityState; 27 import org.chromium.base.ActivityState;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 /** 86 /**
87 * The names of the preferred ModelTypes. 87 * The names of the preferred ModelTypes.
88 */ 88 */
89 private Set<String> mAllTypes; 89 private Set<String> mAllTypes;
90 90
91 /** 91 /**
92 * The names of the non-session preferred ModelTypes. 92 * The names of the non-session preferred ModelTypes.
93 */ 93 */
94 private Set<String> mNonSessionTypes; 94 private Set<String> mNonSessionTypes;
95 95
96 @BeforeClass
97 public static void overrideAccountManagerHelper() {
98 AccountManagerHelper.overrideAccountManagerHelperForTests(
99 new SystemAccountManagerDelegate());
100 }
101
96 @Before 102 @Before
97 public void setUp() throws Exception { 103 public void setUp() throws Exception {
98 Activity activity = Robolectric.buildActivity(Activity.class).setup().ge t(); 104 Activity activity = Robolectric.buildActivity(Activity.class).setup().ge t();
99 mShadowActivity = Shadows.shadowOf(activity); 105 mShadowActivity = Shadows.shadowOf(activity);
100 mContext = activity; 106 mContext = activity;
101 107
102 RobolectricPackageManager packageManager = 108 RobolectricPackageManager packageManager =
103 (RobolectricPackageManager) mContext.getPackageManager(); 109 (RobolectricPackageManager) mContext.getPackageManager();
104 Bundle metaData = new Bundle(); 110 Bundle metaData = new Bundle();
105 metaData.putString( 111 metaData.putString(
106 "ipc.invalidation.ticl.listener_service_class", 112 "ipc.invalidation.ticl.listener_service_class",
107 ChromeInvalidationClientService.class.getName()); 113 ChromeInvalidationClientService.class.getName());
108 ApplicationInfo applicationInfo = new ApplicationInfo(); 114 ApplicationInfo applicationInfo = new ApplicationInfo();
109 applicationInfo.metaData = metaData; 115 applicationInfo.metaData = metaData;
110 PackageInfo packageInfo = new PackageInfo(); 116 PackageInfo packageInfo = new PackageInfo();
111 packageInfo.packageName = mContext.getPackageName(); 117 packageInfo.packageName = mContext.getPackageName();
112 packageInfo.applicationInfo = applicationInfo; 118 packageInfo.applicationInfo = applicationInfo;
113 packageManager.addPackage(packageInfo); 119 packageManager.addPackage(packageInfo);
114 120
115 ContextUtils.initApplicationContextForTests(mContext.getApplicationConte xt()); 121 ContextUtils.initApplicationContextForTests(mContext.getApplicationConte xt());
116 122
117 AccountManagerHelper.overrideAccountManagerHelperForTests(
118 mContext, new SystemAccountManagerDelegate());
119
120 ModelTypeHelper.setTestDelegate(new ModelTypeHelper.TestDelegate() { 123 ModelTypeHelper.setTestDelegate(new ModelTypeHelper.TestDelegate() {
121 @Override 124 @Override
122 public String toNotificationType(int modelType) { 125 public String toNotificationType(int modelType) {
123 return Integer.toString(modelType); 126 return Integer.toString(modelType);
124 } 127 }
125 }); 128 });
126 129
127 ProfileSyncServiceStub profileSyncServiceStub = new ProfileSyncServiceSt ub(); 130 ProfileSyncServiceStub profileSyncServiceStub = new ProfileSyncServiceSt ub();
128 ProfileSyncService.overrideForTests(profileSyncServiceStub); 131 ProfileSyncService.overrideForTests(profileSyncServiceStub);
129 profileSyncServiceStub.setPreferredDataTypes( 132 profileSyncServiceStub.setPreferredDataTypes(
130 CollectionUtil.newHashSet(ModelType.BOOKMARKS, ModelType.SESSION S)); 133 CollectionUtil.newHashSet(ModelType.BOOKMARKS, ModelType.SESSION S));
131 mAllTypes = CollectionUtil.newHashSet( 134 mAllTypes = CollectionUtil.newHashSet(
132 ModelTypeHelper.toNotificationType(ModelType.BOOKMARKS), 135 ModelTypeHelper.toNotificationType(ModelType.BOOKMARKS),
133 ModelTypeHelper.toNotificationType(ModelType.SESSIONS)); 136 ModelTypeHelper.toNotificationType(ModelType.SESSIONS));
134 mNonSessionTypes = CollectionUtil.newHashSet(ModelTypeHelper.toNotificat ionType( 137 mNonSessionTypes = CollectionUtil.newHashSet(ModelTypeHelper.toNotificat ionType(
135 ModelType.BOOKMARKS)); 138 ModelType.BOOKMARKS));
136 139
137 // We don't want to use the system content resolver, so we override it. 140 // We don't want to use the system content resolver, so we override it.
138 MockSyncContentResolverDelegate delegate = new MockSyncContentResolverDe legate(); 141 MockSyncContentResolverDelegate delegate = new MockSyncContentResolverDe legate();
139 // Android master sync can safely always be on. 142 // Android master sync can safely always be on.
140 delegate.setMasterSyncAutomatically(true); 143 delegate.setMasterSyncAutomatically(true);
141 AndroidSyncSettings.overrideForTests(mContext, delegate); 144 AndroidSyncSettings.overrideForTests(mContext, delegate);
142 145
143 ChromeSigninController.get().setSignedInAccountName("test@example.com"); 146 ChromeSigninController.get().setSignedInAccountName("test@example.com");
144 AndroidSyncSettings.updateAccount(mContext, ChromeSigninController.get() .getSignedInUser()); 147 AndroidSyncSettings.updateAccount(mContext, ChromeSigninController.get() .getSignedInUser());
145 AndroidSyncSettings.enableChromeSync(mContext); 148 AndroidSyncSettings.enableChromeSync(mContext);
146 } 149 }
147 150
148 @After
149 public void tearDown() {
150 AccountManagerHelper.resetAccountManagerHelperForTests();
151 }
152
153 /** 151 /**
154 * Verify the intent sent by InvalidationController#stop(). 152 * Verify the intent sent by InvalidationController#stop().
155 */ 153 */
156 @Test 154 @Test
157 @Feature({"Sync"}) 155 @Feature({"Sync"})
158 public void testStop() throws Exception { 156 public void testStop() throws Exception {
159 InvalidationController controller = new InvalidationController(mContext, true); 157 InvalidationController controller = new InvalidationController(mContext, true);
160 controller.stop(); 158 controller.stop();
161 Intent intent = getOnlyIntent(); 159 Intent intent = getOnlyIntent();
162 validateIntentComponent(intent); 160 validateIntentComponent(intent);
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 * intent. 506 * intent.
509 */ 507 */
510 private static Set<String> getRegisterIntentRegisterTypes(Intent intent) { 508 private static Set<String> getRegisterIntentRegisterTypes(Intent intent) {
511 Set<String> registeredTypes = new HashSet<String>(); 509 Set<String> registeredTypes = new HashSet<String>();
512 registeredTypes.addAll( 510 registeredTypes.addAll(
513 intent.getStringArrayListExtra(InvalidationIntentProtocol.EXTRA_ REGISTERED_TYPES)); 511 intent.getStringArrayListExtra(InvalidationIntentProtocol.EXTRA_ REGISTERED_TYPES));
514 return registeredTypes; 512 return registeredTypes;
515 } 513 }
516 514
517 } 515 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698