| 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 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 #define EXPECT_EQ_RANGE_3(expected_literal, expected_cocoa, actual_views) \ | 54 #define EXPECT_EQ_RANGE_3(expected_literal, expected_cocoa, actual_views) \ |
| 55 EXPECT_EQ_RANGE(expected_literal, actual_views); \ | 55 EXPECT_EQ_RANGE(expected_literal, actual_views); \ |
| 56 EXPECT_EQ_RANGE(expected_cocoa, actual_views); | 56 EXPECT_EQ_RANGE(expected_cocoa, actual_views); |
| 57 | 57 |
| 58 #define EXPECT_EQ_3(expected_literal, expected_cocoa, actual_views) \ | 58 #define EXPECT_EQ_3(expected_literal, expected_cocoa, actual_views) \ |
| 59 EXPECT_EQ(expected_literal, actual_views); \ | 59 EXPECT_EQ(expected_literal, actual_views); \ |
| 60 EXPECT_EQ(expected_cocoa, actual_views); | 60 EXPECT_EQ(expected_cocoa, actual_views); |
| 61 | 61 |
| 62 namespace { | 62 namespace { |
| 63 | 63 |
| 64 enum class TestCase { |
| 65 ALL, // Test all strings. |
| 66 LTR_ONLY, // Only test Left To Right strings. |
| 67 }; |
| 68 |
| 64 // Implemented NSResponder action messages for use in tests. | 69 // Implemented NSResponder action messages for use in tests. |
| 65 NSArray* const kMoveActions = @[ | 70 NSArray* const kMoveActions = @[ |
| 66 @"moveForward:", | 71 @"moveForward:", |
| 67 @"moveRight:", | 72 @"moveRight:", |
| 68 @"moveBackward:", | 73 @"moveBackward:", |
| 69 @"moveLeft:", | 74 @"moveLeft:", |
| 70 @"moveUp:", | 75 @"moveUp:", |
| 71 @"moveDown:", | 76 @"moveDown:", |
| 72 @"moveWordForward:", | 77 @"moveWordForward:", |
| 73 @"moveWordBackward:", | 78 @"moveWordBackward:", |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 // Test delete to beginning of line or paragraph based on |sel|. |sel| can be | 330 // Test delete to beginning of line or paragraph based on |sel|. |sel| can be |
| 326 // either deleteToBeginningOfLine: or deleteToBeginningOfParagraph:. | 331 // either deleteToBeginningOfLine: or deleteToBeginningOfParagraph:. |
| 327 void TestDeleteBeginning(SEL sel); | 332 void TestDeleteBeginning(SEL sel); |
| 328 | 333 |
| 329 // Test delete to end of line or paragraph based on |sel|. |sel| can be | 334 // Test delete to end of line or paragraph based on |sel|. |sel| can be |
| 330 // either deleteToEndOfLine: or deleteToEndOfParagraph:. | 335 // either deleteToEndOfLine: or deleteToEndOfParagraph:. |
| 331 void TestDeleteEnd(SEL sel); | 336 void TestDeleteEnd(SEL sel); |
| 332 | 337 |
| 333 // Test editing commands in |selectors| against the expectations set by | 338 // Test editing commands in |selectors| against the expectations set by |
| 334 // |dummy_text_view_|. This is done by selecting every substring within a set | 339 // |dummy_text_view_|. This is done by selecting every substring within a set |
| 335 // of test strings (both RTL and non-RTL) and performing every selector on | 340 // of test strings (both RTL and non-RTL by default) and performing every |
| 336 // both the NSTextView and the BridgedContentView hosting a focused | 341 // selector on both the NSTextView and the BridgedContentView hosting a |
| 337 // views::TextField to ensure the resulting text and selection ranges match. | 342 // focused views::TextField to ensure the resulting text and selection ranges |
| 338 // |selectors| is an NSArray of NSStrings. | 343 // match. |selectors| is an NSArray of NSStrings. |cases| determines whether |
| 339 void TestEditingCommands(NSArray* selectors); | 344 // RTL strings are to be tested. |
| 345 void TestEditingCommands(NSArray* selectors, TestCase cases = TestCase::ALL); |
| 340 | 346 |
| 341 std::unique_ptr<views::View> view_; | 347 std::unique_ptr<views::View> view_; |
| 342 | 348 |
| 343 // Weak. Owned by bridge(). | 349 // Weak. Owned by bridge(). |
| 344 BridgedContentView* ns_view_; | 350 BridgedContentView* ns_view_; |
| 345 | 351 |
| 346 // An NSTextView which helps set the expectations for our tests. | 352 // An NSTextView which helps set the expectations for our tests. |
| 347 base::scoped_nsobject<NSTextView> dummy_text_view_; | 353 base::scoped_nsobject<NSTextView> dummy_text_view_; |
| 348 | 354 |
| 349 base::MessageLoopForUI message_loop_; | 355 base::MessageLoopForUI message_loop_; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(), | 544 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(), |
| 539 GetActualSelectionRange()); | 545 GetActualSelectionRange()); |
| 540 | 546 |
| 541 // Verify yanking inserts the deleted text. | 547 // Verify yanking inserts the deleted text. |
| 542 PerformCommand(@selector(yank:)); | 548 PerformCommand(@selector(yank:)); |
| 543 EXPECT_NSEQ_3(@"foo bar", GetExpectedText(), GetActualText()); | 549 EXPECT_NSEQ_3(@"foo bar", GetExpectedText(), GetActualText()); |
| 544 EXPECT_EQ_RANGE_3(NSMakeRange(4, 0), GetExpectedSelectionRange(), | 550 EXPECT_EQ_RANGE_3(NSMakeRange(4, 0), GetExpectedSelectionRange(), |
| 545 GetActualSelectionRange()); | 551 GetActualSelectionRange()); |
| 546 } | 552 } |
| 547 | 553 |
| 548 void BridgedNativeWidgetTest::TestEditingCommands(NSArray* selectors) { | 554 void BridgedNativeWidgetTest::TestEditingCommands(NSArray* selectors, |
| 549 const base::string16 test_strings[] = { | 555 TestCase cases) { |
| 550 base::WideToUTF16(L"ab c"), | 556 std::vector<base::string16> test_strings; |
| 551 base::WideToUTF16(L"\x0634\x0632 \x064A") // RTL string. | 557 test_strings.push_back(base::WideToUTF16(L"ab c")); |
| 552 }; | 558 if (cases == TestCase::ALL) { |
| 559 test_strings.push_back( |
| 560 base::WideToUTF16(L"\x0634\x0632 \x064A")); // RTL string. |
| 561 } |
| 553 | 562 |
| 554 for (const base::string16& test_string : test_strings) { | 563 for (const base::string16& test_string : test_strings) { |
| 555 for (NSString* selector_string in selectors) { | 564 for (NSString* selector_string in selectors) { |
| 556 SEL sel = NSSelectorFromString(selector_string); | 565 SEL sel = NSSelectorFromString(selector_string); |
| 557 const int len = test_string.length(); | 566 const int len = test_string.length(); |
| 558 for (int i = 0; i <= len; i++) { | 567 for (int i = 0; i <= len; i++) { |
| 559 for (int j = 0; j <= len; j++) { | 568 for (int j = 0; j <= len; j++) { |
| 560 SCOPED_TRACE(base::StringPrintf( | 569 SCOPED_TRACE(base::StringPrintf( |
| 561 "Testing range [%d-%d] for case %s and selector %s\n", i, j, | 570 "Testing range [%d-%d] for case %s and selector %s\n", i, j, |
| 562 base::UTF16ToUTF8(test_string).c_str(), | 571 base::UTF16ToUTF8(test_string).c_str(), |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 | 1110 |
| 1102 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteToEndOfParagraph) { | 1111 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteToEndOfParagraph) { |
| 1103 TestDeleteEnd(@selector(deleteToEndOfParagraph:)); | 1112 TestDeleteEnd(@selector(deleteToEndOfParagraph:)); |
| 1104 } | 1113 } |
| 1105 | 1114 |
| 1106 // Test move commands against expectations set by |dummy_text_view_|. | 1115 // Test move commands against expectations set by |dummy_text_view_|. |
| 1107 TEST_F(BridgedNativeWidgetTest, TextInput_MoveEditingCommands) { | 1116 TEST_F(BridgedNativeWidgetTest, TextInput_MoveEditingCommands) { |
| 1108 TestEditingCommands(kMoveActions); | 1117 TestEditingCommands(kMoveActions); |
| 1109 } | 1118 } |
| 1110 | 1119 |
| 1111 // Todo(karandeepb): Enable this test once the behavior of all move and select | |
| 1112 // commands are fixed. | |
| 1113 // Test move and select commands against expectations set by |dummy_text_view_|. | 1120 // Test move and select commands against expectations set by |dummy_text_view_|. |
| 1114 TEST_F(BridgedNativeWidgetTest, | 1121 TEST_F(BridgedNativeWidgetTest, TextInput_MoveAndSelectEditingCommands) { |
| 1115 TextInput_MoveAndSelectEditingCommands_DISABLED) { | 1122 // The behavior of NSTextView for RTL strings is buggy for some move and |
| 1116 TestEditingCommands(kSelectActions); | 1123 // select commands. Hence don't test against an RTL string. See |
| 1124 // rdar://27863290. |
| 1125 TestEditingCommands(kSelectActions, TestCase::LTR_ONLY); |
| 1117 } | 1126 } |
| 1118 | 1127 |
| 1119 // Test delete commands against expectations set by |dummy_text_view_|. | 1128 // Test delete commands against expectations set by |dummy_text_view_|. |
| 1120 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteCommands) { | 1129 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteCommands) { |
| 1121 TestEditingCommands(kDeleteActions); | 1130 TestEditingCommands(kDeleteActions); |
| 1122 } | 1131 } |
| 1123 | 1132 |
| 1124 // Test that we don't crash during an action message even if the TextInputClient | 1133 // Test that we don't crash during an action message even if the TextInputClient |
| 1125 // is nil. Regression test for crbug.com/615745. | 1134 // is nil. Regression test for crbug.com/615745. |
| 1126 TEST_F(BridgedNativeWidgetTest, NilTextInputClient) { | 1135 TEST_F(BridgedNativeWidgetTest, NilTextInputClient) { |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1297 [center postNotificationName:NSWindowDidExitFullScreenNotification | 1306 [center postNotificationName:NSWindowDidExitFullScreenNotification |
| 1298 object:window]; | 1307 object:window]; |
| 1299 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. | 1308 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. |
| 1300 EXPECT_FALSE(bridge()->target_fullscreen_state()); | 1309 EXPECT_FALSE(bridge()->target_fullscreen_state()); |
| 1301 | 1310 |
| 1302 widget_->CloseNow(); | 1311 widget_->CloseNow(); |
| 1303 } | 1312 } |
| 1304 | 1313 |
| 1305 } // namespace test | 1314 } // namespace test |
| 1306 } // namespace views | 1315 } // namespace views |
| OLD | NEW |