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

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

Issue 2399663003: Reflow comments in //third_party/WebKit/Source/core/editing (Closed)
Patch Set: 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 void setupFontSize(String str1, 67 void setupFontSize(String str1,
68 String str2, 68 String str2,
69 String str3, 69 String str3,
70 size_t selBegin, 70 size_t selBegin,
71 size_t selEnd); 71 size_t selEnd);
72 72
73 void testDirectionExpand(); 73 void testDirectionExpand();
74 void testDirectionShrink(); 74 void testDirectionShrink();
75 void testDirectionSwitchSide(); 75 void testDirectionSwitchSide();
76 76
77 // Pixel coordinates of the positions for each letter within the text being te sted. 77 // Pixel coordinates of the positions for each letter within the text being
78 // tested.
78 Vector<IntPoint> m_letterPos; 79 Vector<IntPoint> m_letterPos;
79 // Pixel coordinates of the middles of the words in the text being tested. 80 // Pixel coordinates of the middles of the words in the text being tested.
80 // (y coordinate is based on y coordinates of m_letterPos) 81 // (y coordinate is based on y coordinates of m_letterPos)
81 Vector<IntPoint> m_wordMiddles; 82 Vector<IntPoint> m_wordMiddles;
82 83
83 private: 84 private:
84 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; 85 std::unique_ptr<DummyPageHolder> m_dummyPageHolder;
85 Persistent<Document> m_document; 86 Persistent<Document> m_document;
86 }; 87 };
87 88
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 "</style>" 317 "</style>"
317 "</head>" 318 "</head>"
318 "<body>" 319 "<body>"
319 "<div id='mytext'></div>" 320 "<div id='mytext'></div>"
320 "</body>" 321 "</body>"
321 "</html>"); 322 "</html>");
322 323
323 setupTextSpan(str1, str2, str3, selBegin, selEnd); 324 setupTextSpan(str1, str2, str3, selBegin, selEnd);
324 } 325 }
325 326
326 // Tests expanding selection on text "abcdef ghij kl mno^p|>qr stuvwi inm mnii, " 327 // Tests expanding selection on text "abcdef ghij kl mno^p|>qr stuvwi inm mnii,"
327 // (^ means base, | means extent, < means start, and > means end). 328 // (^ means base, | means extent, < means start, and > means end). Text needs to
328 // Text needs to be laid out on a single line with no rotation. 329 // be laid out on a single line with no rotation.
329 void GranularityStrategyTest::testDirectionExpand() { 330 void GranularityStrategyTest::testDirectionExpand() {
330 // Expand selection using character granularity until the end of the word 331 // Expand selection using character granularity until the end of the word
331 // is reached. 332 // is reached.
332 // "abcdef ghij kl mno^pq|>r stuvwi inm mnii," 333 // "abcdef ghij kl mno^pq|>r stuvwi inm mnii,"
333 selection().moveRangeSelectionExtent(m_letterPos[20]); 334 selection().moveRangeSelectionExtent(m_letterPos[20]);
334 EXPECT_EQ_SELECTED_TEXT("pq"); 335 EXPECT_EQ_SELECTED_TEXT("pq");
335 // Move to the same postion shouldn't change anything. 336 // Move to the same postion shouldn't change anything.
336 selection().moveRangeSelectionExtent(m_letterPos[20]); 337 selection().moveRangeSelectionExtent(m_letterPos[20]);
337 EXPECT_EQ_SELECTED_TEXT("pq"); 338 EXPECT_EQ_SELECTED_TEXT("pq");
338 // "abcdef ghij kl mno^pqr|> stuvwi inm mnii," 339 // "abcdef ghij kl mno^pqr|> stuvwi inm mnii,"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 494
494 // Test for the default CharacterGranularityStrategy 495 // Test for the default CharacterGranularityStrategy
495 TEST_F(GranularityStrategyTest, Character) { 496 TEST_F(GranularityStrategyTest, Character) {
496 dummyPageHolder().frame().settings()->setSelectionStrategy( 497 dummyPageHolder().frame().settings()->setSelectionStrategy(
497 SelectionStrategy::Character); 498 SelectionStrategy::Character);
498 dummyPageHolder().frame().settings()->setDefaultFontSize(12); 499 dummyPageHolder().frame().settings()->setDefaultFontSize(12);
499 // "Foo Bar Baz," 500 // "Foo Bar Baz,"
500 Text* text = appendTextNode("Foo Bar Baz,"); 501 Text* text = appendTextNode("Foo Bar Baz,");
501 document().updateStyleAndLayout(); 502 document().updateStyleAndLayout();
502 503
503 // "Foo B^a|>r Baz," (^ means base, | means extent, , < means start, and > mea ns end). 504 // "Foo B^a|>r Baz," (^ means base, | means extent, , < means start, and >
505 // means end).
504 selection().setSelection( 506 selection().setSelection(
505 createVisibleSelection(Position(text, 5), Position(text, 6))); 507 createVisibleSelection(Position(text, 5), Position(text, 6)));
506 EXPECT_EQ_SELECTED_TEXT("a"); 508 EXPECT_EQ_SELECTED_TEXT("a");
507 // "Foo B^ar B|>az," 509 // "Foo B^ar B|>az,"
508 selection().moveRangeSelectionExtent( 510 selection().moveRangeSelectionExtent(
509 visiblePositionToContentsPoint(createVisiblePosition(Position(text, 9)))); 511 visiblePositionToContentsPoint(createVisiblePosition(Position(text, 9))));
510 EXPECT_EQ_SELECTED_TEXT("ar B"); 512 EXPECT_EQ_SELECTED_TEXT("ar B");
511 // "F<|oo B^ar Baz," 513 // "F<|oo B^ar Baz,"
512 selection().moveRangeSelectionExtent( 514 selection().moveRangeSelectionExtent(
513 visiblePositionToContentsPoint(createVisiblePosition(Position(text, 1)))); 515 visiblePositionToContentsPoint(createVisiblePosition(Position(text, 1))));
514 EXPECT_EQ_SELECTED_TEXT("oo B"); 516 EXPECT_EQ_SELECTED_TEXT("oo B");
515 } 517 }
516 518
517 // DirectionGranularityStrategy strategy on rotated text should revert to the 519 // DirectionGranularityStrategy strategy on rotated text should revert to the
518 // same behavior as CharacterGranularityStrategy 520 // same behavior as CharacterGranularityStrategy
519 TEST_F(GranularityStrategyTest, DirectionRotate) { 521 TEST_F(GranularityStrategyTest, DirectionRotate) {
520 Text* text = setupRotate("Foo Bar Baz,"); 522 Text* text = setupRotate("Foo Bar Baz,");
521 // "Foo B^a|>r Baz," (^ means base, | means extent, , < means start, and > mea ns end). 523 // "Foo B^a|>r Baz," (^ means base, | means extent, , < means start, and >
524 // means end).
522 selection().setSelection( 525 selection().setSelection(
523 createVisibleSelection(Position(text, 5), Position(text, 6))); 526 createVisibleSelection(Position(text, 5), Position(text, 6)));
524 EXPECT_EQ_SELECTED_TEXT("a"); 527 EXPECT_EQ_SELECTED_TEXT("a");
525 IntPoint p = m_letterPos[9]; 528 IntPoint p = m_letterPos[9];
526 // Need to move by one pixel, otherwise this point is not evaluated 529 // Need to move by one pixel, otherwise this point is not evaluated
527 // to the same line as the text by hit testing. 530 // to the same line as the text by hit testing.
528 p.move(1, 0); 531 p.move(1, 0);
529 // "Foo B^ar B|>az," 532 // "Foo B^ar B|>az,"
530 selection().moveRangeSelectionExtent(p); 533 selection().moveRangeSelectionExtent(p);
531 EXPECT_EQ_SELECTED_TEXT("ar B"); 534 EXPECT_EQ_SELECTED_TEXT("ar B");
532 p = m_letterPos[1]; 535 p = m_letterPos[1];
533 p.move(1, 0); 536 p.move(1, 0);
534 // "F<|oo B^ar Baz," 537 // "F<|oo B^ar Baz,"
535 selection().moveRangeSelectionExtent(p); 538 selection().moveRangeSelectionExtent(p);
536 EXPECT_EQ_SELECTED_TEXT("oo B"); 539 EXPECT_EQ_SELECTED_TEXT("oo B");
537 } 540 }
538 541
539 TEST_F(GranularityStrategyTest, DirectionExpandTranslateZ) { 542 TEST_F(GranularityStrategyTest, DirectionExpandTranslateZ) {
540 Text* text = setupTranslateZ("abcdef ghij kl mnopqr stuvwi inm mnii,"); 543 Text* text = setupTranslateZ("abcdef ghij kl mnopqr stuvwi inm mnii,");
541 // "abcdef ghij kl mno^p|>qr stuvwi inm mnii," (^ means base, | means extent, < means start, and > means end). 544 // "abcdef ghij kl mno^p|>qr stuvwi inm mnii," (^ means base, | means extent,
545 // < means start, and > means end).
542 selection().setSelection( 546 selection().setSelection(
543 createVisibleSelection(Position(text, 18), Position(text, 19))); 547 createVisibleSelection(Position(text, 18), Position(text, 19)));
544 EXPECT_EQ_SELECTED_TEXT("p"); 548 EXPECT_EQ_SELECTED_TEXT("p");
545 testDirectionExpand(); 549 testDirectionExpand();
546 } 550 }
547 551
548 TEST_F(GranularityStrategyTest, DirectionExpandTransform) { 552 TEST_F(GranularityStrategyTest, DirectionExpandTransform) {
549 Text* text = setupTransform("abcdef ghij kl mnopqr stuvwi inm mnii,"); 553 Text* text = setupTransform("abcdef ghij kl mnopqr stuvwi inm mnii,");
550 // "abcdef ghij kl mno^p|>qr stuvwi inm mnii," (^ means base, | means extent, < means start, and > means end). 554 // "abcdef ghij kl mno^p|>qr stuvwi inm mnii," (^ means base, | means extent,
555 // < means start, and > means end).
551 selection().setSelection( 556 selection().setSelection(
552 createVisibleSelection(Position(text, 18), Position(text, 19))); 557 createVisibleSelection(Position(text, 18), Position(text, 19)));
553 EXPECT_EQ_SELECTED_TEXT("p"); 558 EXPECT_EQ_SELECTED_TEXT("p");
554 testDirectionExpand(); 559 testDirectionExpand();
555 } 560 }
556 561
557 TEST_F(GranularityStrategyTest, DirectionExpandVerticalAlign) { 562 TEST_F(GranularityStrategyTest, DirectionExpandVerticalAlign) {
558 // "abcdef ghij kl mno^p|>qr stuvwi inm mnii," (^ means base, | means extent, < means start, and > means end). 563 // "abcdef ghij kl mno^p|>qr stuvwi inm mnii," (^ means base, | means extent,
564 // < means start, and > means end).
559 setupVerticalAlign("abcdef ghij kl m", "nopq", "r stuvwi inm mnii,", 18, 19); 565 setupVerticalAlign("abcdef ghij kl m", "nopq", "r stuvwi inm mnii,", 18, 19);
560 EXPECT_EQ_SELECTED_TEXT("p"); 566 EXPECT_EQ_SELECTED_TEXT("p");
561 testDirectionExpand(); 567 testDirectionExpand();
562 } 568 }
563 569
564 TEST_F(GranularityStrategyTest, DirectionExpandFontSizes) { 570 TEST_F(GranularityStrategyTest, DirectionExpandFontSizes) {
565 setupFontSize("abcdef ghij kl mnopqr st", "uv", "wi inm mnii,", 18, 19); 571 setupFontSize("abcdef ghij kl mnopqr st", "uv", "wi inm mnii,", 18, 19);
566 EXPECT_EQ_SELECTED_TEXT("p"); 572 EXPECT_EQ_SELECTED_TEXT("p");
567 testDirectionExpand(); 573 testDirectionExpand();
568 } 574 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 dummyPageHolder().frame().settings()->setDefaultFontSize(12); 635 dummyPageHolder().frame().settings()->setDefaultFontSize(12);
630 String str = "ab cd efghijkl mnopqr iiin, abc"; 636 String str = "ab cd efghijkl mnopqr iiin, abc";
631 Text* text = document().createTextNode(str); 637 Text* text = document().createTextNode(str);
632 document().body()->appendChild(text); 638 document().body()->appendChild(text);
633 document().updateStyleAndLayout(); 639 document().updateStyleAndLayout();
634 dummyPageHolder().frame().settings()->setSelectionStrategy( 640 dummyPageHolder().frame().settings()->setSelectionStrategy(
635 SelectionStrategy::Direction); 641 SelectionStrategy::Direction);
636 642
637 parseText(text); 643 parseText(text);
638 644
639 // "abcd efgh ijkl mno^pqr|> iiin, abc" (^ means base, | means extent, < means start, and > means end). 645 // "abcd efgh ijkl mno^pqr|> iiin, abc" (^ means base, | means extent, < means
646 // start, and > means end).
640 selection().setSelection( 647 selection().setSelection(
641 createVisibleSelection(Position(text, 18), Position(text, 21))); 648 createVisibleSelection(Position(text, 18), Position(text, 21)));
642 EXPECT_EQ_SELECTED_TEXT("pqr"); 649 EXPECT_EQ_SELECTED_TEXT("pqr");
643 // Move to the middle of word #4 selecting it - this will set the offset to 650 // Move to the middle of word #4 selecting it - this will set the offset to
644 // be half the width of "iiin". 651 // be half the width of "iiin".
645 selection().moveRangeSelectionExtent(m_wordMiddles[4]); 652 selection().moveRangeSelectionExtent(m_wordMiddles[4]);
646 EXPECT_EQ_SELECTED_TEXT("pqr iiin"); 653 EXPECT_EQ_SELECTED_TEXT("pqr iiin");
647 // Move to the middle of word #2 - extent will switch over to the other 654 // Move to the middle of word #2 - extent will switch over to the other
648 // side of the base, and we should enter word granularity since we pass 655 // side of the base, and we should enter word granularity since we pass
649 // the word boundary. The offset should become negative since the width 656 // the word boundary. The offset should become negative since the width
(...skipping 24 matching lines...) Expand all
674 // "ab cd efghijkl ^mnopqr |>stuvwi inm," (^ means base and | means extent, 681 // "ab cd efghijkl ^mnopqr |>stuvwi inm," (^ means base and | means extent,
675 // > means end). 682 // > means end).
676 selection().setSelection( 683 selection().setSelection(
677 createVisibleSelection(Position(text, 15), Position(text, 22))); 684 createVisibleSelection(Position(text, 15), Position(text, 22)));
678 EXPECT_EQ_SELECTED_TEXT("mnopqr "); 685 EXPECT_EQ_SELECTED_TEXT("mnopqr ");
679 selection().moveRangeSelectionExtent(m_wordMiddles[4]); 686 selection().moveRangeSelectionExtent(m_wordMiddles[4]);
680 EXPECT_EQ_SELECTED_TEXT("mnopqr iiin"); 687 EXPECT_EQ_SELECTED_TEXT("mnopqr iiin");
681 } 688 }
682 689
683 } // namespace blink 690 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698