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

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

Issue 1686483002: Oilpan: Remove most WillBe types from the code base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 16 matching lines...) Expand all
27 27
28 IntPoint visiblePositionToContentsPoint(const VisiblePosition& pos) 28 IntPoint visiblePositionToContentsPoint(const VisiblePosition& pos)
29 { 29 {
30 IntPoint result = absoluteCaretBoundsOf(pos).minXMaxYCorner(); 30 IntPoint result = absoluteCaretBoundsOf(pos).minXMaxYCorner();
31 // Need to move the point at least by 1 - caret's minXMaxYCorner is not 31 // Need to move the point at least by 1 - caret's minXMaxYCorner is not
32 // evaluated to the same line as the text by hit testing. 32 // evaluated to the same line as the text by hit testing.
33 result.move(0, -1); 33 result.move(0, -1);
34 return result; 34 return result;
35 } 35 }
36 36
37 using TextNodeVector = WillBeHeapVector<RefPtrWillBeMember<Text>>; 37 using TextNodeVector = HeapVector<Member<Text>>;
38 38
39 class GranularityStrategyTest : public ::testing::Test { 39 class GranularityStrategyTest : public ::testing::Test {
40 protected: 40 protected:
41 void SetUp() override; 41 void SetUp() override;
42 42
43 DummyPageHolder& dummyPageHolder() const { return *m_dummyPageHolder; } 43 DummyPageHolder& dummyPageHolder() const { return *m_dummyPageHolder; }
44 HTMLDocument& document() const; 44 HTMLDocument& document() const;
45 void setSelection(const VisibleSelection&); 45 void setSelection(const VisibleSelection&);
46 FrameSelection& selection() const; 46 FrameSelection& selection() const;
47 PassRefPtrWillBeRawPtr<Text> appendTextNode(const String& data); 47 RawPtr<Text> appendTextNode(const String& data);
48 int layoutCount() const { return m_dummyPageHolder->frameView().layoutCount( ); } 48 int layoutCount() const { return m_dummyPageHolder->frameView().layoutCount( ); }
49 void setInnerHTML(const char*); 49 void setInnerHTML(const char*);
50 // Parses the text node, appending the info to m_letterPos and m_wordMiddles . 50 // Parses the text node, appending the info to m_letterPos and m_wordMiddles .
51 void parseText(Text*); 51 void parseText(Text*);
52 void parseText(const TextNodeVector&); 52 void parseText(const TextNodeVector&);
53 53
54 PassRefPtrWillBeRawPtr<Text> setupTranslateZ(String); 54 RawPtr<Text> setupTranslateZ(String);
55 PassRefPtrWillBeRawPtr<Text> setupTransform(String); 55 RawPtr<Text> setupTransform(String);
56 PassRefPtrWillBeRawPtr<Text> setupRotate(String); 56 RawPtr<Text> setupRotate(String);
57 void setupTextSpan(String str1, String str2, String str3, size_t selBegin, s ize_t selEnd); 57 void setupTextSpan(String str1, String str2, String str3, size_t selBegin, s ize_t selEnd);
58 void setupVerticalAlign(String str1, String str2, String str3, size_t selBeg in, size_t selEnd); 58 void setupVerticalAlign(String str1, String str2, String str3, size_t selBeg in, size_t selEnd);
59 void setupFontSize(String str1, String str2, String str3, size_t selBegin, s ize_t selEnd); 59 void setupFontSize(String str1, String str2, String str3, size_t selBegin, s ize_t selEnd);
60 60
61 void testDirectionExpand(); 61 void testDirectionExpand();
62 void testDirectionShrink(); 62 void testDirectionShrink();
63 void testDirectionSwitchSide(); 63 void testDirectionSwitchSide();
64 64
65 // Pixel coordinates of the positions for each letter within the text being tested. 65 // Pixel coordinates of the positions for each letter within the text being tested.
66 Vector<IntPoint> m_letterPos; 66 Vector<IntPoint> m_letterPos;
67 // Pixel coordinates of the middles of the words in the text being tested. 67 // Pixel coordinates of the middles of the words in the text being tested.
68 // (y coordinate is based on y coordinates of m_letterPos) 68 // (y coordinate is based on y coordinates of m_letterPos)
69 Vector<IntPoint> m_wordMiddles; 69 Vector<IntPoint> m_wordMiddles;
70 70
71 private: 71 private:
72 OwnPtr<DummyPageHolder> m_dummyPageHolder; 72 OwnPtr<DummyPageHolder> m_dummyPageHolder;
73 RawPtrWillBePersistent<HTMLDocument> m_document; 73 Persistent<HTMLDocument> m_document;
74 }; 74 };
75 75
76 void GranularityStrategyTest::SetUp() 76 void GranularityStrategyTest::SetUp()
77 { 77 {
78 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); 78 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600));
79 m_document = toHTMLDocument(&m_dummyPageHolder->document()); 79 m_document = toHTMLDocument(&m_dummyPageHolder->document());
80 ASSERT(m_document); 80 ASSERT(m_document);
81 dummyPageHolder().frame().settings()->setDefaultFontSize(12); 81 dummyPageHolder().frame().settings()->setDefaultFontSize(12);
82 dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy ::Direction); 82 dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy ::Direction);
83 } 83 }
84 84
85 HTMLDocument& GranularityStrategyTest::document() const 85 HTMLDocument& GranularityStrategyTest::document() const
86 { 86 {
87 return *m_document; 87 return *m_document;
88 } 88 }
89 89
90 void GranularityStrategyTest::setSelection(const VisibleSelection& newSelection) 90 void GranularityStrategyTest::setSelection(const VisibleSelection& newSelection)
91 { 91 {
92 m_dummyPageHolder->frame().selection().setSelection(newSelection); 92 m_dummyPageHolder->frame().selection().setSelection(newSelection);
93 } 93 }
94 94
95 FrameSelection& GranularityStrategyTest::selection() const 95 FrameSelection& GranularityStrategyTest::selection() const
96 { 96 {
97 return m_dummyPageHolder->frame().selection(); 97 return m_dummyPageHolder->frame().selection();
98 } 98 }
99 99
100 PassRefPtrWillBeRawPtr<Text> GranularityStrategyTest::appendTextNode(const Strin g& data) 100 RawPtr<Text> GranularityStrategyTest::appendTextNode(const String& data)
101 { 101 {
102 RefPtrWillBeRawPtr<Text> text = document().createTextNode(data); 102 RawPtr<Text> text = document().createTextNode(data);
103 document().body()->appendChild(text); 103 document().body()->appendChild(text);
104 return text.release(); 104 return text.release();
105 } 105 }
106 106
107 void GranularityStrategyTest::setInnerHTML(const char* htmlContent) 107 void GranularityStrategyTest::setInnerHTML(const char* htmlContent)
108 { 108 {
109 document().documentElement()->setInnerHTML(String::fromUTF8(htmlContent), AS SERT_NO_EXCEPTION); 109 document().documentElement()->setInnerHTML(String::fromUTF8(htmlContent), AS SERT_NO_EXCEPTION);
110 document().view()->updateAllLifecyclePhases(); 110 document().view()->updateAllLifecyclePhases();
111 } 111 }
112 112
(...skipping 25 matching lines...) Expand all
138 } 138 }
139 } 139 }
140 if (wordStarted) { 140 if (wordStarted) {
141 const auto& lastNode = textNodes.last(); 141 const auto& lastNode = textNodes.last();
142 int xEnd = visiblePositionToContentsPoint(createVisiblePosition(Position (lastNode, lastNode->wholeText().length()))).x(); 142 int xEnd = visiblePositionToContentsPoint(createVisiblePosition(Position (lastNode, lastNode->wholeText().length()))).x();
143 IntPoint wordMiddle((m_letterPos[wordStartIndex].x() + xEnd) / 2, m_lett erPos[wordStartIndex].y()); 143 IntPoint wordMiddle((m_letterPos[wordStartIndex].x() + xEnd) / 2, m_lett erPos[wordStartIndex].y());
144 m_wordMiddles.append(wordMiddle); 144 m_wordMiddles.append(wordMiddle);
145 } 145 }
146 } 146 }
147 147
148 PassRefPtrWillBeRawPtr<Text> GranularityStrategyTest::setupTranslateZ(String str ) 148 RawPtr<Text> GranularityStrategyTest::setupTranslateZ(String str)
149 { 149 {
150 setInnerHTML( 150 setInnerHTML(
151 "<html>" 151 "<html>"
152 "<head>" 152 "<head>"
153 "<style>" 153 "<style>"
154 "div {" 154 "div {"
155 "transform: translateZ(0);" 155 "transform: translateZ(0);"
156 "}" 156 "}"
157 "</style>" 157 "</style>"
158 "</head>" 158 "</head>"
159 "<body>" 159 "<body>"
160 "<div id='mytext'></div>" 160 "<div id='mytext'></div>"
161 "</body>" 161 "</body>"
162 "</html>"); 162 "</html>");
163 163
164 RefPtrWillBeRawPtr<Text> text = document().createTextNode(str); 164 RawPtr<Text> text = document().createTextNode(str);
165 Element* div = document().getElementById("mytext"); 165 Element* div = document().getElementById("mytext");
166 div->appendChild(text); 166 div->appendChild(text);
167 167
168 document().view()->updateAllLifecyclePhases(); 168 document().view()->updateAllLifecyclePhases();
169 169
170 parseText(text.get()); 170 parseText(text.get());
171 return text.release(); 171 return text.release();
172 } 172 }
173 173
174 PassRefPtrWillBeRawPtr<Text> GranularityStrategyTest::setupTransform(String str) 174 RawPtr<Text> GranularityStrategyTest::setupTransform(String str)
175 { 175 {
176 setInnerHTML( 176 setInnerHTML(
177 "<html>" 177 "<html>"
178 "<head>" 178 "<head>"
179 "<style>" 179 "<style>"
180 "div {" 180 "div {"
181 "transform: scale(1,-1) translate(0,-100px);" 181 "transform: scale(1,-1) translate(0,-100px);"
182 "}" 182 "}"
183 "</style>" 183 "</style>"
184 "</head>" 184 "</head>"
185 "<body>" 185 "<body>"
186 "<div id='mytext'></div>" 186 "<div id='mytext'></div>"
187 "</body>" 187 "</body>"
188 "</html>"); 188 "</html>");
189 189
190 RefPtrWillBeRawPtr<Text> text = document().createTextNode(str); 190 RawPtr<Text> text = document().createTextNode(str);
191 Element* div = document().getElementById("mytext"); 191 Element* div = document().getElementById("mytext");
192 div->appendChild(text); 192 div->appendChild(text);
193 193
194 document().view()->updateAllLifecyclePhases(); 194 document().view()->updateAllLifecyclePhases();
195 195
196 parseText(text.get()); 196 parseText(text.get());
197 return text.release(); 197 return text.release();
198 } 198 }
199 199
200 PassRefPtrWillBeRawPtr<Text> GranularityStrategyTest::setupRotate(String str) 200 RawPtr<Text> GranularityStrategyTest::setupRotate(String str)
201 { 201 {
202 setInnerHTML( 202 setInnerHTML(
203 "<html>" 203 "<html>"
204 "<head>" 204 "<head>"
205 "<style>" 205 "<style>"
206 "div {" 206 "div {"
207 "transform: translate(0px,600px) rotate(90deg);" 207 "transform: translate(0px,600px) rotate(90deg);"
208 "}" 208 "}"
209 "</style>" 209 "</style>"
210 "</head>" 210 "</head>"
211 "<body>" 211 "<body>"
212 "<div id='mytext'></div>" 212 "<div id='mytext'></div>"
213 "</body>" 213 "</body>"
214 "</html>"); 214 "</html>");
215 215
216 RefPtrWillBeRawPtr<Text> text = document().createTextNode(str); 216 RawPtr<Text> text = document().createTextNode(str);
217 Element* div = document().getElementById("mytext"); 217 Element* div = document().getElementById("mytext");
218 div->appendChild(text); 218 div->appendChild(text);
219 219
220 document().view()->updateAllLifecyclePhases(); 220 document().view()->updateAllLifecyclePhases();
221 221
222 parseText(text.get()); 222 parseText(text.get());
223 return text.release(); 223 return text.release();
224 } 224 }
225 225
226 void GranularityStrategyTest::setupTextSpan(String str1, String str2, String str 3, size_t selBegin, size_t selEnd) 226 void GranularityStrategyTest::setupTextSpan(String str1, String str2, String str 3, size_t selBegin, size_t selEnd)
227 { 227 {
228 RefPtrWillBeRawPtr<Text> text1 = document().createTextNode(str1); 228 RawPtr<Text> text1 = document().createTextNode(str1);
229 RefPtrWillBeRawPtr<Text> text2 = document().createTextNode(str2); 229 RawPtr<Text> text2 = document().createTextNode(str2);
230 RefPtrWillBeRawPtr<Text> text3 = document().createTextNode(str3); 230 RawPtr<Text> text3 = document().createTextNode(str3);
231 RefPtrWillBeRawPtr<Element> span = HTMLSpanElement::create(document()); 231 RawPtr<Element> span = HTMLSpanElement::create(document());
232 Element* div = document().getElementById("mytext"); 232 Element* div = document().getElementById("mytext");
233 div->appendChild(text1); 233 div->appendChild(text1);
234 div->appendChild(span); 234 div->appendChild(span);
235 span->appendChild(text2); 235 span->appendChild(text2);
236 div->appendChild(text3); 236 div->appendChild(text3);
237 237
238 document().view()->updateAllLifecyclePhases(); 238 document().view()->updateAllLifecyclePhases();
239 239
240 Vector<IntPoint> letterPos; 240 Vector<IntPoint> letterPos;
241 Vector<IntPoint> wordMiddlePos; 241 Vector<IntPoint> wordMiddlePos;
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 selection().moveRangeSelectionExtent(p); 473 selection().moveRangeSelectionExtent(p);
474 EXPECT_EQ_SELECTED_TEXT("efgh ijkl mno"); 474 EXPECT_EQ_SELECTED_TEXT("efgh ijkl mno");
475 } 475 }
476 476
477 // Test for the default CharacterGranularityStrategy 477 // Test for the default CharacterGranularityStrategy
478 TEST_F(GranularityStrategyTest, Character) 478 TEST_F(GranularityStrategyTest, Character)
479 { 479 {
480 dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy ::Character); 480 dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy ::Character);
481 dummyPageHolder().frame().settings()->setDefaultFontSize(12); 481 dummyPageHolder().frame().settings()->setDefaultFontSize(12);
482 // "Foo Bar Baz," 482 // "Foo Bar Baz,"
483 RefPtrWillBeRawPtr<Text> text = appendTextNode("Foo Bar Baz,"); 483 RawPtr<Text> text = appendTextNode("Foo Bar Baz,");
484 // "Foo B^a|>r Baz," (^ means base, | means extent, , < means start, and > m eans end). 484 // "Foo B^a|>r Baz," (^ means base, | means extent, , < means start, and > m eans end).
485 selection().setSelection(VisibleSelection(Position(text, 5), Position(text, 6))); 485 selection().setSelection(VisibleSelection(Position(text, 5), Position(text, 6)));
486 EXPECT_EQ_SELECTED_TEXT("a"); 486 EXPECT_EQ_SELECTED_TEXT("a");
487 // "Foo B^ar B|>az," 487 // "Foo B^ar B|>az,"
488 selection().moveRangeSelectionExtent(visiblePositionToContentsPoint(createVi siblePosition(Position(text, 9)))); 488 selection().moveRangeSelectionExtent(visiblePositionToContentsPoint(createVi siblePosition(Position(text, 9))));
489 EXPECT_EQ_SELECTED_TEXT("ar B"); 489 EXPECT_EQ_SELECTED_TEXT("ar B");
490 // "F<|oo B^ar Baz," 490 // "F<|oo B^ar Baz,"
491 selection().moveRangeSelectionExtent(visiblePositionToContentsPoint(createVi siblePosition(Position(text, 1)))); 491 selection().moveRangeSelectionExtent(visiblePositionToContentsPoint(createVi siblePosition(Position(text, 1))));
492 EXPECT_EQ_SELECTED_TEXT("oo B"); 492 EXPECT_EQ_SELECTED_TEXT("oo B");
493 } 493 }
494 494
495 // DirectionGranularityStrategy strategy on rotated text should revert to the 495 // DirectionGranularityStrategy strategy on rotated text should revert to the
496 // same behavior as CharacterGranularityStrategy 496 // same behavior as CharacterGranularityStrategy
497 TEST_F(GranularityStrategyTest, DirectionRotate) 497 TEST_F(GranularityStrategyTest, DirectionRotate)
498 { 498 {
499 RefPtrWillBeRawPtr<Text> text = setupRotate("Foo Bar Baz,"); 499 RawPtr<Text> text = setupRotate("Foo Bar Baz,");
500 // "Foo B^a|>r Baz," (^ means base, | means extent, , < means start, and > m eans end). 500 // "Foo B^a|>r Baz," (^ means base, | means extent, , < means start, and > m eans end).
501 selection().setSelection(VisibleSelection(Position(text, 5), Position(text, 6))); 501 selection().setSelection(VisibleSelection(Position(text, 5), Position(text, 6)));
502 EXPECT_EQ_SELECTED_TEXT("a"); 502 EXPECT_EQ_SELECTED_TEXT("a");
503 IntPoint p = m_letterPos[9]; 503 IntPoint p = m_letterPos[9];
504 // Need to move by one pixel, otherwise this point is not evaluated 504 // Need to move by one pixel, otherwise this point is not evaluated
505 // to the same line as the text by hit testing. 505 // to the same line as the text by hit testing.
506 p.move(1, 0); 506 p.move(1, 0);
507 // "Foo B^ar B|>az," 507 // "Foo B^ar B|>az,"
508 selection().moveRangeSelectionExtent(p); 508 selection().moveRangeSelectionExtent(p);
509 EXPECT_EQ_SELECTED_TEXT("ar B"); 509 EXPECT_EQ_SELECTED_TEXT("ar B");
510 p = m_letterPos[1]; 510 p = m_letterPos[1];
511 p.move(1, 0); 511 p.move(1, 0);
512 // "F<|oo B^ar Baz," 512 // "F<|oo B^ar Baz,"
513 selection().moveRangeSelectionExtent(p); 513 selection().moveRangeSelectionExtent(p);
514 EXPECT_EQ_SELECTED_TEXT("oo B"); 514 EXPECT_EQ_SELECTED_TEXT("oo B");
515 } 515 }
516 516
517 TEST_F(GranularityStrategyTest, DirectionExpandTranslateZ) 517 TEST_F(GranularityStrategyTest, DirectionExpandTranslateZ)
518 { 518 {
519 RefPtrWillBeRawPtr<Text> text = setupTranslateZ("abcdef ghij kl mnopqr stuvw i inm mnii,"); 519 RawPtr<Text> text = setupTranslateZ("abcdef ghij kl mnopqr stuvwi inm mnii," );
520 // "abcdef ghij kl mno^p|>qr stuvwi inm mnii," (^ means base, | means exten t, < means start, and > means end). 520 // "abcdef ghij kl mno^p|>qr stuvwi inm mnii," (^ means base, | means exten t, < means start, and > means end).
521 selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 19))); 521 selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 19)));
522 EXPECT_EQ_SELECTED_TEXT("p"); 522 EXPECT_EQ_SELECTED_TEXT("p");
523 testDirectionExpand(); 523 testDirectionExpand();
524 } 524 }
525 525
526 TEST_F(GranularityStrategyTest, DirectionExpandTransform) 526 TEST_F(GranularityStrategyTest, DirectionExpandTransform)
527 { 527 {
528 RefPtrWillBeRawPtr<Text> text = setupTransform("abcdef ghij kl mnopqr stuvwi inm mnii,"); 528 RawPtr<Text> text = setupTransform("abcdef ghij kl mnopqr stuvwi inm mnii,") ;
529 // "abcdef ghij kl mno^p|>qr stuvwi inm mnii," (^ means base, | means exten t, < means start, and > means end). 529 // "abcdef ghij kl mno^p|>qr stuvwi inm mnii," (^ means base, | means exten t, < means start, and > means end).
530 selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 19))); 530 selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 19)));
531 EXPECT_EQ_SELECTED_TEXT("p"); 531 EXPECT_EQ_SELECTED_TEXT("p");
532 testDirectionExpand(); 532 testDirectionExpand();
533 } 533 }
534 534
535 TEST_F(GranularityStrategyTest, DirectionExpandVerticalAlign) 535 TEST_F(GranularityStrategyTest, DirectionExpandVerticalAlign)
536 { 536 {
537 // "abcdef ghij kl mno^p|>qr stuvwi inm mnii," (^ means base, | means exten t, < means start, and > means end). 537 // "abcdef ghij kl mno^p|>qr stuvwi inm mnii," (^ means base, | means exten t, < means start, and > means end).
538 setupVerticalAlign("abcdef ghij kl m", "nopq", "r stuvwi inm mnii,", 18, 19) ; 538 setupVerticalAlign("abcdef ghij kl m", "nopq", "r stuvwi inm mnii,", 18, 19) ;
539 EXPECT_EQ_SELECTED_TEXT("p"); 539 EXPECT_EQ_SELECTED_TEXT("p");
540 testDirectionExpand(); 540 testDirectionExpand();
541 } 541 }
542 542
543 TEST_F(GranularityStrategyTest, DirectionExpandFontSizes) 543 TEST_F(GranularityStrategyTest, DirectionExpandFontSizes)
544 { 544 {
545 setupFontSize("abcdef ghij kl mnopqr st", "uv", "wi inm mnii,", 18, 19); 545 setupFontSize("abcdef ghij kl mnopqr st", "uv", "wi inm mnii,", 18, 19);
546 EXPECT_EQ_SELECTED_TEXT("p"); 546 EXPECT_EQ_SELECTED_TEXT("p");
547 testDirectionExpand(); 547 testDirectionExpand();
548 } 548 }
549 549
550 TEST_F(GranularityStrategyTest, DirectionShrinkTranslateZ) 550 TEST_F(GranularityStrategyTest, DirectionShrinkTranslateZ)
551 { 551 {
552 RefPtrWillBeRawPtr<Text> text = setupTranslateZ("abcdef ghij kl mnopqr iiinm ni, abc"); 552 RawPtr<Text> text = setupTranslateZ("abcdef ghij kl mnopqr iiinmni, abc");
553 selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 21))); 553 selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 21)));
554 EXPECT_EQ_SELECTED_TEXT("pqr"); 554 EXPECT_EQ_SELECTED_TEXT("pqr");
555 testDirectionShrink(); 555 testDirectionShrink();
556 } 556 }
557 557
558 TEST_F(GranularityStrategyTest, DirectionShrinkTransform) 558 TEST_F(GranularityStrategyTest, DirectionShrinkTransform)
559 { 559 {
560 RefPtrWillBeRawPtr<Text> text = setupTransform("abcdef ghij kl mnopqr iiinmn i, abc"); 560 RawPtr<Text> text = setupTransform("abcdef ghij kl mnopqr iiinmni, abc");
561 selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 21))); 561 selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 21)));
562 EXPECT_EQ_SELECTED_TEXT("pqr"); 562 EXPECT_EQ_SELECTED_TEXT("pqr");
563 testDirectionShrink(); 563 testDirectionShrink();
564 } 564 }
565 565
566 TEST_F(GranularityStrategyTest, DirectionShrinkVerticalAlign) 566 TEST_F(GranularityStrategyTest, DirectionShrinkVerticalAlign)
567 { 567 {
568 setupVerticalAlign("abcdef ghij kl mnopqr ii", "inm", "ni, abc", 18, 21); 568 setupVerticalAlign("abcdef ghij kl mnopqr ii", "inm", "ni, abc", 18, 21);
569 EXPECT_EQ_SELECTED_TEXT("pqr"); 569 EXPECT_EQ_SELECTED_TEXT("pqr");
570 testDirectionShrink(); 570 testDirectionShrink();
571 } 571 }
572 572
573 TEST_F(GranularityStrategyTest, DirectionShrinkFontSizes) 573 TEST_F(GranularityStrategyTest, DirectionShrinkFontSizes)
574 { 574 {
575 setupFontSize("abcdef ghij kl mnopqr ii", "inm", "ni, abc", 18, 21); 575 setupFontSize("abcdef ghij kl mnopqr ii", "inm", "ni, abc", 18, 21);
576 EXPECT_EQ_SELECTED_TEXT("pqr"); 576 EXPECT_EQ_SELECTED_TEXT("pqr");
577 testDirectionShrink(); 577 testDirectionShrink();
578 } 578 }
579 579
580 TEST_F(GranularityStrategyTest, DirectionSwitchSideTranslateZ) 580 TEST_F(GranularityStrategyTest, DirectionSwitchSideTranslateZ)
581 { 581 {
582 RefPtrWillBeRawPtr<Text> text = setupTranslateZ("abcd efgh ijkl mnopqr iiinm ni, abc"); 582 RawPtr<Text> text = setupTranslateZ("abcd efgh ijkl mnopqr iiinmni, abc");
583 selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 21))); 583 selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 21)));
584 EXPECT_EQ_SELECTED_TEXT("pqr"); 584 EXPECT_EQ_SELECTED_TEXT("pqr");
585 testDirectionSwitchSide(); 585 testDirectionSwitchSide();
586 } 586 }
587 587
588 TEST_F(GranularityStrategyTest, DirectionSwitchSideTransform) 588 TEST_F(GranularityStrategyTest, DirectionSwitchSideTransform)
589 { 589 {
590 RefPtrWillBeRawPtr<Text> text = setupTransform("abcd efgh ijkl mnopqr iiinmn i, abc"); 590 RawPtr<Text> text = setupTransform("abcd efgh ijkl mnopqr iiinmni, abc");
591 selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 21))); 591 selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 21)));
592 EXPECT_EQ_SELECTED_TEXT("pqr"); 592 EXPECT_EQ_SELECTED_TEXT("pqr");
593 testDirectionSwitchSide(); 593 testDirectionSwitchSide();
594 } 594 }
595 595
596 TEST_F(GranularityStrategyTest, DirectionSwitchSideVerticalAlign) 596 TEST_F(GranularityStrategyTest, DirectionSwitchSideVerticalAlign)
597 { 597 {
598 setupVerticalAlign("abcd efgh ijkl", " mnopqr", " iiinmni, abc", 18, 21); 598 setupVerticalAlign("abcd efgh ijkl", " mnopqr", " iiinmni, abc", 18, 21);
599 EXPECT_EQ_SELECTED_TEXT("pqr"); 599 EXPECT_EQ_SELECTED_TEXT("pqr");
600 testDirectionSwitchSide(); 600 testDirectionSwitchSide();
601 } 601 }
602 602
603 TEST_F(GranularityStrategyTest, DirectionSwitchSideFontSizes) 603 TEST_F(GranularityStrategyTest, DirectionSwitchSideFontSizes)
604 { 604 {
605 setupFontSize("abcd efgh i", "jk", "l mnopqr iiinmni, abc", 18, 21); 605 setupFontSize("abcd efgh i", "jk", "l mnopqr iiinmni, abc", 18, 21);
606 EXPECT_EQ_SELECTED_TEXT("pqr"); 606 EXPECT_EQ_SELECTED_TEXT("pqr");
607 testDirectionSwitchSide(); 607 testDirectionSwitchSide();
608 } 608 }
609 609
610 // Tests moving extent over to the other side of the vase and immediately 610 // Tests moving extent over to the other side of the vase and immediately
611 // passing the word boundary and going into word granularity. 611 // passing the word boundary and going into word granularity.
612 TEST_F(GranularityStrategyTest, DirectionSwitchSideWordGranularityThenShrink) 612 TEST_F(GranularityStrategyTest, DirectionSwitchSideWordGranularityThenShrink)
613 { 613 {
614 dummyPageHolder().frame().settings()->setDefaultFontSize(12); 614 dummyPageHolder().frame().settings()->setDefaultFontSize(12);
615 String str = "ab cd efghijkl mnopqr iiin, abc"; 615 String str = "ab cd efghijkl mnopqr iiin, abc";
616 RefPtrWillBeRawPtr<Text> text = document().createTextNode(str); 616 RawPtr<Text> text = document().createTextNode(str);
617 document().body()->appendChild(text); 617 document().body()->appendChild(text);
618 dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy ::Direction); 618 dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy ::Direction);
619 619
620 parseText(text.get()); 620 parseText(text.get());
621 621
622 // "abcd efgh ijkl mno^pqr|> iiin, abc" (^ means base, | means extent, < mea ns start, and > means end). 622 // "abcd efgh ijkl mno^pqr|> iiin, abc" (^ means base, | means extent, < mea ns start, and > means end).
623 selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 21))); 623 selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 21)));
624 EXPECT_EQ_SELECTED_TEXT("pqr"); 624 EXPECT_EQ_SELECTED_TEXT("pqr");
625 // Move to the middle of word #4 selecting it - this will set the offset to 625 // Move to the middle of word #4 selecting it - this will set the offset to
626 // be half the width of "iiin". 626 // be half the width of "iiin".
(...skipping 11 matching lines...) Expand all
638 selection().moveRangeSelectionExtent(p); 638 selection().moveRangeSelectionExtent(p);
639 EXPECT_EQ_SELECTED_TEXT("fghijkl mno"); 639 EXPECT_EQ_SELECTED_TEXT("fghijkl mno");
640 } 640 }
641 641
642 // Make sure we switch to word granularity right away when starting on a 642 // Make sure we switch to word granularity right away when starting on a
643 // word boundary and extending. 643 // word boundary and extending.
644 TEST_F(GranularityStrategyTest, DirectionSwitchStartOnBoundary) 644 TEST_F(GranularityStrategyTest, DirectionSwitchStartOnBoundary)
645 { 645 {
646 dummyPageHolder().frame().settings()->setDefaultFontSize(12); 646 dummyPageHolder().frame().settings()->setDefaultFontSize(12);
647 String str = "ab cd efghijkl mnopqr iiin, abc"; 647 String str = "ab cd efghijkl mnopqr iiin, abc";
648 RefPtrWillBeRawPtr<Text> text = document().createTextNode(str); 648 RawPtr<Text> text = document().createTextNode(str);
649 document().body()->appendChild(text); 649 document().body()->appendChild(text);
650 dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy ::Direction); 650 dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy ::Direction);
651 651
652 parseText(text.get()); 652 parseText(text.get());
653 653
654 // "ab cd efghijkl ^mnopqr |>stuvwi inm," (^ means base and | means extent, 654 // "ab cd efghijkl ^mnopqr |>stuvwi inm," (^ means base and | means extent,
655 // > means end). 655 // > means end).
656 selection().setSelection(VisibleSelection(Position(text, 15), Position(text, 22))); 656 selection().setSelection(VisibleSelection(Position(text, 15), Position(text, 22)));
657 EXPECT_EQ_SELECTED_TEXT("mnopqr "); 657 EXPECT_EQ_SELECTED_TEXT("mnopqr ");
658 selection().moveRangeSelectionExtent(m_wordMiddles[4]); 658 selection().moveRangeSelectionExtent(m_wordMiddles[4]);
659 EXPECT_EQ_SELECTED_TEXT("mnopqr iiin"); 659 EXPECT_EQ_SELECTED_TEXT("mnopqr iiin");
660 } 660 }
661 661
662 } // namespace blink 662 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698