Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: components/autofill/core/browser/autofill_manager_unittest.cc

Issue 667043002: Add a flag to ignore autocomplete="off" for Autofill. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: fix MSVC error C4373 Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 14 matching lines...) Expand all
25 #include "components/autofill/core/browser/autofill_profile.h" 25 #include "components/autofill/core/browser/autofill_profile.h"
26 #include "components/autofill/core/browser/autofill_test_utils.h" 26 #include "components/autofill/core/browser/autofill_test_utils.h"
27 #include "components/autofill/core/browser/credit_card.h" 27 #include "components/autofill/core/browser/credit_card.h"
28 #include "components/autofill/core/browser/personal_data_manager.h" 28 #include "components/autofill/core/browser/personal_data_manager.h"
29 #include "components/autofill/core/browser/popup_item_ids.h" 29 #include "components/autofill/core/browser/popup_item_ids.h"
30 #include "components/autofill/core/browser/test_autofill_client.h" 30 #include "components/autofill/core/browser/test_autofill_client.h"
31 #include "components/autofill/core/browser/test_autofill_driver.h" 31 #include "components/autofill/core/browser/test_autofill_driver.h"
32 #include "components/autofill/core/browser/test_autofill_external_delegate.h" 32 #include "components/autofill/core/browser/test_autofill_external_delegate.h"
33 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" 33 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
34 #include "components/autofill/core/common/autofill_pref_names.h" 34 #include "components/autofill/core/common/autofill_pref_names.h"
35 #include "components/autofill/core/common/autofill_switches.h"
35 #include "components/autofill/core/common/form_data.h" 36 #include "components/autofill/core/common/form_data.h"
36 #include "components/autofill/core/common/form_field_data.h" 37 #include "components/autofill/core/common/form_field_data.h"
37 #include "grit/components_strings.h" 38 #include "grit/components_strings.h"
38 #include "testing/gmock/include/gmock/gmock.h" 39 #include "testing/gmock/include/gmock/gmock.h"
39 #include "testing/gtest/include/gtest/gtest.h" 40 #include "testing/gtest/include/gtest/gtest.h"
40 #include "ui/base/l10n/l10n_util.h" 41 #include "ui/base/l10n/l10n_util.h"
41 #include "ui/gfx/rect.h" 42 #include "ui/gfx/rect.h"
42 #include "url/gurl.h" 43 #include "url/gurl.h"
43 44
44 using base::ASCIIToUTF16; 45 using base::ASCIIToUTF16;
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 "", "", "", "", "", "", "", "", "", "", "", 352 "", "", "", "", "", "", "", "", "", "", "",
352 "Miku Hatsune", "4234567890654321", month, year, 353 "Miku Hatsune", "4234567890654321", month, year,
353 has_address_fields, true, true); 354 has_address_fields, true, true);
354 } 355 }
355 356
356 class MockAutocompleteHistoryManager : public AutocompleteHistoryManager { 357 class MockAutocompleteHistoryManager : public AutocompleteHistoryManager {
357 public: 358 public:
358 MockAutocompleteHistoryManager(AutofillDriver* driver, AutofillClient* client) 359 MockAutocompleteHistoryManager(AutofillDriver* driver, AutofillClient* client)
359 : AutocompleteHistoryManager(driver, client) {} 360 : AutocompleteHistoryManager(driver, client) {}
360 361
362 MOCK_METHOD8(OnGetAutocompleteSuggestions, void(
363 int query_id,
364 const base::string16& name,
365 const base::string16& prefix,
366 const std::string& form_control_type,
367 const std::vector<base::string16>& autofill_values,
368 const std::vector<base::string16>& autofill_labels,
369 const std::vector<base::string16>& autofill_icons,
370 const std::vector<int>& autofill_unique_ids));
361 MOCK_METHOD1(OnFormSubmitted, void(const FormData& form)); 371 MOCK_METHOD1(OnFormSubmitted, void(const FormData& form));
362 372
363 private: 373 private:
364 DISALLOW_COPY_AND_ASSIGN(MockAutocompleteHistoryManager); 374 DISALLOW_COPY_AND_ASSIGN(MockAutocompleteHistoryManager);
365 }; 375 };
366 376
367 class MockAutofillDriver : public TestAutofillDriver { 377 class MockAutofillDriver : public TestAutofillDriver {
368 public: 378 public:
369 MockAutofillDriver() {} 379 MockAutofillDriver() {}
370 380
(...skipping 2014 matching lines...) Expand 10 before | Expand all | Expand 10 after
2385 ASCIIToUTF16("Jason") 2395 ASCIIToUTF16("Jason")
2386 }; 2396 };
2387 base::string16 expected_labels[] = { base::string16(), base::string16()}; 2397 base::string16 expected_labels[] = { base::string16(), base::string16()};
2388 base::string16 expected_icons[] = { base::string16(), base::string16()}; 2398 base::string16 expected_icons[] = { base::string16(), base::string16()};
2389 int expected_unique_ids[] = {0, 0}; 2399 int expected_unique_ids[] = {0, 0};
2390 external_delegate_->CheckSuggestions( 2400 external_delegate_->CheckSuggestions(
2391 kDefaultPageID, arraysize(expected_values), expected_values, 2401 kDefaultPageID, arraysize(expected_values), expected_values,
2392 expected_labels, expected_icons, expected_unique_ids); 2402 expected_labels, expected_icons, expected_unique_ids);
2393 } 2403 }
2394 2404
2405 TEST_F(AutofillManagerTest, AutocompleteOffRespected) {
2406 TestAutofillClient client;
2407 autofill_manager_.reset(
2408 new TestAutofillManager(autofill_driver_.get(), &client, NULL));
2409 autofill_manager_->set_autofill_enabled(false);
2410 autofill_manager_->SetExternalDelegate(external_delegate_.get());
2411
2412 scoped_ptr<MockAutocompleteHistoryManager> autocomplete_history_manager;
2413 autocomplete_history_manager.reset(
2414 new MockAutocompleteHistoryManager(autofill_driver_.get(), &client));
2415 autofill_manager_->autocomplete_history_manager_ =
2416 autocomplete_history_manager.Pass();
2417 MockAutocompleteHistoryManager* m = static_cast<
2418 MockAutocompleteHistoryManager*>(
2419 autofill_manager_->autocomplete_history_manager_.get());
2420 EXPECT_CALL(*m,
2421 OnGetAutocompleteSuggestions(_, _, _, _, _, _, _, _)).Times(0);
2422
2423 // Set up our form data.
2424 FormData form;
2425 test::CreateTestAddressFormData(&form);
2426 std::vector<FormData> forms(1, form);
2427 FormsSeen(forms);
2428 FormFieldData* field = &form.fields[0];
2429 field->should_autocomplete = false;
2430 GetAutofillSuggestions(form, *field);
2431 }
2432
2433 // Duplicate of the above test with the ignore-autocomplete-off-autofill switch.
2434 TEST_F(AutofillManagerTest, AutocompleteOffRespectedWithFlag) {
2435 CommandLine::ForCurrentProcess()->AppendSwitch(
2436 switches::kIgnoreAutocompleteOffForAutofill);
2437
2438 TestAutofillClient client;
2439 autofill_manager_.reset(
2440 new TestAutofillManager(autofill_driver_.get(), &client, NULL));
2441 autofill_manager_->set_autofill_enabled(false);
2442 autofill_manager_->SetExternalDelegate(external_delegate_.get());
2443
2444 scoped_ptr<MockAutocompleteHistoryManager> autocomplete_history_manager;
2445 autocomplete_history_manager.reset(
2446 new MockAutocompleteHistoryManager(autofill_driver_.get(), &client));
2447 autofill_manager_->autocomplete_history_manager_ =
2448 autocomplete_history_manager.Pass();
2449 MockAutocompleteHistoryManager* m = static_cast<
2450 MockAutocompleteHistoryManager*>(
2451 autofill_manager_->autocomplete_history_manager_.get());
2452 EXPECT_CALL(*m,
2453 OnGetAutocompleteSuggestions(_, _, _, _, _, _, _, _)).Times(0);
2454
2455 // Set up our form data.
2456 FormData form;
2457 test::CreateTestAddressFormData(&form);
2458 std::vector<FormData> forms(1, form);
2459 FormsSeen(forms);
2460 FormFieldData* field = &form.fields[0];
2461 field->should_autocomplete = false;
2462 GetAutofillSuggestions(form, *field);
2463 }
2464
2395 // Test that we are able to save form data when forms are submitted and we only 2465 // Test that we are able to save form data when forms are submitted and we only
2396 // have server data for the field types. 2466 // have server data for the field types.
2397 TEST_F(AutofillManagerTest, FormSubmittedServerTypes) { 2467 TEST_F(AutofillManagerTest, FormSubmittedServerTypes) {
2398 // Set up our form data. 2468 // Set up our form data.
2399 FormData form; 2469 FormData form;
2400 test::CreateTestAddressFormData(&form); 2470 test::CreateTestAddressFormData(&form);
2401 2471
2402 // Simulate having seen this form on page load. 2472 // Simulate having seen this form on page load.
2403 // |form_structure| will be owned by |autofill_manager_|. 2473 // |form_structure| will be owned by |autofill_manager_|.
2404 TestFormStructure* form_structure = new TestFormStructure(form); 2474 TestFormStructure* form_structure = new TestFormStructure(form);
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
2912 test::CreateTestAddressFormData(&form); 2982 test::CreateTestAddressFormData(&form);
2913 std::vector<FormData> forms(1, form); 2983 std::vector<FormData> forms(1, form);
2914 FormsSeen(forms); 2984 FormsSeen(forms);
2915 const FormFieldData& field = form.fields[0]; 2985 const FormFieldData& field = form.fields[0];
2916 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() 2986 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery()
2917 2987
2918 EXPECT_TRUE(external_delegate_->on_query_seen()); 2988 EXPECT_TRUE(external_delegate_->on_query_seen());
2919 } 2989 }
2920 2990
2921 } // namespace autofill 2991 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_manager.cc ('k') | components/autofill/core/common/autofill_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698