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

Side by Side Diff: third_party/WebKit/Source/core/editing/GranularityStrategyTest.cpp

Issue 2374183004: Make non-null VisibleSelections creatable only by createVisibleSelection[Deprecated] (Closed)
Patch Set: Fix mac compile error Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "bindings/core/v8/ExceptionStatePlaceholder.h" 5 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
6 #include "core/dom/Document.h" 6 #include "core/dom/Document.h"
7 #include "core/dom/Element.h" 7 #include "core/dom/Element.h"
8 #include "core/dom/Text.h" 8 #include "core/dom/Text.h"
9 #include "core/editing/FrameSelection.h" 9 #include "core/editing/FrameSelection.h"
10 #include "core/frame/FrameView.h" 10 #include "core/frame/FrameView.h"
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 p1 = Position(text2, selBegin - str1.length()); 253 p1 = Position(text2, selBegin - str1.length());
254 else 254 else
255 p1 = Position(text3, selBegin - str1.length() - str2.length()); 255 p1 = Position(text3, selBegin - str1.length() - str2.length());
256 if (selEnd < str1.length()) 256 if (selEnd < str1.length())
257 p2 = Position(text1, selEnd); 257 p2 = Position(text1, selEnd);
258 else if (selEnd < str1.length() + str2.length()) 258 else if (selEnd < str1.length() + str2.length())
259 p2 = Position(text2, selEnd - str1.length()); 259 p2 = Position(text2, selEnd - str1.length());
260 else 260 else
261 p2 = Position(text3, selEnd - str1.length() - str2.length()); 261 p2 = Position(text3, selEnd - str1.length() - str2.length());
262 262
263 selection().setSelection(VisibleSelection(p1, p2)); 263 selection().setSelection(createVisibleSelectionDeprecated(p1, p2));
264 } 264 }
265 265
266 void GranularityStrategyTest::setupVerticalAlign(String str1, String str2, Strin g str3, size_t selBegin, size_t selEnd) 266 void GranularityStrategyTest::setupVerticalAlign(String str1, String str2, Strin g str3, size_t selBegin, size_t selEnd)
267 { 267 {
268 setInnerHTML( 268 setInnerHTML(
269 "<html>" 269 "<html>"
270 "<head>" 270 "<head>"
271 "<style>" 271 "<style>"
272 "span {" 272 "span {"
273 "vertical-align:20px;" 273 "vertical-align:20px;"
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 // Test for the default CharacterGranularityStrategy 476 // Test for the default CharacterGranularityStrategy
477 TEST_F(GranularityStrategyTest, Character) 477 TEST_F(GranularityStrategyTest, Character)
478 { 478 {
479 dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy ::Character); 479 dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy ::Character);
480 dummyPageHolder().frame().settings()->setDefaultFontSize(12); 480 dummyPageHolder().frame().settings()->setDefaultFontSize(12);
481 // "Foo Bar Baz," 481 // "Foo Bar Baz,"
482 Text* text = appendTextNode("Foo Bar Baz,"); 482 Text* text = appendTextNode("Foo Bar Baz,");
483 document().updateStyleAndLayout(); 483 document().updateStyleAndLayout();
484 484
485 // "Foo B^a|>r Baz," (^ means base, | means extent, , < means start, and > m eans end). 485 // "Foo B^a|>r Baz," (^ means base, | means extent, , < means start, and > m eans end).
486 selection().setSelection(VisibleSelection(Position(text, 5), Position(text, 6))); 486 selection().setSelection(createVisibleSelectionDeprecated(Position(text, 5), Position(text, 6)));
487 EXPECT_EQ_SELECTED_TEXT("a"); 487 EXPECT_EQ_SELECTED_TEXT("a");
488 // "Foo B^ar B|>az," 488 // "Foo B^ar B|>az,"
489 selection().moveRangeSelectionExtent(visiblePositionToContentsPoint(createVi siblePosition(Position(text, 9)))); 489 selection().moveRangeSelectionExtent(visiblePositionToContentsPoint(createVi siblePosition(Position(text, 9))));
490 EXPECT_EQ_SELECTED_TEXT("ar B"); 490 EXPECT_EQ_SELECTED_TEXT("ar B");
491 // "F<|oo B^ar Baz," 491 // "F<|oo B^ar Baz,"
492 selection().moveRangeSelectionExtent(visiblePositionToContentsPoint(createVi siblePosition(Position(text, 1)))); 492 selection().moveRangeSelectionExtent(visiblePositionToContentsPoint(createVi siblePosition(Position(text, 1))));
493 EXPECT_EQ_SELECTED_TEXT("oo B"); 493 EXPECT_EQ_SELECTED_TEXT("oo B");
494 } 494 }
495 495
496 // DirectionGranularityStrategy strategy on rotated text should revert to the 496 // DirectionGranularityStrategy strategy on rotated text should revert to the
497 // same behavior as CharacterGranularityStrategy 497 // same behavior as CharacterGranularityStrategy
498 TEST_F(GranularityStrategyTest, DirectionRotate) 498 TEST_F(GranularityStrategyTest, DirectionRotate)
499 { 499 {
500 Text* text = setupRotate("Foo Bar Baz,"); 500 Text* text = setupRotate("Foo Bar Baz,");
501 // "Foo B^a|>r Baz," (^ means base, | means extent, , < means start, and > m eans end). 501 // "Foo B^a|>r Baz," (^ means base, | means extent, , < means start, and > m eans end).
502 selection().setSelection(VisibleSelection(Position(text, 5), Position(text, 6))); 502 selection().setSelection(createVisibleSelectionDeprecated(Position(text, 5), Position(text, 6)));
503 EXPECT_EQ_SELECTED_TEXT("a"); 503 EXPECT_EQ_SELECTED_TEXT("a");
504 IntPoint p = m_letterPos[9]; 504 IntPoint p = m_letterPos[9];
505 // Need to move by one pixel, otherwise this point is not evaluated 505 // Need to move by one pixel, otherwise this point is not evaluated
506 // to the same line as the text by hit testing. 506 // to the same line as the text by hit testing.
507 p.move(1, 0); 507 p.move(1, 0);
508 // "Foo B^ar B|>az," 508 // "Foo B^ar B|>az,"
509 selection().moveRangeSelectionExtent(p); 509 selection().moveRangeSelectionExtent(p);
510 EXPECT_EQ_SELECTED_TEXT("ar B"); 510 EXPECT_EQ_SELECTED_TEXT("ar B");
511 p = m_letterPos[1]; 511 p = m_letterPos[1];
512 p.move(1, 0); 512 p.move(1, 0);
513 // "F<|oo B^ar Baz," 513 // "F<|oo B^ar Baz,"
514 selection().moveRangeSelectionExtent(p); 514 selection().moveRangeSelectionExtent(p);
515 EXPECT_EQ_SELECTED_TEXT("oo B"); 515 EXPECT_EQ_SELECTED_TEXT("oo B");
516 } 516 }
517 517
518 TEST_F(GranularityStrategyTest, DirectionExpandTranslateZ) 518 TEST_F(GranularityStrategyTest, DirectionExpandTranslateZ)
519 { 519 {
520 Text* text = setupTranslateZ("abcdef ghij kl mnopqr stuvwi inm mnii,"); 520 Text* text = setupTranslateZ("abcdef ghij kl mnopqr stuvwi inm mnii,");
521 // "abcdef ghij kl mno^p|>qr stuvwi inm mnii," (^ means base, | means exten t, < means start, and > means end). 521 // "abcdef ghij kl mno^p|>qr stuvwi inm mnii," (^ means base, | means exten t, < means start, and > means end).
522 selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 19))); 522 selection().setSelection(createVisibleSelectionDeprecated(Position(text, 18) , Position(text, 19)));
523 EXPECT_EQ_SELECTED_TEXT("p"); 523 EXPECT_EQ_SELECTED_TEXT("p");
524 testDirectionExpand(); 524 testDirectionExpand();
525 } 525 }
526 526
527 TEST_F(GranularityStrategyTest, DirectionExpandTransform) 527 TEST_F(GranularityStrategyTest, DirectionExpandTransform)
528 { 528 {
529 Text* text = setupTransform("abcdef ghij kl mnopqr stuvwi inm mnii,"); 529 Text* text = setupTransform("abcdef ghij kl mnopqr stuvwi inm mnii,");
530 // "abcdef ghij kl mno^p|>qr stuvwi inm mnii," (^ means base, | means exten t, < means start, and > means end). 530 // "abcdef ghij kl mno^p|>qr stuvwi inm mnii," (^ means base, | means exten t, < means start, and > means end).
531 selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 19))); 531 selection().setSelection(createVisibleSelectionDeprecated(Position(text, 18) , Position(text, 19)));
532 EXPECT_EQ_SELECTED_TEXT("p"); 532 EXPECT_EQ_SELECTED_TEXT("p");
533 testDirectionExpand(); 533 testDirectionExpand();
534 } 534 }
535 535
536 TEST_F(GranularityStrategyTest, DirectionExpandVerticalAlign) 536 TEST_F(GranularityStrategyTest, DirectionExpandVerticalAlign)
537 { 537 {
538 // "abcdef ghij kl mno^p|>qr stuvwi inm mnii," (^ means base, | means exten t, < means start, and > means end). 538 // "abcdef ghij kl mno^p|>qr stuvwi inm mnii," (^ means base, | means exten t, < means start, and > means end).
539 setupVerticalAlign("abcdef ghij kl m", "nopq", "r stuvwi inm mnii,", 18, 19) ; 539 setupVerticalAlign("abcdef ghij kl m", "nopq", "r stuvwi inm mnii,", 18, 19) ;
540 EXPECT_EQ_SELECTED_TEXT("p"); 540 EXPECT_EQ_SELECTED_TEXT("p");
541 testDirectionExpand(); 541 testDirectionExpand();
542 } 542 }
543 543
544 TEST_F(GranularityStrategyTest, DirectionExpandFontSizes) 544 TEST_F(GranularityStrategyTest, DirectionExpandFontSizes)
545 { 545 {
546 setupFontSize("abcdef ghij kl mnopqr st", "uv", "wi inm mnii,", 18, 19); 546 setupFontSize("abcdef ghij kl mnopqr st", "uv", "wi inm mnii,", 18, 19);
547 EXPECT_EQ_SELECTED_TEXT("p"); 547 EXPECT_EQ_SELECTED_TEXT("p");
548 testDirectionExpand(); 548 testDirectionExpand();
549 } 549 }
550 550
551 TEST_F(GranularityStrategyTest, DirectionShrinkTranslateZ) 551 TEST_F(GranularityStrategyTest, DirectionShrinkTranslateZ)
552 { 552 {
553 Text* text = setupTranslateZ("abcdef ghij kl mnopqr iiinmni, abc"); 553 Text* text = setupTranslateZ("abcdef ghij kl mnopqr iiinmni, abc");
554 selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 21))); 554 selection().setSelection(createVisibleSelectionDeprecated(Position(text, 18) , Position(text, 21)));
555 EXPECT_EQ_SELECTED_TEXT("pqr"); 555 EXPECT_EQ_SELECTED_TEXT("pqr");
556 testDirectionShrink(); 556 testDirectionShrink();
557 } 557 }
558 558
559 TEST_F(GranularityStrategyTest, DirectionShrinkTransform) 559 TEST_F(GranularityStrategyTest, DirectionShrinkTransform)
560 { 560 {
561 Text* text = setupTransform("abcdef ghij kl mnopqr iiinmni, abc"); 561 Text* text = setupTransform("abcdef ghij kl mnopqr iiinmni, abc");
562 selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 21))); 562 selection().setSelection(createVisibleSelectionDeprecated(Position(text, 18) , Position(text, 21)));
563 EXPECT_EQ_SELECTED_TEXT("pqr"); 563 EXPECT_EQ_SELECTED_TEXT("pqr");
564 testDirectionShrink(); 564 testDirectionShrink();
565 } 565 }
566 566
567 TEST_F(GranularityStrategyTest, DirectionShrinkVerticalAlign) 567 TEST_F(GranularityStrategyTest, DirectionShrinkVerticalAlign)
568 { 568 {
569 setupVerticalAlign("abcdef ghij kl mnopqr ii", "inm", "ni, abc", 18, 21); 569 setupVerticalAlign("abcdef ghij kl mnopqr ii", "inm", "ni, abc", 18, 21);
570 EXPECT_EQ_SELECTED_TEXT("pqr"); 570 EXPECT_EQ_SELECTED_TEXT("pqr");
571 testDirectionShrink(); 571 testDirectionShrink();
572 } 572 }
573 573
574 TEST_F(GranularityStrategyTest, DirectionShrinkFontSizes) 574 TEST_F(GranularityStrategyTest, DirectionShrinkFontSizes)
575 { 575 {
576 setupFontSize("abcdef ghij kl mnopqr ii", "inm", "ni, abc", 18, 21); 576 setupFontSize("abcdef ghij kl mnopqr ii", "inm", "ni, abc", 18, 21);
577 EXPECT_EQ_SELECTED_TEXT("pqr"); 577 EXPECT_EQ_SELECTED_TEXT("pqr");
578 testDirectionShrink(); 578 testDirectionShrink();
579 } 579 }
580 580
581 TEST_F(GranularityStrategyTest, DirectionSwitchSideTranslateZ) 581 TEST_F(GranularityStrategyTest, DirectionSwitchSideTranslateZ)
582 { 582 {
583 Text* text = setupTranslateZ("abcd efgh ijkl mnopqr iiinmni, abc"); 583 Text* text = setupTranslateZ("abcd efgh ijkl mnopqr iiinmni, abc");
584 selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 21))); 584 selection().setSelection(createVisibleSelectionDeprecated(Position(text, 18) , Position(text, 21)));
585 EXPECT_EQ_SELECTED_TEXT("pqr"); 585 EXPECT_EQ_SELECTED_TEXT("pqr");
586 testDirectionSwitchSide(); 586 testDirectionSwitchSide();
587 } 587 }
588 588
589 TEST_F(GranularityStrategyTest, DirectionSwitchSideTransform) 589 TEST_F(GranularityStrategyTest, DirectionSwitchSideTransform)
590 { 590 {
591 Text* text = setupTransform("abcd efgh ijkl mnopqr iiinmni, abc"); 591 Text* text = setupTransform("abcd efgh ijkl mnopqr iiinmni, abc");
592 selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 21))); 592 selection().setSelection(createVisibleSelectionDeprecated(Position(text, 18) , Position(text, 21)));
593 EXPECT_EQ_SELECTED_TEXT("pqr"); 593 EXPECT_EQ_SELECTED_TEXT("pqr");
594 testDirectionSwitchSide(); 594 testDirectionSwitchSide();
595 } 595 }
596 596
597 TEST_F(GranularityStrategyTest, DirectionSwitchSideVerticalAlign) 597 TEST_F(GranularityStrategyTest, DirectionSwitchSideVerticalAlign)
598 { 598 {
599 setupVerticalAlign("abcd efgh ijkl", " mnopqr", " iiinmni, abc", 18, 21); 599 setupVerticalAlign("abcd efgh ijkl", " mnopqr", " iiinmni, abc", 18, 21);
600 EXPECT_EQ_SELECTED_TEXT("pqr"); 600 EXPECT_EQ_SELECTED_TEXT("pqr");
601 testDirectionSwitchSide(); 601 testDirectionSwitchSide();
602 } 602 }
(...skipping 12 matching lines...) Expand all
615 dummyPageHolder().frame().settings()->setDefaultFontSize(12); 615 dummyPageHolder().frame().settings()->setDefaultFontSize(12);
616 String str = "ab cd efghijkl mnopqr iiin, abc"; 616 String str = "ab cd efghijkl mnopqr iiin, abc";
617 Text* text = document().createTextNode(str); 617 Text* text = document().createTextNode(str);
618 document().body()->appendChild(text); 618 document().body()->appendChild(text);
619 document().updateStyleAndLayout(); 619 document().updateStyleAndLayout();
620 dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy ::Direction); 620 dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy ::Direction);
621 621
622 parseText(text); 622 parseText(text);
623 623
624 // "abcd efgh ijkl mno^pqr|> iiin, abc" (^ means base, | means extent, < mea ns start, and > means end). 624 // "abcd efgh ijkl mno^pqr|> iiin, abc" (^ means base, | means extent, < mea ns start, and > means end).
625 selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 21))); 625 selection().setSelection(createVisibleSelectionDeprecated(Position(text, 18) , Position(text, 21)));
626 EXPECT_EQ_SELECTED_TEXT("pqr"); 626 EXPECT_EQ_SELECTED_TEXT("pqr");
627 // Move to the middle of word #4 selecting it - this will set the offset to 627 // Move to the middle of word #4 selecting it - this will set the offset to
628 // be half the width of "iiin". 628 // be half the width of "iiin".
629 selection().moveRangeSelectionExtent(m_wordMiddles[4]); 629 selection().moveRangeSelectionExtent(m_wordMiddles[4]);
630 EXPECT_EQ_SELECTED_TEXT("pqr iiin"); 630 EXPECT_EQ_SELECTED_TEXT("pqr iiin");
631 // Move to the middle of word #2 - extent will switch over to the other 631 // Move to the middle of word #2 - extent will switch over to the other
632 // side of the base, and we should enter word granularity since we pass 632 // side of the base, and we should enter word granularity since we pass
633 // the word boundary. The offset should become negative since the width 633 // the word boundary. The offset should become negative since the width
634 // of "efghjkkl" is greater than that of "iiin". 634 // of "efghjkkl" is greater than that of "iiin".
635 int offset = m_letterPos[26].x() - m_wordMiddles[4].x(); 635 int offset = m_letterPos[26].x() - m_wordMiddles[4].x();
(...skipping 13 matching lines...) Expand all
649 String str = "ab cd efghijkl mnopqr iiin, abc"; 649 String str = "ab cd efghijkl mnopqr iiin, abc";
650 Text* text = document().createTextNode(str); 650 Text* text = document().createTextNode(str);
651 document().body()->appendChild(text); 651 document().body()->appendChild(text);
652 document().updateStyleAndLayout(); 652 document().updateStyleAndLayout();
653 dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy ::Direction); 653 dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy ::Direction);
654 654
655 parseText(text); 655 parseText(text);
656 656
657 // "ab cd efghijkl ^mnopqr |>stuvwi inm," (^ means base and | means extent, 657 // "ab cd efghijkl ^mnopqr |>stuvwi inm," (^ means base and | means extent,
658 // > means end). 658 // > means end).
659 selection().setSelection(VisibleSelection(Position(text, 15), Position(text, 22))); 659 selection().setSelection(createVisibleSelectionDeprecated(Position(text, 15) , Position(text, 22)));
660 EXPECT_EQ_SELECTED_TEXT("mnopqr "); 660 EXPECT_EQ_SELECTED_TEXT("mnopqr ");
661 selection().moveRangeSelectionExtent(m_wordMiddles[4]); 661 selection().moveRangeSelectionExtent(m_wordMiddles[4]);
662 EXPECT_EQ_SELECTED_TEXT("mnopqr iiin"); 662 EXPECT_EQ_SELECTED_TEXT("mnopqr iiin");
663 } 663 }
664 664
665 } // namespace blink 665 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698