Commit 597624e7 authored by mkwst@chromium.org's avatar mkwst@chromium.org

Password bubble: refactor ManagePasswordsIconView.

As another step towards a platform-agnostic test suite for the password
management UI, this CL refactors ManagePasswordsIconView in a few ways:

1. It introduces a new 'ManagePasswordsIcon' abstract base class
   to provide a platform-agnostic interface to the Omnibox icon.

2. The ManagePasswordsBubbleUIController is now responsible for
   determining the Omnibox's icon's state, and also responsible
   for triggering automatic display of the bubble UI. The actual
   functionality is still sitting on the icon for the moment, but
   will be moved out to a platform-agnostic layer in a future CL.

3. Most importantly, some basic unit tests verify the functionality
   added above.

BUG=356678

Review URL: https://codereview.chromium.org/250353003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266520 0039d316-1c4b-4281-b951-d872f2087c98
parent 7644fa28
......@@ -10,6 +10,7 @@
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/omnibox/location_bar.h"
#include "chrome/browser/ui/passwords/manage_passwords_icon.h"
#include "chrome/common/url_constants.h"
#include "components/password_manager/core/browser/password_store.h"
#include "content/public/browser/notification_service.h"
......@@ -115,10 +116,6 @@ void ManagePasswordsBubbleUIController::OnLoginsChanged(
}
}
void ManagePasswordsBubbleUIController::OnBubbleShown() {
unset_manage_passwords_bubble_needs_showing();
}
void ManagePasswordsBubbleUIController::
NavigateToPasswordManagerSettingsPage() {
// TODO(mkwst): chrome_pages.h is compiled out of Android. Need to figure out
......@@ -157,3 +154,23 @@ const autofill::PasswordForm& ManagePasswordsBubbleUIController::
DCHECK(form_manager_);
return form_manager_->pending_credentials();
}
void ManagePasswordsBubbleUIController::UpdateIconAndBubbleState(
ManagePasswordsIcon* icon) {
ManagePasswordsIcon::State state = ManagePasswordsIcon::INACTIVE_STATE;
if (autofill_blocked_)
state = ManagePasswordsIcon::BLACKLISTED_STATE;
else if (password_to_be_saved_)
state = ManagePasswordsIcon::PENDING_STATE;
else if (manage_passwords_icon_to_be_shown_)
state = ManagePasswordsIcon::MANAGE_STATE;
icon->SetState(state);
if (manage_passwords_bubble_needs_showing_) {
DCHECK(state == ManagePasswordsIcon::PENDING_STATE);
icon->ShowBubbleWithoutUserInteraction();
manage_passwords_bubble_needs_showing_ = false;
}
}
......@@ -16,6 +16,8 @@ namespace content {
class WebContents;
}
class ManagePasswordsIcon;
// Per-tab class to control the Omnibox password icon and bubble.
class ManagePasswordsBubbleUIController
: public content::WebContentsObserver,
......@@ -51,15 +53,15 @@ class ManagePasswordsBubbleUIController
// the action off to the FormManager.
virtual void NeverSavePassword();
// Called when the bubble is opened after the icon gets displayed. We change
// the state to know that we do not need to pop up the bubble again.
void OnBubbleShown();
// Open a new tab, pointing to the password manager settings page.
virtual void NavigateToPasswordManagerSettingsPage();
virtual const autofill::PasswordForm& PendingCredentials() const;
// Set the state of the Omnibox icon, and possibly show the associated bubble
// without user interaction.
virtual void UpdateIconAndBubbleState(ManagePasswordsIcon* icon);
bool manage_passwords_icon_to_be_shown() const {
return manage_passwords_icon_to_be_shown_;
}
......@@ -72,10 +74,6 @@ class ManagePasswordsBubbleUIController
return manage_passwords_bubble_needs_showing_;
}
void unset_manage_passwords_bubble_needs_showing() {
manage_passwords_bubble_needs_showing_ = false;
}
void unset_password_to_be_saved() {
password_to_be_saved_ = false;
}
......@@ -89,6 +87,8 @@ class ManagePasswordsBubbleUIController
autofill_blocked_ = autofill_blocked;
}
const GURL& origin() const { return origin_; }
protected:
explicit ManagePasswordsBubbleUIController(
content::WebContents* web_contents);
......
// Copyright 2014 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/metrics/histogram_samples.h"
#include "base/prefs/pref_service.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/statistics_delta_reader.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller_mock.h"
#include "chrome/browser/ui/passwords/manage_passwords_icon.h"
#include "chrome/browser/ui/passwords/manage_passwords_icon_mock.h"
#include "chrome/test/base/testing_profile.h"
#include "components/autofill/core/common/password_form.h"
#include "components/password_manager/core/browser/mock_password_manager_driver.h"
#include "components/password_manager/core/browser/password_form_manager.h"
#include "components/password_manager/core/browser/password_manager_driver.h"
#include "components/password_manager/core/browser/stub_password_manager_client.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/web_contents_tester.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
class ManagePasswordsBubbleUIControllerTest : public testing::Test {
public:
ManagePasswordsBubbleUIControllerTest()
: test_web_contents_(
content::WebContentsTester::CreateTestWebContents(&profile_,
NULL)) {}
virtual void SetUp() OVERRIDE {
// Create the test UIController here so that it's bound to
// |test_web_contents_|, and will be retrieved correctly via
// ManagePasswordsBubbleUIController::FromWebContents in |controller()|.
new ManagePasswordsBubbleUIControllerMock(test_web_contents_.get());
test_form_.origin = GURL("http://example.com");
}
autofill::PasswordForm& test_form() { return test_form_; }
ManagePasswordsBubbleUIControllerMock* controller() {
return static_cast<ManagePasswordsBubbleUIControllerMock*>(
ManagePasswordsBubbleUIController::FromWebContents(
test_web_contents_.get()));
}
private:
content::TestBrowserThreadBundle thread_bundle_;
TestingProfile profile_;
scoped_ptr<content::WebContents> test_web_contents_;
autofill::PasswordForm test_form_;
};
TEST_F(ManagePasswordsBubbleUIControllerTest, DefaultState) {
EXPECT_FALSE(controller()->autofill_blocked());
EXPECT_FALSE(controller()->manage_passwords_bubble_needs_showing());
EXPECT_FALSE(controller()->manage_passwords_icon_to_be_shown());
EXPECT_FALSE(controller()->never_saved_password());
EXPECT_FALSE(controller()->password_to_be_saved());
EXPECT_FALSE(controller()->saved_password());
EXPECT_EQ(GURL::EmptyGURL(), controller()->origin());
ManagePasswordsIconMock mock;
controller()->UpdateIconAndBubbleState(&mock);
EXPECT_EQ(ManagePasswordsIcon::INACTIVE_STATE, mock.state());
EXPECT_EQ(0, mock.bubble_shown_count());
}
TEST_F(ManagePasswordsBubbleUIControllerTest, PasswordAutofilled) {
base::string16 kTestUsername = base::ASCIIToUTF16("test_username");
autofill::PasswordFormMap map;
map[kTestUsername] = &test_form();
controller()->OnPasswordAutofilled(map);
EXPECT_TRUE(controller()->manage_passwords_icon_to_be_shown());
EXPECT_FALSE(controller()->autofill_blocked());
EXPECT_FALSE(controller()->manage_passwords_bubble_needs_showing());
EXPECT_FALSE(controller()->never_saved_password());
EXPECT_FALSE(controller()->password_to_be_saved());
EXPECT_FALSE(controller()->saved_password());
EXPECT_EQ(test_form().origin, controller()->origin());
ManagePasswordsIconMock mock;
controller()->UpdateIconAndBubbleState(&mock);
EXPECT_EQ(ManagePasswordsIcon::MANAGE_STATE, mock.state());
EXPECT_EQ(0, mock.bubble_shown_count());
}
TEST_F(ManagePasswordsBubbleUIControllerTest, PasswordSubmitted) {
password_manager::StubPasswordManagerClient client;
password_manager::MockPasswordManagerDriver driver;
password_manager::PasswordFormManager* test_form_manager =
new password_manager::PasswordFormManager(
NULL, &client, &driver, test_form(), false);
controller()->OnPasswordSubmitted(test_form_manager);
EXPECT_TRUE(controller()->manage_passwords_bubble_needs_showing());
EXPECT_TRUE(controller()->manage_passwords_icon_to_be_shown());
EXPECT_TRUE(controller()->password_to_be_saved());
EXPECT_FALSE(controller()->autofill_blocked());
EXPECT_FALSE(controller()->never_saved_password());
EXPECT_FALSE(controller()->saved_password());
// TODO(mkwst): This should be the value of test_form()->origin, but
// it's being masked by the stub implementation of
// ManagePasswordsBubbleUIControllerMock::PendingCredentials.
EXPECT_EQ(GURL::EmptyGURL(), controller()->origin());
ManagePasswordsIconMock mock;
controller()->UpdateIconAndBubbleState(&mock);
EXPECT_EQ(ManagePasswordsIcon::PENDING_STATE, mock.state());
EXPECT_EQ(1, mock.bubble_shown_count());
}
TEST_F(ManagePasswordsBubbleUIControllerTest, BlacklistBlockedAutofill) {
controller()->OnBlacklistBlockedAutofill();
EXPECT_TRUE(controller()->autofill_blocked());
EXPECT_TRUE(controller()->manage_passwords_icon_to_be_shown());
EXPECT_FALSE(controller()->manage_passwords_bubble_needs_showing());
EXPECT_FALSE(controller()->never_saved_password());
EXPECT_FALSE(controller()->password_to_be_saved());
EXPECT_FALSE(controller()->saved_password());
EXPECT_EQ(GURL::EmptyGURL(), controller()->origin());
ManagePasswordsIconMock mock;
controller()->UpdateIconAndBubbleState(&mock);
EXPECT_EQ(ManagePasswordsIcon::BLACKLISTED_STATE, mock.state());
EXPECT_EQ(0, mock.bubble_shown_count());
}
// Copyright 2014 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/manage_passwords_icon.h"
ManagePasswordsIcon::ManagePasswordsIcon() : state_(INACTIVE_STATE) {
}
ManagePasswordsIcon::~ManagePasswordsIcon() {
}
void ManagePasswordsIcon::SetState(State state) {
if (state_ == state)
return;
state_ = state;
SetStateInternal(state);
}
// Copyright 2014 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.
#ifndef CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_ICON_H_
#define CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_ICON_H_
#include "base/basictypes.h"
// Abstract base class for platform-specific password management icon views.
class ManagePasswordsIcon {
public:
enum State {
// The icon should not be displayed.
INACTIVE_STATE,
// The user has blacklisted the current page; the icon should be visible,
// and correctly represent the password manager's disabled state.
BLACKLISTED_STATE,
// Offer the user the ability to manage passwords for the current page.
MANAGE_STATE,
// Offer the user the ability to save a pending password.
PENDING_STATE,
};
// Get/set the icon's state. Implementations of this class must implement
// SetStateInternal to do reasonable platform-specific things to represent
// the icon's state to the user.
void SetState(State state);
State state() const { return state_; }
// Shows the bubble without user interaction; should only be called from
// ManagePasswordsUIController.
//
// TODO(mkwst): This shouldn't be the IconView's responsiblity. Move it
// somewhere else as part of the refactoring in http://crbug.com/365678.
virtual void ShowBubbleWithoutUserInteraction() = 0;
protected:
ManagePasswordsIcon();
~ManagePasswordsIcon();
// Called from SetState() iff the icon's state has changed.
virtual void SetStateInternal(State state) = 0;
private:
State state_;
DISALLOW_COPY_AND_ASSIGN(ManagePasswordsIcon);
};
#endif // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_ICON_H_
// Copyright 2014 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/manage_passwords_icon_mock.h"
ManagePasswordsIconMock::ManagePasswordsIconMock() : bubble_shown_count_(0) {
}
ManagePasswordsIconMock::~ManagePasswordsIconMock() {
}
void ManagePasswordsIconMock::ShowBubbleWithoutUserInteraction() {
++bubble_shown_count_;
}
void ManagePasswordsIconMock::SetStateInternal(ManagePasswordsIcon::State) {
}
// Copyright 2014 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.
#ifndef CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_ICON_MOCK_H_
#define CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_ICON_MOCK_H_
#include "chrome/browser/ui/passwords/manage_passwords_icon.h"
// Mock ManagePasswordsIcon, for testing purposes only.
class ManagePasswordsIconMock : public ManagePasswordsIcon {
public:
ManagePasswordsIconMock();
~ManagePasswordsIconMock();
// ManagePasswordsIcon:
virtual void ShowBubbleWithoutUserInteraction() OVERRIDE;
int bubble_shown_count() const { return bubble_shown_count_; }
protected:
virtual void SetStateInternal(State state) OVERRIDE;
private:
int bubble_shown_count_;
DISALLOW_COPY_AND_ASSIGN(ManagePasswordsIconMock);
};
#endif // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_ICON_MOCK_H_
......@@ -39,6 +39,7 @@
#include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
#include "chrome/browser/ui/omnibox/omnibox_popup_view.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h"
#include "chrome/browser/ui/passwords/manage_passwords_icon.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/toolbar/origin_chip_info.h"
#include "chrome/browser/ui/view_ids.h"
......@@ -378,7 +379,7 @@ void LocationBarView::Init() {
AddChildView(open_pdf_in_reader_view_);
manage_passwords_icon_view_ = new ManagePasswordsIconView(delegate_);
manage_passwords_icon_view_->set_id(VIEW_ID_MANAGE_PASSWORDS_ICON_BUTTON);
manage_passwords_icon_view_->SetState(ManagePasswordsIcon::INACTIVE_STATE);
AddChildView(manage_passwords_icon_view_);
translate_icon_view_ = new TranslateIconView(command_updater());
......@@ -1192,20 +1193,11 @@ bool LocationBarView::RefreshManagePasswordsIconView() {
if (!web_contents)
return false;
const bool was_visible = manage_passwords_icon_view_->visible();
manage_passwords_icon_view_->Update(
ManagePasswordsBubbleUIController::FromWebContents(web_contents));
ManagePasswordsBubbleUIController::FromWebContents(
web_contents)->UpdateIconAndBubbleState(manage_passwords_icon_view_);
return was_visible != manage_passwords_icon_view_->visible();
}
void LocationBarView::ShowManagePasswordsBubbleIfNeeded() {
DCHECK(manage_passwords_icon_view_);
WebContents* web_contents = GetWebContents();
if (!web_contents)
return;
manage_passwords_icon_view_->ShowBubbleIfNeeded(
ManagePasswordsBubbleUIController::FromWebContents(web_contents));
}
void LocationBarView::ShowFirstRunBubbleInternal() {
#if !defined(OS_CHROMEOS)
// First run bubble doesn't make sense for Chrome OS.
......@@ -1295,7 +1287,6 @@ void LocationBarView::UpdateManagePasswordsIconAndBubble() {
Layout();
SchedulePaint();
}
ShowManagePasswordsBubbleIfNeeded();
}
void LocationBarView::UpdatePageActions() {
......
......@@ -88,7 +88,9 @@ void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents,
DCHECK(browser);
DCHECK(browser->window());
DCHECK(browser->fullscreen_controller());
DCHECK(!IsShowing());
if (IsShowing())
return;
BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser);
bool is_fullscreen = browser_view->IsFullscreen();
......
......@@ -5,6 +5,7 @@
#include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
......@@ -14,49 +15,46 @@
ManagePasswordsIconView::ManagePasswordsIconView(
LocationBarView::Delegate* location_bar_delegate)
: location_bar_delegate_(location_bar_delegate) {
set_id(VIEW_ID_MANAGE_PASSWORDS_ICON_BUTTON);
SetAccessibilityFocusable(true);
Update(NULL);
SetState(ManagePasswordsIcon::INACTIVE_STATE);
}
ManagePasswordsIconView::~ManagePasswordsIconView() {}
void ManagePasswordsIconView::Update(
ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller) {
SetVisible(manage_passwords_bubble_ui_controller &&
manage_passwords_bubble_ui_controller->
manage_passwords_icon_to_be_shown() &&
!location_bar_delegate_->GetToolbarModel()->input_in_progress());
if (!visible()) {
ManagePasswordsBubbleView::CloseBubble();
void ManagePasswordsIconView::SetStateInternal(
ManagePasswordsIcon::State state) {
if (state == ManagePasswordsIcon::INACTIVE_STATE) {
SetVisible(false);
if (ManagePasswordsBubbleView::IsShowing())
ManagePasswordsBubbleView::CloseBubble();
return;
}
int icon_to_display =
manage_passwords_bubble_ui_controller->autofill_blocked()
? IDR_SAVE_PASSWORD_BLACKLISTED
: IDR_SAVE_PASSWORD;
SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
icon_to_display));
SetTooltip(manage_passwords_bubble_ui_controller->password_to_be_saved());
}
void ManagePasswordsIconView::ShowBubbleIfNeeded(
ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller) {
if (manage_passwords_bubble_ui_controller->
manage_passwords_bubble_needs_showing() &&
visible() &&
!ManagePasswordsBubbleView::IsShowing()) {
ManagePasswordsBubbleView::ShowBubble(
location_bar_delegate_->GetWebContents(),
ManagePasswordsBubbleView::AUTOMATIC);
manage_passwords_bubble_ui_controller->OnBubbleShown();
}
// Start with the correct values for ManagePasswordsIcon::MANAGE_STATE, and
// adjust things accordingly if we're either in BLACKLISTED_STATE or
// PENDING_STATE.
int which_icon = IDR_SAVE_PASSWORD;
int which_text = IDS_PASSWORD_MANAGER_TOOLTIP_MANAGE;
if (state == ManagePasswordsIcon::BLACKLISTED_STATE)
which_icon = IDR_SAVE_PASSWORD_BLACKLISTED;
else if (state == ManagePasswordsIcon::PENDING_STATE)
which_text = IDS_PASSWORD_MANAGER_TOOLTIP_SAVE;
SetVisible(true);
SetImage(
ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(which_icon));
SetTooltipText(l10n_util::GetStringUTF16(which_text));
}
void ManagePasswordsIconView::SetTooltip(bool password_to_be_saved) {
SetTooltipText(l10n_util::GetStringUTF16(
(password_to_be_saved ?
IDS_PASSWORD_MANAGER_TOOLTIP_SAVE :
IDS_PASSWORD_MANAGER_TOOLTIP_MANAGE)));
void ManagePasswordsIconView::ShowBubbleWithoutUserInteraction() {
// Suppress the bubble if the user is working in the omnibox.
if (location_bar_delegate_->GetToolbarModel()->input_in_progress())
return;
ManagePasswordsBubbleView::ShowBubble(
location_bar_delegate_->GetWebContents(),
ManagePasswordsBubbleView::AUTOMATIC);
}
bool ManagePasswordsIconView::GetTooltipText(const gfx::Point& p,
......
......@@ -6,13 +6,15 @@
#define CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORDS_ICON_VIEW_H_
#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
#include "chrome/browser/ui/passwords/manage_passwords_icon.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "ui/views/controls/image_view.h"
class ManagePasswordsBubbleUIController;
// View for the password icon in the Omnibox.
class ManagePasswordsIconView : public views::ImageView {
class ManagePasswordsIconView : public ManagePasswordsIcon,
public views::ImageView {
public:
// Clicking on the ManagePasswordsIconView shows a ManagePasswordsBubbleView,
// which requires the current WebContents. Because the current WebContents
......@@ -23,16 +25,12 @@ class ManagePasswordsIconView : public views::ImageView {
LocationBarView::Delegate* location_bar_delegate);
virtual ~ManagePasswordsIconView();
// Updates the image and its tooltip appropriately, hiding or showing the icon
// as needed.
void Update(
ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller);
// ManagePasswordsIcon:
virtual void ShowBubbleWithoutUserInteraction() OVERRIDE;
// Shows a bubble from the icon if a password form was submitted.
void ShowBubbleIfNeeded(
ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller);
void SetTooltip(bool password_to_be_saved);
protected:
// ManagePasswordsIcon:
virtual void SetStateInternal(ManagePasswordsIcon::State state) OVERRIDE;
private:
// views::ImageView:
......
......@@ -1243,6 +1243,8 @@
'browser/ui/passwords/manage_passwords_bubble_model.h',
'browser/ui/passwords/manage_passwords_bubble_ui_controller.cc',
'browser/ui/passwords/manage_passwords_bubble_ui_controller.h',
'browser/ui/passwords/manage_passwords_icon.cc',
'browser/ui/passwords/manage_passwords_icon.h',
'browser/ui/passwords/password_manager_presenter.cc',
'browser/ui/passwords/password_manager_presenter.h',
'browser/ui/passwords/password_ui_view.h',
......
......@@ -1665,8 +1665,10 @@
'browser/ui/omnibox/omnibox_popup_model_unittest.cc',
'browser/ui/omnibox/omnibox_view_unittest.cc',
'browser/ui/panels/panel_mouse_watcher_unittest.cc',
'browser/ui/passwords/manage_passwords_icon_mock.cc',
'browser/ui/passwords/manage_passwords_bubble_model_unittest.cc',
'browser/ui/passwords/manage_passwords_bubble_ui_controller_mock.cc',
'browser/ui/passwords/manage_passwords_bubble_ui_controller_unittest.cc',
'browser/ui/passwords/password_manager_presenter_unittest.cc',
'browser/ui/search_engines/keyword_editor_controller_unittest.cc',
'browser/ui/search/instant_page_unittest.cc',
......
......@@ -104,6 +104,8 @@
'..',
],
'sources': [
'password_manager/core/browser/mock_password_manager_driver.cc',
'password_manager/core/browser/mock_password_manager_driver.h',
'password_manager/core/browser/mock_password_store.cc',
'password_manager/core/browser/mock_password_store.h',
'password_manager/core/browser/password_form_data.cc',
......
// Copyright 2014 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 "components/password_manager/core/browser/mock_password_manager_driver.h"
namespace password_manager {
// Out-of-lining these methods only because the chromium-style clang plugin
// complains that complex constructors and destructors should not be inlined.
//
// http://www.chromium.org/developers/coding-style/chromium-style-checker-errors
MockPasswordManagerDriver::MockPasswordManagerDriver() {
}
MockPasswordManagerDriver::~MockPasswordManagerDriver() {
}
} // namespace password_manager
// Copyright 2014 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.
#ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_MOCK_PASSWORD_MANAGER_DRIVER_H_
#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_MOCK_PASSWORD_MANAGER_DRIVER_H_
#include "components/autofill/core/browser/autofill_manager.h"
#include "components/autofill/core/common/form_data.h"
#include "components/autofill/core/common/password_form.h"
#include "components/autofill/core/common/password_form_fill_data.h"
#include "components/password_manager/core/browser/password_autofill_manager.h"
#include "components/password_manager/core/browser/password_generation_manager.h"
#include "components/password_manager/core/browser/password_manager.h"
#include "components/password_manager/core/browser/password_manager_driver.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace password_manager {
class MockPasswordManagerDriver : public PasswordManagerDriver {
public:
MockPasswordManagerDriver();
virtual ~MockPasswordManagerDriver();
MOCK_METHOD1(FillPasswordForm, void(const autofill::PasswordFormFillData&));
MOCK_METHOD0(DidLastPageLoadEncounterSSLErrors, bool());
MOCK_METHOD0(IsOffTheRecord, bool());
MOCK_METHOD0(GetPasswordGenerationManager, PasswordGenerationManager*());
MOCK_METHOD0(GetPasswordManager, PasswordManager*());
MOCK_METHOD0(GetAutofillManager, autofill::AutofillManager*());
MOCK_METHOD0(GetPasswordAutofillManager, PasswordAutofillManager*());
MOCK_METHOD1(AllowPasswordGenerationForForm, void(autofill::PasswordForm*));
MOCK_METHOD1(AccountCreationFormsFound,
void(const std::vector<autofill::FormData>&));
MOCK_METHOD2(AcceptPasswordAutofillSuggestion,
void(const base::string16&, const base::string16&));
};
} // namespace password_manager
#endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_MOCK_PASSWORD_MANAGER_DRIVER_H_
......@@ -11,6 +11,7 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/common/password_form.h"
#include "components/password_manager/core/browser/mock_password_manager_driver.h"
#include "components/password_manager/core/browser/mock_password_store.h"
#include "components/password_manager/core/browser/password_form_manager.h"
#include "components/password_manager/core/browser/password_manager.h"
......@@ -44,25 +45,6 @@ void RunAllPendingTasks() {
run_loop.Run();
}
class MockPasswordManagerDriver : public PasswordManagerDriver {
public:
MockPasswordManagerDriver() {}
virtual ~MockPasswordManagerDriver() {}
MOCK_METHOD1(FillPasswordForm, void(const autofill::PasswordFormFillData&));
MOCK_METHOD0(DidLastPageLoadEncounterSSLErrors, bool());
MOCK_METHOD0(IsOffTheRecord, bool());
MOCK_METHOD0(GetPasswordGenerationManager, PasswordGenerationManager*());
MOCK_METHOD0(GetPasswordManager, PasswordManager*());
MOCK_METHOD0(GetAutofillManager, autofill::AutofillManager*());
MOCK_METHOD0(GetPasswordAutofillManager, PasswordAutofillManager*());
MOCK_METHOD1(AllowPasswordGenerationForForm, void(autofill::PasswordForm*));
MOCK_METHOD1(AccountCreationFormsFound,
void(const std::vector<autofill::FormData>&));
MOCK_METHOD2(AcceptPasswordAutofillSuggestion,
void(const base::string16&, const base::string16&));
};
class TestPasswordManagerClient : public StubPasswordManagerClient {
public:
explicit TestPasswordManagerClient(PasswordStore* password_store)
......
......@@ -10,6 +10,7 @@
#include "base/prefs/testing_pref_service.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "components/password_manager/core/browser/mock_password_manager_driver.h"
#include "components/password_manager/core/browser/mock_password_store.h"
#include "components/password_manager/core/browser/password_autofill_manager.h"
#include "components/password_manager/core/browser/password_manager.h"
......@@ -47,22 +48,6 @@ class MockPasswordManagerClient : public StubPasswordManagerClient {
MOCK_METHOD0(GetDriver, PasswordManagerDriver*());
};
class MockPasswordManagerDriver : public PasswordManagerDriver {
public:
MOCK_METHOD1(FillPasswordForm, void(const autofill::PasswordFormFillData&));
MOCK_METHOD0(DidLastPageLoadEncounterSSLErrors, bool());
MOCK_METHOD0(IsOffTheRecord, bool());
MOCK_METHOD0(GetPasswordGenerationManager, PasswordGenerationManager*());
MOCK_METHOD0(GetPasswordManager, PasswordManager*());
MOCK_METHOD0(GetAutofillManager, autofill::AutofillManager*());
MOCK_METHOD1(AllowPasswordGenerationForForm, void(autofill::PasswordForm*));
MOCK_METHOD1(AccountCreationFormsFound,
void(const std::vector<autofill::FormData>&));
MOCK_METHOD2(AcceptPasswordAutofillSuggestion,
void(const base::string16&, const base::string16&));
MOCK_METHOD0(GetPasswordAutofillManager, PasswordAutofillManager*());
};
ACTION_P(InvokeConsumer, forms) { arg0->OnGetPasswordStoreResults(forms); }
ACTION_P(SaveToScopedPtr, scoped) { scoped->reset(arg0); }
......
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