| 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 "base/process_util.h" | 5 #include "base/process_util.h" |
| 6 #include "base/string_util.h" | 6 #include "base/string_util.h" |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/browser_commands.h" | 9 #include "chrome/browser/ui/browser_commands.h" |
| 10 #include "chrome/browser/ui/browser_tabstrip.h" | 10 #include "chrome/browser/ui/browser_tabstrip.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 static const char kSimplePage[] = "files/find_in_page/simple.html"; | 36 static const char kSimplePage[] = "files/find_in_page/simple.html"; |
| 37 | 37 |
| 38 void Checkpoint(const char* message, const base::TimeTicks& start_time) { | 38 void Checkpoint(const char* message, const base::TimeTicks& start_time) { |
| 39 LOG(INFO) << message << " : " | 39 LOG(INFO) << message << " : " |
| 40 << (base::TimeTicks::Now() - start_time).InMilliseconds() | 40 << (base::TimeTicks::Now() - start_time).InMilliseconds() |
| 41 << " ms" << std::flush; | 41 << " ms" << std::flush; |
| 42 } | 42 } |
| 43 | 43 |
| 44 class FindInPageTest : public InProcessBrowserTest { | 44 class FindInPageTest : public InProcessBrowserTest { |
| 45 public: | 45 public: |
| 46 FindInPageTest() : | 46 FindInPageTest() { |
| 47 #if defined(USE_AURA) | |
| 48 location_bar_focus_view_id_(VIEW_ID_OMNIBOX) | |
| 49 #else | |
| 50 location_bar_focus_view_id_(VIEW_ID_LOCATION_BAR) | |
| 51 #endif | |
| 52 { | |
| 53 FindBarHost::disable_animations_during_testing_ = true; | 47 FindBarHost::disable_animations_during_testing_ = true; |
| 54 } | 48 } |
| 55 | 49 |
| 56 string16 GetFindBarText() { | 50 string16 GetFindBarText() { |
| 57 FindBarTesting* find_bar = | 51 FindBarTesting* find_bar = |
| 58 browser()->GetFindBarController()->find_bar()->GetFindBarTesting(); | 52 browser()->GetFindBarController()->find_bar()->GetFindBarTesting(); |
| 59 return find_bar->GetFindText(); | 53 return find_bar->GetFindText(); |
| 60 } | 54 } |
| 61 | 55 |
| 62 string16 GetFindBarSelectedText() { | 56 string16 GetFindBarSelectedText() { |
| 63 FindBarTesting* find_bar = | 57 FindBarTesting* find_bar = |
| 64 browser()->GetFindBarController()->find_bar()->GetFindBarTesting(); | 58 browser()->GetFindBarController()->find_bar()->GetFindBarTesting(); |
| 65 return find_bar->GetFindSelectedText(); | 59 return find_bar->GetFindSelectedText(); |
| 66 } | 60 } |
| 67 | 61 |
| 68 ViewID location_bar_focus_view_id_; | |
| 69 | |
| 70 private: | 62 private: |
| 71 DISALLOW_COPY_AND_ASSIGN(FindInPageTest); | 63 DISALLOW_COPY_AND_ASSIGN(FindInPageTest); |
| 72 }; | 64 }; |
| 73 | 65 |
| 74 } // namespace | 66 } // namespace |
| 75 | 67 |
| 76 // Fails often on Win, CrOS. http://crbug.com/145476, http://crbug.com/128724 | 68 // Fails often on Win, CrOS. http://crbug.com/145476, http://crbug.com/128724 |
| 77 #if defined(OS_WIN) || defined(OS_CHROMEOS) | 69 #if defined(OS_WIN) || defined(OS_CHROMEOS) |
| 78 #define MAYBE_CrashEscHandlers DISABLED_CrashEscHandlers | 70 #define MAYBE_CrashEscHandlers DISABLED_CrashEscHandlers |
| 79 #else | 71 #else |
| (...skipping 17 matching lines...) Expand all Loading... |
| 97 | 89 |
| 98 // Select tab A. | 90 // Select tab A. |
| 99 browser()->tab_strip_model()->ActivateTabAt(0, true); | 91 browser()->tab_strip_model()->ActivateTabAt(0, true); |
| 100 | 92 |
| 101 // Close tab B. | 93 // Close tab B. |
| 102 browser()->tab_strip_model()->CloseWebContentsAt(1, | 94 browser()->tab_strip_model()->CloseWebContentsAt(1, |
| 103 TabStripModel::CLOSE_NONE); | 95 TabStripModel::CLOSE_NONE); |
| 104 | 96 |
| 105 // Click on the location bar so that Find box loses focus. | 97 // Click on the location bar so that Find box loses focus. |
| 106 ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(), | 98 ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(), |
| 107 VIEW_ID_LOCATION_BAR)); | 99 VIEW_ID_OMNIBOX)); |
| 108 // Check the location bar is focused. | 100 // Check the location bar is focused. |
| 109 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), | 101 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
| 110 location_bar_focus_view_id_)); | |
| 111 | 102 |
| 112 // This used to crash until bug 1303709 was fixed. | 103 // This used to crash until bug 1303709 was fixed. |
| 113 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 104 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 114 browser(), ui::VKEY_ESCAPE, false, false, false, false)); | 105 browser(), ui::VKEY_ESCAPE, false, false, false, false)); |
| 115 } | 106 } |
| 116 | 107 |
| 117 // Fails to start the test server on ChromeOS: http://crbug.com/168974 | 108 // Fails to start the test server on ChromeOS: http://crbug.com/168974 |
| 118 #if defined(OS_CHROMEOS) | 109 #if defined(OS_CHROMEOS) |
| 119 #define MAYBE_FocusRestore DISABLED_FocusRestore | 110 #define MAYBE_FocusRestore DISABLED_FocusRestore |
| 120 #else | 111 #else |
| 121 #define MAYBE_FocusRestore FocusRestore | 112 #define MAYBE_FocusRestore FocusRestore |
| 122 #endif | 113 #endif |
| 123 IN_PROC_BROWSER_TEST_F(FindInPageTest, MAYBE_FocusRestore) { | 114 IN_PROC_BROWSER_TEST_F(FindInPageTest, MAYBE_FocusRestore) { |
| 124 ASSERT_TRUE(test_server()->Start()); | 115 ASSERT_TRUE(test_server()->Start()); |
| 125 | 116 |
| 126 GURL url = test_server()->GetURL("title1.html"); | 117 GURL url = test_server()->GetURL("title1.html"); |
| 127 ui_test_utils::NavigateToURL(browser(), url); | 118 ui_test_utils::NavigateToURL(browser(), url); |
| 128 | 119 |
| 129 // Focus the location bar, open and close the find-in-page, focus should | 120 // Focus the location bar, open and close the find-in-page, focus should |
| 130 // return to the location bar. | 121 // return to the location bar. |
| 131 chrome::FocusLocationBar(browser()); | 122 chrome::FocusLocationBar(browser()); |
| 132 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), | 123 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
| 133 location_bar_focus_view_id_)); | |
| 134 // Ensure the creation of the find bar controller. | 124 // Ensure the creation of the find bar controller. |
| 135 browser()->GetFindBarController()->Show(); | 125 browser()->GetFindBarController()->Show(); |
| 136 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), | 126 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| 137 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); | 127 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
| 138 browser()->GetFindBarController()->EndFindSession( | 128 browser()->GetFindBarController()->EndFindSession( |
| 139 FindBarController::kKeepSelectionOnPage, | 129 FindBarController::kKeepSelectionOnPage, |
| 140 FindBarController::kKeepResultsInFindBox); | 130 FindBarController::kKeepResultsInFindBox); |
| 141 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), | 131 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
| 142 location_bar_focus_view_id_)); | |
| 143 | 132 |
| 144 // Focus the location bar, find something on the page, close the find box, | 133 // Focus the location bar, find something on the page, close the find box, |
| 145 // focus should go to the page. | 134 // focus should go to the page. |
| 146 chrome::FocusLocationBar(browser()); | 135 chrome::FocusLocationBar(browser()); |
| 147 chrome::Find(browser()); | 136 chrome::Find(browser()); |
| 148 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), | 137 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| 149 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); | 138 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
| 150 ui_test_utils::FindInPage( | 139 ui_test_utils::FindInPage( |
| 151 browser()->tab_strip_model()->GetActiveWebContents(), | 140 browser()->tab_strip_model()->GetActiveWebContents(), |
| 152 ASCIIToUTF16("a"), true, false, NULL, NULL); | 141 ASCIIToUTF16("a"), true, false, NULL, NULL); |
| 153 browser()->GetFindBarController()->EndFindSession( | 142 browser()->GetFindBarController()->EndFindSession( |
| 154 FindBarController::kKeepSelectionOnPage, | 143 FindBarController::kKeepSelectionOnPage, |
| 155 FindBarController::kKeepResultsInFindBox); | 144 FindBarController::kKeepResultsInFindBox); |
| 156 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); | 145 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
| 157 | 146 |
| 158 // Focus the location bar, open and close the find box, focus should return to | 147 // Focus the location bar, open and close the find box, focus should return to |
| 159 // the location bar (same as before, just checking that http://crbug.com/23599 | 148 // the location bar (same as before, just checking that http://crbug.com/23599 |
| 160 // is fixed). | 149 // is fixed). |
| 161 chrome::FocusLocationBar(browser()); | 150 chrome::FocusLocationBar(browser()); |
| 162 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), | 151 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
| 163 location_bar_focus_view_id_)); | |
| 164 browser()->GetFindBarController()->Show(); | 152 browser()->GetFindBarController()->Show(); |
| 165 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), | 153 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| 166 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); | 154 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
| 167 browser()->GetFindBarController()->EndFindSession( | 155 browser()->GetFindBarController()->EndFindSession( |
| 168 FindBarController::kKeepSelectionOnPage, | 156 FindBarController::kKeepSelectionOnPage, |
| 169 FindBarController::kKeepResultsInFindBox); | 157 FindBarController::kKeepResultsInFindBox); |
| 170 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), | 158 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
| 171 location_bar_focus_view_id_)); | |
| 172 } | 159 } |
| 173 | 160 |
| 174 // Fails often on Win, CrOS. http://crbug.com/145476, http://crbug.com/128724 | 161 // Fails often on Win, CrOS. http://crbug.com/145476, http://crbug.com/128724 |
| 175 #if defined(OS_WIN) || defined(OS_CHROMEOS) | 162 #if defined(OS_WIN) || defined(OS_CHROMEOS) |
| 176 #define MAYBE_FocusRestoreOnTabSwitch DISABLED_FocusRestoreOnTabSwitch | 163 #define MAYBE_FocusRestoreOnTabSwitch DISABLED_FocusRestoreOnTabSwitch |
| 177 #else | 164 #else |
| 178 #define MAYBE_FocusRestoreOnTabSwitch FocusRestoreOnTabSwitch | 165 #define MAYBE_FocusRestoreOnTabSwitch FocusRestoreOnTabSwitch |
| 179 #endif | 166 #endif |
| 180 IN_PROC_BROWSER_TEST_F(FindInPageTest, MAYBE_FocusRestoreOnTabSwitch) { | 167 IN_PROC_BROWSER_TEST_F(FindInPageTest, MAYBE_FocusRestoreOnTabSwitch) { |
| 181 ASSERT_TRUE(test_server()->Start()); | 168 ASSERT_TRUE(test_server()->Start()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 210 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); | 197 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
| 211 | 198 |
| 212 // Search for 'b'. | 199 // Search for 'b'. |
| 213 ui_test_utils::FindInPage( | 200 ui_test_utils::FindInPage( |
| 214 browser()->tab_strip_model()->GetActiveWebContents(), | 201 browser()->tab_strip_model()->GetActiveWebContents(), |
| 215 ASCIIToUTF16("b"), true, false, NULL, NULL); | 202 ASCIIToUTF16("b"), true, false, NULL, NULL); |
| 216 EXPECT_TRUE(ASCIIToUTF16("b") == find_bar->GetFindSelectedText()); | 203 EXPECT_TRUE(ASCIIToUTF16("b") == find_bar->GetFindSelectedText()); |
| 217 | 204 |
| 218 // Set focus away from the Find bar (to the Location bar). | 205 // Set focus away from the Find bar (to the Location bar). |
| 219 chrome::FocusLocationBar(browser()); | 206 chrome::FocusLocationBar(browser()); |
| 220 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), | 207 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
| 221 location_bar_focus_view_id_)); | |
| 222 | 208 |
| 223 // Select tab A. Find bar should get focus. | 209 // Select tab A. Find bar should get focus. |
| 224 browser()->tab_strip_model()->ActivateTabAt(0, true); | 210 browser()->tab_strip_model()->ActivateTabAt(0, true); |
| 225 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), | 211 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| 226 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); | 212 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
| 227 EXPECT_TRUE(ASCIIToUTF16("a") == find_bar->GetFindSelectedText()); | 213 EXPECT_TRUE(ASCIIToUTF16("a") == find_bar->GetFindSelectedText()); |
| 228 | 214 |
| 229 // Select tab B. Location bar should get focus. | 215 // Select tab B. Location bar should get focus. |
| 230 browser()->tab_strip_model()->ActivateTabAt(1, true); | 216 browser()->tab_strip_model()->ActivateTabAt(1, true); |
| 231 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), | 217 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
| 232 location_bar_focus_view_id_)); | |
| 233 } | 218 } |
| 234 | 219 |
| 235 // Flaky on XP: http://crbug.com/152100 | 220 // Flaky on XP: http://crbug.com/152100 |
| 236 // Flaky on ChromiumOS: http://crbug.com/177487 | 221 // Flaky on ChromiumOS: http://crbug.com/177487 |
| 237 #if defined(OS_WIN) || defined(OS_CHROMEOS) | 222 #if defined(OS_WIN) || defined(OS_CHROMEOS) |
| 238 #define MAYBE_PrepopulateRespectBlank DISABLED_PrepopulateRespectBlank | 223 #define MAYBE_PrepopulateRespectBlank DISABLED_PrepopulateRespectBlank |
| 239 #else | 224 #else |
| 240 #define MAYBE_PrepopulateRespectBlank PrepopulateRespectBlank | 225 #define MAYBE_PrepopulateRespectBlank PrepopulateRespectBlank |
| 241 #endif | 226 #endif |
| 242 // This tests that whenever you clear values from the Find box and close it that | 227 // This tests that whenever you clear values from the Find box and close it that |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 chrome::NOTIFICATION_FIND_RESULT_AVAILABLE, notification_source); | 372 chrome::NOTIFICATION_FIND_RESULT_AVAILABLE, notification_source); |
| 388 | 373 |
| 389 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 374 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 390 browser(), ui::VKEY_V, true, false, false, false)); | 375 browser(), ui::VKEY_V, true, false, false, false)); |
| 391 | 376 |
| 392 ASSERT_NO_FATAL_FAILURE(observer.Wait()); | 377 ASSERT_NO_FATAL_FAILURE(observer.Wait()); |
| 393 FindNotificationDetails details; | 378 FindNotificationDetails details; |
| 394 ASSERT_TRUE(observer.GetDetailsFor(notification_source.map_key(), &details)); | 379 ASSERT_TRUE(observer.GetDetailsFor(notification_source.map_key(), &details)); |
| 395 EXPECT_TRUE(details.number_of_matches() > 0); | 380 EXPECT_TRUE(details.number_of_matches() > 0); |
| 396 } | 381 } |
| OLD | NEW |