OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 text_field_.AddIntListAttribute(AX_ATTR_CACHED_LINE_STARTS, | 146 text_field_.AddIntListAttribute(AX_ATTR_CACHED_LINE_STARTS, |
147 std::vector<int32_t>{0, 7}); | 147 std::vector<int32_t>{0, 7}); |
148 text_field_.child_ids.push_back(static_text1_.id); | 148 text_field_.child_ids.push_back(static_text1_.id); |
149 text_field_.child_ids.push_back(line_break_.id); | 149 text_field_.child_ids.push_back(line_break_.id); |
150 text_field_.child_ids.push_back(static_text2_.id); | 150 text_field_.child_ids.push_back(static_text2_.id); |
151 root_.child_ids.push_back(text_field_.id); | 151 root_.child_ids.push_back(text_field_.id); |
152 | 152 |
153 static_text1_.role = AX_ROLE_STATIC_TEXT; | 153 static_text1_.role = AX_ROLE_STATIC_TEXT; |
154 static_text1_.AddState(AX_STATE_EDITABLE); | 154 static_text1_.AddState(AX_STATE_EDITABLE); |
155 static_text1_.SetName("Line 1"); | 155 static_text1_.SetName("Line 1"); |
156 static_text1_.AddIntAttribute(AX_ATTR_NEXT_ON_LINE_ID, line_break_.id); | |
157 static_text1_.child_ids.push_back(inline_box1_.id); | 156 static_text1_.child_ids.push_back(inline_box1_.id); |
158 | 157 |
159 inline_box1_.role = AX_ROLE_INLINE_TEXT_BOX; | 158 inline_box1_.role = AX_ROLE_INLINE_TEXT_BOX; |
160 inline_box1_.AddState(AX_STATE_EDITABLE); | 159 inline_box1_.AddState(AX_STATE_EDITABLE); |
161 inline_box1_.SetName("Line 1"); | 160 inline_box1_.SetName("Line 1"); |
162 inline_box1_.AddIntListAttribute(AX_ATTR_WORD_STARTS, | 161 inline_box1_.AddIntListAttribute(AX_ATTR_WORD_STARTS, |
163 std::vector<int32_t>{0, 5}); | 162 std::vector<int32_t>{0, 5}); |
164 inline_box1_.AddIntListAttribute(AX_ATTR_WORD_ENDS, | 163 inline_box1_.AddIntListAttribute(AX_ATTR_WORD_ENDS, |
165 std::vector<int32_t>{4, 6}); | 164 std::vector<int32_t>{4, 6}); |
166 inline_box1_.AddIntAttribute(AX_ATTR_NEXT_ON_LINE_ID, line_break_.id); | |
167 | 165 |
168 line_break_.role = AX_ROLE_LINE_BREAK; | 166 line_break_.role = AX_ROLE_LINE_BREAK; |
169 line_break_.AddState(AX_STATE_EDITABLE); | 167 line_break_.AddState(AX_STATE_EDITABLE); |
170 line_break_.SetName("\n"); | 168 line_break_.SetName("\n"); |
171 line_break_.AddIntAttribute(AX_ATTR_PREVIOUS_ON_LINE_ID, inline_box1_.id); | 169 line_break_.AddIntAttribute(AX_ATTR_PREVIOUS_ON_LINE_ID, inline_box1_.id); |
172 | 170 |
173 static_text2_.role = AX_ROLE_STATIC_TEXT; | 171 static_text2_.role = AX_ROLE_STATIC_TEXT; |
174 static_text2_.AddState(AX_STATE_EDITABLE); | 172 static_text2_.AddState(AX_STATE_EDITABLE); |
175 static_text2_.SetName("Line 2"); | 173 static_text2_.SetName("Line 2"); |
176 static_text2_.child_ids.push_back(inline_box2_.id); | 174 static_text2_.child_ids.push_back(inline_box2_.id); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 ASSERT_NE(nullptr, text_position); | 355 ASSERT_NE(nullptr, text_position); |
358 EXPECT_FALSE(text_position->AtEndOfAnchor()); | 356 EXPECT_FALSE(text_position->AtEndOfAnchor()); |
359 | 357 |
360 text_position = AXNodePosition::CreateTextPosition( | 358 text_position = AXNodePosition::CreateTextPosition( |
361 tree_.data().tree_id, inline_box1_.id, 0 /* text_offset */, | 359 tree_.data().tree_id, inline_box1_.id, 0 /* text_offset */, |
362 AX_TEXT_AFFINITY_DOWNSTREAM); | 360 AX_TEXT_AFFINITY_DOWNSTREAM); |
363 ASSERT_NE(nullptr, text_position); | 361 ASSERT_NE(nullptr, text_position); |
364 EXPECT_FALSE(text_position->AtEndOfAnchor()); | 362 EXPECT_FALSE(text_position->AtEndOfAnchor()); |
365 } | 363 } |
366 | 364 |
| 365 TEST_F(AXPositionTest, AtStartOfLineWithTextPosition) { |
| 366 // An upstream affinity should not affect the outcome since there is no soft |
| 367 // line break. |
| 368 TestPositionType text_position = AXNodePosition::CreateTextPosition( |
| 369 tree_.data().tree_id, inline_box1_.id, 0 /* text_offset */, |
| 370 AX_TEXT_AFFINITY_UPSTREAM); |
| 371 ASSERT_NE(nullptr, text_position); |
| 372 EXPECT_TRUE(text_position->AtStartOfLine()); |
| 373 |
| 374 text_position = AXNodePosition::CreateTextPosition( |
| 375 tree_.data().tree_id, inline_box1_.id, 1 /* text_offset */, |
| 376 AX_TEXT_AFFINITY_DOWNSTREAM); |
| 377 ASSERT_NE(nullptr, text_position); |
| 378 EXPECT_FALSE(text_position->AtStartOfLine()); |
| 379 |
| 380 text_position = AXNodePosition::CreateTextPosition( |
| 381 tree_.data().tree_id, line_break_.id, 0 /* text_offset */, |
| 382 AX_TEXT_AFFINITY_DOWNSTREAM); |
| 383 ASSERT_NE(nullptr, text_position); |
| 384 EXPECT_FALSE(text_position->AtStartOfLine()); |
| 385 |
| 386 // An "after text" position anchored at the line break should visually be the |
| 387 // same as a text position at the start of the next line. |
| 388 text_position = AXNodePosition::CreateTextPosition( |
| 389 tree_.data().tree_id, line_break_.id, 1 /* text_offset */, |
| 390 AX_TEXT_AFFINITY_DOWNSTREAM); |
| 391 ASSERT_NE(nullptr, text_position); |
| 392 EXPECT_TRUE(text_position->AtStartOfLine()); |
| 393 |
| 394 // An upstream affinity should not affect the outcome since there is no soft |
| 395 // line break. |
| 396 text_position = AXNodePosition::CreateTextPosition( |
| 397 tree_.data().tree_id, inline_box2_.id, 0 /* text_offset */, |
| 398 AX_TEXT_AFFINITY_UPSTREAM); |
| 399 ASSERT_NE(nullptr, text_position); |
| 400 EXPECT_TRUE(text_position->AtStartOfLine()); |
| 401 |
| 402 text_position = AXNodePosition::CreateTextPosition( |
| 403 tree_.data().tree_id, inline_box2_.id, 1 /* text_offset */, |
| 404 AX_TEXT_AFFINITY_DOWNSTREAM); |
| 405 ASSERT_NE(nullptr, text_position); |
| 406 EXPECT_FALSE(text_position->AtStartOfLine()); |
| 407 } |
| 408 |
| 409 TEST_F(AXPositionTest, AtEndOfLineWithTextPosition) { |
| 410 TestPositionType text_position = AXNodePosition::CreateTextPosition( |
| 411 tree_.data().tree_id, inline_box1_.id, 5 /* text_offset */, |
| 412 AX_TEXT_AFFINITY_DOWNSTREAM); |
| 413 ASSERT_NE(nullptr, text_position); |
| 414 EXPECT_FALSE(text_position->AtEndOfLine()); |
| 415 |
| 416 text_position = AXNodePosition::CreateTextPosition( |
| 417 tree_.data().tree_id, inline_box1_.id, 6 /* text_offset */, |
| 418 AX_TEXT_AFFINITY_DOWNSTREAM); |
| 419 ASSERT_NE(nullptr, text_position); |
| 420 EXPECT_TRUE(text_position->AtEndOfLine()); |
| 421 |
| 422 text_position = AXNodePosition::CreateTextPosition( |
| 423 tree_.data().tree_id, line_break_.id, 0 /* text_offset */, |
| 424 AX_TEXT_AFFINITY_DOWNSTREAM); |
| 425 ASSERT_NE(nullptr, text_position); |
| 426 EXPECT_FALSE(text_position->AtEndOfLine()); |
| 427 |
| 428 text_position = AXNodePosition::CreateTextPosition( |
| 429 tree_.data().tree_id, inline_box2_.id, 5 /* text_offset */, |
| 430 AX_TEXT_AFFINITY_DOWNSTREAM); |
| 431 ASSERT_NE(nullptr, text_position); |
| 432 EXPECT_FALSE(text_position->AtEndOfLine()); |
| 433 |
| 434 text_position = AXNodePosition::CreateTextPosition( |
| 435 tree_.data().tree_id, inline_box2_.id, 6 /* text_offset */, |
| 436 AX_TEXT_AFFINITY_DOWNSTREAM); |
| 437 ASSERT_NE(nullptr, text_position); |
| 438 EXPECT_TRUE(text_position->AtEndOfLine()); |
| 439 } |
| 440 |
367 TEST_F(AXPositionTest, LowestCommonAncestor) { | 441 TEST_F(AXPositionTest, LowestCommonAncestor) { |
368 TestPositionType null_position = AXNodePosition::CreateNullPosition(); | 442 TestPositionType null_position = AXNodePosition::CreateNullPosition(); |
369 ASSERT_NE(nullptr, null_position); | 443 ASSERT_NE(nullptr, null_position); |
370 // An "after children" position. | 444 // An "after children" position. |
371 TestPositionType root_position = AXNodePosition::CreateTreePosition( | 445 TestPositionType root_position = AXNodePosition::CreateTreePosition( |
372 tree_.data().tree_id, root_.id, 3 /* child_index */); | 446 tree_.data().tree_id, root_.id, 3 /* child_index */); |
373 ASSERT_NE(nullptr, root_position); | 447 ASSERT_NE(nullptr, root_position); |
374 // A "before text" position. | 448 // A "before text" position. |
375 TestPositionType button_position = AXNodePosition::CreateTreePosition( | 449 TestPositionType button_position = AXNodePosition::CreateTreePosition( |
376 tree_.data().tree_id, button_.id, AXNodePosition::BEFORE_TEXT); | 450 tree_.data().tree_id, button_.id, AXNodePosition::BEFORE_TEXT); |
(...skipping 1554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1931 AX_TEXT_AFFINITY_DOWNSTREAM); | 2005 AX_TEXT_AFFINITY_DOWNSTREAM); |
1932 AXRange<AXPosition<AXNodePosition, AXNode>> forward_range(start->Clone(), | 2006 AXRange<AXPosition<AXNodePosition, AXNode>> forward_range(start->Clone(), |
1933 end->Clone()); | 2007 end->Clone()); |
1934 EXPECT_EQ(most_text, forward_range.GetText()); | 2008 EXPECT_EQ(most_text, forward_range.GetText()); |
1935 AXRange<AXPosition<AXNodePosition, AXNode>> backward_range(std::move(end), | 2009 AXRange<AXPosition<AXNodePosition, AXNode>> backward_range(std::move(end), |
1936 std::move(start)); | 2010 std::move(start)); |
1937 EXPECT_EQ(most_text, backward_range.GetText()); | 2011 EXPECT_EQ(most_text, backward_range.GetText()); |
1938 } | 2012 } |
1939 | 2013 |
1940 } // namespace ui | 2014 } // namespace ui |
OLD | NEW |