OLD | NEW |
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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "components/autofill/content/renderer/form_autofill_util.h" | 14 #include "components/autofill/content/renderer/form_autofill_util.h" |
15 #include "components/autofill/content/renderer/password_form_conversion_utils.h" | 15 #include "components/autofill/content/renderer/password_form_conversion_utils.h" |
16 #include "components/autofill/core/browser/form_structure.h" | 16 #include "components/autofill/core/browser/form_structure.h" |
17 #include "components/autofill/core/common/password_form.h" | 17 #include "components/autofill/core/common/password_form.h" |
18 #include "content/public/test/render_view_test.h" | 18 #include "content/public/test/render_view_test.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "third_party/WebKit/public/platform/WebVector.h" | 21 #include "third_party/WebKit/public/platform/WebVector.h" |
22 #include "third_party/WebKit/public/web/WebDocument.h" | 22 #include "third_party/WebKit/public/web/WebDocument.h" |
23 #include "third_party/WebKit/public/web/WebFormControlElement.h" | 23 #include "third_party/WebKit/public/web/WebFormControlElement.h" |
24 #include "third_party/WebKit/public/web/WebFormElement.h" | 24 #include "third_party/WebKit/public/web/WebFormElement.h" |
25 #include "third_party/WebKit/public/web/WebInputElement.h" | 25 #include "third_party/WebKit/public/web/WebInputElement.h" |
26 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 26 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
27 | 27 |
28 using blink::WebFormControlElement; | 28 using blink::WebFormControlElement; |
29 using blink::WebFormElement; | 29 using blink::WebFormElement; |
30 using blink::WebFrame; | 30 using blink::WebLocalFrame; |
31 using blink::WebInputElement; | 31 using blink::WebInputElement; |
32 using blink::WebVector; | 32 using blink::WebVector; |
33 | 33 |
34 namespace autofill { | 34 namespace autofill { |
35 namespace { | 35 namespace { |
36 | 36 |
37 const char kTestFormActionURL[] = "http://cnn.com"; | 37 const char kTestFormActionURL[] = "http://cnn.com"; |
38 | 38 |
39 // A builder to produce HTML code for a password form composed of the desired | 39 // A builder to produce HTML code for a password form composed of the desired |
40 // number and kinds of username and password fields. | 40 // number and kinds of username and password fields. |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 (*predictions)[form_data][*(*field)] = | 235 (*predictions)[form_data][*(*field)] = |
236 predictions_positions.find(field_index)->second; | 236 predictions_positions.find(field_index)->second; |
237 } | 237 } |
238 } | 238 } |
239 } | 239 } |
240 | 240 |
241 // Loads the given |html| and retrieves the sole WebFormElement from it. | 241 // Loads the given |html| and retrieves the sole WebFormElement from it. |
242 void LoadWebFormFromHTML(const std::string& html, WebFormElement* form) { | 242 void LoadWebFormFromHTML(const std::string& html, WebFormElement* form) { |
243 LoadHTML(html.c_str()); | 243 LoadHTML(html.c_str()); |
244 | 244 |
245 WebFrame* frame = GetMainFrame(); | 245 WebLocalFrame* frame = GetMainFrame(); |
246 ASSERT_NE(nullptr, frame); | 246 ASSERT_NE(nullptr, frame); |
247 | 247 |
248 WebVector<WebFormElement> forms; | 248 WebVector<WebFormElement> forms; |
249 frame->GetDocument().Forms(forms); | 249 frame->GetDocument().Forms(forms); |
250 ASSERT_EQ(1U, forms.size()); | 250 ASSERT_EQ(1U, forms.size()); |
251 | 251 |
252 *form = forms[0]; | 252 *form = forms[0]; |
253 } | 253 } |
254 | 254 |
255 private: | 255 private: |
(...skipping 1314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1570 | 1570 |
1571 ASSERT_TRUE(password_form); | 1571 ASSERT_TRUE(password_form); |
1572 | 1572 |
1573 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); | 1573 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); |
1574 EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); | 1574 EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); |
1575 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); | 1575 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); |
1576 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); | 1576 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); |
1577 } | 1577 } |
1578 | 1578 |
1579 } // namespace autofill | 1579 } // namespace autofill |
OLD | NEW |