Commit 6d801322 authored by Giovanni Ortuño Urquidi's avatar Giovanni Ortuño Urquidi Committed by Commit Bot

Revert "[signin] Add browser tests for the reauth dialog"

This reverts commit 98d00374.

Reason for revert:
Both of these are failing on MSAN:
SigninReauthViewControllerBrowserTest.CancelReauthDialog
SigninReauthViewControllerBrowserTest.ConfirmReauthDialog

https://ci.chromium.org/p/chromium/builders/ci/Linux%20MSan%20Tests

https://ci.chromium.org/p/chromium/builders/ci/Linux%20MSan%20Tests/24165

https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket.appspot.com/8878588233120522160/+/steps/browser_tests/0/logs/Deterministic_failure:_SigninReauthViewControllerBrowserTest.CancelReauthDialog__status_CRASH_/0

Original change's description:
> [signin] Add browser tests for the reauth dialog
> 
> This CL adds tests for the first step of the reauth flow, the reauth
> confirmation dialog. The tests check that clicking on all buttons
> produces expected results.
> 
> The tests for the second step of the reauth flow will be added in
> follow-up CLs.
> 
> Bug: 1045515
> Change-Id: I4266f29ea03080d3d6612099a0b9a49cff5cdf09
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2219897
> Reviewed-by: David Roger <droger@chromium.org>
> Commit-Queue: Alex Ilin <alexilin@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#774122}

TBR=droger@chromium.org,alexilin@chromium.org

