| 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 <Cocoa/Cocoa.h> | 7 #include <Cocoa/Cocoa.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <tuple> | 10 #include <tuple> |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 pool_.Recycle(); | 272 pool_.Recycle(); |
| 273 base::RunLoop().RunUntilIdle(); | 273 base::RunLoop().RunUntilIdle(); |
| 274 pool_.Recycle(); | 274 pool_.Recycle(); |
| 275 } | 275 } |
| 276 | 276 |
| 277 void DestroyHostViewRetainCocoaView() { | 277 void DestroyHostViewRetainCocoaView() { |
| 278 test_rvh()->GetWidget()->SetView(nullptr); | 278 test_rvh()->GetWidget()->SetView(nullptr); |
| 279 rwhv_mac_->Destroy(); | 279 rwhv_mac_->Destroy(); |
| 280 } | 280 } |
| 281 | 281 |
| 282 void ActivateViewWithTextInputManager(RenderWidgetHostViewBase* view, |
| 283 ui::TextInputType type) { |
| 284 TextInputState state; |
| 285 state.type = type; |
| 286 view->TextInputStateChanged(state); |
| 287 } |
| 288 |
| 282 private: | 289 private: |
| 283 // This class isn't derived from PlatformTest. | 290 // This class isn't derived from PlatformTest. |
| 284 base::mac::ScopedNSAutoreleasePool pool_; | 291 base::mac::ScopedNSAutoreleasePool pool_; |
| 285 | 292 |
| 286 RenderWidgetHostView* old_rwhv_; | 293 RenderWidgetHostView* old_rwhv_; |
| 287 | 294 |
| 288 protected: | 295 protected: |
| 289 RenderWidgetHostViewMac* rwhv_mac_; | 296 RenderWidgetHostViewMac* rwhv_mac_; |
| 290 base::scoped_nsobject<RenderWidgetHostViewCocoa> rwhv_cocoa_; | 297 base::scoped_nsobject<RenderWidgetHostViewCocoa> rwhv_cocoa_; |
| 291 | 298 |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 gfx::Range(1, 2).ToNSRange(), | 534 gfx::Range(1, 2).ToNSRange(), |
| 528 &rect, | 535 &rect, |
| 529 &actual_range)); | 536 &actual_range)); |
| 530 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 537 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 531 gfx::Range(2, 2).ToNSRange(), | 538 gfx::Range(2, 2).ToNSRange(), |
| 532 &rect, | 539 &rect, |
| 533 &actual_range)); | 540 &actual_range)); |
| 534 } | 541 } |
| 535 | 542 |
| 536 TEST_F(RenderWidgetHostViewMacTest, UpdateCompositionSinglelineCase) { | 543 TEST_F(RenderWidgetHostViewMacTest, UpdateCompositionSinglelineCase) { |
| 544 ActivateViewWithTextInputManager(rwhv_mac_, ui::TEXT_INPUT_TYPE_TEXT); |
| 537 const gfx::Point kOrigin(10, 11); | 545 const gfx::Point kOrigin(10, 11); |
| 538 const gfx::Size kBoundsUnit(10, 20); | 546 const gfx::Size kBoundsUnit(10, 20); |
| 539 | 547 |
| 540 NSRect rect; | 548 NSRect rect; |
| 541 // Make sure not crashing by passing NULL pointer instead of |actual_range|. | 549 // Make sure not crashing by passing NULL pointer instead of |actual_range|. |
| 542 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 550 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 543 gfx::Range(0, 0).ToNSRange(), | 551 gfx::Range(0, 0).ToNSRange(), |
| 544 &rect, | 552 &rect, |
| 545 NULL)); | 553 NULL)); |
| 546 | 554 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 // |actual_range|. | 643 // |actual_range|. |
| 636 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 644 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 637 request_range, | 645 request_range, |
| 638 &rect, | 646 &rect, |
| 639 NULL)); | 647 NULL)); |
| 640 } | 648 } |
| 641 } | 649 } |
| 642 } | 650 } |
| 643 | 651 |
| 644 TEST_F(RenderWidgetHostViewMacTest, UpdateCompositionMultilineCase) { | 652 TEST_F(RenderWidgetHostViewMacTest, UpdateCompositionMultilineCase) { |
| 653 ActivateViewWithTextInputManager(rwhv_mac_, ui::TEXT_INPUT_TYPE_TEXT); |
| 645 const gfx::Point kOrigin(10, 11); | 654 const gfx::Point kOrigin(10, 11); |
| 646 const gfx::Size kBoundsUnit(10, 20); | 655 const gfx::Size kBoundsUnit(10, 20); |
| 647 NSRect rect; | 656 NSRect rect; |
| 648 | 657 |
| 649 const int kCompositionLength = 30; | 658 const int kCompositionLength = 30; |
| 650 std::vector<gfx::Rect> composition_bounds; | 659 std::vector<gfx::Rect> composition_bounds; |
| 651 const gfx::Range kCompositionRange(0, kCompositionLength); | 660 const gfx::Range kCompositionRange(0, kCompositionLength); |
| 652 // Set breaking point at 10 and 20. | 661 // Set breaking point at 10 and 20. |
| 653 std::vector<size_t> break_points; | 662 std::vector<size_t> break_points; |
| 654 break_points.push_back(10); | 663 break_points.push_back(10); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 EXPECT_EQ(gfx::Range(10, 20), gfx::Range(actual_range)); | 777 EXPECT_EQ(gfx::Range(10, 20), gfx::Range(actual_range)); |
| 769 EXPECT_EQ( | 778 EXPECT_EQ( |
| 770 GetExpectedRect(kOrigin, kBoundsUnit, gfx::Range(0, 10), 1), | 779 GetExpectedRect(kOrigin, kBoundsUnit, gfx::Range(0, 10), 1), |
| 771 gfx::Rect(NSRectToCGRect(rect))); | 780 gfx::Rect(NSRectToCGRect(rect))); |
| 772 } | 781 } |
| 773 | 782 |
| 774 // Check that events coming from AppKit via -[NSTextInputClient | 783 // Check that events coming from AppKit via -[NSTextInputClient |
| 775 // firstRectForCharacterRange:actualRange] are handled in a sane manner if they | 784 // firstRectForCharacterRange:actualRange] are handled in a sane manner if they |
| 776 // arrive after the C++ RenderWidgetHostView is destroyed. | 785 // arrive after the C++ RenderWidgetHostView is destroyed. |
| 777 TEST_F(RenderWidgetHostViewMacTest, CompositionEventAfterDestroy) { | 786 TEST_F(RenderWidgetHostViewMacTest, CompositionEventAfterDestroy) { |
| 787 ActivateViewWithTextInputManager(rwhv_mac_, ui::TEXT_INPUT_TYPE_TEXT); |
| 778 const gfx::Rect composition_bounds(0, 0, 30, 40); | 788 const gfx::Rect composition_bounds(0, 0, 30, 40); |
| 779 const gfx::Range range(0, 1); | 789 const gfx::Range range(0, 1); |
| 780 rwhv_mac_->ImeCompositionRangeChanged( | 790 rwhv_mac_->ImeCompositionRangeChanged( |
| 781 range, std::vector<gfx::Rect>(1, composition_bounds)); | 791 range, std::vector<gfx::Rect>(1, composition_bounds)); |
| 782 | 792 |
| 783 NSRange actual_range = NSMakeRange(0, 0); | 793 NSRange actual_range = NSMakeRange(0, 0); |
| 784 | 794 |
| 785 base::scoped_nsobject<CocoaTestHelperWindow> window( | 795 base::scoped_nsobject<CocoaTestHelperWindow> window( |
| 786 [[CocoaTestHelperWindow alloc] init]); | 796 [[CocoaTestHelperWindow alloc] init]); |
| 787 [[window contentView] addSubview:rwhv_cocoa_]; | 797 [[window contentView] addSubview:rwhv_cocoa_]; |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1439 // Repeat for the tab's view. | 1449 // Repeat for the tab's view. |
| 1440 [rwhv_cocoa_ setMarkedText:text | 1450 [rwhv_cocoa_ setMarkedText:text |
| 1441 selectedRange:selectedRange | 1451 selectedRange:selectedRange |
| 1442 replacementRange:replacementRange]; | 1452 replacementRange:replacementRange]; |
| 1443 EXPECT_TRUE([rwhv_cocoa_ hasMarkedText]); | 1453 EXPECT_TRUE([rwhv_cocoa_ hasMarkedText]); |
| 1444 rwhv_mac_->ImeCancelComposition(); | 1454 rwhv_mac_->ImeCancelComposition(); |
| 1445 EXPECT_FALSE([rwhv_cocoa_ hasMarkedText]); | 1455 EXPECT_FALSE([rwhv_cocoa_ hasMarkedText]); |
| 1446 } | 1456 } |
| 1447 | 1457 |
| 1448 } // namespace content | 1458 } // namespace content |
| OLD | NEW |