| 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.signin; | 5 package org.chromium.chrome.browser.signin; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.app.DialogFragment; | 8 import android.app.DialogFragment; |
| 9 import android.app.Fragment; | 9 import android.app.Fragment; |
| 10 import android.app.Instrumentation.ActivityMonitor; | 10 import android.app.Instrumentation.ActivityMonitor; |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 203 |
| 204 super.setUp(); | 204 super.setUp(); |
| 205 | 205 |
| 206 mContext = getInstrumentation().getTargetContext(); | 206 mContext = getInstrumentation().getTargetContext(); |
| 207 final TestSignInAllowedObserver signinAllowedObserver = new TestSignInAl
lowedObserver(); | 207 final TestSignInAllowedObserver signinAllowedObserver = new TestSignInAl
lowedObserver(); |
| 208 | 208 |
| 209 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 209 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 210 @Override | 210 @Override |
| 211 public void run() { | 211 public void run() { |
| 212 // This call initializes the ChromeSigninController to use our t
est context. | 212 // This call initializes the ChromeSigninController to use our t
est context. |
| 213 ChromeSigninController.get(); | 213 ChromeSigninController.get(mContext); |
| 214 | 214 |
| 215 // Start observing the SigninManager. | 215 // Start observing the SigninManager. |
| 216 mTestSignInObserver = new TestSignInObserver(); | 216 mTestSignInObserver = new TestSignInObserver(); |
| 217 mSigninManager = SigninManager.get(mContext); | 217 mSigninManager = SigninManager.get(mContext); |
| 218 mSigninManager.addSignInStateObserver(mTestSignInObserver); | 218 mSigninManager.addSignInStateObserver(mTestSignInObserver); |
| 219 | 219 |
| 220 // Get these handles in the UI thread. | 220 // Get these handles in the UI thread. |
| 221 mPrefService = PrefServiceBridge.getInstance(); | 221 mPrefService = PrefServiceBridge.getInstance(); |
| 222 Profile profile = getActivity().getActivityTab().getProfile(); | 222 Profile profile = getActivity().getActivityTab().getProfile(); |
| 223 mBookmarks = new BookmarkBridge(profile); | 223 mBookmarks = new BookmarkBridge(profile); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 246 | 246 |
| 247 @Override | 247 @Override |
| 248 protected void tearDown() throws Exception { | 248 protected void tearDown() throws Exception { |
| 249 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 249 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 250 @Override | 250 @Override |
| 251 public void run() { | 251 public void run() { |
| 252 mBookmarks.removeObserver(mTestBookmarkModelObserver); | 252 mBookmarks.removeObserver(mTestBookmarkModelObserver); |
| 253 | 253 |
| 254 mSigninManager.removeSignInStateObserver(mTestSignInObserver); | 254 mSigninManager.removeSignInStateObserver(mTestSignInObserver); |
| 255 | 255 |
| 256 if (ChromeSigninController.get().isSignedIn()) { | 256 if (ChromeSigninController.get(mContext).isSignedIn()) { |
| 257 mSigninManager.signOut(null, null); | 257 mSigninManager.signOut(null, null); |
| 258 } | 258 } |
| 259 | 259 |
| 260 mBookmarks.destroy(); | 260 mBookmarks.destroy(); |
| 261 } | 261 } |
| 262 }); | 262 }); |
| 263 super.tearDown(); | 263 super.tearDown(); |
| 264 } | 264 } |
| 265 | 265 |
| 266 @Override | 266 @Override |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 public void run() { | 305 public void run() { |
| 306 // Verify that the profile data hasn't been wiped when signing o
ut of a normal | 306 // Verify that the profile data hasn't been wiped when signing o
ut of a normal |
| 307 // account. We check that by looking for the test bookmark from
setUp(). | 307 // account. We check that by looking for the test bookmark from
setUp(). |
| 308 assertEquals(1, mBookmarks.getChildCount(mBookmarks.getMobileFol
derId())); | 308 assertEquals(1, mBookmarks.getChildCount(mBookmarks.getMobileFol
derId())); |
| 309 } | 309 } |
| 310 }); | 310 }); |
| 311 } | 311 } |
| 312 | 312 |
| 313 private void signInToSingleAccount() { | 313 private void signInToSingleAccount() { |
| 314 // Verify that we aren't signed in yet. | 314 // Verify that we aren't signed in yet. |
| 315 assertFalse(ChromeSigninController.get().isSignedIn()); | 315 assertFalse(ChromeSigninController.get(mContext).isSignedIn()); |
| 316 | 316 |
| 317 // Open the preferences UI. | 317 // Open the preferences UI. |
| 318 final Preferences prefActivity = startPreferences(null); | 318 final Preferences prefActivity = startPreferences(null); |
| 319 getInstrumentation().waitForIdleSync(); | 319 getInstrumentation().waitForIdleSync(); |
| 320 | 320 |
| 321 // Create a monitor to catch the AccountSigninActivity when it is create
d. | 321 // Create a monitor to catch the AccountSigninActivity when it is create
d. |
| 322 ActivityMonitor monitor = getInstrumentation().addMonitor( | 322 ActivityMonitor monitor = getInstrumentation().addMonitor( |
| 323 AccountSigninActivity.class.getName(), null, false); | 323 AccountSigninActivity.class.getName(), null, false); |
| 324 | 324 |
| 325 // Click sign in. | 325 // Click sign in. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 350 syncService.setFirstSetupComplete(); | 350 syncService.setFirstSetupComplete(); |
| 351 syncService.setSetupInProgress(false); | 351 syncService.setSetupInProgress(false); |
| 352 } | 352 } |
| 353 }); | 353 }); |
| 354 prefActivity.finish(); | 354 prefActivity.finish(); |
| 355 | 355 |
| 356 // Verify that signin succeeded. | 356 // Verify that signin succeeded. |
| 357 mTestSignInObserver.waitForSignInEvents(1); | 357 mTestSignInObserver.waitForSignInEvents(1); |
| 358 assertEquals(1, mTestSignInObserver.mSignInCount); | 358 assertEquals(1, mTestSignInObserver.mSignInCount); |
| 359 assertEquals(0, mTestSignInObserver.mSignOutCount); | 359 assertEquals(0, mTestSignInObserver.mSignOutCount); |
| 360 assertTrue(ChromeSigninController.get().isSignedIn()); | 360 assertTrue(ChromeSigninController.get(mContext).isSignedIn()); |
| 361 } | 361 } |
| 362 | 362 |
| 363 private void signOut() { | 363 private void signOut() { |
| 364 // Verify that we are currently signed in. | 364 // Verify that we are currently signed in. |
| 365 assertTrue(ChromeSigninController.get().isSignedIn()); | 365 assertTrue(ChromeSigninController.get(mContext).isSignedIn()); |
| 366 | 366 |
| 367 // Open the account preferences. | 367 // Open the account preferences. |
| 368 final Preferences prefActivity = | 368 final Preferences prefActivity = |
| 369 startPreferences(AccountManagementFragment.class.getName()); | 369 startPreferences(AccountManagementFragment.class.getName()); |
| 370 getInstrumentation().waitForIdleSync(); | 370 getInstrumentation().waitForIdleSync(); |
| 371 | 371 |
| 372 // Click on the signout button. | 372 // Click on the signout button. |
| 373 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 373 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 374 @Override | 374 @Override |
| 375 public void run() { | 375 public void run() { |
| 376 clickSignOut(prefActivity); | 376 clickSignOut(prefActivity); |
| 377 } | 377 } |
| 378 }); | 378 }); |
| 379 | 379 |
| 380 // Accept the warning dialog. | 380 // Accept the warning dialog. |
| 381 acceptAlertDialogWithTag(prefActivity, AccountManagementFragment.SIGN_OU
T_DIALOG_TAG); | 381 acceptAlertDialogWithTag(prefActivity, AccountManagementFragment.SIGN_OU
T_DIALOG_TAG); |
| 382 | 382 |
| 383 // Verify that signout succeeded. | 383 // Verify that signout succeeded. |
| 384 mTestSignInObserver.waitForSignInEvents(2); | 384 mTestSignInObserver.waitForSignInEvents(2); |
| 385 assertEquals(1, mTestSignInObserver.mSignInCount); | 385 assertEquals(1, mTestSignInObserver.mSignInCount); |
| 386 assertEquals(1, mTestSignInObserver.mSignOutCount); | 386 assertEquals(1, mTestSignInObserver.mSignOutCount); |
| 387 assertFalse(ChromeSigninController.get().isSignedIn()); | 387 assertFalse(ChromeSigninController.get(mContext).isSignedIn()); |
| 388 | 388 |
| 389 if (!prefActivity.isFinishing()) prefActivity.finish(); | 389 if (!prefActivity.isFinishing()) prefActivity.finish(); |
| 390 getInstrumentation().waitForIdleSync(); | 390 getInstrumentation().waitForIdleSync(); |
| 391 } | 391 } |
| 392 | 392 |
| 393 private static MainPreferences getMainPreferences(Preferences prefActivity)
{ | 393 private static MainPreferences getMainPreferences(Preferences prefActivity)
{ |
| 394 Fragment fragment = prefActivity.getFragmentForTest(); | 394 Fragment fragment = prefActivity.getFragmentForTest(); |
| 395 assertNotNull(fragment); | 395 assertNotNull(fragment); |
| 396 assertTrue(fragment instanceof MainPreferences); | 396 assertTrue(fragment instanceof MainPreferences); |
| 397 return (MainPreferences) fragment; | 397 return (MainPreferences) fragment; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 422 getInstrumentation().waitForIdleSync(); | 422 getInstrumentation().waitForIdleSync(); |
| 423 DialogFragment fragment = ActivityUtils.waitForFragment(activity, tag); | 423 DialogFragment fragment = ActivityUtils.waitForFragment(activity, tag); |
| 424 AlertDialog dialog = (AlertDialog) fragment.getDialog(); | 424 AlertDialog dialog = (AlertDialog) fragment.getDialog(); |
| 425 assertTrue(dialog != null); | 425 assertTrue(dialog != null); |
| 426 assertTrue(dialog.isShowing()); | 426 assertTrue(dialog.isShowing()); |
| 427 Button button = dialog.getButton(DialogInterface.BUTTON_POSITIVE); | 427 Button button = dialog.getButton(DialogInterface.BUTTON_POSITIVE); |
| 428 assertNotNull("Could not find the accept button.", button); | 428 assertNotNull("Could not find the accept button.", button); |
| 429 TestTouchUtils.performClickOnMainSync(getInstrumentation(), button); | 429 TestTouchUtils.performClickOnMainSync(getInstrumentation(), button); |
| 430 } | 430 } |
| 431 } | 431 } |
| OLD | NEW |