Chromium Code Reviews| Index: ios/chrome/browser/passwords/password_controller_unittest.mm |
| diff --git a/ios/chrome/browser/passwords/password_controller_unittest.mm b/ios/chrome/browser/passwords/password_controller_unittest.mm |
| index 7e454731d4210abc316efeac06f8e884ac9563b0..898cf24c02120086b076018bef6359f907e64cea 100644 |
| --- a/ios/chrome/browser/passwords/password_controller_unittest.mm |
| +++ b/ios/chrome/browser/passwords/password_controller_unittest.mm |
| @@ -749,6 +749,44 @@ static NSString* kInputFieldValueVerificationScript = |
| " }" |
| "}; result"; |
| +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.
|
| + 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.
|
| + 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.
|
| +}; |
| + |
| +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.
|
| + TestDataForPasswordFormDetection testData[] = { |
| + // Form without a password field. |
| + {@"<form><input type='text' name='password'></form>", @NO}, |
| + // Form with a password field. |
| + {@"<form><input type='password' name='password'></form>", @YES}}; |
| + for (size_t i = 0; i < arraysize(testData); i++) { |
| + TestDataForPasswordFormDetection& data = testData[i]; |
| + LoadHtml(data.pageContent); |
| + id result = ExecuteJavaScript(@"__gCrWeb.hasPasswordFieldTestOnly()"); |
| + EXPECT_NSEQ(data.containsPassword, result) |
| + << " in test " << i << ": " |
| + << base::SysNSStringToUTF8(data.pageContent); |
| + } |
| +} |
| + |
| +TEST_F(PasswordControllerTest, HasPasswordFieldinFrame) { |
| + TestDataForPasswordFormDetection data = { |
| + // Form with a password field in a nested iframe. |
| + @"<iframe name='pf'></iframe>" |
| + "<script>" |
| + " var doc = frames['pf'].document.open();" |
| + " doc.write('<form><input type=\\'password\\'></form>');" |
| + " doc.close();" |
| + "</script>", |
| + @YES |
| + }; |
| + LoadHtml(data.pageContent); |
| + id result = ExecuteJavaScript(@"__gCrWeb.hasPasswordFieldTestOnly()"); |
| + EXPECT_NSEQ(data.containsPassword, result) |
| + << base::SysNSStringToUTF8(data.pageContent); |
| +} |
| + |
| struct FillPasswordFormTestData { |
| const std::string origin; |
| const std::string action; |
| @@ -764,7 +802,11 @@ struct FillPasswordFormTestData { |
| TEST_F(PasswordControllerTest, FillPasswordForm) { |
| LoadHtml(kHtmlWithMultiplePasswordForms); |
| - EXPECT_NSEQ(@YES, ExecuteJavaScript(@"__gCrWeb.hasPasswordField()")); |
| + // TODO(danyao): can we remove this assertion? This call is the only reason |
| + // why hasPasswordFieldTestOnly is a public API on gCrWeb. If the page does |
| + // not contain a password field, shouldn't one of the expectations of the |
| + // remaining tests also fail? |
| + EXPECT_NSEQ(@YES, ExecuteJavaScript(@"__gCrWeb.hasPasswordFieldTestOnly()")); |
| const std::string base_url = BaseUrl(); |
| // clang-format off |
| @@ -943,7 +985,7 @@ TEST_F(PasswordControllerTest, FindAndFillMultiplePasswordForms) { |
| BOOL PasswordControllerTest::BasicFormFill(NSString* html) { |
| LoadHtml(html); |
| - EXPECT_NSEQ(@YES, ExecuteJavaScript(@"__gCrWeb.hasPasswordField()")); |
| + EXPECT_NSEQ(@YES, ExecuteJavaScript(@"__gCrWeb.hasPasswordFieldTestOnly()")); |
| const std::string base_url = BaseUrl(); |
| PasswordFormFillData form_data; |
| SetPasswordFormFillData(form_data, base_url, base_url, "u0", "test_user", |