Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #import "ios/chrome/browser/passwords/password_controller.h" | 5 #import "ios/chrome/browser/passwords/password_controller.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 742 static NSString* kInputFieldValueVerificationScript = | 742 static NSString* kInputFieldValueVerificationScript = |
| 743 @"var result='';" | 743 @"var result='';" |
| 744 "var inputs = document.getElementsByTagName('input');" | 744 "var inputs = document.getElementsByTagName('input');" |
| 745 "for(var i = 0; i < inputs.length; i++){" | 745 "for(var i = 0; i < inputs.length; i++){" |
| 746 " var input = inputs[i];" | 746 " var input = inputs[i];" |
| 747 " if (input.value) {" | 747 " if (input.value) {" |
| 748 " result += input.id + '=' + input.value +';';" | 748 " result += input.id + '=' + input.value +';';" |
| 749 " }" | 749 " }" |
| 750 "}; result"; | 750 "}; result"; |
| 751 | 751 |
| 752 struct TestDataForPasswordFormDetection { | |
|
Eugene But (OOO till 7-30)
2017/04/11 16:19:40
Could you please add comments to this struct and i
danyao
2017/04/11 18:05:06
Done.
| |
| 753 NSString* pageContent; | |
|
Eugene But (OOO till 7-30)
2017/04/11 16:19:40
s/pageContent/page_content
Same comment form cont
danyao
2017/04/11 18:05:06
Done.
| |
| 754 NSNumber* containsPassword; | |
|
Eugene But (OOO till 7-30)
2017/04/11 16:19:40
Do you want to use bool or BOOL instead of NSNumbe
danyao
2017/04/11 18:05:05
Done.
| |
| 755 }; | |
| 756 | |
| 757 TEST_F(PasswordControllerTest, HasPasswordField) { | |
|
Eugene But (OOO till 7-30)
2017/04/11 16:19:40
Could you please add comments to this test.
danyao
2017/04/11 18:05:06
Done.
| |
| 758 TestDataForPasswordFormDetection testData[] = { | |
| 759 // Form without a password field. | |
| 760 {@"<form><input type='text' name='password'></form>", @NO}, | |
| 761 // Form with a password field. | |
| 762 {@"<form><input type='password' name='password'></form>", @YES}}; | |
| 763 for (size_t i = 0; i < arraysize(testData); i++) { | |
| 764 TestDataForPasswordFormDetection& data = testData[i]; | |
| 765 LoadHtml(data.pageContent); | |
| 766 id result = ExecuteJavaScript(@"__gCrWeb.hasPasswordFieldTestOnly()"); | |
| 767 EXPECT_NSEQ(data.containsPassword, result) | |
| 768 << " in test " << i << ": " | |
| 769 << base::SysNSStringToUTF8(data.pageContent); | |
| 770 } | |
| 771 } | |
| 772 | |
| 773 TEST_F(PasswordControllerTest, HasPasswordFieldinFrame) { | |
| 774 TestDataForPasswordFormDetection data = { | |
| 775 // Form with a password field in a nested iframe. | |
| 776 @"<iframe name='pf'></iframe>" | |
| 777 "<script>" | |
| 778 " var doc = frames['pf'].document.open();" | |
| 779 " doc.write('<form><input type=\\'password\\'></form>');" | |
| 780 " doc.close();" | |
| 781 "</script>", | |
| 782 @YES | |
| 783 }; | |
| 784 LoadHtml(data.pageContent); | |
| 785 id result = ExecuteJavaScript(@"__gCrWeb.hasPasswordFieldTestOnly()"); | |
| 786 EXPECT_NSEQ(data.containsPassword, result) | |
| 787 << base::SysNSStringToUTF8(data.pageContent); | |
| 788 } | |
| 789 | |
| 752 struct FillPasswordFormTestData { | 790 struct FillPasswordFormTestData { |
| 753 const std::string origin; | 791 const std::string origin; |
| 754 const std::string action; | 792 const std::string action; |
| 755 const char* username_field; | 793 const char* username_field; |
| 756 const char* username_value; | 794 const char* username_value; |
| 757 const char* password_field; | 795 const char* password_field; |
| 758 const char* password_value; | 796 const char* password_value; |
| 759 const BOOL should_succeed; | 797 const BOOL should_succeed; |
| 760 NSString* expected_result; | 798 NSString* expected_result; |
| 761 }; | 799 }; |
| 762 | 800 |
| 763 // Test that filling password forms works correctly. | 801 // Test that filling password forms works correctly. |
| 764 TEST_F(PasswordControllerTest, FillPasswordForm) { | 802 TEST_F(PasswordControllerTest, FillPasswordForm) { |
| 765 LoadHtml(kHtmlWithMultiplePasswordForms); | 803 LoadHtml(kHtmlWithMultiplePasswordForms); |
| 766 | 804 |
| 767 EXPECT_NSEQ(@YES, ExecuteJavaScript(@"__gCrWeb.hasPasswordField()")); | 805 // TODO(danyao): can we remove this assertion? This call is the only reason |
| 806 // why hasPasswordFieldTestOnly is a public API on gCrWeb. If the page does | |
| 807 // not contain a password field, shouldn't one of the expectations of the | |
| 808 // remaining tests also fail? | |
| 809 EXPECT_NSEQ(@YES, ExecuteJavaScript(@"__gCrWeb.hasPasswordFieldTestOnly()")); | |
| 768 | 810 |
| 769 const std::string base_url = BaseUrl(); | 811 const std::string base_url = BaseUrl(); |
| 770 // clang-format off | 812 // clang-format off |
| 771 FillPasswordFormTestData test_data[] = { | 813 FillPasswordFormTestData test_data[] = { |
| 772 // Basic test: one-to-one match on the first password form. | 814 // Basic test: one-to-one match on the first password form. |
| 773 { | 815 { |
| 774 base_url, | 816 base_url, |
| 775 base_url, | 817 base_url, |
| 776 "u0", | 818 "u0", |
| 777 "test_user", | 819 "test_user", |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 936 }); | 978 }); |
| 937 EXPECT_EQ(2, success_counter); | 979 EXPECT_EQ(2, success_counter); |
| 938 id result = ExecuteJavaScript(kInputFieldValueVerificationScript); | 980 id result = ExecuteJavaScript(kInputFieldValueVerificationScript); |
| 939 EXPECT_NSEQ(@"u2=john.doe@gmail.com;p2=super!secret;" | 981 EXPECT_NSEQ(@"u2=john.doe@gmail.com;p2=super!secret;" |
| 940 "u3=john.doe@gmail.com;p3=super!secret;", | 982 "u3=john.doe@gmail.com;p3=super!secret;", |
| 941 result); | 983 result); |
| 942 } | 984 } |
| 943 | 985 |
| 944 BOOL PasswordControllerTest::BasicFormFill(NSString* html) { | 986 BOOL PasswordControllerTest::BasicFormFill(NSString* html) { |
| 945 LoadHtml(html); | 987 LoadHtml(html); |
| 946 EXPECT_NSEQ(@YES, ExecuteJavaScript(@"__gCrWeb.hasPasswordField()")); | 988 EXPECT_NSEQ(@YES, ExecuteJavaScript(@"__gCrWeb.hasPasswordFieldTestOnly()")); |
| 947 const std::string base_url = BaseUrl(); | 989 const std::string base_url = BaseUrl(); |
| 948 PasswordFormFillData form_data; | 990 PasswordFormFillData form_data; |
| 949 SetPasswordFormFillData(form_data, base_url, base_url, "u0", "test_user", | 991 SetPasswordFormFillData(form_data, base_url, base_url, "u0", "test_user", |
| 950 "p0", "test_password", nullptr, nullptr, false); | 992 "p0", "test_password", nullptr, nullptr, false); |
| 951 __block BOOL block_was_called = NO; | 993 __block BOOL block_was_called = NO; |
| 952 __block BOOL return_value = NO; | 994 __block BOOL return_value = NO; |
| 953 [passwordController_ fillPasswordForm:form_data | 995 [passwordController_ fillPasswordForm:form_data |
| 954 completionHandler:^(BOOL success) { | 996 completionHandler:^(BOOL success) { |
| 955 block_was_called = YES; | 997 block_was_called = YES; |
| 956 return_value = success; | 998 return_value = success; |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1330 // Tests that an HTTPS page with a password field does not update the SSL status | 1372 // Tests that an HTTPS page with a password field does not update the SSL status |
| 1331 // to indicate DISPLAYED_PASSWORD_FIELD_ON_HTTP. | 1373 // to indicate DISPLAYED_PASSWORD_FIELD_ON_HTTP. |
| 1332 TEST_F(PasswordControllerTest, HTTPSPassword) { | 1374 TEST_F(PasswordControllerTest, HTTPSPassword) { |
| 1333 LoadHtml(kHtmlWithPasswordForm, GURL("https://chromium.test")); | 1375 LoadHtml(kHtmlWithPasswordForm, GURL("https://chromium.test")); |
| 1334 | 1376 |
| 1335 web::SSLStatus ssl_status = | 1377 web::SSLStatus ssl_status = |
| 1336 web_state()->GetNavigationManager()->GetLastCommittedItem()->GetSSL(); | 1378 web_state()->GetNavigationManager()->GetLastCommittedItem()->GetSSL(); |
| 1337 EXPECT_FALSE(ssl_status.content_status & | 1379 EXPECT_FALSE(ssl_status.content_status & |
| 1338 web::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); | 1380 web::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); |
| 1339 } | 1381 } |
| OLD | NEW |