| OLD | NEW |
| 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "web/TextFinder.h" | 7 #include "web/TextFinder.h" |
| 8 | 8 |
| 9 #include "bindings/v8/ExceptionStatePlaceholder.h" | 9 #include "bindings/v8/ExceptionStatePlaceholder.h" |
| 10 #include "core/dom/Document.h" | 10 #include "core/dom/Document.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 int identifier = 0; | 71 int identifier = 0; |
| 72 WebString searchText(String("FindMe")); | 72 WebString searchText(String("FindMe")); |
| 73 WebFindOptions findOptions; // Default. | 73 WebFindOptions findOptions; // Default. |
| 74 bool wrapWithinFrame = true; | 74 bool wrapWithinFrame = true; |
| 75 WebRect* selectionRect = 0; | 75 WebRect* selectionRect = 0; |
| 76 | 76 |
| 77 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi
nFrame, selectionRect)); | 77 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi
nFrame, selectionRect)); |
| 78 Range* activeMatch = textFinder().activeMatch(); | 78 Range* activeMatch = textFinder().activeMatch(); |
| 79 EXPECT_TRUE(activeMatch); | 79 EXPECT_TRUE(activeMatch); |
| 80 if (activeMatch) { | 80 if (activeMatch) { |
| 81 EXPECT_EQ(textNode, activeMatch->startContainer(ASSERT_NO_EXCEPTION)); | 81 EXPECT_EQ(textNode, activeMatch->startContainer()); |
| 82 EXPECT_EQ(4, activeMatch->startOffset(ASSERT_NO_EXCEPTION)); | 82 EXPECT_EQ(4, activeMatch->startOffset()); |
| 83 EXPECT_EQ(textNode, activeMatch->endContainer(ASSERT_NO_EXCEPTION)); | 83 EXPECT_EQ(textNode, activeMatch->endContainer()); |
| 84 EXPECT_EQ(10, activeMatch->endOffset(ASSERT_NO_EXCEPTION)); | 84 EXPECT_EQ(10, activeMatch->endOffset()); |
| 85 } | 85 } |
| 86 | 86 |
| 87 findOptions.findNext = true; | 87 findOptions.findNext = true; |
| 88 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi
nFrame, selectionRect)); | 88 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi
nFrame, selectionRect)); |
| 89 activeMatch = textFinder().activeMatch(); | 89 activeMatch = textFinder().activeMatch(); |
| 90 EXPECT_TRUE(activeMatch); | 90 EXPECT_TRUE(activeMatch); |
| 91 if (activeMatch) { | 91 if (activeMatch) { |
| 92 EXPECT_EQ(textNode, activeMatch->startContainer(ASSERT_NO_EXCEPTION)); | 92 EXPECT_EQ(textNode, activeMatch->startContainer()); |
| 93 EXPECT_EQ(14, activeMatch->startOffset(ASSERT_NO_EXCEPTION)); | 93 EXPECT_EQ(14, activeMatch->startOffset()); |
| 94 EXPECT_EQ(textNode, activeMatch->endContainer(ASSERT_NO_EXCEPTION)); | 94 EXPECT_EQ(textNode, activeMatch->endContainer()); |
| 95 EXPECT_EQ(20, activeMatch->endOffset(ASSERT_NO_EXCEPTION)); | 95 EXPECT_EQ(20, activeMatch->endOffset()); |
| 96 } | 96 } |
| 97 | 97 |
| 98 // Should wrap to the first match. | 98 // Should wrap to the first match. |
| 99 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi
nFrame, selectionRect)); | 99 ASSERT_TRUE(textFinder().find(identifier, searchText, findOptions, wrapWithi
nFrame, selectionRect)); |
| 100 activeMatch = textFinder().activeMatch(); | 100 activeMatch = textFinder().activeMatch(); |
| 101 EXPECT_TRUE(activeMatch); | 101 EXPECT_TRUE(activeMatch); |
| 102 if (activeMatch) { | 102 if (activeMatch) { |
| 103 EXPECT_EQ(textNode, activeMatch->startContainer(ASSERT_NO_EXCEPTION)); | 103 EXPECT_EQ(textNode, activeMatch->startContainer()); |
| 104 EXPECT_EQ(4, activeMatch->startOffset(ASSERT_NO_EXCEPTION)); | 104 EXPECT_EQ(4, activeMatch->startOffset()); |
| 105 EXPECT_EQ(textNode, activeMatch->endContainer(ASSERT_NO_EXCEPTION)); | 105 EXPECT_EQ(textNode, activeMatch->endContainer()); |
| 106 EXPECT_EQ(10, activeMatch->endOffset(ASSERT_NO_EXCEPTION)); | 106 EXPECT_EQ(10, activeMatch->endOffset()); |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 | 109 |
| 110 TEST_F(TextFinderTest, ScopeTextMatchesSimple) | 110 TEST_F(TextFinderTest, ScopeTextMatchesSimple) |
| 111 { | 111 { |
| 112 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT
ION); | 112 document().body()->setInnerHTML("XXXXFindMeYYYYfindmeZZZZ", ASSERT_NO_EXCEPT
ION); |
| 113 Node* textNode = document().body()->firstChild(); | 113 Node* textNode = document().body()->firstChild(); |
| 114 | 114 |
| 115 int identifier = 0; | 115 int identifier = 0; |
| 116 WebString searchText(String("FindMe")); | 116 WebString searchText(String("FindMe")); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 EXPECT_EQ(3, textFinder().totalMatchCount()); | 152 EXPECT_EQ(3, textFinder().totalMatchCount()); |
| 153 WebVector<WebFloatRect> matchRects; | 153 WebVector<WebFloatRect> matchRects; |
| 154 textFinder().findMatchRects(matchRects); | 154 textFinder().findMatchRects(matchRects); |
| 155 ASSERT_EQ(3u, matchRects.size()); | 155 ASSERT_EQ(3u, matchRects.size()); |
| 156 EXPECT_EQ(findInPageRect(textInUElement, 0, textInUElement, 3), matchRects[0
]); | 156 EXPECT_EQ(findInPageRect(textInUElement, 0, textInUElement, 3), matchRects[0
]); |
| 157 EXPECT_EQ(findInPageRect(textInBElement, 0, textInBElement, 3), matchRects[1
]); | 157 EXPECT_EQ(findInPageRect(textInBElement, 0, textInBElement, 3), matchRects[1
]); |
| 158 EXPECT_EQ(findInPageRect(textInIElement, 0, textInIElement, 3), matchRects[2
]); | 158 EXPECT_EQ(findInPageRect(textInIElement, 0, textInIElement, 3), matchRects[2
]); |
| 159 } | 159 } |
| 160 | 160 |
| 161 } // namespace | 161 } // namespace |
| OLD | NEW |