| 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 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 TEST_F(RenderWidgetHostViewMacTest, GetFirstRectForCharacterRangeCaretCase) { | 577 TEST_F(RenderWidgetHostViewMacTest, GetFirstRectForCharacterRangeCaretCase) { |
| 578 const base::string16 kDummyString = base::UTF8ToUTF16("hogehoge"); | 578 const base::string16 kDummyString = base::UTF8ToUTF16("hogehoge"); |
| 579 const size_t kDummyOffset = 0; | 579 const size_t kDummyOffset = 0; |
| 580 | 580 |
| 581 gfx::Rect caret_rect(10, 11, 0, 10); | 581 gfx::Rect caret_rect(10, 11, 0, 10); |
| 582 gfx::Range caret_range(0, 0); | 582 gfx::Range caret_range(0, 0); |
| 583 ViewHostMsg_SelectionBounds_Params params; | 583 ViewHostMsg_SelectionBounds_Params params; |
| 584 | 584 |
| 585 NSRect rect; | 585 NSRect rect; |
| 586 NSRange actual_range; | 586 NSRange actual_range; |
| 587 rwhv_mac_->SelectionChanged(kDummyString, kDummyOffset, caret_range); | 587 rwhv_mac_->SelectionChanged(kDummyString, kDummyOffset, caret_range, true); |
| 588 params.anchor_rect = params.focus_rect = caret_rect; | 588 params.anchor_rect = params.focus_rect = caret_rect; |
| 589 params.anchor_dir = params.focus_dir = blink::kWebTextDirectionLeftToRight; | 589 params.anchor_dir = params.focus_dir = blink::kWebTextDirectionLeftToRight; |
| 590 rwhv_mac_->SelectionBoundsChanged(params); | 590 rwhv_mac_->SelectionBoundsChanged(params); |
| 591 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 591 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 592 caret_range.ToNSRange(), | 592 caret_range.ToNSRange(), |
| 593 &rect, | 593 &rect, |
| 594 &actual_range)); | 594 &actual_range)); |
| 595 EXPECT_EQ(caret_rect, gfx::Rect(NSRectToCGRect(rect))); | 595 EXPECT_EQ(caret_rect, gfx::Rect(NSRectToCGRect(rect))); |
| 596 EXPECT_EQ(caret_range, gfx::Range(actual_range)); | 596 EXPECT_EQ(caret_range, gfx::Range(actual_range)); |
| 597 | 597 |
| 598 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 598 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 599 gfx::Range(0, 1).ToNSRange(), | 599 gfx::Range(0, 1).ToNSRange(), |
| 600 &rect, | 600 &rect, |
| 601 &actual_range)); | 601 &actual_range)); |
| 602 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 602 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 603 gfx::Range(1, 1).ToNSRange(), | 603 gfx::Range(1, 1).ToNSRange(), |
| 604 &rect, | 604 &rect, |
| 605 &actual_range)); | 605 &actual_range)); |
| 606 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 606 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 607 gfx::Range(2, 3).ToNSRange(), | 607 gfx::Range(2, 3).ToNSRange(), |
| 608 &rect, | 608 &rect, |
| 609 &actual_range)); | 609 &actual_range)); |
| 610 | 610 |
| 611 // Caret moved. | 611 // Caret moved. |
| 612 caret_rect = gfx::Rect(20, 11, 0, 10); | 612 caret_rect = gfx::Rect(20, 11, 0, 10); |
| 613 caret_range = gfx::Range(1, 1); | 613 caret_range = gfx::Range(1, 1); |
| 614 params.anchor_rect = params.focus_rect = caret_rect; | 614 params.anchor_rect = params.focus_rect = caret_rect; |
| 615 rwhv_mac_->SelectionChanged(kDummyString, kDummyOffset, caret_range); | 615 rwhv_mac_->SelectionChanged(kDummyString, kDummyOffset, caret_range, true); |
| 616 rwhv_mac_->SelectionBoundsChanged(params); | 616 rwhv_mac_->SelectionBoundsChanged(params); |
| 617 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 617 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 618 caret_range.ToNSRange(), | 618 caret_range.ToNSRange(), |
| 619 &rect, | 619 &rect, |
| 620 &actual_range)); | 620 &actual_range)); |
| 621 EXPECT_EQ(caret_rect, gfx::Rect(NSRectToCGRect(rect))); | 621 EXPECT_EQ(caret_rect, gfx::Rect(NSRectToCGRect(rect))); |
| 622 EXPECT_EQ(caret_range, gfx::Range(actual_range)); | 622 EXPECT_EQ(caret_range, gfx::Range(actual_range)); |
| 623 | 623 |
| 624 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 624 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 625 gfx::Range(0, 0).ToNSRange(), | 625 gfx::Range(0, 0).ToNSRange(), |
| 626 &rect, | 626 &rect, |
| 627 &actual_range)); | 627 &actual_range)); |
| 628 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 628 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 629 gfx::Range(1, 2).ToNSRange(), | 629 gfx::Range(1, 2).ToNSRange(), |
| 630 &rect, | 630 &rect, |
| 631 &actual_range)); | 631 &actual_range)); |
| 632 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 632 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 633 gfx::Range(2, 3).ToNSRange(), | 633 gfx::Range(2, 3).ToNSRange(), |
| 634 &rect, | 634 &rect, |
| 635 &actual_range)); | 635 &actual_range)); |
| 636 | 636 |
| 637 // No caret. | 637 // No caret. |
| 638 caret_range = gfx::Range(1, 2); | 638 caret_range = gfx::Range(1, 2); |
| 639 rwhv_mac_->SelectionChanged(kDummyString, kDummyOffset, caret_range); | 639 rwhv_mac_->SelectionChanged(kDummyString, kDummyOffset, caret_range, true); |
| 640 params.anchor_rect = caret_rect; | 640 params.anchor_rect = caret_rect; |
| 641 params.focus_rect = gfx::Rect(30, 11, 0, 10); | 641 params.focus_rect = gfx::Rect(30, 11, 0, 10); |
| 642 rwhv_mac_->SelectionBoundsChanged(params); | 642 rwhv_mac_->SelectionBoundsChanged(params); |
| 643 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 643 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 644 gfx::Range(0, 0).ToNSRange(), | 644 gfx::Range(0, 0).ToNSRange(), |
| 645 &rect, | 645 &rect, |
| 646 &actual_range)); | 646 &actual_range)); |
| 647 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 647 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 648 gfx::Range(0, 1).ToNSRange(), | 648 gfx::Range(0, 1).ToNSRange(), |
| 649 &rect, | 649 &rect, |
| (...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1690 } | 1690 } |
| 1691 | 1691 |
| 1692 // This test verifies that |selected_text_| is updated accordingly with | 1692 // This test verifies that |selected_text_| is updated accordingly with |
| 1693 // different variations of RWHVMac::SelectChanged updates. | 1693 // different variations of RWHVMac::SelectChanged updates. |
| 1694 TEST_F(RenderWidgetHostViewMacTest, SelectedText) { | 1694 TEST_F(RenderWidgetHostViewMacTest, SelectedText) { |
| 1695 base::string16 sample_text; | 1695 base::string16 sample_text; |
| 1696 base::UTF8ToUTF16("hello world!", 12, &sample_text); | 1696 base::UTF8ToUTF16("hello world!", 12, &sample_text); |
| 1697 gfx::Range range(6, 11); | 1697 gfx::Range range(6, 11); |
| 1698 | 1698 |
| 1699 // Send a valid selection for the word 'World'. | 1699 // Send a valid selection for the word 'World'. |
| 1700 rwhv_mac_->SelectionChanged(sample_text, 0U, range); | 1700 rwhv_mac_->SelectionChanged(sample_text, 0U, range, true); |
| 1701 EXPECT_EQ("world", selected_text()); | 1701 EXPECT_EQ("world", selected_text()); |
| 1702 | 1702 |
| 1703 // Make the range cover some of the text and extend more. | 1703 // Make the range cover some of the text and extend more. |
| 1704 range.set_end(100); | 1704 range.set_end(100); |
| 1705 rwhv_mac_->SelectionChanged(sample_text, 0U, range); | 1705 rwhv_mac_->SelectionChanged(sample_text, 0U, range, true); |
| 1706 EXPECT_EQ("world!", selected_text()); | 1706 EXPECT_EQ("world!", selected_text()); |
| 1707 | 1707 |
| 1708 // Finally, send an empty range. This should clear the selected text. | 1708 // Finally, send an empty range. This should clear the selected text. |
| 1709 range.set_start(100); | 1709 range.set_start(100); |
| 1710 rwhv_mac_->SelectionChanged(sample_text, 0U, range); | 1710 rwhv_mac_->SelectionChanged(sample_text, 0U, range, true); |
| 1711 EXPECT_EQ("", selected_text()); | 1711 EXPECT_EQ("", selected_text()); |
| 1712 } | 1712 } |
| 1713 | 1713 |
| 1714 // This class is used for IME-related unit tests which verify correctness of IME | 1714 // This class is used for IME-related unit tests which verify correctness of IME |
| 1715 // for pages with multiple RWHVs. | 1715 // for pages with multiple RWHVs. |
| 1716 class InputMethodMacTest : public RenderWidgetHostViewMacTest { | 1716 class InputMethodMacTest : public RenderWidgetHostViewMacTest { |
| 1717 public: | 1717 public: |
| 1718 InputMethodMacTest() {} | 1718 InputMethodMacTest() {} |
| 1719 ~InputMethodMacTest() override {} | 1719 ~InputMethodMacTest() override {} |
| 1720 | 1720 |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2034 // -performKeyEquivalent: now returns YES to prevent further propagation, and | 2034 // -performKeyEquivalent: now returns YES to prevent further propagation, and |
| 2035 // the event is sent to the renderer. | 2035 // the event is sent to the renderer. |
| 2036 EXPECT_TRUE([window performKeyEquivalent:key_down]); | 2036 EXPECT_TRUE([window performKeyEquivalent:key_down]); |
| 2037 EXPECT_EQ(2U, process_host->sink().message_count()); | 2037 EXPECT_EQ(2U, process_host->sink().message_count()); |
| 2038 EXPECT_EQ("RawKeyDown Char", GetInputMessageTypes(process_host)); | 2038 EXPECT_EQ("RawKeyDown Char", GetInputMessageTypes(process_host)); |
| 2039 | 2039 |
| 2040 rwhv_mac_->release_pepper_fullscreen_window_for_testing(); | 2040 rwhv_mac_->release_pepper_fullscreen_window_for_testing(); |
| 2041 } | 2041 } |
| 2042 | 2042 |
| 2043 } // namespace content | 2043 } // namespace content |
| OLD | NEW |