Commit 5230c806 authored by Olivier Robin's avatar Olivier Robin Committed by Commit Bot

Call JS using WebFrame when flag is enabled.

This CL does not add support to autofill in iFrames.
Unittests may fail with the Autofill in iFrame flag enabled.
This will be solve in a future CL.

Bug: 881364
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: I38cd09b7aec31d8e47eea8e756ef937bcdde7b1b
Reviewed-on: https://chromium-review.googlesource.com/1230062
Commit-Queue: Olivier Robin <olivierrobin@chromium.org>
Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593160}
parent 2470233f
...@@ -44,16 +44,19 @@ class WebState; ...@@ -44,16 +44,19 @@ class WebState;
(const base::WeakPtr<autofill::AutofillPopupDelegate>&) (const base::WeakPtr<autofill::AutofillPopupDelegate>&)
delegate; delegate;
// The supplied data should be filled into the form. // The supplied data should be filled into the form in |frame|.
- (void)onFormDataFilled:(const autofill::FormData&)result; - (void)onFormDataFilled:(const autofill::FormData&)result
inFrame:(web::WebFrame*)frame;
// Detatches from the web state. // Detatches from the web state.
- (void)detachFromWebState; - (void)detachFromWebState;
// Renders the field type predictions specified in |forms|. This method is a // Renders the field type predictions specified in |forms| in |frame|. This
// no-op if the relevant experiment is not enabled. // method is a no-op if the kAutofillShowTypePredictions experiment is not
// enabled.
- (void)renderAutofillTypePredictions: - (void)renderAutofillTypePredictions:
(const std::vector<autofill::FormDataPredictions>&)forms; (const std::vector<autofill::FormDataPredictions>&)forms
inFrame:(web::WebFrame*)frame;
@end @end
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "ios/web/public/test/fakes/fake_web_frame.h" #include "ios/web/public/test/fakes/fake_web_frame.h"
#import "ios/web/public/test/fakes/test_web_state.h" #import "ios/web/public/test/fakes/test_web_state.h"
#import "ios/web/public/web_state/js/crw_js_injection_receiver.h" #import "ios/web/public/web_state/js/crw_js_injection_receiver.h"
#include "ios/web/public/web_state/web_frame_util.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#import "testing/gtest_mac.h" #import "testing/gtest_mac.h"
...@@ -108,6 +109,7 @@ TEST_F(AutofillAgentTests, OnFormDataFilledTest) { ...@@ -108,6 +109,7 @@ TEST_F(AutofillAgentTests, OnFormDataFilledTest) {
field.value = base::ASCIIToUTF16(""); field.value = base::ASCIIToUTF16("");
field.is_autofilled = true; field.is_autofilled = true;
form.fields.push_back(field); form.fields.push_back(field);
// TODO(crbug.com/881364): Fix for WebFrameMessaging.
// Fields are in alphabetical order. // Fields are in alphabetical order.
[[mock_js_injection_receiver_ expect] [[mock_js_injection_receiver_ expect]
executeJavaScript: executeJavaScript:
...@@ -116,7 +118,8 @@ TEST_F(AutofillAgentTests, OnFormDataFilledTest) { ...@@ -116,7 +118,8 @@ TEST_F(AutofillAgentTests, OnFormDataFilledTest) {
@"\"number\":{\"section\":\"\",\"value\":\"number_value\"}}," @"\"number\":{\"section\":\"\",\"value\":\"number_value\"}},"
@"\"formName\":\"CC form\"}, \"\");" @"\"formName\":\"CC form\"}, \"\");"
completionHandler:[OCMArg any]]; completionHandler:[OCMArg any]];
[autofill_agent_ onFormDataFilled:form]; [autofill_agent_ onFormDataFilled:form
inFrame:web::GetMainWebFrame(&test_web_state_)];
test_web_state_.WasShown(); test_web_state_.WasShown();
EXPECT_OCMOCK_VERIFY(mock_js_injection_receiver_); EXPECT_OCMOCK_VERIFY(mock_js_injection_receiver_);
...@@ -149,6 +152,7 @@ TEST_F(AutofillAgentTests, OnFormDataFilledWithNameCollisionTest) { ...@@ -149,6 +152,7 @@ TEST_F(AutofillAgentTests, OnFormDataFilledWithNameCollisionTest) {
field.value = base::ASCIIToUTF16("value 2"); field.value = base::ASCIIToUTF16("value 2");
field.is_autofilled = true; field.is_autofilled = true;
form.fields.push_back(field); form.fields.push_back(field);
// TODO(crbug.com/881364): Fix for WebFrameMessaging.
// Fields are in alphabetical order. // Fields are in alphabetical order.
[[mock_js_injection_receiver_ expect] [[mock_js_injection_receiver_ expect]
executeJavaScript: executeJavaScript:
...@@ -157,7 +161,8 @@ TEST_F(AutofillAgentTests, OnFormDataFilledWithNameCollisionTest) { ...@@ -157,7 +161,8 @@ TEST_F(AutofillAgentTests, OnFormDataFilledWithNameCollisionTest) {
@"2\"},\"region\":{\"section\":\"\",\"value\":\"California\"}}," @"2\"},\"region\":{\"section\":\"\",\"value\":\"California\"}},"
@"\"formName\":\"\"}, \"\");" @"\"formName\":\"\"}, \"\");"
completionHandler:[OCMArg any]]; completionHandler:[OCMArg any]];
[autofill_agent_ onFormDataFilled:form]; [autofill_agent_ onFormDataFilled:form
inFrame:web::GetMainWebFrame(&test_web_state_)];
test_web_state_.WasShown(); test_web_state_.WasShown();
EXPECT_OCMOCK_VERIFY(mock_js_injection_receiver_); EXPECT_OCMOCK_VERIFY(mock_js_injection_receiver_);
...@@ -169,6 +174,7 @@ TEST_F(AutofillAgentTests, CheckIfSuggestionsAvailable_UserInitiatedActivity1) { ...@@ -169,6 +174,7 @@ TEST_F(AutofillAgentTests, CheckIfSuggestionsAvailable_UserInitiatedActivity1) {
base::test::ScopedFeatureList scoped_feature_list; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature( scoped_feature_list.InitAndEnableFeature(
autofill::features::kAutofillRestrictUnownedFieldsToFormlessCheckout); autofill::features::kAutofillRestrictUnownedFieldsToFormlessCheckout);
// TODO(crbug.com/881364): Fix for WebFrameMessaging.
[[mock_js_injection_receiver_ expect] [[mock_js_injection_receiver_ expect]
executeJavaScript:@"__gCrWeb.autofill.extractForms(1, true);" executeJavaScript:@"__gCrWeb.autofill.extractForms(1, true);"
completionHandler:[OCMArg any]]; completionHandler:[OCMArg any]];
...@@ -194,6 +200,7 @@ TEST_F(AutofillAgentTests, CheckIfSuggestionsAvailable_UserInitiatedActivity2) { ...@@ -194,6 +200,7 @@ TEST_F(AutofillAgentTests, CheckIfSuggestionsAvailable_UserInitiatedActivity2) {
base::test::ScopedFeatureList scoped_feature_list; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndDisableFeature( scoped_feature_list.InitAndDisableFeature(
autofill::features::kAutofillRestrictUnownedFieldsToFormlessCheckout); autofill::features::kAutofillRestrictUnownedFieldsToFormlessCheckout);
// TODO(crbug.com/881364): Fix for WebFrameMessaging.
[[mock_js_injection_receiver_ expect] [[mock_js_injection_receiver_ expect]
executeJavaScript:@"__gCrWeb.autofill.extractForms(1, false);" executeJavaScript:@"__gCrWeb.autofill.extractForms(1, false);"
completionHandler:[OCMArg any]]; completionHandler:[OCMArg any]];
......
...@@ -13,13 +13,17 @@ ...@@ -13,13 +13,17 @@
@interface FakeJSAutofillManager : JsAutofillManager @interface FakeJSAutofillManager : JsAutofillManager
// The name of the form that was most recently passed to // The name of the form that was most recently passed to
// |clearAutofilledFieldsForFormName:fieldIdentifier:completionHandler:|. // |clearAutofilledFieldsForFormName:fieldIdentifier:inFrame:completionHandler:|
@property(nonatomic, copy, readonly) NSString* lastClearedFormName; @property(nonatomic, copy, readonly) NSString* lastClearedFormName;
// The field identifier that was most recently passed to // The field identifier that was most recently passed to
// |clearAutofilledFieldsForFormName:fieldIdentifier:completionHandler:|. // |clearAutofilledFieldsForFormName:fieldIdentifier:inFrame:completionHandler:|
@property(nonatomic, copy, readonly) NSString* lastClearedFieldIdentifier; @property(nonatomic, copy, readonly) NSString* lastClearedFieldIdentifier;
// The field identifier that was most recently passed to
// |clearAutofilledFieldsForFormName:fieldIdentifier:inFrame:completionHandler:|
@property(nonatomic, copy, readonly) NSString* lastClearedFrameIdentifier;
@end @end
#endif // COMPONENTS_AUTOFILL_IOS_BROWSER_FAKE_JS_AUTOFILL_MANAGER_H_ #endif // COMPONENTS_AUTOFILL_IOS_BROWSER_FAKE_JS_AUTOFILL_MANAGER_H_
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
#import "components/autofill/ios/browser/fake_js_autofill_manager.h" #import "components/autofill/ios/browser/fake_js_autofill_manager.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/strings/sys_string_conversions.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "ios/web/public/web_state/web_frame.h"
#include "ios/web/public/web_task_traits.h" #include "ios/web/public/web_task_traits.h"
#include "ios/web/public/web_thread.h" #include "ios/web/public/web_thread.h"
...@@ -17,14 +19,20 @@ ...@@ -17,14 +19,20 @@
@synthesize lastClearedFormName = _lastClearedFormName; @synthesize lastClearedFormName = _lastClearedFormName;
@synthesize lastClearedFieldIdentifier = _lastClearedFieldIdentifier; @synthesize lastClearedFieldIdentifier = _lastClearedFieldIdentifier;
@synthesize lastClearedFrameIdentifier = _lastClearedFrameIdentifier;
- (void)clearAutofilledFieldsForFormName:(NSString*)formName - (void)clearAutofilledFieldsForFormName:(NSString*)formName
fieldIdentifier:(NSString*)fieldIdentifier fieldIdentifier:(NSString*)fieldIdentifier
inFrame:(web::WebFrame*)frame
completionHandler:(ProceduralBlock)completionHandler { completionHandler:(ProceduralBlock)completionHandler {
base::PostTaskWithTraits(FROM_HERE, {web::WebThread::UI}, base::BindOnce(^{ base::PostTaskWithTraits(FROM_HERE, {web::WebThread::UI}, base::BindOnce(^{
_lastClearedFormName = [formName copy]; _lastClearedFormName = [formName copy];
_lastClearedFieldIdentifier = _lastClearedFieldIdentifier =
[fieldIdentifier copy]; [fieldIdentifier copy];
_lastClearedFrameIdentifier =
frame ? base::SysUTF8ToNSString(
frame->GetFrameId())
: nil;
completionHandler(); completionHandler();
})); }));
} }
......
...@@ -6,24 +6,31 @@ ...@@ -6,24 +6,31 @@
#define COMPONENTS_AUTOFILL_IOS_BROWSER_JS_AUTOFILL_MANAGER_H_ #define COMPONENTS_AUTOFILL_IOS_BROWSER_JS_AUTOFILL_MANAGER_H_
#include "base/ios/block_types.h" #include "base/ios/block_types.h"
#include "base/values.h"
#include "components/autofill/core/common/autofill_constants.h" #include "components/autofill/core/common/autofill_constants.h"
#import "ios/web/public/web_state/js/crw_js_injection_receiver.h" #import "ios/web/public/web_state/js/crw_js_injection_receiver.h"
namespace web {
class WebFrame;
}
// Loads the JavaScript file, autofill_controller.js, which contains form // Loads the JavaScript file, autofill_controller.js, which contains form
// parsing and autofill functions. // parsing and autofill functions.
@interface JsAutofillManager : NSObject @interface JsAutofillManager : NSObject
// Extracts forms from a web page. Only forms with at least |requiredFields| // Extracts forms from a web |frame|. Only forms with at least |requiredFields|
// fields are extracted. // fields are extracted.
// |completionHandler| is called with the JSON string of forms of a web page. // |completionHandler| is called with the JSON string of forms of a web page.
// |completionHandler| cannot be nil. // |completionHandler| cannot be nil.
- (void)fetchFormsWithMinimumRequiredFieldsCount:(NSUInteger)requiredFieldsCount - (void)fetchFormsWithMinimumRequiredFieldsCount:(NSUInteger)requiredFieldsCount
inFrame:(web::WebFrame*)frame
completionHandler: completionHandler:
(void (^)(NSString*))completionHandler; (void (^)(NSString*))completionHandler;
// Fills the data in JSON string |dataString| into the active form field, then // Fills the data in JSON string |dataString| into the active form field in
// executes the |completionHandler|. // |frame|, then executes the |completionHandler|.
- (void)fillActiveFormField:(NSString*)dataString - (void)fillActiveFormField:(std::unique_ptr<base::Value>)data
inFrame:(web::WebFrame*)frame
completionHandler:(ProceduralBlock)completionHandler; completionHandler:(ProceduralBlock)completionHandler;
// Fills a number of fields in the same named form for full-form Autofill. // Fills a number of fields in the same named form for full-form Autofill.
...@@ -31,34 +38,39 @@ ...@@ -31,34 +38,39 @@
// Only empty fields will be filled, except that field named // Only empty fields will be filled, except that field named
// |forceFillFieldIdentifier| will always be filled even if non-empty. // |forceFillFieldIdentifier| will always be filled even if non-empty.
// |forceFillFieldIdentifier| may be null. // |forceFillFieldIdentifier| may be null.
// Fields must be contained in |frame|.
// |completionHandler| is called after the forms are filled. |completionHandler| // |completionHandler| is called after the forms are filled. |completionHandler|
// cannot be nil. // cannot be nil.
- (void)fillForm:(NSString*)dataString - (void)fillForm:(std::unique_ptr<base::Value>)data
forceFillFieldIdentifier:(NSString*)forceFillFieldIdentifier forceFillFieldIdentifier:(NSString*)forceFillFieldIdentifier
inFrame:(web::WebFrame*)frame
completionHandler:(ProceduralBlock)completionHandler; completionHandler:(ProceduralBlock)completionHandler;
// Clear autofilled fields of the specified form. Fields that are not currently // Clear autofilled fields of the specified form and frame. Fields that are not
// autofilled are not modified. Field contents are cleared, and Autofill flag // currently autofilled are not modified. Field contents are cleared, and
// and styling are removed. 'change' events are sent for fields whose contents // Autofill flag and styling are removed. 'change' events are sent for fields
// changed. // whose contents changed.
// |fieldIdentifier| identifies the field that initiated the clear action. // |fieldIdentifier| identifies the field that initiated the clear action.
// |completionHandler| is called after the forms are filled. |completionHandler| // |completionHandler| is called after the forms are filled. |completionHandler|
// cannot be nil. // cannot be nil.
- (void)clearAutofilledFieldsForFormName:(NSString*)formName - (void)clearAutofilledFieldsForFormName:(NSString*)formName
fieldIdentifier:(NSString*)fieldIdentifier fieldIdentifier:(NSString*)fieldIdentifier
inFrame:(web::WebFrame*)frame
completionHandler:(ProceduralBlock)completionHandler; completionHandler:(ProceduralBlock)completionHandler;
// Marks up the form with autofill field prediction data (diagnostic tool). // Marks up the form with autofill field prediction data (diagnostic tool).
- (void)fillPredictionData:(NSString*)dataString; - (void)fillPredictionData:(std::unique_ptr<base::Value>)data
inFrame:(web::WebFrame*)frame;
// Adds a delay between filling the form fields. // Adds a delay between filling the form fields in frame.
- (void)addJSDelay; - (void)addJSDelayInFrame:(web::WebFrame*)frame;
// Toggles tracking form related changes in the page. // Toggles tracking form related changes in the frame.
- (void)toggleTrackingFormMutations:(BOOL)state; - (void)toggleTrackingFormMutations:(BOOL)state inFrame:(web::WebFrame*)frame;
// Toggles tracking the source of the input events in the page. // Toggles tracking the source of the input events in the frame.
- (void)toggleTrackingUserEditedFields:(BOOL)state; - (void)toggleTrackingUserEditedFields:(BOOL)state
inFrame:(web::WebFrame*)frame;
// Designated initializer. |receiver| should not be nil. // Designated initializer. |receiver| should not be nil.
- (instancetype)initWithReceiver:(CRWJSInjectionReceiver*)receiver - (instancetype)initWithReceiver:(CRWJSInjectionReceiver*)receiver
......
...@@ -191,7 +191,7 @@ showAutofillPopup:(const std::vector<autofill::Suggestion>&)popup_suggestions ...@@ -191,7 +191,7 @@ showAutofillPopup:(const std::vector<autofill::Suggestion>&)popup_suggestions
- (void)onFormDataFilled:(uint16_t)query_id - (void)onFormDataFilled:(uint16_t)query_id
inFrame:(web::WebFrame*)frame inFrame:(web::WebFrame*)frame
result:(const autofill::FormData&)result { result:(const autofill::FormData&)result {
[_autofillAgent onFormDataFilled:result]; [_autofillAgent onFormDataFilled:result inFrame:frame];
autofill::AutofillManager* manager = [self autofillManagerForFrame:frame]; autofill::AutofillManager* manager = [self autofillManagerForFrame:frame];
if (manager) if (manager)
manager->OnDidFillAutofillFormData(result, base::TimeTicks::Now()); manager->OnDidFillAutofillFormData(result, base::TimeTicks::Now());
...@@ -200,7 +200,7 @@ showAutofillPopup:(const std::vector<autofill::Suggestion>&)popup_suggestions ...@@ -200,7 +200,7 @@ showAutofillPopup:(const std::vector<autofill::Suggestion>&)popup_suggestions
- (void)sendAutofillTypePredictionsToRenderer: - (void)sendAutofillTypePredictionsToRenderer:
(const std::vector<autofill::FormDataPredictions>&)forms (const std::vector<autofill::FormDataPredictions>&)forms
toFrame:(web::WebFrame*)frame { toFrame:(web::WebFrame*)frame {
[_autofillAgent renderAutofillTypePredictions:forms]; [_autofillAgent renderAutofillTypePredictions:forms inFrame:frame];
} }
@end @end
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#import "ios/chrome/browser/web/chrome_web_test.h" #import "ios/chrome/browser/web/chrome_web_test.h"
#import "ios/web/public/test/js_test_util.h" #import "ios/web/public/test/js_test_util.h"
#import "ios/web/public/web_state/js/crw_js_injection_receiver.h" #import "ios/web/public/web_state/js/crw_js_injection_receiver.h"
#include "ios/web/public/web_state/web_frame_util.h"
#import "ios/web/public/web_state/web_state.h" #import "ios/web/public/web_state/web_state.h"
#import "testing/gtest_mac.h" #import "testing/gtest_mac.h"
...@@ -138,12 +139,14 @@ TEST_F(JsAutofillManagerTest, ExtractForms) { ...@@ -138,12 +139,14 @@ TEST_F(JsAutofillManagerTest, ExtractForms) {
__block BOOL block_was_called = NO; __block BOOL block_was_called = NO;
__block NSString* result; __block NSString* result;
[manager_ fetchFormsWithMinimumRequiredFieldsCount: [manager_
autofill::MinRequiredFieldsForHeuristics() fetchFormsWithMinimumRequiredFieldsCount:
completionHandler:^(NSString* actualResult) { autofill::MinRequiredFieldsForHeuristics()
block_was_called = YES; inFrame:web::GetMainWebFrame(web_state())
result = [actualResult copy]; completionHandler:^(NSString* actualResult) {
}]; block_was_called = YES;
result = [actualResult copy];
}];
base::test::ios::WaitUntilCondition(^bool() { base::test::ios::WaitUntilCondition(^bool() {
return block_was_called; return block_was_called;
}); });
...@@ -174,12 +177,14 @@ TEST_F(JsAutofillManagerTest, ExtractFormlessForms_RestrictToFormlessCheckout) { ...@@ -174,12 +177,14 @@ TEST_F(JsAutofillManagerTest, ExtractFormlessForms_RestrictToFormlessCheckout) {
__block BOOL block_was_called = NO; __block BOOL block_was_called = NO;
__block NSString* result; __block NSString* result;
[manager_ fetchFormsWithMinimumRequiredFieldsCount: [manager_
autofill::MinRequiredFieldsForHeuristics() fetchFormsWithMinimumRequiredFieldsCount:
completionHandler:^(NSString* actualResult) { autofill::MinRequiredFieldsForHeuristics()
block_was_called = YES; inFrame:web::GetMainWebFrame(web_state())
result = [actualResult copy]; completionHandler:^(NSString* actualResult) {
}]; block_was_called = YES;
result = [actualResult copy];
}];
base::test::ios::WaitUntilCondition(^bool() { base::test::ios::WaitUntilCondition(^bool() {
return block_was_called; return block_was_called;
}); });
...@@ -207,12 +212,14 @@ TEST_F(JsAutofillManagerTest, ExtractFormlessForms_AllFormlessForms) { ...@@ -207,12 +212,14 @@ TEST_F(JsAutofillManagerTest, ExtractFormlessForms_AllFormlessForms) {
__block BOOL block_was_called = NO; __block BOOL block_was_called = NO;
__block NSString* result; __block NSString* result;
[manager_ fetchFormsWithMinimumRequiredFieldsCount: [manager_
autofill::MinRequiredFieldsForHeuristics() fetchFormsWithMinimumRequiredFieldsCount:
completionHandler:^(NSString* actualResult) { autofill::MinRequiredFieldsForHeuristics()
block_was_called = YES; inFrame:web::GetMainWebFrame(web_state())
result = [actualResult copy]; completionHandler:^(NSString* actualResult) {
}]; block_was_called = YES;
result = [actualResult copy];
}];
base::test::ios::WaitUntilCondition(^bool() { base::test::ios::WaitUntilCondition(^bool() {
return block_was_called; return block_was_called;
}); });
...@@ -237,9 +244,12 @@ TEST_F(JsAutofillManagerTest, FillActiveFormField) { ...@@ -237,9 +244,12 @@ TEST_F(JsAutofillManagerTest, FillActiveFormField) {
NSString* focus_element_javascript = NSString* focus_element_javascript =
[NSString stringWithFormat:@"%@.focus()", get_element_javascript]; [NSString stringWithFormat:@"%@.focus()", get_element_javascript];
ExecuteJavaScript(focus_element_javascript); ExecuteJavaScript(focus_element_javascript);
[manager_ fillActiveFormField: auto data = std::make_unique<base::DictionaryValue>();
@"{\"name\":\"email\",\"identifier\":\"email\",\"value\":" data->SetString("name", "email");
@"\"newemail@com\"}" data->SetString("identifier", "email");
data->SetString("value", "newemail@com");
[manager_ fillActiveFormField:std::move(data)
inFrame:web::GetMainWebFrame(web_state())
completionHandler:^{ completionHandler:^{
}]; }];
...@@ -262,12 +272,14 @@ TEST_F(JsAutofillManagerTest, TestExtractedFieldsNames) { ...@@ -262,12 +272,14 @@ TEST_F(JsAutofillManagerTest, TestExtractedFieldsNames) {
__block BOOL block_was_called = NO; __block BOOL block_was_called = NO;
__block NSString* result; __block NSString* result;
[manager_ fetchFormsWithMinimumRequiredFieldsCount: [manager_
autofill::MinRequiredFieldsForHeuristics() fetchFormsWithMinimumRequiredFieldsCount:
completionHandler:^(NSString* actualResult) { autofill::MinRequiredFieldsForHeuristics()
block_was_called = YES; inFrame:web::GetMainWebFrame(web_state())
result = [actualResult copy]; completionHandler:^(NSString* actualResult) {
}]; block_was_called = YES;
result = [actualResult copy];
}];
base::test::ios::WaitUntilCondition(^bool() { base::test::ios::WaitUntilCondition(^bool() {
return block_was_called; return block_was_called;
}); });
...@@ -331,12 +343,14 @@ TEST_F(JsAutofillManagerTest, TestExtractedFieldsIDs) { ...@@ -331,12 +343,14 @@ TEST_F(JsAutofillManagerTest, TestExtractedFieldsIDs) {
__block BOOL block_was_called = NO; __block BOOL block_was_called = NO;
__block NSString* result; __block NSString* result;
[manager_ fetchFormsWithMinimumRequiredFieldsCount: [manager_
autofill::MinRequiredFieldsForHeuristics() fetchFormsWithMinimumRequiredFieldsCount:
completionHandler:^(NSString* actualResult) { autofill::MinRequiredFieldsForHeuristics()
block_was_called = YES; inFrame:web::GetMainWebFrame(web_state())
result = [actualResult copy]; completionHandler:^(NSString* actualResult) {
}]; block_was_called = YES;
result = [actualResult copy];
}];
base::test::ios::WaitUntilCondition(^bool() { base::test::ios::WaitUntilCondition(^bool() {
return block_was_called; return block_was_called;
}); });
......
...@@ -133,9 +133,13 @@ ...@@ -133,9 +133,13 @@
- (void)clearFormWithName:(NSString*)formName - (void)clearFormWithName:(NSString*)formName
fieldIdentifier:(NSString*)fieldIdentifier fieldIdentifier:(NSString*)fieldIdentifier
frameID:(NSString*)frameID
completionHandler:(nullable void (^)(void))completionHandler { completionHandler:(nullable void (^)(void))completionHandler {
web::WebFrame* frame =
web::GetWebFrameWithId(_webState, base::SysNSStringToUTF8(frameID));
[_JSAutofillManager clearAutofilledFieldsForFormName:formName [_JSAutofillManager clearAutofilledFieldsForFormName:formName
fieldIdentifier:fieldIdentifier fieldIdentifier:fieldIdentifier
inFrame:frame
completionHandler:^{ completionHandler:^{
if (completionHandler) { if (completionHandler) {
completionHandler(); completionHandler();
...@@ -352,7 +356,7 @@ showUnmaskPromptForCard:(const autofill::CreditCard&)creditCard ...@@ -352,7 +356,7 @@ showUnmaskPromptForCard:(const autofill::CreditCard&)creditCard
- (void)onFormDataFilled:(uint16_t)query_id - (void)onFormDataFilled:(uint16_t)query_id
inFrame:(web::WebFrame*)frame inFrame:(web::WebFrame*)frame
result:(const autofill::FormData&)result { result:(const autofill::FormData&)result {
[_autofillAgent onFormDataFilled:result]; [_autofillAgent onFormDataFilled:result inFrame:frame];
autofill::AutofillManager* manager = [self autofillManagerForFrame:frame]; autofill::AutofillManager* manager = [self autofillManagerForFrame:frame];
if (manager) { if (manager) {
manager->OnDidFillAutofillFormData(result, base::TimeTicks::Now()); manager->OnDidFillAutofillFormData(result, base::TimeTicks::Now());
......
...@@ -157,9 +157,13 @@ TEST_F(CWVAutofillControllerTest, FillSuggestion) { ...@@ -157,9 +157,13 @@ TEST_F(CWVAutofillControllerTest, FillSuggestion) {
// Tests CWVAutofillController clears form. // Tests CWVAutofillController clears form.
TEST_F(CWVAutofillControllerTest, ClearForm) { TEST_F(CWVAutofillControllerTest, ClearForm) {
auto frame = std::make_unique<web::FakeWebFrame>(
base::SysNSStringToUTF8(kTestFrameId), true, GURL::EmptyGURL());
web_state_.AddWebFrame(std::move(frame));
__block BOOL clear_form_completion_was_called = NO; __block BOOL clear_form_completion_was_called = NO;
[autofill_controller_ clearFormWithName:kTestFormName [autofill_controller_ clearFormWithName:kTestFormName
fieldIdentifier:kTestFieldIdentifier fieldIdentifier:kTestFieldIdentifier
frameID:kTestFrameId
completionHandler:^{ completionHandler:^{
clear_form_completion_was_called = YES; clear_form_completion_was_called = YES;
}]; }];
...@@ -171,6 +175,7 @@ TEST_F(CWVAutofillControllerTest, ClearForm) { ...@@ -171,6 +175,7 @@ TEST_F(CWVAutofillControllerTest, ClearForm) {
EXPECT_NSEQ(kTestFormName, js_autofill_manager_.lastClearedFormName); EXPECT_NSEQ(kTestFormName, js_autofill_manager_.lastClearedFormName);
EXPECT_NSEQ(kTestFieldIdentifier, EXPECT_NSEQ(kTestFieldIdentifier,
js_autofill_manager_.lastClearedFieldIdentifier); js_autofill_manager_.lastClearedFieldIdentifier);
EXPECT_NSEQ(kTestFrameId, js_autofill_manager_.lastClearedFrameIdentifier);
} }
// Tests CWVAutofillController focus previous field. // Tests CWVAutofillController focus previous field.
......
...@@ -25,7 +25,8 @@ CWV_EXPORT ...@@ -25,7 +25,8 @@ CWV_EXPORT
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
// Clears the fields that belong to the same autofill section as the field // Clears the fields that belong to the same autofill section as the field
// identified by |fieldIdentifier| in the form named |formName|. // identified by |fieldIdentifier| in the form named |formName| in frame
// |frameID|.
// No-op if no such form can be found in the current page. If the field // No-op if no such form can be found in the current page. If the field
// identified by |fieldIdentifier| cannot be found the entire form gets cleared. // identified by |fieldIdentifier| cannot be found the entire form gets cleared.
// |fieldIdentifier| identifies the field that had focus. It is passed to // |fieldIdentifier| identifies the field that had focus. It is passed to
...@@ -33,6 +34,7 @@ CWV_EXPORT ...@@ -33,6 +34,7 @@ CWV_EXPORT
// |completionHandler| will only be called on success. // |completionHandler| will only be called on success.
- (void)clearFormWithName:(NSString*)formName - (void)clearFormWithName:(NSString*)formName
fieldIdentifier:(NSString*)fieldIdentifier fieldIdentifier:(NSString*)fieldIdentifier
frameID:(NSString*)frameID
completionHandler:(nullable void (^)(void))completionHandler; completionHandler:(nullable void (^)(void))completionHandler;
// For the field named |fieldName|, identified by |fieldIdentifier| in the form // For the field named |fieldName|, identified by |fieldIdentifier| in the form
......
...@@ -71,6 +71,7 @@ ...@@ -71,6 +71,7 @@
handler:^(UIAlertAction* _Nonnull action) { handler:^(UIAlertAction* _Nonnull action) {
[autofillController clearFormWithName:formName [autofillController clearFormWithName:formName
fieldIdentifier:fieldIdentifier fieldIdentifier:fieldIdentifier
frameID:frameID
completionHandler:nil]; completionHandler:nil];
}]; }];
[alertController addAction:clearAction]; [alertController addAction:clearAction];
......
...@@ -210,6 +210,7 @@ TEST_F(WebViewAutofillTest, TestSuggestionFetchFillClear) { ...@@ -210,6 +210,7 @@ TEST_F(WebViewAutofillTest, TestSuggestionFetchFillClear) {
ASSERT_NSEQ(nil, filled_error); ASSERT_NSEQ(nil, filled_error);
[autofill_controller_ clearFormWithName:kTestFormName [autofill_controller_ clearFormWithName:kTestFormName
fieldIdentifier:kTestFieldID fieldIdentifier:kTestFieldID
frameID:kTestFrameID
completionHandler:nil]; completionHandler:nil];
NSString* cleared_script = [NSString NSString* cleared_script = [NSString
stringWithFormat:@"document.getElementById('%@').value", kTestFieldID]; stringWithFormat:@"document.getElementById('%@').value", kTestFieldID];
......
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