Skip to content

Refactor chooseAccountActivity #357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 114 commits into from
Nov 23, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
05ce3b5
temporary: saving to work on another computer
SUPERCILEX Oct 7, 2016
2391efb
Merge remote-tracking branch 'firebase/master' into refactor-zombie-a…
SUPERCILEX Oct 8, 2016
05a476a
Merge remote-tracking branch 'firebase/master' into refactor-zombie-a…
SUPERCILEX Oct 14, 2016
2c0eaf5
Code compiles
SUPERCILEX Oct 14, 2016
8adeee1
Cleanup
SUPERCILEX Oct 14, 2016
11f3c2b
Cleanup
SUPERCILEX Oct 14, 2016
cb826f4
Cleanup
SUPERCILEX Oct 14, 2016
3b788f5
Update SmartLock.java with new fragment logic
SUPERCILEX Oct 14, 2016
9eaa4cd
Fix bug in SmartLock.java
SUPERCILEX Oct 14, 2016
3b76ac6
Cleanup
SUPERCILEX Oct 14, 2016
86d58a9
Cleanup
SUPERCILEX Oct 14, 2016
6ad0021
Fix broken tests
SUPERCILEX Oct 14, 2016
550acc9
Cleanup
SUPERCILEX Oct 14, 2016
b9d3ca5
Cleanup
SUPERCILEX Oct 15, 2016
a8b5cf5
Cleanup
SUPERCILEX Oct 15, 2016
83e13d8
Refactor SaveSmartLock.java
SUPERCILEX Oct 15, 2016
c529171
Initial refactor
SUPERCILEX Oct 16, 2016
5142dec
Cleanup
SUPERCILEX Oct 16, 2016
361d308
Cleanup
SUPERCILEX Oct 16, 2016
9a4921e
Bug fix
SUPERCILEX Oct 16, 2016
6af7674
Cleanup
SUPERCILEX Oct 16, 2016
35d94bb
Cleanup
SUPERCILEX Oct 16, 2016
64728b2
Cleanup and bug fixes
SUPERCILEX Oct 16, 2016
dde4160
Cleanup
SUPERCILEX Oct 16, 2016
2d5dfdc
Cleanup
SUPERCILEX Oct 16, 2016
f3bd0f1
Fix intellij messing up documentation.
SUPERCILEX Oct 16, 2016
f06845b
Cleanup
SUPERCILEX Oct 16, 2016
9782793
Cleanup
SUPERCILEX Oct 16, 2016
7d1d1c6
Remove unused strings
SUPERCILEX Oct 16, 2016
20413ee
Cleanup
SUPERCILEX Oct 16, 2016
7842c48
Refactor progress hiding and delegateSignIn()
SUPERCILEX Oct 16, 2016
135d2c5
Cleanup sample
SUPERCILEX Oct 16, 2016
23ae513
Fix null pointer for low memory devices
SUPERCILEX Oct 17, 2016
25eb137
Fix for #171
SUPERCILEX Oct 17, 2016
be7e0c3
Fix for #152
SUPERCILEX Oct 17, 2016
07beeb3
Force activity to implement onResult
SUPERCILEX Oct 17, 2016
13122c3
Fix smart lock failed flow
SUPERCILEX Oct 17, 2016
862b884
make it compile
SUPERCILEX Oct 17, 2016
a7b3336
Relaxed activity requirements to FragmentActivity
SUPERCILEX Oct 18, 2016
db96c91
Cleanup
SUPERCILEX Oct 18, 2016
19bde41
Add interface to SmartLock
SUPERCILEX Oct 18, 2016
96027d0
Merge remote-tracking branch 'firebase/version-1.0.0-dev' into refact…
SUPERCILEX Oct 18, 2016
9511a6d
Merge dev
SUPERCILEX Oct 18, 2016
cbe0cfb
working on tests
SUPERCILEX Oct 19, 2016
a81bf5a
working on tests
SUPERCILEX Oct 19, 2016
db05831
Revert interface, working on fixing tests
SUPERCILEX Oct 19, 2016
8c96216
Fix tests
SUPERCILEX Oct 19, 2016
d333302
Merge remote-tracking branch 'firebase/version-1.0.0-dev' into refact…
SUPERCILEX Oct 19, 2016
cb6efad
Merge dev
SUPERCILEX Oct 19, 2016
af644be
Fix merge mistakes
SUPERCILEX Oct 19, 2016
4152c23
Cleanup
SUPERCILEX Oct 19, 2016
2cc8adf
Final cleanup and fix tests
SUPERCILEX Oct 19, 2016
c138a51
Fix test
SUPERCILEX Oct 19, 2016
f88aab3
Fix test
SUPERCILEX Oct 19, 2016
ad115f0
Merge remote-tracking branch 'firebase/version-1.0.0-dev' into refact…
SUPERCILEX Oct 19, 2016
0a161d7
Merge remote-tracking branch 'origin/refactor-zombie-activities' into…
SUPERCILEX Oct 21, 2016
8813c8c
Fix merge mistakes
SUPERCILEX Oct 21, 2016
6f0f4da
Make git show ChooseAccountActivity renamed to SignInDelegate.java
SUPERCILEX Oct 21, 2016
099ef6d
Now shows rename
SUPERCILEX Oct 21, 2016
517f4ce
Working on fixing merge mistakes and preventing regressions
SUPERCILEX Oct 21, 2016
24ef137
Merge stuff from ChooseAccountActivity into SignInDelegate.java
SUPERCILEX Oct 21, 2016
9b568ec
Merge remote-tracking branch 'firebase/version-1.0.0-dev' into refact…
SUPERCILEX Oct 21, 2016
4a449d5
test
SUPERCILEX Oct 21, 2016
a6553d5
Remove references to enableAutoManage
SUPERCILEX Oct 22, 2016
00126d1
It compiles!
SUPERCILEX Oct 22, 2016
a9c895e
Rename public API to AuthUISignInResult and onSignInResult
SUPERCILEX Oct 22, 2016
8566118
Update public api
SUPERCILEX Oct 22, 2016
f5738b1
Cleanup
SUPERCILEX Oct 22, 2016
1fb5c08
Working on tests
SUPERCILEX Oct 22, 2016
1793dbd
working on tests
SUPERCILEX Oct 22, 2016
ca10f6c
Removed unnecessary tests
SUPERCILEX Oct 22, 2016
a0355b5
Fix bug in SaveSmartLock.java not connecting
SUPERCILEX Oct 22, 2016
e60bb5e
More refactoring!
SUPERCILEX Oct 22, 2016
7fcf057
It compiles!
SUPERCILEX Oct 22, 2016
121919a
Fix tests
SUPERCILEX Oct 22, 2016
a78480e
Fix nullPointerException
SUPERCILEX Oct 22, 2016
a94aedc
Simplify public api
SUPERCILEX Oct 22, 2016
cda7bfd
Bug fixes and prettification
SUPERCILEX Oct 22, 2016
83a0551
Fix null pointer
SUPERCILEX Oct 23, 2016
4613154
Really fix null pointer
SUPERCILEX Oct 23, 2016
058d4fe
Remove unnecessary dismiss dialog
SUPERCILEX Oct 23, 2016
c1418ef
Fix null pointer
SUPERCILEX Oct 23, 2016
6d0bf2f
Cleanup
SUPERCILEX Oct 23, 2016
4998691
Cleanup
SUPERCILEX Oct 23, 2016
e7627fa
Change public api
SUPERCILEX Nov 15, 2016
ee5810a
Merge remote-tracking branch 'firebase/master' into refactor-ChooseAc…
SUPERCILEX Nov 18, 2016
9bb8353
Cleanup
SUPERCILEX Nov 19, 2016
aff9984
Cleanup
SUPERCILEX Nov 19, 2016
a39eb0f
Add @LayoutRes
SUPERCILEX Nov 21, 2016
c5878d2
wrong branch
SUPERCILEX Nov 21, 2016
be88ece
Merge remote-tracking branch 'firebase/master' into refactor-ChooseAc…
SUPERCILEX Nov 21, 2016
8866f60
Fix merge mistakes
SUPERCILEX Nov 22, 2016
cc22d28
Address review comments
SUPERCILEX Nov 22, 2016
d0ef556
Initial cleanup
SUPERCILEX Nov 22, 2016
ea2434d
Fix accidental regressions from ChooseAccountActivity
SUPERCILEX Nov 22, 2016
c77ea5b
Another depressingly large refactor
SUPERCILEX Nov 22, 2016
d4278e7
Fix broken tests
SUPERCILEX Nov 22, 2016
e6ff3ef
Cleanup
SUPERCILEX Nov 22, 2016
3cbfed5
Fix crashes and bugs on low memory devices
SUPERCILEX Nov 22, 2016
3210e7e
Fix bug where google account sign in would be shown even if only emai…
SUPERCILEX Nov 22, 2016
eed92af
More massive reactors: using a gateway activity to not break public a…
SUPERCILEX Nov 23, 2016
80a4cb0
Fix bugs on low memory devices
SUPERCILEX Nov 23, 2016
e25e64e
Fix broken tests
SUPERCILEX Nov 23, 2016
42d695c
Final (I hope) cleanup
SUPERCILEX Nov 23, 2016
e8d5bbe
Nope, package cleanup
SUPERCILEX Nov 23, 2016
be698da
Add leakcanary and update dependencies
SUPERCILEX Nov 23, 2016
ac0a78e
Fix recovery dialog being dismissed on screen rotation
SUPERCILEX Nov 23, 2016
6cce271
Rename SmartLock to SmartLockBase.java
SUPERCILEX Nov 23, 2016
6870518
Fix typo
SUPERCILEX Nov 23, 2016
bb09653
Enable auto manage to help prevent memory leaks
SUPERCILEX Nov 23, 2016
151b8d3
Fix #348 and IllegalStateException in SaveSmartLock because of automa…
SUPERCILEX Nov 23, 2016
707f51a
Refactor GoogleApiClient auto manage constants
SUPERCILEX Nov 23, 2016
6b678e4
Remove unnecessary sign in options.
SUPERCILEX Nov 23, 2016
52d27a3
Fix possible null pointer
SUPERCILEX Nov 23, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
working on tests
  • Loading branch information
