| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 7 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 8 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 8 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 AutofillInteractiveTest() {} | 199 AutofillInteractiveTest() {} |
| 200 | 200 |
| 201 virtual void SetUpOnMainThread() OVERRIDE { | 201 virtual void SetUpOnMainThread() OVERRIDE { |
| 202 // Don't want Keychain coming up on Mac. | 202 // Don't want Keychain coming up on Mac. |
| 203 test::DisableSystemServices(browser()->profile()); | 203 test::DisableSystemServices(browser()->profile()); |
| 204 | 204 |
| 205 // When testing the native UI, hook up a test external delegate, which | 205 // When testing the native UI, hook up a test external delegate, which |
| 206 // allows us to forward keyboard events to the popup directly. | 206 // allows us to forward keyboard events to the popup directly. |
| 207 content::WebContents* web_contents = | 207 content::WebContents* web_contents = |
| 208 browser()->tab_strip_model()->GetActiveWebContents(); | 208 browser()->tab_strip_model()->GetActiveWebContents(); |
| 209 AutofillManager* autofill_manager = | 209 AutofillDriverImpl* autofill_driver = |
| 210 AutofillDriverImpl::FromWebContents(web_contents)->autofill_manager(); | 210 AutofillDriverImpl::FromWebContents(web_contents); |
| 211 AutofillManager* autofill_manager = autofill_driver->autofill_manager(); |
| 211 if (autofill_manager->IsNativeUiEnabled()) { | 212 if (autofill_manager->IsNativeUiEnabled()) { |
| 212 external_delegate_.reset( | 213 scoped_ptr<AutofillExternalDelegate> external_delegate( |
| 213 new TestAutofillExternalDelegate(web_contents, autofill_manager)); | 214 new TestAutofillExternalDelegate(web_contents, autofill_manager)); |
| 214 autofill_manager->SetExternalDelegate(external_delegate_.get()); | 215 autofill_driver->SetAutofillExternalDelegate(external_delegate.Pass()); |
| 215 } | 216 } |
| 216 autofill_manager->SetTestDelegate(&test_delegate_); | 217 autofill_manager->SetTestDelegate(&test_delegate_); |
| 217 } | 218 } |
| 218 | 219 |
| 219 virtual void CleanUpOnMainThread() OVERRIDE { | 220 virtual void CleanUpOnMainThread() OVERRIDE { |
| 220 // Make sure to close any showing popups prior to tearing down the UI. | 221 // Make sure to close any showing popups prior to tearing down the UI. |
| 221 content::WebContents* web_contents = | 222 content::WebContents* web_contents = |
| 222 browser()->tab_strip_model()->GetActiveWebContents(); | 223 browser()->tab_strip_model()->GetActiveWebContents(); |
| 223 AutofillManager* autofill_manager = | 224 AutofillManager* autofill_manager = |
| 224 AutofillDriverImpl::FromWebContents(web_contents)->autofill_manager(); | 225 AutofillDriverImpl::FromWebContents(web_contents)->autofill_manager(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 test_delegate_.Reset(); | 296 test_delegate_.Reset(); |
| 296 content::SimulateKeyPress( | 297 content::SimulateKeyPress( |
| 297 browser()->tab_strip_model()->GetActiveWebContents(), | 298 browser()->tab_strip_model()->GetActiveWebContents(), |
| 298 key, false, false, false, false); | 299 key, false, false, false, false); |
| 299 test_delegate_.Wait(); | 300 test_delegate_.Wait(); |
| 300 } | 301 } |
| 301 | 302 |
| 302 void SendKeyToPopupAndWait(ui::KeyboardCode key) { | 303 void SendKeyToPopupAndWait(ui::KeyboardCode key) { |
| 303 // TODO(isherman): Remove this condition once the WebKit popup UI code is | 304 // TODO(isherman): Remove this condition once the WebKit popup UI code is |
| 304 // removed. | 305 // removed. |
| 305 if (!external_delegate_) { | 306 if (!external_delegate()) { |
| 306 // When testing the WebKit-based UI, route all keys to the page. | 307 // When testing the WebKit-based UI, route all keys to the page. |
| 307 SendKeyToPageAndWait(key); | 308 SendKeyToPageAndWait(key); |
| 308 return; | 309 return; |
| 309 } | 310 } |
| 310 | 311 |
| 311 // When testing the native UI, route popup-targeted key presses via the | 312 // When testing the native UI, route popup-targeted key presses via the |
| 312 // external delegate. | 313 // external delegate. |
| 313 content::NativeWebKeyboardEvent event; | 314 content::NativeWebKeyboardEvent event; |
| 314 event.windowsKeyCode = key; | 315 event.windowsKeyCode = key; |
| 315 test_delegate_.Reset(); | 316 test_delegate_.Reset(); |
| 316 external_delegate_->keyboard_listener()->HandleKeyPressEvent(event); | 317 external_delegate()->keyboard_listener()->HandleKeyPressEvent(event); |
| 317 test_delegate_.Wait(); | 318 test_delegate_.Wait(); |
| 318 } | 319 } |
| 319 | 320 |
| 320 TestAutofillExternalDelegate* external_delegate() { | 321 TestAutofillExternalDelegate* external_delegate() { |
| 321 return external_delegate_.get(); | 322 content::WebContents* web_contents = |
| 323 browser()->tab_strip_model()->GetActiveWebContents(); |
| 324 AutofillDriverImpl* autofill_driver = |
| 325 AutofillDriverImpl::FromWebContents(web_contents); |
| 326 return static_cast<TestAutofillExternalDelegate*>( |
| 327 autofill_driver->autofill_external_delegate()); |
| 322 } | 328 } |
| 323 | 329 |
| 324 AutofillManagerTestDelegateImpl test_delegate_; | 330 AutofillManagerTestDelegateImpl test_delegate_; |
| 325 | |
| 326 private: | |
| 327 scoped_ptr<TestAutofillExternalDelegate> external_delegate_; | |
| 328 }; | 331 }; |
| 329 | 332 |
| 330 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, DISABLED_AutofillSelectViaTab) { | 333 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, DISABLED_AutofillSelectViaTab) { |
| 331 CreateTestProfile(); | 334 CreateTestProfile(); |
| 332 | 335 |
| 333 // Load the test page. | 336 // Load the test page. |
| 334 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), | 337 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), |
| 335 GURL(std::string(kDataURIPrefix) + kTestFormString))); | 338 GURL(std::string(kDataURIPrefix) + kTestFormString))); |
| 336 | 339 |
| 337 // Focus a fillable field. | 340 // Focus a fillable field. |
| 338 FocusFirstNameField(); | 341 FocusFirstNameField(); |
| 339 | 342 |
| 340 // Press the down arrow to initiate Autofill and wait for the popup to be | 343 // Press the down arrow to initiate Autofill and wait for the popup to be |
| 341 // shown. | 344 // shown. |
| 342 SendKeyToPageAndWait(ui::VKEY_DOWN); | 345 SendKeyToPageAndWait(ui::VKEY_DOWN); |
| 343 | 346 |
| 344 // Press the down arrow to select the suggestion and preview the autofilled | 347 // Press the down arrow to select the suggestion and preview the autofilled |
| 345 // form. | 348 // form. |
| 346 SendKeyToPopupAndWait(ui::VKEY_DOWN); | 349 SendKeyToPopupAndWait(ui::VKEY_DOWN); |
| 347 | 350 |
| 348 // Press tab to accept the autofill suggestions. | 351 // Press tab to accept the autofill suggestions. |
| 349 SendKeyToPopupAndWait(ui::VKEY_TAB); | 352 SendKeyToPopupAndWait(ui::VKEY_TAB); |
| 350 | 353 |
| 351 // The form should be filled. | 354 // The form should be filled. |
| 352 ExpectFilledTestForm(); | 355 ExpectFilledTestForm(); |
| 353 } | 356 } |
| 354 | 357 |
| 355 } // namespace autofill | 358 } // namespace autofill |
| OLD | NEW |