Commit a0741928 authored by dconnelly's avatar dconnelly Committed by Commit bot

Add ManagePasswordsBubbleNeverSaveViewController and unit tests.

BUG=328847

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

Cr-Commit-Position: refs/heads/master@{#291902}
parent 6531de85
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/mac/scoped_nsobject.h" #include "base/mac/scoped_nsobject.h"
#import "chrome/browser/ui/cocoa/base_bubble_controller.h" #import "chrome/browser/ui/cocoa/base_bubble_controller.h"
#import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_content_view_controller.h" #import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_content_view_controller.h"
#import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_never_save_view_controller.h"
#import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_pending_view_controller.h" #import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_pending_view_controller.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
...@@ -18,6 +19,7 @@ ...@@ -18,6 +19,7 @@
// accordingly. // accordingly.
@interface ManagePasswordsBubbleController @interface ManagePasswordsBubbleController
: BaseBubbleController<ManagePasswordsBubbleContentViewDelegate, : BaseBubbleController<ManagePasswordsBubbleContentViewDelegate,
ManagePasswordsBubbleNeverSaveViewDelegate,
ManagePasswordsBubblePendingViewDelegate> { ManagePasswordsBubblePendingViewDelegate> {
@private @private
ManagePasswordsBubbleModel* model_; ManagePasswordsBubbleModel* model_;
......
...@@ -101,10 +101,18 @@ ...@@ -101,10 +101,18 @@
#pragma mark ManagePasswordsBubblePendingViewDelegate #pragma mark ManagePasswordsBubblePendingViewDelegate
- (void)passwordShouldNeverBeSavedOnSiteWithExistingPasswords { - (void)passwordShouldNeverBeSavedOnSiteWithExistingPasswords {
// TODO(dconnelly): Set the NeverSaveViewController once it's implemented. currentController_.reset([[ManagePasswordsBubbleNeverSaveViewController alloc]
initWithModel:model_
delegate:self]);
[self performLayout]; [self performLayout];
} }
#pragma mark ManagePasswordsBubbleNeverSaveViewDelegate
- (void)neverSavePasswordCancelled {
[self updateState];
}
@end @end
@implementation ManagePasswordsBubbleController (Testing) @implementation ManagePasswordsBubbleController (Testing)
......
...@@ -70,4 +70,23 @@ TEST_F(ManagePasswordsBubbleControllerTest, ManageStateShouldHaveManageView) { ...@@ -70,4 +70,23 @@ TEST_F(ManagePasswordsBubbleControllerTest, ManageStateShouldHaveManageView) {
[[controller() currentController] class]); [[controller() currentController] class]);
} }
TEST_F(ManagePasswordsBubbleControllerTest,
ChoosingNeverSaveShouldHaveNeverSaveView) {
EXPECT_NE([ManagePasswordsBubbleNeverSaveViewController class],
[[controller() currentController] class]);
[controller() passwordShouldNeverBeSavedOnSiteWithExistingPasswords];
EXPECT_EQ([ManagePasswordsBubbleNeverSaveViewController class],
[[controller() currentController] class]);
}
TEST_F(ManagePasswordsBubbleControllerTest,
CancellingNeverSaveShouldHavePendingView) {
[controller() passwordShouldNeverBeSavedOnSiteWithExistingPasswords];
EXPECT_NE([ManagePasswordsBubblePendingViewController class],
[[controller() currentController] class]);
[controller() neverSavePasswordCancelled];
EXPECT_EQ([ManagePasswordsBubblePendingViewController class],
[[controller() currentController] class]);
}
} // namespace } // namespace
// 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_COCOA_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_NEVER_SAVE_VIEW_CONTROLLER_H_
#define CHROME_BROWSER_UI_COCOA_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_NEVER_SAVE_VIEW_CONTROLLER_H_
#import <Cocoa/Cocoa.h>
#include "base/mac/scoped_nsobject.h"
#import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_content_view_controller.h"
class ManagePasswordsBubbleModel;
// Handles user interaction with the password never save confirmation bubble.
@protocol ManagePasswordsBubbleNeverSaveViewDelegate<
ManagePasswordsBubbleContentViewDelegate>
// The user chose not to never save passwords on this site.
- (void)neverSavePasswordCancelled;
@end
// Manages the view that confirms that the user never wants to save passwords
// on this site.
@interface ManagePasswordsBubbleNeverSaveViewController
: ManagePasswordsBubbleContentViewController {
@private
ManagePasswordsBubbleModel* model_; // weak
id<ManagePasswordsBubbleNeverSaveViewDelegate> delegate_; // weak
base::scoped_nsobject<NSButton> confirmButton_;
base::scoped_nsobject<NSButton> undoButton_;
}
- (id)initWithModel:(ManagePasswordsBubbleModel*)model
delegate:(id<ManagePasswordsBubbleNeverSaveViewDelegate>)delegate;
@end
@interface ManagePasswordsBubbleNeverSaveViewController (Testing)
@property(readonly) NSButton* confirmButton;
@property(readonly) NSButton* undoButton;
@end
#endif // CHROME_BROWSER_UI_COCOA_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_NEVER_SAVE_VIEW_CONTROLLER_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.
#import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_never_save_view_controller.h"
#include "base/strings/sys_string_conversions.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
#include "grit/generated_resources.h"
#import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTweaker.h"
#include "ui/base/l10n/l10n_util.h"
using namespace password_manager::mac::ui;
@interface ManagePasswordsBubbleNeverSaveViewController ()
- (void)onConfirmClicked:(id)sender;
- (void)onUndoClicked:(id)sender;
@end
@implementation ManagePasswordsBubbleNeverSaveViewController
- (id)initWithModel:(ManagePasswordsBubbleModel*)model
delegate:(id<ManagePasswordsBubbleNeverSaveViewDelegate>)delegate {
if ((self = [super initWithNibName:nil bundle:nil])) {
model_ = model;
delegate_ = delegate;
}
return self;
}
- (void)onConfirmClicked:(id)sender {
model_->OnNeverForThisSiteClicked();
[delegate_ viewShouldDismiss];
}
- (void)onUndoClicked:(id)sender {
[delegate_ neverSavePasswordCancelled];
}
- (void)loadView {
self.view = [[[NSView alloc] initWithFrame:NSZeroRect] autorelease];
// -----------------------------------
// | Title |
// | |
// | Confirmation! |
// | |
// | [Undo] [Confirm] |
// -----------------------------------
// Create the elements and add them to the view.
// Title.
NSTextField* titleLabel = [self
addTitleLabel:l10n_util::GetNSString(
IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_TITLE)];
// Blacklist confirmation.
NSTextField* confirmationLabel = [self
addLabel:l10n_util::GetNSString(
IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_TEXT)];
// Undo button.
undoButton_.reset([[self addButton:l10n_util::GetNSString(IDS_CANCEL)
target:self
action:@selector(onUndoClicked:)] retain]);
// Confirm button.
confirmButton_.reset(
[[self addButton:l10n_util::GetNSString(
IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_BUTTON)
target:self
action:@selector(onConfirmClicked:)] retain]);
// Compute the bubble width using the title and confirmation labels.
// The explanation label can wrap to multiple lines.
const CGFloat minContentWidth = kDesiredBubbleWidth - 2 * kFramePadding;
const CGFloat contentWidth =
std::max(NSWidth([titleLabel frame]), minContentWidth);
NSSize confirmationSize = [confirmationLabel frame].size;
confirmationSize.width = contentWidth;
[confirmationLabel setFrameSize:confirmationSize];
[GTMUILocalizerAndLayoutTweaker
sizeToFitFixedWidthTextField:confirmationLabel];
const CGFloat width = kFramePadding + contentWidth + kFramePadding;
// Layout the elements, starting at the bottom and moving up.
// Buttons go on the bottom row and are right-aligned.
// Start with [Confirm].
CGFloat curX = width - kFramePadding - NSWidth([confirmButton_ frame]);
CGFloat curY = kFramePadding;
[confirmButton_ setFrameOrigin:NSMakePoint(curX, curY)];
// [Undo] goes to the left of [Confirm].
curX = NSMinX([confirmButton_ frame]) -
kRelatedControlHorizontalPadding -
NSWidth([undoButton_ frame]);
[undoButton_ setFrameOrigin:NSMakePoint(curX, curY)];
// Confirmation label goes on the next row and is shifted right.
curX = kFramePadding;
curY = NSMaxY([undoButton_ frame]) + kUnrelatedControlVerticalPadding;
[confirmationLabel setFrameOrigin:NSMakePoint(curX, curY)];
// Title goes at the top after some padding.
curY = NSMaxY([confirmationLabel frame]) + kUnrelatedControlVerticalPadding;
[titleLabel setFrameOrigin:NSMakePoint(curX, curY)];
// Update the bubble size.
const CGFloat height = NSMaxY([titleLabel frame]) + kFramePadding;
[self.view setFrame:NSMakeRect(0, 0, width, height)];
}
@end
@implementation ManagePasswordsBubbleNeverSaveViewController (Testing)
- (NSButton*)undoButton {
return undoButton_.get();
}
- (NSButton*)confirmButton {
return confirmButton_.get();
}
@end
// 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.
#import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_never_save_view_controller.h"
#include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
#import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_never_save_view_controller.h"
#include "chrome/browser/ui/cocoa/passwords/manage_passwords_controller_test.h"
#include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h"
#include "components/password_manager/core/common/password_manager_ui.h"
// Helper delegate for testing the never save view of the password management
// bubble.
@interface ManagePasswordsBubbleNeverSaveViewTestDelegate
: NSObject<ManagePasswordsBubbleNeverSaveViewDelegate> {
BOOL dismissed_;
BOOL cancelledNeverSave_;
}
@property(readonly) BOOL dismissed;
@property(readonly) BOOL cancelledNeverSave;
@end
@implementation ManagePasswordsBubbleNeverSaveViewTestDelegate
@synthesize dismissed = dismissed_;
@synthesize cancelledNeverSave = cancelledNeverSave_;
- (void)viewShouldDismiss {
dismissed_ = YES;
}
- (void)neverSavePasswordCancelled {
cancelledNeverSave_ = YES;
}
@end
namespace {
// Tests for the never save view of the password management bubble.
class ManagePasswordsBubbleNeverSaveViewControllerTest
: public ManagePasswordsControllerTest {
public:
ManagePasswordsBubbleNeverSaveViewControllerTest() : controller_(nil) {}
virtual void SetUp() OVERRIDE {
ManagePasswordsControllerTest::SetUp();
delegate_.reset(
[[ManagePasswordsBubbleNeverSaveViewTestDelegate alloc] init]);
ui_controller()->SetState(password_manager::ui::PENDING_PASSWORD_STATE);
}
ManagePasswordsBubbleNeverSaveViewTestDelegate* delegate() {
return delegate_.get();
}
ManagePasswordsBubbleNeverSaveViewController* controller() {
if (!controller_) {
controller_.reset([[ManagePasswordsBubbleNeverSaveViewController alloc]
initWithModel:model()
delegate:delegate()]);
[controller_ loadView];
}
return controller_.get();
}
private:
base::scoped_nsobject<ManagePasswordsBubbleNeverSaveViewController>
controller_;
base::scoped_nsobject<ManagePasswordsBubbleNeverSaveViewTestDelegate>
delegate_;
};
TEST_F(ManagePasswordsBubbleNeverSaveViewControllerTest,
ShouldNotifyDelegateWhenUndoClicked) {
NSButton* undoButton = controller().undoButton;
[undoButton performClick:nil];
EXPECT_TRUE(delegate().cancelledNeverSave);
}
TEST_F(ManagePasswordsBubbleNeverSaveViewControllerTest,
ShouldDismissAndNeverSaveWhenConfirmClicked) {
NSButton* confirmButton = controller().confirmButton;
[confirmButton performClick:nil];
EXPECT_TRUE(delegate().dismissed);
EXPECT_TRUE(ui_controller()->never_saved_password());
}
} // namespace
...@@ -639,6 +639,8 @@ ...@@ -639,6 +639,8 @@
'browser/ui/cocoa/passwords/manage_passwords_bubble_controller.mm', 'browser/ui/cocoa/passwords/manage_passwords_bubble_controller.mm',
'browser/ui/cocoa/passwords/manage_passwords_bubble_manage_view_controller.h', 'browser/ui/cocoa/passwords/manage_passwords_bubble_manage_view_controller.h',
'browser/ui/cocoa/passwords/manage_passwords_bubble_manage_view_controller.mm', 'browser/ui/cocoa/passwords/manage_passwords_bubble_manage_view_controller.mm',
'browser/ui/cocoa/passwords/manage_passwords_bubble_never_save_view_controller.h',
'browser/ui/cocoa/passwords/manage_passwords_bubble_never_save_view_controller.mm',
'browser/ui/cocoa/passwords/manage_passwords_bubble_pending_view_controller.h', 'browser/ui/cocoa/passwords/manage_passwords_bubble_pending_view_controller.h',
'browser/ui/cocoa/passwords/manage_passwords_bubble_pending_view_controller.mm', 'browser/ui/cocoa/passwords/manage_passwords_bubble_pending_view_controller.mm',
'browser/ui/cocoa/pdf_password_dialog.mm', 'browser/ui/cocoa/pdf_password_dialog.mm',
......
...@@ -1627,6 +1627,7 @@ ...@@ -1627,6 +1627,7 @@
'browser/ui/cocoa/passwords/manage_passwords_bubble_confirmation_view_controller_unittest.mm', 'browser/ui/cocoa/passwords/manage_passwords_bubble_confirmation_view_controller_unittest.mm',
'browser/ui/cocoa/passwords/manage_passwords_bubble_controller_unittest.mm', 'browser/ui/cocoa/passwords/manage_passwords_bubble_controller_unittest.mm',
'browser/ui/cocoa/passwords/manage_passwords_bubble_manage_view_controller_unittest.mm', 'browser/ui/cocoa/passwords/manage_passwords_bubble_manage_view_controller_unittest.mm',
'browser/ui/cocoa/passwords/manage_passwords_bubble_never_save_view_controller_unittest.mm',
'browser/ui/cocoa/passwords/manage_passwords_bubble_pending_view_controller_unittest.mm', 'browser/ui/cocoa/passwords/manage_passwords_bubble_pending_view_controller_unittest.mm',
'browser/ui/cocoa/passwords/manage_passwords_controller_test.h', 'browser/ui/cocoa/passwords/manage_passwords_controller_test.h',
'browser/ui/cocoa/passwords/manage_passwords_controller_test.mm', 'browser/ui/cocoa/passwords/manage_passwords_controller_test.mm',
......
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