| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/tabs/tab_strip_model.h" | 8 #include "chrome/browser/tabs/tab_strip_model.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 10 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 static const char kSimplePage[] = "files/find_in_page/simple.html"; | 31 static const char kSimplePage[] = "files/find_in_page/simple.html"; |
| 32 | 32 |
| 33 void Checkpoint(const char* message, const base::TimeTicks& start_time) { | 33 void Checkpoint(const char* message, const base::TimeTicks& start_time) { |
| 34 LOG(INFO) << message << " : " | 34 LOG(INFO) << message << " : " |
| 35 << (base::TimeTicks::Now() - start_time).InMilliseconds() | 35 << (base::TimeTicks::Now() - start_time).InMilliseconds() |
| 36 << " ms" << std::flush; | 36 << " ms" << std::flush; |
| 37 } | 37 } |
| 38 | 38 |
| 39 class FindInPageTest : public InProcessBrowserTest { | 39 class FindInPageTest : public InProcessBrowserTest { |
| 40 public: | 40 public: |
| 41 FindInPageTest() { | 41 FindInPageTest() : |
| 42 #if defined(USE_AURA) |
| 43 location_bar_focus_view_id_(VIEW_ID_OMNIBOX) |
| 44 #else |
| 45 location_bar_focus_view_id_(VIEW_ID_LOCATION_BAR) |
| 46 #endif |
| 47 { |
| 42 set_show_window(true); | 48 set_show_window(true); |
| 43 FindBarHost::disable_animations_during_testing_ = true; | 49 FindBarHost::disable_animations_during_testing_ = true; |
| 44 } | 50 } |
| 45 | 51 |
| 46 string16 GetFindBarText() { | 52 string16 GetFindBarText() { |
| 47 FindBarTesting* find_bar = | 53 FindBarTesting* find_bar = |
| 48 browser()->GetFindBarController()->find_bar()->GetFindBarTesting(); | 54 browser()->GetFindBarController()->find_bar()->GetFindBarTesting(); |
| 49 return find_bar->GetFindText(); | 55 return find_bar->GetFindText(); |
| 50 } | 56 } |
| 51 | 57 |
| 52 string16 GetFindBarSelectedText() { | 58 string16 GetFindBarSelectedText() { |
| 53 FindBarTesting* find_bar = | 59 FindBarTesting* find_bar = |
| 54 browser()->GetFindBarController()->find_bar()->GetFindBarTesting(); | 60 browser()->GetFindBarController()->find_bar()->GetFindBarTesting(); |
| 55 return find_bar->GetFindSelectedText(); | 61 return find_bar->GetFindSelectedText(); |
| 56 } | 62 } |
| 63 |
| 64 ViewID location_bar_focus_view_id_; |
| 65 |
| 66 private: |
| 67 DISALLOW_COPY_AND_ASSIGN(FindInPageTest); |
| 57 }; | 68 }; |
| 58 | 69 |
| 59 } // namespace | 70 } // namespace |
| 60 | 71 |
| 61 #if defined(TOOLKIT_USES_GTK) | 72 #if defined(TOOLKIT_USES_GTK) |
| 62 #define MAYBE_CrashEscHandlers FLAKY_CrashEscHandlers | 73 #define MAYBE_CrashEscHandlers FLAKY_CrashEscHandlers |
| 63 #else | 74 #else |
| 64 #define MAYBE_CrashEscHandlers CrashEscHandlers | 75 #define MAYBE_CrashEscHandlers CrashEscHandlers |
| 65 #endif | 76 #endif |
| 66 | 77 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 82 | 93 |
| 83 // Select tab A. | 94 // Select tab A. |
| 84 browser()->ActivateTabAt(0, true); | 95 browser()->ActivateTabAt(0, true); |
| 85 | 96 |
| 86 // Close tab B. | 97 // Close tab B. |
| 87 browser()->CloseTabContents(browser()->GetTabContentsAt(1)); | 98 browser()->CloseTabContents(browser()->GetTabContentsAt(1)); |
| 88 | 99 |
| 89 // Click on the location bar so that Find box loses focus. | 100 // Click on the location bar so that Find box loses focus. |
| 90 ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(), | 101 ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(), |
| 91 VIEW_ID_LOCATION_BAR)); | 102 VIEW_ID_LOCATION_BAR)); |
| 92 #if defined(TOOLKIT_VIEWS) || defined(OS_WIN) | |
| 93 // Check the location bar is focused. | 103 // Check the location bar is focused. |
| 94 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_LOCATION_BAR)); | 104 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| 95 #endif | 105 location_bar_focus_view_id_)); |
| 96 | 106 |
| 97 // This used to crash until bug 1303709 was fixed. | 107 // This used to crash until bug 1303709 was fixed. |
| 98 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 108 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 99 browser(), ui::VKEY_ESCAPE, false, false, false, false)); | 109 browser(), ui::VKEY_ESCAPE, false, false, false, false)); |
| 100 } | 110 } |
| 101 | 111 |
| 102 IN_PROC_BROWSER_TEST_F(FindInPageTest, FocusRestore) { | 112 IN_PROC_BROWSER_TEST_F(FindInPageTest, FocusRestore) { |
| 103 ASSERT_TRUE(test_server()->Start()); | 113 ASSERT_TRUE(test_server()->Start()); |
| 104 | 114 |
| 105 GURL url = test_server()->GetURL("title1.html"); | 115 GURL url = test_server()->GetURL("title1.html"); |
| 106 ui_test_utils::NavigateToURL(browser(), url); | 116 ui_test_utils::NavigateToURL(browser(), url); |
| 107 | 117 |
| 108 // Focus the location bar, open and close the find-in-page, focus should | 118 // Focus the location bar, open and close the find-in-page, focus should |
| 109 // return to the location bar. | 119 // return to the location bar. |
| 110 browser()->FocusLocationBar(); | 120 browser()->FocusLocationBar(); |
| 111 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_LOCATION_BAR)); | 121 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| 122 location_bar_focus_view_id_)); |
| 112 // Ensure the creation of the find bar controller. | 123 // Ensure the creation of the find bar controller. |
| 113 browser()->GetFindBarController()->Show(); | 124 browser()->GetFindBarController()->Show(); |
| 114 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), | 125 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| 115 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); | 126 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
| 116 browser()->GetFindBarController()->EndFindSession( | 127 browser()->GetFindBarController()->EndFindSession( |
| 117 FindBarController::kKeepSelection); | 128 FindBarController::kKeepSelection); |
| 118 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_LOCATION_BAR)); | 129 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| 130 location_bar_focus_view_id_)); |
| 119 | 131 |
| 120 // Focus the location bar, find something on the page, close the find box, | 132 // Focus the location bar, find something on the page, close the find box, |
| 121 // focus should go to the page. | 133 // focus should go to the page. |
| 122 browser()->FocusLocationBar(); | 134 browser()->FocusLocationBar(); |
| 123 browser()->Find(); | 135 browser()->Find(); |
| 124 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), | 136 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| 125 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); | 137 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
| 126 ui_test_utils::FindInPage(browser()->GetSelectedTabContentsWrapper(), | 138 ui_test_utils::FindInPage(browser()->GetSelectedTabContentsWrapper(), |
| 127 ASCIIToUTF16("a"), true, false, NULL); | 139 ASCIIToUTF16("a"), true, false, NULL); |
| 128 browser()->GetFindBarController()->EndFindSession( | 140 browser()->GetFindBarController()->EndFindSession( |
| 129 FindBarController::kKeepSelection); | 141 FindBarController::kKeepSelection); |
| 130 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), | 142 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| 131 VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 143 VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 132 | 144 |
| 133 // Focus the location bar, open and close the find box, focus should return to | 145 // Focus the location bar, open and close the find box, focus should return to |
| 134 // the location bar (same as before, just checking that http://crbug.com/23599 | 146 // the location bar (same as before, just checking that http://crbug.com/23599 |
| 135 // is fixed). | 147 // is fixed). |
| 136 browser()->FocusLocationBar(); | 148 browser()->FocusLocationBar(); |
| 137 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_LOCATION_BAR)); | 149 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| 150 location_bar_focus_view_id_)); |
| 138 browser()->GetFindBarController()->Show(); | 151 browser()->GetFindBarController()->Show(); |
| 139 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), | 152 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| 140 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); | 153 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
| 141 browser()->GetFindBarController()->EndFindSession( | 154 browser()->GetFindBarController()->EndFindSession( |
| 142 FindBarController::kKeepSelection); | 155 FindBarController::kKeepSelection); |
| 143 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_LOCATION_BAR)); | 156 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| 157 location_bar_focus_view_id_)); |
| 144 } | 158 } |
| 145 | 159 |
| 146 IN_PROC_BROWSER_TEST_F(FindInPageTest, FocusRestoreOnTabSwitch) { | 160 IN_PROC_BROWSER_TEST_F(FindInPageTest, FocusRestoreOnTabSwitch) { |
| 147 ASSERT_TRUE(test_server()->Start()); | 161 ASSERT_TRUE(test_server()->Start()); |
| 148 | 162 |
| 149 // First we navigate to our test page (tab A). | 163 // First we navigate to our test page (tab A). |
| 150 GURL url = test_server()->GetURL(kSimplePage); | 164 GURL url = test_server()->GetURL(kSimplePage); |
| 151 ui_test_utils::NavigateToURL(browser(), url); | 165 ui_test_utils::NavigateToURL(browser(), url); |
| 152 | 166 |
| 153 browser()->Find(); | 167 browser()->Find(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 174 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), | 188 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| 175 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); | 189 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
| 176 | 190 |
| 177 // Search for 'b'. | 191 // Search for 'b'. |
| 178 ui_test_utils::FindInPage(browser()->GetSelectedTabContentsWrapper(), | 192 ui_test_utils::FindInPage(browser()->GetSelectedTabContentsWrapper(), |
| 179 ASCIIToUTF16("b"), true, false, NULL); | 193 ASCIIToUTF16("b"), true, false, NULL); |
| 180 EXPECT_TRUE(ASCIIToUTF16("b") == find_bar->GetFindSelectedText()); | 194 EXPECT_TRUE(ASCIIToUTF16("b") == find_bar->GetFindSelectedText()); |
| 181 | 195 |
| 182 // Set focus away from the Find bar (to the Location bar). | 196 // Set focus away from the Find bar (to the Location bar). |
| 183 browser()->FocusLocationBar(); | 197 browser()->FocusLocationBar(); |
| 184 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_LOCATION_BAR)); | 198 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| 199 location_bar_focus_view_id_)); |
| 185 | 200 |
| 186 // Select tab A. Find bar should get focus. | 201 // Select tab A. Find bar should get focus. |
| 187 browser()->ActivateTabAt(0, true); | 202 browser()->ActivateTabAt(0, true); |
| 188 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), | 203 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| 189 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); | 204 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
| 190 EXPECT_TRUE(ASCIIToUTF16("a") == find_bar->GetFindSelectedText()); | 205 EXPECT_TRUE(ASCIIToUTF16("a") == find_bar->GetFindSelectedText()); |
| 191 | 206 |
| 192 // Select tab B. Location bar should get focus. | 207 // Select tab B. Location bar should get focus. |
| 193 browser()->ActivateTabAt(1, true); | 208 browser()->ActivateTabAt(1, true); |
| 194 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_LOCATION_BAR)); | 209 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| 210 location_bar_focus_view_id_)); |
| 195 } | 211 } |
| 196 | 212 |
| 197 // This tests that whenever you clear values from the Find box and close it that | 213 // This tests that whenever you clear values from the Find box and close it that |
| 198 // it respects that and doesn't show you the last search, as reported in bug: | 214 // it respects that and doesn't show you the last search, as reported in bug: |
| 199 // http://crbug.com/40121. | 215 // http://crbug.com/40121. |
| 200 IN_PROC_BROWSER_TEST_F(FindInPageTest, PrepopulateRespectBlank) { | 216 IN_PROC_BROWSER_TEST_F(FindInPageTest, PrepopulateRespectBlank) { |
| 201 #if defined(OS_MACOSX) | 217 #if defined(OS_MACOSX) |
| 202 // FindInPage on Mac doesn't use prepopulated values. Search there is global. | 218 // FindInPage on Mac doesn't use prepopulated values. Search there is global. |
| 203 return; | 219 return; |
| 204 #endif | 220 #endif |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 chrome::NOTIFICATION_FIND_RESULT_AVAILABLE, notification_source); | 357 chrome::NOTIFICATION_FIND_RESULT_AVAILABLE, notification_source); |
| 342 | 358 |
| 343 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 359 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 344 browser(), ui::VKEY_V, true, false, false, false)); | 360 browser(), ui::VKEY_V, true, false, false, false)); |
| 345 | 361 |
| 346 ASSERT_NO_FATAL_FAILURE(observer.Wait()); | 362 ASSERT_NO_FATAL_FAILURE(observer.Wait()); |
| 347 FindNotificationDetails details; | 363 FindNotificationDetails details; |
| 348 ASSERT_TRUE(observer.GetDetailsFor(notification_source.map_key(), &details)); | 364 ASSERT_TRUE(observer.GetDetailsFor(notification_source.map_key(), &details)); |
| 349 EXPECT_TRUE(details.number_of_matches() > 0); | 365 EXPECT_TRUE(details.number_of_matches() > 0); |
| 350 } | 366 } |
| OLD | NEW |