| 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 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 TEST_F(RenderWidgetHostViewMacTest, GetFirstRectForCharacterRangeCaretCase) { | 591 TEST_F(RenderWidgetHostViewMacTest, GetFirstRectForCharacterRangeCaretCase) { |
| 592 const base::string16 kDummyString = base::UTF8ToUTF16("hogehoge"); | 592 const base::string16 kDummyString = base::UTF8ToUTF16("hogehoge"); |
| 593 const size_t kDummyOffset = 0; | 593 const size_t kDummyOffset = 0; |
| 594 | 594 |
| 595 gfx::Rect caret_rect(10, 11, 0, 10); | 595 gfx::Rect caret_rect(10, 11, 0, 10); |
| 596 gfx::Range caret_range(0, 0); | 596 gfx::Range caret_range(0, 0); |
| 597 ViewHostMsg_SelectionBounds_Params params; | 597 ViewHostMsg_SelectionBounds_Params params; |
| 598 | 598 |
| 599 NSRect rect; | 599 NSRect rect; |
| 600 NSRange actual_range; | 600 NSRange actual_range; |
| 601 rwhv_mac_->SelectionChanged(kDummyString, kDummyOffset, caret_range); | 601 rwhv_mac_->SelectionChanged(kDummyString, kDummyOffset, caret_range, true); |
| 602 params.anchor_rect = params.focus_rect = caret_rect; | 602 params.anchor_rect = params.focus_rect = caret_rect; |
| 603 params.anchor_dir = params.focus_dir = blink::kWebTextDirectionLeftToRight; | 603 params.anchor_dir = params.focus_dir = blink::kWebTextDirectionLeftToRight; |
| 604 rwhv_mac_->SelectionBoundsChanged(params); | 604 rwhv_mac_->SelectionBoundsChanged(params); |
| 605 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 605 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 606 caret_range.ToNSRange(), | 606 caret_range.ToNSRange(), |
| 607 &rect, | 607 &rect, |
| 608 &actual_range)); | 608 &actual_range)); |
| 609 EXPECT_EQ(caret_rect, gfx::Rect(NSRectToCGRect(rect))); | 609 EXPECT_EQ(caret_rect, gfx::Rect(NSRectToCGRect(rect))); |
| 610 EXPECT_EQ(caret_range, gfx::Range(actual_range)); | 610 EXPECT_EQ(caret_range, gfx::Range(actual_range)); |
| 611 | 611 |
| 612 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 612 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 613 gfx::Range(0, 1).ToNSRange(), | 613 gfx::Range(0, 1).ToNSRange(), |
| 614 &rect, | 614 &rect, |
| 615 &actual_range)); | 615 &actual_range)); |
| 616 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 616 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 617 gfx::Range(1, 1).ToNSRange(), | 617 gfx::Range(1, 1).ToNSRange(), |
| 618 &rect, | 618 &rect, |
| 619 &actual_range)); | 619 &actual_range)); |
| 620 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 620 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 621 gfx::Range(2, 3).ToNSRange(), | 621 gfx::Range(2, 3).ToNSRange(), |
| 622 &rect, | 622 &rect, |
| 623 &actual_range)); | 623 &actual_range)); |
| 624 | 624 |
| 625 // Caret moved. | 625 // Caret moved. |
| 626 caret_rect = gfx::Rect(20, 11, 0, 10); | 626 caret_rect = gfx::Rect(20, 11, 0, 10); |
| 627 caret_range = gfx::Range(1, 1); | 627 caret_range = gfx::Range(1, 1); |
| 628 params.anchor_rect = params.focus_rect = caret_rect; | 628 params.anchor_rect = params.focus_rect = caret_rect; |
| 629 rwhv_mac_->SelectionChanged(kDummyString, kDummyOffset, caret_range); | 629 rwhv_mac_->SelectionChanged(kDummyString, kDummyOffset, caret_range, true); |
| 630 rwhv_mac_->SelectionBoundsChanged(params); | 630 rwhv_mac_->SelectionBoundsChanged(params); |
| 631 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 631 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 632 caret_range.ToNSRange(), | 632 caret_range.ToNSRange(), |
| 633 &rect, | 633 &rect, |
| 634 &actual_range)); | 634 &actual_range)); |
| 635 EXPECT_EQ(caret_rect, gfx::Rect(NSRectToCGRect(rect))); | 635 EXPECT_EQ(caret_rect, gfx::Rect(NSRectToCGRect(rect))); |
| 636 EXPECT_EQ(caret_range, gfx::Range(actual_range)); | 636 EXPECT_EQ(caret_range, gfx::Range(actual_range)); |
| 637 | 637 |
| 638 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 638 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 639 gfx::Range(0, 0).ToNSRange(), | 639 gfx::Range(0, 0).ToNSRange(), |
| 640 &rect, | 640 &rect, |
| 641 &actual_range)); | 641 &actual_range)); |
| 642 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 642 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 643 gfx::Range(1, 2).ToNSRange(), | 643 gfx::Range(1, 2).ToNSRange(), |
| 644 &rect, | 644 &rect, |
| 645 &actual_range)); | 645 &actual_range)); |
| 646 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 646 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 647 gfx::Range(2, 3).ToNSRange(), | 647 gfx::Range(2, 3).ToNSRange(), |
| 648 &rect, | 648 &rect, |
| 649 &actual_range)); | 649 &actual_range)); |
| 650 | 650 |
| 651 // No caret. | 651 // No caret. |
| 652 caret_range = gfx::Range(1, 2); | 652 caret_range = gfx::Range(1, 2); |
| 653 rwhv_mac_->SelectionChanged(kDummyString, kDummyOffset, caret_range); | 653 rwhv_mac_->SelectionChanged(kDummyString, kDummyOffset, caret_range, true); |
| 654 params.anchor_rect = caret_rect; | 654 params.anchor_rect = caret_rect; |
| 655 params.focus_rect = gfx::Rect(30, 11, 0, 10); | 655 params.focus_rect = gfx::Rect(30, 11, 0, 10); |
| 656 rwhv_mac_->SelectionBoundsChanged(params); | 656 rwhv_mac_->SelectionBoundsChanged(params); |
| 657 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 657 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 658 gfx::Range(0, 0).ToNSRange(), | 658 gfx::Range(0, 0).ToNSRange(), |
| 659 &rect, | 659 &rect, |
| 660 &actual_range)); | 660 &actual_range)); |
| 661 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 661 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 662 gfx::Range(0, 1).ToNSRange(), | 662 gfx::Range(0, 1).ToNSRange(), |
| 663 &rect, | 663 &rect, |
| (...skipping 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1739 } | 1739 } |
| 1740 | 1740 |
| 1741 // This test verifies that |selected_text_| is updated accordingly with | 1741 // This test verifies that |selected_text_| is updated accordingly with |
| 1742 // different variations of RWHVMac::SelectChanged updates. | 1742 // different variations of RWHVMac::SelectChanged updates. |
| 1743 TEST_F(RenderWidgetHostViewMacTest, SelectedText) { | 1743 TEST_F(RenderWidgetHostViewMacTest, SelectedText) { |
| 1744 base::string16 sample_text; | 1744 base::string16 sample_text; |
| 1745 base::UTF8ToUTF16("hello world!", 12, &sample_text); | 1745 base::UTF8ToUTF16("hello world!", 12, &sample_text); |
| 1746 gfx::Range range(6, 11); | 1746 gfx::Range range(6, 11); |
| 1747 | 1747 |
| 1748 // Send a valid selection for the word 'World'. | 1748 // Send a valid selection for the word 'World'. |
| 1749 rwhv_mac_->SelectionChanged(sample_text, 0U, range); | 1749 rwhv_mac_->SelectionChanged(sample_text, 0U, range, true); |
| 1750 EXPECT_EQ("world", selected_text()); | 1750 EXPECT_EQ("world", selected_text()); |
| 1751 | 1751 |
| 1752 // Make the range cover some of the text and extend more. | 1752 // Make the range cover some of the text and extend more. |
| 1753 range.set_end(100); | 1753 range.set_end(100); |
| 1754 rwhv_mac_->SelectionChanged(sample_text, 0U, range); | 1754 rwhv_mac_->SelectionChanged(sample_text, 0U, range, true); |
| 1755 EXPECT_EQ("world!", selected_text()); | 1755 EXPECT_EQ("world!", selected_text()); |
| 1756 | 1756 |
| 1757 // Finally, send an empty range. This should clear the selected text. | 1757 // Finally, send an empty range. This should clear the selected text. |
| 1758 range.set_start(100); | 1758 range.set_start(100); |
| 1759 rwhv_mac_->SelectionChanged(sample_text, 0U, range); | 1759 rwhv_mac_->SelectionChanged(sample_text, 0U, range, true); |
| 1760 EXPECT_EQ("", selected_text()); | 1760 EXPECT_EQ("", selected_text()); |
| 1761 } | 1761 } |
| 1762 | 1762 |
| 1763 // This class is used for IME-related unit tests which verify correctness of IME | 1763 // This class is used for IME-related unit tests which verify correctness of IME |
| 1764 // for pages with multiple RWHVs. | 1764 // for pages with multiple RWHVs. |
| 1765 class InputMethodMacTest : public RenderWidgetHostViewMacTest { | 1765 class InputMethodMacTest : public RenderWidgetHostViewMacTest { |
| 1766 public: | 1766 public: |
| 1767 InputMethodMacTest() {} | 1767 InputMethodMacTest() {} |
| 1768 ~InputMethodMacTest() override {} | 1768 ~InputMethodMacTest() override {} |
| 1769 | 1769 |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2083 // -performKeyEquivalent: now returns YES to prevent further propagation, and | 2083 // -performKeyEquivalent: now returns YES to prevent further propagation, and |
| 2084 // the event is sent to the renderer. | 2084 // the event is sent to the renderer. |
| 2085 EXPECT_TRUE([window performKeyEquivalent:key_down]); | 2085 EXPECT_TRUE([window performKeyEquivalent:key_down]); |
| 2086 EXPECT_EQ(2U, process_host->sink().message_count()); | 2086 EXPECT_EQ(2U, process_host->sink().message_count()); |
| 2087 EXPECT_EQ("RawKeyDown Char", GetInputMessageTypes(process_host)); | 2087 EXPECT_EQ("RawKeyDown Char", GetInputMessageTypes(process_host)); |
| 2088 | 2088 |
| 2089 rwhv_mac_->release_pepper_fullscreen_window_for_testing(); | 2089 rwhv_mac_->release_pepper_fullscreen_window_for_testing(); |
| 2090 } | 2090 } |
| 2091 | 2091 |
| 2092 } // namespace content | 2092 } // namespace content |
| OLD | NEW |