Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(551)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac_unittest.mm

Issue 2856093003: Update TextSelection for non-user initiated events (Closed)
Patch Set: Update TextSelection for non-user initiated events Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 TEST_F(RenderWidgetHostViewMacTest, GetFirstRectForCharacterRangeCaretCase) { 553 TEST_F(RenderWidgetHostViewMacTest, GetFirstRectForCharacterRangeCaretCase) {
554 const base::string16 kDummyString = base::UTF8ToUTF16("hogehoge"); 554 const base::string16 kDummyString = base::UTF8ToUTF16("hogehoge");
555 const size_t kDummyOffset = 0; 555 const size_t kDummyOffset = 0;
556 556
557 gfx::Rect caret_rect(10, 11, 0, 10); 557 gfx::Rect caret_rect(10, 11, 0, 10);
558 gfx::Range caret_range(0, 0); 558 gfx::Range caret_range(0, 0);
559 ViewHostMsg_SelectionBounds_Params params; 559 ViewHostMsg_SelectionBounds_Params params;
560 560
561 NSRect rect; 561 NSRect rect;
562 NSRange actual_range; 562 NSRange actual_range;
563 rwhv_mac_->SelectionChanged(kDummyString, kDummyOffset, caret_range); 563 rwhv_mac_->SelectionChanged(kDummyString, kDummyOffset, caret_range, true);
564 params.anchor_rect = params.focus_rect = caret_rect; 564 params.anchor_rect = params.focus_rect = caret_rect;
565 params.anchor_dir = params.focus_dir = blink::kWebTextDirectionLeftToRight; 565 params.anchor_dir = params.focus_dir = blink::kWebTextDirectionLeftToRight;
566 rwhv_mac_->SelectionBoundsChanged(params); 566 rwhv_mac_->SelectionBoundsChanged(params);
567 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange( 567 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(
568 caret_range.ToNSRange(), 568 caret_range.ToNSRange(),
569 &rect, 569 &rect,
570 &actual_range)); 570 &actual_range));
571 EXPECT_EQ(caret_rect, gfx::Rect(NSRectToCGRect(rect))); 571 EXPECT_EQ(caret_rect, gfx::Rect(NSRectToCGRect(rect)));
572 EXPECT_EQ(caret_range, gfx::Range(actual_range)); 572 EXPECT_EQ(caret_range, gfx::Range(actual_range));
573 573
574 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( 574 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange(
575 gfx::Range(0, 1).ToNSRange(), 575 gfx::Range(0, 1).ToNSRange(),
576 &rect, 576 &rect,
577 &actual_range)); 577 &actual_range));
578 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( 578 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange(
579 gfx::Range(1, 1).ToNSRange(), 579 gfx::Range(1, 1).ToNSRange(),
580 &rect, 580 &rect,
581 &actual_range)); 581 &actual_range));
582 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( 582 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange(
583 gfx::Range(2, 3).ToNSRange(), 583 gfx::Range(2, 3).ToNSRange(),
584 &rect, 584 &rect,
585 &actual_range)); 585 &actual_range));
586 586
587 // Caret moved. 587 // Caret moved.
588 caret_rect = gfx::Rect(20, 11, 0, 10); 588 caret_rect = gfx::Rect(20, 11, 0, 10);
589 caret_range = gfx::Range(1, 1); 589 caret_range = gfx::Range(1, 1);
590 params.anchor_rect = params.focus_rect = caret_rect; 590 params.anchor_rect = params.focus_rect = caret_rect;
591 rwhv_mac_->SelectionChanged(kDummyString, kDummyOffset, caret_range); 591 rwhv_mac_->SelectionChanged(kDummyString, kDummyOffset, caret_range, true);
592 rwhv_mac_->SelectionBoundsChanged(params); 592 rwhv_mac_->SelectionBoundsChanged(params);
593 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange( 593 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(
594 caret_range.ToNSRange(), 594 caret_range.ToNSRange(),
595 &rect, 595 &rect,
596 &actual_range)); 596 &actual_range));
597 EXPECT_EQ(caret_rect, gfx::Rect(NSRectToCGRect(rect))); 597 EXPECT_EQ(caret_rect, gfx::Rect(NSRectToCGRect(rect)));
598 EXPECT_EQ(caret_range, gfx::Range(actual_range)); 598 EXPECT_EQ(caret_range, gfx::Range(actual_range));
599 599
600 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( 600 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange(
601 gfx::Range(0, 0).ToNSRange(), 601 gfx::Range(0, 0).ToNSRange(),
602 &rect, 602 &rect,
603 &actual_range)); 603 &actual_range));
604 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( 604 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange(
605 gfx::Range(1, 2).ToNSRange(), 605 gfx::Range(1, 2).ToNSRange(),
606 &rect, 606 &rect,
607 &actual_range)); 607 &actual_range));
608 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( 608 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange(
609 gfx::Range(2, 3).ToNSRange(), 609 gfx::Range(2, 3).ToNSRange(),
610 &rect, 610 &rect,
611 &actual_range)); 611 &actual_range));
612 612
613 // No caret. 613 // No caret.
614 caret_range = gfx::Range(1, 2); 614 caret_range = gfx::Range(1, 2);
615 rwhv_mac_->SelectionChanged(kDummyString, kDummyOffset, caret_range); 615 rwhv_mac_->SelectionChanged(kDummyString, kDummyOffset, caret_range, true);
616 params.anchor_rect = caret_rect; 616 params.anchor_rect = caret_rect;
617 params.focus_rect = gfx::Rect(30, 11, 0, 10); 617 params.focus_rect = gfx::Rect(30, 11, 0, 10);
618 rwhv_mac_->SelectionBoundsChanged(params); 618 rwhv_mac_->SelectionBoundsChanged(params);
619 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( 619 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange(
620 gfx::Range(0, 0).ToNSRange(), 620 gfx::Range(0, 0).ToNSRange(),
621 &rect, 621 &rect,
622 &actual_range)); 622 &actual_range));
623 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( 623 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange(
624 gfx::Range(0, 1).ToNSRange(), 624 gfx::Range(0, 1).ToNSRange(),
625 &rect, 625 &rect,
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after
1492 } 1492 }
1493 1493
1494 // This test verifies that |selected_text_| is updated accordingly with 1494 // This test verifies that |selected_text_| is updated accordingly with
1495 // different variations of RWHVMac::SelectChanged updates. 1495 // different variations of RWHVMac::SelectChanged updates.
1496 TEST_F(RenderWidgetHostViewMacTest, SelectedText) { 1496 TEST_F(RenderWidgetHostViewMacTest, SelectedText) {
1497 base::string16 sample_text; 1497 base::string16 sample_text;
1498 base::UTF8ToUTF16("hello world!", 12, &sample_text); 1498 base::UTF8ToUTF16("hello world!", 12, &sample_text);
1499 gfx::Range range(6, 11); 1499 gfx::Range range(6, 11);
1500 1500
1501 // Send a valid selection for the word 'World'. 1501 // Send a valid selection for the word 'World'.
1502 rwhv_mac_->SelectionChanged(sample_text, 0U, range); 1502 rwhv_mac_->SelectionChanged(sample_text, 0U, range, true);
1503 EXPECT_EQ("world", selected_text()); 1503 EXPECT_EQ("world", selected_text());
1504 1504
1505 // Make the range cover some of the text and extend more. 1505 // Make the range cover some of the text and extend more.
1506 range.set_end(100); 1506 range.set_end(100);
1507 rwhv_mac_->SelectionChanged(sample_text, 0U, range); 1507 rwhv_mac_->SelectionChanged(sample_text, 0U, range, true);
1508 EXPECT_EQ("world!", selected_text()); 1508 EXPECT_EQ("world!", selected_text());
1509 1509
1510 // Finally, send an empty range. This should clear the selected text. 1510 // Finally, send an empty range. This should clear the selected text.
1511 range.set_start(100); 1511 range.set_start(100);
1512 rwhv_mac_->SelectionChanged(sample_text, 0U, range); 1512 rwhv_mac_->SelectionChanged(sample_text, 0U, range, true);
1513 EXPECT_EQ("", selected_text()); 1513 EXPECT_EQ("", selected_text());
1514 } 1514 }
1515 1515
1516 // This class is used for IME-related unit tests which verify correctness of IME 1516 // This class is used for IME-related unit tests which verify correctness of IME
1517 // for pages with multiple RWHVs. 1517 // for pages with multiple RWHVs.
1518 class InputMethodMacTest : public RenderWidgetHostViewMacTest { 1518 class InputMethodMacTest : public RenderWidgetHostViewMacTest {
1519 public: 1519 public:
1520 InputMethodMacTest() {} 1520 InputMethodMacTest() {}
1521 ~InputMethodMacTest() override {} 1521 ~InputMethodMacTest() override {}
1522 1522
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
1836 // -performKeyEquivalent: now returns YES to prevent further propagation, and 1836 // -performKeyEquivalent: now returns YES to prevent further propagation, and
1837 // the event is sent to the renderer. 1837 // the event is sent to the renderer.
1838 EXPECT_TRUE([window performKeyEquivalent:key_down]); 1838 EXPECT_TRUE([window performKeyEquivalent:key_down]);
1839 EXPECT_EQ(2U, process_host->sink().message_count()); 1839 EXPECT_EQ(2U, process_host->sink().message_count());
1840 EXPECT_EQ("RawKeyDown Char", GetInputMessageTypes(process_host)); 1840 EXPECT_EQ("RawKeyDown Char", GetInputMessageTypes(process_host));
1841 1841
1842 rwhv_mac_->release_pepper_fullscreen_window_for_testing(); 1842 rwhv_mac_->release_pepper_fullscreen_window_for_testing();
1843 } 1843 }
1844 1844
1845 } // namespace content 1845 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_base.cc ('k') | content/browser/renderer_host/text_input_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698