diff options
author | machenbach@chromium.org <machenbach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-29 13:11:30 +0000 |
---|---|---|
committer | machenbach@chromium.org <machenbach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-29 13:11:30 +0000 |
commit | 99030190fefdd1ee983b3b14c746bba79cfcb5d1 (patch) | |
tree | baf5721a7e774b5a0cbaabbd1f68ce9e12e0f9b0 /chrome/browser/ui | |
parent | e666611c906a03b76d740f36dfdb7eda9836c55e (diff) | |
download | chromium_src-99030190fefdd1ee983b3b14c746bba79cfcb5d1.zip chromium_src-99030190fefdd1ee983b3b14c746bba79cfcb5d1.tar.gz chromium_src-99030190fefdd1ee983b3b14c746bba79cfcb5d1.tar.bz2 |
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
Diffstat (limited to 'chrome/browser/ui')
17 files changed, 64 insertions, 413 deletions
diff --git a/chrome/browser/ui/browser_command_controller.cc b/chrome/browser/ui/browser_command_controller.cc index 6c11ab5..9982ef7 100644 --- a/chrome/browser/ui/browser_command_controller.cc +++ b/chrome/browser/ui/browser_command_controller.cc @@ -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); diff --git a/chrome/browser/ui/browser_commands.cc b/chrome/browser/ui/browser_commands.cc index 2f47e0a..9d9a8e7 100644 --- a/chrome/browser/ui/browser_commands.cc +++ b/chrome/browser/ui/browser_commands.cc @@ -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( diff --git a/chrome/browser/ui/browser_commands.h b/chrome/browser/ui/browser_commands.h index de8bbe6..b060450 100644 --- a/chrome/browser/ui/browser_commands.h +++ b/chrome/browser/ui/browser_commands.h @@ -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); diff --git a/chrome/browser/ui/browser_dialogs.h b/chrome/browser/ui/browser_dialogs.h index 36cda64..cff9e76 100644 --- a/chrome/browser/ui/browser_dialogs.h +++ b/chrome/browser/ui/browser_dialogs.h @@ -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_ diff --git a/chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.cc b/chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.cc index 88c76e6..987077b 100644 --- a/chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.cc +++ b/chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.cc @@ -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; } diff --git a/chrome/browser/ui/passwords/manage_passwords_icon.cc b/chrome/browser/ui/passwords/manage_passwords_icon.cc index c9758b5..0914bba 100644 --- a/chrome/browser/ui/passwords/manage_passwords_icon.cc +++ b/chrome/browser/ui/passwords/manage_passwords_icon.cc @@ -14,5 +14,5 @@ void ManagePasswordsIcon::SetState(State state) { if (state_ == state) return; state_ = state; - UpdateVisibleUI(); + SetStateInternal(state); } diff --git a/chrome/browser/ui/passwords/manage_passwords_icon.h b/chrome/browser/ui/passwords/manage_passwords_icon.h index 004c8cd..0a44406 100644 --- a/chrome/browser/ui/passwords/manage_passwords_icon.h +++ b/chrome/browser/ui/passwords/manage_passwords_icon.h @@ -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_; diff --git a/chrome/browser/ui/passwords/manage_passwords_icon_mock.cc b/chrome/browser/ui/passwords/manage_passwords_icon_mock.cc index 4b575e8..64bdb16 100644 --- a/chrome/browser/ui/passwords/manage_passwords_icon_mock.cc +++ b/chrome/browser/ui/passwords/manage_passwords_icon_mock.cc @@ -14,5 +14,5 @@ void ManagePasswordsIconMock::ShowBubbleWithoutUserInteraction() { ++bubble_shown_count_; } -void ManagePasswordsIconMock::UpdateVisibleUI() { +void ManagePasswordsIconMock::SetStateInternal(ManagePasswordsIcon::State) { } diff --git a/chrome/browser/ui/passwords/manage_passwords_icon_mock.h b/chrome/browser/ui/passwords/manage_passwords_icon_mock.h index de4f814..3781e6a 100644 --- a/chrome/browser/ui/passwords/manage_passwords_icon_mock.h +++ b/chrome/browser/ui/passwords/manage_passwords_icon_mock.h @@ -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_; diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc index f59f4f4..7cf47bd 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -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()); diff --git a/chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc b/chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc index 688e0e9..0c3f0e0 100644 --- a/chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc +++ b/chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc @@ -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 diff --git a/chrome/browser/ui/views/passwords/manage_passwords_bubble_view_browsertest.cc b/chrome/browser/ui/views/passwords/manage_passwords_bubble_view_browsertest.cc deleted file mode 100644 index 788752b..0000000 --- a/chrome/browser/ui/views/passwords/manage_passwords_bubble_view_browsertest.cc +++ /dev/null @@ -1,128 +0,0 @@ -// 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)); -} diff --git a/chrome/browser/ui/views/passwords/manage_passwords_icon_view.cc b/chrome/browser/ui/views/passwords/manage_passwords_icon_view.cc index 73368045..23a5950 100644 --- a/chrome/browser/ui/views/passwords/manage_passwords_icon_view.cc +++ b/chrome/browser/ui/views/passwords/manage_passwords_icon_view.cc @@ -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); + } } diff --git a/chrome/browser/ui/views/passwords/manage_passwords_icon_view.h b/chrome/browser/ui/views/passwords/manage_passwords_icon_view.h index efcef5f..7dd791c 100644 --- a/chrome/browser/ui/views/passwords/manage_passwords_icon_view.h +++ b/chrome/browser/ui/views/passwords/manage_passwords_icon_view.h @@ -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); }; diff --git a/chrome/browser/ui/views/passwords/manage_passwords_icon_view_browsertest.cc b/chrome/browser/ui/views/passwords/manage_passwords_icon_view_browsertest.cc deleted file mode 100644 index e3c8ca6..0000000 --- a/chrome/browser/ui/views/passwords/manage_passwords_icon_view_browsertest.cc +++ /dev/null @@ -1,45 +0,0 @@ -// 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()); -} diff --git a/chrome/browser/ui/views/passwords/manage_passwords_view_test.cc b/chrome/browser/ui/views/passwords/manage_passwords_view_test.cc deleted file mode 100644 index c88ed22..0000000 --- a/chrome/browser/ui/views/passwords/manage_passwords_view_test.cc +++ /dev/null @@ -1,73 +0,0 @@ -// 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()); -} diff --git a/chrome/browser/ui/views/passwords/manage_passwords_view_test.h b/chrome/browser/ui/views/passwords/manage_passwords_view_test.h deleted file mode 100644 index 1402f13..0000000 --- a/chrome/browser/ui/views/passwords/manage_passwords_view_test.h +++ /dev/null @@ -1,51 +0,0 @@ -// 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_ |