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

Side by Side Diff: third_party/WebKit/Source/web/tests/WebFrameTest.cpp

Issue 2857173003: Remove DocumentMarkerController::MarkersInRange() (Closed)
Patch Set: Use std::find_if() Created 3 years, 7 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
« no previous file with comments | « third_party/WebKit/Source/web/ContextMenuClientImpl.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 void SwapAndVerifyMiddleChildConsistency(const char* const message, 314 void SwapAndVerifyMiddleChildConsistency(const char* const message,
315 WebFrame* parent, 315 WebFrame* parent,
316 WebFrame* new_child); 316 WebFrame* new_child);
317 void SwapAndVerifyLastChildConsistency(const char* const message, 317 void SwapAndVerifyLastChildConsistency(const char* const message,
318 WebFrame* parent, 318 WebFrame* parent,
319 WebFrame* new_child); 319 WebFrame* new_child);
320 void SwapAndVerifySubframeConsistency(const char* const message, 320 void SwapAndVerifySubframeConsistency(const char* const message,
321 WebFrame* parent, 321 WebFrame* parent,
322 WebFrame* new_child); 322 WebFrame* new_child);
323 323
324 int NumMarkersInRange(const Document* document,
325 const EphemeralRange& range,
326 DocumentMarker::MarkerTypes marker_types) {
327 Node* start_container = range.StartPosition().ComputeContainerNode();
328 unsigned start_offset = static_cast<unsigned>(
329 range.StartPosition().ComputeOffsetInContainerNode());
330
331 Node* end_container = range.EndPosition().ComputeContainerNode();
332 unsigned end_offset = static_cast<unsigned>(
333 range.EndPosition().ComputeOffsetInContainerNode());
334
335 int node_count = 0;
336 for (Node& node : range.Nodes()) {
337 const DocumentMarkerVector& markers_in_node =
338 document->Markers().MarkersFor(&node, marker_types);
339 node_count += std::count_if(
340 markers_in_node.begin(), markers_in_node.end(),
341 [start_offset, end_offset, &node, &start_container,
342 &end_container](const DocumentMarker* marker) {
343 if (node == start_container && marker->EndOffset() <= start_offset)
344 return false;
345 if (node == end_container && marker->StartOffset() >= end_offset)
346 return false;
347 return true;
348 });
349 }
350
351 return node_count;
352 }
353
324 std::string base_url_; 354 std::string base_url_;
325 std::string not_base_url_; 355 std::string not_base_url_;
326 std::string chrome_url_; 356 std::string chrome_url_;
327 }; 357 };
328 358
329 typedef bool TestParamRootLayerScrolling; 359 typedef bool TestParamRootLayerScrolling;
330 class ParameterizedWebFrameTest 360 class ParameterizedWebFrameTest
331 : public ::testing::WithParamInterface<TestParamRootLayerScrolling>, 361 : public ::testing::WithParamInterface<TestParamRootLayerScrolling>,
332 private ScopedRootLayerScrollingForTest, 362 private ScopedRootLayerScrollingForTest,
333 public WebFrameTest { 363 public WebFrameTest {
(...skipping 6206 matching lines...) Expand 10 before | Expand all | Expand 10 after
6540 const int kAllTextBeginOffset = 0; 6570 const int kAllTextBeginOffset = 0;
6541 const int kAllTextLength = 11; 6571 const int kAllTextLength = 11;
6542 frame->SelectRange(WebRange(kAllTextBeginOffset, kAllTextLength)); 6572 frame->SelectRange(WebRange(kAllTextBeginOffset, kAllTextLength));
6543 EphemeralRange selection_range = 6573 EphemeralRange selection_range =
6544 frame->GetFrame() 6574 frame->GetFrame()
6545 ->Selection() 6575 ->Selection()
6546 .ComputeVisibleSelectionInDOMTreeDeprecated() 6576 .ComputeVisibleSelectionInDOMTreeDeprecated()
6547 .ToNormalizedEphemeralRange(); 6577 .ToNormalizedEphemeralRange();
6548 6578
6549 EXPECT_EQ(1, textcheck.NumberOfTimesChecked()); 6579 EXPECT_EQ(1, textcheck.NumberOfTimesChecked());
6550 EXPECT_EQ(1U, document->Markers() 6580 EXPECT_EQ(1, NumMarkersInRange(document, selection_range,
6551 .MarkersInRange(selection_range, DocumentMarker::kSpelling) 6581 DocumentMarker::kSpelling));
6552 .size());
6553 6582
6554 frame->ReplaceMisspelledRange("welcome"); 6583 frame->ReplaceMisspelledRange("welcome");
6555 EXPECT_EQ("_welcome_.", 6584 EXPECT_EQ("_welcome_.",
6556 WebFrameContentDumper::DumpWebViewAsText( 6585 WebFrameContentDumper::DumpWebViewAsText(
6557 web_view_helper.WebView(), std::numeric_limits<size_t>::max()) 6586 web_view_helper.WebView(), std::numeric_limits<size_t>::max())
6558 .Utf8()); 6587 .Utf8());
6559 } 6588 }
6560 6589
6561 TEST_P(ParameterizedWebFrameTest, RemoveSpellingMarkers) { 6590 TEST_P(ParameterizedWebFrameTest, RemoveSpellingMarkers) {
6562 RegisterMockedHttpURLLoad("spell.html"); 6591 RegisterMockedHttpURLLoad("spell.html");
(...skipping 26 matching lines...) Expand all
6589 6618
6590 const int kAllTextBeginOffset = 0; 6619 const int kAllTextBeginOffset = 0;
6591 const int kAllTextLength = 11; 6620 const int kAllTextLength = 11;
6592 frame->SelectRange(WebRange(kAllTextBeginOffset, kAllTextLength)); 6621 frame->SelectRange(WebRange(kAllTextBeginOffset, kAllTextLength));
6593 EphemeralRange selection_range = 6622 EphemeralRange selection_range =
6594 frame->GetFrame() 6623 frame->GetFrame()
6595 ->Selection() 6624 ->Selection()
6596 .ComputeVisibleSelectionInDOMTreeDeprecated() 6625 .ComputeVisibleSelectionInDOMTreeDeprecated()
6597 .ToNormalizedEphemeralRange(); 6626 .ToNormalizedEphemeralRange();
6598 6627
6599 EXPECT_EQ(0U, document->Markers() 6628 EXPECT_EQ(0, NumMarkersInRange(document, selection_range,
6600 .MarkersInRange(selection_range, DocumentMarker::kSpelling) 6629 DocumentMarker::kSpelling));
6601 .size());
6602 } 6630 }
6603 6631
6604 static void GetSpellingMarkerOffsets(WebVector<unsigned>* offsets, 6632 static void GetSpellingMarkerOffsets(WebVector<unsigned>* offsets,
6605 const Document& document) { 6633 const Document& document) {
6606 Vector<unsigned> result; 6634 Vector<unsigned> result;
6607 const DocumentMarkerVector& document_markers = document.Markers().Markers(); 6635 const DocumentMarkerVector& document_markers = document.Markers().Markers();
6608 for (size_t i = 0; i < document_markers.size(); ++i) 6636 for (size_t i = 0; i < document_markers.size(); ++i)
6609 result.push_back(document_markers[i]->StartOffset()); 6637 result.push_back(document_markers[i]->StartOffset());
6610 offsets->Assign(result); 6638 offsets->Assign(result);
6611 } 6639 }
(...skipping 5443 matching lines...) Expand 10 before | Expand all | Expand 10 after
12055 12083
12056 // Failing the original child frame navigation and trying to render fallback 12084 // Failing the original child frame navigation and trying to render fallback
12057 // content shouldn't crash. It should return NoLoadInProgress. This is so the 12085 // content shouldn't crash. It should return NoLoadInProgress. This is so the
12058 // caller won't attempt to replace the correctly empty frame with an error 12086 // caller won't attempt to replace the correctly empty frame with an error
12059 // page. 12087 // page.
12060 EXPECT_EQ(WebLocalFrame::NoLoadInProgress, 12088 EXPECT_EQ(WebLocalFrame::NoLoadInProgress,
12061 child->MaybeRenderFallbackContent(WebURLError())); 12089 child->MaybeRenderFallbackContent(WebURLError()));
12062 } 12090 }
12063 12091
12064 } // namespace blink 12092 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/ContextMenuClientImpl.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698