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

Side by Side Diff: ui/accessibility/ax_node_position_unittest.cc

Issue 2934953004: De-templatize ui::AXPosition
Patch Set: rebase Created 3 years, 6 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
« no previous file with comments | « ui/accessibility/ax_node_position.cc ('k') | ui/accessibility/ax_position.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "ui/accessibility/ax_enums.h" 17 #include "ui/accessibility/ax_enums.h"
18 #include "ui/accessibility/ax_node.h" 18 #include "ui/accessibility/ax_node.h"
19 #include "ui/accessibility/ax_node_data.h" 19 #include "ui/accessibility/ax_node_data.h"
20 #include "ui/accessibility/ax_node_position.h" 20 #include "ui/accessibility/ax_node_position.h"
21 #include "ui/accessibility/ax_range.h" 21 #include "ui/accessibility/ax_range.h"
22 #include "ui/accessibility/ax_serializable_tree.h" 22 #include "ui/accessibility/ax_serializable_tree.h"
23 #include "ui/accessibility/ax_tree_serializer.h" 23 #include "ui/accessibility/ax_tree_serializer.h"
24 #include "ui/accessibility/ax_tree_update.h" 24 #include "ui/accessibility/ax_tree_update.h"
25 25
26 namespace ui { 26 namespace ui {
27 27
28 using TestPositionType = std::unique_ptr<AXPosition<AXNodePosition, AXNode>>; 28 using ConcretePositionType =
29 std::unique_ptr<AXPosition<AXNodePosition, AXNode>>;
30 using TestPositionType = std::unique_ptr<AXPositionBase>;
29 31
30 namespace { 32 namespace {
31 33
32 int32_t ROOT_ID = 1; 34 int32_t ROOT_ID = 1;
33 int32_t BUTTON_ID = 2; 35 int32_t BUTTON_ID = 2;
34 int32_t CHECK_BOX_ID = 3; 36 int32_t CHECK_BOX_ID = 3;
35 int32_t TEXT_FIELD_ID = 4; 37 int32_t TEXT_FIELD_ID = 4;
36 int32_t STATIC_TEXT1_ID = 5; 38 int32_t STATIC_TEXT1_ID = 5;
37 int32_t INLINE_BOX1_ID = 6; 39 int32_t INLINE_BOX1_ID = 6;
38 int32_t LINE_BREAK_ID = 7; 40 int32_t LINE_BREAK_ID = 7;
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 AXTreeUpdate update; 206 AXTreeUpdate update;
205 serializer.SerializeChanges(src_tree.root(), &update); 207 serializer.SerializeChanges(src_tree.root(), &update);
206 ASSERT_TRUE(tree_.Unserialize(update)); 208 ASSERT_TRUE(tree_.Unserialize(update));
207 AXNodePosition::SetTreeForTesting(&tree_); 209 AXNodePosition::SetTreeForTesting(&tree_);
208 } 210 }
209 211
210 void AXPositionTest::TearDown() { 212 void AXPositionTest::TearDown() {
211 AXNodePosition::SetTreeForTesting(nullptr); 213 AXNodePosition::SetTreeForTesting(nullptr);
212 } 214 }
213 215
216 TestPositionType AsBase(ConcretePositionType concrete) {
217 return base::WrapUnique<AXPositionBase>(concrete.release());
218 }
219
220 TestPositionType CreateNullPosition() {
221 return AsBase(AXNodePosition::CreateConcreteNullPosition());
222 }
223
224 TestPositionType CreateTreePosition(int tree_id,
225 int32_t anchor_id,
226 int child_index) {
227 return AsBase(AXNodePosition::CreateConcreteTreePosition(tree_id, anchor_id,
228 child_index));
229 }
230
231 TestPositionType CreateTextPosition(int tree_id,
232 int32_t anchor_id,
233 int text_offset,
234 AXTextAffinity affinity) {
235 return AsBase(AXNodePosition::CreateConcreteTextPosition(
236 tree_id, anchor_id, text_offset, affinity));
237 }
238
214 } // namespace 239 } // namespace
215 240
216 TEST_F(AXPositionTest, Clone) { 241 TEST_F(AXPositionTest, Clone) {
217 TestPositionType null_position = AXNodePosition::CreateNullPosition(); 242 TestPositionType null_position = CreateNullPosition();
218 ASSERT_NE(nullptr, null_position); 243 ASSERT_NE(nullptr, null_position);
219 TestPositionType copy_position = null_position->Clone(); 244 TestPositionType copy_position = null_position->Clone();
220 ASSERT_NE(nullptr, copy_position); 245 ASSERT_NE(nullptr, copy_position);
221 EXPECT_TRUE(copy_position->IsNullPosition()); 246 EXPECT_TRUE(copy_position->IsNullPosition());
222 247
223 TestPositionType tree_position = AXNodePosition::CreateTreePosition( 248 TestPositionType tree_position =
224 tree_.data().tree_id, root_.id, 1 /* child_index */); 249 CreateTreePosition(tree_.data().tree_id, root_.id, 1 /* child_index */);
225 ASSERT_NE(nullptr, tree_position); 250 ASSERT_NE(nullptr, tree_position);
226 copy_position = tree_position->Clone(); 251 copy_position = tree_position->Clone();
227 ASSERT_NE(nullptr, copy_position); 252 ASSERT_NE(nullptr, copy_position);
228 EXPECT_TRUE(copy_position->IsTreePosition()); 253 EXPECT_TRUE(copy_position->IsTreePosition());
229 EXPECT_EQ(root_.id, copy_position->anchor_id()); 254 EXPECT_EQ(root_.id, copy_position->anchor_id());
230 EXPECT_EQ(1, copy_position->child_index()); 255 EXPECT_EQ(1, copy_position->child_index());
231 EXPECT_EQ(AXNodePosition::INVALID_OFFSET, copy_position->text_offset()); 256 EXPECT_EQ(AXNodePosition::INVALID_OFFSET, copy_position->text_offset());
232 257
233 tree_position = AXNodePosition::CreateTreePosition( 258 tree_position = CreateTreePosition(tree_.data().tree_id, root_.id,
234 tree_.data().tree_id, root_.id, AXNodePosition::BEFORE_TEXT); 259 AXNodePosition::BEFORE_TEXT);
235 ASSERT_NE(nullptr, tree_position); 260 ASSERT_NE(nullptr, tree_position);
236 copy_position = tree_position->Clone(); 261 copy_position = tree_position->Clone();
237 ASSERT_NE(nullptr, copy_position); 262 ASSERT_NE(nullptr, copy_position);
238 EXPECT_TRUE(copy_position->IsTreePosition()); 263 EXPECT_TRUE(copy_position->IsTreePosition());
239 EXPECT_EQ(root_.id, copy_position->anchor_id()); 264 EXPECT_EQ(root_.id, copy_position->anchor_id());
240 EXPECT_EQ(AXNodePosition::BEFORE_TEXT, copy_position->child_index()); 265 EXPECT_EQ(AXNodePosition::BEFORE_TEXT, copy_position->child_index());
241 EXPECT_EQ(AXNodePosition::INVALID_OFFSET, copy_position->text_offset()); 266 EXPECT_EQ(AXNodePosition::INVALID_OFFSET, copy_position->text_offset());
242 267
243 TestPositionType text_position = AXNodePosition::CreateTextPosition( 268 TestPositionType text_position =
244 tree_.data().tree_id, text_field_.id, 1 /* text_offset */, 269 CreateTextPosition(tree_.data().tree_id, text_field_.id,
245 AX_TEXT_AFFINITY_UPSTREAM); 270 1 /* text_offset */, AX_TEXT_AFFINITY_UPSTREAM);
246 ASSERT_NE(nullptr, text_position); 271 ASSERT_NE(nullptr, text_position);
247 copy_position = text_position->Clone(); 272 copy_position = text_position->Clone();
248 ASSERT_NE(nullptr, copy_position); 273 ASSERT_NE(nullptr, copy_position);
249 EXPECT_TRUE(copy_position->IsTextPosition()); 274 EXPECT_TRUE(copy_position->IsTextPosition());
250 EXPECT_EQ(text_field_.id, copy_position->anchor_id()); 275 EXPECT_EQ(text_field_.id, copy_position->anchor_id());
251 EXPECT_EQ(1, copy_position->text_offset()); 276 EXPECT_EQ(1, copy_position->text_offset());
252 EXPECT_EQ(AX_TEXT_AFFINITY_UPSTREAM, copy_position->affinity()); 277 EXPECT_EQ(AX_TEXT_AFFINITY_UPSTREAM, copy_position->affinity());
253 278
254 text_position = AXNodePosition::CreateTextPosition( 279 text_position =
255 tree_.data().tree_id, text_field_.id, 1 /* text_offset */, 280 CreateTextPosition(tree_.data().tree_id, text_field_.id,
256 AX_TEXT_AFFINITY_DOWNSTREAM); 281 1 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
257 ASSERT_NE(nullptr, text_position); 282 ASSERT_NE(nullptr, text_position);
258 copy_position = text_position->Clone(); 283 copy_position = text_position->Clone();
259 ASSERT_NE(nullptr, copy_position); 284 ASSERT_NE(nullptr, copy_position);
260 EXPECT_TRUE(copy_position->IsTextPosition()); 285 EXPECT_TRUE(copy_position->IsTextPosition());
261 EXPECT_EQ(text_field_.id, copy_position->anchor_id()); 286 EXPECT_EQ(text_field_.id, copy_position->anchor_id());
262 EXPECT_EQ(1, copy_position->text_offset()); 287 EXPECT_EQ(1, copy_position->text_offset());
263 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, copy_position->affinity()); 288 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, copy_position->affinity());
264 EXPECT_EQ(AXNodePosition::INVALID_INDEX, copy_position->child_index()); 289 EXPECT_EQ(AXNodePosition::INVALID_INDEX, copy_position->child_index());
265 } 290 }
266 291
267 TEST_F(AXPositionTest, AtStartOfAnchorWithNullPosition) { 292 TEST_F(AXPositionTest, AtStartOfAnchorWithNullPosition) {
268 TestPositionType null_position = AXNodePosition::CreateNullPosition(); 293 TestPositionType null_position = CreateNullPosition();
269 ASSERT_NE(nullptr, null_position); 294 ASSERT_NE(nullptr, null_position);
270 EXPECT_FALSE(null_position->AtStartOfAnchor()); 295 EXPECT_FALSE(null_position->AtStartOfAnchor());
271 } 296 }
272 297
273 TEST_F(AXPositionTest, AtStartOfAnchorWithTreePosition) { 298 TEST_F(AXPositionTest, AtStartOfAnchorWithTreePosition) {
274 TestPositionType tree_position = AXNodePosition::CreateTreePosition( 299 TestPositionType tree_position =
275 tree_.data().tree_id, root_.id, 0 /* child_index */); 300 CreateTreePosition(tree_.data().tree_id, root_.id, 0 /* child_index */);
276 ASSERT_NE(nullptr, tree_position); 301 ASSERT_NE(nullptr, tree_position);
277 EXPECT_TRUE(tree_position->AtStartOfAnchor()); 302 EXPECT_TRUE(tree_position->AtStartOfAnchor());
278 303
279 tree_position = AXNodePosition::CreateTreePosition( 304 tree_position =
280 tree_.data().tree_id, root_.id, 1 /* child_index */); 305 CreateTreePosition(tree_.data().tree_id, root_.id, 1 /* child_index */);
281 ASSERT_NE(nullptr, tree_position); 306 ASSERT_NE(nullptr, tree_position);
282 EXPECT_FALSE(tree_position->AtStartOfAnchor()); 307 EXPECT_FALSE(tree_position->AtStartOfAnchor());
283 308
284 tree_position = AXNodePosition::CreateTreePosition( 309 tree_position =
285 tree_.data().tree_id, root_.id, 3 /* child_index */); 310 CreateTreePosition(tree_.data().tree_id, root_.id, 3 /* child_index */);
286 ASSERT_NE(nullptr, tree_position); 311 ASSERT_NE(nullptr, tree_position);
287 EXPECT_FALSE(tree_position->AtStartOfAnchor()); 312 EXPECT_FALSE(tree_position->AtStartOfAnchor());
288 313
289 // A "before text" position. 314 // A "before text" position.
290 tree_position = AXNodePosition::CreateTreePosition( 315 tree_position = CreateTreePosition(tree_.data().tree_id, inline_box1_.id,
291 tree_.data().tree_id, inline_box1_.id, AXNodePosition::BEFORE_TEXT); 316 AXNodePosition::BEFORE_TEXT);
292 ASSERT_NE(nullptr, tree_position); 317 ASSERT_NE(nullptr, tree_position);
293 EXPECT_TRUE(tree_position->AtStartOfAnchor()); 318 EXPECT_TRUE(tree_position->AtStartOfAnchor());
294 319
295 // An "after text" position. 320 // An "after text" position.
296 tree_position = AXNodePosition::CreateTreePosition( 321 tree_position = CreateTreePosition(tree_.data().tree_id, inline_box1_.id,
297 tree_.data().tree_id, inline_box1_.id, 0 /* child_index */); 322 0 /* child_index */);
298 ASSERT_NE(nullptr, tree_position); 323 ASSERT_NE(nullptr, tree_position);
299 EXPECT_FALSE(tree_position->AtStartOfAnchor()); 324 EXPECT_FALSE(tree_position->AtStartOfAnchor());
300 } 325 }
301 326
302 TEST_F(AXPositionTest, AtStartOfAnchorWithTextPosition) { 327 TEST_F(AXPositionTest, AtStartOfAnchorWithTextPosition) {
303 TestPositionType text_position = AXNodePosition::CreateTextPosition( 328 TestPositionType text_position =
304 tree_.data().tree_id, inline_box1_.id, 0 /* text_offset */, 329 CreateTextPosition(tree_.data().tree_id, inline_box1_.id,
305 AX_TEXT_AFFINITY_UPSTREAM); 330 0 /* text_offset */, AX_TEXT_AFFINITY_UPSTREAM);
306 ASSERT_NE(nullptr, text_position); 331 ASSERT_NE(nullptr, text_position);
307 EXPECT_TRUE(text_position->AtStartOfAnchor()); 332 EXPECT_TRUE(text_position->AtStartOfAnchor());
308 333
309 text_position = AXNodePosition::CreateTextPosition( 334 text_position =
310 tree_.data().tree_id, inline_box1_.id, 1 /* text_offset */, 335 CreateTextPosition(tree_.data().tree_id, inline_box1_.id,
311 AX_TEXT_AFFINITY_DOWNSTREAM); 336 1 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
312 ASSERT_NE(nullptr, text_position); 337 ASSERT_NE(nullptr, text_position);
313 EXPECT_FALSE(text_position->AtStartOfAnchor()); 338 EXPECT_FALSE(text_position->AtStartOfAnchor());
314 339
315 text_position = AXNodePosition::CreateTextPosition( 340 text_position =
316 tree_.data().tree_id, inline_box1_.id, 6 /* text_offset */, 341 CreateTextPosition(tree_.data().tree_id, inline_box1_.id,
317 AX_TEXT_AFFINITY_UPSTREAM); 342 6 /* text_offset */, AX_TEXT_AFFINITY_UPSTREAM);
318 ASSERT_NE(nullptr, text_position); 343 ASSERT_NE(nullptr, text_position);
319 EXPECT_FALSE(text_position->AtStartOfAnchor()); 344 EXPECT_FALSE(text_position->AtStartOfAnchor());
320 } 345 }
321 346
322 TEST_F(AXPositionTest, AtEndOfAnchorWithNullPosition) { 347 TEST_F(AXPositionTest, AtEndOfAnchorWithNullPosition) {
323 TestPositionType null_position = AXNodePosition::CreateNullPosition(); 348 TestPositionType null_position = CreateNullPosition();
324 ASSERT_NE(nullptr, null_position); 349 ASSERT_NE(nullptr, null_position);
325 EXPECT_FALSE(null_position->AtEndOfAnchor()); 350 EXPECT_FALSE(null_position->AtEndOfAnchor());
326 } 351 }
327 352
328 TEST_F(AXPositionTest, AtEndOfAnchorWithTreePosition) { 353 TEST_F(AXPositionTest, AtEndOfAnchorWithTreePosition) {
329 TestPositionType tree_position = AXNodePosition::CreateTreePosition( 354 TestPositionType tree_position =
330 tree_.data().tree_id, root_.id, 3 /* child_index */); 355 CreateTreePosition(tree_.data().tree_id, root_.id, 3 /* child_index */);
331 ASSERT_NE(nullptr, tree_position); 356 ASSERT_NE(nullptr, tree_position);
332 EXPECT_TRUE(tree_position->AtEndOfAnchor()); 357 EXPECT_TRUE(tree_position->AtEndOfAnchor());
333 358
334 tree_position = AXNodePosition::CreateTreePosition( 359 tree_position =
335 tree_.data().tree_id, root_.id, 2 /* child_index */); 360 CreateTreePosition(tree_.data().tree_id, root_.id, 2 /* child_index */);
336 ASSERT_NE(nullptr, tree_position); 361 ASSERT_NE(nullptr, tree_position);
337 EXPECT_FALSE(tree_position->AtEndOfAnchor()); 362 EXPECT_FALSE(tree_position->AtEndOfAnchor());
338 363
339 tree_position = AXNodePosition::CreateTreePosition( 364 tree_position =
340 tree_.data().tree_id, root_.id, 0 /* child_index */); 365 CreateTreePosition(tree_.data().tree_id, root_.id, 0 /* child_index */);
341 ASSERT_NE(nullptr, tree_position); 366 ASSERT_NE(nullptr, tree_position);
342 EXPECT_FALSE(tree_position->AtEndOfAnchor()); 367 EXPECT_FALSE(tree_position->AtEndOfAnchor());
343 } 368 }
344 369
345 TEST_F(AXPositionTest, AtEndOfAnchorWithTextPosition) { 370 TEST_F(AXPositionTest, AtEndOfAnchorWithTextPosition) {
346 TestPositionType text_position = AXNodePosition::CreateTextPosition( 371 TestPositionType text_position =
347 tree_.data().tree_id, inline_box1_.id, 6 /* text_offset */, 372 CreateTextPosition(tree_.data().tree_id, inline_box1_.id,
348 AX_TEXT_AFFINITY_DOWNSTREAM); 373 6 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
349 ASSERT_NE(nullptr, text_position); 374 ASSERT_NE(nullptr, text_position);
350 EXPECT_TRUE(text_position->AtEndOfAnchor()); 375 EXPECT_TRUE(text_position->AtEndOfAnchor());
351 376
352 text_position = AXNodePosition::CreateTextPosition( 377 text_position =
353 tree_.data().tree_id, inline_box1_.id, 5 /* text_offset */, 378 CreateTextPosition(tree_.data().tree_id, inline_box1_.id,
354 AX_TEXT_AFFINITY_UPSTREAM); 379 5 /* text_offset */, AX_TEXT_AFFINITY_UPSTREAM);
355 ASSERT_NE(nullptr, text_position); 380 ASSERT_NE(nullptr, text_position);
356 EXPECT_FALSE(text_position->AtEndOfAnchor()); 381 EXPECT_FALSE(text_position->AtEndOfAnchor());
357 382
358 text_position = AXNodePosition::CreateTextPosition( 383 text_position =
359 tree_.data().tree_id, inline_box1_.id, 0 /* text_offset */, 384 CreateTextPosition(tree_.data().tree_id, inline_box1_.id,
360 AX_TEXT_AFFINITY_DOWNSTREAM); 385 0 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
361 ASSERT_NE(nullptr, text_position); 386 ASSERT_NE(nullptr, text_position);
362 EXPECT_FALSE(text_position->AtEndOfAnchor()); 387 EXPECT_FALSE(text_position->AtEndOfAnchor());
363 } 388 }
364 389
365 TEST_F(AXPositionTest, AtStartOfLineWithTextPosition) { 390 TEST_F(AXPositionTest, AtStartOfLineWithTextPosition) {
366 // An upstream affinity should not affect the outcome since there is no soft 391 // An upstream affinity should not affect the outcome since there is no soft
367 // line break. 392 // line break.
368 TestPositionType text_position = AXNodePosition::CreateTextPosition( 393 TestPositionType text_position =
369 tree_.data().tree_id, inline_box1_.id, 0 /* text_offset */, 394 CreateTextPosition(tree_.data().tree_id, inline_box1_.id,
370 AX_TEXT_AFFINITY_UPSTREAM); 395 0 /* text_offset */, AX_TEXT_AFFINITY_UPSTREAM);
371 ASSERT_NE(nullptr, text_position); 396 ASSERT_NE(nullptr, text_position);
372 EXPECT_TRUE(text_position->AtStartOfLine()); 397 EXPECT_TRUE(text_position->AtStartOfLine());
373 398
374 text_position = AXNodePosition::CreateTextPosition( 399 text_position =
375 tree_.data().tree_id, inline_box1_.id, 1 /* text_offset */, 400 CreateTextPosition(tree_.data().tree_id, inline_box1_.id,
376 AX_TEXT_AFFINITY_DOWNSTREAM); 401 1 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
377 ASSERT_NE(nullptr, text_position); 402 ASSERT_NE(nullptr, text_position);
378 EXPECT_FALSE(text_position->AtStartOfLine()); 403 EXPECT_FALSE(text_position->AtStartOfLine());
379 404
380 text_position = AXNodePosition::CreateTextPosition( 405 text_position =
381 tree_.data().tree_id, line_break_.id, 0 /* text_offset */, 406 CreateTextPosition(tree_.data().tree_id, line_break_.id,
382 AX_TEXT_AFFINITY_DOWNSTREAM); 407 0 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
383 ASSERT_NE(nullptr, text_position); 408 ASSERT_NE(nullptr, text_position);
384 EXPECT_FALSE(text_position->AtStartOfLine()); 409 EXPECT_FALSE(text_position->AtStartOfLine());
385 410
386 // An "after text" position anchored at the line break should visually be the 411 // 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. 412 // same as a text position at the start of the next line.
388 text_position = AXNodePosition::CreateTextPosition( 413 text_position =
389 tree_.data().tree_id, line_break_.id, 1 /* text_offset */, 414 CreateTextPosition(tree_.data().tree_id, line_break_.id,
390 AX_TEXT_AFFINITY_DOWNSTREAM); 415 1 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
391 ASSERT_NE(nullptr, text_position); 416 ASSERT_NE(nullptr, text_position);
392 EXPECT_TRUE(text_position->AtStartOfLine()); 417 EXPECT_TRUE(text_position->AtStartOfLine());
393 418
394 // An upstream affinity should not affect the outcome since there is no soft 419 // An upstream affinity should not affect the outcome since there is no soft
395 // line break. 420 // line break.
396 text_position = AXNodePosition::CreateTextPosition( 421 text_position =
397 tree_.data().tree_id, inline_box2_.id, 0 /* text_offset */, 422 CreateTextPosition(tree_.data().tree_id, inline_box2_.id,
398 AX_TEXT_AFFINITY_UPSTREAM); 423 0 /* text_offset */, AX_TEXT_AFFINITY_UPSTREAM);
399 ASSERT_NE(nullptr, text_position); 424 ASSERT_NE(nullptr, text_position);
400 EXPECT_TRUE(text_position->AtStartOfLine()); 425 EXPECT_TRUE(text_position->AtStartOfLine());
401 426
402 text_position = AXNodePosition::CreateTextPosition( 427 text_position =
403 tree_.data().tree_id, inline_box2_.id, 1 /* text_offset */, 428 CreateTextPosition(tree_.data().tree_id, inline_box2_.id,
404 AX_TEXT_AFFINITY_DOWNSTREAM); 429 1 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
405 ASSERT_NE(nullptr, text_position); 430 ASSERT_NE(nullptr, text_position);
406 EXPECT_FALSE(text_position->AtStartOfLine()); 431 EXPECT_FALSE(text_position->AtStartOfLine());
407 } 432 }
408 433
409 TEST_F(AXPositionTest, AtEndOfLineWithTextPosition) { 434 TEST_F(AXPositionTest, AtEndOfLineWithTextPosition) {
410 TestPositionType text_position = AXNodePosition::CreateTextPosition( 435 TestPositionType text_position =
411 tree_.data().tree_id, inline_box1_.id, 5 /* text_offset */, 436 CreateTextPosition(tree_.data().tree_id, inline_box1_.id,
412 AX_TEXT_AFFINITY_DOWNSTREAM); 437 5 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
413 ASSERT_NE(nullptr, text_position); 438 ASSERT_NE(nullptr, text_position);
414 EXPECT_FALSE(text_position->AtEndOfLine()); 439 EXPECT_FALSE(text_position->AtEndOfLine());
415 440
416 text_position = AXNodePosition::CreateTextPosition( 441 text_position =
417 tree_.data().tree_id, inline_box1_.id, 6 /* text_offset */, 442 CreateTextPosition(tree_.data().tree_id, inline_box1_.id,
418 AX_TEXT_AFFINITY_DOWNSTREAM); 443 6 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
419 ASSERT_NE(nullptr, text_position); 444 ASSERT_NE(nullptr, text_position);
420 EXPECT_TRUE(text_position->AtEndOfLine()); 445 EXPECT_TRUE(text_position->AtEndOfLine());
421 446
422 text_position = AXNodePosition::CreateTextPosition( 447 text_position =
423 tree_.data().tree_id, line_break_.id, 0 /* text_offset */, 448 CreateTextPosition(tree_.data().tree_id, line_break_.id,
424 AX_TEXT_AFFINITY_DOWNSTREAM); 449 0 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
425 ASSERT_NE(nullptr, text_position); 450 ASSERT_NE(nullptr, text_position);
426 EXPECT_FALSE(text_position->AtEndOfLine()); 451 EXPECT_FALSE(text_position->AtEndOfLine());
427 452
428 text_position = AXNodePosition::CreateTextPosition( 453 text_position =
429 tree_.data().tree_id, inline_box2_.id, 5 /* text_offset */, 454 CreateTextPosition(tree_.data().tree_id, inline_box2_.id,
430 AX_TEXT_AFFINITY_DOWNSTREAM); 455 5 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
431 ASSERT_NE(nullptr, text_position); 456 ASSERT_NE(nullptr, text_position);
432 EXPECT_FALSE(text_position->AtEndOfLine()); 457 EXPECT_FALSE(text_position->AtEndOfLine());
433 458
434 text_position = AXNodePosition::CreateTextPosition( 459 text_position =
435 tree_.data().tree_id, inline_box2_.id, 6 /* text_offset */, 460 CreateTextPosition(tree_.data().tree_id, inline_box2_.id,
436 AX_TEXT_AFFINITY_DOWNSTREAM); 461 6 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
437 ASSERT_NE(nullptr, text_position); 462 ASSERT_NE(nullptr, text_position);
438 EXPECT_TRUE(text_position->AtEndOfLine()); 463 EXPECT_TRUE(text_position->AtEndOfLine());
439 } 464 }
440 465
441 TEST_F(AXPositionTest, LowestCommonAncestor) { 466 TEST_F(AXPositionTest, LowestCommonAncestor) {
442 TestPositionType null_position = AXNodePosition::CreateNullPosition(); 467 TestPositionType null_position = CreateNullPosition();
443 ASSERT_NE(nullptr, null_position); 468 ASSERT_NE(nullptr, null_position);
444 // An "after children" position. 469 // An "after children" position.
445 TestPositionType root_position = AXNodePosition::CreateTreePosition( 470 TestPositionType root_position =
446 tree_.data().tree_id, root_.id, 3 /* child_index */); 471 CreateTreePosition(tree_.data().tree_id, root_.id, 3 /* child_index */);
447 ASSERT_NE(nullptr, root_position); 472 ASSERT_NE(nullptr, root_position);
448 // A "before text" position. 473 // A "before text" position.
449 TestPositionType button_position = AXNodePosition::CreateTreePosition( 474 TestPositionType button_position = CreateTreePosition(
450 tree_.data().tree_id, button_.id, AXNodePosition::BEFORE_TEXT); 475 tree_.data().tree_id, button_.id, AXNodePosition::BEFORE_TEXT);
451 ASSERT_NE(nullptr, button_position); 476 ASSERT_NE(nullptr, button_position);
452 TestPositionType text_field_position = AXNodePosition::CreateTreePosition( 477 TestPositionType text_field_position = CreateTreePosition(
453 tree_.data().tree_id, text_field_.id, 2 /* child_index */); 478 tree_.data().tree_id, text_field_.id, 2 /* child_index */);
454 ASSERT_NE(nullptr, text_field_position); 479 ASSERT_NE(nullptr, text_field_position);
455 TestPositionType static_text1_position = AXNodePosition::CreateTreePosition( 480 TestPositionType static_text1_position = CreateTreePosition(
456 tree_.data().tree_id, static_text1_.id, 0 /* child_index */); 481 tree_.data().tree_id, static_text1_.id, 0 /* child_index */);
457 ASSERT_NE(nullptr, static_text1_position); 482 ASSERT_NE(nullptr, static_text1_position);
458 TestPositionType static_text2_position = AXNodePosition::CreateTreePosition( 483 TestPositionType static_text2_position = CreateTreePosition(
459 tree_.data().tree_id, static_text2_.id, 0 /* child_index */); 484 tree_.data().tree_id, static_text2_.id, 0 /* child_index */);
460 ASSERT_NE(nullptr, static_text2_position); 485 ASSERT_NE(nullptr, static_text2_position);
461 TestPositionType inline_box1_position = AXNodePosition::CreateTextPosition( 486 TestPositionType inline_box1_position =
462 tree_.data().tree_id, inline_box1_.id, 0 /* text_offset */, 487 CreateTextPosition(tree_.data().tree_id, inline_box1_.id,
463 AX_TEXT_AFFINITY_DOWNSTREAM); 488 0 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
464 ASSERT_NE(nullptr, inline_box1_position); 489 ASSERT_NE(nullptr, inline_box1_position);
465 TestPositionType inline_box2_position = AXNodePosition::CreateTextPosition( 490 TestPositionType inline_box2_position =
466 tree_.data().tree_id, inline_box2_.id, 0 /* text_offset */, 491 CreateTextPosition(tree_.data().tree_id, inline_box2_.id,
467 AX_TEXT_AFFINITY_UPSTREAM); 492 0 /* text_offset */, AX_TEXT_AFFINITY_UPSTREAM);
468 ASSERT_NE(nullptr, inline_box2_position); 493 ASSERT_NE(nullptr, inline_box2_position);
469 494
470 TestPositionType test_position = 495 TestPositionType test_position =
471 root_position->LowestCommonAncestor(*null_position.get()); 496 root_position->LowestCommonAncestor(*null_position.get());
472 EXPECT_NE(nullptr, test_position); 497 EXPECT_NE(nullptr, test_position);
473 EXPECT_TRUE(test_position->IsNullPosition()); 498 EXPECT_TRUE(test_position->IsNullPosition());
474 499
475 test_position = root_position->LowestCommonAncestor(*root_position.get()); 500 test_position = root_position->LowestCommonAncestor(*root_position.get());
476 EXPECT_NE(nullptr, test_position); 501 EXPECT_NE(nullptr, test_position);
477 EXPECT_TRUE(test_position->IsTreePosition()); 502 EXPECT_TRUE(test_position->IsTreePosition());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 test_position = 539 test_position =
515 inline_box2_position->LowestCommonAncestor(*inline_box1_position.get()); 540 inline_box2_position->LowestCommonAncestor(*inline_box1_position.get());
516 EXPECT_NE(nullptr, test_position); 541 EXPECT_NE(nullptr, test_position);
517 EXPECT_TRUE(test_position->IsTextPosition()); 542 EXPECT_TRUE(test_position->IsTextPosition());
518 EXPECT_EQ(text_field_.id, test_position->anchor_id()); 543 EXPECT_EQ(text_field_.id, test_position->anchor_id());
519 // The text offset should point to the second line. 544 // The text offset should point to the second line.
520 EXPECT_EQ(7, test_position->text_offset()); 545 EXPECT_EQ(7, test_position->text_offset());
521 } 546 }
522 547
523 TEST_F(AXPositionTest, AsTreePositionWithNullPosition) { 548 TEST_F(AXPositionTest, AsTreePositionWithNullPosition) {
524 TestPositionType null_position = AXNodePosition::CreateNullPosition(); 549 TestPositionType null_position = CreateNullPosition();
525 ASSERT_NE(nullptr, null_position); 550 ASSERT_NE(nullptr, null_position);
526 TestPositionType test_position = null_position->AsTreePosition(); 551 TestPositionType test_position = null_position->AsTreePosition();
527 ASSERT_NE(nullptr, test_position); 552 ASSERT_NE(nullptr, test_position);
528 EXPECT_TRUE(test_position->IsNullPosition()); 553 EXPECT_TRUE(test_position->IsNullPosition());
529 } 554 }
530 555
531 TEST_F(AXPositionTest, AsTreePositionWithTreePosition) { 556 TEST_F(AXPositionTest, AsTreePositionWithTreePosition) {
532 TestPositionType tree_position = AXNodePosition::CreateTreePosition( 557 TestPositionType tree_position =
533 tree_.data().tree_id, root_.id, 1 /* child_index */); 558 CreateTreePosition(tree_.data().tree_id, root_.id, 1 /* child_index */);
534 ASSERT_NE(nullptr, tree_position); 559 ASSERT_NE(nullptr, tree_position);
535 TestPositionType test_position = tree_position->AsTreePosition(); 560 TestPositionType test_position = tree_position->AsTreePosition();
536 ASSERT_NE(nullptr, test_position); 561 ASSERT_NE(nullptr, test_position);
537 EXPECT_TRUE(test_position->IsTreePosition()); 562 EXPECT_TRUE(test_position->IsTreePosition());
538 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id()); 563 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id());
539 EXPECT_EQ(root_.id, test_position->anchor_id()); 564 EXPECT_EQ(root_.id, test_position->anchor_id());
540 EXPECT_EQ(1, test_position->child_index()); 565 EXPECT_EQ(1, test_position->child_index());
541 EXPECT_EQ(AXNodePosition::INVALID_OFFSET, test_position->text_offset()); 566 EXPECT_EQ(AXNodePosition::INVALID_OFFSET, test_position->text_offset());
542 } 567 }
543 568
544 TEST_F(AXPositionTest, AsTreePositionWithTextPosition) { 569 TEST_F(AXPositionTest, AsTreePositionWithTextPosition) {
545 // Create a text position pointing to the last character in the text field. 570 // Create a text position pointing to the last character in the text field.
546 TestPositionType text_position = AXNodePosition::CreateTextPosition( 571 TestPositionType text_position =
547 tree_.data().tree_id, text_field_.id, 12 /* text_offset */, 572 CreateTextPosition(tree_.data().tree_id, text_field_.id,
548 AX_TEXT_AFFINITY_DOWNSTREAM); 573 12 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
549 ASSERT_NE(nullptr, text_position); 574 ASSERT_NE(nullptr, text_position);
550 TestPositionType test_position = text_position->AsTreePosition(); 575 TestPositionType test_position = text_position->AsTreePosition();
551 ASSERT_NE(nullptr, test_position); 576 ASSERT_NE(nullptr, test_position);
552 EXPECT_TRUE(test_position->IsTreePosition()); 577 EXPECT_TRUE(test_position->IsTreePosition());
553 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id()); 578 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id());
554 EXPECT_EQ(text_field_.id, test_position->anchor_id()); 579 EXPECT_EQ(text_field_.id, test_position->anchor_id());
555 // The created tree position should point to the second static text node 580 // The created tree position should point to the second static text node
556 // inside the text field. 581 // inside the text field.
557 EXPECT_EQ(2, test_position->child_index()); 582 EXPECT_EQ(2, test_position->child_index());
558 // But its text offset should be unchanged. 583 // But its text offset should be unchanged.
559 EXPECT_EQ(12, test_position->text_offset()); 584 EXPECT_EQ(12, test_position->text_offset());
560 585
561 // Test for a "before text" position. 586 // Test for a "before text" position.
562 text_position = AXNodePosition::CreateTextPosition( 587 text_position =
563 tree_.data().tree_id, inline_box2_.id, 0 /* text_offset */, 588 CreateTextPosition(tree_.data().tree_id, inline_box2_.id,
564 AX_TEXT_AFFINITY_DOWNSTREAM); 589 0 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
565 ASSERT_NE(nullptr, text_position); 590 ASSERT_NE(nullptr, text_position);
566 test_position = text_position->AsTreePosition(); 591 test_position = text_position->AsTreePosition();
567 ASSERT_NE(nullptr, test_position); 592 ASSERT_NE(nullptr, test_position);
568 EXPECT_TRUE(test_position->IsTreePosition()); 593 EXPECT_TRUE(test_position->IsTreePosition());
569 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id()); 594 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id());
570 EXPECT_EQ(inline_box2_.id, test_position->anchor_id()); 595 EXPECT_EQ(inline_box2_.id, test_position->anchor_id());
571 EXPECT_EQ(AXNodePosition::BEFORE_TEXT, test_position->child_index()); 596 EXPECT_EQ(AXNodePosition::BEFORE_TEXT, test_position->child_index());
572 EXPECT_EQ(0, test_position->text_offset()); 597 EXPECT_EQ(0, test_position->text_offset());
573 598
574 // Test for an "after text" position. 599 // Test for an "after text" position.
575 text_position = AXNodePosition::CreateTextPosition( 600 text_position =
576 tree_.data().tree_id, inline_box2_.id, 6 /* text_offset */, 601 CreateTextPosition(tree_.data().tree_id, inline_box2_.id,
577 AX_TEXT_AFFINITY_DOWNSTREAM); 602 6 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
578 ASSERT_NE(nullptr, text_position); 603 ASSERT_NE(nullptr, text_position);
579 test_position = text_position->AsTreePosition(); 604 test_position = text_position->AsTreePosition();
580 ASSERT_NE(nullptr, test_position); 605 ASSERT_NE(nullptr, test_position);
581 EXPECT_TRUE(test_position->IsTreePosition()); 606 EXPECT_TRUE(test_position->IsTreePosition());
582 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id()); 607 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id());
583 EXPECT_EQ(inline_box2_.id, test_position->anchor_id()); 608 EXPECT_EQ(inline_box2_.id, test_position->anchor_id());
584 EXPECT_EQ(0, test_position->child_index()); 609 EXPECT_EQ(0, test_position->child_index());
585 EXPECT_EQ(6, test_position->text_offset()); 610 EXPECT_EQ(6, test_position->text_offset());
586 } 611 }
587 612
588 TEST_F(AXPositionTest, AsTextPositionWithNullPosition) { 613 TEST_F(AXPositionTest, AsTextPositionWithNullPosition) {
589 TestPositionType null_position = AXNodePosition::CreateNullPosition(); 614 TestPositionType null_position = CreateNullPosition();
590 ASSERT_NE(nullptr, null_position); 615 ASSERT_NE(nullptr, null_position);
591 TestPositionType test_position = null_position->AsTextPosition(); 616 TestPositionType test_position = null_position->AsTextPosition();
592 ASSERT_NE(nullptr, test_position); 617 ASSERT_NE(nullptr, test_position);
593 EXPECT_TRUE(test_position->IsNullPosition()); 618 EXPECT_TRUE(test_position->IsNullPosition());
594 } 619 }
595 620
596 TEST_F(AXPositionTest, AsTextPositionWithTreePosition) { 621 TEST_F(AXPositionTest, AsTextPositionWithTreePosition) {
597 // Create a tree position pointing to the line break node inside the text 622 // Create a tree position pointing to the line break node inside the text
598 // field. 623 // field.
599 TestPositionType tree_position = AXNodePosition::CreateTreePosition( 624 TestPositionType tree_position = CreateTreePosition(
600 tree_.data().tree_id, text_field_.id, 1 /* child_index */); 625 tree_.data().tree_id, text_field_.id, 1 /* child_index */);
601 ASSERT_NE(nullptr, tree_position); 626 ASSERT_NE(nullptr, tree_position);
602 TestPositionType test_position = tree_position->AsTextPosition(); 627 TestPositionType test_position = tree_position->AsTextPosition();
603 ASSERT_NE(nullptr, test_position); 628 ASSERT_NE(nullptr, test_position);
604 EXPECT_TRUE(test_position->IsTextPosition()); 629 EXPECT_TRUE(test_position->IsTextPosition());
605 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id()); 630 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id());
606 EXPECT_EQ(text_field_.id, test_position->anchor_id()); 631 EXPECT_EQ(text_field_.id, test_position->anchor_id());
607 // The created text position should point to the 6th character inside the text 632 // The created text position should point to the 6th character inside the text
608 // field, i.e. the line break. 633 // field, i.e. the line break.
609 EXPECT_EQ(6, test_position->text_offset()); 634 EXPECT_EQ(6, test_position->text_offset());
610 // But its child index should be unchanged. 635 // But its child index should be unchanged.
611 EXPECT_EQ(1, test_position->child_index()); 636 EXPECT_EQ(1, test_position->child_index());
612 637
613 // Test for a "before text" position. 638 // Test for a "before text" position.
614 tree_position = AXNodePosition::CreateTreePosition( 639 tree_position = CreateTreePosition(tree_.data().tree_id, inline_box1_.id,
615 tree_.data().tree_id, inline_box1_.id, AXNodePosition::BEFORE_TEXT); 640 AXNodePosition::BEFORE_TEXT);
616 ASSERT_NE(nullptr, tree_position); 641 ASSERT_NE(nullptr, tree_position);
617 test_position = tree_position->AsTextPosition(); 642 test_position = tree_position->AsTextPosition();
618 ASSERT_NE(nullptr, test_position); 643 ASSERT_NE(nullptr, test_position);
619 EXPECT_TRUE(test_position->IsTextPosition()); 644 EXPECT_TRUE(test_position->IsTextPosition());
620 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id()); 645 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id());
621 EXPECT_EQ(inline_box1_.id, test_position->anchor_id()); 646 EXPECT_EQ(inline_box1_.id, test_position->anchor_id());
622 EXPECT_EQ(0, test_position->text_offset()); 647 EXPECT_EQ(0, test_position->text_offset());
623 EXPECT_EQ(AXNodePosition::BEFORE_TEXT, test_position->child_index()); 648 EXPECT_EQ(AXNodePosition::BEFORE_TEXT, test_position->child_index());
624 649
625 // Test for an "after text" position. 650 // Test for an "after text" position.
626 tree_position = AXNodePosition::CreateTreePosition( 651 tree_position = CreateTreePosition(tree_.data().tree_id, inline_box1_.id,
627 tree_.data().tree_id, inline_box1_.id, 0 /* child_index */); 652 0 /* child_index */);
628 ASSERT_NE(nullptr, tree_position); 653 ASSERT_NE(nullptr, tree_position);
629 test_position = tree_position->AsTextPosition(); 654 test_position = tree_position->AsTextPosition();
630 ASSERT_NE(nullptr, test_position); 655 ASSERT_NE(nullptr, test_position);
631 EXPECT_TRUE(test_position->IsTextPosition()); 656 EXPECT_TRUE(test_position->IsTextPosition());
632 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id()); 657 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id());
633 EXPECT_EQ(inline_box1_.id, test_position->anchor_id()); 658 EXPECT_EQ(inline_box1_.id, test_position->anchor_id());
634 EXPECT_EQ(6, test_position->text_offset()); 659 EXPECT_EQ(6, test_position->text_offset());
635 EXPECT_EQ(0, test_position->child_index()); 660 EXPECT_EQ(0, test_position->child_index());
636 } 661 }
637 662
638 TEST_F(AXPositionTest, AsTextPositionWithTextPosition) { 663 TEST_F(AXPositionTest, AsTextPositionWithTextPosition) {
639 TestPositionType text_position = AXNodePosition::CreateTextPosition( 664 TestPositionType text_position =
640 tree_.data().tree_id, text_field_.id, 0 /* text_offset */, 665 CreateTextPosition(tree_.data().tree_id, text_field_.id,
641 AX_TEXT_AFFINITY_DOWNSTREAM); 666 0 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
642 ASSERT_NE(nullptr, text_position); 667 ASSERT_NE(nullptr, text_position);
643 TestPositionType test_position = text_position->AsTextPosition(); 668 TestPositionType test_position = text_position->AsTextPosition();
644 ASSERT_NE(nullptr, test_position); 669 ASSERT_NE(nullptr, test_position);
645 EXPECT_TRUE(test_position->IsTextPosition()); 670 EXPECT_TRUE(test_position->IsTextPosition());
646 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id()); 671 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id());
647 EXPECT_EQ(text_field_.id, test_position->anchor_id()); 672 EXPECT_EQ(text_field_.id, test_position->anchor_id());
648 EXPECT_EQ(0, test_position->text_offset()); 673 EXPECT_EQ(0, test_position->text_offset());
649 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, test_position->affinity()); 674 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, test_position->affinity());
650 EXPECT_EQ(AXNodePosition::INVALID_INDEX, test_position->child_index()); 675 EXPECT_EQ(AXNodePosition::INVALID_INDEX, test_position->child_index());
651 } 676 }
652 677
653 TEST_F(AXPositionTest, AsLeafTextPositionWithNullPosition) { 678 TEST_F(AXPositionTest, AsLeafTextPositionWithNullPosition) {
654 TestPositionType null_position = AXNodePosition::CreateNullPosition(); 679 TestPositionType null_position = CreateNullPosition();
655 ASSERT_NE(nullptr, null_position); 680 ASSERT_NE(nullptr, null_position);
656 TestPositionType test_position = null_position->AsLeafTextPosition(); 681 TestPositionType test_position = null_position->AsLeafTextPosition();
657 ASSERT_NE(nullptr, test_position); 682 ASSERT_NE(nullptr, test_position);
658 EXPECT_TRUE(test_position->IsNullPosition()); 683 EXPECT_TRUE(test_position->IsNullPosition());
659 } 684 }
660 685
661 TEST_F(AXPositionTest, AsLeafTextPositionWithTreePosition) { 686 TEST_F(AXPositionTest, AsLeafTextPositionWithTreePosition) {
662 // Create a tree position pointing to the first static text node inside the 687 // Create a tree position pointing to the first static text node inside the
663 // text field. 688 // text field.
664 TestPositionType tree_position = AXNodePosition::CreateTreePosition( 689 TestPositionType tree_position = CreateTreePosition(
665 tree_.data().tree_id, text_field_.id, 0 /* child_index */); 690 tree_.data().tree_id, text_field_.id, 0 /* child_index */);
666 ASSERT_NE(nullptr, tree_position); 691 ASSERT_NE(nullptr, tree_position);
667 TestPositionType test_position = tree_position->AsLeafTextPosition(); 692 TestPositionType test_position = tree_position->AsLeafTextPosition();
668 ASSERT_NE(nullptr, test_position); 693 ASSERT_NE(nullptr, test_position);
669 EXPECT_TRUE(test_position->IsTextPosition()); 694 EXPECT_TRUE(test_position->IsTextPosition());
670 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id()); 695 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id());
671 EXPECT_EQ(inline_box1_.id, test_position->anchor_id()); 696 EXPECT_EQ(inline_box1_.id, test_position->anchor_id());
672 EXPECT_EQ(0, test_position->text_offset()); 697 EXPECT_EQ(0, test_position->text_offset());
673 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, test_position->affinity()); 698 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, test_position->affinity());
674 699
675 // Create a tree position pointing to the line break node inside the text 700 // Create a tree position pointing to the line break node inside the text
676 // field. 701 // field.
677 tree_position = AXNodePosition::CreateTreePosition( 702 tree_position = CreateTreePosition(tree_.data().tree_id, text_field_.id,
678 tree_.data().tree_id, text_field_.id, 1 /* child_index */); 703 1 /* child_index */);
679 ASSERT_NE(nullptr, tree_position); 704 ASSERT_NE(nullptr, tree_position);
680 test_position = tree_position->AsLeafTextPosition(); 705 test_position = tree_position->AsLeafTextPosition();
681 ASSERT_NE(nullptr, test_position); 706 ASSERT_NE(nullptr, test_position);
682 EXPECT_TRUE(test_position->IsTextPosition()); 707 EXPECT_TRUE(test_position->IsTextPosition());
683 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id()); 708 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id());
684 EXPECT_EQ(line_break_.id, test_position->anchor_id()); 709 EXPECT_EQ(line_break_.id, test_position->anchor_id());
685 EXPECT_EQ(0, test_position->text_offset()); 710 EXPECT_EQ(0, test_position->text_offset());
686 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, test_position->affinity()); 711 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, test_position->affinity());
687 712
688 // Create a text position pointing to the second static text node inside the 713 // Create a text position pointing to the second static text node inside the
689 // text field. 714 // text field.
690 tree_position = AXNodePosition::CreateTreePosition( 715 tree_position = CreateTreePosition(tree_.data().tree_id, text_field_.id,
691 tree_.data().tree_id, text_field_.id, 2 /* child_index */); 716 2 /* child_index */);
692 ASSERT_NE(nullptr, tree_position); 717 ASSERT_NE(nullptr, tree_position);
693 test_position = tree_position->AsLeafTextPosition(); 718 test_position = tree_position->AsLeafTextPosition();
694 ASSERT_NE(nullptr, test_position); 719 ASSERT_NE(nullptr, test_position);
695 EXPECT_TRUE(test_position->IsTextPosition()); 720 EXPECT_TRUE(test_position->IsTextPosition());
696 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id()); 721 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id());
697 EXPECT_EQ(inline_box2_.id, test_position->anchor_id()); 722 EXPECT_EQ(inline_box2_.id, test_position->anchor_id());
698 EXPECT_EQ(0, test_position->text_offset()); 723 EXPECT_EQ(0, test_position->text_offset());
699 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, test_position->affinity()); 724 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, test_position->affinity());
700 } 725 }
701 726
702 TEST_F(AXPositionTest, AsLeafTextPositionWithTextPosition) { 727 TEST_F(AXPositionTest, AsLeafTextPositionWithTextPosition) {
703 // Create a text position pointing to the end of the root (an "after text" 728 // Create a text position pointing to the end of the root (an "after text"
704 // position). 729 // position).
705 TestPositionType text_position = AXNodePosition::CreateTextPosition( 730 TestPositionType text_position =
706 tree_.data().tree_id, root_.id, 28 /* text_offset */, 731 CreateTextPosition(tree_.data().tree_id, root_.id, 28 /* text_offset */,
707 AX_TEXT_AFFINITY_DOWNSTREAM); 732 AX_TEXT_AFFINITY_DOWNSTREAM);
708 ASSERT_NE(nullptr, text_position); 733 ASSERT_NE(nullptr, text_position);
709 TestPositionType test_position = text_position->AsLeafTextPosition(); 734 TestPositionType test_position = text_position->AsLeafTextPosition();
710 ASSERT_NE(nullptr, test_position); 735 ASSERT_NE(nullptr, test_position);
711 EXPECT_TRUE(test_position->IsTextPosition()); 736 EXPECT_TRUE(test_position->IsTextPosition());
712 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id()); 737 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id());
713 EXPECT_EQ(inline_box2_.id, test_position->anchor_id()); 738 EXPECT_EQ(inline_box2_.id, test_position->anchor_id());
714 EXPECT_EQ(6, test_position->text_offset()); 739 EXPECT_EQ(6, test_position->text_offset());
715 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, test_position->affinity()); 740 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, test_position->affinity());
716 741
717 text_position = AXNodePosition::CreateTextPosition( 742 text_position =
718 tree_.data().tree_id, text_field_.id, 0 /* text_offset */, 743 CreateTextPosition(tree_.data().tree_id, text_field_.id,
719 AX_TEXT_AFFINITY_DOWNSTREAM); 744 0 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
720 ASSERT_NE(nullptr, text_position); 745 ASSERT_NE(nullptr, text_position);
721 test_position = text_position->AsLeafTextPosition(); 746 test_position = text_position->AsLeafTextPosition();
722 ASSERT_NE(nullptr, test_position); 747 ASSERT_NE(nullptr, test_position);
723 EXPECT_TRUE(test_position->IsTextPosition()); 748 EXPECT_TRUE(test_position->IsTextPosition());
724 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id()); 749 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id());
725 EXPECT_EQ(inline_box1_.id, test_position->anchor_id()); 750 EXPECT_EQ(inline_box1_.id, test_position->anchor_id());
726 EXPECT_EQ(0, test_position->text_offset()); 751 EXPECT_EQ(0, test_position->text_offset());
727 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, test_position->affinity()); 752 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, test_position->affinity());
728 753
729 text_position = AXNodePosition::CreateTextPosition( 754 text_position =
730 tree_.data().tree_id, text_field_.id, 1 /* text_offset */, 755 CreateTextPosition(tree_.data().tree_id, text_field_.id,
731 AX_TEXT_AFFINITY_UPSTREAM); 756 1 /* text_offset */, AX_TEXT_AFFINITY_UPSTREAM);
732 ASSERT_NE(nullptr, text_position); 757 ASSERT_NE(nullptr, text_position);
733 test_position = text_position->AsLeafTextPosition(); 758 test_position = text_position->AsLeafTextPosition();
734 ASSERT_NE(nullptr, test_position); 759 ASSERT_NE(nullptr, test_position);
735 EXPECT_TRUE(test_position->IsTextPosition()); 760 EXPECT_TRUE(test_position->IsTextPosition());
736 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id()); 761 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id());
737 EXPECT_EQ(inline_box1_.id, test_position->anchor_id()); 762 EXPECT_EQ(inline_box1_.id, test_position->anchor_id());
738 EXPECT_EQ(1, test_position->text_offset()); 763 EXPECT_EQ(1, test_position->text_offset());
739 EXPECT_EQ(AX_TEXT_AFFINITY_UPSTREAM, test_position->affinity()); 764 EXPECT_EQ(AX_TEXT_AFFINITY_UPSTREAM, test_position->affinity());
740 765
741 // Create a text position pointing to the line break character inside the text 766 // Create a text position pointing to the line break character inside the text
742 // field. 767 // field.
743 text_position = AXNodePosition::CreateTextPosition( 768 text_position =
744 tree_.data().tree_id, text_field_.id, 6 /* text_offset */, 769 CreateTextPosition(tree_.data().tree_id, text_field_.id,
745 AX_TEXT_AFFINITY_UPSTREAM); 770 6 /* text_offset */, AX_TEXT_AFFINITY_UPSTREAM);
746 ASSERT_NE(nullptr, text_position); 771 ASSERT_NE(nullptr, text_position);
747 test_position = text_position->AsLeafTextPosition(); 772 test_position = text_position->AsLeafTextPosition();
748 ASSERT_NE(nullptr, test_position); 773 ASSERT_NE(nullptr, test_position);
749 EXPECT_TRUE(test_position->IsTextPosition()); 774 EXPECT_TRUE(test_position->IsTextPosition());
750 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id()); 775 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id());
751 EXPECT_EQ(line_break_.id, test_position->anchor_id()); 776 EXPECT_EQ(line_break_.id, test_position->anchor_id());
752 EXPECT_EQ(0, test_position->text_offset()); 777 EXPECT_EQ(0, test_position->text_offset());
753 EXPECT_EQ(AX_TEXT_AFFINITY_UPSTREAM, test_position->affinity()); 778 EXPECT_EQ(AX_TEXT_AFFINITY_UPSTREAM, test_position->affinity());
754 779
755 // Create a text position pointing to the offset after the last character in 780 // Create a text position pointing to the offset after the last character in
756 // the text field, (an "after text" position). 781 // the text field, (an "after text" position).
757 text_position = AXNodePosition::CreateTextPosition( 782 text_position =
758 tree_.data().tree_id, text_field_.id, 13 /* text_offset */, 783 CreateTextPosition(tree_.data().tree_id, text_field_.id,
759 AX_TEXT_AFFINITY_DOWNSTREAM); 784 13 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
760 ASSERT_NE(nullptr, text_position); 785 ASSERT_NE(nullptr, text_position);
761 test_position = text_position->AsLeafTextPosition(); 786 test_position = text_position->AsLeafTextPosition();
762 ASSERT_NE(nullptr, test_position); 787 ASSERT_NE(nullptr, test_position);
763 EXPECT_TRUE(test_position->IsTextPosition()); 788 EXPECT_TRUE(test_position->IsTextPosition());
764 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id()); 789 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id());
765 EXPECT_EQ(inline_box2_.id, test_position->anchor_id()); 790 EXPECT_EQ(inline_box2_.id, test_position->anchor_id());
766 EXPECT_EQ(6, test_position->text_offset()); 791 EXPECT_EQ(6, test_position->text_offset());
767 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, test_position->affinity()); 792 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, test_position->affinity());
768 } 793 }
769 794
770 TEST_F(AXPositionTest, CreatePositionAtStartOfAnchorWithNullPosition) { 795 TEST_F(AXPositionTest, CreatePositionAtStartOfAnchorWithNullPosition) {
771 TestPositionType null_position = AXNodePosition::CreateNullPosition(); 796 TestPositionType null_position = CreateNullPosition();
772 ASSERT_NE(nullptr, null_position); 797 ASSERT_NE(nullptr, null_position);
773 TestPositionType test_position = 798 TestPositionType test_position =
774 null_position->CreatePositionAtStartOfAnchor(); 799 null_position->CreatePositionAtStartOfAnchor();
775 EXPECT_NE(nullptr, test_position); 800 EXPECT_NE(nullptr, test_position);
776 EXPECT_TRUE(test_position->IsNullPosition()); 801 EXPECT_TRUE(test_position->IsNullPosition());
777 } 802 }
778 803
779 TEST_F(AXPositionTest, CreatePositionAtStartOfAnchorWithTreePosition) { 804 TEST_F(AXPositionTest, CreatePositionAtStartOfAnchorWithTreePosition) {
780 TestPositionType tree_position = AXNodePosition::CreateTreePosition( 805 TestPositionType tree_position =
781 tree_.data().tree_id, root_.id, 0 /* child_index */); 806 CreateTreePosition(tree_.data().tree_id, root_.id, 0 /* child_index */);
782 ASSERT_NE(nullptr, tree_position); 807 ASSERT_NE(nullptr, tree_position);
783 TestPositionType test_position = 808 TestPositionType test_position =
784 tree_position->CreatePositionAtStartOfAnchor(); 809 tree_position->CreatePositionAtStartOfAnchor();
785 EXPECT_NE(nullptr, test_position); 810 EXPECT_NE(nullptr, test_position);
786 EXPECT_TRUE(test_position->IsTreePosition()); 811 EXPECT_TRUE(test_position->IsTreePosition());
787 EXPECT_EQ(root_.id, test_position->anchor_id()); 812 EXPECT_EQ(root_.id, test_position->anchor_id());
788 EXPECT_EQ(0, test_position->child_index()); 813 EXPECT_EQ(0, test_position->child_index());
789 814
790 tree_position = AXNodePosition::CreateTreePosition( 815 tree_position =
791 tree_.data().tree_id, root_.id, 1 /* child_index */); 816 CreateTreePosition(tree_.data().tree_id, root_.id, 1 /* child_index */);
792 ASSERT_NE(nullptr, tree_position); 817 ASSERT_NE(nullptr, tree_position);
793 test_position = tree_position->CreatePositionAtStartOfAnchor(); 818 test_position = tree_position->CreatePositionAtStartOfAnchor();
794 EXPECT_NE(nullptr, test_position); 819 EXPECT_NE(nullptr, test_position);
795 EXPECT_TRUE(test_position->IsTreePosition()); 820 EXPECT_TRUE(test_position->IsTreePosition());
796 EXPECT_EQ(root_.id, test_position->anchor_id()); 821 EXPECT_EQ(root_.id, test_position->anchor_id());
797 EXPECT_EQ(0, test_position->child_index()); 822 EXPECT_EQ(0, test_position->child_index());
798 823
799 // An "after text" position. 824 // An "after text" position.
800 tree_position = AXNodePosition::CreateTreePosition( 825 tree_position = CreateTreePosition(tree_.data().tree_id, inline_box1_.id,
801 tree_.data().tree_id, inline_box1_.id, 0 /* child_index */); 826 0 /* child_index */);
802 ASSERT_NE(nullptr, tree_position); 827 ASSERT_NE(nullptr, tree_position);
803 test_position = tree_position->CreatePositionAtStartOfAnchor(); 828 test_position = tree_position->CreatePositionAtStartOfAnchor();
804 EXPECT_NE(nullptr, test_position); 829 EXPECT_NE(nullptr, test_position);
805 EXPECT_TRUE(test_position->IsTreePosition()); 830 EXPECT_TRUE(test_position->IsTreePosition());
806 EXPECT_EQ(inline_box1_.id, test_position->anchor_id()); 831 EXPECT_EQ(inline_box1_.id, test_position->anchor_id());
807 EXPECT_EQ(AXNodePosition::BEFORE_TEXT, test_position->child_index()); 832 EXPECT_EQ(AXNodePosition::BEFORE_TEXT, test_position->child_index());
808 } 833 }
809 834
810 TEST_F(AXPositionTest, CreatePositionAtStartOfAnchorWithTextPosition) { 835 TEST_F(AXPositionTest, CreatePositionAtStartOfAnchorWithTextPosition) {
811 TestPositionType text_position = AXNodePosition::CreateTextPosition( 836 TestPositionType text_position =
812 tree_.data().tree_id, inline_box1_.id, 0 /* text_offset */, 837 CreateTextPosition(tree_.data().tree_id, inline_box1_.id,
813 AX_TEXT_AFFINITY_DOWNSTREAM); 838 0 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
814 ASSERT_NE(nullptr, text_position); 839 ASSERT_NE(nullptr, text_position);
815 TestPositionType test_position = 840 TestPositionType test_position =
816 text_position->CreatePositionAtStartOfAnchor(); 841 text_position->CreatePositionAtStartOfAnchor();
817 EXPECT_NE(nullptr, test_position); 842 EXPECT_NE(nullptr, test_position);
818 EXPECT_TRUE(test_position->IsTextPosition()); 843 EXPECT_TRUE(test_position->IsTextPosition());
819 EXPECT_EQ(inline_box1_.id, test_position->anchor_id()); 844 EXPECT_EQ(inline_box1_.id, test_position->anchor_id());
820 EXPECT_EQ(0, test_position->text_offset()); 845 EXPECT_EQ(0, test_position->text_offset());
821 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, test_position->affinity()); 846 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, test_position->affinity());
822 847
823 text_position = AXNodePosition::CreateTextPosition( 848 text_position =
824 tree_.data().tree_id, inline_box1_.id, 1 /* text_offset */, 849 CreateTextPosition(tree_.data().tree_id, inline_box1_.id,
825 AX_TEXT_AFFINITY_UPSTREAM); 850 1 /* text_offset */, AX_TEXT_AFFINITY_UPSTREAM);
826 ASSERT_NE(nullptr, text_position); 851 ASSERT_NE(nullptr, text_position);
827 test_position = text_position->CreatePositionAtStartOfAnchor(); 852 test_position = text_position->CreatePositionAtStartOfAnchor();
828 EXPECT_NE(nullptr, test_position); 853 EXPECT_NE(nullptr, test_position);
829 EXPECT_TRUE(test_position->IsTextPosition()); 854 EXPECT_TRUE(test_position->IsTextPosition());
830 EXPECT_EQ(inline_box1_.id, test_position->anchor_id()); 855 EXPECT_EQ(inline_box1_.id, test_position->anchor_id());
831 EXPECT_EQ(0, test_position->text_offset()); 856 EXPECT_EQ(0, test_position->text_offset());
832 // Affinity should have been reset to the default value. 857 // Affinity should have been reset to the default value.
833 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, test_position->affinity()); 858 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, test_position->affinity());
834 } 859 }
835 860
836 TEST_F(AXPositionTest, CreatePositionAtEndOfAnchorWithNullPosition) { 861 TEST_F(AXPositionTest, CreatePositionAtEndOfAnchorWithNullPosition) {
837 TestPositionType null_position = AXNodePosition::CreateNullPosition(); 862 TestPositionType null_position = CreateNullPosition();
838 ASSERT_NE(nullptr, null_position); 863 ASSERT_NE(nullptr, null_position);
839 TestPositionType test_position = null_position->CreatePositionAtEndOfAnchor(); 864 TestPositionType test_position = null_position->CreatePositionAtEndOfAnchor();
840 EXPECT_NE(nullptr, test_position); 865 EXPECT_NE(nullptr, test_position);
841 EXPECT_TRUE(test_position->IsNullPosition()); 866 EXPECT_TRUE(test_position->IsNullPosition());
842 } 867 }
843 868
844 TEST_F(AXPositionTest, CreatePositionAtEndOfAnchorWithTreePosition) { 869 TEST_F(AXPositionTest, CreatePositionAtEndOfAnchorWithTreePosition) {
845 TestPositionType tree_position = AXNodePosition::CreateTreePosition( 870 TestPositionType tree_position =
846 tree_.data().tree_id, root_.id, 3 /* child_index */); 871 CreateTreePosition(tree_.data().tree_id, root_.id, 3 /* child_index */);
847 ASSERT_NE(nullptr, tree_position); 872 ASSERT_NE(nullptr, tree_position);
848 TestPositionType test_position = tree_position->CreatePositionAtEndOfAnchor(); 873 TestPositionType test_position = tree_position->CreatePositionAtEndOfAnchor();
849 EXPECT_NE(nullptr, test_position); 874 EXPECT_NE(nullptr, test_position);
850 EXPECT_TRUE(test_position->IsTreePosition()); 875 EXPECT_TRUE(test_position->IsTreePosition());
851 EXPECT_EQ(root_.id, test_position->anchor_id()); 876 EXPECT_EQ(root_.id, test_position->anchor_id());
852 EXPECT_EQ(3, test_position->child_index()); 877 EXPECT_EQ(3, test_position->child_index());
853 878
854 tree_position = AXNodePosition::CreateTreePosition( 879 tree_position =
855 tree_.data().tree_id, root_.id, 1 /* child_index */); 880 CreateTreePosition(tree_.data().tree_id, root_.id, 1 /* child_index */);
856 ASSERT_NE(nullptr, tree_position); 881 ASSERT_NE(nullptr, tree_position);
857 test_position = tree_position->CreatePositionAtEndOfAnchor(); 882 test_position = tree_position->CreatePositionAtEndOfAnchor();
858 EXPECT_NE(nullptr, test_position); 883 EXPECT_NE(nullptr, test_position);
859 EXPECT_TRUE(test_position->IsTreePosition()); 884 EXPECT_TRUE(test_position->IsTreePosition());
860 EXPECT_EQ(root_.id, test_position->anchor_id()); 885 EXPECT_EQ(root_.id, test_position->anchor_id());
861 EXPECT_EQ(3, test_position->child_index()); 886 EXPECT_EQ(3, test_position->child_index());
862 } 887 }
863 888
864 TEST_F(AXPositionTest, CreatePositionAtEndOfAnchorWithTextPosition) { 889 TEST_F(AXPositionTest, CreatePositionAtEndOfAnchorWithTextPosition) {
865 TestPositionType text_position = AXNodePosition::CreateTextPosition( 890 TestPositionType text_position =
866 tree_.data().tree_id, inline_box1_.id, 6 /* text_offset */, 891 CreateTextPosition(tree_.data().tree_id, inline_box1_.id,
867 AX_TEXT_AFFINITY_DOWNSTREAM); 892 6 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
868 ASSERT_NE(nullptr, text_position); 893 ASSERT_NE(nullptr, text_position);
869 TestPositionType test_position = text_position->CreatePositionAtEndOfAnchor(); 894 TestPositionType test_position = text_position->CreatePositionAtEndOfAnchor();
870 EXPECT_NE(nullptr, test_position); 895 EXPECT_NE(nullptr, test_position);
871 EXPECT_TRUE(test_position->IsTextPosition()); 896 EXPECT_TRUE(test_position->IsTextPosition());
872 EXPECT_EQ(inline_box1_.id, test_position->anchor_id()); 897 EXPECT_EQ(inline_box1_.id, test_position->anchor_id());
873 EXPECT_EQ(6, test_position->text_offset()); 898 EXPECT_EQ(6, test_position->text_offset());
874 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, test_position->affinity()); 899 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, test_position->affinity());
875 900
876 text_position = AXNodePosition::CreateTextPosition( 901 text_position =
877 tree_.data().tree_id, inline_box1_.id, 5 /* text_offset */, 902 CreateTextPosition(tree_.data().tree_id, inline_box1_.id,
878 AX_TEXT_AFFINITY_UPSTREAM); 903 5 /* text_offset */, AX_TEXT_AFFINITY_UPSTREAM);
879 ASSERT_NE(nullptr, text_position); 904 ASSERT_NE(nullptr, text_position);
880 test_position = text_position->CreatePositionAtEndOfAnchor(); 905 test_position = text_position->CreatePositionAtEndOfAnchor();
881 EXPECT_NE(nullptr, test_position); 906 EXPECT_NE(nullptr, test_position);
882 EXPECT_TRUE(test_position->IsTextPosition()); 907 EXPECT_TRUE(test_position->IsTextPosition());
883 EXPECT_EQ(inline_box1_.id, test_position->anchor_id()); 908 EXPECT_EQ(inline_box1_.id, test_position->anchor_id());
884 EXPECT_EQ(6, test_position->text_offset()); 909 EXPECT_EQ(6, test_position->text_offset());
885 // Affinity should have been reset to the default value. 910 // Affinity should have been reset to the default value.
886 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, test_position->affinity()); 911 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, test_position->affinity());
887 } 912 }
888 913
889 TEST_F(AXPositionTest, CreateChildPositionAtWithNullPosition) { 914 TEST_F(AXPositionTest, CreateChildPositionAtWithNullPosition) {
890 TestPositionType null_position = AXNodePosition::CreateNullPosition(); 915 TestPositionType null_position = CreateNullPosition();
891 ASSERT_NE(nullptr, null_position); 916 ASSERT_NE(nullptr, null_position);
892 TestPositionType test_position = null_position->CreateChildPositionAt(0); 917 TestPositionType test_position = null_position->CreateChildPositionAt(0);
893 EXPECT_NE(nullptr, test_position); 918 EXPECT_NE(nullptr, test_position);
894 EXPECT_TRUE(test_position->IsNullPosition()); 919 EXPECT_TRUE(test_position->IsNullPosition());
895 } 920 }
896 921
897 TEST_F(AXPositionTest, CreateChildPositionAtWithTreePosition) { 922 TEST_F(AXPositionTest, CreateChildPositionAtWithTreePosition) {
898 TestPositionType tree_position = AXNodePosition::CreateTreePosition( 923 TestPositionType tree_position =
899 tree_.data().tree_id, root_.id, 2 /* child_index */); 924 CreateTreePosition(tree_.data().tree_id, root_.id, 2 /* child_index */);
900 ASSERT_NE(nullptr, tree_position); 925 ASSERT_NE(nullptr, tree_position);
901 TestPositionType test_position = tree_position->CreateChildPositionAt(1); 926 TestPositionType test_position = tree_position->CreateChildPositionAt(1);
902 EXPECT_NE(nullptr, test_position); 927 EXPECT_NE(nullptr, test_position);
903 EXPECT_TRUE(test_position->IsTreePosition()); 928 EXPECT_TRUE(test_position->IsTreePosition());
904 EXPECT_EQ(check_box_.id, test_position->anchor_id()); 929 EXPECT_EQ(check_box_.id, test_position->anchor_id());
905 // Since the anchor is a leaf node, |child_index| should signify that this is 930 // Since the anchor is a leaf node, |child_index| should signify that this is
906 // a "before text" position. 931 // a "before text" position.
907 EXPECT_EQ(AXNodePosition::BEFORE_TEXT, test_position->child_index()); 932 EXPECT_EQ(AXNodePosition::BEFORE_TEXT, test_position->child_index());
908 933
909 tree_position = AXNodePosition::CreateTreePosition( 934 tree_position =
910 tree_.data().tree_id, button_.id, 0 /* child_index */); 935 CreateTreePosition(tree_.data().tree_id, button_.id, 0 /* child_index */);
911 ASSERT_NE(nullptr, tree_position); 936 ASSERT_NE(nullptr, tree_position);
912 test_position = tree_position->CreateChildPositionAt(0); 937 test_position = tree_position->CreateChildPositionAt(0);
913 EXPECT_NE(nullptr, test_position); 938 EXPECT_NE(nullptr, test_position);
914 EXPECT_TRUE(test_position->IsNullPosition()); 939 EXPECT_TRUE(test_position->IsNullPosition());
915 } 940 }
916 941
917 TEST_F(AXPositionTest, CreateChildPositionAtWithTextPosition) { 942 TEST_F(AXPositionTest, CreateChildPositionAtWithTextPosition) {
918 TestPositionType text_position = AXNodePosition::CreateTextPosition( 943 TestPositionType text_position =
919 tree_.data().tree_id, static_text1_.id, 5 /* text_offset */, 944 CreateTextPosition(tree_.data().tree_id, static_text1_.id,
920 AX_TEXT_AFFINITY_DOWNSTREAM); 945 5 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
921 ASSERT_NE(nullptr, text_position); 946 ASSERT_NE(nullptr, text_position);
922 TestPositionType test_position = text_position->CreateChildPositionAt(0); 947 TestPositionType test_position = text_position->CreateChildPositionAt(0);
923 EXPECT_NE(nullptr, test_position); 948 EXPECT_NE(nullptr, test_position);
924 EXPECT_TRUE(test_position->IsTextPosition()); 949 EXPECT_TRUE(test_position->IsTextPosition());
925 EXPECT_EQ(inline_box1_.id, test_position->anchor_id()); 950 EXPECT_EQ(inline_box1_.id, test_position->anchor_id());
926 EXPECT_EQ(0, test_position->text_offset()); 951 EXPECT_EQ(0, test_position->text_offset());
927 952
928 text_position = AXNodePosition::CreateTextPosition( 953 text_position =
929 tree_.data().tree_id, static_text2_.id, 4 /* text_offset */, 954 CreateTextPosition(tree_.data().tree_id, static_text2_.id,
930 AX_TEXT_AFFINITY_DOWNSTREAM); 955 4 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
931 ASSERT_NE(nullptr, text_position); 956 ASSERT_NE(nullptr, text_position);
932 test_position = text_position->CreateChildPositionAt(1); 957 test_position = text_position->CreateChildPositionAt(1);
933 EXPECT_NE(nullptr, test_position); 958 EXPECT_NE(nullptr, test_position);
934 EXPECT_TRUE(test_position->IsNullPosition()); 959 EXPECT_TRUE(test_position->IsNullPosition());
935 } 960 }
936 961
937 TEST_F(AXPositionTest, CreateParentPositionWithNullPosition) { 962 TEST_F(AXPositionTest, CreateParentPositionWithNullPosition) {
938 TestPositionType null_position = AXNodePosition::CreateNullPosition(); 963 TestPositionType null_position = CreateNullPosition();
939 ASSERT_NE(nullptr, null_position); 964 ASSERT_NE(nullptr, null_position);
940 TestPositionType test_position = null_position->CreateParentPosition(); 965 TestPositionType test_position = null_position->CreateParentPosition();
941 EXPECT_NE(nullptr, test_position); 966 EXPECT_NE(nullptr, test_position);
942 EXPECT_TRUE(test_position->IsNullPosition()); 967 EXPECT_TRUE(test_position->IsNullPosition());
943 } 968 }
944 969
945 TEST_F(AXPositionTest, CreateParentPositionWithTreePosition) { 970 TEST_F(AXPositionTest, CreateParentPositionWithTreePosition) {
946 TestPositionType tree_position = AXNodePosition::CreateTreePosition( 971 TestPositionType tree_position = CreateTreePosition(
947 tree_.data().tree_id, check_box_.id, 0 /* child_index */); 972 tree_.data().tree_id, check_box_.id, 0 /* child_index */);
948 ASSERT_NE(nullptr, tree_position); 973 ASSERT_NE(nullptr, tree_position);
949 TestPositionType test_position = tree_position->CreateParentPosition(); 974 TestPositionType test_position = tree_position->CreateParentPosition();
950 EXPECT_NE(nullptr, test_position); 975 EXPECT_NE(nullptr, test_position);
951 EXPECT_TRUE(test_position->IsTreePosition()); 976 EXPECT_TRUE(test_position->IsTreePosition());
952 EXPECT_EQ(root_.id, test_position->anchor_id()); 977 EXPECT_EQ(root_.id, test_position->anchor_id());
953 // |child_index| should point to the check box node. 978 // |child_index| should point to the check box node.
954 EXPECT_EQ(1, test_position->child_index()); 979 EXPECT_EQ(1, test_position->child_index());
955 980
956 tree_position = AXNodePosition::CreateTreePosition( 981 tree_position =
957 tree_.data().tree_id, root_.id, 1 /* child_index */); 982 CreateTreePosition(tree_.data().tree_id, root_.id, 1 /* child_index */);
958 ASSERT_NE(nullptr, tree_position); 983 ASSERT_NE(nullptr, tree_position);
959 test_position = tree_position->CreateParentPosition(); 984 test_position = tree_position->CreateParentPosition();
960 EXPECT_NE(nullptr, test_position); 985 EXPECT_NE(nullptr, test_position);
961 EXPECT_TRUE(test_position->IsNullPosition()); 986 EXPECT_TRUE(test_position->IsNullPosition());
962 } 987 }
963 988
964 TEST_F(AXPositionTest, CreateParentPositionWithTextPosition) { 989 TEST_F(AXPositionTest, CreateParentPositionWithTextPosition) {
965 TestPositionType text_position = AXNodePosition::CreateTextPosition( 990 TestPositionType text_position =
966 tree_.data().tree_id, inline_box2_.id, 5 /* text_offset */, 991 CreateTextPosition(tree_.data().tree_id, inline_box2_.id,
967 AX_TEXT_AFFINITY_DOWNSTREAM); 992 5 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
968 ASSERT_NE(nullptr, text_position); 993 ASSERT_NE(nullptr, text_position);
969 TestPositionType test_position = text_position->CreateParentPosition(); 994 TestPositionType test_position = text_position->CreateParentPosition();
970 EXPECT_NE(nullptr, test_position); 995 EXPECT_NE(nullptr, test_position);
971 EXPECT_TRUE(test_position->IsTextPosition()); 996 EXPECT_TRUE(test_position->IsTextPosition());
972 EXPECT_EQ(static_text2_.id, test_position->anchor_id()); 997 EXPECT_EQ(static_text2_.id, test_position->anchor_id());
973 EXPECT_EQ(5, test_position->text_offset()); 998 EXPECT_EQ(5, test_position->text_offset());
974 999
975 test_position = test_position->CreateParentPosition(); 1000 test_position = test_position->CreateParentPosition();
976 EXPECT_NE(nullptr, test_position); 1001 EXPECT_NE(nullptr, test_position);
977 EXPECT_TRUE(test_position->IsTextPosition()); 1002 EXPECT_TRUE(test_position->IsTextPosition());
978 EXPECT_EQ(text_field_.id, test_position->anchor_id()); 1003 EXPECT_EQ(text_field_.id, test_position->anchor_id());
979 // |text_offset| should point to the same offset on the second line where the 1004 // |text_offset| should point to the same offset on the second line where the
980 // static text node position was pointing at. 1005 // static text node position was pointing at.
981 EXPECT_EQ(12, test_position->text_offset()); 1006 EXPECT_EQ(12, test_position->text_offset());
982 } 1007 }
983 1008
984 TEST_F(AXPositionTest, 1009 TEST_F(AXPositionTest,
985 CreateNextAndPreviousTextAnchorPositionWithNullPosition) { 1010 CreateNextAndPreviousTextAnchorPositionWithNullPosition) {
986 TestPositionType null_position = AXNodePosition::CreateNullPosition(); 1011 TestPositionType null_position = CreateNullPosition();
987 ASSERT_NE(nullptr, null_position); 1012 ASSERT_NE(nullptr, null_position);
988 TestPositionType test_position = 1013 TestPositionType test_position =
989 null_position->CreateNextTextAnchorPosition(); 1014 null_position->CreateNextTextAnchorPosition();
990 EXPECT_NE(nullptr, test_position); 1015 EXPECT_NE(nullptr, test_position);
991 EXPECT_TRUE(test_position->IsNullPosition()); 1016 EXPECT_TRUE(test_position->IsNullPosition());
992 test_position = null_position->CreatePreviousTextAnchorPosition(); 1017 test_position = null_position->CreatePreviousTextAnchorPosition();
993 EXPECT_NE(nullptr, test_position); 1018 EXPECT_NE(nullptr, test_position);
994 EXPECT_TRUE(test_position->IsNullPosition()); 1019 EXPECT_TRUE(test_position->IsNullPosition());
995 } 1020 }
996 1021
997 TEST_F(AXPositionTest, CreateNextTextAnchorPosition) { 1022 TEST_F(AXPositionTest, CreateNextTextAnchorPosition) {
998 TestPositionType check_box_position = AXNodePosition::CreateTreePosition( 1023 TestPositionType check_box_position =
999 tree_.data().tree_id, root_.id, 1 /* child_index */); 1024 CreateTreePosition(tree_.data().tree_id, root_.id, 1 /* child_index */);
1000 ASSERT_NE(nullptr, check_box_position); 1025 ASSERT_NE(nullptr, check_box_position);
1001 TestPositionType test_position = 1026 TestPositionType test_position =
1002 check_box_position->CreateNextTextAnchorPosition(); 1027 check_box_position->CreateNextTextAnchorPosition();
1003 EXPECT_NE(nullptr, test_position); 1028 EXPECT_NE(nullptr, test_position);
1004 EXPECT_TRUE(test_position->IsTextPosition()); 1029 EXPECT_TRUE(test_position->IsTextPosition());
1005 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id()); 1030 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id());
1006 EXPECT_EQ(check_box_.id, test_position->anchor_id()); 1031 EXPECT_EQ(check_box_.id, test_position->anchor_id());
1007 EXPECT_EQ(0, test_position->text_offset()); 1032 EXPECT_EQ(0, test_position->text_offset());
1008 1033
1009 // The text offset on the root points to the text coming from inside the check 1034 // The text offset on the root points to the text coming from inside the check
1010 // box. 1035 // box.
1011 check_box_position = AXNodePosition::CreateTextPosition( 1036 check_box_position =
1012 tree_.data().tree_id, root_.id, 6 /* text_offset */, 1037 CreateTextPosition(tree_.data().tree_id, root_.id, 6 /* text_offset */,
1013 AX_TEXT_AFFINITY_DOWNSTREAM); 1038 AX_TEXT_AFFINITY_DOWNSTREAM);
1014 ASSERT_NE(nullptr, check_box_position); 1039 ASSERT_NE(nullptr, check_box_position);
1015 test_position = check_box_position->CreateNextTextAnchorPosition(); 1040 test_position = check_box_position->CreateNextTextAnchorPosition();
1016 EXPECT_NE(nullptr, test_position); 1041 EXPECT_NE(nullptr, test_position);
1017 EXPECT_TRUE(test_position->IsTextPosition()); 1042 EXPECT_TRUE(test_position->IsTextPosition());
1018 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id()); 1043 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id());
1019 EXPECT_EQ(check_box_.id, test_position->anchor_id()); 1044 EXPECT_EQ(check_box_.id, test_position->anchor_id());
1020 EXPECT_EQ(0, test_position->text_offset()); 1045 EXPECT_EQ(0, test_position->text_offset());
1021 1046
1022 TestPositionType button_position = AXNodePosition::CreateTextPosition( 1047 TestPositionType button_position =
1023 tree_.data().tree_id, button_.id, 1 /* text_offset */, 1048 CreateTextPosition(tree_.data().tree_id, button_.id, 1 /* text_offset */,
1024 AX_TEXT_AFFINITY_DOWNSTREAM); 1049 AX_TEXT_AFFINITY_DOWNSTREAM);
1025 ASSERT_NE(nullptr, button_position); 1050 ASSERT_NE(nullptr, button_position);
1026 test_position = button_position->CreateNextTextAnchorPosition(); 1051 test_position = button_position->CreateNextTextAnchorPosition();
1027 EXPECT_NE(nullptr, test_position); 1052 EXPECT_NE(nullptr, test_position);
1028 EXPECT_TRUE(test_position->IsTextPosition()); 1053 EXPECT_TRUE(test_position->IsTextPosition());
1029 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id()); 1054 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id());
1030 EXPECT_EQ(check_box_.id, test_position->anchor_id()); 1055 EXPECT_EQ(check_box_.id, test_position->anchor_id());
1031 EXPECT_EQ(0, test_position->text_offset()); 1056 EXPECT_EQ(0, test_position->text_offset());
1032 1057
1033 test_position = test_position->CreateNextTextAnchorPosition(); 1058 test_position = test_position->CreateNextTextAnchorPosition();
1034 EXPECT_NE(nullptr, test_position); 1059 EXPECT_NE(nullptr, test_position);
(...skipping 13 matching lines...) Expand all
1048 EXPECT_NE(nullptr, test_position); 1073 EXPECT_NE(nullptr, test_position);
1049 EXPECT_TRUE(test_position->IsTextPosition()); 1074 EXPECT_TRUE(test_position->IsTextPosition());
1050 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id()); 1075 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id());
1051 EXPECT_EQ(inline_box2_.id, test_position->anchor_id()); 1076 EXPECT_EQ(inline_box2_.id, test_position->anchor_id());
1052 EXPECT_EQ(0, test_position->text_offset()); 1077 EXPECT_EQ(0, test_position->text_offset());
1053 1078
1054 test_position = test_position->CreateNextTextAnchorPosition(); 1079 test_position = test_position->CreateNextTextAnchorPosition();
1055 EXPECT_NE(nullptr, test_position); 1080 EXPECT_NE(nullptr, test_position);
1056 EXPECT_TRUE(test_position->IsNullPosition()); 1081 EXPECT_TRUE(test_position->IsNullPosition());
1057 1082
1058 TestPositionType text_field_position = AXNodePosition::CreateTreePosition( 1083 TestPositionType text_field_position =
1059 tree_.data().tree_id, root_.id, 2 /* child_index */); 1084 CreateTreePosition(tree_.data().tree_id, root_.id, 2 /* child_index */);
1060 ASSERT_NE(nullptr, text_field_position); 1085 ASSERT_NE(nullptr, text_field_position);
1061 test_position = text_field_position->CreateNextTextAnchorPosition(); 1086 test_position = text_field_position->CreateNextTextAnchorPosition();
1062 EXPECT_NE(nullptr, test_position); 1087 EXPECT_NE(nullptr, test_position);
1063 EXPECT_TRUE(test_position->IsTextPosition()); 1088 EXPECT_TRUE(test_position->IsTextPosition());
1064 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id()); 1089 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id());
1065 EXPECT_EQ(inline_box1_.id, test_position->anchor_id()); 1090 EXPECT_EQ(inline_box1_.id, test_position->anchor_id());
1066 EXPECT_EQ(0, test_position->text_offset()); 1091 EXPECT_EQ(0, test_position->text_offset());
1067 } 1092 }
1068 1093
1069 TEST_F(AXPositionTest, CreatePreviousTextAnchorPosition) { 1094 TEST_F(AXPositionTest, CreatePreviousTextAnchorPosition) {
1070 TestPositionType text_position = AXNodePosition::CreateTextPosition( 1095 TestPositionType text_position =
1071 tree_.data().tree_id, inline_box2_.id, 5 /* text_offset */, 1096 CreateTextPosition(tree_.data().tree_id, inline_box2_.id,
1072 AX_TEXT_AFFINITY_DOWNSTREAM); 1097 5 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
1073 ASSERT_NE(nullptr, text_position); 1098 ASSERT_NE(nullptr, text_position);
1074 TestPositionType test_position = 1099 TestPositionType test_position =
1075 text_position->CreatePreviousTextAnchorPosition(); 1100 text_position->CreatePreviousTextAnchorPosition();
1076 EXPECT_NE(nullptr, test_position); 1101 EXPECT_NE(nullptr, test_position);
1077 EXPECT_TRUE(test_position->IsTextPosition()); 1102 EXPECT_TRUE(test_position->IsTextPosition());
1078 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id()); 1103 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id());
1079 EXPECT_EQ(line_break_.id, test_position->anchor_id()); 1104 EXPECT_EQ(line_break_.id, test_position->anchor_id());
1080 EXPECT_EQ(0, test_position->text_offset()); 1105 EXPECT_EQ(0, test_position->text_offset());
1081 1106
1082 // Create a "before text" tree position on the second line of the text box. 1107 // Create a "before text" tree position on the second line of the text box.
1083 TestPositionType before_text_position = AXNodePosition::CreateTreePosition( 1108 TestPositionType before_text_position = CreateTreePosition(
1084 tree_.data().tree_id, inline_box2_.id, AXNodePosition::BEFORE_TEXT); 1109 tree_.data().tree_id, inline_box2_.id, AXNodePosition::BEFORE_TEXT);
1085 ASSERT_NE(nullptr, before_text_position); 1110 ASSERT_NE(nullptr, before_text_position);
1086 test_position = before_text_position->CreatePreviousTextAnchorPosition(); 1111 test_position = before_text_position->CreatePreviousTextAnchorPosition();
1087 EXPECT_NE(nullptr, test_position); 1112 EXPECT_NE(nullptr, test_position);
1088 EXPECT_TRUE(test_position->IsTextPosition()); 1113 EXPECT_TRUE(test_position->IsTextPosition());
1089 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id()); 1114 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id());
1090 EXPECT_EQ(line_break_.id, test_position->anchor_id()); 1115 EXPECT_EQ(line_break_.id, test_position->anchor_id());
1091 EXPECT_EQ(0, test_position->text_offset()); 1116 EXPECT_EQ(0, test_position->text_offset());
1092 1117
1093 test_position = test_position->CreatePreviousTextAnchorPosition(); 1118 test_position = test_position->CreatePreviousTextAnchorPosition();
(...skipping 14 matching lines...) Expand all
1108 EXPECT_NE(nullptr, test_position); 1133 EXPECT_NE(nullptr, test_position);
1109 EXPECT_TRUE(test_position->IsTextPosition()); 1134 EXPECT_TRUE(test_position->IsTextPosition());
1110 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id()); 1135 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id());
1111 EXPECT_EQ(button_.id, test_position->anchor_id()); 1136 EXPECT_EQ(button_.id, test_position->anchor_id());
1112 EXPECT_EQ(0, test_position->text_offset()); 1137 EXPECT_EQ(0, test_position->text_offset());
1113 1138
1114 test_position = test_position->CreatePreviousTextAnchorPosition(); 1139 test_position = test_position->CreatePreviousTextAnchorPosition();
1115 EXPECT_NE(nullptr, test_position); 1140 EXPECT_NE(nullptr, test_position);
1116 EXPECT_TRUE(test_position->IsNullPosition()); 1141 EXPECT_TRUE(test_position->IsNullPosition());
1117 1142
1118 TestPositionType text_field_position = AXNodePosition::CreateTreePosition( 1143 TestPositionType text_field_position = CreateTreePosition(
1119 tree_.data().tree_id, text_field_.id, 2 /* child_index */); 1144 tree_.data().tree_id, text_field_.id, 2 /* child_index */);
1120 ASSERT_NE(nullptr, text_field_position); 1145 ASSERT_NE(nullptr, text_field_position);
1121 test_position = text_field_position->CreatePreviousTextAnchorPosition(); 1146 test_position = text_field_position->CreatePreviousTextAnchorPosition();
1122 EXPECT_NE(nullptr, test_position); 1147 EXPECT_NE(nullptr, test_position);
1123 EXPECT_TRUE(test_position->IsTextPosition()); 1148 EXPECT_TRUE(test_position->IsTextPosition());
1124 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id()); 1149 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id());
1125 EXPECT_EQ(check_box_.id, test_position->anchor_id()); 1150 EXPECT_EQ(check_box_.id, test_position->anchor_id());
1126 EXPECT_EQ(0, test_position->text_offset()); 1151 EXPECT_EQ(0, test_position->text_offset());
1127 1152
1128 // The text offset on the root points to the text coming from inside the check 1153 // The text offset on the root points to the text coming from inside the check
1129 // box. 1154 // box.
1130 TestPositionType check_box_position = AXNodePosition::CreateTextPosition( 1155 TestPositionType check_box_position =
1131 tree_.data().tree_id, check_box_.id, 6 /* text_offset */, 1156 CreateTextPosition(tree_.data().tree_id, check_box_.id,
1132 AX_TEXT_AFFINITY_DOWNSTREAM); 1157 6 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
1133 ASSERT_NE(nullptr, check_box_position); 1158 ASSERT_NE(nullptr, check_box_position);
1134 test_position = check_box_position->CreatePreviousTextAnchorPosition(); 1159 test_position = check_box_position->CreatePreviousTextAnchorPosition();
1135 EXPECT_NE(nullptr, test_position); 1160 EXPECT_NE(nullptr, test_position);
1136 EXPECT_TRUE(test_position->IsTextPosition()); 1161 EXPECT_TRUE(test_position->IsTextPosition());
1137 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id()); 1162 EXPECT_EQ(tree_.data().tree_id, test_position->tree_id());
1138 EXPECT_EQ(button_.id, test_position->anchor_id()); 1163 EXPECT_EQ(button_.id, test_position->anchor_id());
1139 EXPECT_EQ(0, test_position->text_offset()); 1164 EXPECT_EQ(0, test_position->text_offset());
1140 } 1165 }
1141 1166
1142 TEST_F(AXPositionTest, CreateNextAndPreviousCharacterPositionWithNullPosition) { 1167 TEST_F(AXPositionTest, CreateNextAndPreviousCharacterPositionWithNullPosition) {
1143 TestPositionType null_position = AXNodePosition::CreateNullPosition(); 1168 TestPositionType null_position = CreateNullPosition();
1144 ASSERT_NE(nullptr, null_position); 1169 ASSERT_NE(nullptr, null_position);
1145 TestPositionType test_position = null_position->CreateNextCharacterPosition(); 1170 TestPositionType test_position = null_position->CreateNextCharacterPosition();
1146 EXPECT_NE(nullptr, test_position); 1171 EXPECT_NE(nullptr, test_position);
1147 EXPECT_TRUE(test_position->IsNullPosition()); 1172 EXPECT_TRUE(test_position->IsNullPosition());
1148 test_position = null_position->CreatePreviousCharacterPosition(); 1173 test_position = null_position->CreatePreviousCharacterPosition();
1149 EXPECT_NE(nullptr, test_position); 1174 EXPECT_NE(nullptr, test_position);
1150 EXPECT_TRUE(test_position->IsNullPosition()); 1175 EXPECT_TRUE(test_position->IsNullPosition());
1151 } 1176 }
1152 1177
1153 TEST_F(AXPositionTest, CreateNextCharacterPosition) { 1178 TEST_F(AXPositionTest, CreateNextCharacterPosition) {
1154 TestPositionType text_position = AXNodePosition::CreateTextPosition( 1179 TestPositionType text_position =
1155 tree_.data().tree_id, inline_box1_.id, 4 /* text_offset */, 1180 CreateTextPosition(tree_.data().tree_id, inline_box1_.id,
1156 AX_TEXT_AFFINITY_DOWNSTREAM); 1181 4 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
1157 ASSERT_NE(nullptr, text_position); 1182 ASSERT_NE(nullptr, text_position);
1158 TestPositionType test_position = text_position->CreateNextCharacterPosition(); 1183 TestPositionType test_position = text_position->CreateNextCharacterPosition();
1159 EXPECT_NE(nullptr, test_position); 1184 EXPECT_NE(nullptr, test_position);
1160 EXPECT_TRUE(test_position->IsTextPosition()); 1185 EXPECT_TRUE(test_position->IsTextPosition());
1161 EXPECT_EQ(inline_box1_.id, test_position->anchor_id()); 1186 EXPECT_EQ(inline_box1_.id, test_position->anchor_id());
1162 EXPECT_EQ(5, test_position->text_offset()); 1187 EXPECT_EQ(5, test_position->text_offset());
1163 1188
1164 text_position = AXNodePosition::CreateTextPosition( 1189 text_position =
1165 tree_.data().tree_id, inline_box1_.id, 5 /* text_offset */, 1190 CreateTextPosition(tree_.data().tree_id, inline_box1_.id,
1166 AX_TEXT_AFFINITY_DOWNSTREAM); 1191 5 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
1167 ASSERT_NE(nullptr, text_position); 1192 ASSERT_NE(nullptr, text_position);
1168 test_position = text_position->CreateNextCharacterPosition(); 1193 test_position = text_position->CreateNextCharacterPosition();
1169 EXPECT_NE(nullptr, test_position); 1194 EXPECT_NE(nullptr, test_position);
1170 EXPECT_TRUE(test_position->IsTextPosition()); 1195 EXPECT_TRUE(test_position->IsTextPosition());
1171 EXPECT_EQ(line_break_.id, test_position->anchor_id()); 1196 EXPECT_EQ(line_break_.id, test_position->anchor_id());
1172 EXPECT_EQ(0, test_position->text_offset()); 1197 EXPECT_EQ(0, test_position->text_offset());
1173 1198
1174 test_position = test_position->CreateNextCharacterPosition(); 1199 test_position = test_position->CreateNextCharacterPosition();
1175 EXPECT_NE(nullptr, test_position); 1200 EXPECT_NE(nullptr, test_position);
1176 EXPECT_TRUE(test_position->IsTextPosition()); 1201 EXPECT_TRUE(test_position->IsTextPosition());
1177 EXPECT_EQ(inline_box2_.id, test_position->anchor_id()); 1202 EXPECT_EQ(inline_box2_.id, test_position->anchor_id());
1178 EXPECT_EQ(0, test_position->text_offset()); 1203 EXPECT_EQ(0, test_position->text_offset());
1179 1204
1180 test_position = test_position->CreateNextCharacterPosition(); 1205 test_position = test_position->CreateNextCharacterPosition();
1181 EXPECT_NE(nullptr, test_position); 1206 EXPECT_NE(nullptr, test_position);
1182 EXPECT_TRUE(test_position->IsTextPosition()); 1207 EXPECT_TRUE(test_position->IsTextPosition());
1183 EXPECT_EQ(inline_box2_.id, test_position->anchor_id()); 1208 EXPECT_EQ(inline_box2_.id, test_position->anchor_id());
1184 EXPECT_EQ(1, test_position->text_offset()); 1209 EXPECT_EQ(1, test_position->text_offset());
1185 1210
1186 text_position = AXNodePosition::CreateTextPosition( 1211 text_position =
1187 tree_.data().tree_id, check_box_.id, 9 /* text_offset */, 1212 CreateTextPosition(tree_.data().tree_id, check_box_.id,
1188 AX_TEXT_AFFINITY_DOWNSTREAM); 1213 9 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
1189 ASSERT_NE(nullptr, text_position); 1214 ASSERT_NE(nullptr, text_position);
1190 test_position = text_position->CreateNextCharacterPosition(); 1215 test_position = text_position->CreateNextCharacterPosition();
1191 EXPECT_NE(nullptr, test_position); 1216 EXPECT_NE(nullptr, test_position);
1192 EXPECT_TRUE(test_position->IsTextPosition()); 1217 EXPECT_TRUE(test_position->IsTextPosition());
1193 EXPECT_EQ(inline_box1_.id, test_position->anchor_id()); 1218 EXPECT_EQ(inline_box1_.id, test_position->anchor_id());
1194 EXPECT_EQ(0, test_position->text_offset()); 1219 EXPECT_EQ(0, test_position->text_offset());
1195 1220
1196 text_position = AXNodePosition::CreateTextPosition( 1221 text_position =
1197 tree_.data().tree_id, text_field_.id, 0 /* text_offset */, 1222 CreateTextPosition(tree_.data().tree_id, text_field_.id,
1198 AX_TEXT_AFFINITY_UPSTREAM); 1223 0 /* text_offset */, AX_TEXT_AFFINITY_UPSTREAM);
1199 ASSERT_NE(nullptr, text_position); 1224 ASSERT_NE(nullptr, text_position);
1200 test_position = text_position->CreateNextCharacterPosition(); 1225 test_position = text_position->CreateNextCharacterPosition();
1201 EXPECT_NE(nullptr, test_position); 1226 EXPECT_NE(nullptr, test_position);
1202 EXPECT_TRUE(test_position->IsTextPosition()); 1227 EXPECT_TRUE(test_position->IsTextPosition());
1203 EXPECT_EQ(text_field_.id, test_position->anchor_id()); 1228 EXPECT_EQ(text_field_.id, test_position->anchor_id());
1204 EXPECT_EQ(1, test_position->text_offset()); 1229 EXPECT_EQ(1, test_position->text_offset());
1205 // Affinity should have been reset to downstream. 1230 // Affinity should have been reset to downstream.
1206 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, test_position->affinity()); 1231 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, test_position->affinity());
1207 } 1232 }
1208 1233
1209 TEST_F(AXPositionTest, CreatePreviousCharacterPosition) { 1234 TEST_F(AXPositionTest, CreatePreviousCharacterPosition) {
1210 TestPositionType text_position = AXNodePosition::CreateTextPosition( 1235 TestPositionType text_position =
1211 tree_.data().tree_id, inline_box2_.id, 5 /* text_offset */, 1236 CreateTextPosition(tree_.data().tree_id, inline_box2_.id,
1212 AX_TEXT_AFFINITY_DOWNSTREAM); 1237 5 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
1213 ASSERT_NE(nullptr, text_position); 1238 ASSERT_NE(nullptr, text_position);
1214 TestPositionType test_position = 1239 TestPositionType test_position =
1215 text_position->CreatePreviousCharacterPosition(); 1240 text_position->CreatePreviousCharacterPosition();
1216 EXPECT_NE(nullptr, test_position); 1241 EXPECT_NE(nullptr, test_position);
1217 EXPECT_TRUE(test_position->IsTextPosition()); 1242 EXPECT_TRUE(test_position->IsTextPosition());
1218 EXPECT_EQ(inline_box2_.id, test_position->anchor_id()); 1243 EXPECT_EQ(inline_box2_.id, test_position->anchor_id());
1219 EXPECT_EQ(4, test_position->text_offset()); 1244 EXPECT_EQ(4, test_position->text_offset());
1220 1245
1221 text_position = AXNodePosition::CreateTextPosition( 1246 text_position =
1222 tree_.data().tree_id, inline_box2_.id, 0 /* text_offset */, 1247 CreateTextPosition(tree_.data().tree_id, inline_box2_.id,
1223 AX_TEXT_AFFINITY_DOWNSTREAM); 1248 0 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
1224 ASSERT_NE(nullptr, text_position); 1249 ASSERT_NE(nullptr, text_position);
1225 test_position = text_position->CreatePreviousCharacterPosition(); 1250 test_position = text_position->CreatePreviousCharacterPosition();
1226 EXPECT_NE(nullptr, test_position); 1251 EXPECT_NE(nullptr, test_position);
1227 EXPECT_TRUE(test_position->IsTextPosition()); 1252 EXPECT_TRUE(test_position->IsTextPosition());
1228 EXPECT_EQ(line_break_.id, test_position->anchor_id()); 1253 EXPECT_EQ(line_break_.id, test_position->anchor_id());
1229 EXPECT_EQ(0, test_position->text_offset()); 1254 EXPECT_EQ(0, test_position->text_offset());
1230 1255
1231 test_position = test_position->CreatePreviousCharacterPosition(); 1256 test_position = test_position->CreatePreviousCharacterPosition();
1232 EXPECT_NE(nullptr, test_position); 1257 EXPECT_NE(nullptr, test_position);
1233 EXPECT_TRUE(test_position->IsTextPosition()); 1258 EXPECT_TRUE(test_position->IsTextPosition());
1234 EXPECT_EQ(inline_box1_.id, test_position->anchor_id()); 1259 EXPECT_EQ(inline_box1_.id, test_position->anchor_id());
1235 EXPECT_EQ(5, test_position->text_offset()); 1260 EXPECT_EQ(5, test_position->text_offset());
1236 1261
1237 test_position = test_position->CreatePreviousCharacterPosition(); 1262 test_position = test_position->CreatePreviousCharacterPosition();
1238 EXPECT_NE(nullptr, test_position); 1263 EXPECT_NE(nullptr, test_position);
1239 EXPECT_TRUE(test_position->IsTextPosition()); 1264 EXPECT_TRUE(test_position->IsTextPosition());
1240 EXPECT_EQ(inline_box1_.id, test_position->anchor_id()); 1265 EXPECT_EQ(inline_box1_.id, test_position->anchor_id());
1241 EXPECT_EQ(4, test_position->text_offset()); 1266 EXPECT_EQ(4, test_position->text_offset());
1242 1267
1243 text_position = AXNodePosition::CreateTextPosition( 1268 text_position =
1244 tree_.data().tree_id, inline_box1_.id, 0 /* text_offset */, 1269 CreateTextPosition(tree_.data().tree_id, inline_box1_.id,
1245 AX_TEXT_AFFINITY_DOWNSTREAM); 1270 0 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
1246 ASSERT_NE(nullptr, text_position); 1271 ASSERT_NE(nullptr, text_position);
1247 test_position = text_position->CreatePreviousCharacterPosition(); 1272 test_position = text_position->CreatePreviousCharacterPosition();
1248 EXPECT_NE(nullptr, test_position); 1273 EXPECT_NE(nullptr, test_position);
1249 EXPECT_TRUE(test_position->IsTextPosition()); 1274 EXPECT_TRUE(test_position->IsTextPosition());
1250 EXPECT_EQ(check_box_.id, test_position->anchor_id()); 1275 EXPECT_EQ(check_box_.id, test_position->anchor_id());
1251 EXPECT_EQ(8, test_position->text_offset()); 1276 EXPECT_EQ(8, test_position->text_offset());
1252 1277
1253 text_position = AXNodePosition::CreateTextPosition( 1278 text_position =
1254 tree_.data().tree_id, text_field_.id, 1 /* text_offset */, 1279 CreateTextPosition(tree_.data().tree_id, text_field_.id,
1255 AX_TEXT_AFFINITY_UPSTREAM); 1280 1 /* text_offset */, AX_TEXT_AFFINITY_UPSTREAM);
1256 ASSERT_NE(nullptr, text_position); 1281 ASSERT_NE(nullptr, text_position);
1257 test_position = text_position->CreatePreviousCharacterPosition(); 1282 test_position = text_position->CreatePreviousCharacterPosition();
1258 EXPECT_NE(nullptr, test_position); 1283 EXPECT_NE(nullptr, test_position);
1259 EXPECT_TRUE(test_position->IsTextPosition()); 1284 EXPECT_TRUE(test_position->IsTextPosition());
1260 EXPECT_EQ(text_field_.id, test_position->anchor_id()); 1285 EXPECT_EQ(text_field_.id, test_position->anchor_id());
1261 EXPECT_EQ(0, test_position->text_offset()); 1286 EXPECT_EQ(0, test_position->text_offset());
1262 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, test_position->affinity()); 1287 EXPECT_EQ(AX_TEXT_AFFINITY_DOWNSTREAM, test_position->affinity());
1263 } 1288 }
1264 1289
1265 TEST_F(AXPositionTest, CreateNextAndPreviousWordStartPositionWithNullPosition) { 1290 TEST_F(AXPositionTest, CreateNextAndPreviousWordStartPositionWithNullPosition) {
1266 TestPositionType null_position = AXNodePosition::CreateNullPosition(); 1291 TestPositionType null_position = CreateNullPosition();
1267 ASSERT_NE(nullptr, null_position); 1292 ASSERT_NE(nullptr, null_position);
1268 TestPositionType test_position = null_position->CreateNextWordStartPosition(); 1293 TestPositionType test_position = null_position->CreateNextWordStartPosition();
1269 EXPECT_NE(nullptr, test_position); 1294 EXPECT_NE(nullptr, test_position);
1270 EXPECT_TRUE(test_position->IsNullPosition()); 1295 EXPECT_TRUE(test_position->IsNullPosition());
1271 test_position = null_position->CreatePreviousWordStartPosition(); 1296 test_position = null_position->CreatePreviousWordStartPosition();
1272 EXPECT_NE(nullptr, test_position); 1297 EXPECT_NE(nullptr, test_position);
1273 EXPECT_TRUE(test_position->IsNullPosition()); 1298 EXPECT_TRUE(test_position->IsNullPosition());
1274 } 1299 }
1275 1300
1276 TEST_F(AXPositionTest, CreateNextAndPreviousWordEndPositionWithNullPosition) { 1301 TEST_F(AXPositionTest, CreateNextAndPreviousWordEndPositionWithNullPosition) {
1277 TestPositionType null_position = AXNodePosition::CreateNullPosition(); 1302 TestPositionType null_position = CreateNullPosition();
1278 ASSERT_NE(nullptr, null_position); 1303 ASSERT_NE(nullptr, null_position);
1279 TestPositionType test_position = null_position->CreateNextWordEndPosition(); 1304 TestPositionType test_position = null_position->CreateNextWordEndPosition();
1280 EXPECT_NE(nullptr, test_position); 1305 EXPECT_NE(nullptr, test_position);
1281 EXPECT_TRUE(test_position->IsNullPosition()); 1306 EXPECT_TRUE(test_position->IsNullPosition());
1282 test_position = null_position->CreatePreviousWordEndPosition(); 1307 test_position = null_position->CreatePreviousWordEndPosition();
1283 EXPECT_NE(nullptr, test_position); 1308 EXPECT_NE(nullptr, test_position);
1284 EXPECT_TRUE(test_position->IsNullPosition()); 1309 EXPECT_TRUE(test_position->IsNullPosition());
1285 } 1310 }
1286 1311
1287 TEST_F(AXPositionTest, OperatorEquals) { 1312 TEST_F(AXPositionTest, OperatorEquals) {
1288 TestPositionType null_position1 = AXNodePosition::CreateNullPosition(); 1313 TestPositionType null_position1 = CreateNullPosition();
1289 ASSERT_NE(nullptr, null_position1); 1314 ASSERT_NE(nullptr, null_position1);
1290 TestPositionType null_position2 = AXNodePosition::CreateNullPosition(); 1315 TestPositionType null_position2 = CreateNullPosition();
1291 ASSERT_NE(nullptr, null_position2); 1316 ASSERT_NE(nullptr, null_position2);
1292 EXPECT_EQ(*null_position1, *null_position2); 1317 EXPECT_EQ(*null_position1, *null_position2);
1293 1318
1294 // Child indices must match. 1319 // Child indices must match.
1295 TestPositionType button_position1 = AXNodePosition::CreateTreePosition( 1320 TestPositionType button_position1 =
1296 tree_.data().tree_id, root_.id, 0 /* child_index */); 1321 CreateTreePosition(tree_.data().tree_id, root_.id, 0 /* child_index */);
1297 ASSERT_NE(nullptr, button_position1); 1322 ASSERT_NE(nullptr, button_position1);
1298 TestPositionType button_position2 = AXNodePosition::CreateTreePosition( 1323 TestPositionType button_position2 =
1299 tree_.data().tree_id, root_.id, 0 /* child_index */); 1324 CreateTreePosition(tree_.data().tree_id, root_.id, 0 /* child_index */);
1300 ASSERT_NE(nullptr, button_position2); 1325 ASSERT_NE(nullptr, button_position2);
1301 EXPECT_EQ(*button_position1, *button_position2); 1326 EXPECT_EQ(*button_position1, *button_position2);
1302 1327
1303 // Both child indices are invalid. It should result in equivalent null 1328 // Both child indices are invalid. It should result in equivalent null
1304 // positions. 1329 // positions.
1305 TestPositionType tree_position1 = AXNodePosition::CreateTreePosition( 1330 TestPositionType tree_position1 =
1306 tree_.data().tree_id, root_.id, 4 /* child_index */); 1331 CreateTreePosition(tree_.data().tree_id, root_.id, 4 /* child_index */);
1307 ASSERT_NE(nullptr, tree_position1); 1332 ASSERT_NE(nullptr, tree_position1);
1308 TestPositionType tree_position2 = AXNodePosition::CreateTreePosition( 1333 TestPositionType tree_position2 = CreateTreePosition(
1309 tree_.data().tree_id, root_.id, AXNodePosition::INVALID_INDEX); 1334 tree_.data().tree_id, root_.id, AXNodePosition::INVALID_INDEX);
1310 ASSERT_NE(nullptr, tree_position2); 1335 ASSERT_NE(nullptr, tree_position2);
1311 EXPECT_EQ(*tree_position1, *tree_position2); 1336 EXPECT_EQ(*tree_position1, *tree_position2);
1312 1337
1313 // An invalid position should not be equivalent to an "after children" 1338 // An invalid position should not be equivalent to an "after children"
1314 // position. 1339 // position.
1315 tree_position1 = AXNodePosition::CreateTreePosition( 1340 tree_position1 =
1316 tree_.data().tree_id, root_.id, 3 /* child_index */); 1341 CreateTreePosition(tree_.data().tree_id, root_.id, 3 /* child_index */);
1317 ASSERT_NE(nullptr, tree_position1); 1342 ASSERT_NE(nullptr, tree_position1);
1318 tree_position2 = AXNodePosition::CreateTreePosition( 1343 tree_position2 =
1319 tree_.data().tree_id, root_.id, -1 /* child_index */); 1344 CreateTreePosition(tree_.data().tree_id, root_.id, -1 /* child_index */);
1320 ASSERT_NE(nullptr, tree_position2); 1345 ASSERT_NE(nullptr, tree_position2);
1321 EXPECT_NE(*tree_position1, *tree_position2); 1346 EXPECT_NE(*tree_position1, *tree_position2);
1322 1347
1323 // Two "after children" positions on the same node should be equivalent. 1348 // Two "after children" positions on the same node should be equivalent.
1324 tree_position1 = AXNodePosition::CreateTreePosition( 1349 tree_position1 = CreateTreePosition(tree_.data().tree_id, text_field_.id,
1325 tree_.data().tree_id, text_field_.id, 3 /* child_index */); 1350 3 /* child_index */);
1326 ASSERT_NE(nullptr, tree_position1); 1351 ASSERT_NE(nullptr, tree_position1);
1327 tree_position2 = AXNodePosition::CreateTreePosition( 1352 tree_position2 = CreateTreePosition(tree_.data().tree_id, text_field_.id,
1328 tree_.data().tree_id, text_field_.id, 3 /* child_index */); 1353 3 /* child_index */);
1329 ASSERT_NE(nullptr, tree_position2); 1354 ASSERT_NE(nullptr, tree_position2);
1330 EXPECT_EQ(*tree_position1, *tree_position2); 1355 EXPECT_EQ(*tree_position1, *tree_position2);
1331 1356
1332 // Two "before text" positions on the same node should be equivalent. 1357 // Two "before text" positions on the same node should be equivalent.
1333 tree_position1 = AXNodePosition::CreateTreePosition( 1358 tree_position1 = CreateTreePosition(tree_.data().tree_id, inline_box1_.id,
1334 tree_.data().tree_id, inline_box1_.id, AXNodePosition::BEFORE_TEXT); 1359 AXNodePosition::BEFORE_TEXT);
1335 ASSERT_NE(nullptr, tree_position1); 1360 ASSERT_NE(nullptr, tree_position1);
1336 tree_position2 = AXNodePosition::CreateTreePosition( 1361 tree_position2 = CreateTreePosition(tree_.data().tree_id, inline_box1_.id,
1337 tree_.data().tree_id, inline_box1_.id, AXNodePosition::BEFORE_TEXT); 1362 AXNodePosition::BEFORE_TEXT);
1338 ASSERT_NE(nullptr, tree_position2); 1363 ASSERT_NE(nullptr, tree_position2);
1339 EXPECT_EQ(*tree_position1, *tree_position2); 1364 EXPECT_EQ(*tree_position1, *tree_position2);
1340 1365
1341 // Both text offsets are invalid. It should result in equivalent null 1366 // Both text offsets are invalid. It should result in equivalent null
1342 // positions. 1367 // positions.
1343 TestPositionType text_position1 = AXNodePosition::CreateTextPosition( 1368 TestPositionType text_position1 =
1344 tree_.data().tree_id, inline_box1_.id, 15 /* text_offset */, 1369 CreateTextPosition(tree_.data().tree_id, inline_box1_.id,
1345 AX_TEXT_AFFINITY_UPSTREAM); 1370 15 /* text_offset */, AX_TEXT_AFFINITY_UPSTREAM);
1346 ASSERT_NE(nullptr, text_position1); 1371 ASSERT_NE(nullptr, text_position1);
1347 TestPositionType text_position2 = AXNodePosition::CreateTextPosition( 1372 TestPositionType text_position2 =
1348 tree_.data().tree_id, text_field_.id, -1 /* text_offset */, 1373 CreateTextPosition(tree_.data().tree_id, text_field_.id,
1349 AX_TEXT_AFFINITY_UPSTREAM); 1374 -1 /* text_offset */, AX_TEXT_AFFINITY_UPSTREAM);
1350 ASSERT_NE(nullptr, text_position2); 1375 ASSERT_NE(nullptr, text_position2);
1351 EXPECT_EQ(*text_position1, *text_position2); 1376 EXPECT_EQ(*text_position1, *text_position2);
1352 1377
1353 text_position1 = AXNodePosition::CreateTextPosition( 1378 text_position1 =
1354 tree_.data().tree_id, inline_box1_.id, 0 /* text_offset */, 1379 CreateTextPosition(tree_.data().tree_id, inline_box1_.id,
1355 AX_TEXT_AFFINITY_DOWNSTREAM); 1380 0 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
1356 ASSERT_NE(nullptr, text_position1); 1381 ASSERT_NE(nullptr, text_position1);
1357 text_position2 = AXNodePosition::CreateTextPosition( 1382 text_position2 =
1358 tree_.data().tree_id, inline_box1_.id, 0 /* text_offset */, 1383 CreateTextPosition(tree_.data().tree_id, inline_box1_.id,
1359 AX_TEXT_AFFINITY_DOWNSTREAM); 1384 0 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
1360 ASSERT_NE(nullptr, text_position2); 1385 ASSERT_NE(nullptr, text_position2);
1361 EXPECT_EQ(*text_position1, *text_position2); 1386 EXPECT_EQ(*text_position1, *text_position2);
1362 1387
1363 // Affinities should match. 1388 // Affinities should match.
1364 text_position2 = AXNodePosition::CreateTextPosition( 1389 text_position2 =
1365 tree_.data().tree_id, inline_box1_.id, 0 /* text_offset */, 1390 CreateTextPosition(tree_.data().tree_id, inline_box1_.id,
1366 AX_TEXT_AFFINITY_UPSTREAM); 1391 0 /* text_offset */, AX_TEXT_AFFINITY_UPSTREAM);
1367 ASSERT_NE(nullptr, text_position2); 1392 ASSERT_NE(nullptr, text_position2);
1368 EXPECT_NE(*text_position1, *text_position2); 1393 EXPECT_NE(*text_position1, *text_position2);
1369 1394
1370 // Text offsets should match. 1395 // Text offsets should match.
1371 text_position1 = AXNodePosition::CreateTextPosition( 1396 text_position1 =
1372 tree_.data().tree_id, inline_box1_.id, 5 /* text_offset */, 1397 CreateTextPosition(tree_.data().tree_id, inline_box1_.id,
1373 AX_TEXT_AFFINITY_UPSTREAM); 1398 5 /* text_offset */, AX_TEXT_AFFINITY_UPSTREAM);
1374 ASSERT_NE(nullptr, text_position1); 1399 ASSERT_NE(nullptr, text_position1);
1375 EXPECT_NE(*text_position1, *text_position2); 1400 EXPECT_NE(*text_position1, *text_position2);
1376 1401
1377 // Two "after text" positions on the same node should be equivalent. 1402 // Two "after text" positions on the same node should be equivalent.
1378 text_position1 = AXNodePosition::CreateTextPosition( 1403 text_position1 =
1379 tree_.data().tree_id, line_break_.id, 1 /* text_offset */, 1404 CreateTextPosition(tree_.data().tree_id, line_break_.id,
1380 AX_TEXT_AFFINITY_UPSTREAM); 1405 1 /* text_offset */, AX_TEXT_AFFINITY_UPSTREAM);
1381 ASSERT_NE(nullptr, text_position1); 1406 ASSERT_NE(nullptr, text_position1);
1382 text_position2 = AXNodePosition::CreateTextPosition( 1407 text_position2 =
1383 tree_.data().tree_id, line_break_.id, 1 /* text_offset */, 1408 CreateTextPosition(tree_.data().tree_id, line_break_.id,
1384 AX_TEXT_AFFINITY_UPSTREAM); 1409 1 /* text_offset */, AX_TEXT_AFFINITY_UPSTREAM);
1385 ASSERT_NE(nullptr, text_position2); 1410 ASSERT_NE(nullptr, text_position2);
1386 EXPECT_EQ(*text_position1, *text_position2); 1411 EXPECT_EQ(*text_position1, *text_position2);
1387 } 1412 }
1388 1413
1389 TEST_F(AXPositionTest, OperatorsLessThanAndGreaterThan) { 1414 TEST_F(AXPositionTest, OperatorsLessThanAndGreaterThan) {
1390 TestPositionType null_position1 = AXNodePosition::CreateNullPosition(); 1415 TestPositionType null_position1 = CreateNullPosition();
1391 ASSERT_NE(nullptr, null_position1); 1416 ASSERT_NE(nullptr, null_position1);
1392 TestPositionType null_position2 = AXNodePosition::CreateNullPosition(); 1417 TestPositionType null_position2 = CreateNullPosition();
1393 ASSERT_NE(nullptr, null_position2); 1418 ASSERT_NE(nullptr, null_position2);
1394 EXPECT_FALSE(*null_position1 < *null_position2); 1419 EXPECT_FALSE(*null_position1 < *null_position2);
1395 EXPECT_FALSE(*null_position1 > *null_position2); 1420 EXPECT_FALSE(*null_position1 > *null_position2);
1396 1421
1397 TestPositionType button_position1 = AXNodePosition::CreateTreePosition( 1422 TestPositionType button_position1 =
1398 tree_.data().tree_id, root_.id, 0 /* child_index */); 1423 CreateTreePosition(tree_.data().tree_id, root_.id, 0 /* child_index */);
1399 ASSERT_NE(nullptr, button_position1); 1424 ASSERT_NE(nullptr, button_position1);
1400 TestPositionType button_position2 = AXNodePosition::CreateTreePosition( 1425 TestPositionType button_position2 =
1401 tree_.data().tree_id, root_.id, 1 /* child_index */); 1426 CreateTreePosition(tree_.data().tree_id, root_.id, 1 /* child_index */);
1402 ASSERT_NE(nullptr, button_position2); 1427 ASSERT_NE(nullptr, button_position2);
1403 EXPECT_LT(*button_position1, *button_position2); 1428 EXPECT_LT(*button_position1, *button_position2);
1404 EXPECT_GT(*button_position2, *button_position1); 1429 EXPECT_GT(*button_position2, *button_position1);
1405 1430
1406 TestPositionType tree_position1 = AXNodePosition::CreateTreePosition( 1431 TestPositionType tree_position1 = CreateTreePosition(
1407 tree_.data().tree_id, text_field_.id, 2 /* child_index */); 1432 tree_.data().tree_id, text_field_.id, 2 /* child_index */);
1408 ASSERT_NE(nullptr, tree_position1); 1433 ASSERT_NE(nullptr, tree_position1);
1409 // An "after children" position. 1434 // An "after children" position.
1410 TestPositionType tree_position2 = AXNodePosition::CreateTreePosition( 1435 TestPositionType tree_position2 = CreateTreePosition(
1411 tree_.data().tree_id, text_field_.id, 3 /* child_index */); 1436 tree_.data().tree_id, text_field_.id, 3 /* child_index */);
1412 ASSERT_NE(nullptr, tree_position2); 1437 ASSERT_NE(nullptr, tree_position2);
1413 EXPECT_LT(*tree_position1, *tree_position2); 1438 EXPECT_LT(*tree_position1, *tree_position2);
1414 EXPECT_GT(*tree_position2, *tree_position1); 1439 EXPECT_GT(*tree_position2, *tree_position1);
1415 1440
1416 // A "before text" position. 1441 // A "before text" position.
1417 tree_position1 = AXNodePosition::CreateTreePosition( 1442 tree_position1 = CreateTreePosition(tree_.data().tree_id, inline_box1_.id,
1418 tree_.data().tree_id, inline_box1_.id, AXNodePosition::BEFORE_TEXT); 1443 AXNodePosition::BEFORE_TEXT);
1419 ASSERT_NE(nullptr, tree_position1); 1444 ASSERT_NE(nullptr, tree_position1);
1420 // An "after text" position. 1445 // An "after text" position.
1421 tree_position2 = AXNodePosition::CreateTreePosition( 1446 tree_position2 = CreateTreePosition(tree_.data().tree_id, inline_box1_.id,
1422 tree_.data().tree_id, inline_box1_.id, 0 /* child_index */); 1447 0 /* child_index */);
1423 ASSERT_NE(nullptr, tree_position2); 1448 ASSERT_NE(nullptr, tree_position2);
1424 EXPECT_LT(*tree_position1, *tree_position2); 1449 EXPECT_LT(*tree_position1, *tree_position2);
1425 EXPECT_GT(*tree_position2, *tree_position1); 1450 EXPECT_GT(*tree_position2, *tree_position1);
1426 1451
1427 TestPositionType text_position1 = AXNodePosition::CreateTextPosition( 1452 TestPositionType text_position1 =
1428 tree_.data().tree_id, inline_box1_.id, 2 /* text_offset */, 1453 CreateTextPosition(tree_.data().tree_id, inline_box1_.id,
1429 AX_TEXT_AFFINITY_DOWNSTREAM); 1454 2 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
1430 ASSERT_NE(nullptr, text_position1); 1455 ASSERT_NE(nullptr, text_position1);
1431 TestPositionType text_position2 = AXNodePosition::CreateTextPosition( 1456 TestPositionType text_position2 =
1432 tree_.data().tree_id, inline_box1_.id, 0 /* text_offset */, 1457 CreateTextPosition(tree_.data().tree_id, inline_box1_.id,
1433 AX_TEXT_AFFINITY_DOWNSTREAM); 1458 0 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
1434 ASSERT_NE(nullptr, text_position2); 1459 ASSERT_NE(nullptr, text_position2);
1435 EXPECT_GT(*text_position1, *text_position2); 1460 EXPECT_GT(*text_position1, *text_position2);
1436 EXPECT_LT(*text_position2, *text_position1); 1461 EXPECT_LT(*text_position2, *text_position1);
1437 1462
1438 // Affinities should not matter. 1463 // Affinities should not matter.
1439 text_position2 = AXNodePosition::CreateTextPosition( 1464 text_position2 =
1440 tree_.data().tree_id, inline_box1_.id, 0 /* text_offset */, 1465 CreateTextPosition(tree_.data().tree_id, inline_box1_.id,
1441 AX_TEXT_AFFINITY_UPSTREAM); 1466 0 /* text_offset */, AX_TEXT_AFFINITY_UPSTREAM);
1442 ASSERT_NE(nullptr, text_position2); 1467 ASSERT_NE(nullptr, text_position2);
1443 EXPECT_GT(*text_position1, *text_position2); 1468 EXPECT_GT(*text_position1, *text_position2);
1444 EXPECT_LT(*text_position2, *text_position1); 1469 EXPECT_LT(*text_position2, *text_position1);
1445 1470
1446 // An "after text" position. 1471 // An "after text" position.
1447 text_position1 = AXNodePosition::CreateTextPosition( 1472 text_position1 =
1448 tree_.data().tree_id, line_break_.id, 1 /* text_offset */, 1473 CreateTextPosition(tree_.data().tree_id, line_break_.id,
1449 AX_TEXT_AFFINITY_UPSTREAM); 1474 1 /* text_offset */, AX_TEXT_AFFINITY_UPSTREAM);
1450 ASSERT_NE(nullptr, text_position1); 1475 ASSERT_NE(nullptr, text_position1);
1451 // A "before text" position. 1476 // A "before text" position.
1452 text_position2 = AXNodePosition::CreateTextPosition( 1477 text_position2 =
1453 tree_.data().tree_id, line_break_.id, 0 /* text_offset */, 1478 CreateTextPosition(tree_.data().tree_id, line_break_.id,
1454 AX_TEXT_AFFINITY_UPSTREAM); 1479 0 /* text_offset */, AX_TEXT_AFFINITY_UPSTREAM);
1455 ASSERT_NE(nullptr, text_position2); 1480 ASSERT_NE(nullptr, text_position2);
1456 EXPECT_GT(*text_position1, *text_position2); 1481 EXPECT_GT(*text_position1, *text_position2);
1457 EXPECT_LT(*text_position2, *text_position1); 1482 EXPECT_LT(*text_position2, *text_position1);
1458 } 1483 }
1459 1484
1460 // 1485 //
1461 // Parameterized tests. 1486 // Parameterized tests.
1462 // 1487 //
1463 1488
1464 TEST_P(AXPositionTestWithParam, TraverseTreeStartingWithAffinityDownstream) { 1489 TEST_P(AXPositionTestWithParam, TraverseTreeStartingWithAffinityDownstream) {
1465 TestPositionType text_position = AXNodePosition::CreateTextPosition( 1490 TestPositionType text_position =
1466 tree_.data().tree_id, GetParam().start_node_id_, GetParam().start_offset_, 1491 CreateTextPosition(tree_.data().tree_id, GetParam().start_node_id_,
1467 AX_TEXT_AFFINITY_DOWNSTREAM); 1492 GetParam().start_offset_, AX_TEXT_AFFINITY_DOWNSTREAM);
1468 for (const std::string& expectation : GetParam().expectations) { 1493 for (const std::string& expectation : GetParam().expectations) {
1469 text_position = GetParam().TestMethod.Run(text_position); 1494 text_position = GetParam().TestMethod.Run(text_position);
1470 EXPECT_NE(nullptr, text_position); 1495 EXPECT_NE(nullptr, text_position);
1471 EXPECT_EQ(expectation, text_position->ToString()); 1496 EXPECT_EQ(expectation, text_position->ToString());
1472 } 1497 }
1473 } 1498 }
1474 1499
1475 TEST_P(AXPositionTestWithParam, TraverseTreeStartingWithAffinityUpstream) { 1500 TEST_P(AXPositionTestWithParam, TraverseTreeStartingWithAffinityUpstream) {
1476 TestPositionType text_position = AXNodePosition::CreateTextPosition( 1501 TestPositionType text_position =
1477 tree_.data().tree_id, GetParam().start_node_id_, GetParam().start_offset_, 1502 CreateTextPosition(tree_.data().tree_id, GetParam().start_node_id_,
1478 AX_TEXT_AFFINITY_UPSTREAM); 1503 GetParam().start_offset_, AX_TEXT_AFFINITY_UPSTREAM);
1479 for (const std::string& expectation : GetParam().expectations) { 1504 for (const std::string& expectation : GetParam().expectations) {
1480 text_position = GetParam().TestMethod.Run(text_position); 1505 text_position = GetParam().TestMethod.Run(text_position);
1481 EXPECT_NE(nullptr, text_position); 1506 EXPECT_NE(nullptr, text_position);
1482 EXPECT_EQ(expectation, text_position->ToString()); 1507 EXPECT_EQ(expectation, text_position->ToString());
1483 } 1508 }
1484 } 1509 }
1485 1510
1486 // 1511 //
1487 // Instantiations of parameterized tests. 1512 // Instantiations of parameterized tests.
1488 // 1513 //
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
1973 // Tests for |AXRange|. 1998 // Tests for |AXRange|.
1974 // 1999 //
1975 2000
1976 // TODO(nektar): Move these tests to their own file. 2001 // TODO(nektar): Move these tests to their own file.
1977 2002
1978 TEST_F(AXPositionTest, AXRangeGetTextWithWholeObjects) { 2003 TEST_F(AXPositionTest, AXRangeGetTextWithWholeObjects) {
1979 base::string16 all_text = base::UTF8ToUTF16("ButtonCheck boxLine 1\nLine 2"); 2004 base::string16 all_text = base::UTF8ToUTF16("ButtonCheck boxLine 1\nLine 2");
1980 // Create a range starting from the button object and ending at the last 2005 // Create a range starting from the button object and ending at the last
1981 // character of the root, i.e. at the last character of the second line in the 2006 // character of the root, i.e. at the last character of the second line in the
1982 // text field. 2007 // text field.
1983 TestPositionType start = AXNodePosition::CreateTreePosition( 2008 TestPositionType start =
1984 tree_.data().tree_id, root_.id, 0 /* child_index */); 2009 CreateTreePosition(tree_.data().tree_id, root_.id, 0 /* child_index */);
1985 TestPositionType end = AXNodePosition::CreateTextPosition( 2010 TestPositionType end =
1986 tree_.data().tree_id, root_.id, 28 /* text_offset */, 2011 CreateTextPosition(tree_.data().tree_id, root_.id, 28 /* text_offset */,
1987 AX_TEXT_AFFINITY_DOWNSTREAM); 2012 AX_TEXT_AFFINITY_DOWNSTREAM);
1988 AXRange<AXPosition<AXNodePosition, AXNode>> forward_range(start->Clone(), 2013 ui::AXAbstractRange forward_range(start->Clone(), end->Clone());
1989 end->Clone());
1990 EXPECT_EQ(all_text, forward_range.GetText()); 2014 EXPECT_EQ(all_text, forward_range.GetText());
1991 AXRange<AXPosition<AXNodePosition, AXNode>> backward_range(std::move(end), 2015 ui::AXAbstractRange backward_range(std::move(end), std::move(start));
1992 std::move(start));
1993 EXPECT_EQ(all_text, backward_range.GetText()); 2016 EXPECT_EQ(all_text, backward_range.GetText());
1994 } 2017 }
1995 2018
1996 TEST_F(AXPositionTest, AXRangeGetTextWithTextOffsets) { 2019 TEST_F(AXPositionTest, AXRangeGetTextWithTextOffsets) {
1997 base::string16 most_text = base::UTF8ToUTF16("tonCheck boxLine 1\nLine"); 2020 base::string16 most_text = base::UTF8ToUTF16("tonCheck boxLine 1\nLine");
1998 // Create a range starting from the third character in the button object and 2021 // Create a range starting from the third character in the button object and
1999 // ending two characters before the end of the root. 2022 // ending two characters before the end of the root.
2000 TestPositionType start = AXNodePosition::CreateTextPosition( 2023 TestPositionType start =
2001 tree_.data().tree_id, button_.id, 3 /* text_offset */, 2024 CreateTextPosition(tree_.data().tree_id, button_.id, 3 /* text_offset */,
2002 AX_TEXT_AFFINITY_DOWNSTREAM); 2025 AX_TEXT_AFFINITY_DOWNSTREAM);
2003 TestPositionType end = AXNodePosition::CreateTextPosition( 2026 TestPositionType end =
2004 tree_.data().tree_id, static_text2_.id, 4 /* text_offset */, 2027 CreateTextPosition(tree_.data().tree_id, static_text2_.id,
2005 AX_TEXT_AFFINITY_DOWNSTREAM); 2028 4 /* text_offset */, AX_TEXT_AFFINITY_DOWNSTREAM);
2006 AXRange<AXPosition<AXNodePosition, AXNode>> forward_range(start->Clone(), 2029 ui::AXAbstractRange forward_range(start->Clone(), end->Clone());
2007 end->Clone());
2008 EXPECT_EQ(most_text, forward_range.GetText()); 2030 EXPECT_EQ(most_text, forward_range.GetText());
2009 AXRange<AXPosition<AXNodePosition, AXNode>> backward_range(std::move(end), 2031 ui::AXAbstractRange backward_range(std::move(end), std::move(start));
2010 std::move(start));
2011 EXPECT_EQ(most_text, backward_range.GetText()); 2032 EXPECT_EQ(most_text, backward_range.GetText());
2012 } 2033 }
2013 2034
2014 } // namespace ui 2035 } // namespace ui
OLDNEW
« no previous file with comments | « ui/accessibility/ax_node_position.cc ('k') | ui/accessibility/ax_position.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698