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

Unified Diff: ios/chrome/browser/passwords/password_controller_unittest.mm

Issue 2814773002: Move password-related methods from core.js to password_controller.js. (Closed)
Patch Set: Address reviewer comment (fix verb tense in test comment) Created 3 years, 8 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ios/chrome/browser/passwords/resources/password_controller.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..9a6ddbda55743be8cc0acec4f4810cc089b58226 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;
+};
+
+// Tests that the existence of (or the lack of) a password field in the page is
+// 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);
+ }
+}
+
+// Tests that the existence a password field in a nested iframe/ 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;
@@ -760,10 +803,14 @@ struct FillPasswordFormTestData {
NSString* expected_result;
};
-// Test that filling password forms works correctly.
+// Tests that filling password forms works correctly.
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();
« no previous file with comments | « no previous file | ios/chrome/browser/passwords/resources/password_controller.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698