summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgroby@chromium.org <groby@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-17 05:46:34 +0000
committergroby@chromium.org <groby@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-17 05:46:34 +0000
commit225e7f6546d7878484a42dafb9e890359cecc8e3 (patch)
treee903213028eebfe495d298b8fb766ddf3bb29ad7
parent4f09916e79e814ffa8367e63641655e9e7b2e6f3 (diff)
downloadchromium_src-225e7f6546d7878484a42dafb9e890359cecc8e3.zip
chromium_src-225e7f6546d7878484a42dafb9e890359cecc8e3.tar.gz
chromium_src-225e7f6546d7878484a42dafb9e890359cecc8e3.tar.bz2
[rAC, OSX] "Save In Chrome" checkbox.
Add a checkbox that allows to toggle the "Save In Chrome" status. Will allow rAC to save manually entered data in Chrome's autofill data. R=isherman@chromium.org, rsesek@chromium.org BUG=256862 TEST=Bring up rAC dialog, see checkbox. Review URL: https://chromiumcodereview.appspot.com/19287006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@211962 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc4
-rw-r--r--chrome/browser/ui/autofill/mock_autofill_dialog_controller.h2
-rw-r--r--chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h1
-rw-r--r--chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.mm6
-rw-r--r--chrome/browser/ui/cocoa/autofill/autofill_main_container.h12
-rw-r--r--chrome/browser/ui/cocoa/autofill/autofill_main_container.mm27
-rw-r--r--chrome/browser/ui/cocoa/autofill/autofill_main_container_unittest.mm33
7 files changed, 76 insertions, 9 deletions
diff --git a/chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc b/chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc
index f129567..6ca8614 100644
--- a/chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc
+++ b/chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc
@@ -75,10 +75,6 @@ bool MockAutofillDialogController::ShouldShowSpinner() const {
return false;
}
-bool MockAutofillDialogController::ShouldOfferToSaveInChrome() const {
- return false;
-}
-
gfx::Image MockAutofillDialogController::AccountChooserImage() {
return gfx::Image();
}
diff --git a/chrome/browser/ui/autofill/mock_autofill_dialog_controller.h b/chrome/browser/ui/autofill/mock_autofill_dialog_controller.h
index 2ed3042..61a25d3 100644
--- a/chrome/browser/ui/autofill/mock_autofill_dialog_controller.h
+++ b/chrome/browser/ui/autofill/mock_autofill_dialog_controller.h
@@ -25,7 +25,7 @@ class MockAutofillDialogController : public AutofillDialogController {
virtual string16 LegalDocumentsText() OVERRIDE;
virtual DialogSignedInState SignedInState() const OVERRIDE;
virtual bool ShouldShowSpinner() const OVERRIDE;
- virtual bool ShouldOfferToSaveInChrome() const OVERRIDE;
+ MOCK_CONST_METHOD0(ShouldOfferToSaveInChrome, bool());
MOCK_METHOD0(MenuModelForAccountChooser, ui::MenuModel*());
virtual gfx::Image AccountChooserImage() OVERRIDE;
virtual bool ShouldShowProgressBar() const OVERRIDE;
diff --git a/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h b/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h
index 26dda3f..688535c 100644
--- a/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h
+++ b/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h
@@ -123,6 +123,7 @@ class AutofillDialogCocoa : public AutofillDialogView,
- (void)updateSection:(autofill::DialogSection)section;
- (void)getInputs:(autofill::DetailOutputMap*)outputs
forSection:(autofill::DialogSection)section;
+- (BOOL)saveDetailsLocally;
- (content::NavigationController*)showSignIn;
- (void)hideSignIn;
- (void)modelChanged;
diff --git a/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.mm b/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.mm
index 63b5cde..6ac323b 100644
--- a/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.mm
+++ b/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.mm
@@ -103,7 +103,7 @@ string16 AutofillDialogCocoa::GetCvc() {
}
bool AutofillDialogCocoa::SaveDetailsLocally() {
- return false;
+ return [sheet_controller_ saveDetailsLocally];
}
const content::NavigationController* AutofillDialogCocoa::ShowSignIn() {
@@ -326,6 +326,10 @@ void AutofillDialogCocoa::OnConstrainedWindowClosed(
[[mainContainer_ sectionForId:section] getInputs:output];
}
+- (BOOL)saveDetailsLocally {
+ return [mainContainer_ saveDetailsLocally];
+}
+
- (void)hideSignIn {
[[signInContainer_ view] setHidden:YES];
[[mainContainer_ view] setHidden:NO];
diff --git a/chrome/browser/ui/cocoa/autofill/autofill_main_container.h b/chrome/browser/ui/cocoa/autofill/autofill_main_container.h
index ae83ea7..9b5e123 100644
--- a/chrome/browser/ui/cocoa/autofill/autofill_main_container.h
+++ b/chrome/browser/ui/cocoa/autofill/autofill_main_container.h
@@ -29,6 +29,7 @@ namespace autofill {
NSTextViewDelegate> {
@private
base::scoped_nsobject<GTMWidthBasedTweaker> buttonContainer_;
+ base::scoped_nsobject<NSButton> saveInChromeCheckbox_;
base::scoped_nsobject<AutofillDetailsContainer> detailsContainer_;
base::scoped_nsobject<HyperlinkTextView> legalDocumentsView_;
base::scoped_nsobject<AutofillNotificationContainer> notificationContainer_;
@@ -58,6 +59,9 @@ namespace autofill {
// Called when the controller-maintained suggestions model has changed.
- (void)modelChanged;
+// Get status of "Save in Chrome" checkbox.
+- (BOOL)saveDetailsLocally;
+
// Called when the legal documents text might need to be refreshed.
- (void)updateLegalDocuments;
@@ -69,4 +73,12 @@ namespace autofill {
@end
+
+// AutofillMainContainer helper functions, for testing purposes only.
+@interface AutofillMainContainer (Testing)
+
+@property(readonly, nonatomic) NSButton* saveInChromeCheckboxForTesting;
+
+@end
+
#endif // CHROME_BROWSER_UI_COCOA_AUTOFILL_AUTOFILL_MAIN_CONTAINER_H_
diff --git a/chrome/browser/ui/cocoa/autofill/autofill_main_container.mm b/chrome/browser/ui/cocoa/autofill/autofill_main_container.mm
index 8290875..4a9492a 100644
--- a/chrome/browser/ui/cocoa/autofill/autofill_main_container.mm
+++ b/chrome/browser/ui/cocoa/autofill/autofill_main_container.mm
@@ -50,6 +50,15 @@
[self layoutButtons];
+ // Set up "Save in Chrome" checkbox.
+ saveInChromeCheckbox_.reset([[NSButton alloc] initWithFrame:NSZeroRect]);
+ [saveInChromeCheckbox_ setButtonType:NSSwitchButton];
+ [saveInChromeCheckbox_ setTitle:
+ base::SysUTF16ToNSString(controller_->SaveLocallyText())];
+ [saveInChromeCheckbox_ setState:NSOnState];
+ [saveInChromeCheckbox_ sizeToFit];
+ [[self view] addSubview:saveInChromeCheckbox_];
+
detailsContainer_.reset(
[[AutofillDetailsContainer alloc] initWithController:controller_]);
NSSize frameSize = [[detailsContainer_ view] frame].size;
@@ -122,6 +131,10 @@
buttonFrame.origin.y = currentY;
[buttonContainer_ setFrameOrigin:buttonFrame.origin];
+ NSRect checkboxFrame = [saveInChromeCheckbox_ frame];
+ checkboxFrame.origin.y = NSMidY(buttonFrame) - NSHeight(checkboxFrame) / 2.0;
+ [saveInChromeCheckbox_ setFrameOrigin:checkboxFrame.origin];
+
[detailsContainer_ performLayout];
NSRect containerFrame = [[detailsContainer_ view] frame];
containerFrame.origin.y = NSMaxY(buttonFrame);
@@ -208,9 +221,14 @@
}
- (void)modelChanged {
+ [saveInChromeCheckbox_ setHidden:!controller_->ShouldOfferToSaveInChrome()];
[detailsContainer_ modelChanged];
}
+- (BOOL)saveDetailsLocally {
+ return [saveInChromeCheckbox_ state] == NSOnState;
+}
+
- (void)updateLegalDocuments {
NSString* text = base::SysUTF16ToNSString(controller_->LegalDocumentsText());
@@ -254,3 +272,12 @@
}
@end
+
+
+@implementation AutofillMainContainer (Testing)
+
+- (NSButton*)saveInChromeCheckboxForTesting {
+ return saveInChromeCheckbox_.get();
+}
+
+@end
diff --git a/chrome/browser/ui/cocoa/autofill/autofill_main_container_unittest.mm b/chrome/browser/ui/cocoa/autofill/autofill_main_container_unittest.mm
index 5eeaf1d..66ca163 100644
--- a/chrome/browser/ui/cocoa/autofill/autofill_main_container_unittest.mm
+++ b/chrome/browser/ui/cocoa/autofill/autofill_main_container_unittest.mm
@@ -35,10 +35,11 @@ TEST_F(AutofillMainContainerTest, SubViews) {
bool hasButtons = false;
bool hasTextView = false;
bool hasDetailsContainer = false;
+ bool hasCheckbox = false;
int hasNotificationContainer = false;
// Should have account chooser, button strip, and details section.
- EXPECT_EQ(4U, [[[container_ view] subviews] count]);
+ EXPECT_EQ(5U, [[[container_ view] subviews] count]);
for (NSView* view in [[container_ view] subviews]) {
NSArray* subviews = [view subviews];
if ([subviews count] == 2) {
@@ -50,9 +51,12 @@ TEST_F(AutofillMainContainerTest, SubViews) {
} else if ([view isKindOfClass:[NSTextView class]]) {
hasTextView = true;
} else if ([subviews count] > 0 &&
- [[subviews objectAtIndex:0] isKindOfClass:
- [AutofillSectionView class]]) {
+ [[subviews objectAtIndex:0] isKindOfClass:
+ [AutofillSectionView class]]) {
hasDetailsContainer = true;
+ } else if ([view isKindOfClass:[NSButton class]] &&
+ view == [container_ saveInChromeCheckboxForTesting]) {
+ hasCheckbox = true;
} else {
// Assume by default this is the notification area view.
// There is no way to easily verify that with more detail.
@@ -64,4 +68,27 @@ TEST_F(AutofillMainContainerTest, SubViews) {
EXPECT_TRUE(hasTextView);
EXPECT_TRUE(hasDetailsContainer);
EXPECT_TRUE(hasNotificationContainer);
+ EXPECT_TRUE(hasCheckbox);
+}
+
+TEST_F(AutofillMainContainerTest, SaveDetailsLocallyDefaultsToTrue) {
+ EXPECT_TRUE([container_ saveDetailsLocally]);
+}
+
+TEST_F(AutofillMainContainerTest, SaveInChromeCheckboxVisibility) {
+ using namespace testing;
+
+ // Tests that the checkbox is only visible if the controller allows it.
+ EXPECT_CALL(controller_, ShouldOfferToSaveInChrome()).Times(2)
+ .WillOnce(Return(false))
+ .WillOnce(Return(true));
+
+ NSButton* checkbox = [container_ saveInChromeCheckboxForTesting];
+ ASSERT_TRUE(checkbox);
+
+ EXPECT_FALSE([checkbox isHidden]);
+ [container_ modelChanged];
+ EXPECT_TRUE([checkbox isHidden]);
+ [container_ modelChanged];
+ EXPECT_FALSE([checkbox isHidden]);
}