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

Side by Side Diff: chrome/browser/autocomplete_history_manager_unittest.cc

Issue 8680040: Group forms-related files in webkit/glue in a forms/ subdirectory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase + another build fix Created 9 years 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 | Annotate | Revision Log
OLDNEW
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"
11 #include "chrome/browser/autocomplete_history_manager.h" 11 #include "chrome/browser/autocomplete_history_manager.h"
12 #include "chrome/browser/autofill/autofill_external_delegate.h" 12 #include "chrome/browser/autofill/autofill_external_delegate.h"
13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
14 #include "chrome/browser/webdata/web_data_service.h" 14 #include "chrome/browser/webdata/web_data_service.h"
15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 15 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
16 #include "chrome/test/base/testing_browser_process.h" 16 #include "chrome/test/base/testing_browser_process.h"
17 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
18 #include "content/browser/tab_contents/test_tab_contents.h" 18 #include "content/browser/tab_contents/test_tab_contents.h"
19 #include "content/test/test_browser_thread.h" 19 #include "content/test/test_browser_thread.h"
20 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "ui/gfx/rect.h" 22 #include "ui/gfx/rect.h"
23 #include "webkit/glue/form_data.h" 23 #include "webkit/forms/form_data.h"
24 24
25 using content::BrowserThread; 25 using content::BrowserThread;
26 using testing::_; 26 using testing::_;
27 using webkit_glue::FormData; 27 using webkit::forms::FormData;
28 28
29 class MockWebDataService : public WebDataService { 29 class MockWebDataService : public WebDataService {
30 public: 30 public:
31 MOCK_METHOD1(AddFormFields, 31 MOCK_METHOD1(AddFormFields,
32 void(const std::vector<webkit_glue::FormField>&)); // NOLINT 32 void(const std::vector<webkit::forms::FormField>&)); // NOLINT
33 }; 33 };
34 34
35 class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness { 35 class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness {
36 protected: 36 protected:
37 AutocompleteHistoryManagerTest() 37 AutocompleteHistoryManagerTest()
38 : ui_thread_(BrowserThread::UI, MessageLoopForUI::current()) { 38 : ui_thread_(BrowserThread::UI, MessageLoopForUI::current()) {
39 } 39 }
40 40
41 virtual void SetUp() { 41 virtual void SetUp() {
42 ChromeRenderViewHostTestHarness::SetUp(); 42 ChromeRenderViewHostTestHarness::SetUp();
(...skipping 12 matching lines...) Expand all
55 // Tests that credit card numbers are not sent to the WebDatabase to be saved. 55 // Tests that credit card numbers are not sent to the WebDatabase to be saved.
56 TEST_F(AutocompleteHistoryManagerTest, CreditCardNumberValue) { 56 TEST_F(AutocompleteHistoryManagerTest, CreditCardNumberValue) {
57 FormData form; 57 FormData form;
58 form.name = ASCIIToUTF16("MyForm"); 58 form.name = ASCIIToUTF16("MyForm");
59 form.method = ASCIIToUTF16("POST"); 59 form.method = ASCIIToUTF16("POST");
60 form.origin = GURL("http://myform.com/form.html"); 60 form.origin = GURL("http://myform.com/form.html");
61 form.action = GURL("http://myform.com/submit.html"); 61 form.action = GURL("http://myform.com/submit.html");
62 form.user_submitted = true; 62 form.user_submitted = true;
63 63
64 // Valid Visa credit card number pulled from the paypal help site. 64 // Valid Visa credit card number pulled from the paypal help site.
65 webkit_glue::FormField valid_cc; 65 webkit::forms::FormField valid_cc;
66 valid_cc.label = ASCIIToUTF16("Credit Card"); 66 valid_cc.label = ASCIIToUTF16("Credit Card");
67 valid_cc.name = ASCIIToUTF16("ccnum"); 67 valid_cc.name = ASCIIToUTF16("ccnum");
68 valid_cc.value = ASCIIToUTF16("4012888888881881"); 68 valid_cc.value = ASCIIToUTF16("4012888888881881");
69 valid_cc.form_control_type = ASCIIToUTF16("text"); 69 valid_cc.form_control_type = ASCIIToUTF16("text");
70 form.fields.push_back(valid_cc); 70 form.fields.push_back(valid_cc);
71 71
72 EXPECT_CALL(*web_data_service_, AddFormFields(_)).Times(0); 72 EXPECT_CALL(*web_data_service_, AddFormFields(_)).Times(0);
73 autocomplete_manager_->OnFormSubmitted(form); 73 autocomplete_manager_->OnFormSubmitted(form);
74 } 74 }
75 75
76 // Contrary test to AutocompleteHistoryManagerTest.CreditCardNumberValue. The 76 // Contrary test to AutocompleteHistoryManagerTest.CreditCardNumberValue. The
77 // value being submitted is not a valid credit card number, so it will be sent 77 // value being submitted is not a valid credit card number, so it will be sent
78 // to the WebDatabase to be saved. 78 // to the WebDatabase to be saved.
79 TEST_F(AutocompleteHistoryManagerTest, NonCreditCardNumberValue) { 79 TEST_F(AutocompleteHistoryManagerTest, NonCreditCardNumberValue) {
80 FormData form; 80 FormData form;
81 form.name = ASCIIToUTF16("MyForm"); 81 form.name = ASCIIToUTF16("MyForm");
82 form.method = ASCIIToUTF16("POST"); 82 form.method = ASCIIToUTF16("POST");
83 form.origin = GURL("http://myform.com/form.html"); 83 form.origin = GURL("http://myform.com/form.html");
84 form.action = GURL("http://myform.com/submit.html"); 84 form.action = GURL("http://myform.com/submit.html");
85 form.user_submitted = true; 85 form.user_submitted = true;
86 86
87 // Invalid credit card number. 87 // Invalid credit card number.
88 webkit_glue::FormField invalid_cc; 88 webkit::forms::FormField invalid_cc;
89 invalid_cc.label = ASCIIToUTF16("Credit Card"); 89 invalid_cc.label = ASCIIToUTF16("Credit Card");
90 invalid_cc.name = ASCIIToUTF16("ccnum"); 90 invalid_cc.name = ASCIIToUTF16("ccnum");
91 invalid_cc.value = ASCIIToUTF16("4580123456789012"); 91 invalid_cc.value = ASCIIToUTF16("4580123456789012");
92 invalid_cc.form_control_type = ASCIIToUTF16("text"); 92 invalid_cc.form_control_type = ASCIIToUTF16("text");
93 form.fields.push_back(invalid_cc); 93 form.fields.push_back(invalid_cc);
94 94
95 EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1); 95 EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1);
96 autocomplete_manager_->OnFormSubmitted(form); 96 autocomplete_manager_->OnFormSubmitted(form);
97 } 97 }
98 98
99 // Tests that SSNs are not sent to the WebDatabase to be saved. 99 // Tests that SSNs are not sent to the WebDatabase to be saved.
100 TEST_F(AutocompleteHistoryManagerTest, SSNValue) { 100 TEST_F(AutocompleteHistoryManagerTest, SSNValue) {
101 FormData form; 101 FormData form;
102 form.name = ASCIIToUTF16("MyForm"); 102 form.name = ASCIIToUTF16("MyForm");
103 form.method = ASCIIToUTF16("POST"); 103 form.method = ASCIIToUTF16("POST");
104 form.origin = GURL("http://myform.com/form.html"); 104 form.origin = GURL("http://myform.com/form.html");
105 form.action = GURL("http://myform.com/submit.html"); 105 form.action = GURL("http://myform.com/submit.html");
106 form.user_submitted = true; 106 form.user_submitted = true;
107 107
108 webkit_glue::FormField ssn; 108 webkit::forms::FormField ssn;
109 ssn.label = ASCIIToUTF16("Social Security Number"); 109 ssn.label = ASCIIToUTF16("Social Security Number");
110 ssn.name = ASCIIToUTF16("ssn"); 110 ssn.name = ASCIIToUTF16("ssn");
111 ssn.value = ASCIIToUTF16("078-05-1120"); 111 ssn.value = ASCIIToUTF16("078-05-1120");
112 ssn.form_control_type = ASCIIToUTF16("text"); 112 ssn.form_control_type = ASCIIToUTF16("text");
113 form.fields.push_back(ssn); 113 form.fields.push_back(ssn);
114 114
115 EXPECT_CALL(*web_data_service_, AddFormFields(_)).Times(0); 115 EXPECT_CALL(*web_data_service_, AddFormFields(_)).Times(0);
116 autocomplete_manager_->OnFormSubmitted(form); 116 autocomplete_manager_->OnFormSubmitted(form);
117 } 117 }
118 118
119 // Verify that autocomplete text is saved for search fields. 119 // Verify that autocomplete text is saved for search fields.
120 TEST_F(AutocompleteHistoryManagerTest, SearchField) { 120 TEST_F(AutocompleteHistoryManagerTest, SearchField) {
121 FormData form; 121 FormData form;
122 form.name = ASCIIToUTF16("MyForm"); 122 form.name = ASCIIToUTF16("MyForm");
123 form.method = ASCIIToUTF16("POST"); 123 form.method = ASCIIToUTF16("POST");
124 form.origin = GURL("http://myform.com/form.html"); 124 form.origin = GURL("http://myform.com/form.html");
125 form.action = GURL("http://myform.com/submit.html"); 125 form.action = GURL("http://myform.com/submit.html");
126 form.user_submitted = true; 126 form.user_submitted = true;
127 127
128 // Search field. 128 // Search field.
129 webkit_glue::FormField search_field; 129 webkit::forms::FormField search_field;
130 search_field.label = ASCIIToUTF16("Search"); 130 search_field.label = ASCIIToUTF16("Search");
131 search_field.name = ASCIIToUTF16("search"); 131 search_field.name = ASCIIToUTF16("search");
132 search_field.value = ASCIIToUTF16("my favorite query"); 132 search_field.value = ASCIIToUTF16("my favorite query");
133 search_field.form_control_type = ASCIIToUTF16("search"); 133 search_field.form_control_type = ASCIIToUTF16("search");
134 form.fields.push_back(search_field); 134 form.fields.push_back(search_field);
135 135
136 EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1); 136 EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1);
137 autocomplete_manager_->OnFormSubmitted(form); 137 autocomplete_manager_->OnFormSubmitted(form);
138 } 138 }
139 139
140 namespace { 140 namespace {
141 141
142 class MockAutofillExternalDelegate : public AutofillExternalDelegate { 142 class MockAutofillExternalDelegate : public AutofillExternalDelegate {
143 public: 143 public:
144 explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper) 144 explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper)
145 : AutofillExternalDelegate(wrapper) {} 145 : AutofillExternalDelegate(wrapper) {}
146 virtual ~MockAutofillExternalDelegate() {} 146 virtual ~MockAutofillExternalDelegate() {}
147 147
148 virtual void OnQuery(int query_id, 148 virtual void OnQuery(int query_id,
149 const webkit_glue::FormData& form, 149 const webkit::forms::FormData& form,
150 const webkit_glue::FormField& field, 150 const webkit::forms::FormField& field,
151 const gfx::Rect& bounds, 151 const gfx::Rect& bounds,
152 bool display_warning) OVERRIDE {} 152 bool display_warning) OVERRIDE {}
153 153
154 MOCK_METHOD5(OnSuggestionsReturned, 154 MOCK_METHOD5(OnSuggestionsReturned,
155 void(int query_id, 155 void(int query_id,
156 const std::vector<string16>& autofill_values, 156 const std::vector<string16>& autofill_values,
157 const std::vector<string16>& autofill_labels, 157 const std::vector<string16>& autofill_labels,
158 const std::vector<string16>& autofill_icons, 158 const std::vector<string16>& autofill_icons,
159 const std::vector<int>& autofill_unique_ids)); 159 const std::vector<int>& autofill_unique_ids));
160 160
161 virtual void HideAutofillPopup() OVERRIDE {} 161 virtual void HideAutofillPopup() OVERRIDE {}
162 162
163 163
164 virtual void ApplyAutofillSuggestions( 164 virtual void ApplyAutofillSuggestions(
165 const std::vector<string16>& autofill_values, 165 const std::vector<string16>& autofill_values,
166 const std::vector<string16>& autofill_labels, 166 const std::vector<string16>& autofill_labels,
167 const std::vector<string16>& autofill_icons, 167 const std::vector<string16>& autofill_icons,
168 const std::vector<int>& autofill_unique_ids, 168 const std::vector<int>& autofill_unique_ids,
169 int separator_index) OVERRIDE {} 169 int separator_index) OVERRIDE {}
170 170
171 virtual void OnQueryPlatformSpecific( 171 virtual void OnQueryPlatformSpecific(
172 int query_id, 172 int query_id,
173 const webkit_glue::FormData& form, 173 const webkit::forms::FormData& form,
174 const webkit_glue::FormField& field) OVERRIDE {} 174 const webkit::forms::FormField& field) OVERRIDE {}
175 175
176 private: 176 private:
177 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); 177 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate);
178 }; 178 };
179 179
180 class AutocompleteHistoryManagerStubSend : public AutocompleteHistoryManager { 180 class AutocompleteHistoryManagerStubSend : public AutocompleteHistoryManager {
181 public: 181 public:
182 explicit AutocompleteHistoryManagerStubSend(TabContents* tab_contents, 182 explicit AutocompleteHistoryManagerStubSend(TabContents* tab_contents,
183 Profile* profile, 183 Profile* profile,
184 WebDataService* wds) 184 WebDataService* wds)
(...skipping 13 matching lines...) Expand all
198 &profile_, web_data_service_); 198 &profile_, web_data_service_);
199 199
200 MockAutofillExternalDelegate external_delegate( 200 MockAutofillExternalDelegate external_delegate(
201 TabContentsWrapper::GetCurrentWrapperForContents(contents())); 201 TabContentsWrapper::GetCurrentWrapperForContents(contents()));
202 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _)); 202 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _));
203 autocomplete_history_manager.SetExternalDelegate(&external_delegate); 203 autocomplete_history_manager.SetExternalDelegate(&external_delegate);
204 204
205 // Should trigger a call to OnSuggestionsReturned, verified by the mock. 205 // Should trigger a call to OnSuggestionsReturned, verified by the mock.
206 autocomplete_history_manager.SendSuggestions(NULL); 206 autocomplete_history_manager.SendSuggestions(NULL);
207 } 207 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete_history_manager.cc ('k') | chrome/browser/autofill/address_field_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698