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

Side by Side Diff: chrome/android/sync_shell/javatests/src/chromium/chrome/browser/sync/SyncTest.java

Issue 457883002: Use Sync FakeServer in Android tests via custom APK (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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.chrome.browser.sync; 5 package org.chromium.chrome.browser.sync;
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.test.suitebuilder.annotation.LargeTest;
9 import android.util.Log; 10 import android.util.Log;
10 11
11 import org.chromium.base.ThreadUtils; 12 import org.chromium.base.ThreadUtils;
12 import org.chromium.base.test.util.HostDrivenTest; 13 import org.chromium.base.test.util.Feature;
13 import org.chromium.chrome.browser.identity.UniqueIdentificationGenerator; 14 import org.chromium.chrome.browser.identity.UniqueIdentificationGenerator;
14 import org.chromium.chrome.browser.identity.UniqueIdentificationGeneratorFactory ; 15 import org.chromium.chrome.browser.identity.UniqueIdentificationGeneratorFactory ;
15 import org.chromium.chrome.browser.identity.UuidBasedUniqueIdentificationGenerat or; 16 import org.chromium.chrome.browser.identity.UuidBasedUniqueIdentificationGenerat or;
16 import org.chromium.chrome.shell.ChromeShellActivity; 17 import org.chromium.chrome.shell.ChromeShellActivity;
17 import org.chromium.chrome.shell.ChromeShellTestBase; 18 import org.chromium.chrome.shell.ChromeShellTestBase;
18 import org.chromium.chrome.shell.sync.SyncController; 19 import org.chromium.chrome.shell.sync.SyncController;
19 import org.chromium.chrome.test.util.browser.sync.SyncTestUtil; 20 import org.chromium.chrome.test.util.browser.sync.SyncTestUtil;
20 import org.chromium.content.browser.ContentViewCore; 21 import org.chromium.content.browser.ContentViewCore;
21 import org.chromium.content.browser.test.util.Criteria; 22 import org.chromium.content.browser.test.util.Criteria;
22 import org.chromium.content.browser.test.util.CriteriaHelper; 23 import org.chromium.content.browser.test.util.CriteriaHelper;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 SyncStatusHelper.overrideSyncStatusHelperForTests(mContext, syncContentR esolverDelegate); 59 SyncStatusHelper.overrideSyncStatusHelperForTests(mContext, syncContentR esolverDelegate);
59 // This call initializes the ChromeSigninController to use our test cont ext. 60 // This call initializes the ChromeSigninController to use our test cont ext.
60 ChromeSigninController.get(mContext); 61 ChromeSigninController.get(mContext);
61 startChromeBrowserProcessSync(getInstrumentation().getTargetContext()); 62 startChromeBrowserProcessSync(getInstrumentation().getTargetContext());
62 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 63 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
63 @Override 64 @Override
64 public void run() { 65 public void run() {
65 mSyncController = SyncController.get(mContext); 66 mSyncController = SyncController.get(mContext);
66 } 67 }
67 }); 68 });
68 SyncTestUtil.verifySyncServerIsRunning(); 69 FakeServerHelper.useFakeServer(getInstrumentation().getTargetContext());
69 } 70 }
70 71
71 @HostDrivenTest 72 @Override
73 protected void tearDown() throws Exception {
74 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
75 @Override
76 public void run() {
77 mSyncController.stop();
78 FakeServerHelper.deleteFakeServer();
79 }
80 });
81
82 super.tearDown();
83 }
84
85 @LargeTest
86 @Feature({"Sync"})
72 public void testGetAboutSyncInfoYieldsValidData() throws Throwable { 87 public void testGetAboutSyncInfoYieldsValidData() throws Throwable {
73 setupTestAccountAndSignInToSync(FOREIGN_SESSION_TEST_MACHINE_ID); 88 setupTestAccountAndSignInToSync(FOREIGN_SESSION_TEST_MACHINE_ID);
74 89
75 final SyncTestUtil.AboutSyncInfoGetter syncInfoGetter = 90 final SyncTestUtil.AboutSyncInfoGetter syncInfoGetter =
76 new SyncTestUtil.AboutSyncInfoGetter(getActivity()); 91 new SyncTestUtil.AboutSyncInfoGetter(getActivity());
77 runTestOnUiThread(syncInfoGetter); 92 runTestOnUiThread(syncInfoGetter);
78 93
79 boolean gotInfo = CriteriaHelper.pollForCriteria(new Criteria() { 94 boolean gotInfo = CriteriaHelper.pollForCriteria(new Criteria() {
80 @Override 95 @Override
81 public boolean isSatisfied() { 96 public boolean isSatisfied() {
82 return !syncInfoGetter.getAboutInfo().isEmpty(); 97 return !syncInfoGetter.getAboutInfo().isEmpty();
83 } 98 }
84 }, SyncTestUtil.UI_TIMEOUT_MS, SyncTestUtil.CHECK_INTERVAL_MS); 99 }, SyncTestUtil.UI_TIMEOUT_MS, SyncTestUtil.CHECK_INTERVAL_MS);
85 100
86 assertTrue("Couldn't get about info.", gotInfo); 101 assertTrue("Couldn't get about info.", gotInfo);
87 } 102 }
88 103
89 @HostDrivenTest 104 @LargeTest
105 @Feature({"Sync"})
90 public void testAboutSyncPageDisplaysCurrentSyncStatus() throws InterruptedE xception { 106 public void testAboutSyncPageDisplaysCurrentSyncStatus() throws InterruptedE xception {
91 setupTestAccountAndSignInToSync(FOREIGN_SESSION_TEST_MACHINE_ID); 107 setupTestAccountAndSignInToSync(FOREIGN_SESSION_TEST_MACHINE_ID);
92 108
93 loadUrlWithSanitization("chrome://sync"); 109 loadUrlWithSanitization("chrome://sync");
94 SyncTestUtil.AboutSyncInfoGetter aboutInfoGetter = 110 SyncTestUtil.AboutSyncInfoGetter aboutInfoGetter =
95 new SyncTestUtil.AboutSyncInfoGetter(getActivity()); 111 new SyncTestUtil.AboutSyncInfoGetter(getActivity());
96 try { 112 try {
97 runTestOnUiThread(aboutInfoGetter); 113 runTestOnUiThread(aboutInfoGetter);
98 } catch (Throwable t) { 114 } catch (Throwable t) {
99 Log.w(TAG, 115 Log.w(TAG,
(...skipping 23 matching lines...) Expand all
123 return innerHtml.contains(expectedSyncSummary); 139 return innerHtml.contains(expectedSyncSummary);
124 } 140 }
125 141
126 }; 142 };
127 boolean hadExpectedStatus = CriteriaHelper.pollForCriteria( 143 boolean hadExpectedStatus = CriteriaHelper.pollForCriteria(
128 checker, SyncTestUtil.UI_TIMEOUT_MS, SyncTestUtil.CHECK_INTERVAL _MS); 144 checker, SyncTestUtil.UI_TIMEOUT_MS, SyncTestUtil.CHECK_INTERVAL _MS);
129 assertTrue("Sync status not present on about sync page: " + expectedSync Summary, 145 assertTrue("Sync status not present on about sync page: " + expectedSync Summary,
130 hadExpectedStatus); 146 hadExpectedStatus);
131 } 147 }
132 148
133 @HostDrivenTest 149 @LargeTest
150 @Feature({"Sync"})
134 public void testDisableAndEnableSync() throws InterruptedException { 151 public void testDisableAndEnableSync() throws InterruptedException {
135 setupTestAccountAndSignInToSync(FOREIGN_SESSION_TEST_MACHINE_ID); 152 setupTestAccountAndSignInToSync(FOREIGN_SESSION_TEST_MACHINE_ID);
136 Account account = 153 Account account =
137 AccountManagerHelper.createAccountFromName(SyncTestUtil.DEFAULT_ TEST_ACCOUNT); 154 AccountManagerHelper.createAccountFromName(SyncTestUtil.DEFAULT_ TEST_ACCOUNT);
138 155
139 // Disabling Android sync should turn Chrome sync engine off. 156 // Disabling Android sync should turn Chrome sync engine off.
140 SyncStatusHelper.get(mContext).disableAndroidSync(account); 157 SyncStatusHelper.get(mContext).disableAndroidSync(account);
141 SyncTestUtil.verifySyncIsDisabled(mContext, account); 158 SyncTestUtil.verifySyncIsDisabled(mContext, account);
142 159
143 // Enabling Android sync should turn Chrome sync engine on. 160 // Enabling Android sync should turn Chrome sync engine on.
(...skipping 29 matching lines...) Expand all
173 190
174 SyncTestUtil.verifySyncIsSignedIn(mContext, defaultTestAccount); 191 SyncTestUtil.verifySyncIsSignedIn(mContext, defaultTestAccount);
175 assertTrue("Sync everything should be enabled", 192 assertTrue("Sync everything should be enabled",
176 SyncTestUtil.isSyncEverythingEnabled(mContext)); 193 SyncTestUtil.isSyncEverythingEnabled(mContext));
177 } 194 }
178 195
179 private static ContentViewCore getContentViewCore(ChromeShellActivity activi ty) { 196 private static ContentViewCore getContentViewCore(ChromeShellActivity activi ty) {
180 return activity.getActiveContentViewCore(); 197 return activity.getActiveContentViewCore();
181 } 198 }
182 } 199 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698