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

Unified Diff: chrome/android/junit/src/org/chromium/chrome/browser/preferences/password/PasswordReauthenticationTest.java

Issue 2067323004: Allow copying and viewing account credentials in PasswordEntryEditor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add junit test for reauthentication Created 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/junit/src/org/chromium/chrome/browser/preferences/password/PasswordReauthenticationTest.java
diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/preferences/password/PasswordReauthenticationTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/preferences/password/PasswordReauthenticationTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..e3a730362f815864e667a7bdfbd58e08079551ce
--- /dev/null
+++ b/chrome/android/junit/src/org/chromium/chrome/browser/preferences/password/PasswordReauthenticationTest.java
@@ -0,0 +1,80 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
vabr (Chromium) 2016/08/17 08:57:42 nit: 2016
dozsa 2016/08/17 10:40:27 Done.
+// 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 PasswordReauthenticationTest{
+
+ private static PasswordReauthentication sMockPasswordReauthentication;
+
+ // Replacement fragment for PasswordEntryEditor, which is the fragment that
+ // replaces PasswordReauthentication after popBackStack is called.
+ private static Fragment sMockPasswordEntryEditor;
+
+ private static final int CONFIRM_DEVICE_CREDENTIAL_REQUEST_CODE = 2;
Bernhard Bauer 2016/08/16 23:37:35 Rather than duplicating this value, make it visibl
dozsa 2016/08/17 10:40:27 Done.
+
+ private Activity mTestActivity;
+
+ protected void setUp() throws Exception {
+ sMockPasswordReauthentication = new PasswordReauthentication();
+ mTestActivity = Robolectric.setupActivity(Activity.class);
+ }
+
+ /**
+ * Ensure that the on/off switch in "Save Passwords" settings actually enables and disables
vabr (Chromium) 2016/08/17 08:57:42 nit: This comment seems out of date.
dozsa 2016/08/17 10:40:27 Done.
+ * password saving.
+ */
+ @Test
+ public void testOnActivityResult() {
+ sMockPasswordEntryEditor = new Fragment();
+ sMockPasswordReauthentication = new PasswordReauthentication();
+ mTestActivity = Robolectric.setupActivity(Activity.class);
Bernhard Bauer 2016/08/16 23:37:35 These two lines are duplicated in the setUp() meth
dozsa 2016/08/17 10:40:27 Done.
+ Intent returnIntent = new Intent();
+ returnIntent.putExtra("result", "This is the result");
+ sMockPasswordReauthentication.setTesting(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(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 PasswordReauthentication 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());
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698