| Index: chrome/browser/autofill/autofill_interactive_uitest.cc
|
| ===================================================================
|
| --- chrome/browser/autofill/autofill_interactive_uitest.cc (revision 212931)
|
| +++ chrome/browser/autofill/autofill_interactive_uitest.cc (working copy)
|
| @@ -69,92 +69,75 @@
|
| " <input type=\"text\" id=\"phone\"><br>"
|
| "</form>";
|
|
|
| +
|
| +// AutofillManagerTestDelegateImpl --------------------------------------------
|
| +
|
| class AutofillManagerTestDelegateImpl
|
| : public autofill::AutofillManagerTestDelegate {
|
| public:
|
| - AutofillManagerTestDelegateImpl() {}
|
| + AutofillManagerTestDelegateImpl();
|
| + virtual ~AutofillManagerTestDelegateImpl();
|
|
|
| - virtual void DidPreviewFormData() OVERRIDE {
|
| - loop_runner_->Quit();
|
| - }
|
| + // autofill::AutofillManagerTestDelegate:
|
| + virtual void DidPreviewFormData() OVERRIDE;
|
| + virtual void DidFillFormData() OVERRIDE;
|
| + virtual void DidShowSuggestions() OVERRIDE;
|
|
|
| - virtual void DidFillFormData() OVERRIDE {
|
| - loop_runner_->Quit();
|
| - }
|
| + void Reset();
|
| + void Wait();
|
|
|
| - virtual void DidShowSuggestions() OVERRIDE {
|
| - loop_runner_->Quit();
|
| - }
|
| -
|
| - void Reset() {
|
| - loop_runner_ = new content::MessageLoopRunner();
|
| - }
|
| -
|
| - void Wait() {
|
| - loop_runner_->Run();
|
| - }
|
| -
|
| private:
|
| scoped_refptr<content::MessageLoopRunner> loop_runner_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(AutofillManagerTestDelegateImpl);
|
| };
|
|
|
| +AutofillManagerTestDelegateImpl::AutofillManagerTestDelegateImpl() {
|
| +}
|
| +
|
| +AutofillManagerTestDelegateImpl::~AutofillManagerTestDelegateImpl() {
|
| +}
|
| +
|
| +void AutofillManagerTestDelegateImpl::DidPreviewFormData() {
|
| + loop_runner_->Quit();
|
| +}
|
| +
|
| +void AutofillManagerTestDelegateImpl::DidFillFormData() {
|
| + loop_runner_->Quit();
|
| +}
|
| +
|
| +void AutofillManagerTestDelegateImpl::DidShowSuggestions() {
|
| + loop_runner_->Quit();
|
| +}
|
| +
|
| +void AutofillManagerTestDelegateImpl::Reset() {
|
| + loop_runner_ = new content::MessageLoopRunner();
|
| +}
|
| +
|
| +void AutofillManagerTestDelegateImpl::Wait() {
|
| + loop_runner_->Run();
|
| +}
|
| +
|
| +
|
| +// WindowedPersonalDataManagerObserver ----------------------------------------
|
| +
|
| class WindowedPersonalDataManagerObserver
|
| : public PersonalDataManagerObserver,
|
| public content::NotificationObserver {
|
| public:
|
| - explicit WindowedPersonalDataManagerObserver(Browser* browser)
|
| - : alerted_(false),
|
| - has_run_message_loop_(false),
|
| - browser_(browser),
|
| - infobar_service_(NULL) {
|
| - PersonalDataManagerFactory::GetForProfile(browser_->profile())->
|
| - AddObserver(this);
|
| - registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
|
| - content::NotificationService::AllSources());
|
| - }
|
| + explicit WindowedPersonalDataManagerObserver(Browser* browser);
|
| + virtual ~WindowedPersonalDataManagerObserver();
|
|
|
| - virtual ~WindowedPersonalDataManagerObserver() {
|
| - if (infobar_service_ && infobar_service_->infobar_count() > 0)
|
| - infobar_service_->RemoveInfoBar(infobar_service_->infobar_at(0));
|
| - }
|
| -
|
| - void Wait() {
|
| - if (!alerted_) {
|
| - has_run_message_loop_ = true;
|
| - content::RunMessageLoop();
|
| - }
|
| - PersonalDataManagerFactory::GetForProfile(browser_->profile())->
|
| - RemoveObserver(this);
|
| - }
|
| -
|
| // PersonalDataManagerObserver:
|
| - virtual void OnPersonalDataChanged() OVERRIDE {
|
| - if (has_run_message_loop_) {
|
| - base::MessageLoopForUI::current()->Quit();
|
| - has_run_message_loop_ = false;
|
| - }
|
| - alerted_ = true;
|
| - }
|
| + virtual void OnPersonalDataChanged() OVERRIDE;
|
| + virtual void OnInsufficientFormData() OVERRIDE;
|
|
|
| - virtual void OnInsufficientFormData() OVERRIDE {
|
| - OnPersonalDataChanged();
|
| - }
|
| -
|
| // content::NotificationObserver:
|
| virtual void Observe(int type,
|
| const content::NotificationSource& source,
|
| - const content::NotificationDetails& details) OVERRIDE {
|
| - // Accept in the infobar.
|
| - infobar_service_ = InfoBarService::FromWebContents(
|
| - browser_->tab_strip_model()->GetActiveWebContents());
|
| - InfoBarDelegate* infobar = infobar_service_->infobar_at(0);
|
| + const content::NotificationDetails& details) OVERRIDE;
|
|
|
| - ConfirmInfoBarDelegate* confirm_infobar =
|
| - infobar->AsConfirmInfoBarDelegate();
|
| - confirm_infobar->Accept();
|
| - }
|
| + void Wait();
|
|
|
| private:
|
| bool alerted_;
|
| @@ -164,27 +147,72 @@
|
| InfoBarService* infobar_service_;
|
| };
|
|
|
| +WindowedPersonalDataManagerObserver::WindowedPersonalDataManagerObserver(
|
| + Browser* browser)
|
| + : alerted_(false),
|
| + has_run_message_loop_(false),
|
| + browser_(browser),
|
| + infobar_service_(NULL) {
|
| + PersonalDataManagerFactory::GetForProfile(browser_->profile())->
|
| + AddObserver(this);
|
| + registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
|
| + content::NotificationService::AllSources());
|
| +}
|
| +
|
| +WindowedPersonalDataManagerObserver::~WindowedPersonalDataManagerObserver() {
|
| + if (infobar_service_ && infobar_service_->infobar_count() > 0)
|
| + infobar_service_->RemoveInfoBar(infobar_service_->infobar_at(0));
|
| +}
|
| +
|
| +void WindowedPersonalDataManagerObserver::OnPersonalDataChanged() {
|
| + if (has_run_message_loop_) {
|
| + base::MessageLoopForUI::current()->Quit();
|
| + has_run_message_loop_ = false;
|
| + }
|
| + alerted_ = true;
|
| +}
|
| +
|
| +void WindowedPersonalDataManagerObserver::OnInsufficientFormData() {
|
| + OnPersonalDataChanged();
|
| +}
|
| +
|
| +void WindowedPersonalDataManagerObserver::Observe(
|
| + int type,
|
| + const content::NotificationSource& source,
|
| + const content::NotificationDetails& details) {
|
| + // Accept in the infobar.
|
| + infobar_service_ = InfoBarService::FromWebContents(
|
| + browser_->tab_strip_model()->GetActiveWebContents());
|
| + InfoBarDelegate* infobar = infobar_service_->infobar_at(0);
|
| +
|
| + ConfirmInfoBarDelegate* confirm_infobar =
|
| + infobar->AsConfirmInfoBarDelegate();
|
| + confirm_infobar->Accept();
|
| +}
|
| +
|
| +void WindowedPersonalDataManagerObserver::Wait() {
|
| + if (!alerted_) {
|
| + has_run_message_loop_ = true;
|
| + content::RunMessageLoop();
|
| + }
|
| + PersonalDataManagerFactory::GetForProfile(browser_->profile())->
|
| + RemoveObserver(this);
|
| +}
|
| +
|
| +
|
| +// TestAutofillExternalDelegate -----------------------------------------------
|
| +
|
| class TestAutofillExternalDelegate : public AutofillExternalDelegate {
|
| public:
|
| TestAutofillExternalDelegate(content::WebContents* web_contents,
|
| AutofillManager* autofill_manager,
|
| - AutofillDriver* autofill_driver)
|
| - : AutofillExternalDelegate(web_contents, autofill_manager,
|
| - autofill_driver),
|
| - keyboard_listener_(NULL) {
|
| - }
|
| - virtual ~TestAutofillExternalDelegate() {}
|
| + AutofillDriver* autofill_driver);
|
| + virtual ~TestAutofillExternalDelegate();
|
|
|
| - virtual void OnPopupShown(content::KeyboardListener* listener) OVERRIDE {
|
| - AutofillExternalDelegate::OnPopupShown(listener);
|
| - keyboard_listener_ = listener;
|
| - }
|
| + // AutofillExternalDelegate:
|
| + virtual void OnPopupShown(content::KeyboardListener* listener) OVERRIDE;
|
| + virtual void OnPopupHidden(content::KeyboardListener* listener) OVERRIDE;
|
|
|
| - virtual void OnPopupHidden(content::KeyboardListener* listener) OVERRIDE {
|
| - keyboard_listener_ = NULL;
|
| - AutofillExternalDelegate::OnPopupHidden(listener);
|
| - }
|
| -
|
| content::KeyboardListener* keyboard_listener() {
|
| return keyboard_listener_;
|
| }
|
| @@ -197,141 +225,190 @@
|
| DISALLOW_COPY_AND_ASSIGN(TestAutofillExternalDelegate);
|
| };
|
|
|
| +TestAutofillExternalDelegate::TestAutofillExternalDelegate(
|
| + content::WebContents* web_contents,
|
| + AutofillManager* autofill_manager,
|
| + AutofillDriver* autofill_driver)
|
| + : AutofillExternalDelegate(web_contents, autofill_manager, autofill_driver),
|
| + keyboard_listener_(NULL) {
|
| +}
|
| +
|
| +TestAutofillExternalDelegate::~TestAutofillExternalDelegate() {
|
| +}
|
| +
|
| +void TestAutofillExternalDelegate::OnPopupShown(
|
| + content::KeyboardListener* listener) {
|
| + AutofillExternalDelegate::OnPopupShown(listener);
|
| + keyboard_listener_ = listener;
|
| +}
|
| +
|
| +void TestAutofillExternalDelegate::OnPopupHidden(
|
| + content::KeyboardListener* listener) {
|
| + keyboard_listener_ = NULL;
|
| + AutofillExternalDelegate::OnPopupHidden(listener);
|
| +}
|
| +
|
| +
|
| +// AutofillInteractiveTest ----------------------------------------------------
|
| +
|
| class AutofillInteractiveTest : public InProcessBrowserTest {
|
| protected:
|
| - AutofillInteractiveTest() {}
|
| + AutofillInteractiveTest();
|
|
|
| - virtual void SetUpOnMainThread() OVERRIDE {
|
| - // Don't want Keychain coming up on Mac.
|
| - test::DisableSystemServices(browser()->profile());
|
| + // InProcessBrowserTest:
|
| + virtual void SetUpOnMainThread() OVERRIDE;
|
| + virtual void CleanUpOnMainThread() OVERRIDE;
|
|
|
| - // When testing the native UI, hook up a test external delegate, which
|
| - // allows us to forward keyboard events to the popup directly.
|
| - content::WebContents* web_contents =
|
| - browser()->tab_strip_model()->GetActiveWebContents();
|
| - AutofillDriverImpl* autofill_driver =
|
| - AutofillDriverImpl::FromWebContents(web_contents);
|
| - AutofillManager* autofill_manager = autofill_driver->autofill_manager();
|
| - scoped_ptr<AutofillExternalDelegate> external_delegate(
|
| - new TestAutofillExternalDelegate(web_contents, autofill_manager,
|
| - autofill_driver));
|
| - autofill_driver->SetAutofillExternalDelegate(external_delegate.Pass());
|
| - autofill_manager->SetTestDelegate(&test_delegate_);
|
| - }
|
| + PersonalDataManager* GetPersonalDataManager();
|
| + content::RenderViewHost* GetRenderViewHost();
|
| + TestAutofillExternalDelegate* GetExternalDelegate();
|
|
|
| - virtual void CleanUpOnMainThread() OVERRIDE {
|
| - // Make sure to close any showing popups prior to tearing down the UI.
|
| - content::WebContents* web_contents =
|
| - browser()->tab_strip_model()->GetActiveWebContents();
|
| - AutofillManager* autofill_manager =
|
| - AutofillDriverImpl::FromWebContents(web_contents)->autofill_manager();
|
| - autofill_manager->delegate()->HideAutofillPopup();
|
| - }
|
| + void CreateTestProfile();
|
| + void ExpectFieldValue(const std::string& field_name,
|
| + const std::string& expected_value);
|
| + void FocusFirstNameField();
|
| + void ExpectFilledTestForm();
|
| + void SendKeyToPageAndWait(ui::KeyboardCode key);
|
| + void SendKeyToPopupAndWait(ui::KeyboardCode key);
|
|
|
| - PersonalDataManager* personal_data_manager() {
|
| - return PersonalDataManagerFactory::GetForProfile(browser()->profile());
|
| - }
|
| + AutofillManagerTestDelegateImpl test_delegate_;
|
| +};
|
|
|
| - void CreateTestProfile() {
|
| - AutofillProfile profile;
|
| - test::SetProfileInfo(
|
| - &profile, "Milton", "C.", "Waddams",
|
| - "red.swingline@initech.com", "Initech", "4120 Freidrich Lane",
|
| - "Basement", "Austin", "Texas", "78744", "US", "5125551234");
|
| +AutofillInteractiveTest::AutofillInteractiveTest() {
|
| +}
|
|
|
| - WindowedPersonalDataManagerObserver observer(browser());
|
| - personal_data_manager()->AddProfile(profile);
|
| +void AutofillInteractiveTest::SetUpOnMainThread() {
|
| + // Don't want Keychain coming up on Mac.
|
| + test::DisableSystemServices(browser()->profile());
|
|
|
| - // AddProfile is asynchronous. Wait for it to finish before continuing the
|
| - // tests.
|
| - observer.Wait();
|
| - }
|
| + // When testing the native UI, hook up a test external delegate, which allows
|
| + // us to forward keyboard events to the popup directly.
|
| + content::WebContents* web_contents =
|
| + browser()->tab_strip_model()->GetActiveWebContents();
|
| + AutofillDriverImpl* autofill_driver =
|
| + AutofillDriverImpl::FromWebContents(web_contents);
|
| + AutofillManager* autofill_manager = autofill_driver->autofill_manager();
|
| + scoped_ptr<AutofillExternalDelegate> external_delegate(
|
| + new TestAutofillExternalDelegate(web_contents, autofill_manager,
|
| + autofill_driver));
|
| + autofill_driver->SetAutofillExternalDelegate(external_delegate.Pass());
|
| + autofill_manager->SetTestDelegate(&test_delegate_);
|
| +}
|
|
|
| - void ExpectFieldValue(const std::string& field_name,
|
| - const std::string& expected_value) {
|
| - std::string value;
|
| - ASSERT_TRUE(content::ExecuteScriptAndExtractString(
|
| - browser()->tab_strip_model()->GetActiveWebContents(),
|
| - "window.domAutomationController.send("
|
| - " document.getElementById('" + field_name + "').value);",
|
| - &value));
|
| - EXPECT_EQ(expected_value, value);
|
| - }
|
| +void AutofillInteractiveTest::CleanUpOnMainThread() {
|
| + // Make sure to close any showing popups prior to tearing down the UI.
|
| + content::WebContents* web_contents =
|
| + browser()->tab_strip_model()->GetActiveWebContents();
|
| + AutofillManager* autofill_manager =
|
| + AutofillDriverImpl::FromWebContents(web_contents)->autofill_manager();
|
| + autofill_manager->delegate()->HideAutofillPopup();
|
| +}
|
|
|
| - RenderViewHost* render_view_host() {
|
| - return browser()->tab_strip_model()->GetActiveWebContents()->
|
| - GetRenderViewHost();
|
| - }
|
| +PersonalDataManager* AutofillInteractiveTest::GetPersonalDataManager() {
|
| + return PersonalDataManagerFactory::GetForProfile(browser()->profile());
|
| +}
|
|
|
| - void FocusFirstNameField() {
|
| - LOG(WARNING) << "Clicking on the tab.";
|
| - content::SimulateMouseClick(
|
| - browser()->tab_strip_model()->GetActiveWebContents(),
|
| - 0,
|
| - WebKit::WebMouseEvent::ButtonLeft);
|
| +RenderViewHost* AutofillInteractiveTest::GetRenderViewHost() {
|
| + return browser()->tab_strip_model()->GetActiveWebContents()->
|
| + GetRenderViewHost();
|
| +}
|
|
|
| - LOG(WARNING) << "Focusing the first name field.";
|
| - bool result = false;
|
| - ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
|
| - render_view_host(),
|
| - "if (document.readyState === 'complete')"
|
| - " document.getElementById('firstname').focus();"
|
| - "else"
|
| - " domAutomationController.send(false);",
|
| - &result));
|
| - ASSERT_TRUE(result);
|
| - }
|
| +TestAutofillExternalDelegate* AutofillInteractiveTest::GetExternalDelegate() {
|
| + content::WebContents* web_contents =
|
| + browser()->tab_strip_model()->GetActiveWebContents();
|
| + AutofillDriverImpl* autofill_driver =
|
| + AutofillDriverImpl::FromWebContents(web_contents);
|
| + return static_cast<TestAutofillExternalDelegate*>(
|
| + autofill_driver->autofill_external_delegate());
|
| +}
|
|
|
| - void ExpectFilledTestForm() {
|
| - ExpectFieldValue("firstname", "Milton");
|
| - ExpectFieldValue("lastname", "Waddams");
|
| - ExpectFieldValue("address1", "4120 Freidrich Lane");
|
| - ExpectFieldValue("address2", "Basement");
|
| - ExpectFieldValue("city", "Austin");
|
| - ExpectFieldValue("state", "TX");
|
| - ExpectFieldValue("zip", "78744");
|
| - ExpectFieldValue("country", "US");
|
| - ExpectFieldValue("phone", "5125551234");
|
| - }
|
| +void AutofillInteractiveTest::CreateTestProfile() {
|
| + AutofillProfile profile;
|
| + test::SetProfileInfo(
|
| + &profile, "Milton", "C.", "Waddams",
|
| + "red.swingline@initech.com", "Initech", "4120 Freidrich Lane",
|
| + "Basement", "Austin", "Texas", "78744", "US", "5125551234");
|
|
|
| - void SendKeyToPageAndWait(ui::KeyboardCode key) {
|
| - test_delegate_.Reset();
|
| - content::SimulateKeyPress(
|
| - browser()->tab_strip_model()->GetActiveWebContents(),
|
| - key, false, false, false, false);
|
| - test_delegate_.Wait();
|
| - }
|
| + WindowedPersonalDataManagerObserver observer(browser());
|
| + GetPersonalDataManager()->AddProfile(profile);
|
|
|
| - void SendKeyToPopupAndWait(ui::KeyboardCode key) {
|
| - // TODO(isherman): Remove this condition once the WebKit popup UI code is
|
| - // removed.
|
| - if (!external_delegate()) {
|
| - // When testing the WebKit-based UI, route all keys to the page.
|
| - SendKeyToPageAndWait(key);
|
| - return;
|
| - }
|
| + // AddProfile is asynchronous. Wait for it to finish before continuing the
|
| + // tests.
|
| + observer.Wait();
|
| +}
|
|
|
| - // When testing the native UI, route popup-targeted key presses via the
|
| - // external delegate.
|
| - content::NativeWebKeyboardEvent event;
|
| - event.windowsKeyCode = key;
|
| - test_delegate_.Reset();
|
| - external_delegate()->keyboard_listener()->HandleKeyPressEvent(event);
|
| - test_delegate_.Wait();
|
| - }
|
| +void AutofillInteractiveTest::ExpectFieldValue(
|
| + const std::string& field_name,
|
| + const std::string& expected_value) {
|
| + std::string value;
|
| + ASSERT_TRUE(content::ExecuteScriptAndExtractString(
|
| + browser()->tab_strip_model()->GetActiveWebContents(),
|
| + "window.domAutomationController.send("
|
| + " document.getElementById('" + field_name + "').value);",
|
| + &value));
|
| + EXPECT_EQ(expected_value, value);
|
| +}
|
|
|
| - TestAutofillExternalDelegate* external_delegate() {
|
| - content::WebContents* web_contents =
|
| - browser()->tab_strip_model()->GetActiveWebContents();
|
| - AutofillDriverImpl* autofill_driver =
|
| - AutofillDriverImpl::FromWebContents(web_contents);
|
| - return static_cast<TestAutofillExternalDelegate*>(
|
| - autofill_driver->autofill_external_delegate());
|
| +void AutofillInteractiveTest::FocusFirstNameField() {
|
| + LOG(WARNING) << "Clicking on the tab.";
|
| + content::SimulateMouseClick(
|
| + browser()->tab_strip_model()->GetActiveWebContents(),
|
| + 0,
|
| + WebKit::WebMouseEvent::ButtonLeft);
|
| +
|
| + LOG(WARNING) << "Focusing the first name field.";
|
| + bool result = false;
|
| + ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
|
| + GetRenderViewHost(),
|
| + "if (document.readyState === 'complete')"
|
| + " document.getElementById('firstname').focus();"
|
| + "else"
|
| + " domAutomationController.send(false);",
|
| + &result));
|
| + ASSERT_TRUE(result);
|
| +}
|
| +
|
| +void AutofillInteractiveTest::ExpectFilledTestForm() {
|
| + ExpectFieldValue("firstname", "Milton");
|
| + ExpectFieldValue("lastname", "Waddams");
|
| + ExpectFieldValue("address1", "4120 Freidrich Lane");
|
| + ExpectFieldValue("address2", "Basement");
|
| + ExpectFieldValue("city", "Austin");
|
| + ExpectFieldValue("state", "TX");
|
| + ExpectFieldValue("zip", "78744");
|
| + ExpectFieldValue("country", "US");
|
| + ExpectFieldValue("phone", "5125551234");
|
| +}
|
| +
|
| +void AutofillInteractiveTest::SendKeyToPageAndWait(ui::KeyboardCode key) {
|
| + test_delegate_.Reset();
|
| + content::SimulateKeyPress(
|
| + browser()->tab_strip_model()->GetActiveWebContents(),
|
| + key, false, false, false, false);
|
| + test_delegate_.Wait();
|
| +}
|
| +
|
| +void AutofillInteractiveTest::SendKeyToPopupAndWait(ui::KeyboardCode key) {
|
| + // TODO(isherman): Remove this condition once the WebKit popup UI code is
|
| + // removed.
|
| + if (!GetExternalDelegate()) {
|
| + // When testing the WebKit-based UI, route all keys to the page.
|
| + SendKeyToPageAndWait(key);
|
| + return;
|
| }
|
|
|
| - AutofillManagerTestDelegateImpl test_delegate_;
|
| -};
|
| + // When testing the native UI, route popup-targeted key presses via the
|
| + // external delegate.
|
| + content::NativeWebKeyboardEvent event;
|
| + event.windowsKeyCode = key;
|
| + test_delegate_.Reset();
|
| + GetExternalDelegate()->keyboard_listener()->HandleKeyPressEvent(event);
|
| + test_delegate_.Wait();
|
| +}
|
|
|
| +
|
| +// Actual tests ---------------------------------------------------------------
|
| +
|
| IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, DISABLED_AutofillSelectViaTab) {
|
| CreateTestProfile();
|
|
|
|
|