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..47100221dee865a577a2135f01c391242433ce3a 100644 |
| --- a/ios/chrome/browser/passwords/password_controller_unittest.mm |
| +++ b/ios/chrome/browser/passwords/password_controller_unittest.mm |
| @@ -749,6 +749,49 @@ static NSString* kInputFieldValueVerificationScript = |
| " }" |
| "}; result"; |
| +// Test html content and expected result for __gCrWeb.hasPasswordField call. |
| +struct TestDataForPasswordFormDetection { |
| + NSString* page_content; |
| + BOOL contains_password; |
| +}; |
| + |
| +// Test that the existence (or the lack of ) a password field in the page is |
|
Eugene But (OOO till 7-30)
2017/04/11 18:20:20
s/Test/Tests
Style Guide has this: "These comment
danyao
2017/04/11 18:52:53
Done.
|
| +// detected correctly. |
| +TEST_F(PasswordControllerTest, HasPasswordField) { |
| + TestDataForPasswordFormDetection test_data[] = { |
| + // 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(test_data); i++) { |
| + TestDataForPasswordFormDetection& data = test_data[i]; |
| + LoadHtml(data.page_content); |
| + id result = ExecuteJavaScript(@"__gCrWeb.hasPasswordField()"); |
| + EXPECT_NSEQ(data.contains_password, result) |
| + << " in test " << i << ": " |
| + << base::SysNSStringToUTF8(data.page_content); |
| + } |
| +} |
| + |
| +// Test that the existence (or the lack of) a password field in a nested iframe |
|
Eugene But (OOO till 7-30)
2017/04/11 18:20:20
ditto
danyao
2017/04/11 18:52:53
Done.
|
| +// is detected correctly. |
| +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.page_content); |
| + id result = ExecuteJavaScript(@"__gCrWeb.hasPasswordField()"); |
| + EXPECT_NSEQ(data.contains_password, result) |
| + << base::SysNSStringToUTF8(data.page_content); |
| +} |
| + |
| struct FillPasswordFormTestData { |
| const std::string origin; |
| const std::string action; |
| @@ -764,6 +807,10 @@ struct FillPasswordFormTestData { |
| TEST_F(PasswordControllerTest, FillPasswordForm) { |
| LoadHtml(kHtmlWithMultiplePasswordForms); |
| + // TODO(crbug.com/614092): can we remove this assertion? This call is the only |
| + // reason why hasPasswordField 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.hasPasswordField()")); |
| const std::string base_url = BaseUrl(); |