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 #include "content/browser/renderer_host/render_widget_host_view_mac.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
6 | 6 |
7 #include "base/mac/scoped_nsautorelease_pool.h" | 7 #include "base/mac/scoped_nsautorelease_pool.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "content/browser/browser_thread_impl.h" | 9 #include "content/browser/browser_thread_impl.h" |
10 #include "content/browser/renderer_host/test_render_view_host.h" | 10 #include "content/browser/renderer_host/test_render_view_host.h" |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 330 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
331 ui::Range(2, 2).ToNSRange(), | 331 ui::Range(2, 2).ToNSRange(), |
332 &rect, | 332 &rect, |
333 &actual_range)); | 333 &actual_range)); |
334 } | 334 } |
335 | 335 |
336 TEST_F(RenderWidgetHostViewMacTest, UpdateCompositionSinglelineCase) { | 336 TEST_F(RenderWidgetHostViewMacTest, UpdateCompositionSinglelineCase) { |
337 const gfx::Point kOrigin(10, 11); | 337 const gfx::Point kOrigin(10, 11); |
338 const gfx::Size kBoundsUnit(10, 20); | 338 const gfx::Size kBoundsUnit(10, 20); |
339 | 339 |
| 340 NSRect rect; |
| 341 // Make sure not crashing by passing NULL pointer instead of |actual_range|. |
| 342 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 343 ui::Range(0, 0).ToNSRange(), |
| 344 &rect, |
| 345 NULL)); |
| 346 |
340 // If there are no update from renderer, always returned caret position. | 347 // If there are no update from renderer, always returned caret position. |
341 NSRect rect; | |
342 NSRange actual_range; | 348 NSRange actual_range; |
343 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 349 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
344 ui::Range(0, 0).ToNSRange(), | 350 ui::Range(0, 0).ToNSRange(), |
345 &rect, | 351 &rect, |
346 &actual_range)); | 352 &actual_range)); |
347 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 353 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
348 ui::Range(0, 1).ToNSRange(), | 354 ui::Range(0, 1).ToNSRange(), |
349 &rect, | 355 &rect, |
350 &actual_range)); | 356 &actual_range)); |
351 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 357 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 0); | 414 0); |
409 const NSRange request_range = ui::Range( | 415 const NSRange request_range = ui::Range( |
410 kCompositionStart + range.start(), | 416 kCompositionStart + range.start(), |
411 kCompositionStart + range.end()).ToNSRange(); | 417 kCompositionStart + range.end()).ToNSRange(); |
412 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 418 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
413 request_range, | 419 request_range, |
414 &rect, | 420 &rect, |
415 &actual_range)); | 421 &actual_range)); |
416 EXPECT_EQ(ui::Range(request_range), ui::Range(actual_range)); | 422 EXPECT_EQ(ui::Range(request_range), ui::Range(actual_range)); |
417 EXPECT_EQ(expected_rect, gfx::Rect(NSRectToCGRect(rect))); | 423 EXPECT_EQ(expected_rect, gfx::Rect(NSRectToCGRect(rect))); |
| 424 |
| 425 // Make sure not crashing by passing NULL pointer instead of |
| 426 // |actual_range|. |
| 427 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 428 request_range, |
| 429 &rect, |
| 430 NULL)); |
418 } | 431 } |
419 } | 432 } |
420 } | 433 } |
421 | 434 |
422 TEST_F(RenderWidgetHostViewMacTest, UpdateCompositionMultilineCase) { | 435 TEST_F(RenderWidgetHostViewMacTest, UpdateCompositionMultilineCase) { |
423 const gfx::Point kOrigin(10, 11); | 436 const gfx::Point kOrigin(10, 11); |
424 const gfx::Size kBoundsUnit(10, 20); | 437 const gfx::Size kBoundsUnit(10, 20); |
425 NSRect rect; | 438 NSRect rect; |
426 | 439 |
427 const int kCompositionLength = 30; | 440 const int kCompositionLength = 30; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 range = ui::Range(10, 20); | 555 range = ui::Range(10, 20); |
543 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(range.ToNSRange(), | 556 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(range.ToNSRange(), |
544 &rect, | 557 &rect, |
545 &actual_range)); | 558 &actual_range)); |
546 EXPECT_EQ(ui::Range(10, 20), ui::Range(actual_range)); | 559 EXPECT_EQ(ui::Range(10, 20), ui::Range(actual_range)); |
547 EXPECT_EQ( | 560 EXPECT_EQ( |
548 GetExpectedRect(kOrigin, kBoundsUnit, ui::Range(0, 10), 1), | 561 GetExpectedRect(kOrigin, kBoundsUnit, ui::Range(0, 10), 1), |
549 gfx::Rect(NSRectToCGRect(rect))); | 562 gfx::Rect(NSRectToCGRect(rect))); |
550 } | 563 } |
551 } // namespace content | 564 } // namespace content |
OLD | NEW |