Chromium Code Reviews| 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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 // Test delete to end of line or paragraph based on |sel|. |sel| can be | 321 // Test delete to end of line or paragraph based on |sel|. |sel| can be |
| 322 // either deleteToEndOfLine: or deleteToEndOfParagraph:. | 322 // either deleteToEndOfLine: or deleteToEndOfParagraph:. |
| 323 void TestDeleteEnd(SEL sel); | 323 void TestDeleteEnd(SEL sel); |
| 324 | 324 |
| 325 // Test editing commands in |selectors| against the expectations set by | 325 // Test editing commands in |selectors| against the expectations set by |
| 326 // |dummy_text_view_|. This is done by selecting every substring within a set | 326 // |dummy_text_view_|. This is done by selecting every substring within a set |
| 327 // of test strings (both RTL and non-RTL) and performing every selector on | 327 // of test strings (both RTL and non-RTL) and performing every selector on |
| 328 // both the NSTextView and the BridgedContentView hosting a focused | 328 // both the NSTextView and the BridgedContentView hosting a focused |
| 329 // views::TextField to ensure the resulting text and selection ranges match. | 329 // views::TextField to ensure the resulting text and selection ranges match. |
| 330 // |selectors| is an NSArray of NSStrings. | 330 // |selectors| is an NSArray of NSStrings. |
| 331 void TestEditingCommands(NSArray* selectors); | 331 void TestEditingCommands(NSArray* selectors, bool test_rtl = true); |
|
tapted
2016/08/11 03:44:08
nit(optional): bool arguments with a default can b
karandeepb
2016/08/16 10:24:52
Done.
| |
| 332 | 332 |
| 333 std::unique_ptr<views::View> view_; | 333 std::unique_ptr<views::View> view_; |
| 334 | 334 |
| 335 // Weak. Owned by bridge(). | 335 // Weak. Owned by bridge(). |
| 336 BridgedContentView* ns_view_; | 336 BridgedContentView* ns_view_; |
| 337 | 337 |
| 338 // An NSTextView which helps set the expectations for our tests. | 338 // An NSTextView which helps set the expectations for our tests. |
| 339 base::scoped_nsobject<NSTextView> dummy_text_view_; | 339 base::scoped_nsobject<NSTextView> dummy_text_view_; |
| 340 | 340 |
| 341 base::MessageLoopForUI message_loop_; | 341 base::MessageLoopForUI message_loop_; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(), | 530 EXPECT_EQ_RANGE_3(NSMakeRange(0, 0), GetExpectedSelectionRange(), |
| 531 GetActualSelectionRange()); | 531 GetActualSelectionRange()); |
| 532 | 532 |
| 533 // Verify yanking inserts the deleted text. | 533 // Verify yanking inserts the deleted text. |
| 534 PerformCommand(@selector(yank:)); | 534 PerformCommand(@selector(yank:)); |
| 535 EXPECT_NSEQ_3(@"foo bar", GetExpectedText(), GetActualText()); | 535 EXPECT_NSEQ_3(@"foo bar", GetExpectedText(), GetActualText()); |
| 536 EXPECT_EQ_RANGE_3(NSMakeRange(4, 0), GetExpectedSelectionRange(), | 536 EXPECT_EQ_RANGE_3(NSMakeRange(4, 0), GetExpectedSelectionRange(), |
| 537 GetActualSelectionRange()); | 537 GetActualSelectionRange()); |
| 538 } | 538 } |
| 539 | 539 |
| 540 void BridgedNativeWidgetTest::TestEditingCommands(NSArray* selectors) { | 540 void BridgedNativeWidgetTest::TestEditingCommands(NSArray* selectors, |
| 541 const base::string16 test_strings[] = { | 541 bool test_rtl) { |
| 542 base::WideToUTF16(L"ab c"), | 542 std::vector<base::string16> test_strings; |
| 543 base::WideToUTF16(L"\x0634\x0632 \x064A") // RTL string. | 543 test_strings.push_back(base::WideToUTF16(L"ab c")); |
| 544 }; | 544 if (test_rtl) |
| 545 test_strings.push_back(base::WideToUTF16(L"\x0634\x0632 \x064A")); | |
| 545 | 546 |
| 546 for (const base::string16& test_string : test_strings) { | 547 for (const base::string16& test_string : test_strings) { |
| 547 for (NSString* selector_string in selectors) { | 548 for (NSString* selector_string in selectors) { |
| 548 SEL sel = NSSelectorFromString(selector_string); | 549 SEL sel = NSSelectorFromString(selector_string); |
| 549 const int len = test_string.length(); | 550 const int len = test_string.length(); |
| 550 for (int i = 0; i <= len; i++) { | 551 for (int i = 0; i <= len; i++) { |
| 551 for (int j = 0; j <= len; j++) { | 552 for (int j = 0; j <= len; j++) { |
| 552 SCOPED_TRACE(base::StringPrintf( | 553 SCOPED_TRACE(base::StringPrintf( |
| 553 "Testing range [%d-%d] for case %s and selector %s\n", i, j, | 554 "Testing range [%d-%d] for case %s and selector %s\n", i, j, |
| 554 base::UTF16ToUTF8(test_string).c_str(), | 555 base::UTF16ToUTF8(test_string).c_str(), |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1093 | 1094 |
| 1094 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteToEndOfParagraph) { | 1095 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteToEndOfParagraph) { |
| 1095 TestDeleteEnd(@selector(deleteToEndOfParagraph:)); | 1096 TestDeleteEnd(@selector(deleteToEndOfParagraph:)); |
| 1096 } | 1097 } |
| 1097 | 1098 |
| 1098 // Test move commands against expectations set by |dummy_text_view_|. | 1099 // Test move commands against expectations set by |dummy_text_view_|. |
| 1099 TEST_F(BridgedNativeWidgetTest, TextInput_MoveEditingCommands) { | 1100 TEST_F(BridgedNativeWidgetTest, TextInput_MoveEditingCommands) { |
| 1100 TestEditingCommands(kMoveActions); | 1101 TestEditingCommands(kMoveActions); |
| 1101 } | 1102 } |
| 1102 | 1103 |
| 1103 // Todo(karandeepb): Enable this test once the behavior of all move and select | |
| 1104 // commands are fixed. | |
| 1105 // Test move and select commands against expectations set by |dummy_text_view_|. | 1104 // Test move and select commands against expectations set by |dummy_text_view_|. |
| 1106 TEST_F(BridgedNativeWidgetTest, | 1105 TEST_F(BridgedNativeWidgetTest, TextInput_MoveAndSelectEditingCommands) { |
| 1107 TextInput_MoveAndSelectEditingCommands_DISABLED) { | 1106 // The behavior of NSTextView for RTL strings is buggy for some move and |
| 1108 TestEditingCommands(kSelectActions); | 1107 // select commands. Hence don't test against an RTL string. |
| 1108 TestEditingCommands(kSelectActions, false); | |
| 1109 } | 1109 } |
| 1110 | 1110 |
| 1111 // Test delete commands against expectations set by |dummy_text_view_|. | 1111 // Test delete commands against expectations set by |dummy_text_view_|. |
| 1112 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteCommands) { | 1112 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteCommands) { |
| 1113 TestEditingCommands(kDeleteActions); | 1113 TestEditingCommands(kDeleteActions); |
| 1114 } | 1114 } |
| 1115 | 1115 |
| 1116 // Test that we don't crash during an action message even if the TextInputClient | 1116 // Test that we don't crash during an action message even if the TextInputClient |
| 1117 // is nil. Regression test for crbug.com/615745. | 1117 // is nil. Regression test for crbug.com/615745. |
| 1118 TEST_F(BridgedNativeWidgetTest, NilTextInputClient) { | 1118 TEST_F(BridgedNativeWidgetTest, NilTextInputClient) { |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1289 [center postNotificationName:NSWindowDidExitFullScreenNotification | 1289 [center postNotificationName:NSWindowDidExitFullScreenNotification |
| 1290 object:window]; | 1290 object:window]; |
| 1291 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. | 1291 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. |
| 1292 EXPECT_FALSE(bridge()->target_fullscreen_state()); | 1292 EXPECT_FALSE(bridge()->target_fullscreen_state()); |
| 1293 | 1293 |
| 1294 widget_->CloseNow(); | 1294 widget_->CloseNow(); |
| 1295 } | 1295 } |
| 1296 | 1296 |
| 1297 } // namespace test | 1297 } // namespace test |
| 1298 } // namespace views | 1298 } // namespace views |
| OLD | NEW |