Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / components / autofill / core / browser / autofill_manager_unittest.cc
index aba6c08..861ca23 100644 (file)
 #include "base/memory/ref_counted.h"
 #include "base/memory/scoped_ptr.h"
 #include "base/memory/scoped_vector.h"
+#include "base/message_loop/message_loop.h"
 #include "base/prefs/pref_service.h"
+#include "base/run_loop.h"
 #include "base/strings/string16.h"
 #include "base/strings/string_number_conversions.h"
 #include "base/strings/stringprintf.h"
 #include "base/strings/utf_string_conversions.h"
 #include "base/time/time.h"
 #include "base/tuple.h"
-#include "chrome/browser/autofill/personal_data_manager_factory.h"
-#include "chrome/browser/password_manager/chrome_password_manager_client.h"
-#include "chrome/browser/password_manager/password_manager.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/sync/profile_sync_service.h"
-#include "chrome/browser/sync/profile_sync_service_factory.h"
-#include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h"
-#include "chrome/test/base/chrome_render_view_host_test_harness.h"
-#include "chrome/test/base/testing_profile.h"
 #include "components/autofill/core/browser/autocomplete_history_manager.h"
 #include "components/autofill/core/browser/autofill_manager.h"
 #include "components/autofill/core/browser/autofill_metrics.h"
 #include "components/autofill/core/browser/autofill_test_utils.h"
 #include "components/autofill/core/browser/credit_card.h"
 #include "components/autofill/core/browser/personal_data_manager.h"
+#include "components/autofill/core/browser/popup_item_ids.h"
+#include "components/autofill/core/browser/test_autofill_client.h"
 #include "components/autofill/core/browser/test_autofill_driver.h"
 #include "components/autofill/core/browser/test_autofill_external_delegate.h"
-#include "components/autofill/core/browser/test_autofill_manager_delegate.h"
 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
 #include "components/autofill/core/common/autofill_pref_names.h"
 #include "components/autofill/core/common/form_data.h"
 #include "components/autofill/core/common/form_field_data.h"
-#include "components/autofill/core/common/forms_seen_state.h"
-#include "components/user_prefs/user_prefs.h"
-#include "content/public/test/mock_render_process_host.h"
-#include "content/public/test/test_utils.h"
-#include "grit/component_strings.h"
+#include "grit/components_strings.h"
 #include "testing/gmock/include/gmock/gmock.h"
 #include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/WebKit/public/web/WebAutofillClient.h"
 #include "ui/base/l10n/l10n_util.h"
 #include "ui/gfx/rect.h"
 #include "url/gurl.h"
 
 using base::ASCIIToUTF16;
 using base::UTF8ToUTF16;
