1 // Copyright (c) 2012 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 "base/file_util.h"
6 #include "base/message_loop/message_loop.h"
7 #include "base/prefs/pref_service.h"
8 #include "base/strings/string16.h"
9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/app/chrome_command_ids.h"
12 #include "chrome/browser/common/cancelable_request.h"
13 #include "chrome/browser/history/history_service.h"
14 #include "chrome/browser/history/history_service_factory.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_commands.h"
18 #include "chrome/browser/ui/browser_finder.h"
19 #include "chrome/browser/ui/browser_navigator.h"
20 #include "chrome/browser/ui/browser_tabstrip.h"
21 #include "chrome/browser/ui/browser_window.h"
22 #include "chrome/browser/ui/chrome_pages.h"
23 #include "chrome/browser/ui/find_bar/find_bar.h"
24 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
25 #include "chrome/browser/ui/find_bar/find_bar_host_unittest_util.h"
26 #include "chrome/browser/ui/find_bar/find_notification_details.h"
27 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
28 #include "chrome/browser/ui/tabs/tab_strip_model.h"
29 #include "chrome/common/pref_names.h"
30 #include "chrome/common/url_constants.h"
31 #include "chrome/test/base/find_in_page_observer.h"
32 #include "chrome/test/base/in_process_browser_test.h"
33 #include "chrome/test/base/ui_test_utils.h"
34 #include "content/public/browser/download_manager.h"
35 #include "content/public/browser/notification_service.h"
36 #include "content/public/browser/notification_types.h"
37 #include "content/public/browser/render_view_host.h"
38 #include "content/public/browser/web_contents.h"
39 #include "content/public/browser/web_contents_view.h"
40 #include "content/public/test/browser_test_utils.h"
41 #include "net/base/net_util.h"
42 #include "ui/base/accelerators/accelerator.h"
43 #include "ui/events/keycodes/keyboard_codes.h"
45 #if defined(OS_WIN) && defined(USE_AURA)
46 #include "content/public/browser/web_contents_view.h"
47 #include "ui/aura/root_window.h"
48 #include "ui/aura/window.h"
51 using base::ASCIIToUTF16
;
52 using base::WideToUTF16
;
53 using content::NavigationController
;
54 using content::WebContents
;
58 const char kAnchorPage
[] = "anchor.html";
59 const char kAnchor
[] = "#chapter2";
60 const char kFramePage
[] = "frames.html";
61 const char kFrameData
[] = "framedata_general.html";
62 const char kUserSelectPage
[] = "user-select.html";
63 const char kCrashPage
[] = "crash_1341577.html";
64 const char kTooFewMatchesPage
[] = "bug_1155639.html";
65 const char kLongTextareaPage
[] = "large_textarea.html";
66 const char kEndState
[] = "end_state.html";
67 const char kPrematureEnd
[] = "premature_end.html";
68 const char kMoveIfOver
[] = "move_if_obscuring.html";
69 const char kBitstackCrash
[] = "crash_14491.html";
70 const char kSelectChangesOrdinal
[] = "select_changes_ordinal.html";
71 const char kStartAfterSelection
[] = "start_after_selection.html";
72 const char kSimple
[] = "simple.html";
73 const char kLinkPage
[] = "link.html";
75 const bool kBack
= false;
76 const bool kFwd
= true;
78 const bool kIgnoreCase
= false;
79 const bool kCaseSensitive
= true;
81 const int kMoveIterations
= 30;
85 class FindInPageControllerTest
: public InProcessBrowserTest
{
87 FindInPageControllerTest() {
88 chrome::DisableFindBarAnimationsDuringTesting(true);
92 bool GetFindBarWindowInfoForBrowser(
93 Browser
* browser
, gfx::Point
* position
, bool* fully_visible
) {
94 FindBarTesting
* find_bar
=
95 browser
->GetFindBarController()->find_bar()->GetFindBarTesting();
96 return find_bar
->GetFindBarWindowInfo(position
, fully_visible
);
99 bool GetFindBarWindowInfo(gfx::Point
* position
, bool* fully_visible
) {
100 return GetFindBarWindowInfoForBrowser(browser(), position
, fully_visible
);
103 base::string16
GetFindBarTextForBrowser(Browser
* browser
) {
104 FindBar
* find_bar
= browser
->GetFindBarController()->find_bar();
105 return find_bar
->GetFindText();
108 base::string16
GetFindBarText() {
109 return GetFindBarTextForBrowser(browser());
112 base::string16
GetFindBarMatchCountTextForBrowser(Browser
* browser
) {
113 FindBarTesting
* find_bar
=
114 browser
->GetFindBarController()->find_bar()->GetFindBarTesting();
115 return find_bar
->GetMatchCountText();
118 base::string16
GetMatchCountText() {
119 return GetFindBarMatchCountTextForBrowser(browser());
122 int GetFindBarWidthForBrowser(Browser
* browser
) {
123 FindBarTesting
* find_bar
=
124 browser
->GetFindBarController()->find_bar()->GetFindBarTesting();
125 return find_bar
->GetWidth();
128 void EnsureFindBoxOpenForBrowser(Browser
* browser
) {
129 chrome::ShowFindBar(browser
);
131 bool fully_visible
= false;
132 EXPECT_TRUE(GetFindBarWindowInfoForBrowser(
133 browser
, &position
, &fully_visible
));
134 EXPECT_TRUE(fully_visible
);
137 void EnsureFindBoxOpen() {
138 EnsureFindBoxOpenForBrowser(browser());
141 // Platform independent FindInPage that takes |const wchar_t*|
143 int FindInPageWchar(WebContents
* web_contents
,
144 const wchar_t* search_str
,
148 base::string16
search_str16(WideToUTF16(std::wstring(search_str
)));
149 Browser
* browser
= chrome::FindBrowserWithWebContents(web_contents
);
150 browser
->GetFindBarController()->find_bar()->SetFindTextAndSelectedRange(
151 search_str16
, gfx::Range());
152 return ui_test_utils::FindInPage(
153 web_contents
, search_str16
, forward
, case_sensitive
, ordinal
, NULL
);
156 // Calls FindInPageWchar till the find box's x position != |start_x_position|.
157 // Return |start_x_position| if the find box has not moved after iterating
158 // through all matches of |search_str|.
159 int FindInPageTillBoxMoves(WebContents
* web_contents
,
160 int start_x_position
,
161 const wchar_t* search_str
,
162 int expected_matches
) {
163 // Search for |search_str| which the Find box is obscuring.
164 for (int index
= 0; index
< expected_matches
; ++index
) {
166 EXPECT_EQ(expected_matches
, FindInPageWchar(web_contents
, search_str
,
167 kFwd
, kIgnoreCase
, &ordinal
));
169 // Check the position.
172 EXPECT_TRUE(GetFindBarWindowInfo(&position
, &fully_visible
));
173 EXPECT_TRUE(fully_visible
);
175 // If the Find box has moved then we are done.
176 if (position
.x() != start_x_position
)
179 return start_x_position
;
182 GURL
GetURL(const std::string
& filename
) {
183 return ui_test_utils::GetTestUrl(
184 base::FilePath().AppendASCII("find_in_page"),
185 base::FilePath().AppendASCII(filename
));
188 void FlushHistoryService() {
189 HistoryServiceFactory::GetForProfile(
190 browser()->profile(), Profile::IMPLICIT_ACCESS
)->FlushForTest(
191 base::Bind(&base::MessageLoop::Quit
,
192 base::Unretained(base::MessageLoop::current()->current())));
193 content::RunMessageLoop();
197 // This test loads a page with frames and starts FindInPage requests.
198 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, FindInPageFrames
) {
199 // First we navigate to our frames page.
200 GURL url
= GetURL(kFramePage
);
201 ui_test_utils::NavigateToURL(browser(), url
);
203 // Try incremental search (mimicking user typing in).
205 WebContents
* web_contents
=
206 browser()->tab_strip_model()->GetActiveWebContents();
207 EXPECT_EQ(18, FindInPageWchar(web_contents
, L
"g",
208 kFwd
, kIgnoreCase
, &ordinal
));
209 EXPECT_EQ(1, ordinal
);
210 EXPECT_EQ(11, FindInPageWchar(web_contents
, L
"go",
211 kFwd
, kIgnoreCase
, &ordinal
));
212 EXPECT_EQ(1, ordinal
);
213 EXPECT_EQ(4, FindInPageWchar(web_contents
, L
"goo",
214 kFwd
, kIgnoreCase
, &ordinal
));
215 EXPECT_EQ(1, ordinal
);
216 EXPECT_EQ(3, FindInPageWchar(web_contents
, L
"goog",
217 kFwd
, kIgnoreCase
, &ordinal
));
218 EXPECT_EQ(1, ordinal
);
219 EXPECT_EQ(2, FindInPageWchar(web_contents
, L
"googl",
220 kFwd
, kIgnoreCase
, &ordinal
));
221 EXPECT_EQ(1, ordinal
);
222 EXPECT_EQ(1, FindInPageWchar(web_contents
, L
"google",
223 kFwd
, kIgnoreCase
, &ordinal
));
224 EXPECT_EQ(1, ordinal
);
225 EXPECT_EQ(0, FindInPageWchar(web_contents
, L
"google!",
226 kFwd
, kIgnoreCase
, &ordinal
));
227 EXPECT_EQ(0, ordinal
);
229 // Negative test (no matches should be found).
230 EXPECT_EQ(0, FindInPageWchar(web_contents
, L
"Non-existing string",
231 kFwd
, kIgnoreCase
, &ordinal
));
232 EXPECT_EQ(0, ordinal
);
234 // 'horse' only exists in the three right frames.
235 EXPECT_EQ(3, FindInPageWchar(web_contents
, L
"horse",
236 kFwd
, kIgnoreCase
, &ordinal
));
237 EXPECT_EQ(1, ordinal
);
239 // 'cat' only exists in the first frame.
240 EXPECT_EQ(1, FindInPageWchar(web_contents
, L
"cat",
241 kFwd
, kIgnoreCase
, &ordinal
));
242 EXPECT_EQ(1, ordinal
);
244 // Try searching again, should still come up with 1 match.
245 EXPECT_EQ(1, FindInPageWchar(web_contents
, L
"cat",
246 kFwd
, kIgnoreCase
, &ordinal
));
247 EXPECT_EQ(1, ordinal
);
249 // Try searching backwards, ignoring case, should still come up with 1 match.
250 EXPECT_EQ(1, FindInPageWchar(web_contents
, L
"CAT",
251 kBack
, kIgnoreCase
, &ordinal
));
252 EXPECT_EQ(1, ordinal
);
254 // Try case sensitive, should NOT find it.
255 EXPECT_EQ(0, FindInPageWchar(web_contents
, L
"CAT",
256 kFwd
, kCaseSensitive
, &ordinal
));
257 EXPECT_EQ(0, ordinal
);
259 // Try again case sensitive, but this time with right case.
260 EXPECT_EQ(1, FindInPageWchar(web_contents
, L
"dog",
261 kFwd
, kCaseSensitive
, &ordinal
));
262 EXPECT_EQ(1, ordinal
);
264 // Try non-Latin characters ('Hreggvidur' with 'eth' for 'd' in left frame).
265 EXPECT_EQ(1, FindInPageWchar(web_contents
, L
"Hreggvi\u00F0ur",
266 kFwd
, kIgnoreCase
, &ordinal
));
267 EXPECT_EQ(1, ordinal
);
268 EXPECT_EQ(1, FindInPageWchar(web_contents
, L
"Hreggvi\u00F0ur",
269 kFwd
, kCaseSensitive
, &ordinal
));
270 EXPECT_EQ(1, ordinal
);
271 EXPECT_EQ(0, FindInPageWchar(web_contents
, L
"hreggvi\u00F0ur",
272 kFwd
, kCaseSensitive
, &ordinal
));
273 EXPECT_EQ(0, ordinal
);
276 // Verify search for text within various forms and text areas.
277 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, FindInPageFormsTextAreas
) {
278 std::vector
<GURL
> urls
;
279 urls
.push_back(GetURL("textintextarea.html"));
280 urls
.push_back(GetURL("smalltextarea.html"));
281 urls
.push_back(GetURL("populatedform.html"));
282 WebContents
* web_contents
=
283 browser()->tab_strip_model()->GetActiveWebContents();
285 for (size_t i
= 0; i
< urls
.size(); ++i
) {
286 ui_test_utils::NavigateToURL(browser(), urls
[i
]);
287 EXPECT_EQ(1, FindInPageWchar(web_contents
, L
"cat",
288 kFwd
, kIgnoreCase
, NULL
));
289 EXPECT_EQ(0, FindInPageWchar(web_contents
, L
"bat",
290 kFwd
, kIgnoreCase
, NULL
));
294 // Verify search for text within special URLs such as chrome:history,
295 // chrome://downloads, data directory
296 #if defined(OS_WIN) && defined(USE_AURA)
297 // Disabled due to crbug.com/175711
298 #define MAYBE_SearchWithinSpecialURL \
299 DISABLED_SearchWithinSpecialURL
301 #define MAYBE_SearchWithinSpecialURL \
302 SearchWithinSpecialURL
304 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, MAYBE_SearchWithinSpecialURL
) {
305 WebContents
* web_contents
=
306 browser()->tab_strip_model()->GetActiveWebContents();
308 base::FilePath data_dir
=
309 ui_test_utils::GetTestFilePath(base::FilePath(), base::FilePath());
310 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(data_dir
));
311 EXPECT_EQ(1, FindInPageWchar(web_contents
, L
"downloads",
312 kFwd
, kIgnoreCase
, NULL
));
314 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIHistoryURL
));
316 // The history page does an async request to the history service and then
317 // updates the renderer. So we make a query as well, and by the time it comes
318 // back we know the data is on its way to the renderer.
319 FlushHistoryService();
321 base::string16
query(data_dir
.LossyDisplayName());
323 ui_test_utils::FindInPage(web_contents
, query
,
324 kFwd
, kIgnoreCase
, NULL
, NULL
));
326 GURL download_url
= ui_test_utils::GetTestUrl(
327 base::FilePath().AppendASCII("downloads"),
328 base::FilePath().AppendASCII("a_zip_file.zip"));
329 ui_test_utils::DownloadURL(browser(), download_url
);
331 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL
));
332 FlushHistoryService();
334 FindInPageWchar(web_contents
,
335 base::ASCIIToWide(download_url
.spec()).c_str(),
336 kFwd
, kIgnoreCase
, NULL
));
339 // Verify search selection coordinates. The data file used is set-up such that
340 // the text occurs on the same line, and we verify their positions by verifying
341 // their relative positions.
342 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, FindInPageSpecialURLs
) {
343 std::wstring
search_string(L
"\u5728\u897f\u660c\u536b\u661f\u53d1");
344 gfx::Rect first
, second
, first_reverse
;
345 WebContents
* web_contents
=
346 browser()->tab_strip_model()->GetActiveWebContents();
347 ui_test_utils::NavigateToURL(browser(), GetURL("specialchar.html"));
348 ui_test_utils::FindInPage(web_contents
, WideToUTF16(search_string
),
349 kFwd
, kIgnoreCase
, NULL
, &first
);
350 ui_test_utils::FindInPage(web_contents
, WideToUTF16(search_string
),
351 kFwd
, kIgnoreCase
, NULL
, &second
);
353 // We have search occurrence in the same row, so top-bottom coordinates should
354 // be the same even for second search.
355 ASSERT_EQ(first
.y(), second
.y());
356 ASSERT_EQ(first
.bottom(), second
.bottom());
357 ASSERT_LT(first
.x(), second
.x());
358 ASSERT_LT(first
.right(), second
.right());
360 ui_test_utils::FindInPage(
361 web_contents
, WideToUTF16(search_string
), kBack
, kIgnoreCase
, NULL
,
363 // We find next and we go back so find coordinates should be the same as
365 ASSERT_EQ(first
, first_reverse
);
368 // Verifies that comments and meta data are not searchable.
369 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
,
370 CommentsAndMetaDataNotSearchable
) {
371 WebContents
* web_contents
=
372 browser()->tab_strip_model()->GetActiveWebContents();
373 ui_test_utils::NavigateToURL(browser(), GetURL("specialchar.html"));
375 std::wstring search_string
=
376 L
"\u4e2d\u65b0\u793e\u8bb0\u8005\u5b8b\u5409\u6cb3\u6444\u4e2d\u65b0\u7f51";
377 EXPECT_EQ(0, ui_test_utils::FindInPage(
378 web_contents
, WideToUTF16(search_string
), kFwd
, kIgnoreCase
, NULL
, NULL
));
381 // Verifies that span and lists are searchable.
382 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, SpanAndListsSearchable
) {
383 WebContents
* web_contents
=
384 browser()->tab_strip_model()->GetActiveWebContents();
385 ui_test_utils::NavigateToURL(browser(), GetURL("FindRandomTests.html"));
387 std::wstring search_string
= L
"has light blue eyes and my father has dark";
388 EXPECT_EQ(1, ui_test_utils::FindInPage(
389 web_contents
, WideToUTF16(search_string
), kFwd
, kIgnoreCase
, NULL
, NULL
));
391 search_string
= L
"Google\nApple\nandroid";
392 EXPECT_EQ(1, ui_test_utils::FindInPage(
393 web_contents
, WideToUTF16(search_string
), kFwd
, kIgnoreCase
, NULL
, NULL
));
396 // Find in a very large page.
397 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, LargePage
) {
398 WebContents
* web_contents
=
399 browser()->tab_strip_model()->GetActiveWebContents();
400 ui_test_utils::NavigateToURL(browser(), GetURL("largepage.html"));
402 std::wstring search_string
= L
"daughter of Prince";
404 FindInPageWchar(web_contents
, search_string
.c_str(),
405 kFwd
, kIgnoreCase
, NULL
));
408 // Find a very long string in a large page.
409 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, FindLongString
) {
410 WebContents
* web_contents
=
411 browser()->tab_strip_model()->GetActiveWebContents();
412 ui_test_utils::NavigateToURL(browser(), GetURL("largepage.html"));
414 base::FilePath path
= ui_test_utils::GetTestFilePath(
415 base::FilePath().AppendASCII("find_in_page"),
416 base::FilePath().AppendASCII("LongFind.txt"));
418 base::ReadFileToString(path
, &query
);
419 std::wstring search_string
= base::UTF8ToWide(query
);
421 FindInPageWchar(web_contents
, search_string
.c_str(),
422 kFwd
, kIgnoreCase
, NULL
));
425 // Find a big font string in a page.
426 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, BigString
) {
427 WebContents
* web_contents
=
428 browser()->tab_strip_model()->GetActiveWebContents();
429 ui_test_utils::NavigateToURL(browser(), GetURL("BigText.html"));
431 FindInPageWchar(web_contents
, L
"SomeLargeString",
432 kFwd
, kIgnoreCase
, NULL
));
435 // Search Back and Forward on a single occurrence.
436 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, SingleOccurrence
) {
437 WebContents
* web_contents
=
438 browser()->tab_strip_model()->GetActiveWebContents();
439 ui_test_utils::NavigateToURL(browser(), GetURL("FindRandomTests.html"));
441 gfx::Rect first_rect
;
443 ui_test_utils::FindInPage(web_contents
,
444 ASCIIToUTF16("2010 Pro Bowl"), kFwd
,
445 kIgnoreCase
, NULL
, &first_rect
));
447 gfx::Rect second_rect
;
449 ui_test_utils::FindInPage(web_contents
,
450 ASCIIToUTF16("2010 Pro Bowl"), kFwd
,
451 kIgnoreCase
, NULL
, &second_rect
));
453 // Doing a fake find so we have no previous search.
454 ui_test_utils::FindInPage(web_contents
, ASCIIToUTF16("ghgfjgfh201232rere"),
455 kFwd
, kIgnoreCase
, NULL
, NULL
);
457 ASSERT_EQ(first_rect
, second_rect
);
460 ui_test_utils::FindInPage(web_contents
,
461 ASCIIToUTF16("2010 Pro Bowl"), kFwd
,
462 kIgnoreCase
, NULL
, &first_rect
));
464 ui_test_utils::FindInPage(web_contents
,
465 ASCIIToUTF16("2010 Pro Bowl"), kBack
,
466 kIgnoreCase
, NULL
, &second_rect
));
467 ASSERT_EQ(first_rect
, second_rect
);
470 // Find the whole text file page and find count should be 1.
471 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, FindWholeFileContent
) {
472 WebContents
* web_contents
=
473 browser()->tab_strip_model()->GetActiveWebContents();
475 base::FilePath path
= ui_test_utils::GetTestFilePath(
476 base::FilePath().AppendASCII("find_in_page"),
477 base::FilePath().AppendASCII("find_test.txt"));
478 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(path
));
481 base::ReadFileToString(path
, &query
);
482 std::wstring search_string
= base::UTF8ToWide(query
);
484 FindInPageWchar(web_contents
, search_string
.c_str(),
485 false, false, NULL
));
488 // Specifying a prototype so that we can add the WARN_UNUSED_RESULT attribute.
489 bool FocusedOnPage(WebContents
* web_contents
, std::string
* result
)
492 bool FocusedOnPage(WebContents
* web_contents
, std::string
* result
) {
493 return content::ExecuteScriptAndExtractString(
495 "window.domAutomationController.send(getFocusedElement());",
499 // This tests the FindInPage end-state, in other words: what is focused when you
500 // close the Find box (ie. if you find within a link the link should be
502 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, FindInPageEndState
) {
503 // First we navigate to our special focus tracking page.
504 GURL url
= GetURL(kEndState
);
505 ui_test_utils::NavigateToURL(browser(), url
);
507 WebContents
* web_contents
=
508 browser()->tab_strip_model()->GetActiveWebContents();
509 ASSERT_TRUE(NULL
!= web_contents
);
510 FindTabHelper
* find_tab_helper
=
511 FindTabHelper::FromWebContents(web_contents
);
513 // Verify that nothing has focus.
515 ASSERT_TRUE(FocusedOnPage(web_contents
, &result
));
516 ASSERT_STREQ("{nothing focused}", result
.c_str());
518 // Search for a text that exists within a link on the page.
520 EXPECT_EQ(1, FindInPageWchar(web_contents
, L
"nk",
521 kFwd
, kIgnoreCase
, &ordinal
));
522 EXPECT_EQ(1, ordinal
);
524 // End the find session, which should set focus to the link.
525 find_tab_helper
->StopFinding(FindBarController::kKeepSelectionOnPage
);
527 // Verify that the link is focused.
528 ASSERT_TRUE(FocusedOnPage(web_contents
, &result
));
529 EXPECT_STREQ("link1", result
.c_str());
531 // Search for a text that exists within a link on the page.
532 EXPECT_EQ(1, FindInPageWchar(web_contents
, L
"Google",
533 kFwd
, kIgnoreCase
, &ordinal
));
534 EXPECT_EQ(1, ordinal
);
536 // Move the selection to link 1, after searching.
537 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
539 "window.domAutomationController.send(selectLink1());",
542 // End the find session.
543 find_tab_helper
->StopFinding(FindBarController::kKeepSelectionOnPage
);
545 // Verify that link2 is not focused.
546 ASSERT_TRUE(FocusedOnPage(web_contents
, &result
));
547 EXPECT_STREQ("", result
.c_str());
550 // This test loads a single-frame page and makes sure the ordinal returned makes
551 // sense as we FindNext over all the items.
552 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, FindInPageOrdinal
) {
553 // First we navigate to our page.
554 GURL url
= GetURL(kFrameData
);
555 ui_test_utils::NavigateToURL(browser(), url
);
557 // Search for 'o', which should make the first item active and return
558 // '1 in 3' (1st ordinal of a total of 3 matches).
559 WebContents
* web_contents
=
560 browser()->tab_strip_model()->GetActiveWebContents();
562 EXPECT_EQ(3, FindInPageWchar(web_contents
, L
"o",
563 kFwd
, kIgnoreCase
, &ordinal
));
564 EXPECT_EQ(1, ordinal
);
565 EXPECT_EQ(3, FindInPageWchar(web_contents
, L
"o",
566 kFwd
, kIgnoreCase
, &ordinal
));
567 EXPECT_EQ(2, ordinal
);
568 EXPECT_EQ(3, FindInPageWchar(web_contents
, L
"o",
569 kFwd
, kIgnoreCase
, &ordinal
));
570 EXPECT_EQ(3, ordinal
);
571 // Go back one match.
572 EXPECT_EQ(3, FindInPageWchar(web_contents
, L
"o",
573 kBack
, kIgnoreCase
, &ordinal
));
574 EXPECT_EQ(2, ordinal
);
575 EXPECT_EQ(3, FindInPageWchar(web_contents
, L
"o",
576 kFwd
, kIgnoreCase
, &ordinal
));
577 EXPECT_EQ(3, ordinal
);
578 // This should wrap to the top.
579 EXPECT_EQ(3, FindInPageWchar(web_contents
, L
"o",
580 kFwd
, kIgnoreCase
, &ordinal
));
581 EXPECT_EQ(1, ordinal
);
582 // This should go back to the end.
583 EXPECT_EQ(3, FindInPageWchar(web_contents
, L
"o",
584 kBack
, kIgnoreCase
, &ordinal
));
585 EXPECT_EQ(3, ordinal
);
588 // This tests that the ordinal is correctly adjusted after a selection
589 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
,
590 SelectChangesOrdinal_Issue20883
) {
591 // First we navigate to our test content.
592 GURL url
= GetURL(kSelectChangesOrdinal
);
593 ui_test_utils::NavigateToURL(browser(), url
);
595 // Search for a text that exists within a link on the page.
596 WebContents
* web_contents
=
597 browser()->tab_strip_model()->GetActiveWebContents();
598 ASSERT_TRUE(NULL
!= web_contents
);
599 FindTabHelper
* find_tab_helper
=
600 FindTabHelper::FromWebContents(web_contents
);
603 EXPECT_EQ(4, FindInPageWchar(web_contents
,
605 kFwd
, kIgnoreCase
, &ordinal
));
606 EXPECT_EQ(1, ordinal
);
608 // Move the selection to link 1, after searching.
610 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
612 "window.domAutomationController.send(selectLink1());",
615 // Do a find-next after the selection. This should move forward
616 // from there to the 3rd instance of 'google'.
617 EXPECT_EQ(4, FindInPageWchar(web_contents
,
619 kFwd
, kIgnoreCase
, &ordinal
));
620 EXPECT_EQ(3, ordinal
);
622 // End the find session.
623 find_tab_helper
->StopFinding(FindBarController::kKeepSelectionOnPage
);
626 // This tests that we start searching after selected text.
627 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
,
628 StartSearchAfterSelection
) {
629 // First we navigate to our test content.
630 ui_test_utils::NavigateToURL(browser(), GetURL(kStartAfterSelection
));
632 WebContents
* web_contents
=
633 browser()->tab_strip_model()->GetActiveWebContents();
634 ASSERT_TRUE(web_contents
!= NULL
);
637 // Move the selection to the text span.
639 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
641 "window.domAutomationController.send(selectSpan());",
644 // Do a find-next after the selection. This should select the 2nd occurrence
645 // of the word 'find'.
646 EXPECT_EQ(4, FindInPageWchar(web_contents
,
648 kFwd
, kIgnoreCase
, &ordinal
));
649 EXPECT_EQ(2, ordinal
);
651 // Refine the search, current active match should not change.
652 EXPECT_EQ(4, FindInPageWchar(web_contents
,
654 kFwd
, kIgnoreCase
, &ordinal
));
655 EXPECT_EQ(2, ordinal
);
657 // Refine the search to 'findMe'. The first new match is before the current
658 // active match, the second one is after it. This verifies that refining a
659 // search doesn't reset it.
660 EXPECT_EQ(2, FindInPageWchar(web_contents
,
662 kFwd
, kIgnoreCase
, &ordinal
));
663 EXPECT_EQ(2, ordinal
);
666 // This test loads a page with frames and makes sure the ordinal returned makes
668 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, FindInPageMultiFramesOrdinal
) {
669 // First we navigate to our page.
670 GURL url
= GetURL(kFramePage
);
671 ui_test_utils::NavigateToURL(browser(), url
);
673 // Search for 'a', which should make the first item active and return
674 // '1 in 7' (1st ordinal of a total of 7 matches).
675 WebContents
* web_contents
=
676 browser()->tab_strip_model()->GetActiveWebContents();
679 FindInPageWchar(web_contents
, L
"a", kFwd
, kIgnoreCase
, &ordinal
));
680 EXPECT_EQ(1, ordinal
);
682 FindInPageWchar(web_contents
, L
"a", kFwd
, kIgnoreCase
, &ordinal
));
683 EXPECT_EQ(2, ordinal
);
685 FindInPageWchar(web_contents
, L
"a", kFwd
, kIgnoreCase
, &ordinal
));
686 EXPECT_EQ(3, ordinal
);
688 FindInPageWchar(web_contents
, L
"a", kFwd
, kIgnoreCase
, &ordinal
));
689 EXPECT_EQ(4, ordinal
);
690 // Go back one, which should go back one frame.
692 FindInPageWchar(web_contents
, L
"a", kBack
, kIgnoreCase
, &ordinal
));
693 EXPECT_EQ(3, ordinal
);
695 FindInPageWchar(web_contents
, L
"a", kFwd
, kIgnoreCase
, &ordinal
));
696 EXPECT_EQ(4, ordinal
);
698 FindInPageWchar(web_contents
, L
"a", kFwd
, kIgnoreCase
, &ordinal
));
699 EXPECT_EQ(5, ordinal
);
701 FindInPageWchar(web_contents
, L
"a", kFwd
, kIgnoreCase
, &ordinal
));
702 EXPECT_EQ(6, ordinal
);
704 FindInPageWchar(web_contents
, L
"a", kFwd
, kIgnoreCase
, &ordinal
));
705 EXPECT_EQ(7, ordinal
);
706 // Now we should wrap back to frame 1.
708 FindInPageWchar(web_contents
, L
"a", kFwd
, kIgnoreCase
, &ordinal
));
709 EXPECT_EQ(1, ordinal
);
710 // Now we should wrap back to frame last frame.
712 FindInPageWchar(web_contents
, L
"a", kBack
, kIgnoreCase
, &ordinal
));
713 EXPECT_EQ(7, ordinal
);
716 // We could get ordinals out of whack when restarting search in subframes.
717 // See http://crbug.com/5132.
718 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, FindInPage_Issue5132
) {
719 // First we navigate to our page.
720 GURL url
= GetURL(kFramePage
);
721 ui_test_utils::NavigateToURL(browser(), url
);
723 // Search for 'goa' three times (6 matches on page).
725 WebContents
* web_contents
=
726 browser()->tab_strip_model()->GetActiveWebContents();
727 EXPECT_EQ(6, FindInPageWchar(web_contents
, L
"goa",
728 kFwd
, kIgnoreCase
, &ordinal
));
729 EXPECT_EQ(1, ordinal
);
730 EXPECT_EQ(6, FindInPageWchar(web_contents
, L
"goa",
731 kFwd
, kIgnoreCase
, &ordinal
));
732 EXPECT_EQ(2, ordinal
);
733 EXPECT_EQ(6, FindInPageWchar(web_contents
, L
"goa",
734 kFwd
, kIgnoreCase
, &ordinal
));
735 EXPECT_EQ(3, ordinal
);
736 // Add space to search (should result in no matches).
737 EXPECT_EQ(0, FindInPageWchar(web_contents
, L
"goa ",
738 kFwd
, kIgnoreCase
, &ordinal
));
739 EXPECT_EQ(0, ordinal
);
740 // Remove the space, should be back to '3 out of 6')
741 EXPECT_EQ(6, FindInPageWchar(web_contents
, L
"goa",
742 kFwd
, kIgnoreCase
, &ordinal
));
743 EXPECT_EQ(3, ordinal
);
746 // This tests that the ordinal and match count is cleared after a navigation,
747 // as reported in issue http://crbug.com/126468.
748 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, NavigateClearsOrdinal
) {
749 // First we navigate to our test content.
750 GURL url
= GetURL(kSimple
);
751 ui_test_utils::NavigateToURL(browser(), url
);
753 // Open the Find box. In most tests we can just search without opening the
754 // box first, but in this case we are testing functionality triggered by
755 // NOTIFICATION_NAV_ENTRY_COMMITTED in the FindBarController and the observer
756 // for that event isn't setup unless the box is open.
759 // Search for a text that exists within a link on the page.
760 WebContents
* web_contents
=
761 browser()->tab_strip_model()->GetActiveWebContents();
762 ASSERT_TRUE(NULL
!= web_contents
);
764 EXPECT_EQ(8, FindInPageWchar(web_contents
,
766 kFwd
, kIgnoreCase
, &ordinal
));
767 EXPECT_EQ(1, ordinal
);
769 // Then navigate away (to any page).
770 url
= GetURL(kLinkPage
);
771 ui_test_utils::NavigateToURL(browser(), url
);
773 // Open the Find box again.
776 EXPECT_EQ(ASCIIToUTF16("e"), GetFindBarText());
777 EXPECT_EQ(ASCIIToUTF16(""), GetMatchCountText());
780 // Load a page with no selectable text and make sure we don't crash.
781 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, FindUnselectableText
) {
782 // First we navigate to our page.
783 GURL url
= GetURL(kUserSelectPage
);
784 ui_test_utils::NavigateToURL(browser(), url
);
787 WebContents
* web_contents
=
788 browser()->tab_strip_model()->GetActiveWebContents();
789 EXPECT_EQ(1, FindInPageWchar(web_contents
,
791 kFwd
, kIgnoreCase
, &ordinal
));
792 EXPECT_EQ(1, ordinal
);
795 // Try to reproduce the crash seen in issue 1341577.
796 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, FindCrash_Issue1341577
) {
797 // First we navigate to our page.
798 GURL url
= GetURL(kCrashPage
);
799 ui_test_utils::NavigateToURL(browser(), url
);
801 // This would crash the tab. These must be the first two find requests issued
802 // against the frame, otherwise an active frame pointer is set and it wont
803 // produce the crash.
804 // We used to check the return value and |ordinal|. With ICU 4.2, FiP does
805 // not find a stand-alone dependent vowel sign of Indic scripts. So, the
806 // exptected values are all 0. To make this test pass regardless of
807 // ICU version, we just call FiP and see if there's any crash.
808 // TODO(jungshik): According to a native Malayalam speaker, it's ok not
809 // to find U+0D4C. Still need to investigate further this issue.
811 WebContents
* web_contents
=
812 browser()->tab_strip_model()->GetActiveWebContents();
813 FindInPageWchar(web_contents
, L
"\u0D4C", kFwd
, kIgnoreCase
, &ordinal
);
814 FindInPageWchar(web_contents
, L
"\u0D4C", kFwd
, kIgnoreCase
, &ordinal
);
816 // This should work fine.
817 EXPECT_EQ(1, FindInPageWchar(web_contents
, L
"\u0D24\u0D46",
818 kFwd
, kIgnoreCase
, &ordinal
));
819 EXPECT_EQ(1, ordinal
);
820 EXPECT_EQ(0, FindInPageWchar(web_contents
, L
"nostring",
821 kFwd
, kIgnoreCase
, &ordinal
));
822 EXPECT_EQ(0, ordinal
);
825 // Try to reproduce the crash seen in http://crbug.com/14491, where an assert
826 // hits in the BitStack size comparison in WebKit.
827 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, FindCrash_Issue14491
) {
828 // First we navigate to our page.
829 GURL url
= GetURL(kBitstackCrash
);
830 ui_test_utils::NavigateToURL(browser(), url
);
832 // This used to crash the tab.
834 EXPECT_EQ(0, FindInPageWchar(browser()->tab_strip_model()->
835 GetActiveWebContents(),
836 L
"s", kFwd
, kIgnoreCase
, &ordinal
));
837 EXPECT_EQ(0, ordinal
);
840 // Test to make sure Find does the right thing when restarting from a timeout.
841 // We used to have a problem where we'd stop finding matches when all of the
842 // following conditions were true:
843 // 1) The page has a lot of text to search.
844 // 2) The page contains more than one match.
845 // 3) It takes longer than the time-slice given to each Find operation (100
846 // ms) to find one or more of those matches (so Find times out and has to try
847 // again from where it left off).
848 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, FindRestarts_Issue1155639
) {
849 // First we navigate to our page.
850 GURL url
= GetURL(kTooFewMatchesPage
);
851 ui_test_utils::NavigateToURL(browser(), url
);
853 // This string appears 5 times at the bottom of a long page. If Find restarts
854 // properly after a timeout, it will find 5 matches, not just 1.
856 EXPECT_EQ(5, FindInPageWchar(browser()->tab_strip_model()->
857 GetActiveWebContents(),
859 kFwd
, kIgnoreCase
, &ordinal
));
860 EXPECT_EQ(1, ordinal
);
863 // Make sure we don't get into an infinite loop when text box contains very
864 // large amount of text.
865 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, FindRestarts_Issue70505
) {
866 // First we navigate to our page.
867 GURL url
= GetURL(kLongTextareaPage
);
868 ui_test_utils::NavigateToURL(browser(), url
);
870 // If this test hangs on the FindInPage call, then it might be a regression
871 // such as the one found in issue http://crbug.com/70505.
873 FindInPageWchar(browser()->tab_strip_model()->GetActiveWebContents(),
874 L
"a", kFwd
, kIgnoreCase
, &ordinal
);
875 EXPECT_EQ(1, ordinal
);
876 // TODO(finnur): We cannot reliably get the matchcount for this Find call
877 // until we fix issue http://crbug.com/71176.
880 // This tests bug 11761: FindInPage terminates search prematurely.
881 // This test is not expected to pass until bug 11761 is fixed.
882 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
,
883 DISABLED_FindInPagePrematureEnd
) {
884 // First we navigate to our special focus tracking page.
885 GURL url
= GetURL(kPrematureEnd
);
886 ui_test_utils::NavigateToURL(browser(), url
);
888 WebContents
* web_contents
=
889 browser()->tab_strip_model()->GetActiveWebContents();
890 ASSERT_TRUE(NULL
!= web_contents
);
892 // Search for a text that exists within a link on the page.
894 EXPECT_EQ(2, FindInPageWchar(web_contents
, L
"html ",
895 kFwd
, kIgnoreCase
, &ordinal
));
896 EXPECT_EQ(1, ordinal
);
899 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, FindDisappearOnNavigate
) {
900 // First we navigate to our special focus tracking page.
901 GURL url
= GetURL(kSimple
);
902 GURL url2
= GetURL(kFramePage
);
903 ui_test_utils::NavigateToURL(browser(), url
);
905 chrome::ShowFindBar(browser());
908 bool fully_visible
= false;
910 // Make sure it is open.
911 EXPECT_TRUE(GetFindBarWindowInfo(&position
, &fully_visible
));
912 EXPECT_TRUE(fully_visible
);
914 // Reload the tab and make sure Find window doesn't go away.
915 content::WindowedNotificationObserver
observer(
916 content::NOTIFICATION_LOAD_STOP
,
917 content::Source
<NavigationController
>(
918 &browser()->tab_strip_model()->GetActiveWebContents()->
920 chrome::Reload(browser(), CURRENT_TAB
);
923 EXPECT_TRUE(GetFindBarWindowInfo(&position
, &fully_visible
));
924 EXPECT_TRUE(fully_visible
);
926 // Navigate and make sure the Find window goes away.
927 ui_test_utils::NavigateToURL(browser(), url2
);
929 EXPECT_TRUE(GetFindBarWindowInfo(&position
, &fully_visible
));
930 EXPECT_FALSE(fully_visible
);
933 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, FindStayVisibleOnAnchorLoad
) {
934 // First we navigate to our special focus tracking page.
935 GURL url
= GetURL(kAnchorPage
);
936 ui_test_utils::NavigateToURL(browser(), url
);
938 chrome::ShowFindBar(browser());
941 bool fully_visible
= false;
943 // Make sure it is open.
944 EXPECT_TRUE(GetFindBarWindowInfo(&position
, &fully_visible
));
945 EXPECT_TRUE(fully_visible
);
947 // Navigate to the same page (but add an anchor/ref/fragment/whatever the kids
948 // are calling it these days).
949 GURL url_with_anchor
= url
.Resolve(kAnchor
);
950 ui_test_utils::NavigateToURL(browser(), url_with_anchor
);
952 // Make sure it is still open.
953 EXPECT_TRUE(GetFindBarWindowInfo(&position
, &fully_visible
));
954 EXPECT_TRUE(fully_visible
);
957 // FindDisappearOnNewTabAndHistory is flaky, at least on Mac.
958 // See http://crbug.com/43072
959 #if defined(OS_MACOSX)
960 #define MAYBE_FindDisappearOnNewTabAndHistory DISABLED_FindDisappearOnNewTabAndHistory
962 #define MAYBE_FindDisappearOnNewTabAndHistory FindDisappearOnNewTabAndHistory
965 // Make sure Find box disappears when History/Downloads page is opened, and
966 // when a New Tab is opened.
967 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
,
968 MAYBE_FindDisappearOnNewTabAndHistory
) {
969 // First we navigate to our special focus tracking page.
970 GURL url
= GetURL(kSimple
);
971 ui_test_utils::NavigateToURL(browser(), url
);
973 chrome::ShowFindBar(browser());
976 bool fully_visible
= false;
978 // Make sure it is open.
979 EXPECT_TRUE(GetFindBarWindowInfo(&position
, &fully_visible
));
980 EXPECT_TRUE(fully_visible
);
982 // Open another tab (tab B).
983 chrome::NewTab(browser());
984 ui_test_utils::NavigateToURL(browser(), url
);
986 // Make sure Find box is closed.
987 EXPECT_TRUE(GetFindBarWindowInfo(&position
, &fully_visible
));
988 EXPECT_FALSE(fully_visible
);
991 chrome::CloseTab(browser());
993 // Make sure Find window appears again.
994 EXPECT_TRUE(GetFindBarWindowInfo(&position
, &fully_visible
));
995 EXPECT_TRUE(fully_visible
);
997 chrome::ShowHistory(browser());
999 // Make sure Find box is closed.
1000 EXPECT_TRUE(GetFindBarWindowInfo(&position
, &fully_visible
));
1001 EXPECT_FALSE(fully_visible
);
1004 // Make sure Find box moves out of the way if it is obscuring the active match.
1005 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, FindMovesWhenObscuring
) {
1006 GURL url
= GetURL(kMoveIfOver
);
1007 ui_test_utils::NavigateToURL(browser(), url
);
1009 chrome::ShowFindBar(browser());
1011 // This is needed on GTK because the reposition operation is asynchronous.
1012 base::MessageLoop::current()->RunUntilIdle();
1014 gfx::Point start_position
;
1015 gfx::Point position
;
1016 bool fully_visible
= false;
1019 // Make sure it is open.
1020 EXPECT_TRUE(GetFindBarWindowInfo(&start_position
, &fully_visible
));
1021 EXPECT_TRUE(fully_visible
);
1023 WebContents
* web_contents
=
1024 browser()->tab_strip_model()->GetActiveWebContents();
1026 int moved_x_coord
= FindInPageTillBoxMoves(web_contents
, start_position
.x(),
1027 L
"Chromium", kMoveIterations
);
1028 // The find box should have moved.
1029 EXPECT_TRUE(moved_x_coord
!= start_position
.x());
1031 // Search for something guaranteed not to be obscured by the Find box.
1032 EXPECT_EQ(1, FindInPageWchar(web_contents
, L
"Done",
1033 kFwd
, kIgnoreCase
, &ordinal
));
1034 // Check the position.
1035 EXPECT_TRUE(GetFindBarWindowInfo(&position
, &fully_visible
));
1036 EXPECT_TRUE(fully_visible
);
1038 // Make sure Find box has moved back to its original location.
1039 EXPECT_EQ(position
.x(), start_position
.x());
1041 // Move the find box again.
1042 moved_x_coord
= FindInPageTillBoxMoves(web_contents
, start_position
.x(),
1043 L
"Chromium", kMoveIterations
);
1044 EXPECT_TRUE(moved_x_coord
!= start_position
.x());
1046 // Search for an invalid string.
1047 EXPECT_EQ(0, FindInPageWchar(web_contents
, L
"WeirdSearchString",
1048 kFwd
, kIgnoreCase
, &ordinal
));
1050 // Check the position.
1051 EXPECT_TRUE(GetFindBarWindowInfo(&position
, &fully_visible
));
1052 EXPECT_TRUE(fully_visible
);
1054 // Make sure Find box has moved back to its original location.
1055 EXPECT_EQ(position
.x(), start_position
.x());
1058 // FindNextInNewTabUsesPrepopulate times-out on Mac, Windows and Aura.
1059 // See http://crbug.com/43070
1060 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
1061 #define MAYBE_FindNextInNewTabUsesPrepopulate \
1062 DISABLED_FindNextInNewTabUsesPrepopulate
1064 #define MAYBE_FindNextInNewTabUsesPrepopulate FindNextInNewTabUsesPrepopulate
1067 // Make sure F3 in a new tab works if Find has previous string to search for.
1068 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
,
1069 MAYBE_FindNextInNewTabUsesPrepopulate
) {
1070 // First we navigate to any page.
1071 GURL url
= GetURL(kSimple
);
1072 ui_test_utils::NavigateToURL(browser(), url
);
1074 // Search for 'no_match'. No matches should be found.
1076 WebContents
* web_contents
=
1077 browser()->tab_strip_model()->GetActiveWebContents();
1078 EXPECT_EQ(0, FindInPageWchar(web_contents
, L
"no_match",
1079 kFwd
, kIgnoreCase
, &ordinal
));
1080 EXPECT_EQ(0, ordinal
);
1082 // Open another tab (tab B).
1083 chrome::NewTab(browser());
1084 ui_test_utils::NavigateToURL(browser(), url
);
1086 // Simulate what happens when you press F3 for FindNext. We should get a
1087 // response here (a hang means search was aborted).
1088 EXPECT_EQ(0, ui_test_utils::FindInPage(web_contents
, base::string16(),
1089 kFwd
, kIgnoreCase
, &ordinal
, NULL
));
1090 EXPECT_EQ(0, ordinal
);
1092 // Open another tab (tab C).
1093 chrome::NewTab(browser());
1094 ui_test_utils::NavigateToURL(browser(), url
);
1096 // Simulate what happens when you press F3 for FindNext. We should get a
1097 // response here (a hang means search was aborted).
1098 EXPECT_EQ(0, ui_test_utils::FindInPage(web_contents
, base::string16(),
1099 kFwd
, kIgnoreCase
, &ordinal
, NULL
));
1100 EXPECT_EQ(0, ordinal
);
1103 // Make sure Find box does not become UI-inactive when no text is in the box as
1104 // we switch to a tab contents with an empty find string. See issue 13570.
1105 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, StayActive
) {
1106 // First we navigate to any page.
1107 GURL url
= GetURL(kSimple
);
1108 ui_test_utils::NavigateToURL(browser(), url
);
1110 chrome::ShowFindBar(browser());
1112 // Simulate a user clearing the search string. Ideally, we should be
1113 // simulating keypresses here for searching for something and pressing
1114 // backspace, but that's been proven flaky in the past, so we go straight to
1116 FindTabHelper
* find_tab_helper
= FindTabHelper::FromWebContents(
1117 browser()->tab_strip_model()->GetActiveWebContents());
1118 // Stop the (non-existing) find operation, and clear the selection (which
1119 // signals the UI is still active).
1120 find_tab_helper
->StopFinding(FindBarController::kClearSelectionOnPage
);
1121 // Make sure the Find UI flag hasn't been cleared, it must be so that the UI
1122 // still responds to browser window resizing.
1123 ASSERT_TRUE(find_tab_helper
->find_ui_active());
1126 // Make sure F3 works after you FindNext a couple of times and end the Find
1127 // session. See issue http://crbug.com/28306.
1128 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, RestartSearchFromF3
) {
1129 // First we navigate to a simple page.
1130 GURL url
= GetURL(kSimple
);
1131 ui_test_utils::NavigateToURL(browser(), url
);
1133 // Search for 'page'. Should have 1 match.
1135 WebContents
* web_contents
=
1136 browser()->tab_strip_model()->GetActiveWebContents();
1137 EXPECT_EQ(1, FindInPageWchar(web_contents
, L
"page",
1138 kFwd
, kIgnoreCase
, &ordinal
));
1139 EXPECT_EQ(1, ordinal
);
1141 // Simulate what happens when you press F3 for FindNext. Still should show
1142 // one match. This cleared the pre-populate string at one point (see bug).
1143 EXPECT_EQ(1, ui_test_utils::FindInPage(web_contents
, base::string16(),
1144 kFwd
, kIgnoreCase
, &ordinal
, NULL
));
1145 EXPECT_EQ(1, ordinal
);
1147 // End the Find session, thereby making the next F3 start afresh.
1148 browser()->GetFindBarController()->EndFindSession(
1149 FindBarController::kKeepSelectionOnPage
,
1150 FindBarController::kKeepResultsInFindBox
);
1152 // Simulate F3 while Find box is closed. Should have 1 match.
1153 EXPECT_EQ(1, FindInPageWchar(web_contents
, L
"", kFwd
, kIgnoreCase
, &ordinal
));
1154 EXPECT_EQ(1, ordinal
);
1157 // When re-opening the find bar with F3, the find bar should be re-populated
1158 // with the last search from the same tab rather than the last overall search.
1159 // The only exception is if there is a global pasteboard (for example on Mac).
1160 // http://crbug.com/30006
1161 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, PreferPreviousSearch
) {
1162 // First we navigate to any page.
1163 GURL url
= GetURL(kSimple
);
1164 ui_test_utils::NavigateToURL(browser(), url
);
1168 WebContents
* web_contents_1
=
1169 browser()->tab_strip_model()->GetActiveWebContents();
1170 EXPECT_EQ(1, FindInPageWchar(web_contents_1
, L
"text",
1171 kFwd
, kIgnoreCase
, &ordinal
));
1173 // Create a second tab.
1174 // For some reason we can't use AddSelectedTabWithURL here on ChromeOS. It
1175 // could be some delicate assumption about the tab starting off unselected or
1176 // something relating to user gesture.
1177 chrome::AddTabAt(browser(), GURL(), -1, true);
1178 ui_test_utils::NavigateToURL(browser(), url
);
1179 WebContents
* web_contents_2
=
1180 browser()->tab_strip_model()->GetActiveWebContents();
1181 EXPECT_NE(web_contents_1
, web_contents_2
);
1184 FindInPageWchar(web_contents_2
, L
"given", kFwd
, kIgnoreCase
, &ordinal
);
1186 // Switch back to first tab.
1187 browser()->tab_strip_model()->ActivateTabAt(0, false);
1188 browser()->GetFindBarController()->EndFindSession(
1189 FindBarController::kKeepSelectionOnPage
,
1190 FindBarController::kKeepResultsInFindBox
);
1192 ui_test_utils::FindInPage(web_contents_1
, base::string16(),
1193 kFwd
, kIgnoreCase
, &ordinal
, NULL
);
1194 FindBar
* find_bar
= browser()->GetFindBarController()->find_bar();
1195 if (find_bar
->HasGlobalFindPasteboard()) {
1196 EXPECT_EQ(FindTabHelper::FromWebContents(web_contents_1
)->find_text(),
1197 WideToUTF16(L
"given"));
1199 EXPECT_EQ(FindTabHelper::FromWebContents(web_contents_1
)->find_text(),
1200 WideToUTF16(L
"text"));
1204 // This tests that whenever you close and reopen the Find bar, it should show
1205 // the last search entered in that tab. http://crbug.com/40121.
1206 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, PrepopulateSameTab
) {
1207 // First we navigate to any page.
1208 GURL url
= GetURL(kSimple
);
1209 ui_test_utils::NavigateToURL(browser(), url
);
1211 // Search for the word "page".
1213 WebContents
* web_contents
=
1214 browser()->tab_strip_model()->GetActiveWebContents();
1215 EXPECT_EQ(1, FindInPageWchar(web_contents
, L
"page",
1216 kFwd
, kIgnoreCase
, &ordinal
));
1218 // Open the Find box.
1219 EnsureFindBoxOpen();
1221 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1222 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText());
1224 // Close the Find box.
1225 browser()->GetFindBarController()->EndFindSession(
1226 FindBarController::kKeepSelectionOnPage
,
1227 FindBarController::kKeepResultsInFindBox
);
1229 // Open the Find box again.
1230 EnsureFindBoxOpen();
1232 // After the Find box has been reopened, it should have been prepopulated with
1233 // the word "page" again.
1234 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1235 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText());
1238 // This tests that whenever you open Find in a new tab it should prepopulate
1239 // with a previous search term (in any tab), if a search has not been issued in
1241 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, PrepopulateInNewTab
) {
1242 // First we navigate to any page.
1243 GURL url
= GetURL(kSimple
);
1244 ui_test_utils::NavigateToURL(browser(), url
);
1246 // Search for the word "page".
1248 WebContents
* web_contents_1
=
1249 browser()->tab_strip_model()->GetActiveWebContents();
1250 EXPECT_EQ(1, FindInPageWchar(web_contents_1
, L
"page",
1251 kFwd
, kIgnoreCase
, &ordinal
));
1252 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText());
1254 // Now create a second tab and load the same page.
1255 chrome::AddSelectedTabWithURL(browser(), url
, content::PAGE_TRANSITION_TYPED
);
1256 WebContents
* web_contents_2
=
1257 browser()->tab_strip_model()->GetActiveWebContents();
1258 EXPECT_NE(web_contents_1
, web_contents_2
);
1260 // Open the Find box.
1261 EnsureFindBoxOpen();
1263 // The new tab should have "page" prepopulated, since that was the last search
1264 // in the first tab.
1265 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1266 // But it should not seem like a search has been issued.
1267 EXPECT_EQ(base::string16(), GetMatchCountText());
1270 // This makes sure that we can search for A in tabA, then for B in tabB and
1271 // when we come back to tabA we should still see A (because that was the last
1272 // search in that tab).
1273 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, PrepopulatePreserveLast
) {
1274 FindBar
* find_bar
= browser()->GetFindBarController()->find_bar();
1275 if (find_bar
->HasGlobalFindPasteboard())
1278 // First we navigate to any page.
1279 GURL url
= GetURL(kSimple
);
1280 ui_test_utils::NavigateToURL(browser(), url
);
1282 // Search for the word "page".
1284 WebContents
* web_contents_1
=
1285 browser()->tab_strip_model()->GetActiveWebContents();
1286 EXPECT_EQ(1, FindInPageWchar(web_contents_1
, L
"page",
1287 kFwd
, kIgnoreCase
, &ordinal
));
1289 // Open the Find box.
1290 EnsureFindBoxOpen();
1292 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1294 // Close the Find box.
1295 browser()->GetFindBarController()->EndFindSession(
1296 FindBarController::kKeepSelectionOnPage
,
1297 FindBarController::kKeepResultsInFindBox
);
1299 // Now create a second tab and load the same page.
1300 chrome::AddTabAt(browser(), GURL(), -1, true);
1301 ui_test_utils::NavigateToURL(browser(), url
);
1302 WebContents
* web_contents_2
=
1303 browser()->tab_strip_model()->GetActiveWebContents();
1304 EXPECT_NE(web_contents_1
, web_contents_2
);
1306 // Search for the word "text".
1307 FindInPageWchar(web_contents_2
, L
"text", kFwd
, kIgnoreCase
, &ordinal
);
1309 // Go back to the first tab and make sure we have NOT switched the prepopulate
1311 browser()->tab_strip_model()->ActivateTabAt(0, false);
1313 // Open the Find box.
1314 EnsureFindBoxOpen();
1316 // After the Find box has been reopened, it should have been prepopulated with
1317 // the word "page" again, since that was the last search in that tab.
1318 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1320 // Close the Find box.
1321 browser()->GetFindBarController()->EndFindSession(
1322 FindBarController::kKeepSelectionOnPage
,
1323 FindBarController::kKeepResultsInFindBox
);
1325 // Re-open the Find box.
1326 // This is a special case: previous search in WebContents used to get cleared
1327 // if you opened and closed the FindBox, which would cause the global
1328 // prepopulate value to show instead of last search in this tab.
1329 EnsureFindBoxOpen();
1331 // After the Find box has been reopened, it should have been prepopulated with
1332 // the word "page" again, since that was the last search in that tab.
1333 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1336 // TODO(rohitrao): Searching in incognito tabs does not work in browser tests in
1337 // Linux views. Investigate and fix. http://crbug.com/40948
1338 #if defined(OS_LINUX) && defined(TOOLKIT_VIEWS)
1339 #define MAYBE_NoIncognitoPrepopulate DISABLED_NoIncognitoPrepopulate
1341 #define MAYBE_NoIncognitoPrepopulate NoIncognitoPrepopulate
1344 // This tests that search terms entered into an incognito find bar are not used
1345 // as prepopulate terms for non-incognito windows.
1346 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, MAYBE_NoIncognitoPrepopulate
) {
1347 FindBar
* find_bar
= browser()->GetFindBarController()->find_bar();
1348 if (find_bar
->HasGlobalFindPasteboard())
1351 // First we navigate to the "simple" test page.
1352 GURL url
= GetURL(kSimple
);
1353 ui_test_utils::NavigateToURL(browser(), url
);
1355 // Search for the word "page" in the normal browser tab.
1357 WebContents
* web_contents_1
=
1358 browser()->tab_strip_model()->GetActiveWebContents();
1359 EXPECT_EQ(1, FindInPageWchar(web_contents_1
, L
"page",
1360 kFwd
, kIgnoreCase
, &ordinal
));
1362 // Open the Find box.
1363 EnsureFindBoxOpenForBrowser(browser());
1364 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser()));
1366 // Close the Find box.
1367 browser()->GetFindBarController()->EndFindSession(
1368 FindBarController::kKeepSelectionOnPage
,
1369 FindBarController::kKeepResultsInFindBox
);
1371 // Open a new incognito window and navigate to the same page.
1372 Profile
* incognito_profile
= browser()->profile()->GetOffTheRecordProfile();
1373 Browser
* incognito_browser
=
1374 new Browser(Browser::CreateParams(incognito_profile
,
1375 browser()->host_desktop_type()));
1376 content::WindowedNotificationObserver
observer(
1377 content::NOTIFICATION_LOAD_STOP
,
1378 content::NotificationService::AllSources());
1379 chrome::AddSelectedTabWithURL(incognito_browser
, url
,
1380 content::PAGE_TRANSITION_AUTO_TOPLEVEL
);
1382 incognito_browser
->window()->Show();
1384 // Open the find box and make sure that it is prepopulated with "page".
1385 EnsureFindBoxOpenForBrowser(incognito_browser
);
1386 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(incognito_browser
));
1388 // Search for the word "text" in the incognito tab.
1389 WebContents
* incognito_tab
=
1390 incognito_browser
->tab_strip_model()->GetActiveWebContents();
1391 EXPECT_EQ(1, FindInPageWchar(incognito_tab
, L
"text",
1392 kFwd
, kIgnoreCase
, &ordinal
));
1393 EXPECT_EQ(ASCIIToUTF16("text"), GetFindBarTextForBrowser(incognito_browser
));
1395 // Close the Find box.
1396 incognito_browser
->GetFindBarController()->EndFindSession(
1397 FindBarController::kKeepSelectionOnPage
,
1398 FindBarController::kKeepResultsInFindBox
);
1400 // Now open a new tab in the original (non-incognito) browser.
1401 chrome::AddSelectedTabWithURL(browser(), url
, content::PAGE_TRANSITION_TYPED
);
1402 WebContents
* web_contents_2
=
1403 browser()->tab_strip_model()->GetActiveWebContents();
1404 EXPECT_NE(web_contents_1
, web_contents_2
);
1406 // Open the Find box and make sure it is prepopulated with the search term
1407 // from the original browser, not the search term from the incognito window.
1408 EnsureFindBoxOpenForBrowser(browser());
1409 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser()));
1412 // This makes sure that dismissing the find bar with kActivateSelection works.
1413 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, ActivateLinkNavigatesPage
) {
1414 // First we navigate to our test content.
1415 GURL url
= GetURL(kLinkPage
);
1416 ui_test_utils::NavigateToURL(browser(), url
);
1418 WebContents
* web_contents
=
1419 browser()->tab_strip_model()->GetActiveWebContents();
1420 FindTabHelper
* find_tab_helper
=
1421 FindTabHelper::FromWebContents(web_contents
);
1424 FindInPageWchar(web_contents
, L
"link", kFwd
, kIgnoreCase
, &ordinal
);
1425 EXPECT_EQ(ordinal
, 1);
1427 // End the find session, click on the link.
1428 content::WindowedNotificationObserver
observer(
1429 content::NOTIFICATION_LOAD_STOP
,
1430 content::Source
<NavigationController
>(&web_contents
->GetController()));
1431 find_tab_helper
->StopFinding(FindBarController::kActivateSelectionOnPage
);
1435 // Tests that FindBar fits within a narrow browser window.
1436 // Flaky on Linux/GTK: http://crbug.com/136443.
1437 #if defined(TOOLKIT_GTK)
1438 #define MAYBE_FitWindow DISABLED_FitWindow
1440 #define MAYBE_FitWindow FitWindow
1442 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, MAYBE_FitWindow
) {
1443 Browser::CreateParams
params(Browser::TYPE_POPUP
, browser()->profile(),
1444 browser()->host_desktop_type());
1445 params
.initial_bounds
= gfx::Rect(0, 0, 250, 500);
1446 Browser
* popup
= new Browser(params
);
1447 content::WindowedNotificationObserver
observer(
1448 content::NOTIFICATION_LOAD_STOP
,
1449 content::NotificationService::AllSources());
1450 chrome::AddSelectedTabWithURL(popup
, GURL(content::kAboutBlankURL
),
1451 content::PAGE_TRANSITION_LINK
);
1452 // Wait for the page to finish loading.
1454 popup
->window()->Show();
1456 // On GTK, bounds change is asynchronous.
1457 base::MessageLoop::current()->RunUntilIdle();
1459 EnsureFindBoxOpenForBrowser(popup
);
1461 // GTK adjusts FindBar size asynchronously.
1462 base::MessageLoop::current()->RunUntilIdle();
1464 ASSERT_LE(GetFindBarWidthForBrowser(popup
),
1465 popup
->window()->GetBounds().width());
1468 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
,
1469 FindMovesOnTabClose_Issue1343052
) {
1470 EnsureFindBoxOpen();
1471 content::RunAllPendingInMessageLoop(); // Needed on Linux.
1473 gfx::Point position
;
1474 EXPECT_TRUE(GetFindBarWindowInfo(&position
, NULL
));
1476 // Open another tab.
1477 GURL url
= GetURL(kSimple
);
1478 ui_test_utils::NavigateToURLWithDisposition(
1479 browser(), url
, NEW_FOREGROUND_TAB
,
1480 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION
);
1483 chrome::CloseTab(browser());
1485 // See if the Find window has moved.
1486 gfx::Point position2
;
1487 EXPECT_TRUE(GetFindBarWindowInfo(&position2
, NULL
));
1488 EXPECT_EQ(position
, position2
);
1490 // Toggle the bookmark bar state. Note that this starts an animation, and
1491 // there isn't a good way other than looping and polling to see when it's
1492 // done. So instead we change the state and open a new tab, since the new tab
1493 // animation doesn't happen on tab change.
1494 chrome::ToggleBookmarkBar(browser());
1496 ui_test_utils::NavigateToURLWithDisposition(
1497 browser(), url
, NEW_FOREGROUND_TAB
,
1498 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION
);
1500 EnsureFindBoxOpen();
1501 content::RunAllPendingInMessageLoop(); // Needed on Linux.
1502 EXPECT_TRUE(GetFindBarWindowInfo(&position
, NULL
));
1504 ui_test_utils::NavigateToURLWithDisposition(
1505 browser(), url
, NEW_FOREGROUND_TAB
,
1506 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION
);
1507 chrome::CloseTab(browser());
1508 EXPECT_TRUE(GetFindBarWindowInfo(&position2
, NULL
));
1509 EXPECT_EQ(position
, position2
);
1512 // Verify that if there's a global pasteboard (for example on Mac) then doing
1513 // a search on one tab will clear the matches label on the other tabs.
1514 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
,
1515 GlobalPasteBoardClearMatches
) {
1516 FindBar
* find_bar
= browser()->GetFindBarController()->find_bar();
1517 if (!find_bar
->HasGlobalFindPasteboard())
1520 // First we navigate to any page.
1521 GURL url
= GetURL(kSimple
);
1522 ui_test_utils::NavigateToURL(browser(), url
);
1524 // Change the match count on the first tab to "1 of 1".
1526 WebContents
* web_contents_1
=
1527 browser()->tab_strip_model()->GetActiveWebContents();
1528 EXPECT_EQ(1, FindInPageWchar(web_contents_1
, L
"page",
1529 kFwd
, kIgnoreCase
, &ordinal
));
1530 EnsureFindBoxOpen();
1531 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText());
1533 // Next, do a search in a second tab.
1534 chrome::AddTabAt(browser(), GURL(), -1, true);
1535 ui_test_utils::NavigateToURL(browser(), url
);
1536 WebContents
* web_contents_2
=
1537 browser()->tab_strip_model()->GetActiveWebContents();
1538 FindInPageWchar(web_contents_2
, L
"text", kFwd
, kIgnoreCase
, &ordinal
);
1539 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText());
1541 // Go back to the first tab and verify that the match text is cleared.
1543 browser()->tab_strip_model()->ActivateTabAt(0, false);
1544 EXPECT_EQ(ASCIIToUTF16(""), GetMatchCountText());
1547 // Verify that Incognito window doesn't propagate find string to other widows.
1548 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, GlobalPasteboardIncognito
) {
1549 Browser
* browser_incognito
= CreateIncognitoBrowser();
1550 WebContents
* web_contents_1
=
1551 browser()->tab_strip_model()->GetActiveWebContents();
1552 FindInPageWchar(web_contents_1
, L
"page", kFwd
, kIgnoreCase
, NULL
);
1553 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1554 WebContents
* web_contents_2
=
1555 browser_incognito
->tab_strip_model()->GetActiveWebContents();
1556 FindInPageWchar(web_contents_2
, L
"Incognito", kFwd
, kIgnoreCase
, NULL
);
1557 EXPECT_EQ(ASCIIToUTF16("Incognito"),
1558 GetFindBarTextForBrowser(browser_incognito
));
1559 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1562 // Find text in regular window, find different text in incognito, send
1563 // IDC_FIND_NEXT to incognito. It should search for the second phrase.
1564 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, IncognitoFindNextSecret
) {
1565 WebContents
* web_contents
=
1566 browser()->tab_strip_model()->GetActiveWebContents();
1567 // On Mac this updates the find pboard.
1568 FindInPageWchar(web_contents
, L
"bar", kFwd
, kIgnoreCase
, NULL
);
1570 Browser
* browser_incognito
= CreateIncognitoBrowser();
1571 ui_test_utils::NavigateToURL(browser_incognito
,
1572 GURL("data:text/plain,barfoofoo"));
1573 WebContents
* web_contents_incognito
=
1574 browser_incognito
->tab_strip_model()->GetActiveWebContents();
1575 FindInPageWchar(web_contents_incognito
, L
"foo", true, kIgnoreCase
, NULL
);
1576 EXPECT_EQ(ASCIIToUTF16("foo"),
1577 GetFindBarTextForBrowser(browser_incognito
));
1578 EXPECT_EQ(ASCIIToUTF16("1 of 2"),
1579 GetFindBarMatchCountTextForBrowser(browser_incognito
));
1581 // Close the find bar.
1582 FindTabHelper
* find_tab_helper
=
1583 FindTabHelper::FromWebContents(web_contents_incognito
);
1584 find_tab_helper
->StopFinding(FindBarController::kActivateSelectionOnPage
);
1586 // Cmd + G triggers IDC_FIND_NEXT command. Thus we test FindInPage()
1587 // method from browser_commands.cc. FindInPageWchar() bypasses it.
1588 EXPECT_TRUE(chrome::ExecuteCommand(browser_incognito
, IDC_FIND_NEXT
));
1589 ui_test_utils::FindInPageNotificationObserver
observer(
1590 web_contents_incognito
);
1592 EXPECT_EQ(ASCIIToUTF16("foo"),
1593 GetFindBarTextForBrowser(browser_incognito
));
1594 EXPECT_EQ(ASCIIToUTF16("2 of 2"),
1595 GetFindBarMatchCountTextForBrowser(browser_incognito
));
1598 // Find text in regular window, send IDC_FIND_NEXT to incognito. It should
1599 // search for the first phrase.
1600 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, IncognitoFindNextShared
) {
1601 WebContents
* web_contents
=
1602 browser()->tab_strip_model()->GetActiveWebContents();
1603 // On Mac this updates the find pboard.
1604 FindInPageWchar(web_contents
, L
"bar", kFwd
, kIgnoreCase
, NULL
);
1606 Browser
* browser_incognito
= CreateIncognitoBrowser();
1607 ui_test_utils::NavigateToURL(browser_incognito
,
1608 GURL("data:text/plain,bar"));
1610 EXPECT_TRUE(chrome::ExecuteCommand(browser_incognito
, IDC_FIND_NEXT
));
1611 WebContents
* web_contents_incognito
=
1612 browser_incognito
->tab_strip_model()->GetActiveWebContents();
1613 ui_test_utils::FindInPageNotificationObserver
observer(
1614 web_contents_incognito
);
1616 EXPECT_EQ(ASCIIToUTF16("bar"),
1617 GetFindBarTextForBrowser(browser_incognito
));
1620 #if defined(OS_WIN) && defined(USE_AURA)
1622 BOOL CALLBACK
EnumerateChildren(HWND hwnd
, LPARAM l_param
) {
1623 HWND
* child
= reinterpret_cast<HWND
*>(l_param
);
1625 // The first child window is the plugin, then its children. So stop
1626 // enumerating after the first callback.
1630 // Ensure that the find bar is always over a windowed NPAPI plugin.
1631 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest
, WindowedNPAPIPluginHidden
) {
1632 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPluginsAlwaysAuthorize
,
1635 // First load the page and wait for the NPAPI plugin's window to display.
1636 base::string16
expected_title(ASCIIToUTF16("ready"));
1637 content::WebContents
* tab
=
1638 browser()->tab_strip_model()->GetActiveWebContents();
1639 content::TitleWatcher
title_watcher(tab
, expected_title
);
1641 GURL url
= ui_test_utils::GetTestUrl(
1642 base::FilePath().AppendASCII("printing"),
1643 base::FilePath().AppendASCII("npapi_plugin.html"));
1644 ui_test_utils::NavigateToURL(browser(), url
);
1646 EXPECT_EQ(expected_title
, title_watcher
.WaitAndGetTitle());
1648 // Now get the region of the plugin before the find bar is shown.
1649 HWND hwnd
= tab
->GetView()->GetNativeView()->GetDispatcher()->host()->
1650 GetAcceleratedWidget();
1652 EnumChildWindows(hwnd
, EnumerateChildren
,reinterpret_cast<LPARAM
>(&child
));
1654 RECT region_before
, region_after
;
1655 int result
= GetWindowRgnBox(child
, ®ion_before
);
1656 ASSERT_EQ(result
, SIMPLEREGION
);
1658 // Create a new tab and open the find bar there.
1659 chrome::NewTab(browser());
1660 browser()->tab_strip_model()->ActivateTabAt(1, true);
1661 ui_test_utils::NavigateToURL(browser(), GURL(content::kAboutBlankURL
));
1663 EnsureFindBoxOpen();
1665 // Now switch back to the original tab with the plugin and show the find bar.
1666 browser()->tab_strip_model()->ActivateTabAt(0, true);
1667 EnsureFindBoxOpen();
1669 result
= GetWindowRgnBox(child
, ®ion_after
);
1670 if (result
== NULLREGION
) {
1671 // Depending on the browser window size, the plugin could be full covered.
1675 if (result
== COMPLEXREGION
) {
1676 // Complex region, by definition not equal to the initial region.
1680 ASSERT_EQ(result
, SIMPLEREGION
);
1682 region_before
.left
== region_after
.left
&&
1683 region_before
.top
== region_after
.top
&&
1684 region_before
.right
== region_after
.right
&&
1685 region_before
.bottom
== region_after
.bottom
;
1686 ASSERT_FALSE(rects_equal
);