OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #import "ui/views/cocoa/bridged_native_widget.h" | 5 #import "ui/views/cocoa/bridged_native_widget.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #import "base/mac/foundation_util.h" | 9 #import "base/mac/foundation_util.h" |
10 #import "base/mac/mac_util.h" | 10 #import "base/mac/mac_util.h" |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 InstallTextField(test_string, ui::TEXT_INPUT_TYPE_TEXT); | 423 InstallTextField(test_string, ui::TEXT_INPUT_TYPE_TEXT); |
424 EXPECT_TRUE([ns_view_ inputContext]); | 424 EXPECT_TRUE([ns_view_ inputContext]); |
425 [ns_view_ setTextInputClient:nil]; | 425 [ns_view_ setTextInputClient:nil]; |
426 EXPECT_FALSE([ns_view_ inputContext]); | 426 EXPECT_FALSE([ns_view_ inputContext]); |
427 InstallTextField(test_string, ui::TEXT_INPUT_TYPE_NONE); | 427 InstallTextField(test_string, ui::TEXT_INPUT_TYPE_NONE); |
428 EXPECT_FALSE([ns_view_ inputContext]); | 428 EXPECT_FALSE([ns_view_ inputContext]); |
429 } | 429 } |
430 | 430 |
431 // Test getting complete string using text input protocol. | 431 // Test getting complete string using text input protocol. |
432 TEST_F(BridgedNativeWidgetTest, TextInput_GetCompleteString) { | 432 TEST_F(BridgedNativeWidgetTest, TextInput_GetCompleteString) { |
433 const std::string kTestString = "foo bar baz"; | 433 const std::string test_string = "foo bar baz"; |
434 InstallTextField(kTestString); | 434 InstallTextField(test_string); |
435 | 435 |
436 NSRange range = NSMakeRange(0, kTestString.size()); | 436 NSRange range = NSMakeRange(0, test_string.size()); |
437 NSRange actual_range; | 437 NSRange actual_range; |
438 NSAttributedString* text = | 438 NSAttributedString* text = |
439 [ns_view_ attributedSubstringForProposedRange:range | 439 [ns_view_ attributedSubstringForProposedRange:range |
440 actualRange:&actual_range]; | 440 actualRange:&actual_range]; |
441 EXPECT_EQ(kTestString, SysNSStringToUTF8([text string])); | 441 EXPECT_EQ(test_string, SysNSStringToUTF8([text string])); |
442 EXPECT_EQ_RANGE(range, actual_range); | 442 EXPECT_EQ_RANGE(range, actual_range); |
443 } | 443 } |
444 | 444 |
445 // Test getting middle substring using text input protocol. | 445 // Test getting middle substring using text input protocol. |
446 TEST_F(BridgedNativeWidgetTest, TextInput_GetMiddleSubstring) { | 446 TEST_F(BridgedNativeWidgetTest, TextInput_GetMiddleSubstring) { |
447 const std::string kTestString = "foo bar baz"; | 447 const std::string test_string = "foo bar baz"; |
448 InstallTextField(kTestString); | 448 InstallTextField(test_string); |
449 | 449 |
450 NSRange range = NSMakeRange(4, 3); | 450 NSRange range = NSMakeRange(4, 3); |
451 NSRange actual_range; | 451 NSRange actual_range; |
452 NSAttributedString* text = | 452 NSAttributedString* text = |
453 [ns_view_ attributedSubstringForProposedRange:range | 453 [ns_view_ attributedSubstringForProposedRange:range |
454 actualRange:&actual_range]; | 454 actualRange:&actual_range]; |
455 EXPECT_EQ("bar", SysNSStringToUTF8([text string])); | 455 EXPECT_EQ("bar", SysNSStringToUTF8([text string])); |
456 EXPECT_EQ_RANGE(range, actual_range); | 456 EXPECT_EQ_RANGE(range, actual_range); |
457 } | 457 } |
458 | 458 |
459 // Test getting ending substring using text input protocol. | 459 // Test getting ending substring using text input protocol. |
460 TEST_F(BridgedNativeWidgetTest, TextInput_GetEndingSubstring) { | 460 TEST_F(BridgedNativeWidgetTest, TextInput_GetEndingSubstring) { |
461 const std::string kTestString = "foo bar baz"; | 461 const std::string test_string = "foo bar baz"; |
462 InstallTextField(kTestString); | 462 InstallTextField(test_string); |
463 | 463 |
464 NSRange range = NSMakeRange(8, 100); | 464 NSRange range = NSMakeRange(8, 100); |
465 NSRange actual_range; | 465 NSRange actual_range; |
466 NSAttributedString* text = | 466 NSAttributedString* text = |
467 [ns_view_ attributedSubstringForProposedRange:range | 467 [ns_view_ attributedSubstringForProposedRange:range |
468 actualRange:&actual_range]; | 468 actualRange:&actual_range]; |
469 EXPECT_EQ("baz", SysNSStringToUTF8([text string])); | 469 EXPECT_EQ("baz", SysNSStringToUTF8([text string])); |
470 EXPECT_EQ(range.location, actual_range.location); | 470 EXPECT_EQ(range.location, actual_range.location); |
471 EXPECT_EQ(3U, actual_range.length); | 471 EXPECT_EQ(3U, actual_range.length); |
472 } | 472 } |
473 | 473 |
474 // Test getting empty substring using text input protocol. | 474 // Test getting empty substring using text input protocol. |
475 TEST_F(BridgedNativeWidgetTest, TextInput_GetEmptySubstring) { | 475 TEST_F(BridgedNativeWidgetTest, TextInput_GetEmptySubstring) { |
476 const std::string kTestString = "foo bar baz"; | 476 const std::string test_string = "foo bar baz"; |
477 InstallTextField(kTestString); | 477 InstallTextField(test_string); |
478 | 478 |
479 NSRange range = EmptyRange(); | 479 NSRange range = EmptyRange(); |
480 NSRange actual_range; | 480 NSRange actual_range; |
481 NSAttributedString* text = | 481 NSAttributedString* text = |
482 [ns_view_ attributedSubstringForProposedRange:range | 482 [ns_view_ attributedSubstringForProposedRange:range |
483 actualRange:&actual_range]; | 483 actualRange:&actual_range]; |
484 EXPECT_EQ("", SysNSStringToUTF8([text string])); | 484 EXPECT_EQ("", SysNSStringToUTF8([text string])); |
485 EXPECT_EQ_RANGE(range, actual_range); | 485 EXPECT_EQ_RANGE(range, actual_range); |
486 } | 486 } |
487 | 487 |
488 // Test inserting text using text input protocol. | 488 // Test inserting text using text input protocol. |
489 TEST_F(BridgedNativeWidgetTest, TextInput_InsertText) { | 489 TEST_F(BridgedNativeWidgetTest, TextInput_InsertText) { |
490 const std::string kTestString = "foo"; | 490 const std::string test_string = "foo"; |
491 InstallTextField(kTestString); | 491 InstallTextField(test_string); |
492 | 492 |
493 [ns_view_ insertText:SysUTF8ToNSString(kTestString) | 493 [ns_view_ insertText:SysUTF8ToNSString(test_string) |
494 replacementRange:EmptyRange()]; | 494 replacementRange:EmptyRange()]; |
495 gfx::Range range(0, kTestString.size()); | 495 gfx::Range range(0, test_string.size()); |
496 base::string16 text; | 496 base::string16 text; |
497 EXPECT_TRUE([ns_view_ textInputClient]->GetTextFromRange(range, &text)); | 497 EXPECT_TRUE([ns_view_ textInputClient]->GetTextFromRange(range, &text)); |
498 EXPECT_EQ(ASCIIToUTF16(kTestString), text); | 498 EXPECT_EQ(ASCIIToUTF16(test_string), text); |
499 } | 499 } |
500 | 500 |
501 // Test replacing text using text input protocol. | 501 // Test replacing text using text input protocol. |
502 TEST_F(BridgedNativeWidgetTest, TextInput_ReplaceText) { | 502 TEST_F(BridgedNativeWidgetTest, TextInput_ReplaceText) { |
503 const std::string kTestString = "foo bar"; | 503 const std::string test_string = "foo bar"; |
504 InstallTextField(kTestString); | 504 InstallTextField(test_string); |
505 | 505 |
506 [ns_view_ insertText:@"baz" replacementRange:NSMakeRange(4, 3)]; | 506 [ns_view_ insertText:@"baz" replacementRange:NSMakeRange(4, 3)]; |
507 EXPECT_EQ("foo baz", GetText()); | 507 EXPECT_EQ("foo baz", GetText()); |
508 } | 508 } |
509 | 509 |
510 // Test IME composition using text input protocol. | 510 // Test IME composition using text input protocol. |
511 TEST_F(BridgedNativeWidgetTest, TextInput_Compose) { | 511 TEST_F(BridgedNativeWidgetTest, TextInput_Compose) { |
512 const std::string kTestString = "foo "; | 512 const std::string test_string = "foo "; |
513 InstallTextField(kTestString); | 513 InstallTextField(test_string); |
514 | 514 |
515 EXPECT_FALSE([ns_view_ hasMarkedText]); | 515 EXPECT_FALSE([ns_view_ hasMarkedText]); |
516 EXPECT_EQ_RANGE(EmptyRange(), [ns_view_ markedRange]); | 516 EXPECT_EQ_RANGE(EmptyRange(), [ns_view_ markedRange]); |
517 | 517 |
518 // Start composition. | 518 // Start composition. |
519 NSString* compositionText = @"bar"; | 519 NSString* compositionText = @"bar"; |
520 NSUInteger compositionLength = [compositionText length]; | 520 NSUInteger compositionLength = [compositionText length]; |
521 [ns_view_ setMarkedText:compositionText | 521 [ns_view_ setMarkedText:compositionText |
522 selectedRange:NSMakeRange(0, 2) | 522 selectedRange:NSMakeRange(0, 2) |
523 replacementRange:EmptyRange()]; | 523 replacementRange:EmptyRange()]; |
524 EXPECT_TRUE([ns_view_ hasMarkedText]); | 524 EXPECT_TRUE([ns_view_ hasMarkedText]); |
525 EXPECT_EQ_RANGE(NSMakeRange(kTestString.size(), compositionLength), | 525 EXPECT_EQ_RANGE(NSMakeRange(test_string.size(), compositionLength), |
526 [ns_view_ markedRange]); | 526 [ns_view_ markedRange]); |
527 EXPECT_EQ_RANGE(NSMakeRange(kTestString.size(), 2), [ns_view_ selectedRange]); | 527 EXPECT_EQ_RANGE(NSMakeRange(test_string.size(), 2), [ns_view_ selectedRange]); |
528 | 528 |
529 // Confirm composition. | 529 // Confirm composition. |
530 [ns_view_ unmarkText]; | 530 [ns_view_ unmarkText]; |
531 EXPECT_FALSE([ns_view_ hasMarkedText]); | 531 EXPECT_FALSE([ns_view_ hasMarkedText]); |
532 EXPECT_EQ_RANGE(EmptyRange(), [ns_view_ markedRange]); | 532 EXPECT_EQ_RANGE(EmptyRange(), [ns_view_ markedRange]); |
533 EXPECT_EQ("foo bar", GetText()); | 533 EXPECT_EQ("foo bar", GetText()); |
534 EXPECT_EQ_RANGE(NSMakeRange(GetText().size(), 0), [ns_view_ selectedRange]); | 534 EXPECT_EQ_RANGE(NSMakeRange(GetText().size(), 0), [ns_view_ selectedRange]); |
535 } | 535 } |
536 | 536 |
537 // Test moving the caret left and right using text input protocol. | 537 // Test moving the caret left and right using text input protocol. |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 // Make sure not crashing by passing null pointer instead of actualRange. | 646 // Make sure not crashing by passing null pointer instead of actualRange. |
647 rect = [ns_view_ firstRectForCharacterRange:query_range actualRange:nullptr]; | 647 rect = [ns_view_ firstRectForCharacterRange:query_range actualRange:nullptr]; |
648 } | 648 } |
649 | 649 |
650 // Test firstRectForCharacterRange:actualRange for non-empty query ranges within | 650 // Test firstRectForCharacterRange:actualRange for non-empty query ranges within |
651 // the composition range. | 651 // the composition range. |
652 TEST_F(BridgedNativeWidgetTest, TextInput_FirstRectForCharacterRange) { | 652 TEST_F(BridgedNativeWidgetTest, TextInput_FirstRectForCharacterRange) { |
653 InstallTextField(""); | 653 InstallTextField(""); |
654 ui::TextInputClient* client = [ns_view_ textInputClient]; | 654 ui::TextInputClient* client = [ns_view_ textInputClient]; |
655 | 655 |
656 const base::string16 kTestString = base::ASCIIToUTF16("test_str"); | 656 const base::string16 test_string = base::ASCIIToUTF16("test_str"); |
657 const size_t kTextLength = 8; | 657 const size_t kTextLength = 8; |
658 SetCompositionText(client, kTestString, 1, nullptr); | 658 SetCompositionText(client, test_string, 1, nullptr); |
659 | 659 |
660 // Query bounds for the whole composition string. | 660 // Query bounds for the whole composition string. |
661 NSRange query_range = NSMakeRange(0, kTextLength); | 661 NSRange query_range = NSMakeRange(0, kTextLength); |
662 NSRange actual_range; | 662 NSRange actual_range; |
663 NSRect rect = [ns_view_ firstRectForCharacterRange:query_range | 663 NSRect rect = [ns_view_ firstRectForCharacterRange:query_range |
664 actualRange:&actual_range]; | 664 actualRange:&actual_range]; |
665 EXPECT_EQ(GetExpectedBoundsForRange(client, kTestString, query_range), | 665 EXPECT_EQ(GetExpectedBoundsForRange(client, test_string, query_range), |
666 gfx::ScreenRectFromNSRect(rect)); | 666 gfx::ScreenRectFromNSRect(rect)); |
667 EXPECT_EQ_RANGE(query_range, actual_range); | 667 EXPECT_EQ_RANGE(query_range, actual_range); |
668 | 668 |
669 // Query bounds for the substring "est_". | 669 // Query bounds for the substring "est_". |
670 query_range = NSMakeRange(1, 4); | 670 query_range = NSMakeRange(1, 4); |
671 rect = [ns_view_ firstRectForCharacterRange:query_range | 671 rect = [ns_view_ firstRectForCharacterRange:query_range |
672 actualRange:&actual_range]; | 672 actualRange:&actual_range]; |
673 EXPECT_EQ(GetExpectedBoundsForRange(client, kTestString, query_range), | 673 EXPECT_EQ(GetExpectedBoundsForRange(client, test_string, query_range), |
674 gfx::ScreenRectFromNSRect(rect)); | 674 gfx::ScreenRectFromNSRect(rect)); |
675 EXPECT_EQ_RANGE(query_range, actual_range); | 675 EXPECT_EQ_RANGE(query_range, actual_range); |
676 } | 676 } |
677 | 677 |
678 typedef BridgedNativeWidgetTestBase BridgedNativeWidgetSimulateFullscreenTest; | 678 typedef BridgedNativeWidgetTestBase BridgedNativeWidgetSimulateFullscreenTest; |
679 | 679 |
680 // Simulate the notifications that AppKit would send out if a fullscreen | 680 // Simulate the notifications that AppKit would send out if a fullscreen |
681 // operation begins, and then fails and must abort. This notification sequence | 681 // operation begins, and then fails and must abort. This notification sequence |
682 // was determined by posting delayed tasks to toggle fullscreen state and then | 682 // was determined by posting delayed tasks to toggle fullscreen state and then |
683 // mashing Ctrl+Left/Right to keep OSX in a transition between Spaces to cause | 683 // mashing Ctrl+Left/Right to keep OSX in a transition between Spaces to cause |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 [center postNotificationName:NSWindowDidExitFullScreenNotification | 746 [center postNotificationName:NSWindowDidExitFullScreenNotification |
747 object:window]; | 747 object:window]; |
748 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. | 748 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. |
749 EXPECT_FALSE(bridge()->target_fullscreen_state()); | 749 EXPECT_FALSE(bridge()->target_fullscreen_state()); |
750 | 750 |
751 widget_->CloseNow(); | 751 widget_->CloseNow(); |
752 } | 752 } |
753 | 753 |
754 } // namespace test | 754 } // namespace test |
755 } // namespace views | 755 } // namespace views |
OLD | NEW |