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

Side by Side Diff: ui/views/cocoa/bridged_native_widget_unittest.mm

Issue 2228833002: MacViews: Fix behavior of move and select commands when selection direction changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@use_text_commands
Patch Set: Add apple rdar in comment. Created 4 years, 4 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 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
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
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
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)
msw 2016/08/16 18:37:58 nit: curly braces
karandeepb 2016/08/17 04:37:23 Done.
559 test_strings.push_back(
560 base::WideToUTF16(L"\x0634\x0632 \x064A")); // RTL string.
553 561
554 for (const base::string16& test_string : test_strings) { 562 for (const base::string16& test_string : test_strings) {
555 for (NSString* selector_string in selectors) { 563 for (NSString* selector_string in selectors) {
556 SEL sel = NSSelectorFromString(selector_string); 564 SEL sel = NSSelectorFromString(selector_string);
557 const int len = test_string.length(); 565 const int len = test_string.length();
558 for (int i = 0; i <= len; i++) { 566 for (int i = 0; i <= len; i++) {
559 for (int j = 0; j <= len; j++) { 567 for (int j = 0; j <= len; j++) {
560 SCOPED_TRACE(base::StringPrintf( 568 SCOPED_TRACE(base::StringPrintf(
561 "Testing range [%d-%d] for case %s and selector %s\n", i, j, 569 "Testing range [%d-%d] for case %s and selector %s\n", i, j,
562 base::UTF16ToUTF8(test_string).c_str(), 570 base::UTF16ToUTF8(test_string).c_str(),
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 1109
1102 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteToEndOfParagraph) { 1110 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteToEndOfParagraph) {
1103 TestDeleteEnd(@selector(deleteToEndOfParagraph:)); 1111 TestDeleteEnd(@selector(deleteToEndOfParagraph:));
1104 } 1112 }
1105 1113
1106 // Test move commands against expectations set by |dummy_text_view_|. 1114 // Test move commands against expectations set by |dummy_text_view_|.
1107 TEST_F(BridgedNativeWidgetTest, TextInput_MoveEditingCommands) { 1115 TEST_F(BridgedNativeWidgetTest, TextInput_MoveEditingCommands) {
1108 TestEditingCommands(kMoveActions); 1116 TestEditingCommands(kMoveActions);
1109 } 1117 }
1110 1118
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_|. 1119 // Test move and select commands against expectations set by |dummy_text_view_|.
1114 TEST_F(BridgedNativeWidgetTest, 1120 TEST_F(BridgedNativeWidgetTest, TextInput_MoveAndSelectEditingCommands) {
msw 2016/08/16 18:37:58 Thanks for enabling this test for LTR!
1115 TextInput_MoveAndSelectEditingCommands_DISABLED) { 1121 // The behavior of NSTextView for RTL strings is buggy for some move and
1116 TestEditingCommands(kSelectActions); 1122 // select commands. Hence don't test against an RTL string. See
1123 // rdar://27863290.
msw 2016/08/16 18:37:58 q: I'm not familiar with rdar, but I found via cod
karandeepb 2016/08/17 04:37:22 OpenRadar is an external system where you can log
1124 TestEditingCommands(kSelectActions, TestCase::LTR_ONLY);
1117 } 1125 }
1118 1126
1119 // Test delete commands against expectations set by |dummy_text_view_|. 1127 // Test delete commands against expectations set by |dummy_text_view_|.
1120 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteCommands) { 1128 TEST_F(BridgedNativeWidgetTest, TextInput_DeleteCommands) {
1121 TestEditingCommands(kDeleteActions); 1129 TestEditingCommands(kDeleteActions);
1122 } 1130 }
1123 1131
1124 // Test that we don't crash during an action message even if the TextInputClient 1132 // Test that we don't crash during an action message even if the TextInputClient
1125 // is nil. Regression test for crbug.com/615745. 1133 // is nil. Regression test for crbug.com/615745.
1126 TEST_F(BridgedNativeWidgetTest, NilTextInputClient) { 1134 TEST_F(BridgedNativeWidgetTest, NilTextInputClient) {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 [center postNotificationName:NSWindowDidExitFullScreenNotification 1305 [center postNotificationName:NSWindowDidExitFullScreenNotification
1298 object:window]; 1306 object:window];
1299 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. 1307 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change.
1300 EXPECT_FALSE(bridge()->target_fullscreen_state()); 1308 EXPECT_FALSE(bridge()->target_fullscreen_state());
1301 1309
1302 widget_->CloseNow(); 1310 widget_->CloseNow();
1303 } 1311 }
1304 1312
1305 } // namespace test 1313 } // namespace test
1306 } // namespace views 1314 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698