Temporarily re-enabling SizeAfterPrefChange test with traces (this time for Linux...
[chromium-blink-merge.git] / chrome / browser / ui / find_bar / find_bar_host_browsertest.cc
blob0e9d57483df6b4edc0ce646634ae74407c8e573b
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, mac and ChromeOS as it started being flaky, see
805 // http://crbug/367701.
806 #if defined(OS_MACOSX) && !defined(OS_IOS) || defined(OS_WIN) || \
807 defined(OS_CHROMEOS)
808 #define MAYBE_FindRestarts_Issue70505 DISABLED_FindRestarts_Issue70505
809 #else
810 #define MAYBE_FindRestarts_Issue70505 FindRestarts_Issue70505
811 #endif
812 // Make sure we don't get into an infinite loop when text box contains very
813 // large amount of text.
814 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
815 MAYBE_FindRestarts_Issue70505) {
816 // First we navigate to our page.
817 GURL url = GetURL(kLongTextareaPage);
818 ui_test_utils::NavigateToURL(browser(), url);
820 // If this test hangs on the FindInPage call, then it might be a regression
821 // such as the one found in issue http://crbug.com/70505.
822 int ordinal = 0;
823 FindInPageWchar(browser()->tab_strip_model()->GetActiveWebContents(),
824 L"a", kFwd, kIgnoreCase, &ordinal);
825 EXPECT_EQ(1, ordinal);
826 // TODO(finnur): We cannot reliably get the matchcount for this Find call
827 // until we fix issue http://crbug.com/71176.
830 // This tests bug 11761: FindInPage terminates search prematurely.
831 // This test is not expected to pass until bug 11761 is fixed.
832 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
833 DISABLED_FindInPagePrematureEnd) {
834 // First we navigate to our special focus tracking page.
835 GURL url = GetURL(kPrematureEnd);
836 ui_test_utils::NavigateToURL(browser(), url);
838 WebContents* web_contents =
839 browser()->tab_strip_model()->GetActiveWebContents();
840 ASSERT_TRUE(NULL != web_contents);
842 // Search for a text that exists within a link on the page.
843 int ordinal = 0;
844 EXPECT_EQ(2, FindInPageWchar(web_contents, L"html ",
845 kFwd, kIgnoreCase, &ordinal));
846 EXPECT_EQ(1, ordinal);
849 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindDisappearOnNavigate) {
850 // First we navigate to our special focus tracking page.
851 GURL url = GetURL(kSimple);
852 GURL url2 = GetURL(kFramePage);
853 ui_test_utils::NavigateToURL(browser(), url);
855 chrome::ShowFindBar(browser());
857 gfx::Point position;
858 bool fully_visible = false;
860 // Make sure it is open.
861 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
862 EXPECT_TRUE(fully_visible);
864 // Reload the tab and make sure Find window doesn't go away.
865 content::WindowedNotificationObserver observer(
866 content::NOTIFICATION_LOAD_STOP,
867 content::Source<NavigationController>(
868 &browser()->tab_strip_model()->GetActiveWebContents()->
869 GetController()));
870 chrome::Reload(browser(), CURRENT_TAB);
871 observer.Wait();
873 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
874 EXPECT_TRUE(fully_visible);
876 // Navigate and make sure the Find window goes away.
877 ui_test_utils::NavigateToURL(browser(), url2);
879 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
880 EXPECT_FALSE(fully_visible);
883 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindStayVisibleOnAnchorLoad) {
884 // First we navigate to our special focus tracking page.
885 GURL url = GetURL(kAnchorPage);
886 ui_test_utils::NavigateToURL(browser(), url);
888 chrome::ShowFindBar(browser());
890 gfx::Point position;
891 bool fully_visible = false;
893 // Make sure it is open.
894 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
895 EXPECT_TRUE(fully_visible);
897 // Navigate to the same page (but add an anchor/ref/fragment/whatever the kids
898 // are calling it these days).
899 GURL url_with_anchor = url.Resolve(kAnchor);
900 ui_test_utils::NavigateToURL(browser(), url_with_anchor);
902 // Make sure it is still open.
903 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
904 EXPECT_TRUE(fully_visible);
907 // FindDisappearOnNewTabAndHistory is flaky, at least on Mac.
908 // See http://crbug.com/43072
909 #if defined(OS_MACOSX)
910 #define MAYBE_FindDisappearOnNewTabAndHistory DISABLED_FindDisappearOnNewTabAndHistory
911 #else
912 #define MAYBE_FindDisappearOnNewTabAndHistory FindDisappearOnNewTabAndHistory
913 #endif
915 // Make sure Find box disappears when History/Downloads page is opened, and
916 // when a New Tab is opened.
917 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
918 MAYBE_FindDisappearOnNewTabAndHistory) {
919 // First we navigate to our special focus tracking page.
920 GURL url = GetURL(kSimple);
921 ui_test_utils::NavigateToURL(browser(), url);
923 chrome::ShowFindBar(browser());
925 gfx::Point position;
926 bool fully_visible = false;
928 // Make sure it is open.
929 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
930 EXPECT_TRUE(fully_visible);
932 // Open another tab (tab B).
933 chrome::NewTab(browser());
934 ui_test_utils::NavigateToURL(browser(), url);
936 // Make sure Find box is closed.
937 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
938 EXPECT_FALSE(fully_visible);
940 // Close tab B.
941 chrome::CloseTab(browser());
943 // Make sure Find window appears again.
944 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
945 EXPECT_TRUE(fully_visible);
947 chrome::ShowHistory(browser());
949 // Make sure Find box is closed.
950 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
951 EXPECT_FALSE(fully_visible);
954 // Make sure Find box moves out of the way if it is obscuring the active match.
955 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindMovesWhenObscuring) {
956 GURL url = GetURL(kMoveIfOver);
957 ui_test_utils::NavigateToURL(browser(), url);
959 chrome::ShowFindBar(browser());
961 // This is needed on GTK because the reposition operation is asynchronous.
962 base::MessageLoop::current()->RunUntilIdle();
964 gfx::Point start_position;
965 gfx::Point position;
966 bool fully_visible = false;
967 int ordinal = 0;
969 // Make sure it is open.
970 EXPECT_TRUE(GetFindBarWindowInfo(&start_position, &fully_visible));
971 EXPECT_TRUE(fully_visible);
973 WebContents* web_contents =
974 browser()->tab_strip_model()->GetActiveWebContents();
976 int moved_x_coord = FindInPageTillBoxMoves(web_contents, start_position.x(),
977 L"Chromium", kMoveIterations);
978 // The find box should have moved.
979 EXPECT_TRUE(moved_x_coord != start_position.x());
981 // Search for something guaranteed not to be obscured by the Find box.
982 EXPECT_EQ(1, FindInPageWchar(web_contents, L"Done",
983 kFwd, kIgnoreCase, &ordinal));
984 // Check the position.
985 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
986 EXPECT_TRUE(fully_visible);
988 // Make sure Find box has moved back to its original location.
989 EXPECT_EQ(position.x(), start_position.x());
991 // Move the find box again.
992 moved_x_coord = FindInPageTillBoxMoves(web_contents, start_position.x(),
993 L"Chromium", kMoveIterations);
994 EXPECT_TRUE(moved_x_coord != start_position.x());
996 // Search for an invalid string.
997 EXPECT_EQ(0, FindInPageWchar(web_contents, L"WeirdSearchString",
998 kFwd, kIgnoreCase, &ordinal));
1000 // Check the position.
1001 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
1002 EXPECT_TRUE(fully_visible);
1004 // Make sure Find box has moved back to its original location.
1005 EXPECT_EQ(position.x(), start_position.x());
1008 // FindNextInNewTabUsesPrepopulate times-out on Mac and Aura.
1009 // See http://crbug.com/43070
1010 #if defined(OS_MACOSX) || defined(USE_AURA)
1011 #define MAYBE_FindNextInNewTabUsesPrepopulate \
1012 DISABLED_FindNextInNewTabUsesPrepopulate
1013 #else
1014 #define MAYBE_FindNextInNewTabUsesPrepopulate FindNextInNewTabUsesPrepopulate
1015 #endif
1017 // Make sure F3 in a new tab works if Find has previous string to search for.
1018 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
1019 MAYBE_FindNextInNewTabUsesPrepopulate) {
1020 // First we navigate to any page.
1021 GURL url = GetURL(kSimple);
1022 ui_test_utils::NavigateToURL(browser(), url);
1024 // Search for 'no_match'. No matches should be found.
1025 int ordinal = 0;
1026 WebContents* web_contents =
1027 browser()->tab_strip_model()->GetActiveWebContents();
1028 EXPECT_EQ(0, FindInPageWchar(web_contents, L"no_match",
1029 kFwd, kIgnoreCase, &ordinal));
1030 EXPECT_EQ(0, ordinal);
1032 // Open another tab (tab B).
1033 chrome::NewTab(browser());
1034 ui_test_utils::NavigateToURL(browser(), url);
1036 // Simulate what happens when you press F3 for FindNext. We should get a
1037 // response here (a hang means search was aborted).
1038 EXPECT_EQ(0, ui_test_utils::FindInPage(web_contents, base::string16(),
1039 kFwd, kIgnoreCase, &ordinal, NULL));
1040 EXPECT_EQ(0, ordinal);
1042 // Open another tab (tab C).
1043 chrome::NewTab(browser());
1044 ui_test_utils::NavigateToURL(browser(), url);
1046 // Simulate what happens when you press F3 for FindNext. We should get a
1047 // response here (a hang means search was aborted).
1048 EXPECT_EQ(0, ui_test_utils::FindInPage(web_contents, base::string16(),
1049 kFwd, kIgnoreCase, &ordinal, NULL));
1050 EXPECT_EQ(0, ordinal);
1053 // Make sure Find box does not become UI-inactive when no text is in the box as
1054 // we switch to a tab contents with an empty find string. See issue 13570.
1055 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, StayActive) {
1056 // First we navigate to any page.
1057 GURL url = GetURL(kSimple);
1058 ui_test_utils::NavigateToURL(browser(), url);
1060 chrome::ShowFindBar(browser());
1062 // Simulate a user clearing the search string. Ideally, we should be
1063 // simulating keypresses here for searching for something and pressing
1064 // backspace, but that's been proven flaky in the past, so we go straight to
1065 // web_contents.
1066 FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents(
1067 browser()->tab_strip_model()->GetActiveWebContents());
1068 // Stop the (non-existing) find operation, and clear the selection (which
1069 // signals the UI is still active).
1070 find_tab_helper->StopFinding(FindBarController::kClearSelectionOnPage);
1071 // Make sure the Find UI flag hasn't been cleared, it must be so that the UI
1072 // still responds to browser window resizing.
1073 ASSERT_TRUE(find_tab_helper->find_ui_active());
1076 // Make sure F3 works after you FindNext a couple of times and end the Find
1077 // session. See issue http://crbug.com/28306.
1078 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, RestartSearchFromF3) {
1079 // First we navigate to a simple page.
1080 GURL url = GetURL(kSimple);
1081 ui_test_utils::NavigateToURL(browser(), url);
1083 // Search for 'page'. Should have 1 match.
1084 int ordinal = 0;
1085 WebContents* web_contents =
1086 browser()->tab_strip_model()->GetActiveWebContents();
1087 EXPECT_EQ(1, FindInPageWchar(web_contents, L"page",
1088 kFwd, kIgnoreCase, &ordinal));
1089 EXPECT_EQ(1, ordinal);
1091 // Simulate what happens when you press F3 for FindNext. Still should show
1092 // one match. This cleared the pre-populate string at one point (see bug).
1093 EXPECT_EQ(1, ui_test_utils::FindInPage(web_contents, base::string16(),
1094 kFwd, kIgnoreCase, &ordinal, NULL));
1095 EXPECT_EQ(1, ordinal);
1097 // End the Find session, thereby making the next F3 start afresh.
1098 browser()->GetFindBarController()->EndFindSession(
1099 FindBarController::kKeepSelectionOnPage,
1100 FindBarController::kKeepResultsInFindBox);
1102 // Simulate F3 while Find box is closed. Should have 1 match.
1103 EXPECT_EQ(1, FindInPageWchar(web_contents, L"", kFwd, kIgnoreCase, &ordinal));
1104 EXPECT_EQ(1, ordinal);
1107 // When re-opening the find bar with F3, the find bar should be re-populated
1108 // with the last search from the same tab rather than the last overall search.
1109 // The only exception is if there is a global pasteboard (for example on Mac).
1110 // http://crbug.com/30006
1111 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PreferPreviousSearch) {
1112 // First we navigate to any page.
1113 GURL url = GetURL(kSimple);
1114 ui_test_utils::NavigateToURL(browser(), url);
1116 // Find "Default".
1117 int ordinal = 0;
1118 WebContents* web_contents_1 =
1119 browser()->tab_strip_model()->GetActiveWebContents();
1120 EXPECT_EQ(1, FindInPageWchar(web_contents_1, L"text",
1121 kFwd, kIgnoreCase, &ordinal));
1123 // Create a second tab.
1124 // For some reason we can't use AddSelectedTabWithURL here on ChromeOS. It
1125 // could be some delicate assumption about the tab starting off unselected or
1126 // something relating to user gesture.
1127 chrome::AddTabAt(browser(), GURL(), -1, true);
1128 ui_test_utils::NavigateToURL(browser(), url);
1129 WebContents* web_contents_2 =
1130 browser()->tab_strip_model()->GetActiveWebContents();
1131 EXPECT_NE(web_contents_1, web_contents_2);
1133 // Find "given".
1134 FindInPageWchar(web_contents_2, L"given", kFwd, kIgnoreCase, &ordinal);
1136 // Switch back to first tab.
1137 browser()->tab_strip_model()->ActivateTabAt(0, false);
1138 browser()->GetFindBarController()->EndFindSession(
1139 FindBarController::kKeepSelectionOnPage,
1140 FindBarController::kKeepResultsInFindBox);
1141 // Simulate F3.
1142 ui_test_utils::FindInPage(web_contents_1, base::string16(),
1143 kFwd, kIgnoreCase, &ordinal, NULL);
1144 FindBar* find_bar = browser()->GetFindBarController()->find_bar();
1145 if (find_bar->HasGlobalFindPasteboard()) {
1146 EXPECT_EQ(FindTabHelper::FromWebContents(web_contents_1)->find_text(),
1147 WideToUTF16(L"given"));
1148 } else {
1149 EXPECT_EQ(FindTabHelper::FromWebContents(web_contents_1)->find_text(),
1150 WideToUTF16(L"text"));
1154 // This tests that whenever you close and reopen the Find bar, it should show
1155 // the last search entered in that tab. http://crbug.com/40121.
1156 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateSameTab) {
1157 // First we navigate to any page.
1158 GURL url = GetURL(kSimple);
1159 ui_test_utils::NavigateToURL(browser(), url);
1161 // Search for the word "page".
1162 int ordinal = 0;
1163 WebContents* web_contents =
1164 browser()->tab_strip_model()->GetActiveWebContents();
1165 EXPECT_EQ(1, FindInPageWchar(web_contents, L"page",
1166 kFwd, kIgnoreCase, &ordinal));
1168 // Open the Find box.
1169 EnsureFindBoxOpen();
1171 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1172 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText());
1174 // Close the Find box.
1175 browser()->GetFindBarController()->EndFindSession(
1176 FindBarController::kKeepSelectionOnPage,
1177 FindBarController::kKeepResultsInFindBox);
1179 // Open the Find box again.
1180 EnsureFindBoxOpen();
1182 // After the Find box has been reopened, it should have been prepopulated with
1183 // the word "page" again.
1184 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1185 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText());
1188 // This tests that whenever you open Find in a new tab it should prepopulate
1189 // with a previous search term (in any tab), if a search has not been issued in
1190 // this tab before.
1191 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateInNewTab) {
1192 // First we navigate to any page.
1193 GURL url = GetURL(kSimple);
1194 ui_test_utils::NavigateToURL(browser(), url);
1196 // Search for the word "page".
1197 int ordinal = 0;
1198 WebContents* web_contents_1 =
1199 browser()->tab_strip_model()->GetActiveWebContents();
1200 EXPECT_EQ(1, FindInPageWchar(web_contents_1, L"page",
1201 kFwd, kIgnoreCase, &ordinal));
1202 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText());
1204 // Now create a second tab and load the same page.
1205 chrome::AddSelectedTabWithURL(browser(), url, content::PAGE_TRANSITION_TYPED);
1206 WebContents* web_contents_2 =
1207 browser()->tab_strip_model()->GetActiveWebContents();
1208 EXPECT_NE(web_contents_1, web_contents_2);
1210 // Open the Find box.
1211 EnsureFindBoxOpen();
1213 // The new tab should have "page" prepopulated, since that was the last search
1214 // in the first tab.
1215 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1216 // But it should not seem like a search has been issued.
1217 EXPECT_EQ(base::string16(), GetMatchCountText());
1220 // This makes sure that we can search for A in tabA, then for B in tabB and
1221 // when we come back to tabA we should still see A (because that was the last
1222 // search in that tab).
1223 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulatePreserveLast) {
1224 FindBar* find_bar = browser()->GetFindBarController()->find_bar();
1225 if (find_bar->HasGlobalFindPasteboard())
1226 return;
1228 // First we navigate to any page.
1229 GURL url = GetURL(kSimple);
1230 ui_test_utils::NavigateToURL(browser(), url);
1232 // Search for the word "page".
1233 int ordinal = 0;
1234 WebContents* web_contents_1 =
1235 browser()->tab_strip_model()->GetActiveWebContents();
1236 EXPECT_EQ(1, FindInPageWchar(web_contents_1, L"page",
1237 kFwd, kIgnoreCase, &ordinal));
1239 // Open the Find box.
1240 EnsureFindBoxOpen();
1242 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1244 // Close the Find box.
1245 browser()->GetFindBarController()->EndFindSession(
1246 FindBarController::kKeepSelectionOnPage,
1247 FindBarController::kKeepResultsInFindBox);
1249 // Now create a second tab and load the same page.
1250 chrome::AddTabAt(browser(), GURL(), -1, true);
1251 ui_test_utils::NavigateToURL(browser(), url);
1252 WebContents* web_contents_2 =
1253 browser()->tab_strip_model()->GetActiveWebContents();
1254 EXPECT_NE(web_contents_1, web_contents_2);
1256 // Search for the word "text".
1257 FindInPageWchar(web_contents_2, L"text", kFwd, kIgnoreCase, &ordinal);
1259 // Go back to the first tab and make sure we have NOT switched the prepopulate
1260 // text to "text".
1261 browser()->tab_strip_model()->ActivateTabAt(0, false);
1263 // Open the Find box.
1264 EnsureFindBoxOpen();
1266 // After the Find box has been reopened, it should have been prepopulated with
1267 // the word "page" again, since that was the last search in that tab.
1268 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1270 // Close the Find box.
1271 browser()->GetFindBarController()->EndFindSession(
1272 FindBarController::kKeepSelectionOnPage,
1273 FindBarController::kKeepResultsInFindBox);
1275 // Re-open the Find box.
1276 // This is a special case: previous search in WebContents used to get cleared
1277 // if you opened and closed the FindBox, which would cause the global
1278 // prepopulate value to show instead of last search in this tab.
1279 EnsureFindBoxOpen();
1281 // After the Find box has been reopened, it should have been prepopulated with
1282 // the word "page" again, since that was the last search in that tab.
1283 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1286 // TODO(rohitrao): Searching in incognito tabs does not work in browser tests in
1287 // Linux views. Investigate and fix. http://crbug.com/40948
1288 #if defined(OS_LINUX) && defined(TOOLKIT_VIEWS)
1289 #define MAYBE_NoIncognitoPrepopulate DISABLED_NoIncognitoPrepopulate
1290 #else
1291 #define MAYBE_NoIncognitoPrepopulate NoIncognitoPrepopulate
1292 #endif
1294 // This tests that search terms entered into an incognito find bar are not used
1295 // as prepopulate terms for non-incognito windows.
1296 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, MAYBE_NoIncognitoPrepopulate) {
1297 FindBar* find_bar = browser()->GetFindBarController()->find_bar();
1298 if (find_bar->HasGlobalFindPasteboard())
1299 return;
1301 // First we navigate to the "simple" test page.
1302 GURL url = GetURL(kSimple);
1303 ui_test_utils::NavigateToURL(browser(), url);
1305 // Search for the word "page" in the normal browser tab.
1306 int ordinal = 0;
1307 WebContents* web_contents_1 =
1308 browser()->tab_strip_model()->GetActiveWebContents();
1309 EXPECT_EQ(1, FindInPageWchar(web_contents_1, L"page",
1310 kFwd, kIgnoreCase, &ordinal));
1312 // Open the Find box.
1313 EnsureFindBoxOpenForBrowser(browser());
1314 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser()));
1316 // Close the Find box.
1317 browser()->GetFindBarController()->EndFindSession(
1318 FindBarController::kKeepSelectionOnPage,
1319 FindBarController::kKeepResultsInFindBox);
1321 // Open a new incognito window and navigate to the same page.
1322 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile();
1323 Browser* incognito_browser =
1324 new Browser(Browser::CreateParams(incognito_profile,
1325 browser()->host_desktop_type()));
1326 content::WindowedNotificationObserver observer(
1327 content::NOTIFICATION_LOAD_STOP,
1328 content::NotificationService::AllSources());
1329 chrome::AddSelectedTabWithURL(incognito_browser, url,
1330 content::PAGE_TRANSITION_AUTO_TOPLEVEL);
1331 observer.Wait();
1332 incognito_browser->window()->Show();
1334 // Open the find box and make sure that it is prepopulated with "page".
1335 EnsureFindBoxOpenForBrowser(incognito_browser);
1336 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(incognito_browser));
1338 // Search for the word "text" in the incognito tab.
1339 WebContents* incognito_tab =
1340 incognito_browser->tab_strip_model()->GetActiveWebContents();
1341 EXPECT_EQ(1, FindInPageWchar(incognito_tab, L"text",
1342 kFwd, kIgnoreCase, &ordinal));
1343 EXPECT_EQ(ASCIIToUTF16("text"), GetFindBarTextForBrowser(incognito_browser));
1345 // Close the Find box.
1346 incognito_browser->GetFindBarController()->EndFindSession(
1347 FindBarController::kKeepSelectionOnPage,
1348 FindBarController::kKeepResultsInFindBox);
1350 // Now open a new tab in the original (non-incognito) browser.
1351 chrome::AddSelectedTabWithURL(browser(), url, content::PAGE_TRANSITION_TYPED);
1352 WebContents* web_contents_2 =
1353 browser()->tab_strip_model()->GetActiveWebContents();
1354 EXPECT_NE(web_contents_1, web_contents_2);
1356 // Open the Find box and make sure it is prepopulated with the search term
1357 // from the original browser, not the search term from the incognito window.
1358 EnsureFindBoxOpenForBrowser(browser());
1359 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser()));
1362 // This makes sure that dismissing the find bar with kActivateSelection works.
1363 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, ActivateLinkNavigatesPage) {
1364 // First we navigate to our test content.
1365 GURL url = GetURL(kLinkPage);
1366 ui_test_utils::NavigateToURL(browser(), url);
1368 WebContents* web_contents =
1369 browser()->tab_strip_model()->GetActiveWebContents();
1370 FindTabHelper* find_tab_helper =
1371 FindTabHelper::FromWebContents(web_contents);
1373 int ordinal = 0;
1374 FindInPageWchar(web_contents, L"link", kFwd, kIgnoreCase, &ordinal);
1375 EXPECT_EQ(ordinal, 1);
1377 // End the find session, click on the link.
1378 content::WindowedNotificationObserver observer(
1379 content::NOTIFICATION_LOAD_STOP,
1380 content::Source<NavigationController>(&web_contents->GetController()));
1381 find_tab_helper->StopFinding(FindBarController::kActivateSelectionOnPage);
1382 observer.Wait();
1385 // Tests that FindBar fits within a narrow browser window.
1386 // Flaky on Linux/GTK: http://crbug.com/136443.
1387 #if defined(TOOLKIT_GTK)
1388 #define MAYBE_FitWindow DISABLED_FitWindow
1389 #else
1390 #define MAYBE_FitWindow FitWindow
1391 #endif
1392 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, MAYBE_FitWindow) {
1393 Browser::CreateParams params(Browser::TYPE_POPUP, browser()->profile(),
1394 browser()->host_desktop_type());
1395 params.initial_bounds = gfx::Rect(0, 0, 250, 500);
1396 Browser* popup = new Browser(params);
1397 content::WindowedNotificationObserver observer(
1398 content::NOTIFICATION_LOAD_STOP,
1399 content::NotificationService::AllSources());
1400 chrome::AddSelectedTabWithURL(popup, GURL(content::kAboutBlankURL),
1401 content::PAGE_TRANSITION_LINK);
1402 // Wait for the page to finish loading.
1403 observer.Wait();
1404 popup->window()->Show();
1406 // On GTK, bounds change is asynchronous.
1407 base::MessageLoop::current()->RunUntilIdle();
1409 EnsureFindBoxOpenForBrowser(popup);
1411 // GTK adjusts FindBar size asynchronously.
1412 base::MessageLoop::current()->RunUntilIdle();
1414 ASSERT_LE(GetFindBarWidthForBrowser(popup),
1415 popup->window()->GetBounds().width());
1418 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
1419 FindMovesOnTabClose_Issue1343052) {
1420 EnsureFindBoxOpen();
1421 content::RunAllPendingInMessageLoop(); // Needed on Linux.
1423 gfx::Point position;
1424 EXPECT_TRUE(GetFindBarWindowInfo(&position, NULL));
1426 // Open another tab.
1427 GURL url = GetURL(kSimple);
1428 ui_test_utils::NavigateToURLWithDisposition(
1429 browser(), url, NEW_FOREGROUND_TAB,
1430 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1432 // Close it.
1433 chrome::CloseTab(browser());
1435 // See if the Find window has moved.
1436 gfx::Point position2;
1437 EXPECT_TRUE(GetFindBarWindowInfo(&position2, NULL));
1438 EXPECT_EQ(position, position2);
1440 // Toggle the bookmark bar state. Note that this starts an animation, and
1441 // there isn't a good way other than looping and polling to see when it's
1442 // done. So instead we change the state and open a new tab, since the new tab
1443 // animation doesn't happen on tab change.
1444 chrome::ToggleBookmarkBar(browser());
1446 ui_test_utils::NavigateToURLWithDisposition(
1447 browser(), url, NEW_FOREGROUND_TAB,
1448 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1450 EnsureFindBoxOpen();
1451 content::RunAllPendingInMessageLoop(); // Needed on Linux.
1452 EXPECT_TRUE(GetFindBarWindowInfo(&position, NULL));
1454 ui_test_utils::NavigateToURLWithDisposition(
1455 browser(), url, NEW_FOREGROUND_TAB,
1456 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1457 chrome::CloseTab(browser());
1458 EXPECT_TRUE(GetFindBarWindowInfo(&position2, NULL));
1459 EXPECT_EQ(position, position2);
1462 // Verify that if there's a global pasteboard (for example on Mac) then doing
1463 // a search on one tab will clear the matches label on the other tabs.
1464 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
1465 GlobalPasteBoardClearMatches) {
1466 FindBar* find_bar = browser()->GetFindBarController()->find_bar();
1467 if (!find_bar->HasGlobalFindPasteboard())
1468 return;
1470 // First we navigate to any page.
1471 GURL url = GetURL(kSimple);
1472 ui_test_utils::NavigateToURL(browser(), url);
1474 // Change the match count on the first tab to "1 of 1".
1475 int ordinal = 0;
1476 WebContents* web_contents_1 =
1477 browser()->tab_strip_model()->GetActiveWebContents();
1478 EXPECT_EQ(1, FindInPageWchar(web_contents_1, L"page",
1479 kFwd, kIgnoreCase, &ordinal));
1480 EnsureFindBoxOpen();
1481 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText());
1483 // Next, do a search in a second tab.
1484 chrome::AddTabAt(browser(), GURL(), -1, true);
1485 ui_test_utils::NavigateToURL(browser(), url);
1486 WebContents* web_contents_2 =
1487 browser()->tab_strip_model()->GetActiveWebContents();
1488 FindInPageWchar(web_contents_2, L"text", kFwd, kIgnoreCase, &ordinal);
1489 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText());
1491 // Go back to the first tab and verify that the match text is cleared.
1492 // text to "text".
1493 browser()->tab_strip_model()->ActivateTabAt(0, false);
1494 EXPECT_EQ(ASCIIToUTF16(""), GetMatchCountText());
1497 // Verify that Incognito window doesn't propagate find string to other widows.
1498 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, GlobalPasteboardIncognito) {
1499 Browser* browser_incognito = CreateIncognitoBrowser();
1500 WebContents* web_contents_1 =
1501 browser()->tab_strip_model()->GetActiveWebContents();
1502 FindInPageWchar(web_contents_1, L"page", kFwd, kIgnoreCase, NULL);
1503 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1504 WebContents* web_contents_2 =
1505 browser_incognito->tab_strip_model()->GetActiveWebContents();
1506 FindInPageWchar(web_contents_2, L"Incognito", kFwd, kIgnoreCase, NULL);
1507 EXPECT_EQ(ASCIIToUTF16("Incognito"),
1508 GetFindBarTextForBrowser(browser_incognito));
1509 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
1512 // Find text in regular window, find different text in incognito, send
1513 // IDC_FIND_NEXT to incognito. It should search for the second phrase.
1514 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, IncognitoFindNextSecret) {
1515 WebContents* web_contents =
1516 browser()->tab_strip_model()->GetActiveWebContents();
1517 // On Mac this updates the find pboard.
1518 FindInPageWchar(web_contents, L"bar", kFwd, kIgnoreCase, NULL);
1520 Browser* browser_incognito = CreateIncognitoBrowser();
1521 ui_test_utils::NavigateToURL(browser_incognito,
1522 GURL("data:text/plain,barfoofoo"));
1523 WebContents* web_contents_incognito =
1524 browser_incognito->tab_strip_model()->GetActiveWebContents();
1525 FindInPageWchar(web_contents_incognito, L"foo", true, kIgnoreCase, NULL);
1526 EXPECT_EQ(ASCIIToUTF16("foo"),
1527 GetFindBarTextForBrowser(browser_incognito));
1528 EXPECT_EQ(ASCIIToUTF16("1 of 2"),
1529 GetFindBarMatchCountTextForBrowser(browser_incognito));
1531 // Close the find bar.
1532 FindTabHelper* find_tab_helper =
1533 FindTabHelper::FromWebContents(web_contents_incognito);
1534 find_tab_helper->StopFinding(FindBarController::kActivateSelectionOnPage);
1536 // Cmd + G triggers IDC_FIND_NEXT command. Thus we test FindInPage()
1537 // method from browser_commands.cc. FindInPageWchar() bypasses it.
1538 EXPECT_TRUE(chrome::ExecuteCommand(browser_incognito, IDC_FIND_NEXT));
1539 ui_test_utils::FindInPageNotificationObserver observer(
1540 web_contents_incognito);
1541 observer.Wait();
1542 EXPECT_EQ(ASCIIToUTF16("foo"),
1543 GetFindBarTextForBrowser(browser_incognito));
1544 EXPECT_EQ(ASCIIToUTF16("2 of 2"),
1545 GetFindBarMatchCountTextForBrowser(browser_incognito));
1548 // Find text in regular window, send IDC_FIND_NEXT to incognito. It should
1549 // search for the first phrase.
1550 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, IncognitoFindNextShared) {
1551 WebContents* web_contents =
1552 browser()->tab_strip_model()->GetActiveWebContents();
1553 // On Mac this updates the find pboard.
1554 FindInPageWchar(web_contents, L"bar", kFwd, kIgnoreCase, NULL);
1556 Browser* browser_incognito = CreateIncognitoBrowser();
1557 ui_test_utils::NavigateToURL(browser_incognito,
1558 GURL("data:text/plain,bar"));
1560 EXPECT_TRUE(chrome::ExecuteCommand(browser_incognito, IDC_FIND_NEXT));
1561 WebContents* web_contents_incognito =
1562 browser_incognito->tab_strip_model()->GetActiveWebContents();
1563 ui_test_utils::FindInPageNotificationObserver observer(
1564 web_contents_incognito);
1565 observer.Wait();
1566 EXPECT_EQ(ASCIIToUTF16("bar"),
1567 GetFindBarTextForBrowser(browser_incognito));
1570 #if defined(OS_WIN)
1572 BOOL CALLBACK EnumerateChildren(HWND hwnd, LPARAM l_param) {
1573 HWND* child = reinterpret_cast<HWND*>(l_param);
1574 *child = hwnd;
1575 // The first child window is the plugin, then its children. So stop
1576 // enumerating after the first callback.
1577 return FALSE;
1580 // Ensure that the find bar is always over a windowed NPAPI plugin.
1581 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, WindowedNPAPIPluginHidden) {
1582 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPluginsAlwaysAuthorize,
1583 true);
1585 // First load the page and wait for the NPAPI plugin's window to display.
1586 base::string16 expected_title(ASCIIToUTF16("ready"));
1587 content::WebContents* tab =
1588 browser()->tab_strip_model()->GetActiveWebContents();
1589 content::TitleWatcher title_watcher(tab, expected_title);
1591 GURL url = ui_test_utils::GetTestUrl(
1592 base::FilePath().AppendASCII("printing"),
1593 base::FilePath().AppendASCII("npapi_plugin.html"));
1594 ui_test_utils::NavigateToURL(browser(), url);
1596 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
1598 // Now get the region of the plugin before the find bar is shown.
1599 HWND hwnd = tab->GetNativeView()->GetHost()->GetAcceleratedWidget();
1600 HWND child = NULL;
1601 EnumChildWindows(hwnd, EnumerateChildren,reinterpret_cast<LPARAM>(&child));
1603 RECT region_before, region_after;
1604 int result = GetWindowRgnBox(child, &region_before);
1605 ASSERT_EQ(result, SIMPLEREGION);
1607 // Create a new tab and open the find bar there.
1608 chrome::NewTab(browser());
1609 browser()->tab_strip_model()->ActivateTabAt(1, true);
1610 ui_test_utils::NavigateToURL(browser(), GURL(content::kAboutBlankURL));
1612 EnsureFindBoxOpen();
1614 // Now switch back to the original tab with the plugin and show the find bar.
1615 browser()->tab_strip_model()->ActivateTabAt(0, true);
1616 EnsureFindBoxOpen();
1618 result = GetWindowRgnBox(child, &region_after);
1619 if (result == NULLREGION) {
1620 // Depending on the browser window size, the plugin could be full covered.
1621 return;
1624 if (result == COMPLEXREGION) {
1625 // Complex region, by definition not equal to the initial region.
1626 return;
1629 ASSERT_EQ(result, SIMPLEREGION);
1630 bool rects_equal =
1631 region_before.left == region_after.left &&
1632 region_before.top == region_after.top &&
1633 region_before.right == region_after.right &&
1634 region_before.bottom == region_after.bottom;
1635 ASSERT_FALSE(rects_equal);
1638 #endif