Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: chrome/browser/ui/find_bar/find_bar_host_browsertest.cc

Issue 12314090: Add utf_string_conversions to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/browser.cc ('k') | chrome/browser/ui/omnibox/omnibox_view_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/string16.h" 7 #include "base/string16.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/common/cancelable_request.h" 10 #include "chrome/browser/common/cancelable_request.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } 131 }
132 132
133 // Platform independent FindInPage that takes |const wchar_t*| 133 // Platform independent FindInPage that takes |const wchar_t*|
134 // as an input. 134 // as an input.
135 int FindInPageWchar(WebContents* web_contents, 135 int FindInPageWchar(WebContents* web_contents,
136 const wchar_t* search_str, 136 const wchar_t* search_str,
137 bool forward, 137 bool forward,
138 bool case_sensitive, 138 bool case_sensitive,
139 int* ordinal) { 139 int* ordinal) {
140 return ui_test_utils::FindInPage( 140 return ui_test_utils::FindInPage(
141 web_contents, WideToUTF16(std::wstring(search_str)), 141 web_contents, base::WideToUTF16(std::wstring(search_str)),
142 forward, case_sensitive, ordinal, NULL); 142 forward, case_sensitive, ordinal, NULL);
143 } 143 }
144 144
145 // Calls FindInPageWchar till the find box's x position != |start_x_position|. 145 // Calls FindInPageWchar till the find box's x position != |start_x_position|.
146 // Return |start_x_position| if the find box has not moved after iterating 146 // Return |start_x_position| if the find box has not moved after iterating
147 // through all matches of |search_str|. 147 // through all matches of |search_str|.
148 int FindInPageTillBoxMoves(WebContents* web_contents, 148 int FindInPageTillBoxMoves(WebContents* web_contents,
149 int start_x_position, 149 int start_x_position,
150 const wchar_t* search_str, 150 const wchar_t* search_str,
151 int expected_matches) { 151 int expected_matches) {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 313
314 GURL download_url = ui_test_utils::GetTestUrl( 314 GURL download_url = ui_test_utils::GetTestUrl(
315 base::FilePath().AppendASCII("downloads"), 315 base::FilePath().AppendASCII("downloads"),
316 base::FilePath().AppendASCII("a_zip_file.zip")); 316 base::FilePath().AppendASCII("a_zip_file.zip"));
317 ui_test_utils::DownloadURL(browser(), download_url); 317 ui_test_utils::DownloadURL(browser(), download_url);
318 318
319 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL)); 319 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL));
320 FlushHistoryService(); 320 FlushHistoryService();
321 EXPECT_EQ(1, 321 EXPECT_EQ(1,
322 FindInPageWchar(web_contents, 322 FindInPageWchar(web_contents,
323 ASCIIToWide(download_url.spec()).c_str(), kFwd, 323 base::ASCIIToWide(download_url.spec()).c_str(),
324 kIgnoreCase, NULL)); 324 kFwd, kIgnoreCase, NULL));
325 } 325 }
326 326
327 // Verify search selection coordinates. The data file used is set-up such that 327 // Verify search selection coordinates. The data file used is set-up such that
328 // the text occurs on the same line, and we verify their positions by verifying 328 // the text occurs on the same line, and we verify their positions by verifying
329 // their relative positions. 329 // their relative positions.
330 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageSpecialURLs) { 330 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageSpecialURLs) {
331 std::wstring search_string(L"\u5728\u897f\u660c\u536b\u661f\u53d1"); 331 std::wstring search_string(L"\u5728\u897f\u660c\u536b\u661f\u53d1");
332 gfx::Rect first, second, first_reverse; 332 gfx::Rect first, second, first_reverse;
333 WebContents* web_contents = 333 WebContents* web_contents =
334 browser()->tab_strip_model()->GetActiveWebContents(); 334 browser()->tab_strip_model()->GetActiveWebContents();
335 ui_test_utils::NavigateToURL(browser(), GetURL("specialchar.html")); 335 ui_test_utils::NavigateToURL(browser(), GetURL("specialchar.html"));
336 ui_test_utils::FindInPage(web_contents, WideToUTF16(search_string), 336 ui_test_utils::FindInPage(web_contents, base::WideToUTF16(search_string),
337 kFwd, kIgnoreCase, NULL, &first); 337 kFwd, kIgnoreCase, NULL, &first);
338 ui_test_utils::FindInPage(web_contents, WideToUTF16(search_string), 338 ui_test_utils::FindInPage(web_contents, base::WideToUTF16(search_string),
339 kFwd, kIgnoreCase, NULL, &second); 339 kFwd, kIgnoreCase, NULL, &second);
340 340
341 // We have search occurrence in the same row, so top-bottom coordinates should 341 // We have search occurrence in the same row, so top-bottom coordinates should
342 // be the same even for second search. 342 // be the same even for second search.
343 ASSERT_EQ(first.y(), second.y()); 343 ASSERT_EQ(first.y(), second.y());
344 ASSERT_EQ(first.bottom(), second.bottom()); 344 ASSERT_EQ(first.bottom(), second.bottom());
345 ASSERT_LT(first.x(), second.x()); 345 ASSERT_LT(first.x(), second.x());
346 ASSERT_LT(first.right(), second.right()); 346 ASSERT_LT(first.right(), second.right());
347 347
348 ui_test_utils::FindInPage( 348 ui_test_utils::FindInPage(
349 web_contents, WideToUTF16(search_string), kBack, kIgnoreCase, NULL, 349 web_contents, base::WideToUTF16(search_string), kBack, kIgnoreCase, NULL,
350 &first_reverse); 350 &first_reverse);
351 // We find next and we go back so find coordinates should be the same as 351 // We find next and we go back so find coordinates should be the same as
352 // previous ones. 352 // previous ones.
353 ASSERT_EQ(first, first_reverse); 353 ASSERT_EQ(first, first_reverse);
354 } 354 }
355 355
356 // Verifies that comments and meta data are not searchable. 356 // Verifies that comments and meta data are not searchable.
357 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, 357 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
358 CommentsAndMetaDataNotSearchable) { 358 CommentsAndMetaDataNotSearchable) {
359 WebContents* web_contents = 359 WebContents* web_contents =
360 browser()->tab_strip_model()->GetActiveWebContents(); 360 browser()->tab_strip_model()->GetActiveWebContents();
361 ui_test_utils::NavigateToURL(browser(), GetURL("specialchar.html")); 361 ui_test_utils::NavigateToURL(browser(), GetURL("specialchar.html"));
362 362
363 std::wstring search_string = 363 std::wstring search_string =
364 L"\u4e2d\u65b0\u793e\u8bb0\u8005\u5b8b\u5409\u6cb3\u6444\u4e2d\u65b0\u7f51 "; 364 L"\u4e2d\u65b0\u793e\u8bb0\u8005\u5b8b"
365 L"\u5409\u6cb3\u6444\u4e2d\u65b0\u7f51";
365 EXPECT_EQ(0, ui_test_utils::FindInPage( 366 EXPECT_EQ(0, ui_test_utils::FindInPage(
366 web_contents, WideToUTF16(search_string), kFwd, kIgnoreCase, NULL, NULL)); 367 web_contents, base::WideToUTF16(search_string), kFwd, kIgnoreCase, NULL,
368 NULL));
367 } 369 }
368 370
369 // Verifies that span and lists are searchable. 371 // Verifies that span and lists are searchable.
370 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, SpanAndListsSearchable) { 372 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, SpanAndListsSearchable) {
371 WebContents* web_contents = 373 WebContents* web_contents =
372 browser()->tab_strip_model()->GetActiveWebContents(); 374 browser()->tab_strip_model()->GetActiveWebContents();
373 ui_test_utils::NavigateToURL(browser(), GetURL("FindRandomTests.html")); 375 ui_test_utils::NavigateToURL(browser(), GetURL("FindRandomTests.html"));
374 376
375 std::wstring search_string = L"has light blue eyes and my father has dark"; 377 std::wstring search_string = L"has light blue eyes and my father has dark";
376 EXPECT_EQ(1, ui_test_utils::FindInPage( 378 EXPECT_EQ(1, ui_test_utils::FindInPage(
377 web_contents, WideToUTF16(search_string), kFwd, kIgnoreCase, NULL, NULL)); 379 web_contents, base::WideToUTF16(search_string), kFwd, kIgnoreCase, NULL,
380 NULL));
378 381
379 search_string = L"Google\nApple\nandroid"; 382 search_string = L"Google\nApple\nandroid";
380 EXPECT_EQ(1, ui_test_utils::FindInPage( 383 EXPECT_EQ(1, ui_test_utils::FindInPage(
381 web_contents, WideToUTF16(search_string), kFwd, kIgnoreCase, NULL, NULL)); 384 web_contents, base::WideToUTF16(search_string), kFwd, kIgnoreCase, NULL,
385 NULL));
382 } 386 }
383 387
384 // Find in a very large page. 388 // Find in a very large page.
385 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, LargePage) { 389 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, LargePage) {
386 WebContents* web_contents = 390 WebContents* web_contents =
387 browser()->tab_strip_model()->GetActiveWebContents(); 391 browser()->tab_strip_model()->GetActiveWebContents();
388 ui_test_utils::NavigateToURL(browser(), GetURL("largepage.html")); 392 ui_test_utils::NavigateToURL(browser(), GetURL("largepage.html"));
389 393
390 std::wstring search_string = L"daughter of Prince"; 394 std::wstring search_string = L"daughter of Prince";
391 EXPECT_EQ(373, 395 EXPECT_EQ(373,
392 FindInPageWchar(web_contents, search_string.c_str(), 396 FindInPageWchar(web_contents, search_string.c_str(),
393 kFwd, kIgnoreCase, NULL)); 397 kFwd, kIgnoreCase, NULL));
394 } 398 }
395 399
396 // Find a very long string in a large page. 400 // Find a very long string in a large page.
397 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindLongString) { 401 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindLongString) {
398 WebContents* web_contents = 402 WebContents* web_contents =
399 browser()->tab_strip_model()->GetActiveWebContents(); 403 browser()->tab_strip_model()->GetActiveWebContents();
400 ui_test_utils::NavigateToURL(browser(), GetURL("largepage.html")); 404 ui_test_utils::NavigateToURL(browser(), GetURL("largepage.html"));
401 405
402 base::FilePath path = ui_test_utils::GetTestFilePath( 406 base::FilePath path = ui_test_utils::GetTestFilePath(
403 base::FilePath().AppendASCII("find_in_page"), 407 base::FilePath().AppendASCII("find_in_page"),
404 base::FilePath().AppendASCII("LongFind.txt")); 408 base::FilePath().AppendASCII("LongFind.txt"));
405 std::string query; 409 std::string query;
406 file_util::ReadFileToString(path, &query); 410 file_util::ReadFileToString(path, &query);
407 std::wstring search_string = UTF8ToWide(query); 411 std::wstring search_string = base::UTF8ToWide(query);
408 EXPECT_EQ(1, 412 EXPECT_EQ(1,
409 FindInPageWchar(web_contents, search_string.c_str(), 413 FindInPageWchar(web_contents, search_string.c_str(),
410 kFwd, kIgnoreCase, NULL)); 414 kFwd, kIgnoreCase, NULL));
411 } 415 }
412 416
413 // Find a big font string in a page. 417 // Find a big font string in a page.
414 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, BigString) { 418 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, BigString) {
415 WebContents* web_contents = 419 WebContents* web_contents =
416 browser()->tab_strip_model()->GetActiveWebContents(); 420 browser()->tab_strip_model()->GetActiveWebContents();
417 ui_test_utils::NavigateToURL(browser(), GetURL("BigText.html")); 421 ui_test_utils::NavigateToURL(browser(), GetURL("BigText.html"));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 WebContents* web_contents = 464 WebContents* web_contents =
461 browser()->tab_strip_model()->GetActiveWebContents(); 465 browser()->tab_strip_model()->GetActiveWebContents();
462 466
463 base::FilePath path = ui_test_utils::GetTestFilePath( 467 base::FilePath path = ui_test_utils::GetTestFilePath(
464 base::FilePath().AppendASCII("find_in_page"), 468 base::FilePath().AppendASCII("find_in_page"),
465 base::FilePath().AppendASCII("find_test.txt")); 469 base::FilePath().AppendASCII("find_test.txt"));
466 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(path)); 470 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(path));
467 471
468 std::string query; 472 std::string query;
469 file_util::ReadFileToString(path, &query); 473 file_util::ReadFileToString(path, &query);
470 std::wstring search_string = UTF8ToWide(query); 474 std::wstring search_string = base::UTF8ToWide(query);
471 EXPECT_EQ(1, 475 EXPECT_EQ(1,
472 FindInPageWchar(web_contents, search_string.c_str(), 476 FindInPageWchar(web_contents, search_string.c_str(),
473 false, false, NULL)); 477 false, false, NULL));
474 } 478 }
475 479
476 // Specifying a prototype so that we can add the WARN_UNUSED_RESULT attribute. 480 // Specifying a prototype so that we can add the WARN_UNUSED_RESULT attribute.
477 bool FocusedOnPage(WebContents* web_contents, std::string* result) 481 bool FocusedOnPage(WebContents* web_contents, std::string* result)
478 WARN_UNUSED_RESULT; 482 WARN_UNUSED_RESULT;
479 483
480 bool FocusedOnPage(WebContents* web_contents, std::string* result) { 484 bool FocusedOnPage(WebContents* web_contents, std::string* result) {
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 1187
1184 // Switch back to first tab. 1188 // Switch back to first tab.
1185 browser()->tab_strip_model()->ActivateTabAt(0, false); 1189 browser()->tab_strip_model()->ActivateTabAt(0, false);
1186 browser()->GetFindBarController()->EndFindSession( 1190 browser()->GetFindBarController()->EndFindSession(
1187 FindBarController::kKeepSelectionOnPage, 1191 FindBarController::kKeepSelectionOnPage,
1188 FindBarController::kKeepResultsInFindBox); 1192 FindBarController::kKeepResultsInFindBox);
1189 // Simulate F3. 1193 // Simulate F3.
1190 ui_test_utils::FindInPage(web_contents_1, string16(), 1194 ui_test_utils::FindInPage(web_contents_1, string16(),
1191 kFwd, kIgnoreCase, &ordinal, NULL); 1195 kFwd, kIgnoreCase, &ordinal, NULL);
1192 EXPECT_EQ(FindTabHelper::FromWebContents(web_contents_1)->find_text(), 1196 EXPECT_EQ(FindTabHelper::FromWebContents(web_contents_1)->find_text(),
1193 WideToUTF16(L"text")); 1197 base::WideToUTF16(L"text"));
1194 } 1198 }
1195 1199
1196 // This tests that whenever you close and reopen the Find bar, it should show 1200 // This tests that whenever you close and reopen the Find bar, it should show
1197 // the last search entered in that tab. http://crbug.com/40121. 1201 // the last search entered in that tab. http://crbug.com/40121.
1198 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateSameTab) { 1202 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateSameTab) {
1199 #if defined(OS_MACOSX) 1203 #if defined(OS_MACOSX)
1200 // FindInPage on Mac doesn't use prepopulated values. Search there is global. 1204 // FindInPage on Mac doesn't use prepopulated values. Search there is global.
1201 return; 1205 return;
1202 #endif 1206 #endif
1203 1207
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 content::RunAllPendingInMessageLoop(); // Needed on Linux. 1507 content::RunAllPendingInMessageLoop(); // Needed on Linux.
1504 EXPECT_TRUE(GetFindBarWindowInfo(&position, NULL)); 1508 EXPECT_TRUE(GetFindBarWindowInfo(&position, NULL));
1505 1509
1506 ui_test_utils::NavigateToURLWithDisposition( 1510 ui_test_utils::NavigateToURLWithDisposition(
1507 browser(), url, NEW_FOREGROUND_TAB, 1511 browser(), url, NEW_FOREGROUND_TAB,
1508 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 1512 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1509 chrome::CloseTab(browser()); 1513 chrome::CloseTab(browser());
1510 EXPECT_TRUE(GetFindBarWindowInfo(&position2, NULL)); 1514 EXPECT_TRUE(GetFindBarWindowInfo(&position2, NULL));
1511 EXPECT_EQ(position, position2); 1515 EXPECT_EQ(position, position2);
1512 } 1516 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser.cc ('k') | chrome/browser/ui/omnibox/omnibox_view_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698