Index: chrome/android/junit/src/org/chromium/chrome/browser/preferences/password/PasswordReauthenticationFragmentTest.java |
diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/preferences/password/PasswordReauthenticationFragmentTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/preferences/password/PasswordReauthenticationFragmentTest.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..dce8cac0541dbdce75f8ca66aa8ffb5d389a0208 |
--- /dev/null |
+++ b/chrome/android/junit/src/org/chromium/chrome/browser/preferences/password/PasswordReauthenticationFragmentTest.java |
@@ -0,0 +1,69 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.chrome.browser.preferences.password; |
+ |
+import static org.junit.Assert.assertEquals; |
+ |
+import android.app.Activity; |
+import android.app.Fragment; |
+import android.app.FragmentManager; |
+import android.app.FragmentTransaction; |
+import android.content.Intent; |
+ |
+import org.chromium.testing.local.LocalRobolectricTestRunner; |
+ |
+import org.junit.Test; |
+import org.junit.runner.RunWith; |
+import org.robolectric.Robolectric; |
+ |
+/** |
+ * Tests for the "Save Passwords" settings screen. |
+ */ |
+@RunWith(LocalRobolectricTestRunner.class) |
+public class PasswordReauthenticationFragmentTest{ |
+ |
+ /** |
+ * Ensure that upon reauthentication PasswordReauthenticationFragment is popped from |
+ * the FragmentManager backstack. |
+ */ |
+ @Test |
+ public void testOnActivityResult() { |
+ PasswordReauthenticationFragment sMockPasswordReauthentication = |
+ new PasswordReauthenticationFragment(); |
+ |
+ // Replacement fragment for PasswordEntryEditor, which is the fragment that |
+ // replaces PasswordReauthentication after popBackStack is called. |
+ Fragment sMockPasswordEntryEditor = new Fragment(); |
+ |
+ Activity mTestActivity = Robolectric.setupActivity(Activity.class); |
+ Intent returnIntent = new Intent(); |
+ returnIntent.putExtra("result", "This is the result"); |
+ sMockPasswordReauthentication.preventLockingForTesting(true); |
+ |
+ FragmentManager fragmentManager = mTestActivity.getFragmentManager(); |
+ FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); |
+ fragmentTransaction.add(sMockPasswordEntryEditor, "password_entry_editor"); |
+ fragmentTransaction.addToBackStack("add_password_entry_editor"); |
+ fragmentTransaction.commit(); |
+ |
+ FragmentTransaction fragmentTransaction2 = fragmentManager.beginTransaction(); |
+ fragmentTransaction2.add(sMockPasswordReauthentication, "password_reauthentication"); |
+ fragmentTransaction2.addToBackStack("add_password_reauthentication"); |
+ fragmentTransaction2.commit(); |
+ |
+ sMockPasswordReauthentication.onActivityResult( |
+ PasswordReauthenticationFragment.CONFIRM_DEVICE_CREDENTIAL_REQUEST_CODE, |
+ mTestActivity.RESULT_OK, returnIntent); |
+ fragmentManager.executePendingTransactions(); |
+ |
+ // Assert that the number of fragments in the Back Stack is equal to 1 after |
+ // reauthentication, as PasswordReauthenticationFragment is popped. |
+ assertEquals(1, fragmentManager.getBackStackEntryCount()); |
+ |
+ // Assert that the remaining fragment in the Back Stack is PasswordEntryEditor. |
+ assertEquals("add_password_entry_editor", fragmentManager.getBackStackEntryAt(0) |
+ .getName()); |
+ } |
+} |