SUPERCILEX committed Oct 19, 2016
commit cbe0cfb32a676d0d357fc8a808238dd1185a2af0
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.firebase.ui.auth.ui.email;

import android.app.Activity;
import android.content.Intent;
import android.support.design.widget.TextInputLayout;
import android.widget.Button;
Expand All @@ -28,22 +29,31 @@
import com.firebase.ui.auth.test_helpers.FirebaseAuthWrapperImplShadow;
import com.firebase.ui.auth.test_helpers.TestConstants;
import com.firebase.ui.auth.test_helpers.TestHelper;
import com.firebase.ui.auth.ui.ActivityHelper;
import com.firebase.ui.auth.util.PlayServicesHelper;
import com.firebase.ui.auth.util.SmartLock;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.GoogleAuthProvider;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowActivity;

import java.util.Collections;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand All @@ -64,9 +74,12 @@ private SignInActivity createActivity() {
TestHelper.getFlowParameters(
Collections.<String>emptyList()),
null);
return Robolectric.buildActivity(SignInActivity.class).withIntent(startIntent)
.create().visible().get();

return Robolectric
.buildActivity(SignInActivity.class)
.withIntent(startIntent)
.create()
.visible()
.get();
}

@Test
Expand Down Expand Up @@ -106,7 +119,7 @@ public void testSignInButton_signsInAndSavesCredentials() {
when(ActivityHelperShadow.firebaseAuth.signInWithEmailAndPassword(
TestConstants.EMAIL,
TestConstants.PASSWORD)).thenReturn(
new AutoCompleteTask<>(new FakeAuthResult(mockFirebaseUser), true, null));
new AutoCompleteTask<>(new FakeAuthResult(mockFirebaseUser), true, null));
when(mockFirebaseUser.getDisplayName()).thenReturn(TestConstants.NAME);
when(mockFirebaseUser.getEmail()).thenReturn(TestConstants.EMAIL);

