| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 AutofillTest() {} | 222 AutofillTest() {} |
| 223 | 223 |
| 224 virtual void SetUpOnMainThread() OVERRIDE { | 224 virtual void SetUpOnMainThread() OVERRIDE { |
| 225 // Don't want Keychain coming up on Mac. | 225 // Don't want Keychain coming up on Mac. |
| 226 test::DisableSystemServices(browser()->profile()); | 226 test::DisableSystemServices(browser()->profile()); |
| 227 | 227 |
| 228 // When testing the native UI, hook up a test external delegate, which | 228 // When testing the native UI, hook up a test external delegate, which |
| 229 // allows us to forward keyboard events to the popup directly. | 229 // allows us to forward keyboard events to the popup directly. |
| 230 content::WebContents* web_contents = | 230 content::WebContents* web_contents = |
| 231 browser()->tab_strip_model()->GetActiveWebContents(); | 231 browser()->tab_strip_model()->GetActiveWebContents(); |
| 232 AutofillManager* autofill_manager = | 232 AutofillDriverImpl* autofill_driver = |
| 233 AutofillDriverImpl::FromWebContents(web_contents)->autofill_manager(); | 233 AutofillDriverImpl::FromWebContents(web_contents); |
| 234 AutofillManager* autofill_manager = autofill_driver->autofill_manager(); |
| 234 if (autofill_manager->IsNativeUiEnabled()) { | 235 if (autofill_manager->IsNativeUiEnabled()) { |
| 235 external_delegate_.reset( | 236 scoped_ptr<AutofillExternalDelegate> external_delegate( |
| 236 new TestAutofillExternalDelegate(web_contents, autofill_manager)); | 237 new TestAutofillExternalDelegate(web_contents, autofill_manager)); |
| 237 autofill_manager->SetExternalDelegate(external_delegate_.get()); | 238 autofill_driver->SetAutofillExternalDelegate(external_delegate.Pass()); |
| 238 } | 239 } |
| 239 autofill_manager->SetTestDelegate(&test_delegate_); | 240 autofill_manager->SetTestDelegate(&test_delegate_); |
| 240 } | 241 } |
| 241 | 242 |
| 242 virtual void CleanUpOnMainThread() OVERRIDE { | 243 virtual void CleanUpOnMainThread() OVERRIDE { |
| 243 // Make sure to close any showing popups prior to tearing down the UI. | 244 // Make sure to close any showing popups prior to tearing down the UI. |
| 244 content::WebContents* web_contents = | 245 content::WebContents* web_contents = |
| 245 browser()->tab_strip_model()->GetActiveWebContents(); | 246 browser()->tab_strip_model()->GetActiveWebContents(); |
| 246 AutofillManager* autofill_manager = | 247 AutofillManager* autofill_manager = |
| 247 AutofillDriverImpl::FromWebContents(web_contents)->autofill_manager(); | 248 AutofillDriverImpl::FromWebContents(web_contents)->autofill_manager(); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 test_delegate_.Reset(); | 466 test_delegate_.Reset(); |
| 466 content::SimulateKeyPress( | 467 content::SimulateKeyPress( |
| 467 browser()->tab_strip_model()->GetActiveWebContents(), | 468 browser()->tab_strip_model()->GetActiveWebContents(), |
| 468 key, false, false, false, false); | 469 key, false, false, false, false); |
| 469 test_delegate_.Wait(); | 470 test_delegate_.Wait(); |
| 470 } | 471 } |
| 471 | 472 |
| 472 void SendKeyToPopupAndWait(ui::KeyboardCode key) { | 473 void SendKeyToPopupAndWait(ui::KeyboardCode key) { |
| 473 // TODO(isherman): Remove this condition once the WebKit popup UI code is | 474 // TODO(isherman): Remove this condition once the WebKit popup UI code is |
| 474 // removed. | 475 // removed. |
| 475 if (!external_delegate_) { | 476 if (!external_delegate()) { |
| 476 // When testing the WebKit-based UI, route all keys to the page. | 477 // When testing the WebKit-based UI, route all keys to the page. |
| 477 SendKeyToPageAndWait(key); | 478 SendKeyToPageAndWait(key); |
| 478 return; | 479 return; |
| 479 } | 480 } |
| 480 | 481 |
| 481 // When testing the native UI, route popup-targeted key presses via the | 482 // When testing the native UI, route popup-targeted key presses via the |
| 482 // external delegate. | 483 // external delegate. |
| 483 content::NativeWebKeyboardEvent event; | 484 content::NativeWebKeyboardEvent event; |
| 484 event.windowsKeyCode = key; | 485 event.windowsKeyCode = key; |
| 485 test_delegate_.Reset(); | 486 test_delegate_.Reset(); |
| 486 external_delegate_->keyboard_listener()->HandleKeyPressEvent(event); | 487 external_delegate()->keyboard_listener()->HandleKeyPressEvent(event); |
| 487 test_delegate_.Wait(); | 488 test_delegate_.Wait(); |
| 488 } | 489 } |
| 489 | 490 |
| 490 void TryBasicFormFill() { | 491 void TryBasicFormFill() { |
| 491 FocusFirstNameField(); | 492 FocusFirstNameField(); |
| 492 | 493 |
| 493 // Start filling the first name field with "M" and wait for the popup to be | 494 // Start filling the first name field with "M" and wait for the popup to be |
| 494 // shown. | 495 // shown. |
| 495 LOG(WARNING) << "Typing 'M' to bring up the Autofill popup."; | 496 LOG(WARNING) << "Typing 'M' to bring up the Autofill popup."; |
| 496 SendKeyToPageAndWait(ui::VKEY_M); | 497 SendKeyToPageAndWait(ui::VKEY_M); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 515 | 516 |
| 516 // Press Enter to accept the autofill suggestions. | 517 // Press Enter to accept the autofill suggestions. |
| 517 LOG(WARNING) << "Simulating Return press to fill the form."; | 518 LOG(WARNING) << "Simulating Return press to fill the form."; |
| 518 SendKeyToPopupAndWait(ui::VKEY_RETURN); | 519 SendKeyToPopupAndWait(ui::VKEY_RETURN); |
| 519 | 520 |
| 520 // The form should be filled. | 521 // The form should be filled. |
| 521 ExpectFilledTestForm(); | 522 ExpectFilledTestForm(); |
| 522 } | 523 } |
| 523 | 524 |
| 524 TestAutofillExternalDelegate* external_delegate() { | 525 TestAutofillExternalDelegate* external_delegate() { |
| 525 return external_delegate_.get(); | 526 content::WebContents* web_contents = |
| 527 browser()->tab_strip_model()->GetActiveWebContents(); |
| 528 AutofillDriverImpl* autofill_driver = |
| 529 AutofillDriverImpl::FromWebContents(web_contents); |
| 530 return static_cast<TestAutofillExternalDelegate*>( |
| 531 autofill_driver->autofill_external_delegate()); |
| 526 } | 532 } |
| 527 | 533 |
| 528 AutofillManagerTestDelegateImpl test_delegate_; | 534 AutofillManagerTestDelegateImpl test_delegate_; |
| 529 | 535 |
| 530 private: | 536 private: |
| 531 net::TestURLFetcherFactory url_fetcher_factory_; | 537 net::TestURLFetcherFactory url_fetcher_factory_; |
| 532 scoped_ptr<TestAutofillExternalDelegate> external_delegate_; | |
| 533 }; | 538 }; |
| 534 | 539 |
| 535 // http://crbug.com/150084 | 540 // http://crbug.com/150084 |
| 536 #if defined(OS_MACOSX) | 541 #if defined(OS_MACOSX) |
| 537 #define MAYBE_BasicFormFill BasicFormFill | 542 #define MAYBE_BasicFormFill BasicFormFill |
| 538 #else | 543 #else |
| 539 #define MAYBE_BasicFormFill DISABLED_BasicFormFill | 544 #define MAYBE_BasicFormFill DISABLED_BasicFormFill |
| 540 #endif | 545 #endif |
| 541 // Test that basic form fill is working. | 546 // Test that basic form fill is working. |
| 542 IN_PROC_BROWSER_TEST_F(AutofillTest, MAYBE_BasicFormFill) { | 547 IN_PROC_BROWSER_TEST_F(AutofillTest, MAYBE_BasicFormFill) { |
| (...skipping 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1713 IN_PROC_BROWSER_TEST_F(AutofillTest, | 1718 IN_PROC_BROWSER_TEST_F(AutofillTest, |
| 1714 DISABLED_MergeAggregatedDuplicatedProfiles) { | 1719 DISABLED_MergeAggregatedDuplicatedProfiles) { |
| 1715 int num_of_profiles = | 1720 int num_of_profiles = |
| 1716 AggregateProfilesIntoAutofillPrefs("dataset_no_address.txt"); | 1721 AggregateProfilesIntoAutofillPrefs("dataset_no_address.txt"); |
| 1717 | 1722 |
| 1718 ASSERT_GT(num_of_profiles, | 1723 ASSERT_GT(num_of_profiles, |
| 1719 static_cast<int>(personal_data_manager()->GetProfiles().size())); | 1724 static_cast<int>(personal_data_manager()->GetProfiles().size())); |
| 1720 } | 1725 } |
| 1721 | 1726 |
| 1722 } // namespace autofill | 1727 } // namespace autofill |
| OLD | NEW |