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

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

Issue 2345693005: Prune createVisiblePositionDeprecated from unit tests (Closed)
Patch Set: Created 4 years, 3 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 } 117 }
118 118
119 void GranularityStrategyTest::parseText(const TextNodeVector& textNodes) 119 void GranularityStrategyTest::parseText(const TextNodeVector& textNodes)
120 { 120 {
121 bool wordStarted = false; 121 bool wordStarted = false;
122 int wordStartIndex = 0; 122 int wordStartIndex = 0;
123 for (auto& text : textNodes) { 123 for (auto& text : textNodes) {
124 int wordStartIndexOffset = m_letterPos.size(); 124 int wordStartIndexOffset = m_letterPos.size();
125 String str = text->wholeText(); 125 String str = text->wholeText();
126 for (size_t i = 0; i < str.length(); i++) { 126 for (size_t i = 0; i < str.length(); i++) {
127 m_letterPos.append(visiblePositionToContentsPoint(createVisiblePosit ionDeprecated(Position(text, i)))); 127 m_letterPos.append(visiblePositionToContentsPoint(createVisiblePosit ion(Position(text, i))));
128 char c = str[i]; 128 char c = str[i];
129 if (isASCIIAlphanumeric(c) && !wordStarted) { 129 if (isASCIIAlphanumeric(c) && !wordStarted) {
130 wordStartIndex = i + wordStartIndexOffset; 130 wordStartIndex = i + wordStartIndexOffset;
131 wordStarted = true; 131 wordStarted = true;
132 } else if (!isASCIIAlphanumeric(c) && wordStarted) { 132 } else if (!isASCIIAlphanumeric(c) && wordStarted) {
133 IntPoint wordMiddle((m_letterPos[wordStartIndex].x() + m_letterP os[i + wordStartIndexOffset].x()) / 2, m_letterPos[wordStartIndex].y()); 133 IntPoint wordMiddle((m_letterPos[wordStartIndex].x() + m_letterP os[i + wordStartIndexOffset].x()) / 2, m_letterPos[wordStartIndex].y());
134 m_wordMiddles.append(wordMiddle); 134 m_wordMiddles.append(wordMiddle);
135 wordStarted = false; 135 wordStarted = false;
136 } 136 }
137 } 137 }
138 } 138 }
139 if (wordStarted) { 139 if (wordStarted) {
140 const auto& lastNode = textNodes.last(); 140 const auto& lastNode = textNodes.last();
141 int xEnd = visiblePositionToContentsPoint(createVisiblePositionDeprecate d(Position(lastNode, lastNode->wholeText().length()))).x(); 141 int xEnd = visiblePositionToContentsPoint(createVisiblePosition(Position (lastNode, lastNode->wholeText().length()))).x();
142 IntPoint wordMiddle((m_letterPos[wordStartIndex].x() + xEnd) / 2, m_lett erPos[wordStartIndex].y()); 142 IntPoint wordMiddle((m_letterPos[wordStartIndex].x() + xEnd) / 2, m_lett erPos[wordStartIndex].y());
143 m_wordMiddles.append(wordMiddle); 143 m_wordMiddles.append(wordMiddle);
144 } 144 }
145 } 145 }
146 146
147 Text* GranularityStrategyTest::setupTranslateZ(String str) 147 Text* GranularityStrategyTest::setupTranslateZ(String str)
148 { 148 {
149 setInnerHTML( 149 setInnerHTML(
150 "<html>" 150 "<html>"
151 "<head>" 151 "<head>"
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 EXPECT_EQ_SELECTED_TEXT("efgh ijkl mno"); 473 EXPECT_EQ_SELECTED_TEXT("efgh ijkl mno");
474 } 474 }
475 475
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();
484
483 // "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).
484 selection().setSelection(VisibleSelection(Position(text, 5), Position(text, 6))); 486 selection().setSelection(VisibleSelection(Position(text, 5), Position(text, 6)));
485 EXPECT_EQ_SELECTED_TEXT("a"); 487 EXPECT_EQ_SELECTED_TEXT("a");
486 // "Foo B^ar B|>az," 488 // "Foo B^ar B|>az,"
487 selection().moveRangeSelectionExtent(visiblePositionToContentsPoint(createVi siblePositionDeprecated(Position(text, 9)))); 489 selection().moveRangeSelectionExtent(visiblePositionToContentsPoint(createVi siblePosition(Position(text, 9))));
488 EXPECT_EQ_SELECTED_TEXT("ar B"); 490 EXPECT_EQ_SELECTED_TEXT("ar B");
489 // "F<|oo B^ar Baz," 491 // "F<|oo B^ar Baz,"
490 selection().moveRangeSelectionExtent(visiblePositionToContentsPoint(createVi siblePositionDeprecated(Position(text, 1)))); 492 selection().moveRangeSelectionExtent(visiblePositionToContentsPoint(createVi siblePosition(Position(text, 1))));
491 EXPECT_EQ_SELECTED_TEXT("oo B"); 493 EXPECT_EQ_SELECTED_TEXT("oo B");
492 } 494 }
493 495
494 // DirectionGranularityStrategy strategy on rotated text should revert to the 496 // DirectionGranularityStrategy strategy on rotated text should revert to the
495 // same behavior as CharacterGranularityStrategy 497 // same behavior as CharacterGranularityStrategy
496 TEST_F(GranularityStrategyTest, DirectionRotate) 498 TEST_F(GranularityStrategyTest, DirectionRotate)
497 { 499 {
498 Text* text = setupRotate("Foo Bar Baz,"); 500 Text* text = setupRotate("Foo Bar Baz,");
499 // "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).
500 selection().setSelection(VisibleSelection(Position(text, 5), Position(text, 6))); 502 selection().setSelection(VisibleSelection(Position(text, 5), Position(text, 6)));
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 } 609 }
608 610
609 // Tests moving extent over to the other side of the vase and immediately 611 // Tests moving extent over to the other side of the vase and immediately
610 // passing the word boundary and going into word granularity. 612 // passing the word boundary and going into word granularity.
611 TEST_F(GranularityStrategyTest, DirectionSwitchSideWordGranularityThenShrink) 613 TEST_F(GranularityStrategyTest, DirectionSwitchSideWordGranularityThenShrink)
612 { 614 {
613 dummyPageHolder().frame().settings()->setDefaultFontSize(12); 615 dummyPageHolder().frame().settings()->setDefaultFontSize(12);
614 String str = "ab cd efghijkl mnopqr iiin, abc"; 616 String str = "ab cd efghijkl mnopqr iiin, abc";
615 Text* text = document().createTextNode(str); 617 Text* text = document().createTextNode(str);
616 document().body()->appendChild(text); 618 document().body()->appendChild(text);
619 document().updateStyleAndLayout();
617 dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy ::Direction); 620 dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy ::Direction);
618 621
619 parseText(text); 622 parseText(text);
620 623
621 // "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).
622 selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 21))); 625 selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 21)));
623 EXPECT_EQ_SELECTED_TEXT("pqr"); 626 EXPECT_EQ_SELECTED_TEXT("pqr");
624 // 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
625 // be half the width of "iiin". 628 // be half the width of "iiin".
626 selection().moveRangeSelectionExtent(m_wordMiddles[4]); 629 selection().moveRangeSelectionExtent(m_wordMiddles[4]);
(...skipping 12 matching lines...) Expand all
639 } 642 }
640 643
641 // Make sure we switch to word granularity right away when starting on a 644 // Make sure we switch to word granularity right away when starting on a
642 // word boundary and extending. 645 // word boundary and extending.
643 TEST_F(GranularityStrategyTest, DirectionSwitchStartOnBoundary) 646 TEST_F(GranularityStrategyTest, DirectionSwitchStartOnBoundary)
644 { 647 {
645 dummyPageHolder().frame().settings()->setDefaultFontSize(12); 648 dummyPageHolder().frame().settings()->setDefaultFontSize(12);
646 String str = "ab cd efghijkl mnopqr iiin, abc"; 649 String str = "ab cd efghijkl mnopqr iiin, abc";
647 Text* text = document().createTextNode(str); 650 Text* text = document().createTextNode(str);
648 document().body()->appendChild(text); 651 document().body()->appendChild(text);
652 document().updateStyleAndLayout();
649 dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy ::Direction); 653 dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy ::Direction);
650 654
651 parseText(text); 655 parseText(text);
652 656
653 // "ab cd efghijkl ^mnopqr |>stuvwi inm," (^ means base and | means extent, 657 // "ab cd efghijkl ^mnopqr |>stuvwi inm," (^ means base and | means extent,
654 // > means end). 658 // > means end).
655 selection().setSelection(VisibleSelection(Position(text, 15), Position(text, 22))); 659 selection().setSelection(VisibleSelection(Position(text, 15), Position(text, 22)));
656 EXPECT_EQ_SELECTED_TEXT("mnopqr "); 660 EXPECT_EQ_SELECTED_TEXT("mnopqr ");
657 selection().moveRangeSelectionExtent(m_wordMiddles[4]); 661 selection().moveRangeSelectionExtent(m_wordMiddles[4]);
658 EXPECT_EQ_SELECTED_TEXT("mnopqr iiin"); 662 EXPECT_EQ_SELECTED_TEXT("mnopqr iiin");
659 } 663 }
660 664
661 } // namespace blink 665 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698