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

Side by Side Diff: ios/chrome/browser/passwords/password_controller_unittest.mm

Issue 2466143002: iOS: Mark HTTP pages with password fields with an omnibox icon. (Closed)
Patch Set: iOS HTTP Bad. Created 4 years 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 unified diff | Download patch
OLDNEW
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 10 matching lines...) Expand all
21 #include "components/password_manager/core/browser/log_manager.h" 21 #include "components/password_manager/core/browser/log_manager.h"
22 #include "components/password_manager/core/browser/mock_password_store.h" 22 #include "components/password_manager/core/browser/mock_password_store.h"
23 #include "components/password_manager/core/browser/stub_password_manager_client. h" 23 #include "components/password_manager/core/browser/stub_password_manager_client. h"
24 #include "components/password_manager/core/common/password_manager_pref_names.h" 24 #include "components/password_manager/core/common/password_manager_pref_names.h"
25 #include "components/prefs/pref_registry_simple.h" 25 #include "components/prefs/pref_registry_simple.h"
26 #include "components/prefs/testing_pref_service.h" 26 #include "components/prefs/testing_pref_service.h"
27 #import "ios/chrome/browser/autofill/form_input_accessory_view_controller.h" 27 #import "ios/chrome/browser/autofill/form_input_accessory_view_controller.h"
28 #import "ios/chrome/browser/autofill/form_suggestion_controller.h" 28 #import "ios/chrome/browser/autofill/form_suggestion_controller.h"
29 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" 29 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
30 #import "ios/chrome/browser/passwords/js_password_manager.h" 30 #import "ios/chrome/browser/passwords/js_password_manager.h"
31 #import "ios/web/public/navigation_item.h"
32 #import "ios/web/public/navigation_manager.h"
31 #import "ios/web/public/web_state/web_state.h" 33 #import "ios/web/public/web_state/web_state.h"
34 #include "ios/web/public/ssl_status.h"
32 #import "ios/web/public/test/web_test_with_web_state.h" 35 #import "ios/web/public/test/web_test_with_web_state.h"
33 #import "ios/web/public/test/test_web_state.h" 36 #import "ios/web/public/test/test_web_state.h"
34 #include "testing/gmock/include/gmock/gmock.h" 37 #include "testing/gmock/include/gmock/gmock.h"
35 #include "testing/gtest/include/gtest/gtest.h" 38 #include "testing/gtest/include/gtest/gtest.h"
36 #include "testing/gtest_mac.h" 39 #include "testing/gtest_mac.h"
37 #import "third_party/ocmock/OCMock/OCMock.h" 40 #import "third_party/ocmock/OCMock/OCMock.h"
38 #import "third_party/ocmock/OCMock/OCPartialMockObject.h" 41 #import "third_party/ocmock/OCMock/OCPartialMockObject.h"
39 #include "url/gurl.h" 42 #include "url/gurl.h"
40 43
41 #if !defined(__has_feature) || !__has_feature(objc_arc) 44 #if !defined(__has_feature) || !__has_feature(objc_arc)
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 "<input id='pw0' type='password' name='p0'>" 977 "<input id='pw0' type='password' name='p0'>"
975 "</form>")); 978 "</form>"));
976 // Form fill should fail with 'readonly' attribute on password. 979 // Form fill should fail with 'readonly' attribute on password.
977 EXPECT_FALSE(BasicFormFill( 980 EXPECT_FALSE(BasicFormFill(
978 @"<form>" 981 @"<form>"
979 "<input id='un0' type='text' name='u0'>" 982 "<input id='un0' type='text' name='u0'>"
980 "<input id='pw0' type='password' name='p0' readonly='readonly'>" 983 "<input id='pw0' type='password' name='p0' readonly='readonly'>"
981 "</form>")); 984 "</form>"));
982 } 985 }
983 986
987 // An HTML page without a password form.
988 static NSString* kHtmlWithoutPasswordForm =
989 @"<h2>The rain in Spain stays <i>mainly</i> in the plain.</h2>";
990
984 // An HTML page containing one password form. The username input field 991 // An HTML page containing one password form. The username input field
985 // also has custom event handlers. We need to verify that those event 992 // also has custom event handlers. We need to verify that those event
986 // handlers are still triggered even though we override them with our own. 993 // handlers are still triggered even though we override them with our own.
987 static NSString* kHtmlWithPasswordForm = 994 static NSString* kHtmlWithPasswordForm =
988 @"<form>" 995 @"<form>"
989 "<input id='un' type='text' name=\"u'\"" 996 "<input id='un' type='text' name=\"u'\""
990 " onkeyup='window.onKeyUpCalled_=true'" 997 " onkeyup='window.onKeyUpCalled_=true'"
991 " onchange='window.onChangeCalled_=true'>" 998 " onchange='window.onChangeCalled_=true'>"
992 "<input id='pw' type='password' name=\"p'\">" 999 "<input id='pw' type='password' name=\"p'\">"
993 "</form>"; 1000 "</form>";
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 LogSavePasswordProgress(testing::Ne( 1286 LogSavePasswordProgress(testing::Ne(
1280 "Message: \"PasswordManager::OnPasswordFormsRendered\"\n"))) 1287 "Message: \"PasswordManager::OnPasswordFormsRendered\"\n")))
1281 .Times(testing::AnyNumber()); 1288 .Times(testing::AnyNumber());
1282 EXPECT_CALL(*weak_client, GetLogManager()) 1289 EXPECT_CALL(*weak_client, GetLogManager())
1283 .WillRepeatedly(Return(&log_manager)); 1290 .WillRepeatedly(Return(&log_manager));
1284 1291
1285 web_state.SetContentIsHTML(false); 1292 web_state.SetContentIsHTML(false);
1286 web_state.SetCurrentURL(GURL("https://example.com")); 1293 web_state.SetCurrentURL(GURL("https://example.com"));
1287 [passwordController webStateDidLoadPage:&web_state]; 1294 [passwordController webStateDidLoadPage:&web_state];
1288 } 1295 }
1296
1297 // Tests that an HTTP page without a password field does not update the SSL
1298 // status to indicate DISPLAYED_PASSWORD_FIELD_ON_HTTP.
1299 TEST_F(PasswordControllerTest, HTTPNoPassword) {
1300 LoadHtml(kHtmlWithoutPasswordForm, GURL("http://chromium.test"));
1301
1302 web::SSLStatus ssl_status =
1303 web_state()->GetNavigationManager()->GetLastCommittedItem()->GetSSL();
1304 EXPECT_FALSE(ssl_status.content_status &
1305 web::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
1306 }
1307
1308 // Tests that an HTTP page with a password field updates the SSL status
1309 // to indicate DISPLAYED_PASSWORD_FIELD_ON_HTTP.
1310 TEST_F(PasswordControllerTest, HTTPPassword) {
1311 LoadHtml(kHtmlWithPasswordForm, GURL("http://chromium.test"));
1312
1313 web::SSLStatus ssl_status =
1314 web_state()->GetNavigationManager()->GetLastCommittedItem()->GetSSL();
1315 EXPECT_TRUE(ssl_status.content_status &
1316 web::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
1317 }
1318
1319 // Tests that an HTTPS page without a password field does not update the SSL
1320 // status to indicate DISPLAYED_PASSWORD_FIELD_ON_HTTP.
1321 TEST_F(PasswordControllerTest, HTTPSNoPassword) {
1322 LoadHtml(kHtmlWithoutPasswordForm, GURL("https://chromium.test"));
1323
1324 web::SSLStatus ssl_status =
1325 web_state()->GetNavigationManager()->GetLastCommittedItem()->GetSSL();
1326 EXPECT_FALSE(ssl_status.content_status &
1327 web::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
1328 }
1329
1330 // Tests that an HTTPS page with a password field does not update the SSL status
1331 // to indicate DISPLAYED_PASSWORD_FIELD_ON_HTTP.
1332 TEST_F(PasswordControllerTest, HTTPSPassword) {
1333 LoadHtml(kHtmlWithPasswordForm, GURL("https://chromium.test"));
1334
1335 web::SSLStatus ssl_status =
1336 web_state()->GetNavigationManager()->GetLastCommittedItem()->GetSSL();
1337 EXPECT_FALSE(ssl_status.content_status &
1338 web::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
1339 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/passwords/password_controller.mm ('k') | ios/chrome/browser/ssl/ios_security_state_tab_helper.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698