| OLD | NEW |
| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/test/scoped_feature_list.h" | |
| 15 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 16 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
| 17 #include "chrome/browser/history/history_service_factory.h" | 16 #include "chrome/browser/history/history_service_factory.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_commands.h" | 19 #include "chrome/browser/ui/browser_commands.h" |
| 21 #include "chrome/browser/ui/browser_finder.h" | 20 #include "chrome/browser/ui/browser_finder.h" |
| 22 #include "chrome/browser/ui/browser_tabstrip.h" | 21 #include "chrome/browser/ui/browser_tabstrip.h" |
| 23 #include "chrome/browser/ui/browser_window.h" | 22 #include "chrome/browser/ui/browser_window.h" |
| 24 #include "chrome/browser/ui/chrome_pages.h" | 23 #include "chrome/browser/ui/chrome_pages.h" |
| 25 #include "chrome/browser/ui/find_bar/find_bar.h" | 24 #include "chrome/browser/ui/find_bar/find_bar.h" |
| 26 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 25 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
| 27 #include "chrome/browser/ui/find_bar/find_bar_host_unittest_util.h" | 26 #include "chrome/browser/ui/find_bar/find_bar_host_unittest_util.h" |
| 28 #include "chrome/browser/ui/find_bar/find_notification_details.h" | 27 #include "chrome/browser/ui/find_bar/find_notification_details.h" |
| 29 #include "chrome/browser/ui/find_bar/find_tab_helper.h" | 28 #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
| 30 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 29 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 31 #include "chrome/browser/ui/webui/md_history_ui.h" | 30 #include "chrome/browser/ui/webui/md_history_ui.h" |
| 32 #include "chrome/common/chrome_features.h" | |
| 33 #include "chrome/common/chrome_switches.h" | |
| 34 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
| 35 #include "chrome/test/base/find_in_page_observer.h" | 32 #include "chrome/test/base/find_in_page_observer.h" |
| 36 #include "chrome/test/base/in_process_browser_test.h" | 33 #include "chrome/test/base/in_process_browser_test.h" |
| 37 #include "chrome/test/base/ui_test_utils.h" | 34 #include "chrome/test/base/ui_test_utils.h" |
| 38 #include "components/history/core/browser/history_service.h" | 35 #include "components/history/core/browser/history_service.h" |
| 39 #include "components/prefs/pref_service.h" | 36 #include "components/prefs/pref_service.h" |
| 40 #include "content/public/browser/download_manager.h" | 37 #include "content/public/browser/download_manager.h" |
| 41 #include "content/public/browser/notification_service.h" | 38 #include "content/public/browser/notification_service.h" |
| 42 #include "content/public/browser/notification_types.h" | 39 #include "content/public/browser/notification_types.h" |
| 43 #include "content/public/browser/render_view_host.h" | 40 #include "content/public/browser/render_view_host.h" |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 constexpr char kRemoveFrameScript[] = | 343 constexpr char kRemoveFrameScript[] = |
| 347 "frame = document.getElementsByTagName(\"FRAME\")[0];\n" | 344 "frame = document.getElementsByTagName(\"FRAME\")[0];\n" |
| 348 "frame.parentElement.removeChild(frame);\n"; | 345 "frame.parentElement.removeChild(frame);\n"; |
| 349 ASSERT_TRUE(content::ExecuteScript(web_contents, kRemoveFrameScript)); | 346 ASSERT_TRUE(content::ExecuteScript(web_contents, kRemoveFrameScript)); |
| 350 | 347 |
| 351 ui_test_utils::NavigateToURL(browser(), GetURL("specialchar.html")); | 348 ui_test_utils::NavigateToURL(browser(), GetURL("specialchar.html")); |
| 352 | 349 |
| 353 EXPECT_EQ(1u, GetFindBarAudibleAlertsForBrowser(browser())); | 350 EXPECT_EQ(1u, GetFindBarAudibleAlertsForBrowser(browser())); |
| 354 } | 351 } |
| 355 | 352 |
| 356 // Verify search for text within special URLs such as chrome:history, | |
| 357 // chrome://downloads, data directory | |
| 358 #if defined(OS_MACOSX) || defined(OS_WIN) | |
| 359 // Disabled on Mac due to http://crbug.com/419987 | |
| 360 // Disabled on Win due to http://crbug.com/661013 | |
| 361 #define MAYBE_SearchWithinSpecialURL \ | |
| 362 DISABLED_SearchWithinSpecialURL | |
| 363 #else | |
| 364 #define MAYBE_SearchWithinSpecialURL \ | |
| 365 SearchWithinSpecialURL | |
| 366 #endif | |
| 367 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, MAYBE_SearchWithinSpecialURL) { | |
| 368 // TODO(tsergeant): Get this test working on MD History, which loads very | |
| 369 // asynchronously and causes this test to fail. | |
| 370 base::test::ScopedFeatureList scoped_feature_list; | |
| 371 scoped_feature_list.InitAndDisableFeature(features::kMaterialDesignHistory); | |
| 372 | |
| 373 WebContents* web_contents = | |
| 374 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 375 | |
| 376 base::FilePath data_dir = | |
| 377 ui_test_utils::GetTestFilePath(base::FilePath(), base::FilePath()); | |
| 378 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(data_dir)); | |
| 379 EXPECT_EQ(1, FindInPageASCII(web_contents, "downloads", | |
| 380 kFwd, kIgnoreCase, NULL)); | |
| 381 | |
| 382 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIHistoryURL)); | |
| 383 | |
| 384 // The history page does an async request to the history service and then | |
| 385 // updates the renderer. So we make a query as well, and by the time it comes | |
| 386 // back we know the data is on its way to the renderer. | |
| 387 FlushHistoryService(); | |
| 388 | |
| 389 base::string16 query(data_dir.LossyDisplayName()); | |
| 390 EXPECT_EQ(1, | |
| 391 ui_test_utils::FindInPage(web_contents, query, | |
| 392 kFwd, kIgnoreCase, NULL, NULL)); | |
| 393 | |
| 394 GURL download_url = ui_test_utils::GetTestUrl( | |
| 395 base::FilePath().AppendASCII("downloads"), | |
| 396 base::FilePath().AppendASCII("a_zip_file.zip")); | |
| 397 ui_test_utils::DownloadURL(browser(), download_url); | |
| 398 | |
| 399 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL)); | |
| 400 FlushHistoryService(); | |
| 401 ASSERT_TRUE(content::ExecuteScript(web_contents, "Polymer.dom.flush();")); | |
| 402 EXPECT_EQ(1, FindInPageASCII(web_contents, download_url.spec(), | |
| 403 kFwd, kIgnoreCase, NULL)); | |
| 404 } | |
| 405 | |
| 406 // Verify search selection coordinates. The data file used is set-up such that | 353 // Verify search selection coordinates. The data file used is set-up such that |
| 407 // the text occurs on the same line, and we verify their positions by verifying | 354 // the text occurs on the same line, and we verify their positions by verifying |
| 408 // their relative positions. | 355 // their relative positions. |
| 409 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageSpecialURLs) { | 356 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageSpecialURLs) { |
| 410 const std::wstring search_string(L"\u5728\u897f\u660c\u536b\u661f\u53d1"); | 357 const std::wstring search_string(L"\u5728\u897f\u660c\u536b\u661f\u53d1"); |
| 411 gfx::Rect first, second, first_reverse; | 358 gfx::Rect first, second, first_reverse; |
| 412 WebContents* web_contents = | 359 WebContents* web_contents = |
| 413 browser()->tab_strip_model()->GetActiveWebContents(); | 360 browser()->tab_strip_model()->GetActiveWebContents(); |
| 414 ui_test_utils::NavigateToURL(browser(), GetURL("specialchar.html")); | 361 ui_test_utils::NavigateToURL(browser(), GetURL("specialchar.html")); |
| 415 ui_test_utils::FindInPage(web_contents, WideToUTF16(search_string), | 362 ui_test_utils::FindInPage(web_contents, WideToUTF16(search_string), |
| (...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1620 | 1567 |
| 1621 EXPECT_TRUE(chrome::ExecuteCommand(browser_incognito, IDC_FIND_NEXT)); | 1568 EXPECT_TRUE(chrome::ExecuteCommand(browser_incognito, IDC_FIND_NEXT)); |
| 1622 WebContents* web_contents_incognito = | 1569 WebContents* web_contents_incognito = |
| 1623 browser_incognito->tab_strip_model()->GetActiveWebContents(); | 1570 browser_incognito->tab_strip_model()->GetActiveWebContents(); |
| 1624 ui_test_utils::FindInPageNotificationObserver observer( | 1571 ui_test_utils::FindInPageNotificationObserver observer( |
| 1625 web_contents_incognito); | 1572 web_contents_incognito); |
| 1626 observer.Wait(); | 1573 observer.Wait(); |
| 1627 EXPECT_EQ(ASCIIToUTF16("bar"), | 1574 EXPECT_EQ(ASCIIToUTF16("bar"), |
| 1628 GetFindBarTextForBrowser(browser_incognito)); | 1575 GetFindBarTextForBrowser(browser_incognito)); |
| 1629 } | 1576 } |
| OLD | NEW |