Expand All @@ -116,5 +129,29 @@ public void testSignInButton_signsInAndSavesCredentials() {
verify(ActivityHelperShadow.firebaseAuth).signInWithEmailAndPassword(
TestConstants.EMAIL,
TestConstants.PASSWORD);

SmartLock smart = new SmartLock();
SmartLock.SmartLockResultListener resultListener = mock(SmartLock.SmartLockResultListener.class);

final CountDownLatch latch = new CountDownLatch(1);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) {
latch.countDown();
return null;
}
}).when(resultListener).onCredentialsSaved(Activity.RESULT_OK);

try {
smart.saveCredentialsOrFinish(signInActivity,
new ActivityHelper(signInActivity, signInActivity.getIntent()),
resultListener,
mockFirebaseUser,
TestConstants.PASSWORD,
GoogleAuthProvider.PROVIDER_ID);
assertTrue(latch.await(10, TimeUnit.SECONDS));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@
import com.firebase.ui.auth.test_helpers.FirebaseAuthWrapperImplShadow;
import com.firebase.ui.auth.test_helpers.GoogleProviderShadow;
import com.firebase.ui.auth.test_helpers.LoginManagerShadow;
import com.firebase.ui.auth.test_helpers.TestConstants;
import com.firebase.ui.auth.test_helpers.TestHelper;
import com.firebase.ui.auth.ui.ExtraConstants;
import com.firebase.ui.auth.ui.account_link.SaveCredentialsActivity;
import com.firebase.ui.auth.ui.email.EmailHintContainerActivity;
import com.firebase.ui.auth.util.PlayServicesHelper;
import com.google.firebase.auth.AuthCredential;
Expand Down Expand Up @@ -209,24 +206,24 @@ public void testTwitterLoginFlowStarts() {
private static void verifySaveCredentialIntent(
ShadowActivity.IntentForResult nextIntent,
String provider) {
assertEquals(
SaveCredentialsActivity.class.getName(),
nextIntent.intent.getComponent().getClassName());
assertEquals(
nextIntent.intent.getExtras().getString(ExtraConstants.EXTRA_EMAIL),
TestConstants.EMAIL);
assertEquals(
nextIntent.intent.getExtras().getString(ExtraConstants.EXTRA_NAME),
TestConstants.NAME);
assertEquals(
nextIntent.intent.getExtras().getString(ExtraConstants.EXTRA_PROFILE_PICTURE_URI),
TestConstants.PHOTO_URL);
assertEquals(
nextIntent.intent.getExtras().getString(ExtraConstants.EXTRA_PROVIDER),
provider);
assertEquals(
nextIntent.intent.getExtras().getString(ExtraConstants.EXTRA_PASSWORD),
null);
// assertEquals(
// SaveCredentialsActivity.class.getName(),
// nextIntent.intent.getComponent().getClassName());
// assertEquals(
// nextIntent.intent.getExtras().getString(ExtraConstants.EXTRA_EMAIL),
// TestConstants.EMAIL);
// assertEquals(
// nextIntent.intent.getExtras().getString(ExtraConstants.EXTRA_NAME),
// TestConstants.NAME);
// assertEquals(
// nextIntent.intent.getExtras().getString(ExtraConstants.EXTRA_PROFILE_PICTURE_URI),
// TestConstants.PHOTO_URL);
// assertEquals(
// nextIntent.intent.getExtras().getString(ExtraConstants.EXTRA_PROVIDER),
// provider);
// assertEquals(
// nextIntent.intent.getExtras().getString(ExtraConstants.EXTRA_PASSWORD),
// null);
}

private AuthMethodPickerActivity createActivity(List<String> providers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.firebase.ui.auth.ui.idp;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
Expand All @@ -34,6 +35,7 @@
import com.firebase.ui.auth.ui.FlowParameters;
import com.firebase.ui.auth.ui.account_link.WelcomeBackIDPPrompt;
import com.firebase.ui.auth.ui.account_link.WelcomeBackPasswordPrompt;
import com.firebase.ui.auth.ui.email.SignInActivity;
import com.firebase.ui.auth.util.CredentialsAPI;
import com.firebase.ui.auth.util.PlayServicesHelper;
import com.firebase.ui.auth.util.SmartLock;
Expand All @@ -53,13 +55,21 @@
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -96,7 +106,7 @@ public void testSignInSucceeded() {
GoogleAuthProvider.PROVIDER_ID,
TestConstants.EMAIL,
new Bundle());
SmartLock smartLock = new SmartLock();
SmartLock smartLock = mock(SmartLock.class);
CredentialSignInHandler credentialSignInHandler = new CredentialSignInHandler(
mockActivity,
mockActivityHelper,
Expand All @@ -108,7 +118,6 @@ public void testSignInSucceeded() {
// Build basic flow parameters
FlowParameters flowParams = AuthUI.getInstance(mFirebaseApp)
.createSignInIntentBuilder()
.setIsSmartLockEnabled(false)
.build()
.getParcelableExtra(ExtraConstants.EXTRA_FLOW_PARAMS);

Expand All @@ -117,16 +126,48 @@ public void testSignInSucceeded() {
when(mockActivityHelper.getFlowParams()).thenReturn(flowParams);
credentialSignInHandler.onComplete(signInTask);

// Intent smartLockIntent = smartLock.getIntentForTest();
// assertEquals(
// TestConstants.EMAIL,
// smartLockIntent.getExtras().getString(ExtraConstants.EXTRA_EMAIL));
// assertEquals(
// TestConstants.NAME,
// smartLockIntent.getExtras().getString(ExtraConstants.EXTRA_NAME));
// assertEquals(
// TestConstants.PHOTO_URL,
// smartLockIntent.getExtras().getString(ExtraConstants.EXTRA_PROFILE_PICTURE_URI));
verify(smartLock).saveCredentialsOrFinish(mockActivity, mockActivityHelper, credentialSignInHandler, mockFirebaseUser, null, GoogleAuthProvider.PROVIDER_ID);

SmartLock smart = new SmartLock();
SmartLock.SmartLockResultListener resultListener = mock(SmartLock.SmartLockResultListener.class);

final CountDownLatch latch = new CountDownLatch(1);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) {
latch.countDown();
return null;
}
}).when(resultListener).onCredentialsSaved(Activity.RESULT_OK);


SignInActivity s = createActivity();

try {
smart.saveCredentialsOrFinish(s,
new ActivityHelper(mockActivity, mockActivity.getIntent()),
resultListener,
mockFirebaseUser,
TestConstants.PASSWORD,
GoogleAuthProvider.PROVIDER_ID);
assertTrue(latch.await(10, TimeUnit.SECONDS));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}

private SignInActivity createActivity() {
Intent startIntent = SignInActivity.createIntent(
RuntimeEnvironment.application,
TestHelper.getFlowParameters(
Collections.<String>emptyList()),
null);
return Robolectric
.buildActivity(SignInActivity.class)
.withIntent(startIntent)
.create()
.visible()
.get();
}

@Test
Expand Down