OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/renderer_host/text_input_client_mac.h" | 5 #import "content/browser/renderer_host/text_input_client_mac.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
10 #include "content/browser/gpu/gpu_surface_tracker.h" | 10 #include "content/browser/gpu/gpu_surface_tracker.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 } | 197 } |
198 | 198 |
199 TEST_F(TextInputClientMacTest, TimeoutRectForRange) { | 199 TEST_F(TextInputClientMacTest, TimeoutRectForRange) { |
200 NSRect rect = service()->GetFirstRectForRange(widget(), NSMakeRange(0, 32)); | 200 NSRect rect = service()->GetFirstRectForRange(widget(), NSMakeRange(0, 32)); |
201 EXPECT_EQ(1U, ipc_sink().message_count()); | 201 EXPECT_EQ(1U, ipc_sink().message_count()); |
202 EXPECT_TRUE(ipc_sink().GetUniqueMessageMatching( | 202 EXPECT_TRUE(ipc_sink().GetUniqueMessageMatching( |
203 TextInputClientMsg_FirstRectForCharacterRange::ID)); | 203 TextInputClientMsg_FirstRectForCharacterRange::ID)); |
204 EXPECT_NSEQ(NSZeroRect, rect); | 204 EXPECT_NSEQ(NSZeroRect, rect); |
205 } | 205 } |
206 | 206 |
207 TEST_F(TextInputClientMacTest, GetSubstring) { | |
208 ScopedTestingThread thread(this); | |
209 NSDictionary* attributes = | |
210 [NSDictionary dictionaryWithObject:[NSColor purpleColor] | |
211 forKey:NSForegroundColorAttributeName]; | |
212 base::scoped_nsobject<NSMutableAttributedString> kSuccessValue( | |
213 [[NSMutableAttributedString alloc] | |
214 initWithString:@"Barney is a purple dinosaur" | |
215 attributes:attributes]); | |
216 | |
217 PostTask(FROM_HERE, | |
218 base::Bind(&TextInputClientMac::SetSubstringAndSignal, | |
219 base::Unretained(service()), | |
220 base::Unretained(kSuccessValue.get()))); | |
221 NSAttributedString* string = service()->GetAttributedSubstringFromRange( | |
222 widget(), NSMakeRange(0, 32)); | |
223 | |
224 EXPECT_NSEQ(kSuccessValue, string); | |
225 EXPECT_NE(kSuccessValue.get(), string); // |string| should be a copy. | |
226 EXPECT_EQ(1U, ipc_sink().message_count()); | |
227 EXPECT_TRUE(ipc_sink().GetUniqueMessageMatching( | |
228 TextInputClientMsg_StringForRange::ID)); | |
229 } | |
230 | |
231 TEST_F(TextInputClientMacTest, TimeoutSubstring) { | |
232 NSAttributedString* string = service()->GetAttributedSubstringFromRange( | |
233 widget(), NSMakeRange(0, 32)); | |
234 EXPECT_EQ(nil, string); | |
235 EXPECT_EQ(1U, ipc_sink().message_count()); | |
236 EXPECT_TRUE(ipc_sink().GetUniqueMessageMatching( | |
237 TextInputClientMsg_StringForRange::ID)); | |
238 } | |
239 | |
240 } // namespace content | 207 } // namespace content |
OLD | NEW |