| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "content/public/test/find_test_utils.h" | 5 #include "content/public/test/find_test_utils.h" |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 namespace content { | 9 namespace content { |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 const int kInvalidId = -1; | 13 const int kInvalidId = -1; |
| 14 | 14 |
| 15 } // namespace | 15 } // namespace |
| 16 | 16 |
| 17 FindResults::FindResults(int request_id, | 17 FindResults::FindResults(int request_id, |
| 18 int number_of_matches, | 18 int number_of_matches, |
| 19 int active_match_ordinal) | 19 int active_match_ordinal, |
| 20 bool was_frame_removal) |
| 20 : request_id(request_id), | 21 : request_id(request_id), |
| 21 number_of_matches(number_of_matches), | 22 number_of_matches(number_of_matches), |
| 22 active_match_ordinal(active_match_ordinal) {} | 23 active_match_ordinal(active_match_ordinal), |
| 24 was_frame_removal(was_frame_removal) {} |
| 23 | 25 |
| 24 FindResults::FindResults() : FindResults(kInvalidId, 0, 0) {} | 26 FindResults::FindResults() : FindResults(kInvalidId, 0, 0, false) {} |
| 25 | 27 |
| 26 FindTestWebContentsDelegate::FindTestWebContentsDelegate() | 28 FindTestWebContentsDelegate::FindTestWebContentsDelegate() |
| 27 : last_request_id_(kInvalidId), | 29 : last_request_id_(kInvalidId), |
| 28 last_finished_request_id_(kInvalidId), | 30 last_finished_request_id_(kInvalidId), |
| 29 next_reply_received_(false), | 31 next_reply_received_(false), |
| 30 record_replies_(false), | 32 record_replies_(false), |
| 31 waiting_for_(NOTHING) {} | 33 waiting_for_(NOTHING) {} |
| 32 | 34 |
| 33 FindTestWebContentsDelegate::~FindTestWebContentsDelegate() {} | 35 FindTestWebContentsDelegate::~FindTestWebContentsDelegate() {} |
| 34 | 36 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 void FindTestWebContentsDelegate::WaitForMatchRects() { | 74 void FindTestWebContentsDelegate::WaitForMatchRects() { |
| 73 WaitFor(MATCH_RECTS); | 75 WaitFor(MATCH_RECTS); |
| 74 } | 76 } |
| 75 #endif | 77 #endif |
| 76 | 78 |
| 77 void FindTestWebContentsDelegate::FindReply(WebContents* web_contents, | 79 void FindTestWebContentsDelegate::FindReply(WebContents* web_contents, |
| 78 int request_id, | 80 int request_id, |
| 79 int number_of_matches, | 81 int number_of_matches, |
| 80 const gfx::Rect& selection_rect, | 82 const gfx::Rect& selection_rect, |
| 81 int active_match_ordinal, | 83 int active_match_ordinal, |
| 82 bool final_update) { | 84 bool final_update, |
| 85 bool was_frame_removal) { |
| 83 if (record_replies_) { | 86 if (record_replies_) { |
| 84 reply_record_.emplace_back( | 87 reply_record_.emplace_back(request_id, number_of_matches, |
| 85 request_id, number_of_matches, active_match_ordinal); | 88 active_match_ordinal, was_frame_removal); |
| 86 } | 89 } |
| 87 | 90 |
| 88 // Update the current results. | 91 // Update the current results. |
| 89 if (request_id > current_results_.request_id) | 92 if (request_id > current_results_.request_id) |
| 90 current_results_.request_id = request_id; | 93 current_results_.request_id = request_id; |
| 91 if (number_of_matches != -1) | 94 if (number_of_matches != -1) |
| 92 current_results_.number_of_matches = number_of_matches; | 95 current_results_.number_of_matches = number_of_matches; |
| 93 if (active_match_ordinal != -1) | 96 if (active_match_ordinal != -1) |
| 94 current_results_.active_match_ordinal = active_match_ordinal; | 97 current_results_.active_match_ordinal = active_match_ordinal; |
| 98 current_results_.was_frame_removal = was_frame_removal; |
| 95 | 99 |
| 96 if (!final_update) | 100 if (!final_update) |
| 97 return; | 101 return; |
| 98 | 102 |
| 99 if (request_id > last_finished_request_id_) | 103 if (request_id > last_finished_request_id_) |
| 100 last_finished_request_id_ = request_id; | 104 last_finished_request_id_ = request_id; |
| 101 next_reply_received_ = true; | 105 next_reply_received_ = true; |
| 102 | 106 |
| 103 // If we are waiting for this find reply, stop waiting. | 107 // If we are waiting for this find reply, stop waiting. |
| 104 if (waiting_for_ == NEXT_REPLY || | 108 if (waiting_for_ == NEXT_REPLY || |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 find_match_rects_ = rects; | 144 find_match_rects_ = rects; |
| 141 active_match_rect_ = active_rect; | 145 active_match_rect_ = active_rect; |
| 142 | 146 |
| 143 // If we are waiting for match rects, stop waiting. | 147 // If we are waiting for match rects, stop waiting. |
| 144 if (waiting_for_ == MATCH_RECTS) | 148 if (waiting_for_ == MATCH_RECTS) |
| 145 StopWaiting(); | 149 StopWaiting(); |
| 146 } | 150 } |
| 147 #endif | 151 #endif |
| 148 | 152 |
| 149 } // namespace content | 153 } // namespace content |
| OLD | NEW |