Change-Id: I08bfa073e1b51c4dbb3125232cc4b60880deb293
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 1045515
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2227932Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Commit-Queue: Giovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774447}
parent 2aee8f6c
......@@ -125,10 +125,6 @@ void SigninReauthViewController::OnReauthConfirmed() {
OnStateChanged();
}
void SigninReauthViewController::OnReauthDismissed() {
CompleteReauth(signin::ReauthResult::kDismissedByUser);
}
void SigninReauthViewController::OnGaiaReauthPageNavigated() {
if (gaia_reauth_page_state_ >= GaiaReauthPageState::kNavigated)
return;
......
......@@ -70,10 +70,6 @@ class SigninReauthViewController
// dialog.
// This happens before the Gaia reauth page is shown.
void OnReauthConfirmed();
// Called when the user clicks the cancel button in the reauth confirmation
// dialog.
// This happens before the Gaia reauth page is shown.
void OnReauthDismissed();
// Called when the Gaia reauth page has navigated.
void OnGaiaReauthPageNavigated();
......
// Copyright 2020 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.
#include "base/callback.h"
#include "base/run_loop.h"
#include "base/test/bind_test_util.h"
#include "base/test/mock_callback.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/reauth_result.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/signin_reauth_view_controller.h"
#include "chrome/browser/ui/signin_view_controller.h"
#include "chrome/browser/ui/webui/signin/login_ui_test_utils.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/signin/public/identity_manager/consent_level.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/signin/public/identity_manager/identity_test_utils.h"
#include "content/public/test/browser_test.h"
#include "google_apis/gaia/core_account_id.h"
// Browser tests for SigninReauthViewController.
class SigninReauthViewControllerBrowserTest : public InProcessBrowserTest {
public:
void SetUpOnMainThread() override {
InProcessBrowserTest::SetUpOnMainThread();
account_id_ = signin::SetUnconsentedPrimaryAccount(identity_manager(),
"alice@gmail.com")
.account_id;
}
signin::IdentityManager* identity_manager() {
return IdentityManagerFactory::GetForProfile(browser()->profile());
}
SigninReauthViewController* signin_reauth_view_controller() {
SigninViewController* signin_view_controller =
browser()->signin_view_controller();
DCHECK(signin_view_controller->ShowsModalDialog());
return static_cast<SigninReauthViewController*>(
signin_view_controller->GetModalDialogDelegateForTesting());
}
CoreAccountId account_id() { return account_id_; }
private:
CoreAccountId account_id_;
};
// Tests that the abort handle cancels an ongoing reauth flow.
IN_PROC_BROWSER_TEST_F(SigninReauthViewControllerBrowserTest,
AbortReauthDialog_AbortHandle) {
base::MockCallback<base::OnceCallback<void(signin::ReauthResult)>>
reauth_callback;
std::unique_ptr<SigninViewController::ReauthAbortHandle> abort_handle =
browser()->signin_view_controller()->ShowReauthPrompt(
account_id(), reauth_callback.Get());
EXPECT_CALL(reauth_callback, Run(signin::ReauthResult::kCancelled));
abort_handle.reset();
}
// Tests canceling the reauth dialog through CloseModalSignin().
IN_PROC_BROWSER_TEST_F(SigninReauthViewControllerBrowserTest,
AbortReauthDialog_CloseModalSignin) {
base::MockCallback<base::OnceCallback<void(signin::ReauthResult)>>
reauth_callback;
std::unique_ptr<SigninViewController::ReauthAbortHandle> abort_handle =
browser()->signin_view_controller()->ShowReauthPrompt(
account_id(), reauth_callback.Get());
EXPECT_CALL(reauth_callback, Run(signin::ReauthResult::kCancelled));
browser()->signin_view_controller()->CloseModalSignin();
}
// Tests closing the reauth dialog through by clicking on the close button (the
// X).
IN_PROC_BROWSER_TEST_F(SigninReauthViewControllerBrowserTest,
CloseReauthDialog) {
base::MockCallback<base::OnceCallback<void(signin::ReauthResult)>>
reauth_callback;
std::unique_ptr<SigninViewController::ReauthAbortHandle> abort_handle =
browser()->signin_view_controller()->ShowReauthPrompt(
account_id(), reauth_callback.Get());
EXPECT_CALL(reauth_callback, Run(signin::ReauthResult::kDismissedByUser));
// The test cannot depend on Views implementation so it simulates clicking on
// the close button through calling the close event.
signin_reauth_view_controller()->OnModalSigninClosed();
}
// Tests clicking on the confirm button in the reauth dialog.
IN_PROC_BROWSER_TEST_F(SigninReauthViewControllerBrowserTest,
ConfirmReauthDialog) {
signin::ReauthResult reauth_result;
base::RunLoop run_loop;
std::unique_ptr<SigninViewController::ReauthAbortHandle> abort_handle =
browser()->signin_view_controller()->ShowReauthPrompt(
account_id(),
base::BindLambdaForTesting([&](signin::ReauthResult result) {
reauth_result = result;
run_loop.Quit();
}));
login_ui_test_utils::ConfirmReauthConfirmationDialog(
browser(), base::TimeDelta::FromSeconds(5));
run_loop.Run();
EXPECT_EQ(reauth_result, signin::ReauthResult::kSuccess);
}
// Tests clicking on the cancel button in the reauth dialog.
IN_PROC_BROWSER_TEST_F(SigninReauthViewControllerBrowserTest,
CancelReauthDialog) {
signin::ReauthResult reauth_result;
base::RunLoop run_loop;
std::unique_ptr<SigninViewController::ReauthAbortHandle> abort_handle =
browser()->signin_view_controller()->ShowReauthPrompt(
account_id(),
base::BindLambdaForTesting([&](signin::ReauthResult result) {
reauth_result = result;
run_loop.Quit();
}));
login_ui_test_utils::CancelReauthConfirmationDialog(
browser(), base::TimeDelta::FromSeconds(5));
run_loop.Run();
EXPECT_EQ(reauth_result, signin::ReauthResult::kDismissedByUser);
}
......@@ -272,11 +272,6 @@ void SigninViewController::OnReauthConfirmed() {
reauth_controller_->OnReauthConfirmed();
}
void SigninViewController::OnReauthDismissed() {
if (reauth_controller_)
reauth_controller_->OnReauthDismissed();
}
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
void SigninViewController::ShowDiceSigninTab(
signin_metrics::Reason signin_reason,
......@@ -440,9 +435,3 @@ SigninViewController::GetModalDialogWebContentsForTesting() {
DCHECK(delegate_);
return delegate_->GetWebContents();
}
SigninViewControllerDelegate*
SigninViewController::GetModalDialogDelegateForTesting() {
DCHECK(delegate_);
return delegate_;
}
......@@ -142,12 +142,8 @@ class SigninViewController : public SigninViewControllerDelegate::Observer {
// Notifies that the user confirmed the reauth dialog.
void OnReauthConfirmed();
// Notifies that the user dismissed the reauth dialog.
void OnReauthDismissed();
private:
friend class login_ui_test_utils::SigninViewControllerTestUtil;
friend class SigninReauthViewControllerBrowserTest;
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
// Shows the DICE-specific sign-in flow: opens a Gaia sign-in webpage in a new
......@@ -162,9 +158,6 @@ class SigninViewController : public SigninViewControllerDelegate::Observer {
// Returns the web contents of the modal dialog.
content::WebContents* GetModalDialogWebContentsForTesting();
// Returns the modal dialog delegate.
SigninViewControllerDelegate* GetModalDialogDelegateForTesting();
// Browser owning this controller.
Browser* browser_;
......
......@@ -7,6 +7,7 @@
#include "base/callback.h"
#include "base/run_loop.h"
#include "base/test/bind_test_util.h"
#include "base/test/mock_callback.h"
#include "build/build_config.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/reauth_result.h"
......@@ -67,6 +68,19 @@ IN_PROC_BROWSER_TEST_F(SignInViewControllerBrowserTest, Accelerators) {
EXPECT_EQ(2, browser()->tab_strip_model()->count());
}
IN_PROC_BROWSER_TEST_F(SignInViewControllerBrowserTest, AbortOngoingReauth) {
CoreAccountId account_id = signin::SetUnconsentedPrimaryAccount(
GetIdentityManager(), "alice@gmail.com")
.account_id;
base::MockCallback<base::OnceCallback<void(signin::ReauthResult)>>
reauth_callback;
std::unique_ptr<SigninViewController::ReauthAbortHandle> abort_handle =
browser()->signin_view_controller()->ShowReauthPrompt(
account_id, reauth_callback.Get());
EXPECT_CALL(reauth_callback, Run(signin::ReauthResult::kCancelled));
abort_handle.reset();
}
// Tests that the confirm button is focused by default in the reauth dialog.
IN_PROC_BROWSER_TEST_F(SignInViewControllerBrowserTest, ReauthDefaultFocus) {
CoreAccountId account_id = signin::SetUnconsentedPrimaryAccount(
......
......@@ -5,7 +5,6 @@
#include "chrome/browser/ui/webui/signin/login_ui_test_utils.h"
#include "base/bind.h"
#include "base/notreached.h"
#include "base/run_loop.h"
#include "base/scoped_observer.h"
#include "base/strings/stringprintf.h"
......@@ -193,8 +192,6 @@ void WaitUntilAnyElementExistsInSigninFrame(
enum class SyncConfirmationDialogAction { kConfirm, kCancel };
enum class ReauthDialogAction { kConfirm, kCancel };
#if !defined(OS_CHROMEOS)
std::string GetButtonIdForSyncConfirmationDialogAction(
SyncConfirmationDialogAction action) {
......@@ -228,16 +225,6 @@ std::string GetButtonIdForSigninEmailConfirmationDialogAction(
}
}
std::string GetButtonIdForReauthConfirmationDialogAction(
ReauthDialogAction action) {
switch (action) {
case ReauthDialogAction::kConfirm:
return "confirmButton";
case ReauthDialogAction::kCancel:
return "cancelButton";
}
}
std::string GetButtonSelectorForApp(const std::string& app,
const std::string& button_id) {
return base::StringPrintf(
......@@ -345,39 +332,9 @@ class SigninViewControllerTestUtil {
content::WebContents* dialog_web_contents =
signin_view_controller->GetModalDialogWebContentsForTesting();
DCHECK(dialog_web_contents);
const std::string button_selector = GetButtonSelectorForApp(
"signin-reauth-app", GetButtonIdForReauthConfirmationDialogAction(
ReauthDialogAction::kConfirm));
const std::string button_selector =
GetButtonSelectorForApp("signin-reauth-app", "confirmButton");
return IsElementReady(dialog_web_contents, button_selector);
#endif
}
static bool TryCompleteReauthConfirmationDialog(Browser* browser,
ReauthDialogAction action) {
#if defined(OS_CHROMEOS)
NOTREACHED();
return false;
#else
SigninViewController* signin_view_controller =
browser->signin_view_controller();
DCHECK(signin_view_controller);
if (!signin_view_controller->ShowsModalDialog())
return false;
content::WebContents* dialog_web_contents =
signin_view_controller->GetModalDialogWebContentsForTesting();
DCHECK(dialog_web_contents);
std::string button_selector = GetButtonSelectorForApp(
"signin-reauth-app",
GetButtonIdForReauthConfirmationDialogAction(action));
if (!IsElementReady(dialog_web_contents, button_selector))
return false;
// This cannot be a synchronous call, because it closes the window as a side
// effect, which may cause the javascript execution to never finish.
content::ExecuteScriptAsync(dialog_web_contents,
button_selector + ".click();");
return true;
#endif
}
};
......@@ -534,28 +491,4 @@ void WaitUntilReauthUIIsReady(Browser* browser) {
"Could not find reauth confirm button");
}
bool CompleteReauthConfirmationDialog(Browser* browser,
base::TimeDelta timeout,
ReauthDialogAction action) {
const base::Time expire_time = base::Time::Now() + timeout;
while (base::Time::Now() <= expire_time) {
if (SigninViewControllerTestUtil::TryCompleteReauthConfirmationDialog(
browser, action))
return true;
RunLoopFor(base::TimeDelta::FromMilliseconds(1000));
}
return false;
}
bool ConfirmReauthConfirmationDialog(Browser* browser,
base::TimeDelta timeout) {
return CompleteReauthConfirmationDialog(browser, timeout,
ReauthDialogAction::kConfirm);
}
bool CancelReauthConfirmationDialog(Browser* browser, base::TimeDelta timeout) {
return CompleteReauthConfirmationDialog(browser, timeout,
ReauthDialogAction::kCancel);
}
} // namespace login_ui_test_utils
......@@ -63,16 +63,6 @@ bool CompleteSigninEmailConfirmationDialog(
// Waits for the reauth confirmation dialog to get displayed.
void WaitUntilReauthUIIsReady(Browser* browser);
// Waits for the reauth confirmation dialog to get displayed, then executes
// javascript to click on confirm button. Returns false if dialog wasn't
// dismissed before |timeout|.
bool ConfirmReauthConfirmationDialog(Browser* browser, base::TimeDelta timeout);
// Waits for the reauth confirmation dialog to get displayed, then executes
// javascript to click on cancel button. Returns false if dialog wasn't
// dismissed before |timeout|.
bool CancelReauthConfirmationDialog(Browser* browser, base::TimeDelta timeout);
} // namespace login_ui_test_utils
#endif // CHROME_BROWSER_UI_WEBUI_SIGNIN_LOGIN_UI_TEST_UTILS_H_
......@@ -29,5 +29,5 @@ void SigninReauthHandler::HandleConfirm(const base::ListValue* args) {
}
void SigninReauthHandler::HandleCancel(const base::ListValue* args) {
browser_->signin_view_controller()->OnReauthDismissed();
browser_->signin_view_controller()->CloseModalSignin();
}
......@@ -1545,7 +1545,6 @@ if (!is_android) {
sources += [
"../browser/external_protocol/external_protocol_handler_browsertest.cc",
"../browser/lifetime/application_lifetime_browsertest.cc",
"../browser/ui/signin_reauth_view_controller_browsertest.cc",
]
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment