| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/task.h" | 9 #include "base/task.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 // Tests that credit card numbers are not sent to the WebDatabase to be saved. | 51 // Tests that credit card numbers are not sent to the WebDatabase to be saved. |
| 52 TEST_F(AutocompleteHistoryManagerTest, CreditCardNumberValue) { | 52 TEST_F(AutocompleteHistoryManagerTest, CreditCardNumberValue) { |
| 53 FormData form; | 53 FormData form; |
| 54 form.name = ASCIIToUTF16("MyForm"); | 54 form.name = ASCIIToUTF16("MyForm"); |
| 55 form.method = ASCIIToUTF16("POST"); | 55 form.method = ASCIIToUTF16("POST"); |
| 56 form.origin = GURL("http://myform.com/form.html"); | 56 form.origin = GURL("http://myform.com/form.html"); |
| 57 form.action = GURL("http://myform.com/submit.html"); | 57 form.action = GURL("http://myform.com/submit.html"); |
| 58 form.user_submitted = true; | 58 form.user_submitted = true; |
| 59 | 59 |
| 60 // Valid Visa credit card number pulled from the paypal help site. | 60 // Valid Visa credit card number pulled from the paypal help site. |
| 61 webkit_glue::FormField valid_cc(ASCIIToUTF16("Credit Card"), | 61 webkit_glue::FormField valid_cc; |
| 62 ASCIIToUTF16("ccnum"), | 62 valid_cc.label = ASCIIToUTF16("Credit Card"); |
| 63 ASCIIToUTF16("4012888888881881"), | 63 valid_cc.name = ASCIIToUTF16("ccnum"); |
| 64 ASCIIToUTF16("text"), | 64 valid_cc.value = ASCIIToUTF16("4012888888881881"); |
| 65 20, | 65 valid_cc.form_control_type = ASCIIToUTF16("text"); |
| 66 false); | |
| 67 form.fields.push_back(valid_cc); | 66 form.fields.push_back(valid_cc); |
| 68 | 67 |
| 69 EXPECT_CALL(*web_data_service_, AddFormFields(_)).Times(0); | 68 EXPECT_CALL(*web_data_service_, AddFormFields(_)).Times(0); |
| 70 autocomplete_manager_->OnFormSubmitted(form); | 69 autocomplete_manager_->OnFormSubmitted(form); |
| 71 } | 70 } |
| 72 | 71 |
| 73 // Contrary test to AutocompleteHistoryManagerTest.CreditCardNumberValue. The | 72 // Contrary test to AutocompleteHistoryManagerTest.CreditCardNumberValue. The |
| 74 // value being submitted is not a valid credit card number, so it will be sent | 73 // value being submitted is not a valid credit card number, so it will be sent |
| 75 // to the WebDatabase to be saved. | 74 // to the WebDatabase to be saved. |
| 76 TEST_F(AutocompleteHistoryManagerTest, NonCreditCardNumberValue) { | 75 TEST_F(AutocompleteHistoryManagerTest, NonCreditCardNumberValue) { |
| 77 FormData form; | 76 FormData form; |
| 78 form.name = ASCIIToUTF16("MyForm"); | 77 form.name = ASCIIToUTF16("MyForm"); |
| 79 form.method = ASCIIToUTF16("POST"); | 78 form.method = ASCIIToUTF16("POST"); |
| 80 form.origin = GURL("http://myform.com/form.html"); | 79 form.origin = GURL("http://myform.com/form.html"); |
| 81 form.action = GURL("http://myform.com/submit.html"); | 80 form.action = GURL("http://myform.com/submit.html"); |
| 82 form.user_submitted = true; | 81 form.user_submitted = true; |
| 83 | 82 |
| 84 // Invalid credit card number. | 83 // Invalid credit card number. |
| 85 webkit_glue::FormField invalid_cc(ASCIIToUTF16("Credit Card"), | 84 webkit_glue::FormField invalid_cc; |
| 86 ASCIIToUTF16("ccnum"), | 85 invalid_cc.label = ASCIIToUTF16("Credit Card"); |
| 87 ASCIIToUTF16("4580123456789012"), | 86 invalid_cc.name = ASCIIToUTF16("ccnum"); |
| 88 ASCIIToUTF16("text"), | 87 invalid_cc.value = ASCIIToUTF16("4580123456789012"); |
| 89 20, | 88 invalid_cc.form_control_type = ASCIIToUTF16("text"); |
| 90 false); | |
| 91 form.fields.push_back(invalid_cc); | 89 form.fields.push_back(invalid_cc); |
| 92 | 90 |
| 93 EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1); | 91 EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1); |
| 94 autocomplete_manager_->OnFormSubmitted(form); | 92 autocomplete_manager_->OnFormSubmitted(form); |
| 95 } | 93 } |
| 96 | 94 |
| 97 // Tests that SSNs are not sent to the WebDatabase to be saved. | 95 // Tests that SSNs are not sent to the WebDatabase to be saved. |
| 98 TEST_F(AutocompleteHistoryManagerTest, SSNValue) { | 96 TEST_F(AutocompleteHistoryManagerTest, SSNValue) { |
| 99 FormData form; | 97 FormData form; |
| 100 form.name = ASCIIToUTF16("MyForm"); | 98 form.name = ASCIIToUTF16("MyForm"); |
| 101 form.method = ASCIIToUTF16("POST"); | 99 form.method = ASCIIToUTF16("POST"); |
| 102 form.origin = GURL("http://myform.com/form.html"); | 100 form.origin = GURL("http://myform.com/form.html"); |
| 103 form.action = GURL("http://myform.com/submit.html"); | 101 form.action = GURL("http://myform.com/submit.html"); |
| 104 form.user_submitted = true; | 102 form.user_submitted = true; |
| 105 | 103 |
| 106 webkit_glue::FormField ssn(ASCIIToUTF16("Social Security Number"), | 104 webkit_glue::FormField ssn; |
| 107 ASCIIToUTF16("ssn"), | 105 ssn.label = ASCIIToUTF16("Social Security Number"); |
| 108 ASCIIToUTF16("078-05-1120"), | 106 ssn.name = ASCIIToUTF16("ssn"); |
| 109 ASCIIToUTF16("text"), | 107 ssn.value = ASCIIToUTF16("078-05-1120"); |
| 110 20, | 108 ssn.form_control_type = ASCIIToUTF16("text"); |
| 111 false); | |
| 112 form.fields.push_back(ssn); | 109 form.fields.push_back(ssn); |
| 113 | 110 |
| 114 EXPECT_CALL(*web_data_service_, AddFormFields(_)).Times(0); | 111 EXPECT_CALL(*web_data_service_, AddFormFields(_)).Times(0); |
| 115 autocomplete_manager_->OnFormSubmitted(form); | 112 autocomplete_manager_->OnFormSubmitted(form); |
| 116 } | 113 } |
| 117 | 114 |
| 118 // Verify that autocomplete text is saved for search fields. | 115 // Verify that autocomplete text is saved for search fields. |
| 119 TEST_F(AutocompleteHistoryManagerTest, SearchField) { | 116 TEST_F(AutocompleteHistoryManagerTest, SearchField) { |
| 120 FormData form; | 117 FormData form; |
| 121 form.name = ASCIIToUTF16("MyForm"); | 118 form.name = ASCIIToUTF16("MyForm"); |
| 122 form.method = ASCIIToUTF16("POST"); | 119 form.method = ASCIIToUTF16("POST"); |
| 123 form.origin = GURL("http://myform.com/form.html"); | 120 form.origin = GURL("http://myform.com/form.html"); |
| 124 form.action = GURL("http://myform.com/submit.html"); | 121 form.action = GURL("http://myform.com/submit.html"); |
| 125 form.user_submitted = true; | 122 form.user_submitted = true; |
| 126 | 123 |
| 127 // Invalid credit card number. | 124 // Search field. |
| 128 webkit_glue::FormField search_field(ASCIIToUTF16("Search"), | 125 webkit_glue::FormField search_field; |
| 129 ASCIIToUTF16("search"), | 126 search_field.label = ASCIIToUTF16("Search"); |
| 130 ASCIIToUTF16("my favorite query"), | 127 search_field.name = ASCIIToUTF16("search"); |
| 131 ASCIIToUTF16("search"), | 128 search_field.value = ASCIIToUTF16("my favorite query"); |
| 132 20, | 129 search_field.form_control_type = ASCIIToUTF16("search"); |
| 133 false); | |
| 134 form.fields.push_back(search_field); | 130 form.fields.push_back(search_field); |
| 135 | 131 |
| 136 EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1); | 132 EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1); |
| 137 autocomplete_manager_->OnFormSubmitted(form); | 133 autocomplete_manager_->OnFormSubmitted(form); |
| 138 } | 134 } |
| OLD | NEW |