| Index: chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa_browsertest.mm
|
| diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc b/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa_browsertest.mm
|
| similarity index 16%
|
| copy from chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc
|
| copy to chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa_browsertest.mm
|
| index 73f8f92a3a1498a9859bfbb018d1901027240ae9..99861daa4373b2110a37237789564871207927c6 100644
|
| --- a/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc
|
| +++ b/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa_browsertest.mm
|
| @@ -1,19 +1,18 @@
|
| -// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
| +#import "chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h"
|
|
|
| #include "base/bind.h"
|
| #include "base/message_loop.h"
|
| -#include "base/time.h"
|
| -#include "base/utf_string_conversions.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h"
|
| -#include "chrome/browser/ui/autofill/autofill_dialog_view.h"
|
| #include "chrome/browser/ui/browser.h"
|
| #include "chrome/browser/ui/tabs/tab_strip_model.h"
|
| #include "chrome/test/base/in_process_browser_test.h"
|
| -#include "components/autofill/browser/autofill_metrics.h"
|
| #include "components/autofill/common/form_data.h"
|
| -#include "components/autofill/common/form_field_data.h"
|
| +#include "content/public/browser/web_contents.h"
|
| +#include "content/public/browser/web_contents_view.h"
|
| #include "content/public/test/test_utils.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| @@ -23,83 +22,35 @@ namespace {
|
|
|
| void MockCallback(const FormStructure*, const std::string&) {}
|
|
|
| -class MockAutofillMetrics : public AutofillMetrics {
|
| - public:
|
| - MockAutofillMetrics()
|
| - : dialog_type_(static_cast<DialogType>(-1)),
|
| - dialog_dismissal_action_(
|
| - static_cast<AutofillMetrics::DialogDismissalAction>(-1)),
|
| - autocheckout_status_(
|
| - static_cast<AutofillMetrics::AutocheckoutCompletionStatus>(-1)) {}
|
| - virtual ~MockAutofillMetrics() {}
|
| -
|
| - // AutofillMetrics:
|
| - virtual void LogAutocheckoutDuration(
|
| - const base::TimeDelta& duration,
|
| - AutocheckoutCompletionStatus status) const OVERRIDE {
|
| - // Ignore constness for testing.
|
| - MockAutofillMetrics* mutable_this = const_cast<MockAutofillMetrics*>(this);
|
| - mutable_this->autocheckout_status_ = status;
|
| - }
|
| -
|
| - virtual void LogDialogUiDuration(
|
| - const base::TimeDelta& duration,
|
| - DialogType dialog_type,
|
| - DialogDismissalAction dismissal_action) const OVERRIDE {
|
| - // Ignore constness for testing.
|
| - MockAutofillMetrics* mutable_this = const_cast<MockAutofillMetrics*>(this);
|
| - mutable_this->dialog_type_ = dialog_type;
|
| - mutable_this->dialog_dismissal_action_ = dismissal_action;
|
| - }
|
| -
|
| - DialogType dialog_type() const { return dialog_type_; }
|
| - AutofillMetrics::DialogDismissalAction dialog_dismissal_action() const {
|
| - return dialog_dismissal_action_;
|
| - }
|
| -
|
| - AutofillMetrics::AutocheckoutCompletionStatus autocheckout_status() const {
|
| - return autocheckout_status_;
|
| - }
|
| -
|
| - private:
|
| - DialogType dialog_type_;
|
| - AutofillMetrics::DialogDismissalAction dialog_dismissal_action_;
|
| - AutofillMetrics::AutocheckoutCompletionStatus autocheckout_status_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics);
|
| -};
|
| -
|
| class TestAutofillDialogController : public AutofillDialogControllerImpl {
|
| public:
|
| - TestAutofillDialogController(content::WebContents* contents,
|
| - const FormData& form_data,
|
| - const AutofillMetrics& metric_logger,
|
| - const DialogType dialog_type)
|
| + TestAutofillDialogController(
|
| + content::WebContents* contents,
|
| + const FormData& form_structure,
|
| + const AutofillMetrics& metric_logger,
|
| + scoped_refptr<content::MessageLoopRunner> runner,
|
| + const DialogType dialog_type)
|
| : AutofillDialogControllerImpl(contents,
|
| - form_data,
|
| + form_structure,
|
| GURL(),
|
| dialog_type,
|
| - base::Bind(&MockCallback)),
|
| - metric_logger_(metric_logger) {
|
| + base::Bind(MockCallback)),
|
| + metric_logger_(metric_logger) ,
|
| + runner_(runner) {
|
| DisableWallet();
|
| }
|
|
|
| virtual ~TestAutofillDialogController() {}
|
|
|
| virtual void ViewClosed() OVERRIDE {
|
| + DCHECK(runner_);
|
| AutofillDialogControllerImpl::ViewClosed();
|
| - MessageLoop::current()->Quit();
|
| - }
|
| -
|
| - virtual bool InputIsValid(AutofillFieldType type,
|
| - const string16& value) const OVERRIDE {
|
| - return true;
|
| + runner_->Quit();
|
| }
|
|
|
| - virtual std::vector<AutofillFieldType> InputsAreValid(
|
| - const DetailOutputMap& inputs,
|
| - ValidationType validation_type) const OVERRIDE {
|
| - return std::vector<AutofillFieldType>();
|
| + void RunMessageLoop() {
|
| + DCHECK(runner_);
|
| + runner_->Run();
|
| }
|
|
|
| // Increase visibility for testing.
|
| @@ -112,142 +63,51 @@ class TestAutofillDialogController : public AutofillDialogControllerImpl {
|
| }
|
|
|
| const AutofillMetrics& metric_logger_;
|
| + scoped_refptr<content::MessageLoopRunner> runner_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController);
|
| };
|
|
|
| -} // namespace
|
| -
|
| -class AutofillDialogControllerTest : public InProcessBrowserTest {
|
| +class AutofillDialogCocoaBrowserTest : public InProcessBrowserTest {
|
| public:
|
| - AutofillDialogControllerTest() {}
|
| - virtual ~AutofillDialogControllerTest() {}
|
| -
|
| - content::WebContents* GetActiveWebContents() {
|
| - return browser()->tab_strip_model()->GetActiveWebContents();
|
| + AutofillDialogCocoaBrowserTest() : InProcessBrowserTest() {}
|
| +
|
| + virtual ~AutofillDialogCocoaBrowserTest() {}
|
| +
|
| + virtual void SetUpOnMainThread() OVERRIDE {
|
| + FormFieldData field;
|
| + field.autocomplete_attribute = "cc-number";
|
| + FormData form_data;
|
| + form_data.fields.push_back(field);
|
| + runner_ = new content::MessageLoopRunner;
|
| + controller_ = new TestAutofillDialogController(
|
| + browser()->tab_strip_model()->GetActiveWebContents(),
|
| + form_data,
|
| + metric_logger_,
|
| + runner_,
|
| + DIALOG_TYPE_REQUEST_AUTOCOMPLETE);
|
| }
|
|
|
| - private:
|
| - DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerTest);
|
| -};
|
| -
|
| -// TODO(isherman): Enable this test on other platforms once the UI is
|
| -// implemented on those platforms.
|
| -#if defined(TOOLKIT_VIEWS)
|
| -#define MAYBE_RequestAutocompleteUiDurationMetrics \
|
| - RequestAutocompleteUiDurationMetrics
|
| -#else
|
| -#define MAYBE_RequestAutocompleteUiDurationMetrics \
|
| - DISABLED_RequestAutocompleteUiDurationMetrics
|
| -#endif // defined(TOOLKIT_VIEWS)
|
| -IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest,
|
| - MAYBE_RequestAutocompleteUiDurationMetrics) {
|
| - FormData form;
|
| - form.name = ASCIIToUTF16("TestForm");
|
| - form.method = ASCIIToUTF16("POST");
|
| - form.origin = GURL("http://example.com/form.html");
|
| - form.action = GURL("http://example.com/submit.html");
|
| - form.user_submitted = true;
|
| -
|
| - FormFieldData field;
|
| - field.autocomplete_attribute = "email";
|
| - form.fields.push_back(field);
|
| -
|
| - // Submit the form data.
|
| - {
|
| - MockAutofillMetrics metric_logger;
|
| - TestAutofillDialogController* dialog_controller =
|
| - new TestAutofillDialogController(
|
| - GetActiveWebContents(), form, metric_logger,
|
| - DIALOG_TYPE_REQUEST_AUTOCOMPLETE);
|
| - dialog_controller->Show();
|
| - dialog_controller->view()->SubmitForTesting();
|
| -
|
| - content::RunMessageLoop();
|
| -
|
| - EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED,
|
| - metric_logger.dialog_dismissal_action());
|
| - EXPECT_EQ(DIALOG_TYPE_REQUEST_AUTOCOMPLETE, metric_logger.dialog_type());
|
| - }
|
| -
|
| - // Cancel out of the dialog.
|
| - {
|
| - MockAutofillMetrics metric_logger;
|
| - TestAutofillDialogController* dialog_controller =
|
| - new TestAutofillDialogController(
|
| - GetActiveWebContents(), form, metric_logger,
|
| - DIALOG_TYPE_AUTOCHECKOUT);
|
| - dialog_controller->Show();
|
| - dialog_controller->view()->CancelForTesting();
|
| -
|
| - content::RunMessageLoop();
|
| -
|
| - EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED,
|
| - metric_logger.dialog_dismissal_action());
|
| - EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger.dialog_type());
|
| - }
|
| -
|
| - // Take some other action that dismisses the dialog.
|
| - {
|
| - MockAutofillMetrics metric_logger;
|
| - TestAutofillDialogController* dialog_controller =
|
| - new TestAutofillDialogController(
|
| - GetActiveWebContents(), form, metric_logger,
|
| - DIALOG_TYPE_AUTOCHECKOUT);
|
| - dialog_controller->Show();
|
| - dialog_controller->Hide();
|
| -
|
| - content::RunMessageLoop();
|
| -
|
| - EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED,
|
| - metric_logger.dialog_dismissal_action());
|
| - EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger.dialog_type());
|
| - }
|
| -
|
| - // Test Autocheckout success metrics.
|
| - {
|
| - MockAutofillMetrics metric_logger;
|
| - TestAutofillDialogController* dialog_controller =
|
| - new TestAutofillDialogController(
|
| - GetActiveWebContents(), form, metric_logger,
|
| - DIALOG_TYPE_AUTOCHECKOUT);
|
| - dialog_controller->Show();
|
| - dialog_controller->view()->SubmitForTesting();
|
| -
|
| - EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED,
|
| - metric_logger.dialog_dismissal_action());
|
| - EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger.dialog_type());
|
| + TestAutofillDialogController* controller() { return controller_; }
|
|
|
| - dialog_controller->Hide();
|
| -
|
| - content::RunMessageLoop();
|
| -
|
| - EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_SUCCEEDED,
|
| - metric_logger.autocheckout_status());
|
| - }
|
| -
|
| - // Test Autocheckout failure metric.
|
| - {
|
| - MockAutofillMetrics metric_logger;
|
| - TestAutofillDialogController* dialog_controller =
|
| - new TestAutofillDialogController(
|
| - GetActiveWebContents(), form, metric_logger,
|
| - DIALOG_TYPE_AUTOCHECKOUT);
|
| - dialog_controller->Show();
|
| - dialog_controller->view()->SubmitForTesting();
|
| + private:
|
| + // The controller owns itself.
|
| + TestAutofillDialogController* controller_;
|
|
|
| - EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED,
|
| - metric_logger.dialog_dismissal_action());
|
| - EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger.dialog_type());
|
| + // The following members must outlive the controller.
|
| + AutofillMetrics metric_logger_;
|
| + scoped_refptr<content::MessageLoopRunner> runner_;
|
|
|
| - dialog_controller->OnAutocheckoutError();
|
| - dialog_controller->view()->CancelForTesting();
|
| + DISALLOW_COPY_AND_ASSIGN(AutofillDialogCocoaBrowserTest);
|
| +};
|
|
|
| - content::RunMessageLoop();
|
| +IN_PROC_BROWSER_TEST_F(AutofillDialogCocoaBrowserTest, DisplayUI) {
|
| + controller()->Show();
|
| + controller()->view()->CancelForTesting();
|
|
|
| - EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_FAILED,
|
| - metric_logger.autocheckout_status());
|
| - }
|
| + controller()->RunMessageLoop();
|
| }
|
|
|
| -} // namespace autofill
|
| +} // namespace
|
| +
|
| +} // namespace autofill
|
|
|