Commit 895539fa authored by dconnelly's avatar dconnelly Committed by Commit bot

Hook up the Mac password bubble to the browser and add browser tests.

BUG=328847

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

Cr-Commit-Position: refs/heads/master@{#291703}
parent e8d91bdd
......@@ -404,9 +404,6 @@ bool ChromePasswordManagerClient::LastLoadWasTransactionalReauthPage() const {
}
bool ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled() {
#if !defined(USE_AURA)
return false;
#endif
CommandLine* command_line = CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kDisableSavePasswordBubble))
return false;
......
......@@ -797,15 +797,12 @@ void Translate(Browser* browser) {
}
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) {
......
......@@ -114,12 +114,8 @@ 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
......
......@@ -166,6 +166,9 @@ class LocationBarViewMac : public LocationBar,
AutocompleteTextField* GetAutocompleteTextField() { return field_; }
ManagePasswordsDecoration* manage_passwords_decoration() {
return manage_passwords_decoration_.get();
}
// content::NotificationObserver:
virtual void Observe(int type,
......
......@@ -133,7 +133,7 @@ LocationBarViewMac::LocationBarViewMac(AutocompleteTextField* field,
new GeneratedCreditCardDecoration(this)),
search_button_decoration_(new SearchButtonDecoration(this)),
manage_passwords_decoration_(
new ManagePasswordsDecoration(command_updater)),
new ManagePasswordsDecoration(command_updater, this)),
browser_(browser),
weak_ptr_factory_(this) {
for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
......@@ -222,6 +222,7 @@ void LocationBarViewMac::UpdateManagePasswordsIconAndBubble() {
return;
ManagePasswordsUIController::FromWebContents(web_contents)
->UpdateIconAndBubbleState(manage_passwords_decoration_->icon());
OnDecorationsChanged();
}
void LocationBarViewMac::UpdatePageActions() {
......@@ -526,6 +527,7 @@ NSPoint LocationBarViewMac::GetPageActionBubblePoint(
}
void LocationBarViewMac::Update(const WebContents* contents) {
UpdateManagePasswordsIconAndBubble();
UpdateStarDecorationVisibility();
UpdateTranslateDecoration();
UpdateZoomDecoration();
......
......@@ -13,6 +13,7 @@
#include "chrome/browser/ui/passwords/manage_passwords_icon.h"
class CommandUpdater;
class LocationBarViewMac;
class ManagePasswordsDecoration;
// Cocoa implementation of ManagePasswordsIcon that delegates to
......@@ -34,7 +35,8 @@ class ManagePasswordsIconCocoa : public ManagePasswordsIcon {
// password management is available on the current page.
class ManagePasswordsDecoration : public ImageDecoration {
public:
explicit ManagePasswordsDecoration(CommandUpdater* command_updater);
explicit ManagePasswordsDecoration(CommandUpdater* command_updater,
LocationBarViewMac* location_bar);
virtual ~ManagePasswordsDecoration();
// Implement |LocationBarDecoration|
......@@ -50,9 +52,18 @@ class ManagePasswordsDecoration : public ImageDecoration {
ManagePasswordsIconCocoa* icon() { return icon_.get(); }
private:
// Triggers a redraw after a state change.
void OnChange();
// Updates child view states.
void UpdateUIState();
// Shows the manage passwords bubble.
CommandUpdater* command_updater_; // Weak, owned by Browser.
// Displays all the decorations.
LocationBarViewMac* location_bar_; // Weak, owns us.
// The platform-independent interface.
scoped_ptr<ManagePasswordsIconCocoa> icon_;
......
......@@ -8,6 +8,7 @@
#include "chrome/browser/command_updater.h"
#include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
#include "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_cocoa.h"
#include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
#include "ui/base/l10n/l10n_util_mac.h"
// ManagePasswordsIconCocoa
......@@ -27,10 +28,12 @@ void ManagePasswordsIconCocoa::UpdateVisibleUI() {
// ManagePasswordsDecoration
ManagePasswordsDecoration::ManagePasswordsDecoration(
CommandUpdater* command_updater)
CommandUpdater* command_updater,
LocationBarViewMac* location_bar)
: command_updater_(command_updater),
location_bar_(location_bar),
icon_(new ManagePasswordsIconCocoa(this)) {
UpdateVisibleUI();
UpdateUIState();
}
ManagePasswordsDecoration::~ManagePasswordsDecoration() {}
......@@ -45,8 +48,12 @@ bool ManagePasswordsDecoration::AcceptsMousePress() {
}
bool ManagePasswordsDecoration::OnMousePressed(NSRect frame, NSPoint location) {
command_updater_->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE);
return true;
bool result = ImageDecoration::OnMousePressed(frame, location);
if (ManagePasswordsBubbleCocoa::instance())
ManagePasswordsBubbleCocoa::instance()->Close();
else
command_updater_->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE);
return result;
}
NSString* ManagePasswordsDecoration::GetToolTip() {
......@@ -55,7 +62,13 @@ NSString* ManagePasswordsDecoration::GetToolTip() {
: nil;
}
void ManagePasswordsDecoration::UpdateVisibleUI() {
void ManagePasswordsDecoration::OnChange() {
// |location_bar_| can be NULL in tests.
if (location_bar_)
location_bar_->OnDecorationsChanged();
}
void ManagePasswordsDecoration::UpdateUIState() {
if (icon_->state() == password_manager::ui::INACTIVE_STATE) {
SetVisible(false);
SetImage(nil);
......@@ -66,3 +79,8 @@ void ManagePasswordsDecoration::UpdateVisibleUI() {
SetVisible(true);
SetImage(OmniboxViewMac::ImageForResource(icon_->icon_id()));
}
void ManagePasswordsDecoration::UpdateVisibleUI() {
UpdateUIState();
OnChange();
}
......@@ -53,7 +53,8 @@ bool ImagesEqual(NSImage* left, NSImage* right) {
class ManagePasswordsDecorationTest : public CocoaTest {
public:
ManagePasswordsDecorationTest()
: commandUpdater_(&commandDelegate_), decoration_(&commandUpdater_) {
: commandUpdater_(&commandDelegate_),
decoration_(&commandUpdater_, NULL) {
commandUpdater_.UpdateCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE, true);
}
......@@ -69,7 +70,7 @@ class ManagePasswordsDecorationTest : public CocoaTest {
TEST_F(ManagePasswordsDecorationTest, ExecutesManagePasswordsCommandOnClick) {
EXPECT_TRUE(decoration()->AcceptsMousePress());
EXPECT_TRUE(decoration()->OnMousePressed(NSRect(), NSPoint()));
EXPECT_FALSE(decoration()->OnMousePressed(NSRect(), NSPoint()));
EXPECT_EQ(IDC_MANAGE_PASSWORDS_FOR_PAGE, commandDelegate()->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 "base/mac/foundation_util.h"
#include "base/mac/scoped_objc_class_swizzler.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#import "chrome/browser/ui/cocoa/info_bubble_window.h"
#include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
#include "chrome/browser/ui/cocoa/location_bar/manage_passwords_decoration.h"
#include "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_cocoa.h"
#include "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_controller.h"
#include "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_pending_view_controller.h"
#include "chrome/browser/ui/passwords/manage_passwords_test.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "content/public/test/test_utils.h"
#include "testing/gtest_mac.h"
// A helper class to swizzle [NSWindow isKeyWindow] to always return true.
@interface AlwaysKeyNSWindow : NSWindow
- (BOOL)isKeyWindow;
@end
@implementation AlwaysKeyNSWindow
- (BOOL)isKeyWindow {
return YES;
}
@end
// Integration tests for the Mac password bubble.
class ManagePasswordsBubbleTest : public ManagePasswordsTest {
public:
virtual void SetUpOnMainThread() OVERRIDE {
ManagePasswordsTest::SetUpOnMainThread();
browser()->window()->Show();
}
virtual void TearDownOnMainThread() OVERRIDE {
ManagePasswordsTest::TearDownOnMainThread();
}
ManagePasswordsBubbleController* controller() {
return ManagePasswordsBubbleCocoa::instance()
? ManagePasswordsBubbleCocoa::instance()->controller_
: nil;
}
void DoWithSwizzledNSWindow(void (^block)(void)) {
// Swizzle [NSWindow isKeyWindow] so that BrowserWindow::IsActive will
// return true and the bubble can be displayed.
base::mac::ScopedObjCClassSwizzler swizzler(
[NSWindow class], [AlwaysKeyNSWindow class], @selector(isKeyWindow));
block();
}
void DisableAnimationsOnController() {
InfoBubbleWindow* window =
base::mac::ObjCCast<InfoBubbleWindow>([controller() window]);
[window setAllowedAnimations:info_bubble::kAnimateNone];
}
ManagePasswordsDecoration* decoration() {
NSWindow* window = browser()->window()->GetNativeWindow();
BrowserWindowController* bwc =
[BrowserWindowController browserWindowControllerForWindow:window];
return [bwc locationBarBridge]->manage_passwords_decoration();
}
virtual ManagePasswordsIcon* view() OVERRIDE {
return decoration()->icon();
}
};
IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleTest,
PasswordEntryShowsPendingSaveView) {
EXPECT_FALSE(ManagePasswordsBubbleCocoa::instance());
DoWithSwizzledNSWindow(^{ SetupPendingPassword(); });
EXPECT_TRUE(ManagePasswordsBubbleCocoa::instance());
EXPECT_EQ([ManagePasswordsBubblePendingViewController class],
[controller().currentController class]);
EXPECT_TRUE(view()->active());
}
IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleTest, IconClickTogglesBubble) {
// Show the bubble automatically.
DoWithSwizzledNSWindow(^{ SetupPendingPassword(); });
// Close the bubble by clicking on the decoration.
DisableAnimationsOnController();
decoration()->OnMousePressed(NSZeroRect, NSZeroPoint);
EXPECT_FALSE(ManagePasswordsBubbleCocoa::instance());
// Show the bubble by clicking on the decoration.
DoWithSwizzledNSWindow(^{
decoration()->OnMousePressed(NSZeroRect, NSZeroPoint);
});
EXPECT_TRUE(ManagePasswordsBubbleCocoa::instance());
}
IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleTest, TabChangeTogglesIcon) {
// Show the bubble (and icon) automatically.
DoWithSwizzledNSWindow(^{ SetupPendingPassword(); });
EXPECT_TRUE(decoration()->IsVisible());
// Open a new tab.
int firstTab = browser()->tab_strip_model()->active_index();
AddTabAtIndex(
firstTab + 1, GURL("http://foo.bar/"), content::PAGE_TRANSITION_TYPED);
EXPECT_FALSE(decoration()->IsVisible());
// Switch back to the previous tab.
browser()->tab_strip_model()->ActivateTabAt(firstTab, true);
EXPECT_TRUE(decoration()->IsVisible());
}
......@@ -14,8 +14,13 @@ namespace content {
class WebContents;
}
namespace chrome {
void ShowManagePasswordsBubble(content::WebContents* webContents);
}
@class ManagePasswordsBubbleController;
@class ManagePasswordsBubbleCocoaNotificationBridge;
class ManagePasswordsIcon;
// Cocoa implementation of the platform-independent password bubble interface.
class ManagePasswordsBubbleCocoa : public ManagePasswordsBubble {
......@@ -23,7 +28,8 @@ class ManagePasswordsBubbleCocoa : public ManagePasswordsBubble {
// Creates and shows the bubble, which owns itself. Does nothing if the bubble
// is already shown.
static void ShowBubble(content::WebContents* webContents,
DisplayReason displayReason);
DisplayReason displayReason,
ManagePasswordsIcon* icon);
// Closes and deletes the bubble.
void Close();
......@@ -33,16 +39,23 @@ class ManagePasswordsBubbleCocoa : public ManagePasswordsBubble {
private:
friend class ManagePasswordsBubbleCocoaTest;
friend class ManagePasswordsBubbleTest;
friend void chrome::ShowManagePasswordsBubble(
content::WebContents* webContents);
// Instance-specific logic. Clients should use the static interface.
ManagePasswordsBubbleCocoa(content::WebContents* webContents,
DisplayReason displayReason);
DisplayReason displayReason,
ManagePasswordsIcon* icon);
virtual ~ManagePasswordsBubbleCocoa();
void Show();
// Cleans up state and deletes itself. Called when the bubble is closed.
void OnClose();
// The location bar icon corresponding to the bubble.
ManagePasswordsIcon* icon_;
// Whether there is currently a close operation taking place. Prevents
// multiple attempts to close the window.
bool closing_;
......
......@@ -7,7 +7,11 @@
#include "base/mac/scoped_block.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_finder.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
#include "chrome/browser/ui/cocoa/location_bar/manage_passwords_decoration.h"
#import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_controller.h"
#include "chrome/browser/ui/passwords/manage_passwords_icon.h"
#include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
#include "content/public/browser/web_contents.h"
......@@ -35,20 +39,47 @@ typedef void (^Callback)(void);
// static
ManagePasswordsBubbleCocoa* ManagePasswordsBubbleCocoa::bubble_ = NULL;
namespace chrome {
void ShowManagePasswordsBubble(content::WebContents* webContents) {
ManagePasswordsBubbleCocoa* instance = ManagePasswordsBubbleCocoa::instance();
if (instance && (instance->webContents_ != webContents)) {
// The bubble is currently shown for some other tab. We should close it now
// and open for |webContents|.
instance->Close();
}
ManagePasswordsUIController* controller =
ManagePasswordsUIController::FromWebContents(webContents);
NSWindow* window = webContents->GetTopLevelNativeWindow();
BrowserWindowController* bwc =
[BrowserWindowController browserWindowControllerForWindow:window];
ManagePasswordsBubbleCocoa::ShowBubble(
webContents,
password_manager::ui::IsAutomaticDisplayState(controller->state())
? ManagePasswordsBubble::AUTOMATIC
: ManagePasswordsBubble::USER_ACTION,
[bwc locationBarBridge]->manage_passwords_decoration()->icon());
}
} // namespace chrome
ManagePasswordsBubbleCocoa::ManagePasswordsBubbleCocoa(
content::WebContents* webContents,
DisplayReason displayReason)
DisplayReason displayReason,
ManagePasswordsIcon* icon)
: ManagePasswordsBubble(webContents, displayReason),
icon_(icon),
closing_(false),
controller_(nil),
webContents_(webContents),
bridge_(nil) {
icon_->SetActive(true);
}
ManagePasswordsBubbleCocoa::~ManagePasswordsBubbleCocoa() {
[[NSNotificationCenter defaultCenter] removeObserver:bridge_];
// Clear the global instance pointer.
bubble_ = NULL;
icon_->SetActive(false);
}
void ManagePasswordsBubbleCocoa::Show() {
......@@ -90,9 +121,10 @@ void ManagePasswordsBubbleCocoa::OnClose() {
// static
void ManagePasswordsBubbleCocoa::ShowBubble(content::WebContents* webContents,
DisplayReason displayReason) {
DisplayReason displayReason,
ManagePasswordsIcon* icon) {
if (bubble_)
return;
bubble_ = new ManagePasswordsBubbleCocoa(webContents, displayReason);
bubble_ = new ManagePasswordsBubbleCocoa(webContents, displayReason, icon);
bubble_->Show();
}
......@@ -9,9 +9,13 @@
#include "base/compiler_specific.h"
#include "base/mac/foundation_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
#include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
#import "chrome/browser/ui/cocoa/info_bubble_window.h"
#include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
#include "chrome/browser/ui/cocoa/location_bar/manage_passwords_decoration.h"
#import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_controller.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble.h"
#include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h"
......@@ -43,12 +47,18 @@ class ManagePasswordsBubbleCocoaTest : public CocoaProfileTest {
content::WebContents* webContents() { return webContents_; }
void ShowBubble() {
NSWindow* nativeWindow = browser()->window()->GetNativeWindow();
BrowserWindowController* bwc =
[BrowserWindowController browserWindowControllerForWindow:nativeWindow];
ManagePasswordsIcon* icon =
[bwc locationBarBridge]->manage_passwords_decoration()->icon();
ManagePasswordsBubbleCocoa::ShowBubble(
webContents(), ManagePasswordsBubble::DisplayReason::AUTOMATIC);
webContents(), ManagePasswordsBubble::DisplayReason::AUTOMATIC, icon);
// Disable animations so that closing happens immediately.
InfoBubbleWindow* window = base::mac::ObjCCast<InfoBubbleWindow>(
InfoBubbleWindow* bubbleWindow = base::mac::ObjCCast<InfoBubbleWindow>(
[ManagePasswordsBubbleCocoa::instance()->controller_ window]);
[window setAllowedAnimations:info_bubble::kAnimateNone];
[bubbleWindow setAllowedAnimations:info_bubble::kAnimateNone];
}
void CloseBubble() {
......
......@@ -2,18 +2,16 @@
// 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/browser/ui/passwords/manage_passwords_test.h"
#include "base/strings/utf_string_conversions.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/browser_window.h"
#include "chrome/browser/ui/passwords/manage_passwords_icon.h"
#include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.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"
......@@ -23,7 +21,7 @@
#include "components/password_manager/core/browser/stub_password_manager_driver.h"
#include "testing/gtest/include/gtest/gtest.h"
void ManagePasswordsViewTest::SetUpOnMainThread() {
void ManagePasswordsTest::SetUpOnMainThread() {
AddTabAtIndex(0, GURL("http://example.com/"), content::PAGE_TRANSITION_TYPED);
// Create the test UIController here so that it's bound to the currently
// active WebContents.
......@@ -31,19 +29,13 @@ void ManagePasswordsViewTest::SetUpOnMainThread() {
browser()->tab_strip_model()->GetActiveWebContents());
}
ManagePasswordsUIControllerMock* ManagePasswordsViewTest::controller() {
ManagePasswordsUIControllerMock* ManagePasswordsTest::controller() {
return static_cast<ManagePasswordsUIControllerMock*>(
ManagePasswordsUIController::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() {
void ManagePasswordsTest::ExecuteManagePasswordsCommand() {
// Show the window to ensure that it's active.
browser()->window()->Show();
......@@ -55,7 +47,7 @@ void ManagePasswordsViewTest::ExecuteManagePasswordsCommand() {
content::RunAllPendingInMessageLoop();
}
void ManagePasswordsViewTest::SetupManagingPasswords() {
void ManagePasswordsTest::SetupManagingPasswords() {
base::string16 kTestUsername = base::ASCIIToUTF16("test_username");
autofill::PasswordFormMap map;
map[kTestUsername] = test_form();
......@@ -63,7 +55,7 @@ void ManagePasswordsViewTest::SetupManagingPasswords() {
controller()->UpdateIconAndBubbleState(view());
}
void ManagePasswordsViewTest::SetupPendingPassword() {
void ManagePasswordsTest::SetupPendingPassword() {
password_manager::StubPasswordManagerClient client;
password_manager::StubPasswordManagerDriver driver;
scoped_ptr<password_manager::PasswordFormManager> test_form_manager(
......@@ -77,7 +69,7 @@ void ManagePasswordsViewTest::SetupPendingPassword() {
controller()->UpdateIconAndBubbleState(view());
}
void ManagePasswordsViewTest::SetupAutomaticPassword() {
void ManagePasswordsTest::SetupAutomaticPassword() {
password_manager::StubPasswordManagerClient client;
password_manager::StubPasswordManagerDriver driver;
scoped_ptr<password_manager::PasswordFormManager> test_form_manager(
......@@ -91,7 +83,7 @@ void ManagePasswordsViewTest::SetupAutomaticPassword() {
controller()->UpdateIconAndBubbleState(view());
}
void ManagePasswordsViewTest::SetupBlackistedPassword() {
void ManagePasswordsTest::SetupBlackistedPassword() {
base::string16 kTestUsername = base::ASCIIToUTF16("test_username");
autofill::PasswordFormMap map;
map[kTestUsername] = test_form();
......@@ -99,7 +91,7 @@ void ManagePasswordsViewTest::SetupBlackistedPassword() {
controller()->UpdateIconAndBubbleState(view());
}
base::HistogramSamples* ManagePasswordsViewTest::GetSamples(
base::HistogramSamples* ManagePasswordsTest::GetSamples(
const char* histogram) {
// Ensure that everything has been properly recorded before pulling samples.
content::RunAllPendingInMessageLoop();
......
......@@ -2,8 +2,8 @@
// 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_
#ifndef CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_TEST_H_
#define CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_TEST_H_
#include "base/metrics/histogram_samples.h"
#include "base/test/histogram_tester.h"
......@@ -12,14 +12,14 @@
#include "testing/gtest/include/gtest/gtest.h"
class ManagePasswordsUIControllerMock;
class ManagePasswordsIconView;
class ManagePasswordsIcon;
// Test class for the various password management view bits and pieces. Sets
// up a ManagePasswordsUIControllerMock, and provides some helper methods
// to poke at the bubble, icon, and controller's state.
class ManagePasswordsViewTest : public InProcessBrowserTest {
class ManagePasswordsTest : public InProcessBrowserTest {
public:
ManagePasswordsViewTest() {}
ManagePasswordsTest() {}
// InProcessBrowserTest:
virtual void SetUpOnMainThread() OVERRIDE;
......@@ -28,7 +28,7 @@ class ManagePasswordsViewTest : public InProcessBrowserTest {
ManagePasswordsUIControllerMock* controller();
// Get the icon view for the current WebContents.
ManagePasswordsIconView* view();
virtual ManagePasswordsIcon* view() = 0;
// Execute the browser command to open the manage passwords bubble.
void ExecuteManagePasswordsCommand();
......@@ -54,7 +54,7 @@ class ManagePasswordsViewTest : public InProcessBrowserTest {
autofill::PasswordForm test_form_;
base::HistogramTester histogram_tester_;
DISALLOW_COPY_AND_ASSIGN(ManagePasswordsViewTest);
DISALLOW_COPY_AND_ASSIGN(ManagePasswordsTest);
};
#endif // CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORDS_VIEW_TEST_H_
#endif // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_TEST_H_
......@@ -6,8 +6,12 @@
#include "base/metrics/histogram_samples.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/passwords/manage_passwords_test.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/views/passwords/manage_passwords_view_test.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 "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"
......@@ -18,9 +22,24 @@ const char kDisplayDispositionMetric[] = "PasswordBubble.DisplayDisposition";
} // namespace
typedef ManagePasswordsViewTest ManagePasswordsBubbleViewTest;
namespace metrics_util = password_manager::metrics_util;
class ManagePasswordsBubbleViewTest : public ManagePasswordsTest {
public:
ManagePasswordsBubbleViewTest() {}
virtual ~ManagePasswordsBubbleViewTest() {}
virtual ManagePasswordsIcon* view() OVERRIDE {
BrowserView* browser_view = static_cast<BrowserView*>(browser()->window());
return browser_view->GetToolbarView()
->location_bar()
->manage_passwords_icon_view();
}
private:
DISALLOW_COPY_AND_ASSIGN(ManagePasswordsBubbleViewTest);
};
IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, BasicOpenAndClose) {
EXPECT_FALSE(ManagePasswordsBubbleView::IsShowing());
ManagePasswordsBubbleView::ShowBubble(
......
......@@ -4,16 +4,35 @@
#include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/passwords/manage_passwords_icon.h"
#include "chrome/browser/ui/passwords/manage_passwords_test.h"
#include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h"
#include "chrome/browser/ui/views/passwords/manage_passwords_view_test.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "components/password_manager/core/common/password_manager_ui.h"
#include "content/public/test/test_utils.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "testing/gtest/include/gtest/gtest.h"
typedef ManagePasswordsViewTest ManagePasswordsIconViewTest;
class ManagePasswordsIconViewTest : public ManagePasswordsTest {
public:
ManagePasswordsIconViewTest() {}
virtual ~ManagePasswordsIconViewTest() {}
virtual ManagePasswordsIconView* view() OVERRIDE {
BrowserView* browser_view = static_cast<BrowserView*>(browser()->window());
return static_cast<ManagePasswordsIconView*>(
browser_view->GetToolbarView()
->location_bar()
->manage_passwords_icon_view());
}
private:
DISALLOW_COPY_AND_ASSIGN(ManagePasswordsIconViewTest);
};
IN_PROC_BROWSER_TEST_F(ManagePasswordsIconViewTest, DefaultStateIsInactive) {
EXPECT_EQ(password_manager::ui::INACTIVE_STATE, view()->state());
......
......@@ -111,6 +111,8 @@
'browser/ui/panels/test_panel_notification_observer.h',
'browser/ui/panels/test_panel_collection_squeeze_observer.cc',
'browser/ui/panels/test_panel_collection_squeeze_observer.h',
'browser/ui/passwords/manage_passwords_test.cc',
'browser/ui/passwords/manage_passwords_test.h',
'browser/ui/search/instant_extended_interactive_uitest.cc',
'browser/ui/pdf/pdf_interactive_browsertest.cc',
'browser/ui/search/instant_extended_manual_interactive_uitest.cc',
......@@ -138,8 +140,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',
......@@ -1450,6 +1450,7 @@
'browser/ui/cocoa/omnibox/omnibox_view_mac_browsertest.mm',
'browser/ui/cocoa/one_click_signin_bubble_controller_browsertest.mm',
'browser/ui/cocoa/one_click_signin_dialog_controller_browsertest.mm',
'browser/ui/cocoa/passwords/manage_passwords_bubble_browsertest.mm',
'browser/ui/cocoa/profiles/profile_signin_confirmation_view_controller_browsertest.mm',
'browser/ui/cocoa/ssl_client_certificate_selector_cocoa_browsertest.mm',
'browser/ui/cocoa/view_id_util_browsertest.mm',
......@@ -1459,6 +1460,7 @@
'browser/ui/global_error/global_error_service_browsertest.cc',
'browser/ui/login/login_prompt_browsertest.cc',
'browser/ui/panels/panel_extension_browsertest.cc',
'browser/ui/passwords/manage_passwords_test.cc',
'browser/ui/pdf/pdf_browsertest.cc',
'browser/ui/prefs/prefs_tab_helper_browsertest.cc',
'browser/ui/settings_window_manager_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