Chromium Code Reviews

Unified Diff: chrome/browser/cocoa/autocomplete_text_field_unittest.mm

Issue 159018: [Mac] Strip newlines from paste. (Closed)
Patch Set: Test empty clipboard Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
« no previous file with comments | « chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/cocoa/autocomplete_text_field_unittest.mm
diff --git a/chrome/browser/cocoa/autocomplete_text_field_unittest.mm b/chrome/browser/cocoa/autocomplete_text_field_unittest.mm
index 9e861a8e0473fe3411c860bfeab6308d53004a85..03a786f66f2072b88028b876ddbb4d825936229b 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_unittest.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field_unittest.mm
@@ -10,6 +10,14 @@
#import "chrome/browser/cocoa/cocoa_test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
+@interface AutocompleteTextFieldTestDelegate : NSObject {
+ BOOL textShouldPaste_;
+ BOOL receivedTextShouldPaste_;
+}
+- initWithTextShouldPaste:(BOOL)flag;
+- (BOOL)receivedTextShouldPaste;
+@end
+
namespace {
class AutocompleteTextFieldTest : public testing::Test {
@@ -43,4 +51,46 @@ TEST_F(AutocompleteTextFieldTest, Display) {
[field_ display];
}
+// Test that -textShouldPaste: properly queries the delegate.
+TEST_F(AutocompleteTextFieldTest, TextShouldPaste) {
+ EXPECT_TRUE(![field_ delegate]);
+ EXPECT_TRUE([field_ textShouldPaste:nil]);
+
+ scoped_nsobject<AutocompleteTextFieldTestDelegate> shouldPaste(
+ [[AutocompleteTextFieldTestDelegate alloc] initWithTextShouldPaste:YES]);
+ [field_ setDelegate:shouldPaste];
+ EXPECT_FALSE([shouldPaste receivedTextShouldPaste]);
+ EXPECT_TRUE([field_ textShouldPaste:nil]);
+ EXPECT_TRUE([shouldPaste receivedTextShouldPaste]);
+
+ scoped_nsobject<AutocompleteTextFieldTestDelegate> shouldNotPaste(
+ [[AutocompleteTextFieldTestDelegate alloc] initWithTextShouldPaste:NO]);
+ [field_ setDelegate:shouldNotPaste];
+ EXPECT_FALSE([shouldNotPaste receivedTextShouldPaste]);
+ EXPECT_FALSE([field_ textShouldPaste:nil]);
+ EXPECT_TRUE([shouldNotPaste receivedTextShouldPaste]);
+}
+
} // namespace
+
+@implementation AutocompleteTextFieldTestDelegate
+
+- initWithTextShouldPaste:(BOOL)flag {
+ self = [super init];
+ if (self) {
+ textShouldPaste_ = flag;
+ receivedTextShouldPaste_ = NO;
+ }
+ return self;
+}
+
+- (BOOL)receivedTextShouldPaste {
+ return receivedTextShouldPaste_;
+}
+
+- (BOOL)control:(NSControl*)control textShouldPaste:(NSText*)fieldEditor {
+ receivedTextShouldPaste_ = YES;
+ return textShouldPaste_;
+}
+
+@end
« no previous file with comments | « chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine