[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / find_bar / find_bar_host_browsertest.cc
blob1a2ab5de17bb002835d9de8697e6142920ca33a2
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/test/browser_test_utils.h"
40 #include "net/base/filename_util.h"
41 #include "ui/base/accelerators/accelerator.h"
42 #include "ui/events/keycodes/keyboard_codes.h"
44 #if defined(OS_WIN)
45 #include "ui/aura/window.h"
46 #include "ui/aura/window_tree_host.h"
47 #endif
49 using base::ASCIIToUTF16;
50 using base::WideToUTF16;
51 using content::NavigationController;
52 using content::WebContents;
54 namespace {
56 const char kAnchorPage[] = "anchor.html";
57 const char kAnchor[] = "#chapter2";
58 const char kFramePage[] = "frames.html";
59 const char kFrameData[] = "framedata_general.html";
60 const char kUserSelectPage[] = "user-select.html";
61 const char kCrashPage[] = "crash_1341577.html";
62 const char kTooFewMatchesPage[] = "bug_1155639.html";
63 const char kLongTextareaPage[] = "large_textarea.html";
64 const char kPrematureEnd[] = "premature_end.html";
65 const char kMoveIfOver[] = "move_if_obscuring.html";
66 const char kBitstackCrash[] = "crash_14491.html";
67 const char kSelectChangesOrdinal[] = "select_changes_ordinal.html";
68 const char kStartAfterSelection[] = "start_after_selection.html";
69 const char kSimple[] = "simple.html";
70 const char kLinkPage[] = "link.html";
72 const bool kBack = false;
73 const bool kFwd = true;
75 const bool kIgnoreCase = false;
76 const bool kCaseSensitive = true;
78 const int kMoveIterations = 30;
80 } // namespace
82 class FindInPageControllerTest : public InProcessBrowserTest {
83 public:
84 FindInPageControllerTest() {
85 chrome::DisableFindBarAnimationsDuringTesting(true);
88 protected:
89 bool GetFindBarWindowInfoForBrowser(
90 Browser* browser, gfx::Point* position, bool* fully_visible) {
91 FindBarTesting* find_bar =
92 browser->GetFindBarController()->find_bar()->GetFindBarTesting();
93 return find_bar->GetFindBarWindowInfo(position, fully_visible);
96 bool GetFindBarWindowInfo(gfx::Point* position, bool* fully_visible) {
97 return GetFindBarWindowInfoForBrowser(browser(), position, fully_visible);
100 base::string16 GetFindBarTextForBrowser(Browser* browser) {
101 FindBar* find_bar = browser->GetFindBarController()->find_bar();
102 return find_bar->GetFindText();
105 base::string16 GetFindBarText() {
106 return GetFindBarTextForBrowser(browser());
109 base::string16 GetFindBarMatchCountTextForBrowser(Browser* browser) {
110 FindBarTesting* find_bar =
111 browser->GetFindBarController()->find_bar()->GetFindBarTesting();
112 return find_bar->GetMatchCountText();
115 base::string16 GetMatchCountText() {
116 return GetFindBarMatchCountTextForBrowser(browser());
119 int GetFindBarWidthForBrowser(Browser* browser) {
120 FindBarTesting* find_bar =
121 browser->GetFindBarController()->find_bar()->GetFindBarTesting();
122 return find_bar->GetWidth();
125 void EnsureFindBoxOpenForBrowser(Browser* browser) {
126 chrome::ShowFindBar(browser);
127 gfx::Point position;
128 bool fully_visible = false;
129 EXPECT_TRUE(GetFindBarWindowInfoForBrowser(
130 browser, &position, &fully_visible));
131 EXPECT_TRUE(fully_visible);
134 void EnsureFindBoxOpen() {
135 EnsureFindBoxOpenForBrowser(browser());
138 // Platform independent FindInPage that takes |const wchar_t*|
139 // as an input.
140 int FindInPageWchar(WebContents* web_contents,
141 const wchar_t* search_str,
142 bool forward,
143 bool case_sensitive,
144 int* ordinal) {
145 base::string16 search_str16(WideToUTF16(std::wstring(search_str)));
146 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
147 browser->GetFindBarController()->find_bar()->SetFindTextAndSelectedRange(
148 search_str16, gfx::Range());
149 return ui_test_utils::FindInPage(
150 web_contents, search_str16, forward, case_sensitive, ordinal, NULL);
153 // Calls FindInPageWchar till the find box's x position != |start_x_position|.
154 // Return |start_x_position| if the find box has not moved after iterating
155 // through all matches of |search_str|.
156 int FindInPageTillBoxMoves(WebContents* web_contents,
157 int start_x_position,
158 const wchar_t* search_str,
159 int expected_matches) {
160 // Search for |search_str| which the Find box is obscuring.
161 for (int index = 0; index < expected_matches; ++index) {
162 int ordinal = 0;
163 EXPECT_EQ(expected_matches, FindInPageWchar(web_contents, search_str,
164 kFwd, kIgnoreCase, &ordinal));
166 // Check the position.
167 bool fully_visible;
168 gfx::Point position;
169 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
170 EXPECT_TRUE(fully_visible);
172 // If the Find box has moved then we are done.
173 if (position.x() != start_x_position)
174 return position.x();
176 return start_x_position;
179 GURL GetURL(const std::string& filename) {
180 return ui_test_utils::GetTestUrl(
181 base::FilePath().AppendASCII("find_in_page"),
182 base::FilePath().AppendASCII(filename));
185 void FlushHistoryService() {
186 HistoryServiceFactory::GetForProfile(
187 browser()->profile(), Profile::IMPLICIT_ACCESS)->FlushForTest(
188 base::Bind(&base::MessageLoop::Quit,
189 base::Unretained(base::MessageLoop::current()->current())));
190 content::RunMessageLoop();
194 // This test loads a page with frames and starts FindInPage requests.
195 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFrames) {
196 // First we navigate to our frames page.
197 GURL url = GetURL(kFramePage);
198 ui_test_utils::NavigateToURL(browser(), url);
200 // Try incremental search (mimicking user typing in).
201 int ordinal = 0;
202 WebContents* web_contents =
203 browser()->tab_strip_model()->GetActiveWebContents();
204 EXPECT_EQ(18, FindInPageWchar(web_contents, L"g",
205 kFwd, kIgnoreCase, &ordinal));
206 EXPECT_EQ(1, ordinal);
207 EXPECT_EQ(11, FindInPageWchar(web_contents, L"go",
208 kFwd, kIgnoreCase, &ordinal));
209 EXPECT_EQ(1, ordinal);
210 EXPECT_EQ(4, FindInPageWchar(web_contents, L"goo",
211 kFwd, kIgnoreCase, &ordinal));
212 EXPECT_EQ(1, ordinal);
213 EXPECT_EQ(3, FindInPageWchar(web_contents, L"goog",
214 kFwd, kIgnoreCase, &ordinal));
215 EXPECT_EQ(1, ordinal);
216 EXPECT_EQ(2, FindInPageWchar(web_contents, L"googl",
217 kFwd, kIgnoreCase, &ordinal));
218 EXPECT_EQ(1, ordinal);
219 EXPECT_EQ(1, FindInPageWchar(web_contents, L"google",
220 kFwd, kIgnoreCase, &ordinal));
221 EXPECT_EQ(1, ordinal);
222 EXPECT_EQ(0, FindInPageWchar(web_contents, L"google!",
223 kFwd, kIgnoreCase, &ordinal));
224 EXPECT_EQ(0, ordinal);
226 // Negative test (no matches should be found).
227 EXPECT_EQ(0, FindInPageWchar(web_contents, L"Non-existing string",
228 kFwd, kIgnoreCase, &ordinal));
229 EXPECT_EQ(0, ordinal);
231 // 'horse' only exists in the three right frames.
232 EXPECT_EQ(3, FindInPageWchar(web_contents, L"horse",
233 kFwd, kIgnoreCase, &ordinal));
234 EXPECT_EQ(1, ordinal);
236 // 'cat' only exists in the first frame.
237 EXPECT_EQ(1, FindInPageWchar(web_contents, L"cat",
238 kFwd, kIgnoreCase, &ordinal));
239 EXPECT_EQ(1, ordinal);
241 // Try searching again, should still come up with 1 match.
242 EXPECT_EQ(1, FindInPageWchar(web_contents, L"cat",
243 kFwd, kIgnoreCase, &ordinal));
244 EXPECT_EQ(1, ordinal);
246 // Try searching backwards, ignoring case, should still come up with 1 match.
247 EXPECT_EQ(1, FindInPageWchar(web_contents, L"CAT",
248 kBack, kIgnoreCase, &ordinal));
249 EXPECT_EQ(1, ordinal);
251 // Try case sensitive, should NOT find it.
252 EXPECT_EQ(0, FindInPageWchar(web_contents, L"CAT",
253 kFwd, kCaseSensitive, &ordinal));
254 EXPECT_EQ(0, ordinal);
256 // Try again case sensitive, but this time with right case.
257 EXPECT_EQ(1, FindInPageWchar(web_contents, L"dog",
258 kFwd, kCaseSensitive, &ordinal));
259 EXPECT_EQ(1, ordinal);
261 // Try non-Latin characters ('Hreggvidur' with 'eth' for 'd' in left frame).
262 EXPECT_EQ(1, FindInPageWchar(web_contents, L"Hreggvi\u00F0ur",
263 kFwd, kIgnoreCase, &ordinal));
264 EXPECT_EQ(1, ordinal);
265 EXPECT_EQ(1, FindInPageWchar(web_contents, L"Hreggvi\u00F0ur",
266 kFwd, kCaseSensitive, &ordinal));
267 EXPECT_EQ(1, ordinal);
268 EXPECT_EQ(0, FindInPageWchar(web_contents, L"hreggvi\u00F0ur",
269 kFwd, kCaseSensitive, &ordinal));
270 EXPECT_EQ(0, ordinal);
273 // Verify search for text within various forms and text areas.
274 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFormsTextAreas) {
275 std::vector<GURL> urls;
276 urls.push_back(GetURL("textintextarea.html"));
277 urls.push_back(GetURL("smalltextarea.html"));
278 urls.push_back(GetURL("populatedform.html"));
279 WebContents* web_contents =
280 browser()->tab_strip_model()->GetActiveWebContents();
282 for (size_t i = 0; i < urls.size(); ++i) {
283 ui_test_utils::NavigateToURL(browser(), urls[i]);
284 EXPECT_EQ(1, FindInPageWchar(web_contents, L"cat",
285 kFwd, kIgnoreCase, NULL));
286 EXPECT_EQ(0, FindInPageWchar(web_contents, L"bat",
287 kFwd, kIgnoreCase, NULL));
291 // Verify search for text within special URLs such as chrome:history,
292 // chrome://downloads, data directory
293 #if defined(OS_WIN)
294 // Disabled due to crbug.com/175711
295 #define MAYBE_SearchWithinSpecialURL \
296 DISABLED_SearchWithinSpecialURL
297 #else
298 #define MAYBE_SearchWithinSpecialURL \
299 SearchWithinSpecialURL
300 #endif
301 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, MAYBE_SearchWithinSpecialURL) {
302 WebContents* web_contents =
303 browser()->tab_strip_model()->GetActiveWebContents();
305 base::FilePath data_dir =
306 ui_test_utils::GetTestFilePath(base::FilePath(), base::FilePath());
307 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(data_dir));
308 EXPECT_EQ(1, FindInPageWchar(web_contents, L"downloads",
309 kFwd, kIgnoreCase, NULL));
311 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIHistoryURL));
313 // The history page does an async request to the history service and then
314 // updates the renderer. So we make a query as well, and by the time it comes
315 // back we know the data is on its way to the renderer.
316 FlushHistoryService();
318 base::string16 query(data_dir.LossyDisplayName());
319 EXPECT_EQ(1,
320 ui_test_utils::FindInPage(web_contents, query,
321 kFwd, kIgnoreCase, NULL, NULL));
323 GURL download_url = ui_test_utils::GetTestUrl(
324 base::FilePath().AppendASCII("downloads"),
325 base::FilePath().AppendASCII("a_zip_file.zip"));
326 ui_test_utils::DownloadURL(browser(), download_url);
328 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL));
329 FlushHistoryService();
330 EXPECT_EQ(1,
331 FindInPageWchar(web_contents,
332 base::ASCIIToWide(download_url.spec()).c_str(),
333 kFwd, kIgnoreCase, NULL));
336 // Verify search selection coordinates. The data file used is set-up such that
337 // the text occurs on the same line, and we verify their positions by verifying
338 // their relative positions.
339 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageSpecialURLs) {
340 std::wstring search_string(L"\u5728\u897f\u660c\u536b\u661f\u53d1");
341 gfx::Rect first, second, first_reverse;
342 WebContents* web_contents =
343 browser()->tab_strip_model()->GetActiveWebContents();
344 ui_test_utils::NavigateToURL(browser(), GetURL("specialchar.html"));
345 ui_test_utils::FindInPage(web_contents, WideToUTF16(search_string),
346 kFwd, kIgnoreCase, NULL, &first);
347 ui_test_utils::FindInPage(web_contents, WideToUTF16(search_string),
348 kFwd, kIgnoreCase, NULL, &second);
350 // We have search occurrence in the same row, so top-bottom coordinates should
351 // be the same even for second search.
352 ASSERT_EQ(first.y(), second.y());
353 ASSERT_EQ(first.bottom(), second.bottom());
354 ASSERT_LT(first.x(), second.x());
355 ASSERT_LT(first.right(), second.right());
357 ui_test_utils::FindInPage(
358 web_contents, WideToUTF16(search_string), kBack, kIgnoreCase, NULL,
359 &first_reverse);
360 // We find next and we go back so find coordinates should be the same as
361 // previous ones.
362 ASSERT_EQ(first, first_reverse);
365 // Verifies that comments and meta data are not searchable.
366 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
367 CommentsAndMetaDataNotSearchable) {
368 WebContents* web_contents =
369 browser()->tab_strip_model()->GetActiveWebContents();
370 ui_test_utils::NavigateToURL(browser(), GetURL("specialchar.html"));
372 std::wstring search_string =
373 L"\u4e2d\u65b0\u793e\u8bb0\u8005\u5b8b\u5409\u6cb3\u6444\u4e2d\u65b0\u7f51";
374 EXPECT_EQ(0, ui_test_utils::FindInPage(
375 web_contents, WideToUTF16(search_string), kFwd, kIgnoreCase, NULL, NULL));
378 // Verifies that span and lists are searchable.
379 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, SpanAndListsSearchable) {
380 WebContents* web_contents =
381 browser()->tab_strip_model()->GetActiveWebContents();
382 ui_test_utils::NavigateToURL(browser(), GetURL("FindRandomTests.html"));
384 std::wstring search_string = L"has light blue eyes and my father has dark";
385 EXPECT_EQ(1, ui_test_utils::FindInPage(
386 web_contents, WideToUTF16(search_string), kFwd, kIgnoreCase, NULL, NULL));
388 search_string = L"Google\nApple\nandroid";
389 EXPECT_EQ(1, ui_test_utils::FindInPage(
390 web_contents, WideToUTF16(search_string), kFwd, kIgnoreCase, NULL, NULL));
393 // Find in a very large page.
394 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, LargePage) {
395 WebContents* web_contents =
396 browser()->tab_strip_model()->GetActiveWebContents();
397 ui_test_utils::NavigateToURL(browser(), GetURL("largepage.html"));
399 std::wstring search_string = L"daughter of Prince";
400 EXPECT_EQ(373,
401 FindInPageWchar(web_contents, search_string.c_str(),
402 kFwd, kIgnoreCase, NULL));
405 // Find a very long string in a large page.
406 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindLongString) {
407 WebContents* web_contents =
408 browser()->tab_strip_model()->GetActiveWebContents();
409 ui_test_utils::NavigateToURL(browser(), GetURL("largepage.html"));
411 base::FilePath path = ui_test_utils::GetTestFilePath(
412 base::FilePath().AppendASCII("find_in_page"),
413 base::FilePath().AppendASCII("LongFind.txt"));
414 std::string query;
415 base::ReadFileToString(path, &query);
416 std::wstring search_string = base::UTF8ToWide(query);
417 EXPECT_EQ(1,
418 FindInPageWchar(web_contents, search_string.c_str(),
419 kFwd, kIgnoreCase, NULL));
422 // Find a big font string in a page.
423 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, BigString) {
424 WebContents* web_contents =
425 browser()->tab_strip_model()->GetActiveWebContents();
426 ui_test_utils::NavigateToURL(browser(), GetURL("BigText.html"));
427 EXPECT_EQ(1,
428 FindInPageWchar(web_contents, L"SomeLargeString",
429 kFwd, kIgnoreCase, NULL));
432 // http://crbug.com/369169
433 #if defined(OS_CHROMEOS)
434 #define MAYBE_SingleOccurrence DISABLED_SingleOccurrence
435 #else
436 #define MAYBE_SingleOccurrence SingleOccurrence
437 #endif
438 // Search Back and Forward on a single occurrence.
439 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, MAYBE_SingleOccurrence) {
440 WebContents* web_contents =
441 browser()->tab_strip_model()->GetActiveWebContents();
442 ui_test_utils::NavigateToURL(browser(), GetURL("FindRandomTests.html"));
444 gfx::Rect first_rect;
445 EXPECT_EQ(1,
446 ui_test_utils::FindInPage(web_contents,
447 ASCIIToUTF16("2010 Pro Bowl"), kFwd,
448 kIgnoreCase, NULL, &first_rect));
450 gfx::Rect second_rect;
451 EXPECT_EQ(1,
452 ui_test_utils::FindInPage(web_contents,
453 ASCIIToUTF16("2010 Pro Bowl"), kFwd,
454 kIgnoreCase, NULL, &second_rect));
456 // Doing a fake find so we have no previous search.
457 ui_test_utils::FindInPage(web_contents, ASCIIToUTF16("ghgfjgfh201232rere"),
458 kFwd, kIgnoreCase, NULL, NULL);
460 ASSERT_EQ(first_rect, second_rect);
462 EXPECT_EQ(1,
463 ui_test_utils::FindInPage(web_contents,
464 ASCIIToUTF16("2010 Pro Bowl"), kFwd,
465 kIgnoreCase, NULL, &first_rect));
466 EXPECT_EQ(1,
467 ui_test_utils::FindInPage(web_contents,
468 ASCIIToUTF16("2010 Pro Bowl"), kBack,
469 kIgnoreCase, NULL, &second_rect));
470 ASSERT_EQ(first_rect, second_rect);
473 // Find the whole text file page and find count should be 1.
474 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindWholeFileContent) {
475 WebContents* web_contents =
476 browser()->tab_strip_model()->GetActiveWebContents();
478 base::FilePath path = ui_test_utils::GetTestFilePath(
479 base::FilePath().AppendASCII("find_in_page"),
480 base::FilePath().AppendASCII("find_test.txt"));
481 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(path));
483 std::string query;
484 base::ReadFileToString(path, &query);
485 std::wstring search_string = base::UTF8ToWide(query);
486 EXPECT_EQ(1,
487 FindInPageWchar(web_contents, search_string.c_str(),
488 false, false, NULL));
491 // This test loads a single-frame page and makes sure the ordinal returned makes
492 // sense as we FindNext over all the items.
493 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageOrdinal) {
494 // First we navigate to our page.
495 GURL url = GetURL(kFrameData);
496 ui_test_utils::NavigateToURL(browser(), url);
498 // Search for 'o', which should make the first item active and return
499 // '1 in 3' (1st ordinal of a total of 3 matches).
500 WebContents* web_contents =
501 browser()->tab_strip_model()->GetActiveWebContents();
502 int ordinal = 0;
503 EXPECT_EQ(3, FindInPageWchar(web_contents, L"o",
504 kFwd, kIgnoreCase, &ordinal));
505 EXPECT_EQ(1, ordinal);
506 EXPECT_EQ(3, FindInPageWchar(web_contents, L"o",
507 kFwd, kIgnoreCase, &ordinal));
508 EXPECT_EQ(2, ordinal);
509 EXPECT_EQ(3, FindInPageWchar(web_contents, L"o",
510 kFwd, kIgnoreCase, &ordinal));
511 EXPECT_EQ(3, ordinal);
512 // Go back one match.
513 EXPECT_EQ(3, FindInPageWchar(web_contents, L"o",
514 kBack, kIgnoreCase, &ordinal));
515 EXPECT_EQ(2, ordinal);
516 EXPECT_EQ(3, FindInPageWchar(web_contents, L"o",
517 kFwd, kIgnoreCase, &ordinal));
518 EXPECT_EQ(3, ordinal);
519 // This should wrap to the top.
520 EXPECT_EQ(3, FindInPageWchar(web_contents, L"o",
521 kFwd, kIgnoreCase, &ordinal));
522 EXPECT_EQ(1, ordinal);
523 // This should go back to the end.
524 EXPECT_EQ(3, FindInPageWchar(web_contents, L"o",
525 kBack, kIgnoreCase, &ordinal));
526 EXPECT_EQ(3, ordinal);
529 // This tests that the ordinal is correctly adjusted after a selection
530 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
531 SelectChangesOrdinal_Issue20883) {
532 // First we navigate to our test content.
533 GURL url = GetURL(kSelectChangesOrdinal);
534 ui_test_utils::NavigateToURL(browser(), url);
536 // Search for a text that exists within a link on the page.
537 WebContents* web_contents =
538 browser()->tab_strip_model()->GetActiveWebContents();
539 ASSERT_TRUE(NULL != web_contents);
540 FindTabHelper* find_tab_helper =
541 FindTabHelper::FromWebContents(web_contents);
543 int ordinal = 0;
544 EXPECT_EQ(4, FindInPageWchar(web_contents,
545 L"google",
546 kFwd, kIgnoreCase, &ordinal));
547 EXPECT_EQ(1, ordinal);
549 // Move the selection to link 1, after searching.
550 std::string result;
551 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
552 web_contents,
553 "window.domAutomationController.send(selectLink1());",
554 &result));
556 // Do a find-next after the selection. This should move forward
557 // from there to the 3rd instance of 'google'.
558 EXPECT_EQ(4, FindInPageWchar(web_contents,
559 L"google",
560 kFwd, kIgnoreCase, &ordinal));
561 EXPECT_EQ(3, ordinal);
563 // End the find session.
564 find_tab_helper->StopFinding(FindBarController::kKeepSelectionOnPage);
567 // This tests that we start searching after selected text.
568 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
569 StartSearchAfterSelection) {
570 // First we navigate to our test content.
571 ui_test_utils::NavigateToURL(browser(), GetURL(kStartAfterSelection));
573 WebContents* web_contents =
574 browser()->tab_strip_model()->GetActiveWebContents();
575 ASSERT_TRUE(web_contents != NULL);
576 int ordinal = 0;
578 // Move the selection to the text span.
579 std::string result;
580 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
581 web_contents,
582 "window.domAutomationController.send(selectSpan());",
583 &result));
585 // Do a find-next after the selection. This should select the 2nd occurrence
586 // of the word 'find'.
587 EXPECT_EQ(4, FindInPageWchar(web_contents,
588 L"fi",
589 kFwd, kIgnoreCase, &ordinal));
590 EXPECT_EQ(2, ordinal);
592 // Refine the search, current active match should not change.
593 EXPECT_EQ(4, FindInPageWchar(web_contents,
594 L"find",
595 kFwd, kIgnoreCase, &ordinal));
596 EXPECT_EQ(2, ordinal);
598 // Refine the search to 'findMe'. The first new match is before the current
599 // active match, the second one is after it. This verifies that refining a
600 // search doesn't reset it.
601 EXPECT_EQ(2, FindInPageWchar(web_contents,
602 L"findMe",
603 kFwd, kIgnoreCase, &ordinal));
604 EXPECT_EQ(2, ordinal);
607 // This test loads a page with frames and makes sure the ordinal returned makes
608 // sense.
609 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) {
610 // First we navigate to our page.
611 GURL url = GetURL(kFramePage);
612 ui_test_utils::NavigateToURL(browser(), url);
614 // Search for 'a', which should make the first item active and return
615 // '1 in 7' (1st ordinal of a total of 7 matches).
616 WebContents* web_contents =
617 browser()->tab_strip_model()->GetActiveWebContents();
618 int ordinal = 0;
619 EXPECT_EQ(7,
620 FindInPageWchar(web_contents, L"a", kFwd, kIgnoreCase, &ordinal));
621 EXPECT_EQ(1, ordinal);
622 EXPECT_EQ(7,
623 FindInPageWchar(web_contents, L"a", kFwd, kIgnoreCase, &ordinal));
624 EXPECT_EQ(2, ordinal);
625 EXPECT_EQ(7,
626 FindInPageWchar(web_contents, L"a", kFwd, kIgnoreCase, &ordinal));
627 EXPECT_EQ(3, ordinal);
628 EXPECT_EQ(7,
629 FindInPageWchar(web_contents, L"a", kFwd, kIgnoreCase, &ordinal));
630 EXPECT_EQ(4, ordinal);
631 // Go back one, which should go back one frame.
632 EXPECT_EQ(7,
633 FindInPageWchar(web_contents, L"a", kBack, kIgnoreCase, &ordinal));
634 EXPECT_EQ(3, ordinal);
635 EXPECT_EQ(7,
636 FindInPageWchar(web_contents, L"a", kFwd, kIgnoreCase, &ordinal));
637 EXPECT_EQ(4, ordinal);
638 EXPECT_EQ(7,
639 FindInPageWchar(web_contents, L"a", kFwd, kIgnoreCase, &ordinal));
640 EXPECT_EQ(5, ordinal);
641 EXPECT_EQ(7,
642 FindInPageWchar(web_contents, L"a", kFwd, kIgnoreCase, &ordinal));
643 EXPECT_EQ(6, ordinal);
644 EXPECT_EQ(7,
645 FindInPageWchar(web_contents, L"a", kFwd, kIgnoreCase, &ordinal));
646 EXPECT_EQ(7, ordinal);
647 // Now we should wrap back to frame 1.
648 EXPECT_EQ(7,
649 FindInPageWchar(web_contents, L"a", kFwd, kIgnoreCase, &ordinal));
650 EXPECT_EQ(1, ordinal);
651 // Now we should wrap back to frame last frame.
652 EXPECT_EQ(7,
653 FindInPageWchar(web_contents, L"a", kBack, kIgnoreCase, &ordinal));
654 EXPECT_EQ(7, ordinal);
657 // We could get ordinals out of whack when restarting search in subframes.
658 // See http://crbug.com/5132.
659 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPage_Issue5132) {
660 // First we navigate to our page.
661 GURL url = GetURL(kFramePage);
662 ui_test_utils::NavigateToURL(browser(), url);
664 // Search for 'goa' three times (6 matches on page).
665 int ordinal = 0;
666 WebContents* web_contents =
667 browser()->tab_strip_model()->GetActiveWebContents();
668 EXPECT_EQ(6, FindInPageWchar(web_contents, L"goa",
669 kFwd, kIgnoreCase, &ordinal));
670 EXPECT_EQ(1, ordinal);
671 EXPECT_EQ(6, FindInPageWchar(web_contents, L"goa",
672 kFwd, kIgnoreCase, &ordinal));
673 EXPECT_EQ(2, ordinal);
674 EXPECT_EQ(6, FindInPageWchar(web_contents, L"goa",
675 kFwd, kIgnoreCase, &ordinal));
676 EXPECT_EQ(3, ordinal);
677 // Add space to search (should result in no matches).
678 EXPECT_EQ(0, FindInPageWchar(web_contents, L"goa ",
679 kFwd, kIgnoreCase, &ordinal));
680 EXPECT_EQ(0, ordinal);
681 // Remove the space, should be back to '3 out of 6')
682 EXPECT_EQ(6, FindInPageWchar(web_contents, L"goa",
683 kFwd, kIgnoreCase, &ordinal));
684 EXPECT_EQ(3, ordinal);
687 // This tests that the ordinal and match count is cleared after a navigation,
688 // as reported in issue http://crbug.com/126468.
689 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, NavigateClearsOrdinal) {
690 // First we navigate to our test content.
691 GURL url = GetURL(kSimple);
692 ui_test_utils::NavigateToURL(browser(), url);
694 // Open the Find box. In most tests we can just search without opening the
695 // box first, but in this case we are testing functionality triggered by
696 // NOTIFICATION_NAV_ENTRY_COMMITTED in the FindBarController and the observer
697 // for that event isn't setup unless the box is open.
698 EnsureFindBoxOpen();
700 // Search for a text that exists within a link on the page.
701 WebContents* web_contents =
702 browser()->tab_strip_model()->GetActiveWebContents();
703 ASSERT_TRUE(NULL != web_contents);
704 int ordinal = 0;
705 EXPECT_EQ(8, FindInPageWchar(web_contents,
706 L"e",
707 kFwd, kIgnoreCase, &ordinal));
708 EXPECT_EQ(1, ordinal);
710 // Then navigate away (to any page).
711 url = GetURL(kLinkPage);
712 ui_test_utils::NavigateToURL(browser(), url);
714 // Open the Find box again.
715 EnsureFindBoxOpen();
717 EXPECT_EQ(ASCIIToUTF16("e"), GetFindBarText());
718 EXPECT_EQ(ASCIIToUTF16(""), GetMatchCountText());
721 // Load a page with no selectable text and make sure we don't crash.
722 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindUnselectableText) {
723 // First we navigate to our page.
724 GURL url = GetURL(kUserSelectPage);
725 ui_test_utils::NavigateToURL(browser(), url);
727 int ordinal = 0;
728 WebContents* web_contents =
729 browser()->tab_strip_model()->GetActiveWebContents();
730 EXPECT_EQ(1, FindInPageWchar(web_contents,
731 L"text",
732 kFwd, kIgnoreCase, &ordinal));
733 EXPECT_EQ(1, ordinal);
736 // Try to reproduce the crash seen in issue 1341577.
737 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue1341577) {
738 // First we navigate to our page.
739 GURL url = GetURL(kCrashPage);
740 ui_test_utils::NavigateToURL(browser(), url);
742 // This would crash the tab. These must be the first two find requests issued
743 // against the frame, otherwise an active frame pointer is set and it wont
744 // produce the crash.
745 // We used to check the return value and |ordinal|. With ICU 4.2, FiP does
746 // not find a stand-alone dependent vowel sign of Indic scripts. So, the
747 // exptected values are all 0. To make this test pass regardless of
748 // ICU version, we just call FiP and see if there's any crash.
749 // TODO(jungshik): According to a native Malayalam speaker, it's ok not
750 // to find U+0D4C. Still need to investigate further this issue.
751 int ordinal = 0;
752 WebContents* web_contents =
753 browser()->tab_strip_model()->GetActiveWebContents();
754 FindInPageWchar(web_contents, L"\u0D4C", kFwd, kIgnoreCase, &ordinal);
755 FindInPageWchar(web_contents, L"\u0D4C", kFwd, kIgnoreCase, &ordinal);
757 // This should work fine.
758 EXPECT_EQ(1, FindInPageWchar(web_contents, L"\u0D24\u0D46",
759 kFwd, kIgnoreCase, &ordinal));
760 EXPECT_EQ(1, ordinal);
761 EXPECT_EQ(0, FindInPageWchar(web_contents, L"nostring",
762 kFwd, kIgnoreCase, &ordinal));
763 EXPECT_EQ(0, ordinal);
766 // Try to reproduce the crash seen in http://crbug.com/14491, where an assert
767 // hits in the BitStack size comparison in WebKit.
768 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue14491) {
769 // First we navigate to our page.
770 GURL url = GetURL(kBitstackCrash);
771 ui_test_utils::NavigateToURL(browser(), url);
773 // This used to crash the tab.
774 int ordinal = 0;
775 EXPECT_EQ(0, FindInPageWchar(browser()->tab_strip_model()->
776 GetActiveWebContents(),
777 L"s", kFwd, kIgnoreCase, &ordinal));
778 EXPECT_EQ(0, ordinal);
781 // Test to make sure Find does the right thing when restarting from a timeout.
782 // We used to have a problem where we'd stop finding matches when all of the
783 // following conditions were true:
784 // 1) The page has a lot of text to search.
785 // 2) The page contains more than one match.
786 // 3) It takes longer than the time-slice given to each Find operation (100
787 // ms) to find one or more of those matches (so Find times out and has to try
788 // again from where it left off).
789 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindRestarts_Issue1155639) {
790 // First we navigate to our page.
791 GURL url = GetURL(kTooFewMatchesPage);
792 ui_test_utils::NavigateToURL(browser(), url);
794 // This string appears 5 times at the bottom of a long page. If Find restarts
795 // properly after a timeout, it will find 5 matches, not just 1.
796 int ordinal = 0;
797 EXPECT_EQ(5, FindInPageWchar(browser()->tab_strip_model()->
798 GetActiveWebContents(),
799 L"008.xml",
800 kFwd, kIgnoreCase, &ordinal));
801 EXPECT_EQ(1, ordinal);
804 // Disable the test for win and mac as it started being flaky, see
805 // http://crbug/367701.
806 #if defined(OS_MACOSX) && !defined(OS_IOS) || defined(OS_WIN)
807 #define MAYBE_FindRestarts_Issue70505 DISABLED_FindRestarts_Issue70505
808 #else
809 #define MAYBE_FindRestarts_Issue70505 FindRestarts_Issue70505
810 #endif
811 // Make sure we don't get into an infinite loop when text box contains very
812 // large amount of text.
813 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
814 MAYBE_FindRestarts_Issue70505) {
815 // First we navigate to our page.
816 GURL url = GetURL(kLongTextareaPage);
817 ui_test_utils::NavigateToURL(browser(), url);
819 // If this test hangs on the FindInPage call, then it might be a regression
820 // such as the one found in issue http://crbug.com/70505.
821 int ordinal = 0;
822 FindInPageWchar(browser()->tab_strip_model()->GetActiveWebContents(),
823 L"a", kFwd, kIgnoreCase, &ordinal);
824 EXPECT_EQ(1, ordinal);
825 // TODO(finnur): We cannot reliably get the matchcount for this Find call
826 // until we fix issue http://crbug.com/71176.
829 // This tests bug 11761: FindInPage terminates search prematurely.
830 // This test is not expected to pass until bug 11761 is fixed.
831 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
832 DISABLED_FindInPagePrematureEnd) {
833 // First we navigate to our special focus tracking page.
834 GURL url = GetURL(kPrematureEnd);
835 ui_test_utils::NavigateToURL(browser(), url);
837 WebContents* web_contents =
838 browser()->tab_strip_model()->GetActiveWebContents();
839 ASSERT_TRUE(NULL != web_contents);
841 // Search for a text that exists within a link on the page.
842 int ordinal = 0;
843 EXPECT_EQ(2, FindInPageWchar(web_contents, L"html ",
844 kFwd, kIgnoreCase, &ordinal));
845 EXPECT_EQ(1, ordinal);
848 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindDisappearOnNavigate) {
849 // First we navigate to our special focus tracking page.
850 GURL url = GetURL(kSimple);
851 GURL url2 = GetURL(kFramePage);
852 ui_test_utils::NavigateToURL(browser(), url);
854 chrome::ShowFindBar(browser());
856 gfx::Point position;
857 bool fully_visible = false;
859 // Make sure it is open.
860 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
861 EXPECT_TRUE(fully_visible);
863 // Reload the tab and make sure Find window doesn't go away.
864 content::WindowedNotificationObserver observer(
865 content::NOTIFICATION_LOAD_STOP,
866 content::Source<NavigationController>(
867 &browser()->tab_strip_model()->GetActiveWebContents()->
868 GetController()));
869 chrome::Reload(browser(), CURRENT_TAB);
870 observer.Wait();
872 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
873 EXPECT_TRUE(fully_visible);
875 // Navigate and make sure the Find window goes away.
876 ui_test_utils::NavigateToURL(browser(), url2);
878 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
879 EXPECT_FALSE(fully_visible);
882 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindStayVisibleOnAnchorLoad) {
883 // First we navigate to our special focus tracking page.
884 GURL url = GetURL(kAnchorPage);
885 ui_test_utils::NavigateToURL(browser(), url);
887 chrome::ShowFindBar(browser());
889 gfx::Point position;
890 bool fully_visible = false;
892 // Make sure it is open.
893 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
894 EXPECT_TRUE(fully_visible);
896 // Navigate to the same page (but add an anchor/ref/fragment/whatever the kids
897 // are calling it these days).
898 GURL url_with_anchor = url.Resolve(kAnchor);
899 ui_test_utils::NavigateToURL(browser(), url_with_anchor);
901 // Make sure it is still open.
902 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
903 EXPECT_TRUE(fully_visible);
906 // FindDisappearOnNewTabAndHistory is flaky, at least on Mac.
907 // See http://crbug.com/43072
908 #if defined(OS_MACOSX)
909 #define MAYBE_FindDisappearOnNewTabAndHistory DISABLED_FindDisappearOnNewTabAndHistory
910 #else
911 #define MAYBE_FindDisappearOnNewTabAndHistory FindDisappearOnNewTabAndHistory
912 #endif
914 // Make sure Find box disappears when History/Downloads page is opened, and
915 // when a New Tab is opened.
916 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
917 MAYBE_FindDisappearOnNewTabAndHistory) {
918 // First we navigate to our special focus tracking page.
919 GURL url = GetURL(kSimple);
920 ui_test_utils::NavigateToURL(browser(), url);
922 chrome::ShowFindBar(browser());
924 gfx::Point position;
925 bool fully_visible = false;
927 // Make sure it is open.
928 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
929 EXPECT_TRUE(fully_visible);
931 // Open another tab (tab B).
932 chrome::NewTab(browser());
933 ui_test_utils::NavigateToURL(browser(), url);
935 // Make sure Find box is closed.
936 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
937 EXPECT_FALSE(fully_visible);
939 // Close tab B.
940 chrome::CloseTab(browser());
942 // Make sure Find window appears again.
943 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
944 EXPECT_TRUE(fully_visible);
946 chrome::ShowHistory(browser());
948 // Make sure Find box is closed.
949 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
950 EXPECT_FALSE(fully_visible);
953 // Make sure Find box moves out of the way if it is obscuring the active match.
954 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindMovesWhenObscuring) {
955 GURL url = GetURL(kMoveIfOver);
956 ui_test_utils::NavigateToURL(browser(), url);
958 chrome::ShowFindBar(browser());
960 // This is needed on GTK because the reposition operation is asynchronous.
961 base::MessageLoop::current()->RunUntilIdle();
963 gfx::Point start_position;
964 gfx::Point position;
965 bool fully_visible = false;
966 int ordinal = 0;
968 // Make sure it is open.
969 EXPECT_TRUE(GetFindBarWindowInfo(&start_position, &fully_visible));
970 EXPECT_TRUE(fully_visible);
972 WebContents* web_contents =
973 browser()->tab_strip_model()->GetActiveWebContents();
975 int moved_x_coord = FindInPageTillBoxMoves(web_contents, start_position.x(),
976 L"Chromium", kMoveIterations);
977 // The find box should have moved.
978 EXPECT_TRUE(moved_x_coord != start_position.x());
980 // Search for something guaranteed not to be obscured by the Find box.
981 EXPECT_EQ(1, FindInPageWchar(web_contents, L"Done",
982 kFwd, kIgnoreCase, &ordinal));
983 // Check the position.
984 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
985 EXPECT_TRUE(fully_visible);
987 // Make sure Find box has moved back to its original location.
988 EXPECT_EQ(position.x(), start_position.x());
990 // Move the find box again.
991 moved_x_coord = FindInPageTillBoxMoves(web_contents, start_position.x(),
992 L"Chromium", kMoveIterations);
993 EXPECT_TRUE(moved_x_coord != start_position.x());
995 // Search for an invalid string.
996 EXPECT_EQ(0, FindInPageWchar(web_contents, L"WeirdSearchString",
997 kFwd, kIgnoreCase, &ordinal));
999 // Check the position.
1000 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
1001 EXPECT_TRUE(fully_visible);
1003 // Make sure Find box has moved back to its original location.
1004 EXPECT_EQ(position.x(), start_position.x());
1007 // FindNextInNewTabUsesPrepopulate times-out on Mac and Aura.
1008 // See http://crbug.com/43070
1009 #if defined(OS_MACOSX) || defined(USE_AURA)
1010 #define MAYBE_FindNextInNewTabUsesPrepopulate \
1011 DISABLED_FindNextInNewTabUsesPrepopulate
1012 #else
1013 #define MAYBE_FindNextInNewTabUsesPrepopulate FindNextInNewTabUsesPrepopulate
1014 #endif
1016 // Make sure F3 in a new tab works if Find has previous string to search for.
1017 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
1018 MAYBE_FindNextInNewTabUsesPrepopulate) {
1019 // First we navigate to any page.
1020 GURL url = GetURL(kSimple);
1021 ui_test_utils::NavigateToURL(browser(), url);
1023 // Search for 'no_match'. No matches should be found.
1024 int ordinal = 0;
1025 WebContents* web_contents =
1026 browser()->tab_strip_model()->GetActiveWebContents();
1027 EXPECT_EQ(0, FindInPageWchar(web_contents, L"no_match",
1028 kFwd, kIgnoreCase, &ordinal));
1029 EXPECT_EQ(0, ordinal);
1031 // Open another tab (tab B).
1032 chrome::NewTab(browser());
1033 ui_test_utils::NavigateToURL(browser(), url);
1035 // Simulate what happens when you press F3 for FindNext. We should get a
1036 // response here (a hang means search was aborted).
1037 EXPECT_EQ(0, ui_test_utils::FindInPage(web_contents, base::string16(),
1038 kFwd, kIgnoreCase, &ordinal, NULL));
1039 EXPECT_EQ(0, ordinal);
1041 // Open another tab (tab C).
1042 chrome::NewTab(browser());
1043 ui_test_utils::NavigateToURL(browser(), url);
1045 // Simulate what happens when you press F3 for FindNext. We should get a
1046 // response here (a hang means search was aborted).
1047 EXPECT_EQ(0, ui_test_utils::FindInPage(web_contents, base::string16(),
1048 kFwd, kIgnoreCase, &ordinal, NULL));
1049 EXPECT_EQ(0, ordinal);
1052 // Make sure Find box does not become UI-inactive when no text is in the box as
1053 // we switch to a tab contents with an empty find string. See issue 13570.
1054 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, StayActive) {
1055 // First we navigate to any page.
1056 GURL url = GetURL(kSimple);
1057 ui_test_utils::NavigateToURL(browser(), url);
1059 chrome::ShowFindBar(browser());
1061 // Simulate a user clearing the search string. Ideally, we should be
1062 // simulating keypresses here for searching for something and pressing
1063 // backspace, but that's been proven flaky in the past, so we go straight to
1064 // web_contents.
1065 FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents(
1066 browser()->tab_strip_model()->GetActiveWebContents());
1067 // Stop the (non-existing) find operation, and clear the selection (which
1068 // signals the UI is still active).
1069 find_tab_helper->StopFinding(FindBarController::kClearSelectionOnPage);
1070 // Make sure the Find UI flag hasn't been cleared, it must be so that the UI
1071 // still responds to browser window resizing.
1072 ASSERT_TRUE(find_tab_helper->find_ui_active());
1075 // Make sure F3 works after you FindNext a couple of times and end the Find
1076 // session. See issue http://crbug.com/28306.
1077 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, RestartSearchFromF3) {
1078 // First we navigate to a simple page.
1079 GURL url = GetURL(kSimple);
1080 ui_test_utils::NavigateToURL(browser(), url);
1082 // Search for 'page'. Should have 1 match.
1083 int ordinal = 0;
1084 WebContents* web_contents =
1085 browser()->tab_strip_model()->GetActiveWebContents();
1086 EXPECT_EQ(1, FindInPageWchar(web_contents, L"page",
1087 kFwd, kIgnoreCase, &ordinal));
1088 EXPECT_EQ(1, ordinal);
1090 // Simulate what happens when you press F3 for FindNext. Still should show
1091 // one match. This cleared the pre-populate string at one point (see bug).
1092 EXPECT_EQ(1, ui_test_utils::FindInPage(web_contents, base::string16(),
1093 kFwd, kIgnoreCase, &ordinal, NULL));
1094 EXPECT_EQ(1, ordinal);
1096 // End the Find session, thereby making the next F3 start afresh.
1097 browser()->GetFindBarController()->EndFindSession(
1098 FindBarController::kKeepSelectionOnPage,
1099 FindBarController::kKeepResultsInFindBox);
1101 // Simulate F3 while Find box is closed. Should have 1 match.
1102 EXPECT_EQ(1, FindInPageWchar(web_contents, L"", kFwd, kIgnoreCase, &ordinal));
1103 EXPECT_EQ(1, ordinal);
1106 // When re-opening the find bar with F3, the find bar should be re-populated
1107 // with the last search from the same tab rather than the last overall search.
1108 // The only exception is if there is a global pasteboard (for example on Mac).
1109 // http://crbug.com/30006
1110 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PreferPreviousSearch) {
1111 // First we navigate to any page.
1112 GURL url = GetURL(kSimple);
1113 ui_test_utils::NavigateToURL(browser(), url);
1115 // Find "Default".
1116 int ordinal = 0;
1117 WebContents* web_contents_1 =
1118 browser()->tab_strip_model()->GetActiveWebContents();
1119 EXPECT_EQ(1, FindInPageWchar(web_contents_1, L"text",
1120 kFwd, kIgnoreCase, &ordinal));
1122 // Create a second tab.
1123 // For some reason we can't use AddSelectedTabWithURL here on ChromeOS. It
1124 // could be some delicate assumption about the tab starting off unselected or
1125 // something relating to user gesture.
1126 chrome::AddTabAt(browser(), GURL(), -1, true);
1127 ui_test_utils::NavigateToURL(browser(), url);
1128 WebContents* web_contents_2 =
1129 browser()->tab_strip_model()->GetActiveWebContents();
1130 EXPECT_NE(web_contents_1, web_contents_2);
1132 // Find "given".
1133 FindInPageWchar(web_contents_2, L"given", kFwd, kIgnoreCase, &ordinal);
1135 // Switch back to first tab.
1136 browser()->tab_strip_model()->ActivateTabAt(0, false);
1137 browser()->GetFindBarController()->EndFindSession(
1138 FindBarController::kKeepSelectionOnPage,
1139 FindBarController::kKeepResultsInFindBox);
1140 // Simulate F3.
1141 ui_test_utils::FindInPage(web_contents_1, base::string16(),
1142 kFwd, kIgnoreCase, &ordinal, NULL);
1143 FindBar* find_bar = browser()->GetFindBarController()->find_bar();
1144 if (find_bar->HasGlobalFindPasteboard()) {
1145 EXPECT_EQ(FindTabHelper::FromWebContents(web_contents_1)->find_text(),
1146 WideToUTF16(L"given"));
1147 } else {
1148 EXPECT_EQ(FindTabHelper::FromWebContents(web_contents_1)->find_text(),
1149 WideToUTF16(L"text"));
1153 // This tests that whenever you close and reopen the Find bar, it should show
1154 // the last search entered in that tab. http://crbug.com/40121.
1155 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateSameTab) {
1156 // First we navigate to any page.
1157 GURL url = GetURL(kSimple);
1158 ui_test_utils::NavigateToURL(browser(), url);
1160 // Search for the word "page".
1161 int ordinal = 0;
1162 WebContents* web_contents =
1163 browser()->tab_strip_model()->GetActiveWebContents();
1164 EXPECT_EQ(1, FindInPageWchar(web_contents, L"page",
1165 kFwd, kIgnoreCase, &ordinal));
1167 // Open the Find box.
1168 EnsureFindBoxOpen();
1170 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1171 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText());
1173 // Close the Find box.
1174 browser()->GetFindBarController()->EndFindSession(
1175 FindBarController::kKeepSelectionOnPage,
1176 FindBarController::kKeepResultsInFindBox);
1178 // Open the Find box again.
1179 EnsureFindBoxOpen();
1181 // After the Find box has been reopened, it should have been prepopulated with
1182 // the word "page" again.
1183 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1184 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText());
1187 // This tests that whenever you open Find in a new tab it should prepopulate
1188 // with a previous search term (in any tab), if a search has not been issued in
1189 // this tab before.
1190 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateInNewTab) {
1191 // First we navigate to any page.
1192 GURL url = GetURL(kSimple);
1193 ui_test_utils::NavigateToURL(browser(), url);
1195 // Search for the word "page".
1196 int ordinal = 0;
1197 WebContents* web_contents_1 =
1198 browser()->tab_strip_model()->GetActiveWebContents();
1199 EXPECT_EQ(1, FindInPageWchar(web_contents_1, L"page",
1200 kFwd, kIgnoreCase, &ordinal));
1201 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText());
1203 // Now create a second tab and load the same page.
1204 chrome::AddSelectedTabWithURL(browser(), url, content::PAGE_TRANSITION_TYPED);
1205 WebContents* web_contents_2 =
1206 browser()->tab_strip_model()->GetActiveWebContents();
1207 EXPECT_NE(web_contents_1, web_contents_2);
1209 // Open the Find box.
1210 EnsureFindBoxOpen();
1212 // The new tab should have "page" prepopulated, since that was the last search
1213 // in the first tab.
1214 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1215 // But it should not seem like a search has been issued.
1216 EXPECT_EQ(base::string16(), GetMatchCountText());
1219 // This makes sure that we can search for A in tabA, then for B in tabB and
1220 // when we come back to tabA we should still see A (because that was the last
1221 // search in that tab).
1222 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulatePreserveLast) {
1223 FindBar* find_bar = browser()->GetFindBarController()->find_bar();
1224 if (find_bar->HasGlobalFindPasteboard())
1225 return;
1227 // First we navigate to any page.
1228 GURL url = GetURL(kSimple);
1229 ui_test_utils::NavigateToURL(browser(), url);
1231 // Search for the word "page".
1232 int ordinal = 0;
1233 WebContents* web_contents_1 =
1234 browser()->tab_strip_model()->GetActiveWebContents();
1235 EXPECT_EQ(1, FindInPageWchar(web_contents_1, L"page",
1236 kFwd, kIgnoreCase, &ordinal));
1238 // Open the Find box.
1239 EnsureFindBoxOpen();
1241 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1243 // Close the Find box.
1244 browser()->GetFindBarController()->EndFindSession(
1245 FindBarController::kKeepSelectionOnPage,
1246 FindBarController::kKeepResultsInFindBox);
1248 // Now create a second tab and load the same page.
1249 chrome::AddTabAt(browser(), GURL(), -1, true);
1250 ui_test_utils::NavigateToURL(browser(), url);
1251 WebContents* web_contents_2 =
1252 browser()->tab_strip_model()->GetActiveWebContents();
1253 EXPECT_NE(web_contents_1, web_contents_2);
1255 // Search for the word "text".
1256 FindInPageWchar(web_contents_2, L"text", kFwd, kIgnoreCase, &ordinal);
1258 // Go back to the first tab and make sure we have NOT switched the prepopulate
1259 // text to "text".
1260 browser()->tab_strip_model()->ActivateTabAt(0, false);
1262 // Open the Find box.
1263 EnsureFindBoxOpen();
1265 // After the Find box has been reopened, it should have been prepopulated with
1266 // the word "page" again, since that was the last search in that tab.
1267 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1269 // Close the Find box.
1270 browser()->GetFindBarController()->EndFindSession(
1271 FindBarController::kKeepSelectionOnPage,
1272 FindBarController::kKeepResultsInFindBox);
1274 // Re-open the Find box.
1275 // This is a special case: previous search in WebContents used to get cleared
1276 // if you opened and closed the FindBox, which would cause the global
1277 // prepopulate value to show instead of last search in this tab.
1278 EnsureFindBoxOpen();
1280 // After the Find box has been reopened, it should have been prepopulated with
1281 // the word "page" again, since that was the last search in that tab.
1282 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1285 // TODO(rohitrao): Searching in incognito tabs does not work in browser tests in
1286 // Linux views. Investigate and fix. http://crbug.com/40948
1287 #if defined(OS_LINUX) && defined(TOOLKIT_VIEWS)
1288 #define MAYBE_NoIncognitoPrepopulate DISABLED_NoIncognitoPrepopulate
1289 #else
1290 #define MAYBE_NoIncognitoPrepopulate NoIncognitoPrepopulate
1291 #endif
1293 // This tests that search terms entered into an incognito find bar are not used
1294 // as prepopulate terms for non-incognito windows.
1295 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, MAYBE_NoIncognitoPrepopulate) {
1296 FindBar* find_bar = browser()->GetFindBarController()->find_bar();
1297 if (find_bar->HasGlobalFindPasteboard())
1298 return;
1300 // First we navigate to the "simple" test page.
1301 GURL url = GetURL(kSimple);
1302 ui_test_utils::NavigateToURL(browser(), url);
1304 // Search for the word "page" in the normal browser tab.
1305 int ordinal = 0;
1306 WebContents* web_contents_1 =
1307 browser()->tab_strip_model()->GetActiveWebContents();
1308 EXPECT_EQ(1, FindInPageWchar(web_contents_1, L"page",
1309 kFwd, kIgnoreCase, &ordinal));
1311 // Open the Find box.
1312 EnsureFindBoxOpenForBrowser(browser());
1313 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser()));
1315 // Close the Find box.
1316 browser()->GetFindBarController()->EndFindSession(
1317 FindBarController::kKeepSelectionOnPage,
1318 FindBarController::kKeepResultsInFindBox);
1320 // Open a new incognito window and navigate to the same page.
1321 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile();
1322 Browser* incognito_browser =
1323 new Browser(Browser::CreateParams(incognito_profile,
1324 browser()->host_desktop_type()));
1325 content::WindowedNotificationObserver observer(
1326 content::NOTIFICATION_LOAD_STOP,
1327 content::NotificationService::AllSources());
1328 chrome::AddSelectedTabWithURL(incognito_browser, url,
1329 content::PAGE_TRANSITION_AUTO_TOPLEVEL);
1330 observer.Wait();
1331 incognito_browser->window()->Show();
1333 // Open the find box and make sure that it is prepopulated with "page".
1334 EnsureFindBoxOpenForBrowser(incognito_browser);
1335 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(incognito_browser));
1337 // Search for the word "text" in the incognito tab.
1338 WebContents* incognito_tab =
1339 incognito_browser->tab_strip_model()->GetActiveWebContents();
1340 EXPECT_EQ(1, FindInPageWchar(incognito_tab, L"text",
1341 kFwd, kIgnoreCase, &ordinal));
1342 EXPECT_EQ(ASCIIToUTF16("text"), GetFindBarTextForBrowser(incognito_browser));
1344 // Close the Find box.
1345 incognito_browser->GetFindBarController()->EndFindSession(
1346 FindBarController::kKeepSelectionOnPage,
1347 FindBarController::kKeepResultsInFindBox);
1349 // Now open a new tab in the original (non-incognito) browser.
1350 chrome::AddSelectedTabWithURL(browser(), url, content::PAGE_TRANSITION_TYPED);
1351 WebContents* web_contents_2 =
1352 browser()->tab_strip_model()->GetActiveWebContents();
1353 EXPECT_NE(web_contents_1, web_contents_2);
1355 // Open the Find box and make sure it is prepopulated with the search term
1356 // from the original browser, not the search term from the incognito window.
1357 EnsureFindBoxOpenForBrowser(browser());
1358 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser()));
1361 // This makes sure that dismissing the find bar with kActivateSelection works.
1362 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, ActivateLinkNavigatesPage) {
1363 // First we navigate to our test content.
1364 GURL url = GetURL(kLinkPage);
1365 ui_test_utils::NavigateToURL(browser(), url);
1367 WebContents* web_contents =
1368 browser()->tab_strip_model()->GetActiveWebContents();
1369 FindTabHelper* find_tab_helper =
1370 FindTabHelper::FromWebContents(web_contents);
1372 int ordinal = 0;
1373 FindInPageWchar(web_contents, L"link", kFwd, kIgnoreCase, &ordinal);
1374 EXPECT_EQ(ordinal, 1);
1376 // End the find session, click on the link.
1377 content::WindowedNotificationObserver observer(
1378 content::NOTIFICATION_LOAD_STOP,
1379 content::Source<NavigationController>(&web_contents->GetController()));
1380 find_tab_helper->StopFinding(FindBarController::kActivateSelectionOnPage);
1381 observer.Wait();
1384 // Tests that FindBar fits within a narrow browser window.
1385 // Flaky on Linux/GTK: http://crbug.com/136443.
1386 #if defined(TOOLKIT_GTK)
1387 #define MAYBE_FitWindow DISABLED_FitWindow
1388 #else
1389 #define MAYBE_FitWindow FitWindow
1390 #endif
1391 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, MAYBE_FitWindow) {
1392 Browser::CreateParams params(Browser::TYPE_POPUP, browser()->profile(),
1393 browser()->host_desktop_type());
1394 params.initial_bounds = gfx::Rect(0, 0, 250, 500);
1395 Browser* popup = new Browser(params);
1396 content::WindowedNotificationObserver observer(
1397 content::NOTIFICATION_LOAD_STOP,
1398 content::NotificationService::AllSources());
1399 chrome::AddSelectedTabWithURL(popup, GURL(content::kAboutBlankURL),
1400 content::PAGE_TRANSITION_LINK);
1401 // Wait for the page to finish loading.
1402 observer.Wait();
1403 popup->window()->Show();
1405 // On GTK, bounds change is asynchronous.
1406 base::MessageLoop::current()->RunUntilIdle();
1408 EnsureFindBoxOpenForBrowser(popup);
1410 // GTK adjusts FindBar size asynchronously.
1411 base::MessageLoop::current()->RunUntilIdle();
1413 ASSERT_LE(GetFindBarWidthForBrowser(popup),
1414 popup->window()->GetBounds().width());
1417 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
1418 FindMovesOnTabClose_Issue1343052) {
1419 EnsureFindBoxOpen();
1420 content::RunAllPendingInMessageLoop(); // Needed on Linux.
1422 gfx::Point position;
1423 EXPECT_TRUE(GetFindBarWindowInfo(&position, NULL));
1425 // Open another tab.
1426 GURL url = GetURL(kSimple);
1427 ui_test_utils::NavigateToURLWithDisposition(
1428 browser(), url, NEW_FOREGROUND_TAB,
1429 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1431 // Close it.
1432 chrome::CloseTab(browser());
1434 // See if the Find window has moved.
1435 gfx::Point position2;
1436 EXPECT_TRUE(GetFindBarWindowInfo(&position2, NULL));
1437 EXPECT_EQ(position, position2);
1439 // Toggle the bookmark bar state. Note that this starts an animation, and
1440 // there isn't a good way other than looping and polling to see when it's
1441 // done. So instead we change the state and open a new tab, since the new tab
1442 // animation doesn't happen on tab change.
1443 chrome::ToggleBookmarkBar(browser());
1445 ui_test_utils::NavigateToURLWithDisposition(
1446 browser(), url, NEW_FOREGROUND_TAB,
1447 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1449 EnsureFindBoxOpen();
1450 content::RunAllPendingInMessageLoop(); // Needed on Linux.
1451 EXPECT_TRUE(GetFindBarWindowInfo(&position, NULL));
1453 ui_test_utils::NavigateToURLWithDisposition(
1454 browser(), url, NEW_FOREGROUND_TAB,
1455 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1456 chrome::CloseTab(browser());
1457 EXPECT_TRUE(GetFindBarWindowInfo(&position2, NULL));
1458 EXPECT_EQ(position, position2);
1461 // Verify that if there's a global pasteboard (for example on Mac) then doing
1462 // a search on one tab will clear the matches label on the other tabs.
1463 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
1464 GlobalPasteBoardClearMatches) {
1465 FindBar* find_bar = browser()->GetFindBarController()->find_bar();
1466 if (!find_bar->HasGlobalFindPasteboard())
1467 return;
1469 // First we navigate to any page.
1470 GURL url = GetURL(kSimple);
1471 ui_test_utils::NavigateToURL(browser(), url);
1473 // Change the match count on the first tab to "1 of 1".
1474 int ordinal = 0;
1475 WebContents* web_contents_1 =
1476 browser()->tab_strip_model()->GetActiveWebContents();
1477 EXPECT_EQ(1, FindInPageWchar(web_contents_1, L"page",
1478 kFwd, kIgnoreCase, &ordinal));
1479 EnsureFindBoxOpen();
1480 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText());
1482 // Next, do a search in a second tab.
1483 chrome::AddTabAt(browser(), GURL(), -1, true);
1484 ui_test_utils::NavigateToURL(browser(), url);
1485 WebContents* web_contents_2 =
1486 browser()->tab_strip_model()->GetActiveWebContents();
1487 FindInPageWchar(web_contents_2, L"text", kFwd, kIgnoreCase, &ordinal);
1488 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText());
1490 // Go back to the first tab and verify that the match text is cleared.
1491 // text to "text".
1492 browser()->tab_strip_model()->ActivateTabAt(0, false);
1493 EXPECT_EQ(ASCIIToUTF16(""), GetMatchCountText());
1496 // Verify that Incognito window doesn't propagate find string to other widows.
1497 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, GlobalPasteboardIncognito) {
1498 Browser* browser_incognito = CreateIncognitoBrowser();
1499 WebContents* web_contents_1 =
1500 browser()->tab_strip_model()->GetActiveWebContents();
1501 FindInPageWchar(web_contents_1, L"page", kFwd, kIgnoreCase, NULL);
1502 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1503 WebContents* web_contents_2 =
1504 browser_incognito->tab_strip_model()->GetActiveWebContents();
1505 FindInPageWchar(web_contents_2, L"Incognito", kFwd, kIgnoreCase, NULL);
1506 EXPECT_EQ(ASCIIToUTF16("Incognito"),
1507 GetFindBarTextForBrowser(browser_incognito));
1508 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1511 // Find text in regular window, find different text in incognito, send
1512 // IDC_FIND_NEXT to incognito. It should search for the second phrase.
1513 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, IncognitoFindNextSecret) {
1514 WebContents* web_contents =
1515 browser()->tab_strip_model()->GetActiveWebContents();
1516 // On Mac this updates the find pboard.
1517 FindInPageWchar(web_contents, L"bar", kFwd, kIgnoreCase, NULL);
1519 Browser* browser_incognito = CreateIncognitoBrowser();
1520 ui_test_utils::NavigateToURL(browser_incognito,
1521 GURL("data:text/plain,barfoofoo"));
1522 WebContents* web_contents_incognito =
1523 browser_incognito->tab_strip_model()->GetActiveWebContents();
1524 FindInPageWchar(web_contents_incognito, L"foo", true, kIgnoreCase, NULL);
1525 EXPECT_EQ(ASCIIToUTF16("foo"),
1526 GetFindBarTextForBrowser(browser_incognito));
1527 EXPECT_EQ(ASCIIToUTF16("1 of 2"),
1528 GetFindBarMatchCountTextForBrowser(browser_incognito));
1530 // Close the find bar.
1531 FindTabHelper* find_tab_helper =
1532 FindTabHelper::FromWebContents(web_contents_incognito);
1533 find_tab_helper->StopFinding(FindBarController::kActivateSelectionOnPage);
1535 // Cmd + G triggers IDC_FIND_NEXT command. Thus we test FindInPage()
1536 // method from browser_commands.cc. FindInPageWchar() bypasses it.
1537 EXPECT_TRUE(chrome::ExecuteCommand(browser_incognito, IDC_FIND_NEXT));
1538 ui_test_utils::FindInPageNotificationObserver observer(
1539 web_contents_incognito);
1540 observer.Wait();
1541 EXPECT_EQ(ASCIIToUTF16("foo"),
1542 GetFindBarTextForBrowser(browser_incognito));
1543 EXPECT_EQ(ASCIIToUTF16("2 of 2"),
1544 GetFindBarMatchCountTextForBrowser(browser_incognito));
1547 // Find text in regular window, send IDC_FIND_NEXT to incognito. It should
1548 // search for the first phrase.
1549 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, IncognitoFindNextShared) {
1550 WebContents* web_contents =
1551 browser()->tab_strip_model()->GetActiveWebContents();
1552 // On Mac this updates the find pboard.
1553 FindInPageWchar(web_contents, L"bar", kFwd, kIgnoreCase, NULL);
1555 Browser* browser_incognito = CreateIncognitoBrowser();
1556 ui_test_utils::NavigateToURL(browser_incognito,
1557 GURL("data:text/plain,bar"));
1559 EXPECT_TRUE(chrome::ExecuteCommand(browser_incognito, IDC_FIND_NEXT));
1560 WebContents* web_contents_incognito =
1561 browser_incognito->tab_strip_model()->GetActiveWebContents();
1562 ui_test_utils::FindInPageNotificationObserver observer(
1563 web_contents_incognito);
1564 observer.Wait();
1565 EXPECT_EQ(ASCIIToUTF16("bar"),
1566 GetFindBarTextForBrowser(browser_incognito));
1569 #if defined(OS_WIN)
1571 BOOL CALLBACK EnumerateChildren(HWND hwnd, LPARAM l_param) {
1572 HWND* child = reinterpret_cast<HWND*>(l_param);
1573 *child = hwnd;
1574 // The first child window is the plugin, then its children. So stop
1575 // enumerating after the first callback.
1576 return FALSE;
1579 // Ensure that the find bar is always over a windowed NPAPI plugin.
1580 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, WindowedNPAPIPluginHidden) {
1581 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPluginsAlwaysAuthorize,
1582 true);
1584 // First load the page and wait for the NPAPI plugin's window to display.
1585 base::string16 expected_title(ASCIIToUTF16("ready"));
1586 content::WebContents* tab =
1587 browser()->tab_strip_model()->GetActiveWebContents();
1588 content::TitleWatcher title_watcher(tab, expected_title);
1590 GURL url = ui_test_utils::GetTestUrl(
1591 base::FilePath().AppendASCII("printing"),
1592 base::FilePath().AppendASCII("npapi_plugin.html"));
1593 ui_test_utils::NavigateToURL(browser(), url);
1595 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
1597 // Now get the region of the plugin before the find bar is shown.
1598 HWND hwnd = tab->GetNativeView()->GetHost()->GetAcceleratedWidget();
1599 HWND child = NULL;
1600 EnumChildWindows(hwnd, EnumerateChildren,reinterpret_cast<LPARAM>(&child));
1602 RECT region_before, region_after;
1603 int result = GetWindowRgnBox(child, &region_before);
1604 ASSERT_EQ(result, SIMPLEREGION);
1606 // Create a new tab and open the find bar there.
1607 chrome::NewTab(browser());
1608 browser()->tab_strip_model()->ActivateTabAt(1, true);
1609 ui_test_utils::NavigateToURL(browser(), GURL(content::kAboutBlankURL));
1611 EnsureFindBoxOpen();
1613 // Now switch back to the original tab with the plugin and show the find bar.
1614 browser()->tab_strip_model()->ActivateTabAt(0, true);
1615 EnsureFindBoxOpen();
1617 result = GetWindowRgnBox(child, &region_after);
1618 if (result == NULLREGION) {
1619 // Depending on the browser window size, the plugin could be full covered.
1620 return;
1623 if (result == COMPLEXREGION) {
1624 // Complex region, by definition not equal to the initial region.
1625 return;
1628 ASSERT_EQ(result, SIMPLEREGION);
1629 bool rects_equal =
1630 region_before.left == region_after.left &&
1631 region_before.top == region_after.top &&
1632 region_before.right == region_after.right &&
1633 region_before.bottom == region_after.bottom;
1634 ASSERT_FALSE(rects_equal);
1637 #endif