-using content::WebContents;
 using testing::_;
 
 namespace autofill {
@@ -63,8 +51,6 @@ typedef PersonalDataManager::GUIDPair GUIDPair;
 
 namespace {
 
-// The page ID sent to the AutofillManager from the RenderView, used to send
-// an IPC message back to the renderer.
 const int kDefaultPageID = 137;
 
 class TestPersonalDataManager : public PersonalDataManager {
@@ -75,12 +61,7 @@ class TestPersonalDataManager : public PersonalDataManager {
   }
 
   using PersonalDataManager::set_database;
-  using PersonalDataManager::set_pref_service;
-
-  // Factory method for keyed service.  PersonalDataManager is NULL for testing.
-  static BrowserContextKeyedService* Build(content::BrowserContext* profile) {
-    return NULL;
-  }
+  using PersonalDataManager::SetPrefService;
 
   MOCK_METHOD1(SaveImportedProfile, std::string(const AutofillProfile&));
 
@@ -128,7 +109,7 @@ class TestPersonalDataManager : public PersonalDataManager {
 
   // Do nothing (auxiliary profiles will be created in
   // CreateTestAuxiliaryProfile).
-  virtual void LoadAuxiliaryProfiles() const OVERRIDE {}
+  virtual void LoadAuxiliaryProfiles(bool record_metrics) const OVERRIDE {}
 
   void ClearAutofillProfiles() {
     web_profiles_.clear();
@@ -207,7 +188,6 @@ void CreateTestCreditCardFormData(FormData* form,
                                   bool is_https,
                                   bool use_month_type) {
   form->name = ASCIIToUTF16("MyForm");
-  form->method = ASCIIToUTF16("POST");
   if (is_https) {
     form->origin = GURL("https://myform.com/form.html");
     form->action = GURL("https://myform.com/submit.html");
@@ -277,7 +257,6 @@ void ExpectFilledForm(int page_id,
 
   EXPECT_EQ(expected_page_id, page_id);
   EXPECT_EQ(ASCIIToUTF16("MyForm"), filled_form.name);
-  EXPECT_EQ(ASCIIToUTF16("POST"), filled_form.method);
   if (has_credit_card_fields) {
     EXPECT_EQ(GURL("https://myform.com/form.html"), filled_form.origin);
     EXPECT_EQ(GURL("https://myform.com/submit.html"), filled_form.action);
@@ -378,9 +357,8 @@ void ExpectFilledCreditCardYearMonthWithYearMonth(int page_id,
 
 class MockAutocompleteHistoryManager : public AutocompleteHistoryManager {
  public:
-  MockAutocompleteHistoryManager(AutofillDriver* driver,
-                                 AutofillManagerDelegate* delegate)
-      : AutocompleteHistoryManager(driver, delegate) {}
+  MockAutocompleteHistoryManager(AutofillDriver* driver, AutofillClient* client)
+      : AutocompleteHistoryManager(driver, client) {}
 
   MOCK_METHOD1(OnFormSubmitted, void(const FormData& form));
 
@@ -393,7 +371,8 @@ class MockAutofillDriver : public TestAutofillDriver {
   MockAutofillDriver() {}
 
   // Mock methods to enable testability.
-  MOCK_METHOD2(SendFormDataToRenderer, void(int query_id,
+  MOCK_METHOD3(SendFormDataToRenderer, void(int query_id,
+                                            RendererFormDataAction action,
                                             const FormData& data));
 
  private:
@@ -403,9 +382,9 @@ class MockAutofillDriver : public TestAutofillDriver {
 class TestAutofillManager : public AutofillManager {
  public:
   TestAutofillManager(AutofillDriver* driver,
-                      autofill::AutofillManagerDelegate* delegate,
+                      autofill::AutofillClient* client,
                       TestPersonalDataManager* personal_data)
-      : AutofillManager(driver, delegate, personal_data),
+      : AutofillManager(driver, client, personal_data),
         personal_data_(personal_data),
         autofill_enabled_(true) {}
   virtual ~TestAutofillManager() {}
@@ -426,7 +405,7 @@ class TestAutofillManager : public AutofillManager {
       const base::TimeTicks& load_time,
       const base::TimeTicks& interaction_time,
       const base::TimeTicks& submission_time) OVERRIDE {
-    message_loop_runner_->Quit();
+    run_loop_->Quit();
 
     // If we have expected field types set, make sure they match.
     if (!expected_submitted_field_types_.empty()) {
@@ -456,16 +435,12 @@ class TestAutofillManager : public AutofillManager {
                                                  submission_time);
   }
 
-  // Resets the MessageLoopRunner so that it can wait for an asynchronous form
+  // Resets the run loop so that it can wait for an asynchronous form
   // submission to complete.
-  void ResetMessageLoopRunner() {
-    message_loop_runner_ = new content::MessageLoopRunner();
-  }
+  void ResetRunLoop() { run_loop_.reset(new base::RunLoop()); }
 
   // Wait for the asynchronous OnFormSubmitted() call to complete.
-  void WaitForAsyncFormSubmit() {
-    message_loop_runner_->Run();
-  }
+  void WaitForAsyncFormSubmit() { run_loop_->Run(); }
 
   virtual void UploadFormData(const FormStructure& submitted_form) OVERRIDE {
     submitted_form_signature_ = submitted_form.FormSignature();
@@ -512,7 +487,7 @@ class TestAutofillManager : public AutofillManager {
 
   bool autofill_enabled_;
 
-  scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
+  scoped_ptr<base::RunLoop> run_loop_;
 
   std::string submitted_form_signature_;
   std::vector<ServerFieldTypeSet> expected_submitted_field_types_;
@@ -522,8 +497,7 @@ class TestAutofillManager : public AutofillManager {
 
 class TestAutofillExternalDelegate : public AutofillExternalDelegate {
  public:
-  explicit TestAutofillExternalDelegate(content::WebContents* web_contents,
-                                        AutofillManager* autofill_manager,
+  explicit TestAutofillExternalDelegate(AutofillManager* autofill_manager,
                                         AutofillDriver* autofill_driver)
       : AutofillExternalDelegate(autofill_manager, autofill_driver),
         on_query_seen_(false),
@@ -607,26 +581,17 @@ class TestAutofillExternalDelegate : public AutofillExternalDelegate {
 
 }  // namespace
 
-class AutofillManagerTest : public ChromeRenderViewHostTestHarness {
+class AutofillManagerTest : public testing::Test {
  public:
   virtual void SetUp() OVERRIDE {
-    ChromeRenderViewHostTestHarness::SetUp();
-
-    autofill::PersonalDataManagerFactory::GetInstance()->SetTestingFactory(
-        profile(), TestPersonalDataManager::Build);
-
-    autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents());
-
-    autofill::TabAutofillManagerDelegate* manager_delegate =
-        autofill::TabAutofillManagerDelegate::FromWebContents(web_contents());
-    personal_data_.set_database(manager_delegate->GetDatabase());
-    personal_data_.set_pref_service(profile()->GetPrefs());
+    autofill_client_.SetPrefs(test::PrefServiceForTesting());
+    personal_data_.set_database(autofill_client_.GetDatabase());
+    personal_data_.SetPrefService(autofill_client_.GetPrefs());
     autofill_driver_.reset(new MockAutofillDriver());
     autofill_manager_.reset(new TestAutofillManager(
-        autofill_driver_.get(), manager_delegate, &personal_data_));
+        autofill_driver_.get(), &autofill_client_, &personal_data_));
 
     external_delegate_.reset(new TestAutofillExternalDelegate(
-        web_contents(),
         autofill_manager_.get(),
         autofill_driver_.get()));
     autofill_manager_->SetExternalDelegate(external_delegate_.get());
@@ -634,16 +599,14 @@ class AutofillManagerTest : public ChromeRenderViewHostTestHarness {
 
   virtual void TearDown() OVERRIDE {
     // Order of destruction is important as AutofillManager relies on
-    // PersonalDataManager to be around when it gets destroyed. Also, a real
-    // AutofillManager is tied to the lifetime of the WebContents, so it must
-    // be destroyed at the destruction of the WebContents.
+    // PersonalDataManager to be around when it gets destroyed.
     autofill_manager_.reset();
     autofill_driver_.reset();
-    ChromeRenderViewHostTestHarness::TearDown();
 
     // Remove the AutofillWebDataService so TestPersonalDataManager does not
     // need to care about removing self as an observer in destruction.
     personal_data_.set_database(scoped_refptr<AutofillWebDataService>(NULL));
+    personal_data_.SetPrefService(NULL);
   }
 
   void GetAutofillSuggestions(int query_id,
@@ -667,22 +630,11 @@ class AutofillManagerTest : public ChromeRenderViewHostTestHarness {
   }
 
   void FormsSeen(const std::vector<FormData>& forms) {
-    autofill_manager_->OnFormsSeen(forms, base::TimeTicks(),
-                                   autofill::NO_SPECIAL_FORMS_SEEN);
-  }
-
-  void PartialFormsSeen(const std::vector<FormData>& forms) {
-    autofill_manager_->OnFormsSeen(forms, base::TimeTicks(),
-                                   autofill::PARTIAL_FORMS_SEEN);
-  }
-
-  void DynamicFormsSeen(const std::vector<FormData>& forms) {
-    autofill_manager_->OnFormsSeen(forms, base::TimeTicks(),
-                                   autofill::DYNAMIC_FORMS_SEEN);
+    autofill_manager_->OnFormsSeen(forms, base::TimeTicks());
   }
 
   void FormSubmitted(const FormData& form) {
-    autofill_manager_->ResetMessageLoopRunner();
+    autofill_manager_->ResetRunLoop();
     if (autofill_manager_->OnFormSubmitted(form, base::TimeTicks::Now()))
       autofill_manager_->WaitForAsyncFormSubmit();
   }
@@ -691,7 +643,9 @@ class AutofillManagerTest : public ChromeRenderViewHostTestHarness {
                             const FormData& form,
                             const FormFieldData& field,
                             int unique_id) {
-    autofill_manager_->OnFillAutofillFormData(query_id, form, field, unique_id);
+    autofill_manager_->FillOrPreviewForm(
+        AutofillDriver::FORM_DATA_ACTION_FILL, query_id, form, field,
+        unique_id);
   }
 
   // Calls |autofill_manager_->OnFillAutofillFormData()| with the specified
@@ -705,9 +659,9 @@ class AutofillManagerTest : public ChromeRenderViewHostTestHarness {
                                           int unique_id,
                                           int* response_query_id,
                                           FormData* response_data) {
-    EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _)).
+    EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _, _)).
         WillOnce((DoAll(testing::SaveArg<0>(response_query_id),
-                        testing::SaveArg<1>(response_data))));
+                        testing::SaveArg<2>(response_data))));
     FillAutofillFormData(input_query_id, input_form, input_field, unique_id);
   }
 
@@ -716,14 +670,12 @@ class AutofillManagerTest : public ChromeRenderViewHostTestHarness {
   }
 
  protected:
+  base::MessageLoop message_loop_;
+  TestAutofillClient autofill_client_;
   scoped_ptr<MockAutofillDriver> autofill_driver_;
   scoped_ptr<TestAutofillManager> autofill_manager_;
   scoped_ptr<TestAutofillExternalDelegate> external_delegate_;
   TestPersonalDataManager personal_data_;
-
-  // Used when we want an off the record profile. This will store the original
-  // profile from which the off the record profile is derived.
-  scoped_ptr<Profile> other_browser_context_;
 };
 
 class TestFormStructure : public FormStructure {
@@ -817,7 +769,6 @@ TEST_F(AutofillManagerTest, GetProfileSuggestionsUnknownFields) {
   // Set up our form data.
   FormData form;
   form.name = ASCIIToUTF16("MyForm");
-  form.method = ASCIIToUTF16("POST");
   form.origin = GURL("http://myform.com/form.html");
   form.action = GURL("http://myform.com/submit.html");
   form.user_submitted = true;
@@ -893,65 +844,6 @@ TEST_F(AutofillManagerTest, GetProfileSuggestionsAutofillDisabledByUser) {
   EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen());
 }
 
-// Test that we return a warning explaining that autofill suggestions are
-// unavailable when the form method is GET rather than POST.
-TEST_F(AutofillManagerTest, GetProfileSuggestionsMethodGet) {
-  // Set up our form data.
-  FormData form;
-  test::CreateTestAddressFormData(&form);
-  form.method = ASCIIToUTF16("GET");
-  std::vector<FormData> forms(1, form);
-  FormsSeen(forms);
-
-  const FormFieldData& field = form.fields[0];
-  GetAutofillSuggestions(form, field);
-
-  // No suggestions provided, so send an empty vector as the results.
-  // This triggers the combined message send.
-  AutocompleteSuggestionsReturned(std::vector<base::string16>());
-
-  // Test that we sent the right values to the external delegate.
-  base::string16 expected_values[] = {
-    l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED)
-  };
-  base::string16 expected_labels[] = {base::string16()};
-  base::string16 expected_icons[] = {base::string16()};
-  int expected_unique_ids[] =
-      {blink::WebAutofillClient::MenuItemIDWarningMessage};
-  external_delegate_->CheckSuggestions(
-      kDefaultPageID, arraysize(expected_values), expected_values,
-      expected_labels, expected_icons, expected_unique_ids);
-
-  // Now add some Autocomplete suggestions. We should return the autocomplete
-  // suggestions and the warning; these will be culled by the renderer.
-  const int kPageID2 = 2;
-  GetAutofillSuggestions(kPageID2, form, field);
-
-  std::vector<base::string16> suggestions;
-  suggestions.push_back(ASCIIToUTF16("Jay"));
-  suggestions.push_back(ASCIIToUTF16("Jason"));
-  AutocompleteSuggestionsReturned(suggestions);
-
-  base::string16 expected_values2[] = {
-    l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED),
-    ASCIIToUTF16("Jay"),
-    ASCIIToUTF16("Jason")
-  };
-  base::string16 expected_labels2[] = { base::string16(), base::string16(),
-                                        base::string16()};
-  base::string16 expected_icons2[] = { base::string16(), base::string16(),
-                                       base::string16()};
-  int expected_unique_ids2[] = {-1, 0, 0};
-  external_delegate_->CheckSuggestions(
-      kPageID2, arraysize(expected_values2), expected_values2,
-      expected_labels2, expected_icons2, expected_unique_ids2);
-
-  // Now clear the test profiles and try again -- we shouldn't return a warning.
-  personal_data_.ClearAutofillProfiles();
-  GetAutofillSuggestions(form, field);
-  EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen());
-}
-
 // Test that we return all credit card profile suggestions when all form fields
 // are empty.
 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsEmptyValue) {
@@ -973,8 +865,8 @@ TEST_F(AutofillManagerTest, GetCreditCardSuggestionsEmptyValue) {
     ASCIIToUTF16("************3456"),
     ASCIIToUTF16("************8765")
   };
-  base::string16 expected_labels[] = { ASCIIToUTF16("*3456"),
-                                       ASCIIToUTF16("*8765")};
+  base::string16 expected_labels[] = { ASCIIToUTF16("04/12"),
+                                       ASCIIToUTF16("10/14")};
   base::string16 expected_icons[] = {
     ASCIIToUTF16(kVisaCard),
     ASCIIToUTF16(kMasterCard)
@@ -1007,7 +899,7 @@ TEST_F(AutofillManagerTest, GetCreditCardSuggestionsMatchCharacter) {
 
   // Test that we sent the right values to the external delegate.
   base::string16 expected_values[] = {ASCIIToUTF16("************3456")};
-  base::string16 expected_labels[] = {ASCIIToUTF16("*3456")};
+  base::string16 expected_labels[] = {ASCIIToUTF16("04/12")};
   base::string16 expected_icons[] = {ASCIIToUTF16(kVisaCard)};
   int expected_unique_ids[] = {autofill_manager_->GetPackedCreditCardID(4)};
   external_delegate_->CheckSuggestions(
@@ -1116,7 +1008,7 @@ TEST_F(AutofillManagerTest, GetCreditCardSuggestionsRepeatedObfuscatedNumber) {
   CreditCard* credit_card = new CreditCard;
   test::SetCreditCardInfo(credit_card, "Elvis Presley",
                           "5231567890123456",  // Mastercard
-                          "04", "2012");
+                          "05", "2012");
   credit_card->set_guid("00000000-0000-0000-0000-000000000007");
   autofill_manager_->AddCreditCard(credit_card);
 
@@ -1140,9 +1032,9 @@ TEST_F(AutofillManagerTest, GetCreditCardSuggestionsRepeatedObfuscatedNumber) {
     ASCIIToUTF16("************3456")
   };
   base::string16 expected_labels[] = {
-    ASCIIToUTF16("*3456"),
-    ASCIIToUTF16("*8765"),
-    ASCIIToUTF16("*3456"),
+    ASCIIToUTF16("04/12"),
+    ASCIIToUTF16("10/14"),
+    ASCIIToUTF16("05/12"),
   };
   base::string16 expected_icons[] = {
     ASCIIToUTF16(kVisaCard),
@@ -1203,8 +1095,8 @@ TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestions) {
     ASCIIToUTF16("************3456"),
     ASCIIToUTF16("************8765")
   };
-  base::string16 expected_labels2[] = { ASCIIToUTF16("*3456"),
-                                        ASCIIToUTF16("*8765")};
+  base::string16 expected_labels2[] = { ASCIIToUTF16("04/12"),
+                                        ASCIIToUTF16("10/14")};
   base::string16 expected_icons2[] = {
     ASCIIToUTF16(kVisaCard),
     ASCIIToUTF16(kMasterCard)
@@ -1433,9 +1325,12 @@ TEST_F(AutofillManagerTest, GetFieldSuggestionsForMultiValuedProfileUnfilled) {
                        "", "", "", "", "", "", "");
   profile->set_guid("00000000-0000-0000-0000-000000000101");
   std::vector<base::string16> multi_values(2);
-  multi_values[0] = ASCIIToUTF16("Elvis Presley");
-  multi_values[1] = ASCIIToUTF16("Elena Love");
-  profile->SetRawMultiInfo(NAME_FULL, multi_values);
+  multi_values[0] = ASCIIToUTF16("Elvis");
+  multi_values[1] = ASCIIToUTF16("Elena");
+  profile->SetRawMultiInfo(NAME_FIRST, multi_values);
+  multi_values[0] = ASCIIToUTF16("Presley");
+  multi_values[1] = ASCIIToUTF16("Love");
+  profile->SetRawMultiInfo(NAME_LAST, multi_values);
   personal_data_.ClearAutofillProfiles();
   autofill_manager_->AddProfile(profile);
 
@@ -1501,10 +1396,14 @@ TEST_F(AutofillManagerTest, GetFieldSuggestionsForMultiValuedProfileFilled) {
   AutofillProfile* profile = new AutofillProfile;
   profile->set_guid("00000000-0000-0000-0000-000000000102");
   std::vector<base::string16> multi_values(3);
-  multi_values[0] = ASCIIToUTF16("Travis Smith");
-  multi_values[1] = ASCIIToUTF16("Cynthia Love");
-  multi_values[2] = ASCIIToUTF16("Zac Mango");
-  profile->SetRawMultiInfo(NAME_FULL, multi_values);
+  multi_values[0] = ASCIIToUTF16("Travis");
+  multi_values[1] = ASCIIToUTF16("Cynthia");
+  multi_values[2] = ASCIIToUTF16("Zac");
+  profile->SetRawMultiInfo(NAME_FIRST, multi_values);
+  multi_values[0] = ASCIIToUTF16("Smith");
+  multi_values[1] = ASCIIToUTF16("Love");
+  multi_values[2] = ASCIIToUTF16("Mango");
+  profile->SetRawMultiInfo(NAME_LAST, multi_values);
   autofill_manager_->AddProfile(profile);
 
   // Get the first name field.  And start out with "Travis", hoping for all the
@@ -1542,11 +1441,10 @@ TEST_F(AutofillManagerTest, GetProfileSuggestionsFancyPhone) {
 
   AutofillProfile* profile = new AutofillProfile;
   profile->set_guid("00000000-0000-0000-0000-000000000103");
-  std::vector<base::string16> multi_values(1);
-  multi_values[0] = ASCIIToUTF16("Natty Bumppo");
-  profile->SetRawMultiInfo(NAME_FULL, multi_values);
-  multi_values[0] = ASCIIToUTF16("1800PRAIRIE");
-  profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, multi_values);
+  profile->SetInfo(AutofillType(NAME_FULL), ASCIIToUTF16("Natty Bumppo"),
+                   "en-US");
+  profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER,
+                      ASCIIToUTF16("1800PRAIRIE"));
   autofill_manager_->AddProfile(profile);
 
   const FormFieldData& field = form.fields[9];
@@ -1598,8 +1496,14 @@ TEST_F(AutofillManagerTest, FillAddressForm) {
 // Test that we correctly fill an address form from an auxiliary profile.
 TEST_F(AutofillManagerTest, FillAddressFormFromAuxiliaryProfile) {
   personal_data_.ClearAutofillProfiles();
-  PrefService* prefs = user_prefs::UserPrefs::Get(profile());
-  prefs->SetBoolean(::autofill::prefs::kAutofillAuxiliaryProfilesEnabled, true);
+#if defined(OS_MACOSX) && !defined(OS_IOS)
+  autofill_client_.GetPrefs()->SetBoolean(
+      ::autofill::prefs::kAutofillUseMacAddressBook, true);
+#else
+  autofill_client_.GetPrefs()->SetBoolean(
+      ::autofill::prefs::kAutofillAuxiliaryProfilesEnabled, true);
+#endif  // defined(OS_MACOSX) && !defined(OS_IOS)
+
   personal_data_.CreateTestAuxiliaryProfiles();
 
   // Set up our form data.
@@ -1838,7 +1742,6 @@ TEST_F(AutofillManagerTest, FillFormWithAuthorSpecifiedSections) {
   // The billing section includes both address and credit card fields.
   FormData form;
   form.name = ASCIIToUTF16("MyForm");
-  form.method = ASCIIToUTF16("POST");
   form.origin = GURL("https://myform.com/form.html");
   form.action = GURL("https://myform.com/submit.html");
   form.user_submitted = true;
@@ -1903,7 +1806,6 @@ TEST_F(AutofillManagerTest, FillFormWithAuthorSpecifiedSections) {
     SCOPED_TRACE("Unnamed section");
     EXPECT_EQ(kDefaultPageID, response_page_id);
     EXPECT_EQ(ASCIIToUTF16("MyForm"), response_data.name);
-    EXPECT_EQ(ASCIIToUTF16("POST"), response_data.method);
     EXPECT_EQ(GURL("https://myform.com/form.html"), response_data.origin);
     EXPECT_EQ(GURL("https://myform.com/submit.html"), response_data.action);
     EXPECT_TRUE(response_data.user_submitted);
@@ -1935,7 +1837,6 @@ TEST_F(AutofillManagerTest, FillFormWithAuthorSpecifiedSections) {
     SCOPED_TRACE("Billing address");
     EXPECT_EQ(kPageID2, response_page_id);
     EXPECT_EQ(ASCIIToUTF16("MyForm"), response_data.name);
-    EXPECT_EQ(ASCIIToUTF16("POST"), response_data.method);
     EXPECT_EQ(GURL("https://myform.com/form.html"), response_data.origin);
     EXPECT_EQ(GURL("https://myform.com/submit.html"), response_data.action);
     EXPECT_TRUE(response_data.user_submitted);
@@ -1968,7 +1869,6 @@ TEST_F(AutofillManagerTest, FillFormWithAuthorSpecifiedSections) {
     SCOPED_TRACE("Credit card");
     EXPECT_EQ(kPageID3, response_page_id);
     EXPECT_EQ(ASCIIToUTF16("MyForm"), response_data.name);
-    EXPECT_EQ(ASCIIToUTF16("POST"), response_data.method);
     EXPECT_EQ(GURL("https://myform.com/form.html"), response_data.origin);
     EXPECT_EQ(GURL("https://myform.com/submit.html"), response_data.action);
     EXPECT_TRUE(response_data.user_submitted);
@@ -2090,12 +1990,21 @@ TEST_F(AutofillManagerTest, FillAddressFormWithVariantType) {
   // Add a name variant to the Elvis profile.
   AutofillProfile* profile = autofill_manager_->GetProfileWithGUID(
       "00000000-0000-0000-0000-000000000001");
-  const base::string16 elvis_name = profile->GetRawInfo(NAME_FULL);
 
   std::vector<base::string16> name_variants;
-  name_variants.push_back(ASCIIToUTF16("Some Other Guy"));
-  name_variants.push_back(elvis_name);
-  profile->SetRawMultiInfo(NAME_FULL, name_variants);
+  name_variants.push_back(ASCIIToUTF16("Some"));
+  name_variants.push_back(profile->GetRawInfo(NAME_FIRST));
+  profile->SetRawMultiInfo(NAME_FIRST, name_variants);
+
+  name_variants.clear();
+  name_variants.push_back(ASCIIToUTF16("Other"));
+  name_variants.push_back(profile->GetRawInfo(NAME_MIDDLE));
+  profile->SetRawMultiInfo(NAME_MIDDLE, name_variants);
+
+  name_variants.clear();
+  name_variants.push_back(ASCIIToUTF16("Guy"));
+  name_variants.push_back(profile->GetRawInfo(NAME_LAST));
+  profile->SetRawMultiInfo(NAME_LAST, name_variants);
 
   GUIDPair guid(profile->guid(), 1);
   GUIDPair empty(std::string(), 0);
@@ -2132,7 +2041,6 @@ TEST_F(AutofillManagerTest, FillPhoneNumber) {
   // In the other form, rely on the autocompletetype attribute.
   FormData form_with_maxlength;
   form_with_maxlength.name = ASCIIToUTF16("MyMaxlengthPhoneForm");
-  form_with_maxlength.method = ASCIIToUTF16("POST");
   form_with_maxlength.origin = GURL("http://myform.com/phone_form.html");
   form_with_maxlength.action = GURL("http://myform.com/phone_submit.html");
   form_with_maxlength.user_submitted = true;
@@ -2354,22 +2262,19 @@ TEST_F(AutofillManagerTest, FormSubmitted) {
 // Test that when Autocomplete is enabled and Autofill is disabled,
 // form submissions are still received by AutocompleteHistoryManager.
 TEST_F(AutofillManagerTest, FormSubmittedAutocompleteEnabled) {
-  TestAutofillManagerDelegate delegate;
-  autofill_manager_.reset(new TestAutofillManager(
-      autofill_driver_.get(),
-      &delegate,
-      NULL));
+  TestAutofillClient client;
+  autofill_manager_.reset(
+      new TestAutofillManager(autofill_driver_.get(), &client, NULL));
   autofill_manager_->set_autofill_enabled(false);
   scoped_ptr<MockAutocompleteHistoryManager> autocomplete_history_manager;
   autocomplete_history_manager.reset(
-      new MockAutocompleteHistoryManager(autofill_driver_.get(), &delegate));
+      new MockAutocompleteHistoryManager(autofill_driver_.get(), &client));
   autofill_manager_->autocomplete_history_manager_ =
       autocomplete_history_manager.Pass();
 
   // Set up our form data.
   FormData form;
   test::CreateTestAddressFormData(&form);
-  form.method = ASCIIToUTF16("GET");
   MockAutocompleteHistoryManager* m = static_cast<
       MockAutocompleteHistoryManager*>(
           autofill_manager_->autocomplete_history_manager_.get());
@@ -2381,18 +2286,15 @@ TEST_F(AutofillManagerTest, FormSubmittedAutocompleteEnabled) {
 // Test that when Autocomplete is enabled and Autofill is disabled,
 // Autocomplete suggestions are still received.
 TEST_F(AutofillManagerTest, AutocompleteSuggestionsWhenAutofillDisabled) {
-  TestAutofillManagerDelegate delegate;
-  autofill_manager_.reset(new TestAutofillManager(
-      autofill_driver_.get(),
-      &delegate,
-      NULL));
+  TestAutofillClient client;
+  autofill_manager_.reset(
+      new TestAutofillManager(autofill_driver_.get(), &client, NULL));
   autofill_manager_->set_autofill_enabled(false);
   autofill_manager_->SetExternalDelegate(external_delegate_.get());
 
   // Set up our form data.
   FormData form;
   test::CreateTestAddressFormData(&form);
-  form.method = ASCIIToUTF16("GET");
   std::vector<FormData> forms(1, form);
   FormsSeen(forms);
   const FormFieldData& field = form.fields[0];
@@ -2522,15 +2424,14 @@ TEST_F(AutofillManagerTest, FormSubmittedWithDefaultValues) {
 // Checks that resetting the auxiliary profile enabled preference does the right
 // thing on all platforms.
 TEST_F(AutofillManagerTest, AuxiliaryProfilesReset) {
-  PrefService* prefs = user_prefs::UserPrefs::Get(profile());
-#if defined(OS_MACOSX) || defined(OS_ANDROID)
-  // Auxiliary profiles is implemented on Mac and Android only.
-  // OSX: enables Mac Address Book integration.
-  // Android: enables integration with user's contact profile.
+  PrefService* prefs = autofill_client_.GetPrefs();
+#if defined(OS_MACOSX)
+  // Auxiliary profiles is implemented on Mac only.
+  // OSX: This preference exists for legacy reasons. It is no longer used.
   ASSERT_TRUE(
       prefs->GetBoolean(::autofill::prefs::kAutofillAuxiliaryProfilesEnabled));
-  prefs->SetBoolean(
-      ::autofill::prefs::kAutofillAuxiliaryProfilesEnabled, false);
+  prefs->SetBoolean(::autofill::prefs::kAutofillAuxiliaryProfilesEnabled,
+                    false);
   prefs->ClearPref(::autofill::prefs::kAutofillAuxiliaryProfilesEnabled);
   ASSERT_TRUE(
       prefs->GetBoolean(::autofill::prefs::kAutofillAuxiliaryProfilesEnabled));
@@ -2541,13 +2442,12 @@ TEST_F(AutofillManagerTest, AuxiliaryProfilesReset) {
   prefs->ClearPref(::autofill::prefs::kAutofillAuxiliaryProfilesEnabled);
   ASSERT_FALSE(
       prefs->GetBoolean(::autofill::prefs::kAutofillAuxiliaryProfilesEnabled));
-#endif
+#endif  // defined(OS_MACOSX)
 }
 
 TEST_F(AutofillManagerTest, DeterminePossibleFieldTypesForUpload) {
   FormData form;
   form.name = ASCIIToUTF16("MyForm");
-  form.method = ASCIIToUTF16("POST");
   form.origin = GURL("http://myform.com/form.html");
   form.action = GURL("http://myform.com/submit.html");
   form.user_submitted = true;
@@ -2882,17 +2782,20 @@ TEST_F(AutofillManagerTest, RemoveProfileVariant) {
 
 namespace {
 
-class MockAutofillManagerDelegate : public TestAutofillManagerDelegate {
+class MockAutofillClient : public TestAutofillClient {
  public:
-  MockAutofillManagerDelegate() {}
+  MockAutofillClient() {}
 
-  virtual ~MockAutofillManagerDelegate() {}
+  virtual ~MockAutofillClient() {}
 
   virtual void ShowRequestAutocompleteDialog(
       const FormData& form,
       const GURL& source_url,
-      const base::Callback<void(const FormStructure*)>& callback) OVERRIDE {
-    callback.Run(user_supplied_data_.get());
+      const ResultCallback& callback) OVERRIDE {
+    callback.Run(user_supplied_data_ ? AutocompleteResultSuccess :
+                                       AutocompleteResultErrorDisabled,
+                 base::string16(),
+                 user_supplied_data_.get());
   }
 
   void SetUserSuppliedData(scoped_ptr<FormStructure> user_supplied_data) {
@@ -2902,7 +2805,7 @@ class MockAutofillManagerDelegate : public TestAutofillManagerDelegate {
  private:
   scoped_ptr<FormStructure> user_supplied_data_;
 
DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate);
 DISALLOW_COPY_AND_ASSIGN(MockAutofillClient);
 };
 
 }  // namespace