Revert of Password bubble: Introduce a command to open the bubble....

Revert of Password bubble: Introduce a command to open the bubble. (https://codereview.chromium.org/246393004/)

Reason for revert:
This is causing leaks on linux asan lsan:
http://build.chromium.org/p/chromium.memory/builders/Linux%20ASan%20LSan%20Tests%20%283%29/builds/2361

Original issue's description:
> Password bubble: ManagePasswordsIconView is now a BubbleIconView.
> 
> This CL introduces a new browser command to open the Manage Passwords bubble,
> and converts the ManagePasswordsIconView class into a subclass of
> BubbleIconView, which uses the new command to control the bubble's state.
> This allows us to more easily test the view and the UI controller, as each
> object's job is now more clearly defined (and the view is now doing a good
> deal less work), and to independently verify that the command is doing the
> right thing.
> 
> After this CL, we'll (finally!) have something approaching reasonable test
> coverage for the core of the views code.
> 
> BUG=365678
> TBR=cpu@chromium.org
> 
> Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=266859

TBR=markusheintz@chromium.org,vabr@chromium.org,cpu@chromium.org,pkasting@chromium.org,mkwst@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=365678

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266862 0039d316-1c4b-4281-b951-d872f2087c98
parent e666611c
......@@ -88,7 +88,6 @@
#define IDC_PRINT_TO_DESTINATION 35008
#define IDC_BOOKMARK_PAGE_FROM_STAR 35009
#define IDC_TRANSLATE_PAGE 35010
#define IDC_MANAGE_PASSWORDS_FOR_PAGE 35011
// When adding a new encoding to this list, be sure to append it to the
// EncodingMenuController::kValidEncodingIds array in
......
......@@ -562,11 +562,6 @@ void BrowserCommandController::ExecuteCommandWithDisposition(
case IDC_TRANSLATE_PAGE:
Translate(browser_);
break;
case IDC_MANAGE_PASSWORDS_FOR_PAGE:
ManagePasswordsForPage(browser_);
break;
// Page encoding commands
case IDC_ENCODING_AUTO_DETECT:
browser_->ToggleEncodingAutoDetect();
break;
......@@ -926,7 +921,6 @@ void BrowserCommandController::InitCommandState() {
// Page-related commands
command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true);
command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE_FROM_STAR, true);
command_updater_.UpdateCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE, true);
command_updater_.UpdateCommandEnabled(IDC_ENCODING_AUTO_DETECT, true);
command_updater_.UpdateCommandEnabled(IDC_ENCODING_UTF8, true);
command_updater_.UpdateCommandEnabled(IDC_ENCODING_UTF16LE, true);
......
......@@ -785,18 +785,6 @@ void Translate(Browser* browser) {
web_contents, step, TranslateErrors::NONE);
}
void ManagePasswordsForPage(Browser* browser) {
// TODO(mkwst): Implement this feature on Mac: http://crbug.com/261628
#if !defined(OS_MACOSX)
if (!browser->window()->IsActive())
return;
WebContents* web_contents =
browser->tab_strip_model()->GetActiveWebContents();
chrome::ShowManagePasswordsBubble(web_contents);
#endif
}
void TogglePagePinnedToStartScreen(Browser* browser) {
#if defined(OS_WIN)
MetroPinTabHelper::FromWebContents(
......
......@@ -97,7 +97,6 @@ bool CanBookmarkCurrentPage(const Browser* browser);
void BookmarkAllTabs(Browser* browser);
bool CanBookmarkAllTabs(const Browser* browser);
void Translate(Browser* browser);
void ManagePasswordsForPage(Browser* browser);
void TogglePagePinnedToStartScreen(Browser* browser);
void SavePage(Browser* browser);
bool CanSavePage(const Browser* browser);
......
......@@ -114,13 +114,6 @@ void ShowSignedCertificateTimestampsViewer(
content::WebContents* web_contents,
const content::SignedCertificateTimestampIDStatusList& sct_ids_list);
#if !defined(OS_MACOSX)
// Shows the ManagePasswords bubble for a particular |web_contents|.
//
// TODO(mkwst): Implement this feature on Mac: http://crbug.com/261628
void ShowManagePasswordsBubble(content::WebContents* web_contents);
#endif
} // namespace chrome
#endif // CHROME_BROWSER_UI_BROWSER_DIALOGS_H_
......@@ -170,8 +170,6 @@ void ManagePasswordsBubbleUIController::UpdateIconAndBubbleState(
if (manage_passwords_bubble_needs_showing_) {
DCHECK(state == ManagePasswordsIcon::PENDING_STATE);
// TODO(mkwst): Replace this with execution of a browser command once we
// can pipe a CommandUpdater down here.
icon->ShowBubbleWithoutUserInteraction();
manage_passwords_bubble_needs_showing_ = false;
}
......
......@@ -14,5 +14,5 @@ void ManagePasswordsIcon::SetState(State state) {
if (state_ == state)
return;
state_ = state;
UpdateVisibleUI();
SetStateInternal(state);
}
......@@ -42,9 +42,8 @@ class ManagePasswordsIcon {
ManagePasswordsIcon();
~ManagePasswordsIcon();
// Called from SetState() iff the icon's state has changed in order to do
// whatever platform-specific UI work is necessary given the new state.
virtual void UpdateVisibleUI() = 0;
// Called from SetState() iff the icon's state has changed.
virtual void SetStateInternal(State state) = 0;
private:
State state_;
......
......@@ -14,5 +14,5 @@ void ManagePasswordsIconMock::ShowBubbleWithoutUserInteraction() {
++bubble_shown_count_;
}
void ManagePasswordsIconMock::UpdateVisibleUI() {
void ManagePasswordsIconMock::SetStateInternal(ManagePasswordsIcon::State) {
}
......@@ -18,8 +18,7 @@ class ManagePasswordsIconMock : public ManagePasswordsIcon {
int bubble_shown_count() const { return bubble_shown_count_; }
protected:
// ManagePasswordsIcon:
virtual void UpdateVisibleUI() OVERRIDE;
virtual void SetStateInternal(State state) OVERRIDE;
private:
int bubble_shown_count_;
......
......@@ -378,8 +378,8 @@ void LocationBarView::Init() {
open_pdf_in_reader_view_ = new OpenPDFInReaderView();
AddChildView(open_pdf_in_reader_view_);
manage_passwords_icon_view_ =
new ManagePasswordsIconView(delegate_, command_updater());
manage_passwords_icon_view_ = new ManagePasswordsIconView(delegate_);
manage_passwords_icon_view_->SetState(ManagePasswordsIcon::INACTIVE_STATE);
AddChildView(manage_passwords_icon_view_);
translate_icon_view_ = new TranslateIconView(command_updater());
......
......@@ -10,7 +10,6 @@
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/browser/ui/views/passwords/manage_password_item_view.h"
......@@ -76,23 +75,6 @@ class SavePasswordRefusalComboboxModel : public ui::ComboboxModel {
} // namespace
// Globals --------------------------------------------------------------------
namespace chrome {
void ShowManagePasswordsBubble(content::WebContents* web_contents) {
ManagePasswordsBubbleUIController* controller =
ManagePasswordsBubbleUIController::FromWebContents(web_contents);
ManagePasswordsBubbleView::ShowBubble(
web_contents,
controller->manage_passwords_bubble_needs_showing() ?
ManagePasswordsBubbleView::AUTOMATIC :
ManagePasswordsBubbleView::USER_ACTION);
}
} // namespace chrome
// ManagePasswordsBubbleView --------------------------------------------------
// static
......
// 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/views/passwords/manage_passwords_bubble_view.h"
#include "base/metrics/histogram_samples.h"
#include "base/test/statistics_delta_reader.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/views/passwords/manage_passwords_view_test.h"
#include "components/password_manager/core/browser/password_manager_metrics_util.h"
#include "components/password_manager/core/browser/stub_password_manager_client.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
const char kDisplayDispositionMetric[] = "PasswordBubble.DisplayDisposition";
} // namespace
typedef ManagePasswordsViewTest ManagePasswordsBubbleViewTest;
IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, BasicOpenAndClose) {
EXPECT_FALSE(ManagePasswordsBubbleView::IsShowing());
ManagePasswordsBubbleView::ShowBubble(
browser()->tab_strip_model()->GetActiveWebContents(),
ManagePasswordsBubble::USER_ACTION);
EXPECT_TRUE(ManagePasswordsBubbleView::IsShowing());
ManagePasswordsBubbleView::CloseBubble();
EXPECT_FALSE(ManagePasswordsBubbleView::IsShowing());
// And, just for grins, ensure that we can re-open the bubble.
ManagePasswordsBubbleView::ShowBubble(
browser()->tab_strip_model()->GetActiveWebContents(),
ManagePasswordsBubble::USER_ACTION);
EXPECT_TRUE(ManagePasswordsBubbleView::IsShowing());
ManagePasswordsBubbleView::CloseBubble();
EXPECT_FALSE(ManagePasswordsBubbleView::IsShowing());
}
// Same as 'BasicOpenAndClose', but use the command rather than the static
// method directly.
IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, CommandControlsBubble) {
// The command only works if the icon is visible, so get into management mode.
SetupManagingPasswords();
EXPECT_FALSE(ManagePasswordsBubbleView::IsShowing());
ExecuteManagePasswordsCommand();
EXPECT_TRUE(ManagePasswordsBubbleView::IsShowing());
ManagePasswordsBubbleView::CloseBubble();
EXPECT_FALSE(ManagePasswordsBubbleView::IsShowing());
// And, just for grins, ensure that we can re-open the bubble.
ExecuteManagePasswordsCommand();
EXPECT_TRUE(ManagePasswordsBubbleView::IsShowing());
ManagePasswordsBubbleView::CloseBubble();
EXPECT_FALSE(ManagePasswordsBubbleView::IsShowing());
}
IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest,
CommandExecutionInManagingState) {
base::StatisticsDeltaReader statistics_delta_reader;
SetupManagingPasswords();
ExecuteManagePasswordsCommand();
scoped_ptr<base::HistogramSamples> samples(
statistics_delta_reader.GetHistogramSamplesSinceCreation(
kDisplayDispositionMetric));
EXPECT_EQ(
0,
samples->GetCount(
password_manager::metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING));
EXPECT_EQ(0,
samples->GetCount(
password_manager::metrics_util::MANUAL_WITH_PASSWORD_PENDING));
EXPECT_EQ(1,
samples->GetCount(
password_manager::metrics_util::MANUAL_MANAGE_PASSWORDS));
}
IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest,
CommandExecutionInAutomaticState) {
base::StatisticsDeltaReader statistics_delta_reader;
SetupPendingPassword();
ExecuteManagePasswordsCommand();
scoped_ptr<base::HistogramSamples> samples(
statistics_delta_reader.GetHistogramSamplesSinceCreation(
kDisplayDispositionMetric));
EXPECT_EQ(
1,
samples->GetCount(
password_manager::metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING));
EXPECT_EQ(0,
samples->GetCount(
password_manager::metrics_util::MANUAL_WITH_PASSWORD_PENDING));
EXPECT_EQ(0,
samples->GetCount(
password_manager::metrics_util::MANUAL_MANAGE_PASSWORDS));
}
IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest,
CommandExecutionInPendingState) {
base::StatisticsDeltaReader statistics_delta_reader;
SetupPendingPassword();
// Open once with pending password: automagical!
ExecuteManagePasswordsCommand();
ManagePasswordsBubbleView::CloseBubble();
// This opening should be measured as manual.
ExecuteManagePasswordsCommand();
scoped_ptr<base::HistogramSamples> samples(
statistics_delta_reader.GetHistogramSamplesSinceCreation(
kDisplayDispositionMetric));
EXPECT_EQ(
1,
samples->GetCount(
password_manager::metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING));
EXPECT_EQ(1,
samples->GetCount(
password_manager::metrics_util::MANUAL_WITH_PASSWORD_PENDING));
EXPECT_EQ(0,
samples->GetCount(
password_manager::metrics_util::MANUAL_MANAGE_PASSWORDS));
}
......@@ -4,8 +4,6 @@
#include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/command_updater.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"
......@@ -15,45 +13,38 @@
#include "ui/base/resource/resource_bundle.h"
ManagePasswordsIconView::ManagePasswordsIconView(
LocationBarView::Delegate* location_bar_delegate,
CommandUpdater* command_updater)
: BubbleIconView(command_updater, IDC_MANAGE_PASSWORDS_FOR_PAGE),
location_bar_delegate_(location_bar_delegate),
command_updater_(command_updater),
icon_id_(0),
tooltip_text_id_(0) {
LocationBarView::Delegate* location_bar_delegate)
: location_bar_delegate_(location_bar_delegate) {
set_id(VIEW_ID_MANAGE_PASSWORDS_ICON_BUTTON);
SetAccessibilityFocusable(true);
UpdateVisibleUI();
SetState(ManagePasswordsIcon::INACTIVE_STATE);
}
ManagePasswordsIconView::~ManagePasswordsIconView() {}
void ManagePasswordsIconView::UpdateVisibleUI() {
// If the icon is inactive: clear out it's image and tooltip, hide the icon,
// close any active bubble, and exit early.
if (state() == ManagePasswordsIcon::INACTIVE_STATE) {
icon_id_ = 0;
tooltip_text_id_ = 0;
void ManagePasswordsIconView::SetStateInternal(
ManagePasswordsIcon::State state) {
if (state == ManagePasswordsIcon::INACTIVE_STATE) {
SetVisible(false);
if (ManagePasswordsBubbleView::IsShowing())
ManagePasswordsBubbleView::CloseBubble();
return;
}
// Otherwise, start with the correct values for MANAGE_STATE, and adjust
// things accordingly if we're either in BLACKLISTED_STATE or PENDING_STATE.
icon_id_ = IDR_SAVE_PASSWORD;
tooltip_text_id_ = IDS_PASSWORD_MANAGER_TOOLTIP_MANAGE;
if (state() == ManagePasswordsIcon::BLACKLISTED_STATE)
icon_id_ = IDR_SAVE_PASSWORD_BLACKLISTED;
else if (state() == ManagePasswordsIcon::PENDING_STATE)
tooltip_text_id_ = IDS_PASSWORD_MANAGER_TOOLTIP_SAVE;
// 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(icon_id_));
SetTooltipText(l10n_util::GetStringUTF16(tooltip_text_id_));
SetImage(
ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(which_icon));
SetTooltipText(l10n_util::GetStringUTF16(which_text));
}
void ManagePasswordsIconView::ShowBubbleWithoutUserInteraction() {
......@@ -61,13 +52,36 @@ void ManagePasswordsIconView::ShowBubbleWithoutUserInteraction() {
if (location_bar_delegate_->GetToolbarModel()->input_in_progress())
return;
command_updater_->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE);
ManagePasswordsBubbleView::ShowBubble(
location_bar_delegate_->GetWebContents(),
ManagePasswordsBubbleView::AUTOMATIC);
}
bool ManagePasswordsIconView::GetTooltipText(const gfx::Point& p,
base::string16* tooltip) const {
// Don't show tooltip if the password bubble is displayed.
return !ManagePasswordsBubbleView::IsShowing() &&
ImageView::GetTooltipText(p, tooltip);
}
bool ManagePasswordsIconView::IsBubbleShowing() const {
return ManagePasswordsBubbleView::IsShowing();
void ManagePasswordsIconView::OnGestureEvent(ui::GestureEvent* event) {
if (event->type() == ui::ET_GESTURE_TAP) {
ManagePasswordsBubbleView::ShowBubble(
location_bar_delegate_->GetWebContents(),
ManagePasswordsBubbleView::USER_ACTION);
event->SetHandled();
}
}
void ManagePasswordsIconView::OnExecuting(
BubbleIconView::ExecuteSource source) {
bool ManagePasswordsIconView::OnMousePressed(const ui::MouseEvent& event) {
// Do nothing until the mouse button is released.
return true;
}
void ManagePasswordsIconView::OnMouseReleased(const ui::MouseEvent& event) {
if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) {
ManagePasswordsBubbleView::ShowBubble(
location_bar_delegate_->GetWebContents(),
ManagePasswordsBubbleView::USER_ACTION);
}
}
......@@ -7,60 +7,42 @@
#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/bubble_icon_view.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "ui/views/controls/image_view.h"
class CommandUpdater;
class ManagePasswordsBubbleUIController;
// View for the password icon in the Omnibox.
class ManagePasswordsIconView : public ManagePasswordsIcon,
public BubbleIconView {
public views::ImageView {
public:
// Clicking on the ManagePasswordsIconView shows a ManagePasswordsBubbleView,
// which requires the current WebContents. Because the current WebContents
// changes as the user switches tabs, it cannot be provided in the
// constructor. Instead, a LocationBarView::Delegate is passed here so that it
// can be queried for the current WebContents as needed.
ManagePasswordsIconView(LocationBarView::Delegate* location_bar_delegate,
CommandUpdater* command_updater);
explicit ManagePasswordsIconView(
LocationBarView::Delegate* location_bar_delegate);
virtual ~ManagePasswordsIconView();
// ManagePasswordsIcon:
//
// TODO(mkwst): Remove this once we get rid of the single call to
// ShowBubbleWithoutUserInteraction in ManagePasswordsBubbleUIController.
virtual void ShowBubbleWithoutUserInteraction() OVERRIDE;
// BubbleIconView:
virtual bool IsBubbleShowing() const OVERRIDE;
virtual void OnExecuting(BubbleIconView::ExecuteSource source) OVERRIDE;
#if defined(UNIT_TEST)
int icon_id() const { return icon_id_; }
int tooltip_text_id() const { return tooltip_text_id_; }
#endif
protected:
// ManagePasswordsIcon:
virtual void UpdateVisibleUI() OVERRIDE;
virtual void SetStateInternal(ManagePasswordsIcon::State state) OVERRIDE;
private:
// views::ImageView:
virtual bool GetTooltipText(const gfx::Point& p,
base::string16* tooltip) const OVERRIDE;
virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE;
// The delegate used to get the currently visible WebContents.
LocationBarView::Delegate* location_bar_delegate_;
// The updater used to deliver commands to the browser; we'll use this to
// pop open the bubble when necessary.
//
// TODO(mkwst): Remove this once we get rid of the single call to
// ShowBubbleWithoutUserInteraction in ManagePasswordsBubbleUIController.
CommandUpdater* command_updater_;
// The ID of the icon and text resources that are currently displayed.
int icon_id_;
int tooltip_text_id_;
DISALLOW_COPY_AND_ASSIGN(ManagePasswordsIconView);
};
......
// 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/views/passwords/manage_passwords_icon_view.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/views/passwords/manage_passwords_view_test.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "testing/gtest/include/gtest/gtest.h"
typedef ManagePasswordsViewTest ManagePasswordsIconViewTest;
IN_PROC_BROWSER_TEST_F(ManagePasswordsIconViewTest, DefaultStateIsInactive) {
EXPECT_EQ(ManagePasswordsIcon::INACTIVE_STATE, view()->state());
EXPECT_FALSE(view()->visible());
EXPECT_EQ(0, view()->icon_id());
EXPECT_EQ(0, view()->tooltip_text_id());
}
IN_PROC_BROWSER_TEST_F(ManagePasswordsIconViewTest, PendingState) {
SetupPendingPassword();
EXPECT_EQ(ManagePasswordsIcon::PENDING_STATE, view()->state());
EXPECT_TRUE(view()->visible());
EXPECT_EQ(IDR_SAVE_PASSWORD, view()->icon_id());
EXPECT_EQ(IDS_PASSWORD_MANAGER_TOOLTIP_SAVE, view()->tooltip_text_id());
}
IN_PROC_BROWSER_TEST_F(ManagePasswordsIconViewTest, ManageState) {
SetupManagingPasswords();
EXPECT_EQ(ManagePasswordsIcon::MANAGE_STATE, view()->state());
EXPECT_TRUE(view()->visible());
EXPECT_EQ(IDR_SAVE_PASSWORD, view()->icon_id());
EXPECT_EQ(IDS_PASSWORD_MANAGER_TOOLTIP_MANAGE, view()->tooltip_text_id());
}
IN_PROC_BROWSER_TEST_F(ManagePasswordsIconViewTest, BlacklistedState) {
SetupBlackistedPassword();
EXPECT_EQ(ManagePasswordsIcon::BLACKLISTED_STATE, view()->state());
EXPECT_TRUE(view()->visible());
EXPECT_EQ(IDR_SAVE_PASSWORD_BLACKLISTED, view()->icon_id());
EXPECT_EQ(IDS_PASSWORD_MANAGER_TOOLTIP_MANAGE, view()->tooltip_text_id());
}
// 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/views/passwords/manage_passwords_view_test.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_command_controller.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/tabs/tab_strip_model.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h"
#include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.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/password_manager_metrics_util.h"
#include "components/password_manager/core/browser/stub_password_manager_client.h"
#include "testing/gtest/include/gtest/gtest.h"
void ManagePasswordsViewTest::SetUpOnMainThread() {
// Create the test UIController here so that it's bound to the currently
// active WebContents.
new ManagePasswordsBubbleUIControllerMock(
browser()->tab_strip_model()->GetActiveWebContents());
}
ManagePasswordsBubbleUIControllerMock* ManagePasswordsViewTest::controller() {
return static_cast<ManagePasswordsBubbleUIControllerMock*>(
ManagePasswordsBubbleUIController::FromWebContents(
browser()->tab_strip_model()->GetActiveWebContents()));
}
ManagePasswordsIconView* ManagePasswordsViewTest::view() {
BrowserView* browser_view = static_cast<BrowserView*>(browser()->window());
return browser_view->GetToolbarView()->location_bar()->
manage_passwords_icon_view();
}
void ManagePasswordsViewTest::ExecuteManagePasswordsCommand() {
CommandUpdater* updater = browser()->command_controller()->command_updater();
EXPECT_TRUE(updater->IsCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE));
EXPECT_TRUE(updater->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE));
}
void ManagePasswordsViewTest::SetupManagingPasswords() {
base::string16 kTestUsername = base::ASCIIToUTF16("test_username");
autofill::PasswordFormMap map;
map[kTestUsername] = test_form();
controller()->OnPasswordAutofilled(map);
controller()->UpdateIconAndBubbleState(view());
}
void ManagePasswordsViewTest::SetupPendingPassword() {
password_manager::StubPasswordManagerClient client;
password_manager::MockPasswordManagerDriver driver;
scoped_ptr<password_manager::PasswordFormManager> test_form_manager(
new password_manager::PasswordFormManager(
NULL, &client, &driver, *test_form(), false));
controller()->OnPasswordSubmitted(test_form_manager.release());
controller()->UpdateIconAndBubbleState(view());
}
void ManagePasswordsViewTest::SetupBlackistedPassword() {
controller()->OnBlacklistBlockedAutofill();
controller()->UpdateIconAndBubbleState(view());
}
// 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_VIEWS_PASSWORDS_MANAGE_PASSWORDS_VIEW_TEST_H_
#define CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORDS_VIEW_TEST_H_
#include "chrome/test/base/in_process_browser_test.h"
#include "components/autofill/core/common/password_form.h"
#include "testing/gtest/include/gtest/gtest.h"
class ManagePasswordsBubbleUIControllerMock;
class ManagePasswordsIconView;
// Test class for the various password management view bits and pieces. Sets
// up a ManagePasswordsBubbleUIControllerMock, and provides some helper methods
// to poke at the bubble, icon, and controller's state.
class ManagePasswordsViewTest : public InProcessBrowserTest {
public:
ManagePasswordsViewTest() {}
// InProcessBrowserTest:
virtual void SetUpOnMainThread() OVERRIDE;
// Get the mock UI controller for the current WebContents.
ManagePasswordsBubbleUIControllerMock* controller();
// Get the icon view for the current WebContents.
ManagePasswordsIconView* view();
// Execute the browser command to open the manage passwords bubble.
void ExecuteManagePasswordsCommand();
// Put the controller, icon, and bubble into a managing-password state.
void SetupManagingPasswords();
// Put the controller, icon, and bubble into a pending-password state.
void SetupPendingPassword();
// Put the controller, icon, and bubble into a blacklisted state.
void SetupBlackistedPassword();
autofill::PasswordForm* test_form() { return &test_form_; }
private:
autofill::PasswordForm test_form_;
DISALLOW_COPY_AND_ASSIGN(ManagePasswordsViewTest);
};
#endif // CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORDS_VIEW_TEST_H_
......@@ -128,10 +128,6 @@
'browser/ui/views/message_center/web_notification_tray_browsertest.cc',
'browser/ui/views/omnibox/omnibox_view_views_browsertest.cc',
'browser/ui/views/panels/panel_view_browsertest.cc',
'browser/ui/views/passwords/manage_passwords_view_test.cc',
'browser/ui/views/passwords/manage_passwords_view_test.h',
'browser/ui/views/passwords/manage_passwords_bubble_view_browsertest.cc',
'browser/ui/views/passwords/manage_passwords_icon_view_browsertest.cc',
'browser/ui/views/ssl_client_certificate_selector_browsertest.cc',
'browser/ui/views/status_icons/status_tray_state_changer_interactive_uitest_win.cc',
'browser/ui/views/tabs/tab_drag_controller_interactive_uitest.cc',
......
......@@ -203,8 +203,6 @@
'browser/ui/fullscreen/fullscreen_controller_state_tests.h',
'browser/ui/fullscreen/fullscreen_controller_test.cc',
'browser/ui/fullscreen/fullscreen_controller_test.h',
'browser/ui/passwords/manage_passwords_bubble_ui_controller_mock.cc',
'browser/ui/passwords/manage_passwords_bubble_ui_controller_mock.h',
'browser/ui/test/test_confirm_bubble_model.cc',
'browser/ui/test/test_confirm_bubble_model.h',
'browser/ui/views/find_bar_host_unittest_util_views.cc',
......@@ -1667,6 +1665,7 @@
'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',
......
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