1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_TEST_AUTOFILL_MANAGER_H_
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_TEST_AUTOFILL_MANAGER_H_
7 
8 #include <memory>
9 #include <string>
10 #include <utility>
11 #include <vector>
12 
13 #include "base/optional.h"
14 #include "base/run_loop.h"
15 #include "components/autofill/core/browser/autofill_manager.h"
16 
17 using base::TimeTicks;
18 
19 namespace autofill {
20 
21 class AutofillClient;
22 class AutofillDriver;
23 class FormStructure;
24 class TestPersonalDataManager;
25 class MockAutocompleteHistoryManager;
26 
27 class TestAutofillManager : public AutofillManager {
28  public:
29   TestAutofillManager(
30       AutofillDriver* driver,
31       AutofillClient* client,
32       TestPersonalDataManager* personal_data,
33       MockAutocompleteHistoryManager* autocomplete_history_manager);
34   ~TestAutofillManager() override;
35 
36   // AutofillManager overrides.
37   bool IsAutofillProfileEnabled() const override;
38   bool IsAutofillCreditCardEnabled() const override;
39   void UploadFormData(const FormStructure& submitted_form,
40                       bool observed_submission) override;
41   bool MaybeStartVoteUploadProcess(
42       std::unique_ptr<FormStructure> form_structure,
43       bool observed_submission) override;
44   void UploadFormDataAsyncCallback(const FormStructure* submitted_form,
45                                    const base::TimeTicks& interaction_time,
46                                    const base::TimeTicks& submission_time,
47                                    bool observed_submission) override;
48 
49   // Unique to TestAutofillManager:
50 
51   int GetPackedCreditCardID(int credit_card_id);
52 
53   void AddSeenForm(const FormData& form,
54                    const std::vector<ServerFieldType>& heuristic_types,
55                    const std::vector<ServerFieldType>& server_types);
56 
57   void AddSeenFormStructure(std::unique_ptr<FormStructure> form_structure);
58 
59   void ClearFormStructures();
60 
61   const std::string GetSubmittedFormSignature();
62 
63   void SetAutofillProfileEnabled(bool profile_enabled);
64 
65   void SetAutofillCreditCardEnabled(bool credit_card_enabled);
66 
67   void SetExpectedSubmittedFieldTypes(
68       const std::vector<ServerFieldTypeSet>& expected_types);
69 
70   void SetExpectedObservedSubmission(bool expected);
71 
72   void SetCallParentUploadFormData(bool value);
73 
74   using AutofillManager::is_rich_query_enabled;
75 
76  private:
77   TestPersonalDataManager* personal_data_;  // Weak reference.
78   bool autofill_profile_enabled_ = true;
79   bool autofill_credit_card_enabled_ = true;
80   bool call_parent_upload_form_data_ = false;
81   base::Optional<bool> expected_observed_submission_;
82 
83   std::unique_ptr<base::RunLoop> run_loop_;
84 
85   std::string submitted_form_signature_;
86   std::vector<ServerFieldTypeSet> expected_submitted_field_types_;
87 
88   DISALLOW_COPY_AND_ASSIGN(TestAutofillManager);
89 };
90 
91 }  // namespace autofill
92 
93 #endif  // COMPONENTS_AUTOFILL_CORE_BROWSER_TEST_AUTOFILL_MANAGER_H_
94