| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/test/test_find_request_manager.h" |
| 6 |
| 7 #include "content/browser/web_contents/web_contents_impl.h" |
| 8 |
| 9 namespace content { |
| 10 |
| 11 TestFindRequestManager::TestFindRequestManager(WebContentsImpl* web_contents) |
| 12 : FindRequestManager(web_contents), |
| 13 last_request_id_(kInvalidId), |
| 14 last_finished_request_id_(kInvalidId), |
| 15 waiting_request_id_(kInvalidId) {} |
| 16 |
| 17 TestFindRequestManager::~TestFindRequestManager() {} |
| 18 |
| 19 void TestFindRequestManager::Find(int request_id, |
| 20 const base::string16& search_text, |
| 21 const blink::WebFindOptions& options) { |
| 22 last_request_id_ = request_id; |
| 23 FindRequestManager::Find(request_id, search_text, options); |
| 24 } |
| 25 |
| 26 void TestFindRequestManager::WaitForFinalReply() { |
| 27 if (last_finished_request_id_ == last_request_id_) |
| 28 return; |
| 29 |
| 30 waiting_request_id_ = last_request_id_; |
| 31 find_message_loop_runner_ = new content::MessageLoopRunner; |
| 32 find_message_loop_runner_->Run(); |
| 33 } |
| 34 |
| 35 TestFindRequestManager::FindResults TestFindRequestManager::GetFindResults() { |
| 36 FindResults results; |
| 37 results.request_id = last_finished_request_id_; |
| 38 results.number_of_matches = number_of_matches_; |
| 39 results.active_match_ordinal = active_match_ordinal_; |
| 40 return results; |
| 41 } |
| 42 |
| 43 void TestFindRequestManager::NotifyFindReply(int request_id, |
| 44 bool final_update) const { |
| 45 if (final_update) |
| 46 last_finished_request_id_ = request_id; |
| 47 |
| 48 // If we are waiting for a final reply and this is it, stop waiting. |
| 49 if (find_message_loop_runner_.get() && |
| 50 last_finished_request_id_ >= waiting_request_id_) { |
| 51 find_message_loop_runner_->Quit(); |
| 52 } |
| 53 |
| 54 FindRequestManager::NotifyFindReply(request_id, final_update); |
| 55 } |
| 56 |
| 57 } // namespace content |
| OLD | NEW |