summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-29 17:28:29 +0000
committerjrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-29 17:28:29 +0000
commit2de1e53f716e5fc1264a680be94f371d01002108 (patch)
tree291ebd906235776747b106ef83acb6d61224ce1e
parentb51713b1d630e4ee893c5c7d037ec7a4213bc579 (diff)
downloadchromium_src-2de1e53f716e5fc1264a680be94f371d01002108.zip
chromium_src-2de1e53f716e5fc1264a680be94f371d01002108.tar.gz
chromium_src-2de1e53f716e5fc1264a680be94f371d01002108.tar.bz2
Disable "OK" button in edit dialog of bookmark button when name is not valid
TEST=see bug BUG=http://crbug.com/19558 Review URL: http://codereview.chromium.org/249030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27501 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/cocoa/bookmark_editor_controller.mm17
-rw-r--r--chrome/browser/cocoa/bookmark_editor_controller_unittest.mm13
2 files changed, 27 insertions, 3 deletions
diff --git a/chrome/browser/cocoa/bookmark_editor_controller.mm b/chrome/browser/cocoa/bookmark_editor_controller.mm
index 79cd1dc..bfa8156 100644
--- a/chrome/browser/cocoa/bookmark_editor_controller.mm
+++ b/chrome/browser/cocoa/bookmark_editor_controller.mm
@@ -67,8 +67,9 @@ void BookmarkEditor::Show(gfx::NativeView parent_hwnd,
[nameField_ setStringValue:initialName_];
[urlField_ setStringValue:initialUrl_];
- // Get a ping when the URL text changes;
+ // Get a ping when the URL or name text fields change;
// trigger an initial ping to set things up.
+ [nameField_ setDelegate:self];
[urlField_ setDelegate:self];
[self controlTextDidChange:nil];
@@ -136,7 +137,17 @@ void BookmarkEditor::Show(gfx::NativeView parent_hwnd,
// the notification.)
- (void)controlTextDidChange:(NSNotification *)aNotification {
GURL newURL = [self GURLFromUrlField];
- if (newURL.is_valid()) {
+ NSString* name = [nameField_ stringValue];
+
+ // if empty or only whitespace, name is not valid.
+ bool name_valid = true;
+ if (([name length] == 0) ||
+ ([[name stringByTrimmingCharactersInSet:[NSCharacterSet
+ whitespaceAndNewlineCharacterSet]] length] == 0)) {
+ name_valid = false;
+ }
+
+ if (newURL.is_valid() && name_valid) {
[okButton_ setEnabled:YES];
} else {
[okButton_ setEnabled:NO];
@@ -182,6 +193,7 @@ void BookmarkEditor::Show(gfx::NativeView parent_hwnd,
// This is probably unnecessary but it feels cleaner since the
// delegate of a text field can be automatically registered for
// notifications.
+ [nameField_ setDelegate:nil];
[urlField_ setDelegate:nil];
[[self window] orderOut:self];
@@ -202,6 +214,7 @@ void BookmarkEditor::Show(gfx::NativeView parent_hwnd,
- (void)setDisplayName:(NSString*)name {
[nameField_ setStringValue:name];
+ [self controlTextDidChange:nil];
}
- (void)setDisplayURL:(NSString*)name {
diff --git a/chrome/browser/cocoa/bookmark_editor_controller_unittest.mm b/chrome/browser/cocoa/bookmark_editor_controller_unittest.mm
index 947095e..dd35b37 100644
--- a/chrome/browser/cocoa/bookmark_editor_controller_unittest.mm
+++ b/chrome/browser/cocoa/bookmark_editor_controller_unittest.mm
@@ -106,10 +106,21 @@ TEST_F(BookmarkEditorControllerTest, UserEditsStuff) {
child = parent->GetChild(0);
EXPECT_TRUE(child->GetURL().is_valid());
- // Confirm OK button enabled/disabled as appropriate.
+ // Confirm OK button enabled/disabled as appropriate:
+ // First test the URL.
EXPECT_TRUE([controller okButtonEnabled]);
[controller setDisplayURL:@""];
EXPECT_FALSE([controller okButtonEnabled]);
[controller setDisplayURL:@"http://www.cnn.com"];
EXPECT_TRUE([controller okButtonEnabled]);
+ // Then test the name.
+ [controller setDisplayName:@""];
+ EXPECT_FALSE([controller okButtonEnabled]);
+ [controller setDisplayName:@" "];
+ EXPECT_FALSE([controller okButtonEnabled]);
+ // Then little mix of both.
+ [controller setDisplayName:@"name"];
+ EXPECT_TRUE([controller okButtonEnabled]);
+ [controller setDisplayURL:@""];
+ EXPECT_FALSE([controller okButtonEnabled]);
}