Commit cbcb1ea2 authored by Victor Hugo Vianna Silva's avatar Victor Hugo Vianna Silva Committed by Commit Bot

Allow mocking of SigninViewController methods

Unit testing the new AccountStorageAuthHelper requires mocking 2 of the
methods of SigninViewController. This CL makes such methods virtual and
adds the basic unit test setup.

Future CLs will:
1) Refactor AccountStorageAuthHelper so that it can be injected a
signin_view_controller_getter callback. The controller itself cannot be
directly injected since its attached to a browser, while the helper is
per tab.
2) Add the actual tests.

Bug: 1070944
Change-Id: I48fe5031e24ee6488be293d7f96f44c4716ae6b1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2153047
Commit-Queue: Victor Vianna <victorvianna@google.com>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Cr-Commit-Position: refs/heads/master@{#760039}
parent a2a364c6
// 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 "chrome/browser/ui/passwords/account_storage_auth_helper.h"
#include <string>
#include "base/callback.h"
#include "build/build_config.h"
#include "chrome/browser/signin/reauth_result.h"
#include "chrome/browser/ui/signin_view_controller.h"
#include "components/signin/public/base/signin_metrics.h"
#include "google_apis/gaia/core_account_id.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
class MockSigninViewController : public SigninViewController {
public:
MockSigninViewController() : SigninViewController(/*browser=*/nullptr) {}
~MockSigninViewController() override = default;
MOCK_METHOD(void,
ShowReauthPrompt,
(const CoreAccountId&,
base::OnceCallback<void(signin::ReauthResult)>),
(override));
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
MOCK_METHOD(void,
ShowDiceAddAccountTab,
(signin_metrics::AccessPoint, const std::string&),
(override));
#endif
};
} // namespace
class AccountStorageAuthHelperTest : public ::testing::Test {
public:
AccountStorageAuthHelperTest() = default;
~AccountStorageAuthHelperTest() override = default;
protected:
MockSigninViewController mock_signin_view_controller_;
};
...@@ -74,8 +74,8 @@ class SigninViewController { ...@@ -74,8 +74,8 @@ class SigninViewController {
// Shows the Dice "add account" tab, which adds an account to the browser but // Shows the Dice "add account" tab, which adds an account to the browser but
// does not turn sync on. |email_hint| may be empty. // does not turn sync on. |email_hint| may be empty.
void ShowDiceAddAccountTab(signin_metrics::AccessPoint access_point, virtual void ShowDiceAddAccountTab(signin_metrics::AccessPoint access_point,
const std::string& email_hint); const std::string& email_hint);
// Shows the modal sign-in email confirmation dialog as a tab-modal dialog on // Shows the modal sign-in email confirmation dialog as a tab-modal dialog on
// top of the currently displayed WebContents in |browser_|. // top of the currently displayed WebContents in |browser_|.
...@@ -103,7 +103,7 @@ class SigninViewController { ...@@ -103,7 +103,7 @@ class SigninViewController {
// indefinitely. // indefinitely.
// The reauth prompt that is currently displayed can be cancelled by // The reauth prompt that is currently displayed can be cancelled by
// CloseModalSignin(). // CloseModalSignin().
void ShowReauthPrompt( virtual void ShowReauthPrompt(
const CoreAccountId& account_id, const CoreAccountId& account_id,
base::OnceCallback<void(signin::ReauthResult)> reauth_callback); base::OnceCallback<void(signin::ReauthResult)> reauth_callback);
......
...@@ -4084,6 +4084,7 @@ test("unit_tests") { ...@@ -4084,6 +4084,7 @@ test("unit_tests") {
"../browser/ui/omnibox/chrome_omnibox_navigation_observer_unittest.cc", "../browser/ui/omnibox/chrome_omnibox_navigation_observer_unittest.cc",
"../browser/ui/omnibox/clipboard_utils_unittest.cc", "../browser/ui/omnibox/clipboard_utils_unittest.cc",
"../browser/ui/page_info/permission_menu_model_unittest.cc", "../browser/ui/page_info/permission_menu_model_unittest.cc",
"../browser/ui/passwords/account_storage_auth_helper_unittest.cc",
"../browser/ui/passwords/bubble_controllers/auto_sign_in_bubble_controller_unittest.cc", "../browser/ui/passwords/bubble_controllers/auto_sign_in_bubble_controller_unittest.cc",
"../browser/ui/passwords/bubble_controllers/generation_confirmation_bubble_controller_unittest.cc", "../browser/ui/passwords/bubble_controllers/generation_confirmation_bubble_controller_unittest.cc",
"../browser/ui/passwords/bubble_controllers/items_bubble_controller_unittest.cc", "../browser/ui/passwords/bubble_controllers/items_bubble_controller_unittest.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