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