Skip to content

Commit

Permalink
Fix flaky #testCanCopyPasswordIfReauthSucceeds
Browse files Browse the repository at this point in the history
Speculative fix by adding a Toast Shadow.

Flakes when resharded - stumbled on this when dry runs failed
for my CL https://crrev.com/c/4571882

See also https://chromium-review.googlesource.com/c/chromium/src/+/4519916/comment/7cc1fe67_24781a0f/

(cherry picked from commit 017872b)

Change-Id: I26e019f664c135b020803dbdc889d60dd7cd3d0d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4575084
Reviewed-by: Wenyu Fu <wenyufu@chromium.org>
Reviewed-by: Lijin Shen <lazzzis@google.com>
Auto-Submit: Donn Denman <donnd@chromium.org>
Commit-Queue: Donn Denman <donnd@chromium.org>
Reviewed-by: Ioana Pandele <ioanap@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1151388}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4590315
Commit-Queue: Theresa Sullivan <twellington@chromium.org>
Reviewed-by: Theresa Sullivan <twellington@chromium.org>
Cr-Commit-Position: refs/branch-heads/5790@{#379}
Cr-Branched-From: 1d71a33-refs/heads/main@{#1148114}
  • Loading branch information
Donn Denman authored and Chromium LUCI CQ committed Jun 5, 2023
1 parent 9f17187 commit 5a96d56
Showing 1 changed file with 16 additions and 1 deletion.
Expand Up @@ -51,6 +51,8 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;

import org.chromium.base.Callback;
import org.chromium.base.metrics.RecordHistogram;
Expand All @@ -63,12 +65,13 @@
import org.chromium.chrome.browser.password_manager.settings.PasswordAccessReauthenticationHelper.ReauthReason;
import org.chromium.ui.base.Clipboard;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.widget.Toast;

/**
* Tests verifying that the credential edit mediator modifies the model correctly.
*/
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
@Config(shadows = {CredentialEditControllerTest.ShadowToast.class})
public class CredentialEditControllerTest {
private static final String TEST_URL = "https://m.a.xyz/signin";
private static final String TEST_USERNAME = "TestUsername";
Expand All @@ -88,6 +91,16 @@ public class CredentialEditControllerTest {
@Mock
private Runnable mHelpLauncher;

/** Shadow for the {@link Toast} class to make sure we don't try to run it's native code. */
@Implements(Toast.class)
public static class ShadowToast {
public ShadowToast() {}

/** Ignore show(). */
@Implementation
protected void show() {}
}

CredentialEditMediator mMediator;
PropertyModel mModel;

Expand Down Expand Up @@ -212,6 +225,8 @@ public void testCanCopyPasswordIfReauthSucceeds() {
Context context = ApplicationProvider.getApplicationContext();
mMediator.onCopyPassword(context);

verify(mReauthenticationHelper)
.reauthenticate(eq(ReauthReason.COPY_PASSWORD), any(Callback.class));
ClipboardManager clipboard =
(ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
assertNotNull(clipboard.getPrimaryClip());
Expand Down

0 comments on commit 5a96d56

Please sign in to comment.