1 // Copyright 2013 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.
5 #include "chrome/test/base/find_in_page_observer.h"
7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
9 #include "content/public/test/test_utils.h"
11 namespace ui_test_utils
{
13 FindInPageNotificationObserver::FindInPageNotificationObserver(
14 content::WebContents
* parent_tab
)
15 : active_match_ordinal_(-1),
16 number_of_matches_(0),
17 current_find_request_id_(0),
20 FindTabHelper
* find_tab_helper
=
21 FindTabHelper::FromWebContents(parent_tab
);
22 current_find_request_id_
= find_tab_helper
->current_find_request_id();
23 registrar_
.Add(this, chrome::NOTIFICATION_FIND_RESULT_AVAILABLE
,
24 content::Source
<content::WebContents
>(parent_tab
));
27 FindInPageNotificationObserver::~FindInPageNotificationObserver() {}
29 void FindInPageNotificationObserver::Wait() {
33 message_loop_runner_
= new content::MessageLoopRunner
;
34 message_loop_runner_
->Run();
37 void FindInPageNotificationObserver::Observe(
39 const content::NotificationSource
& source
,
40 const content::NotificationDetails
& details
) {
41 if (type
== chrome::NOTIFICATION_FIND_RESULT_AVAILABLE
) {
42 content::Details
<FindNotificationDetails
> find_details(details
);
43 if (find_details
->request_id() == current_find_request_id_
) {
44 // We get multiple responses and one of those will contain the ordinal.
45 // This message comes to us before the final update is sent.
46 if (find_details
->active_match_ordinal() > -1) {
47 active_match_ordinal_
= find_details
->active_match_ordinal();
48 selection_rect_
= find_details
->selection_rect();
50 if (find_details
->final_update()) {
51 number_of_matches_
= find_details
->number_of_matches();
55 message_loop_runner_
->Quit();
58 DVLOG(1) << "Ignoring, since we only care about the final message";
66 } // namespace ui_test_utils