OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * Copyright (c) 2013, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 EXPECT_EQ(text, iter.CurrentContainer()); | 770 EXPECT_EQ(text, iter.CurrentContainer()); |
771 EXPECT_EQ(Position(text, 7), iter.StartPositionInCurrentContainer()); | 771 EXPECT_EQ(Position(text, 7), iter.StartPositionInCurrentContainer()); |
772 EXPECT_EQ(Position(text, 10), iter.EndPositionInCurrentContainer()); | 772 EXPECT_EQ(Position(text, 10), iter.EndPositionInCurrentContainer()); |
773 | 773 |
774 iter.Advance(); | 774 iter.Advance(); |
775 EXPECT_TRUE(iter.AtEnd()); | 775 EXPECT_TRUE(iter.AtEnd()); |
776 | 776 |
777 EXPECT_EQ("A) xyz", String(buffer.Data())); | 777 EXPECT_EQ("A) xyz", String(buffer.Data())); |
778 } | 778 } |
779 | 779 |
| 780 TEST_F(TextIteratorTest, StartAndEndInMultiCharFirstLetterWithCollapsedSpace) { |
| 781 SetBodyContent( |
| 782 "<style>div:first-letter {color:red;}</style><div> (A) xyz</div>"); |
| 783 |
| 784 Element* div = GetDocument().QuerySelector("div"); |
| 785 Node* text = div->firstChild(); |
| 786 Position start(text, 3); |
| 787 Position end(text, 4); |
| 788 TextIterator iter(start, end); |
| 789 ForwardsTextBuffer buffer; |
| 790 |
| 791 EXPECT_FALSE(iter.AtEnd()); |
| 792 EXPECT_EQ(1, iter.length()); |
| 793 EXPECT_EQ(1, iter.CopyTextTo(&buffer, 0)) << "Should emit 'A'."; |
| 794 EXPECT_EQ(text, iter.CurrentContainer()); |
| 795 EXPECT_EQ(Position(text, 3), iter.StartPositionInCurrentContainer()); |
| 796 EXPECT_EQ(Position(text, 4), iter.EndPositionInCurrentContainer()); |
| 797 |
| 798 iter.Advance(); |
| 799 EXPECT_TRUE(iter.AtEnd()); |
| 800 |
| 801 EXPECT_EQ("A", String(buffer.Data())); |
| 802 } |
| 803 |
780 TEST_F(TextIteratorTest, StartAtRemainingText) { | 804 TEST_F(TextIteratorTest, StartAtRemainingText) { |
781 SetBodyContent("<style>div:first-letter {color:red;}</style><div>Axyz</div>"); | 805 SetBodyContent("<style>div:first-letter {color:red;}</style><div>Axyz</div>"); |
782 | 806 |
783 Element* div = GetDocument().QuerySelector("div"); | 807 Element* div = GetDocument().QuerySelector("div"); |
784 Node* text = div->firstChild(); | 808 Node* text = div->firstChild(); |
785 Position start(text, 1); | 809 Position start(text, 1); |
786 Position end(text, 4); | 810 Position end(text, 4); |
787 TextIterator iter(start, end); | 811 TextIterator iter(start, end); |
788 ForwardsTextBuffer buffer; | 812 ForwardsTextBuffer buffer; |
789 | 813 |
790 EXPECT_FALSE(iter.AtEnd()); | 814 EXPECT_FALSE(iter.AtEnd()); |
791 EXPECT_EQ(3, iter.length()); | 815 EXPECT_EQ(3, iter.length()); |
792 EXPECT_EQ(3, iter.CopyTextTo(&buffer, 0)) << "Should emit 'xyz'."; | 816 EXPECT_EQ(3, iter.CopyTextTo(&buffer, 0)) << "Should emit 'xyz'."; |
793 EXPECT_EQ(text, iter.CurrentContainer()); | 817 EXPECT_EQ(text, iter.CurrentContainer()); |
794 EXPECT_EQ(Position(text, 1), iter.StartPositionInCurrentContainer()); | 818 EXPECT_EQ(Position(text, 1), iter.StartPositionInCurrentContainer()); |
795 EXPECT_EQ(Position(text, 4), iter.EndPositionInCurrentContainer()); | 819 EXPECT_EQ(Position(text, 4), iter.EndPositionInCurrentContainer()); |
796 | 820 |
797 iter.Advance(); | 821 iter.Advance(); |
798 EXPECT_TRUE(iter.AtEnd()); | 822 EXPECT_TRUE(iter.AtEnd()); |
799 | 823 |
800 EXPECT_EQ("xyz", String(buffer.Data())); | 824 EXPECT_EQ("xyz", String(buffer.Data())); |
801 } | 825 } |
802 | 826 |
| 827 TEST_F(TextIteratorTest, StartAtFirstLetterInPre) { |
| 828 SetBodyContent("<style>pre:first-letter {color:red;}</style><pre>Axyz</pre>"); |
| 829 |
| 830 Element* pre = GetDocument().QuerySelector("pre"); |
| 831 Node* text = pre->firstChild(); |
| 832 Position start(text, 0); |
| 833 Position end(text, 4); |
| 834 TextIterator iter(start, end); |
| 835 ForwardsTextBuffer buffer; |
| 836 |
| 837 EXPECT_FALSE(iter.AtEnd()); |
| 838 EXPECT_EQ(1, iter.length()); |
| 839 EXPECT_EQ(1, iter.CopyTextTo(&buffer, 0)) << "Should emit 'A'."; |
| 840 EXPECT_EQ(text, iter.CurrentContainer()); |
| 841 EXPECT_EQ(Position(text, 0), iter.StartPositionInCurrentContainer()); |
| 842 EXPECT_EQ(Position(text, 1), iter.EndPositionInCurrentContainer()); |
| 843 |
| 844 iter.Advance(); |
| 845 EXPECT_FALSE(iter.AtEnd()); |
| 846 EXPECT_EQ(3, iter.length()); |
| 847 EXPECT_EQ(3, iter.CopyTextTo(&buffer, 0)) << "Should emit 'xyz'."; |
| 848 EXPECT_EQ(text, iter.CurrentContainer()); |
| 849 EXPECT_EQ(Position(text, 1), iter.StartPositionInCurrentContainer()); |
| 850 EXPECT_EQ(Position(text, 4), iter.EndPositionInCurrentContainer()); |
| 851 |
| 852 iter.Advance(); |
| 853 EXPECT_TRUE(iter.AtEnd()); |
| 854 |
| 855 EXPECT_EQ("Axyz", String(buffer.Data())); |
| 856 } |
| 857 |
| 858 TEST_F(TextIteratorTest, StartInMultiCharFirstLetterInPre) { |
| 859 SetBodyContent( |
| 860 "<style>pre:first-letter {color:red;}</style><pre>(A)xyz</pre>"); |
| 861 |
| 862 Element* pre = GetDocument().QuerySelector("pre"); |
| 863 Node* text = pre->firstChild(); |
| 864 Position start(text, 1); |
| 865 Position end(text, 6); |
| 866 TextIterator iter(start, end); |
| 867 ForwardsTextBuffer buffer; |
| 868 |
| 869 EXPECT_FALSE(iter.AtEnd()); |
| 870 EXPECT_EQ(2, iter.length()); |
| 871 EXPECT_EQ(2, iter.CopyTextTo(&buffer, 0)) << "Should emit 'A)'."; |
| 872 EXPECT_EQ(text, iter.CurrentContainer()); |
| 873 EXPECT_EQ(Position(text, 1), iter.StartPositionInCurrentContainer()); |
| 874 EXPECT_EQ(Position(text, 3), iter.EndPositionInCurrentContainer()); |
| 875 |
| 876 iter.Advance(); |
| 877 EXPECT_FALSE(iter.AtEnd()); |
| 878 EXPECT_EQ(3, iter.length()); |
| 879 EXPECT_EQ(3, iter.CopyTextTo(&buffer, 0)) << "Should emit 'xyz'."; |
| 880 EXPECT_EQ(text, iter.CurrentContainer()); |
| 881 EXPECT_EQ(Position(text, 3), iter.StartPositionInCurrentContainer()); |
| 882 EXPECT_EQ(Position(text, 6), iter.EndPositionInCurrentContainer()); |
| 883 |
| 884 iter.Advance(); |
| 885 EXPECT_TRUE(iter.AtEnd()); |
| 886 |
| 887 EXPECT_EQ("A)xyz", String(buffer.Data())); |
| 888 } |
| 889 |
| 890 TEST_F(TextIteratorTest, StartAndEndInMultiCharFirstLetterInPre) { |
| 891 SetBodyContent( |
| 892 "<style>pre:first-letter {color:red;}</style><pre>(A)xyz</pre>"); |
| 893 |
| 894 Element* pre = GetDocument().QuerySelector("pre"); |
| 895 Node* text = pre->firstChild(); |
| 896 Position start(text, 1); |
| 897 Position end(text, 2); |
| 898 TextIterator iter(start, end); |
| 899 ForwardsTextBuffer buffer; |
| 900 |
| 901 EXPECT_FALSE(iter.AtEnd()); |
| 902 EXPECT_EQ(1, iter.length()); |
| 903 EXPECT_EQ(1, iter.CopyTextTo(&buffer, 0)) << "Should emit 'A'."; |
| 904 EXPECT_EQ(text, iter.CurrentContainer()); |
| 905 EXPECT_EQ(Position(text, 1), iter.StartPositionInCurrentContainer()); |
| 906 EXPECT_EQ(Position(text, 2), iter.EndPositionInCurrentContainer()); |
| 907 |
| 908 iter.Advance(); |
| 909 EXPECT_TRUE(iter.AtEnd()); |
| 910 |
| 911 EXPECT_EQ("A", String(buffer.Data())); |
| 912 } |
| 913 |
| 914 TEST_F(TextIteratorTest, StartAtRemainingTextInPre) { |
| 915 SetBodyContent("<style>pre:first-letter {color:red;}</style><pre>Axyz</pre>"); |
| 916 |
| 917 Element* pre = GetDocument().QuerySelector("pre"); |
| 918 Node* text = pre->firstChild(); |
| 919 Position start(text, 1); |
| 920 Position end(text, 4); |
| 921 TextIterator iter(start, end); |
| 922 ForwardsTextBuffer buffer; |
| 923 |
| 924 EXPECT_FALSE(iter.AtEnd()); |
| 925 EXPECT_EQ(3, iter.length()); |
| 926 EXPECT_EQ(3, iter.CopyTextTo(&buffer, 0)) << "Should emit 'xyz'."; |
| 927 EXPECT_EQ(text, iter.CurrentContainer()); |
| 928 EXPECT_EQ(Position(text, 1), iter.StartPositionInCurrentContainer()); |
| 929 EXPECT_EQ(Position(text, 4), iter.EndPositionInCurrentContainer()); |
| 930 |
| 931 iter.Advance(); |
| 932 EXPECT_TRUE(iter.AtEnd()); |
| 933 |
| 934 EXPECT_EQ("xyz", String(buffer.Data())); |
| 935 } |
| 936 |
803 } // namespace blink | 937 } // namespace blink |
OLD | NEW |