| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/autofill/autocomplete_history_manager.h" | 10 #include "chrome/browser/autofill/autocomplete_history_manager.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 form.method = ASCIIToUTF16("POST"); | 66 form.method = ASCIIToUTF16("POST"); |
| 67 form.origin = GURL("http://myform.com/form.html"); | 67 form.origin = GURL("http://myform.com/form.html"); |
| 68 form.action = GURL("http://myform.com/submit.html"); | 68 form.action = GURL("http://myform.com/submit.html"); |
| 69 form.user_submitted = true; | 69 form.user_submitted = true; |
| 70 | 70 |
| 71 // Valid Visa credit card number pulled from the paypal help site. | 71 // Valid Visa credit card number pulled from the paypal help site. |
| 72 FormFieldData valid_cc; | 72 FormFieldData valid_cc; |
| 73 valid_cc.label = ASCIIToUTF16("Credit Card"); | 73 valid_cc.label = ASCIIToUTF16("Credit Card"); |
| 74 valid_cc.name = ASCIIToUTF16("ccnum"); | 74 valid_cc.name = ASCIIToUTF16("ccnum"); |
| 75 valid_cc.value = ASCIIToUTF16("4012888888881881"); | 75 valid_cc.value = ASCIIToUTF16("4012888888881881"); |
| 76 valid_cc.form_control_type = ASCIIToUTF16("text"); | 76 valid_cc.form_control_type = "text"; |
| 77 form.fields.push_back(valid_cc); | 77 form.fields.push_back(valid_cc); |
| 78 | 78 |
| 79 EXPECT_CALL(*web_data_service_, AddFormFields(_)).Times(0); | 79 EXPECT_CALL(*web_data_service_, AddFormFields(_)).Times(0); |
| 80 autocomplete_manager_->OnFormSubmitted(form); | 80 autocomplete_manager_->OnFormSubmitted(form); |
| 81 } | 81 } |
| 82 | 82 |
| 83 // Contrary test to AutocompleteHistoryManagerTest.CreditCardNumberValue. The | 83 // Contrary test to AutocompleteHistoryManagerTest.CreditCardNumberValue. The |
| 84 // value being submitted is not a valid credit card number, so it will be sent | 84 // value being submitted is not a valid credit card number, so it will be sent |
| 85 // to the WebDatabase to be saved. | 85 // to the WebDatabase to be saved. |
| 86 TEST_F(AutocompleteHistoryManagerTest, NonCreditCardNumberValue) { | 86 TEST_F(AutocompleteHistoryManagerTest, NonCreditCardNumberValue) { |
| 87 FormData form; | 87 FormData form; |
| 88 form.name = ASCIIToUTF16("MyForm"); | 88 form.name = ASCIIToUTF16("MyForm"); |
| 89 form.method = ASCIIToUTF16("POST"); | 89 form.method = ASCIIToUTF16("POST"); |
| 90 form.origin = GURL("http://myform.com/form.html"); | 90 form.origin = GURL("http://myform.com/form.html"); |
| 91 form.action = GURL("http://myform.com/submit.html"); | 91 form.action = GURL("http://myform.com/submit.html"); |
| 92 form.user_submitted = true; | 92 form.user_submitted = true; |
| 93 | 93 |
| 94 // Invalid credit card number. | 94 // Invalid credit card number. |
| 95 FormFieldData invalid_cc; | 95 FormFieldData invalid_cc; |
| 96 invalid_cc.label = ASCIIToUTF16("Credit Card"); | 96 invalid_cc.label = ASCIIToUTF16("Credit Card"); |
| 97 invalid_cc.name = ASCIIToUTF16("ccnum"); | 97 invalid_cc.name = ASCIIToUTF16("ccnum"); |
| 98 invalid_cc.value = ASCIIToUTF16("4580123456789012"); | 98 invalid_cc.value = ASCIIToUTF16("4580123456789012"); |
| 99 invalid_cc.form_control_type = ASCIIToUTF16("text"); | 99 invalid_cc.form_control_type = "text"; |
| 100 form.fields.push_back(invalid_cc); | 100 form.fields.push_back(invalid_cc); |
| 101 | 101 |
| 102 EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1); | 102 EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1); |
| 103 autocomplete_manager_->OnFormSubmitted(form); | 103 autocomplete_manager_->OnFormSubmitted(form); |
| 104 } | 104 } |
| 105 | 105 |
| 106 // Tests that SSNs are not sent to the WebDatabase to be saved. | 106 // Tests that SSNs are not sent to the WebDatabase to be saved. |
| 107 TEST_F(AutocompleteHistoryManagerTest, SSNValue) { | 107 TEST_F(AutocompleteHistoryManagerTest, SSNValue) { |
| 108 FormData form; | 108 FormData form; |
| 109 form.name = ASCIIToUTF16("MyForm"); | 109 form.name = ASCIIToUTF16("MyForm"); |
| 110 form.method = ASCIIToUTF16("POST"); | 110 form.method = ASCIIToUTF16("POST"); |
| 111 form.origin = GURL("http://myform.com/form.html"); | 111 form.origin = GURL("http://myform.com/form.html"); |
| 112 form.action = GURL("http://myform.com/submit.html"); | 112 form.action = GURL("http://myform.com/submit.html"); |
| 113 form.user_submitted = true; | 113 form.user_submitted = true; |
| 114 | 114 |
| 115 FormFieldData ssn; | 115 FormFieldData ssn; |
| 116 ssn.label = ASCIIToUTF16("Social Security Number"); | 116 ssn.label = ASCIIToUTF16("Social Security Number"); |
| 117 ssn.name = ASCIIToUTF16("ssn"); | 117 ssn.name = ASCIIToUTF16("ssn"); |
| 118 ssn.value = ASCIIToUTF16("078-05-1120"); | 118 ssn.value = ASCIIToUTF16("078-05-1120"); |
| 119 ssn.form_control_type = ASCIIToUTF16("text"); | 119 ssn.form_control_type = "text"; |
| 120 form.fields.push_back(ssn); | 120 form.fields.push_back(ssn); |
| 121 | 121 |
| 122 EXPECT_CALL(*web_data_service_, AddFormFields(_)).Times(0); | 122 EXPECT_CALL(*web_data_service_, AddFormFields(_)).Times(0); |
| 123 autocomplete_manager_->OnFormSubmitted(form); | 123 autocomplete_manager_->OnFormSubmitted(form); |
| 124 } | 124 } |
| 125 | 125 |
| 126 // Verify that autocomplete text is saved for search fields. | 126 // Verify that autocomplete text is saved for search fields. |
| 127 TEST_F(AutocompleteHistoryManagerTest, SearchField) { | 127 TEST_F(AutocompleteHistoryManagerTest, SearchField) { |
| 128 FormData form; | 128 FormData form; |
| 129 form.name = ASCIIToUTF16("MyForm"); | 129 form.name = ASCIIToUTF16("MyForm"); |
| 130 form.method = ASCIIToUTF16("POST"); | 130 form.method = ASCIIToUTF16("POST"); |
| 131 form.origin = GURL("http://myform.com/form.html"); | 131 form.origin = GURL("http://myform.com/form.html"); |
| 132 form.action = GURL("http://myform.com/submit.html"); | 132 form.action = GURL("http://myform.com/submit.html"); |
| 133 form.user_submitted = true; | 133 form.user_submitted = true; |
| 134 | 134 |
| 135 // Search field. | 135 // Search field. |
| 136 FormFieldData search_field; | 136 FormFieldData search_field; |
| 137 search_field.label = ASCIIToUTF16("Search"); | 137 search_field.label = ASCIIToUTF16("Search"); |
| 138 search_field.name = ASCIIToUTF16("search"); | 138 search_field.name = ASCIIToUTF16("search"); |
| 139 search_field.value = ASCIIToUTF16("my favorite query"); | 139 search_field.value = ASCIIToUTF16("my favorite query"); |
| 140 search_field.form_control_type = ASCIIToUTF16("search"); | 140 search_field.form_control_type = "search"; |
| 141 form.fields.push_back(search_field); | 141 form.fields.push_back(search_field); |
| 142 | 142 |
| 143 EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1); | 143 EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1); |
| 144 autocomplete_manager_->OnFormSubmitted(form); | 144 autocomplete_manager_->OnFormSubmitted(form); |
| 145 } | 145 } |
| 146 | 146 |
| 147 namespace { | 147 namespace { |
| 148 | 148 |
| 149 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { | 149 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { |
| 150 public: | 150 public: |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 scoped_ptr<AutofillWebDataService>( | 192 scoped_ptr<AutofillWebDataService>( |
| 193 new AutofillWebDataServiceImpl(web_data_service_))); | 193 new AutofillWebDataServiceImpl(web_data_service_))); |
| 194 | 194 |
| 195 MockAutofillExternalDelegate external_delegate(web_contents()); | 195 MockAutofillExternalDelegate external_delegate(web_contents()); |
| 196 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _)); | 196 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _)); |
| 197 autocomplete_history_manager.SetExternalDelegate(&external_delegate); | 197 autocomplete_history_manager.SetExternalDelegate(&external_delegate); |
| 198 | 198 |
| 199 // Should trigger a call to OnSuggestionsReturned, verified by the mock. | 199 // Should trigger a call to OnSuggestionsReturned, verified by the mock. |
| 200 autocomplete_history_manager.SendSuggestions(NULL); | 200 autocomplete_history_manager.SendSuggestions(NULL); |
| 201 } | 201 } |
| OLD | NEW |