Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side 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. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #include "base/scoped_nsobject.h" 7 #include "base/scoped_nsobject.h"
8 #import "chrome/browser/cocoa/autocomplete_text_field.h" 8 #import "chrome/browser/cocoa/autocomplete_text_field.h"
9 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h" 9 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h"
10 #import "chrome/browser/cocoa/cocoa_test_helper.h" 10 #import "chrome/browser/cocoa/cocoa_test_helper.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 @interface AutocompleteTextFieldTestDelegate : NSObject {
14 BOOL textShouldPaste_;
15 BOOL receivedTextShouldPaste_;
16 }
17 - initWithTextShouldPaste:(BOOL)flag;
18 - (BOOL)receivedTextShouldPaste;
19 @end
20
13 namespace { 21 namespace {
14 22
15 class AutocompleteTextFieldTest : public testing::Test { 23 class AutocompleteTextFieldTest : public testing::Test {
16 public: 24 public:
17 AutocompleteTextFieldTest() { 25 AutocompleteTextFieldTest() {
18 NSRect frame = NSMakeRect(0, 0, 50, 30); 26 NSRect frame = NSMakeRect(0, 0, 50, 30);
19 field_.reset([[AutocompleteTextField alloc] initWithFrame:frame]); 27 field_.reset([[AutocompleteTextField alloc] initWithFrame:frame]);
20 [field_ setStringValue:@"Testing"]; 28 [field_ setStringValue:@"Testing"];
21 [cocoa_helper_.contentView() addSubview:field_.get()]; 29 [cocoa_helper_.contentView() addSubview:field_.get()];
22 } 30 }
(...skipping 13 matching lines...) Expand all
36 EXPECT_EQ(cocoa_helper_.contentView(), [field_ superview]); 44 EXPECT_EQ(cocoa_helper_.contentView(), [field_ superview]);
37 [field_.get() removeFromSuperview]; 45 [field_.get() removeFromSuperview];
38 EXPECT_FALSE([field_ superview]); 46 EXPECT_FALSE([field_ superview]);
39 } 47 }
40 48
41 // Test drawing, mostly to ensure nothing leaks or crashes. 49 // Test drawing, mostly to ensure nothing leaks or crashes.
42 TEST_F(AutocompleteTextFieldTest, Display) { 50 TEST_F(AutocompleteTextFieldTest, Display) {
43 [field_ display]; 51 [field_ display];
44 } 52 }
45 53
54 // Test that -textShouldPaste: properly queries the delegate.
55 TEST_F(AutocompleteTextFieldTest, TextShouldPaste) {
56 EXPECT_TRUE(![field_ delegate]);
57 EXPECT_TRUE([field_ textShouldPaste:nil]);
58
59 scoped_nsobject<AutocompleteTextFieldTestDelegate> shouldPaste(
60 [[AutocompleteTextFieldTestDelegate alloc] initWithTextShouldPaste:YES]);
61 [field_ setDelegate:shouldPaste];
62 EXPECT_FALSE([shouldPaste receivedTextShouldPaste]);
63 EXPECT_TRUE([field_ textShouldPaste:nil]);
64 EXPECT_TRUE([shouldPaste receivedTextShouldPaste]);
65
66 scoped_nsobject<AutocompleteTextFieldTestDelegate> shouldNotPaste(
67 [[AutocompleteTextFieldTestDelegate alloc] initWithTextShouldPaste:NO]);
68 [field_ setDelegate:shouldNotPaste];
69 EXPECT_FALSE([shouldNotPaste receivedTextShouldPaste]);
70 EXPECT_FALSE([field_ textShouldPaste:nil]);
71 EXPECT_TRUE([shouldNotPaste receivedTextShouldPaste]);
72 }
73
46 } // namespace 74 } // namespace
75
76 @implementation AutocompleteTextFieldTestDelegate
77
78 - initWithTextShouldPaste:(BOOL)flag {
79 self = [super init];
80 if (self) {
81 textShouldPaste_ = flag;
82 receivedTextShouldPaste_ = NO;
83 }
84 return self;
85 }
86
87 - (BOOL)receivedTextShouldPaste {
88 return receivedTextShouldPaste_;
89 }
90
91 - (BOOL)control:(NSControl*)control textShouldPaste:(NSText*)fieldEditor {
92 receivedTextShouldPaste_ = YES;
93 return textShouldPaste_;
94 }
95
96 @end
OLDNEW
« 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
This is Rietveld 408576698