Commit 333b2496 authored by Javier Ernesto Flores Robles's avatar Javier Ernesto Flores Robles Committed by Commit Bot

[iOS][MF] Model for passwords view controller

Obj-c model for the manual fallback passwords view controller. Also adds
a convenience initializer from a password form.

Bug: 845472
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I0bdd704eb9cfa075f7cd78bdea2eaed191cd5bd0
Reviewed-on: https://chromium-review.googlesource.com/1172348Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584073}
parent f6323455
# Copyright 2017 The Chromium Authors. All rights reserved. # Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
...@@ -6,15 +6,50 @@ import("//ios/web/js_compile.gni") ...@@ -6,15 +6,50 @@ import("//ios/web/js_compile.gni")
source_set("manual_fill") { source_set("manual_fill") {
sources = [ sources = [
"keyboard_accessory_view.h", "credential_password_form.h",
"keyboard_accessory_view.mm", "credential_password_form.mm",
] ]
deps = [ deps = [
"//base", "//base",
"//components/autofill/core/common",
"//components/password_manager/core/browser",
"//ios/chrome/browser/autofill/manual_fill:manual_fill",
"//ios/chrome/browser/ui/autofill/manual_fill:manual_fill_ui",
"//net:net",
"//third_party/material_design_icons:ic_account_circle", "//third_party/material_design_icons:ic_account_circle",
"//third_party/material_design_icons:ic_credit_card", "//third_party/material_design_icons:ic_credit_card",
"//third_party/material_design_icons:ic_vpn_key", "//third_party/material_design_icons:ic_vpn_key",
"//url:url",
] ]
libs = [ "UIKit.framework" ] libs = [ "UIKit.framework" ]
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
} }
source_set("manual_fill_ui") {
sources = [
"credential.h",
"credential.mm",
]
deps = [
"//base",
]
libs = [ "UIKit.framework" ]
configs += [ "//build/config/compiler:enable_arc" ]
}
source_set("unit_tests") {
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
"credential_password_form_unittest.mm",
"credential_unittest.mm",
]
deps = [
":manual_fill",
":manual_fill_ui",
"//base:base",
"//components/autofill/core/common:common",
"//testing/gtest:gtest",
"//url:url",
]
}
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_CREDENTIAL_H_
#define IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_CREDENTIAL_H_
#import <Foundation/Foundation.h>
// This represents a user credential to use with manual fill.
@interface ManualFillCredential : NSObject
// The username related to this credential.
@property(nonatomic, readonly) NSString* username;
// The password related to this credential.
@property(nonatomic, readonly) NSString* password;
// The site name is the last part of the domain. In some cases it will be the
// same as the host, i.e. if is not identified, or the host is equal to the site
// name.
@property(nonatomic, readonly) NSString* siteName;
// The host part of the credential, it should have "www." stripped if present.
@property(nonatomic, readonly) NSString* host;
// Default init.
- (instancetype)initWithUsername:(NSString*)username
password:(NSString*)password
siteName:(NSString*)siteName
host:(NSString*)host NS_DESIGNATED_INITIALIZER;
// Unavailable. Please use |initWithUsername:password:siteName:host:|.
- (instancetype)init NS_UNAVAILABLE;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_CREDENTIAL_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/autofill/manual_fill/credential.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation ManualFillCredential
@synthesize username = _username;
@synthesize password = _password;
@synthesize siteName = _siteName;
@synthesize host = _host;
- (instancetype)initWithUsername:(NSString*)username
password:(NSString*)password
siteName:(NSString*)siteName
host:(NSString*)host {
self = [super init];
if (self) {
_host = [host copy];
_siteName = [siteName copy];
_username = [username copy];
_password = [password copy];
}
return self;
}
- (BOOL)isEqual:(id)object {
if (!object) {
return NO;
}
if (self == object) {
return YES;
}
if (![object isMemberOfClass:[ManualFillCredential class]]) {
return NO;
}
ManualFillCredential* otherObject = (ManualFillCredential*)object;
if (![otherObject.host isEqual:self.host]) {
return NO;
}
if (![otherObject.username isEqual:self.username]) {
return NO;
}
if (![otherObject.password isEqual:self.password]) {
return NO;
}
if (![otherObject.siteName isEqual:self.siteName]) {
return NO;
}
return YES;
}
- (NSUInteger)hash {
return [self.host hash] ^ [self.username hash] ^ [self.password hash];
}
- (NSString*)description {
return [NSString
stringWithFormat:@"<%@ (%p): username: %@, siteName: %@, host: %@>",
NSStringFromClass([self class]), self, self.username,
self.siteName, self.host];
}
@end
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_CREDENTIAL_PASSWORD_FORM_H_
#define IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_CREDENTIAL_PASSWORD_FORM_H_
#import "ios/chrome/browser/ui/autofill/manual_fill/credential.h"
namespace autofill {
struct PasswordForm;
}
@interface ManualFillCredential (PasswordForm)
// Convenience initializer from a PasswordForm.
- (instancetype)initWithPasswordForm:
(const autofill::PasswordForm&)passwordForm;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_CREDENTIAL_PASSWORD_FORM_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/autofill/manual_fill/credential_password_form.h"
#include "base/strings/sys_string_conversions.h"
#include "components/autofill/core/common/password_form.h"
#include "components/password_manager/core/browser/password_ui_utils.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation ManualFillCredential (PasswordForm)
- (instancetype)initWithPasswordForm:
(const autofill::PasswordForm&)passwordForm {
std::string host = passwordForm.origin.host();
std::string site_name =
net::registry_controlled_domains::GetDomainAndRegistry(
host, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
NSString* siteName = base::SysUTF8ToNSString(site_name);
NSString* username = base::SysUTF16ToNSString(passwordForm.username_value);
NSString* password = base::SysUTF16ToNSString(passwordForm.password_value);
NSString* credentialHost = base::SysUTF8ToNSString(host);
if ([credentialHost hasPrefix:@"www."] && credentialHost.length > 4) {
credentialHost = [credentialHost substringFromIndex:4];
}
return [self initWithUsername:username
password:password
siteName:siteName.length ? siteName : credentialHost
host:credentialHost];
}
@end
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/autofill/manual_fill/credential_password_form.h"
#include "base/strings/sys_string_conversions.h"
#include "components/autofill/core/common/password_form.h"
#include "testing/platform_test.h"
#include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using autofill::PasswordForm;
using ManualFillCredentialFormPasswordiOSTest = PlatformTest;
// Tests the creation of a credential from a password form.
TEST_F(ManualFillCredentialFormPasswordiOSTest, CreationHTTPURL) {
NSString* password = @"password_value";
NSString* username = @"username_value";
NSString* url = @"http://www.alpha.example.com/path/";
PasswordForm passwordForm = PasswordForm();
passwordForm.password_value = base::SysNSStringToUTF16(password);
passwordForm.username_value = base::SysNSStringToUTF16(username);
passwordForm.origin = GURL(base::SysNSStringToUTF16(url));
ManualFillCredential* credential =
[[ManualFillCredential alloc] initWithPasswordForm:passwordForm];
EXPECT_TRUE(credential);
EXPECT_TRUE([username isEqualToString:credential.username]);
EXPECT_TRUE([password isEqualToString:credential.password]);
EXPECT_TRUE([@"example.com" isEqualToString:credential.siteName]);
EXPECT_TRUE([@"alpha.example.com" isEqualToString:credential.host]);
}
// Tests the creation of a credential from a password form.
TEST_F(ManualFillCredentialFormPasswordiOSTest, CreationHTTPSURL) {
NSString* password = @"password_value";
NSString* username = @"username_value";
NSString* url = @"https://www.alpha.example.com/path/";
PasswordForm passwordForm = PasswordForm();
passwordForm.password_value = base::SysNSStringToUTF16(password);
passwordForm.username_value = base::SysNSStringToUTF16(username);
passwordForm.origin = GURL(base::SysNSStringToUTF16(url));
ManualFillCredential* credential =
[[ManualFillCredential alloc] initWithPasswordForm:passwordForm];
EXPECT_TRUE(credential);
EXPECT_TRUE([username isEqualToString:credential.username]);
EXPECT_TRUE([password isEqualToString:credential.password]);
EXPECT_TRUE([@"example.com" isEqualToString:credential.siteName]);
EXPECT_TRUE([@"alpha.example.com" isEqualToString:credential.host]);
}
// Tests the creation of a credential from a password form.
TEST_F(ManualFillCredentialFormPasswordiOSTest, CreationNoWWW) {
NSString* password = @"password_value";
NSString* username = @"username_value";
NSString* url = @"http://alpha.example.com/path/";
PasswordForm passwordForm = PasswordForm();
passwordForm.password_value = base::SysNSStringToUTF16(password);
passwordForm.username_value = base::SysNSStringToUTF16(username);
passwordForm.origin = GURL(base::SysNSStringToUTF16(url));
ManualFillCredential* credential =
[[ManualFillCredential alloc] initWithPasswordForm:passwordForm];
EXPECT_TRUE(credential);
EXPECT_TRUE([username isEqualToString:credential.username]);
EXPECT_TRUE([password isEqualToString:credential.password]);
EXPECT_TRUE([@"example.com" isEqualToString:credential.siteName]);
EXPECT_TRUE([@"alpha.example.com" isEqualToString:credential.host]);
}
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/autofill/manual_fill/credential.h"
#include "testing/platform_test.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using ManualFillCredentialiOSTest = PlatformTest;
// Tests that a credential is correctly created.
TEST_F(ManualFillCredentialiOSTest, Creation) {
NSString* username = @"username@example.com";
NSString* password = @"password";
NSString* siteName = @"example.com";
NSString* host = @"sub.example.com";
ManualFillCredential* credential =
[[ManualFillCredential alloc] initWithUsername:username
password:password
siteName:siteName
host:host];
EXPECT_TRUE(credential);
EXPECT_TRUE([username isEqualToString:credential.username]);
EXPECT_TRUE([password isEqualToString:credential.password]);
EXPECT_TRUE([siteName isEqualToString:credential.siteName]);
EXPECT_TRUE([host isEqualToString:credential.host]);
}
// Test equality between credentials.
TEST_F(ManualFillCredentialiOSTest, Equality) {
NSString* username = @"username@example.com";
NSString* password = @"password";
NSString* siteName = @"example.com";
NSString* host = @"sub.example.com";
ManualFillCredential* credential =
[[ManualFillCredential alloc] initWithUsername:username
password:password
siteName:siteName
host:host];
ManualFillCredential* equalCredential =
[[ManualFillCredential alloc] initWithUsername:username
password:password
siteName:siteName
host:host];
EXPECT_TRUE([credential isEqual:equalCredential]);
ManualFillCredential* differentUsernameCredential =
[[ManualFillCredential alloc] initWithUsername:@"username2"
password:password
siteName:siteName
host:host];
EXPECT_FALSE([credential isEqual:differentUsernameCredential]);
ManualFillCredential* differentPasswordCredential =
[[ManualFillCredential alloc] initWithUsername:username
password:@"psswd"
siteName:siteName
host:host];
EXPECT_FALSE([credential isEqual:differentPasswordCredential]);
ManualFillCredential* differentSiteNameCredential =
[[ManualFillCredential alloc] initWithUsername:username
password:password
siteName:@"notexample.com"
host:host];
EXPECT_FALSE([credential isEqual:differentSiteNameCredential]);
ManualFillCredential* differentHostCredential =
[[ManualFillCredential alloc] initWithUsername:username
password:password
siteName:siteName
host:@"other.example.com"];
EXPECT_FALSE([credential isEqual:differentHostCredential]);
}
...@@ -179,6 +179,7 @@ test("ios_chrome_unittests") { ...@@ -179,6 +179,7 @@ test("ios_chrome_unittests") {
"//ios/chrome/browser/ui/app_launcher:unit_tests", "//ios/chrome/browser/ui/app_launcher:unit_tests",
"//ios/chrome/browser/ui/authentication:unit_tests", "//ios/chrome/browser/ui/authentication:unit_tests",
"//ios/chrome/browser/ui/autofill/cells:unit_tests", "//ios/chrome/browser/ui/autofill/cells:unit_tests",
"//ios/chrome/browser/ui/autofill/manual_fill:unit_tests",
"//ios/chrome/browser/ui/bookmarks:unit_tests", "//ios/chrome/browser/ui/bookmarks:unit_tests",
"//ios/chrome/browser/ui/bookmarks/cells:unit_tests", "//ios/chrome/browser/ui/bookmarks/cells:unit_tests",
"//ios/chrome/browser/ui/broadcaster:unit_tests", "//ios/chrome/browser/ui/broadcaster:unit_tests",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment