Commit 45e6b9e2 authored by Olivier Robin's avatar Olivier Robin Committed by Commit Bot

Migrate remaining calls to WebState form activity methods

- Create test utils
- Move the FormActivityTabHelper from WebStateObserver to Script callback
- Remove all the methods from WebState and WebStateObserver.

Bug: 823285
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I0953a91144524018dbff154b2ff5b7bd18e17013
Reviewed-on: https://chromium-review.googlesource.com/1133000
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@{#575630}
parent 72cc1de4
...@@ -20,20 +20,43 @@ source_set("form_util") { ...@@ -20,20 +20,43 @@ source_set("form_util") {
] ]
} }
source_set("test_support") {
testonly = true
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"test_form_activity_observer.h",
"test_form_activity_observer.mm",
"test_form_activity_tab_helper.h",
"test_form_activity_tab_helper.mm",
]
deps = [
":form_util",
"//base",
"//ios/web/public",
"//testing/gtest",
]
}
source_set("unit_tests") { source_set("unit_tests") {
testonly = true testonly = true
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
sources = [ sources = [
"fill_js_unittest.mm", "fill_js_unittest.mm",
"form_activity_observer_bridge_unittest.mm",
"form_activity_tab_helper_unittest.mm",
"form_unittest.mm", "form_unittest.mm",
] ]
deps = [ deps = [
":form_js", ":form_js",
":form_util",
":test_support",
"//base", "//base",
"//base/test:test_support",
"//ios/chrome/app:tests_fake_hook", "//ios/chrome/app:tests_fake_hook",
"//ios/chrome/browser/browser_state:test_support", "//ios/chrome/browser/browser_state:test_support",
"//ios/chrome/browser/tabs:tabs_internal", "//ios/chrome/browser/tabs:tabs_internal",
"//ios/chrome/browser/web:test_support", "//ios/chrome/browser/web:test_support",
"//ios/testing:ios_test_support",
"//ios/web/public/test", "//ios/web/public/test",
"//ios/web/public/test/fakes", "//ios/web/public/test/fakes",
"//ios/web/web_state/js", "//ios/web/web_state/js",
......
specific_include_rules = { specific_include_rules = {
# Unittests using form.js need page_script_util to inject the script.
"form_unittest\.mm": [ "form_unittest\.mm": [
"+ios/web/web_state/js/page_script_util.h", "+ios/web/web_state/js/page_script_util.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 "components/autofill/ios/form_util/form_activity_observer_bridge.h"
#include "components/autofill/ios/form_util/test_form_activity_observer.h"
#import "ios/web/public/test/fakes/test_web_state.h"
#include "testing/platform_test.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface FakeFormActivityObserver : NSObject<FormActivityObserver>
// Arguments passed to |webState:didSubmitDocumentWithFormNamed:userInitiated:|.
@property(nonatomic, readonly)
autofill::TestSubmitDocumentInfo* submitDocumentInfo;
// Arguments passed to
// |webState:didRegisterFormActivity:|.
@property(nonatomic, readonly) autofill::TestFormActivityInfo* formActivityInfo;
@end
@implementation FakeFormActivityObserver {
// Arguments passed to
// |webState:submittedDocumentWithFormNamed:hasUserGesture:formInMainFrame:|.
std::unique_ptr<autofill::TestSubmitDocumentInfo> _submitDocumentInfo;
// Arguments passed to
// |webState:registeredFormActivity:|.
std::unique_ptr<autofill::TestFormActivityInfo> _formActivityInfo;
}
- (autofill::TestSubmitDocumentInfo*)submitDocumentInfo {
return _submitDocumentInfo.get();
}
- (autofill::TestFormActivityInfo*)formActivityInfo {
return _formActivityInfo.get();
}
- (void)webState:(web::WebState*)webState
submittedDocumentWithFormNamed:(const std::string&)formName
hasUserGesture:(BOOL)hasUserGesture
formInMainFrame:(BOOL)formInMainFrame {
_submitDocumentInfo = std::make_unique<autofill::TestSubmitDocumentInfo>();
_submitDocumentInfo->web_state = webState;
_submitDocumentInfo->form_name = formName;
_submitDocumentInfo->has_user_gesture = hasUserGesture;
_submitDocumentInfo->form_in_main_frame = formInMainFrame;
}
- (void)webState:(web::WebState*)webState
registeredFormActivity:(const web::FormActivityParams&)params {
_formActivityInfo = std::make_unique<autofill::TestFormActivityInfo>();
_formActivityInfo->web_state = webState;
_formActivityInfo->form_activity = params;
}
@end
// Test fixture to test WebStateObserverBridge class.
class FormActivityObserverBridgeTest : public PlatformTest {
public:
FormActivityObserverBridgeTest()
: observer_([[FakeFormActivityObserver alloc] init]),
observer_bridge_(&test_web_state_, observer_) {}
protected:
web::TestWebState test_web_state_;
FakeFormActivityObserver* observer_;
autofill::FormActivityObserverBridge observer_bridge_;
};
// Tests |webState:didRegisterFormActivityWithParams:| forwarding.
TEST_F(FormActivityObserverBridgeTest, DocumentSubmitted) {
ASSERT_FALSE([observer_ submitDocumentInfo]);
std::string kTestFormName("form-name");
bool has_user_gesture = true;
bool form_in_main_frame = true;
observer_bridge_.DidSubmitDocument(&test_web_state_, kTestFormName,
has_user_gesture, form_in_main_frame);
ASSERT_TRUE([observer_ submitDocumentInfo]);
EXPECT_EQ(&test_web_state_, [observer_ submitDocumentInfo]->web_state);
EXPECT_EQ(kTestFormName, [observer_ submitDocumentInfo]->form_name);
EXPECT_EQ(has_user_gesture, [observer_ submitDocumentInfo]->has_user_gesture);
EXPECT_EQ(form_in_main_frame,
[observer_ submitDocumentInfo]->form_in_main_frame);
}
// Tests |webState:didRegisterFormActivity:...| forwarding.
TEST_F(FormActivityObserverBridgeTest, FormActivityRegistered) {
ASSERT_FALSE([observer_ formActivityInfo]);
web::FormActivityParams params;
params.form_name = "form-name";
params.field_name = "field-name";
params.field_type = "field-type";
params.type = "type";
params.value = "value";
params.input_missing = true;
observer_bridge_.OnFormActivity(&test_web_state_, params);
ASSERT_TRUE([observer_ formActivityInfo]);
EXPECT_EQ(&test_web_state_, [observer_ formActivityInfo]->web_state);
EXPECT_EQ(params.form_name,
[observer_ formActivityInfo]->form_activity.form_name);
EXPECT_EQ(params.field_name,
[observer_ formActivityInfo]->form_activity.field_name);
EXPECT_EQ(params.field_type,
[observer_ formActivityInfo]->form_activity.field_type);
EXPECT_EQ(params.type, [observer_ formActivityInfo]->form_activity.type);
EXPECT_EQ(params.value, [observer_ formActivityInfo]->form_activity.value);
EXPECT_TRUE([observer_ formActivityInfo]->form_activity.input_missing);
}
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/values.h"
#import "ios/web/public/web_state/ui/crw_web_view_proxy.h"
#include "ios/web/public/web_state/web_state_observer.h" #include "ios/web/public/web_state/web_state_observer.h"
#import "ios/web/public/web_state/web_state_user_data.h" #import "ios/web/public/web_state/web_state_user_data.h"
...@@ -26,22 +28,36 @@ class FormActivityTabHelper ...@@ -26,22 +28,36 @@ class FormActivityTabHelper
web::WebState* web_state); web::WebState* web_state);
// Observer registration methods. // Observer registration methods.
void AddObserver(FormActivityObserver* observer); virtual void AddObserver(FormActivityObserver* observer);
void RemoveObserver(FormActivityObserver* observer); virtual void RemoveObserver(FormActivityObserver* observer);
private: private:
friend class web::WebStateUserData<FormActivityTabHelper>; friend class web::WebStateUserData<FormActivityTabHelper>;
// TestFormActivityTabHelper can be used by tests that want to simulate form
// events without loading page and executing JavaScript.
// To trigger events, TestFormActivityTabHelper will access |observer_|.
friend class TestFormActivityTabHelper;
explicit FormActivityTabHelper(web::WebState* web_state); explicit FormActivityTabHelper(web::WebState* web_state);
// WebStateObserver implementation. // WebStateObserver implementation.
void WebStateDestroyed(web::WebState* web_state) override; void WebStateDestroyed(web::WebState* web_state) override;
void DocumentSubmitted(web::WebState* web_state, // Handler for "form.activity" JavaScript command.
const std::string& form_name, bool HandleFormActivity(const base::DictionaryValue& message,
bool user_initiated, bool has_user_gesture,
bool is_main_frame) override; bool form_in_main_frame);
void FormActivityRegistered(web::WebState* web_state,
const web::FormActivityParams& params) override; // Handler for "form.submit" JavaScript command.
bool FormSubmissionHandler(const base::DictionaryValue& message,
bool has_user_gesture,
bool form_in_main_frame);
// Handler for "form.*" JavaScript command. Dispatch to more specific handler.
bool OnFormCommand(const base::DictionaryValue& message,
const GURL& url,
bool has_user_gesture,
bool form_in_main_frame);
// The WebState this instance is observing. Will be null after // The WebState this instance is observing. Will be null after
// WebStateDestroyed has been called. // WebStateDestroyed has been called.
......
...@@ -18,7 +18,11 @@ DEFINE_WEB_STATE_USER_DATA_KEY(autofill::FormActivityTabHelper); ...@@ -18,7 +18,11 @@ DEFINE_WEB_STATE_USER_DATA_KEY(autofill::FormActivityTabHelper);
namespace autofill { namespace autofill {
FormActivityTabHelper::~FormActivityTabHelper() = default; namespace {
// Prefix for the form activity event commands. Must be kept in sync with
// form.js.
const char kCommandPrefix[] = "form";
}
// static // static
FormActivityTabHelper* FormActivityTabHelper::GetOrCreateForWebState( FormActivityTabHelper* FormActivityTabHelper::GetOrCreateForWebState(
...@@ -35,6 +39,18 @@ FormActivityTabHelper* FormActivityTabHelper::GetOrCreateForWebState( ...@@ -35,6 +39,18 @@ FormActivityTabHelper* FormActivityTabHelper::GetOrCreateForWebState(
FormActivityTabHelper::FormActivityTabHelper(web::WebState* web_state) FormActivityTabHelper::FormActivityTabHelper(web::WebState* web_state)
: web_state_(web_state) { : web_state_(web_state) {
web_state_->AddObserver(this); web_state_->AddObserver(this);
web_state_->AddScriptCommandCallback(
base::BindRepeating(&FormActivityTabHelper::OnFormCommand,
base::Unretained(this)),
kCommandPrefix);
}
FormActivityTabHelper::~FormActivityTabHelper() {
if (web_state_) {
web_state_->RemoveObserver(this);
web_state_->RemoveScriptCommandCallback(kCommandPrefix);
web_state_ = nullptr;
}
} }
void FormActivityTabHelper::AddObserver(FormActivityObserver* observer) { void FormActivityTabHelper::AddObserver(FormActivityObserver* observer) {
...@@ -45,24 +61,71 @@ void FormActivityTabHelper::RemoveObserver(FormActivityObserver* observer) { ...@@ -45,24 +61,71 @@ void FormActivityTabHelper::RemoveObserver(FormActivityObserver* observer) {
observers_.RemoveObserver(observer); observers_.RemoveObserver(observer);
} }
void FormActivityTabHelper::FormActivityRegistered( bool FormActivityTabHelper::OnFormCommand(const base::DictionaryValue& message,
web::WebState* web_state, const GURL& url,
const web::FormActivityParams& params) { bool has_user_gesture,
bool form_in_main_frame) {
std::string command;
if (!message.GetString("command", &command)) {
DLOG(WARNING) << "JS message parameter not found: command";
return NO;
}
if (command == "form.submit") {
return FormSubmissionHandler(message, has_user_gesture, form_in_main_frame);
}
if (command == "form.activity") {
return HandleFormActivity(message, has_user_gesture, form_in_main_frame);
}
return false;
}
bool FormActivityTabHelper::HandleFormActivity(
const base::DictionaryValue& message,
bool has_user_gesture,
bool form_in_main_frame) {
web::FormActivityParams params;
if (!message.GetString("formName", &params.form_name) ||
!message.GetString("fieldName", &params.field_name) ||
!message.GetString("fieldIdentifier", &params.field_identifier) ||
!message.GetString("fieldType", &params.field_type) ||
!message.GetString("type", &params.type) ||
!message.GetString("value", &params.value) ||
!message.GetBoolean("hasUserGesture", &params.has_user_gesture)) {
params.input_missing = true;
}
params.is_main_frame = form_in_main_frame;
for (auto& observer : observers_) for (auto& observer : observers_)
observer.OnFormActivity(web_state, params); observer.OnFormActivity(web_state_, params);
return true;
} }
void FormActivityTabHelper::DocumentSubmitted(web::WebState* web_state, bool FormActivityTabHelper::FormSubmissionHandler(
const std::string& form_name, const base::DictionaryValue& message,
bool user_initiated, bool has_user_gesture,
bool is_main_frame) { bool form_in_main_frame) {
std::string href;
if (!message.GetString("href", &href)) {
DLOG(WARNING) << "JS message parameter not found: href";
return false;
}
std::string form_name;
message.GetString("formName", &form_name);
// We decide the form is user-submitted if the user has interacted with
// the main page (using logic from the popup blocker), or if the keyboard
// is visible.
BOOL submitted_by_user =
has_user_gesture || [web_state_->GetWebViewProxy() keyboardAccessory];
for (auto& observer : observers_) for (auto& observer : observers_)
observer.DidSubmitDocument(web_state, form_name, user_initiated, observer.DidSubmitDocument(web_state_, form_name, submitted_by_user,
is_main_frame); form_in_main_frame);
return true;
} }
void FormActivityTabHelper::WebStateDestroyed(web::WebState* web_state) { void FormActivityTabHelper::WebStateDestroyed(web::WebState* web_state) {
DCHECK_EQ(web_state_, web_state); DCHECK_EQ(web_state_, web_state);
web_state_->RemoveScriptCommandCallback(kCommandPrefix);
web_state_->RemoveObserver(this); web_state_->RemoveObserver(this);
web_state_ = nullptr; web_state_ = nullptr;
} }
......
// 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 "components/autofill/ios/form_util/form_activity_tab_helper.h"
#import "base/test/ios/wait_util.h"
#import "components/autofill/ios/form_util/form_activity_observer.h"
#import "components/autofill/ios/form_util/test_form_activity_observer.h"
#import "ios/web/public/test/fakes/test_web_client.h"
#import "ios/web/public/test/fakes/test_web_state.h"
#import "ios/web/public/test/fakes/test_web_state_observer_util.h"
#import "ios/web/public/test/web_js_test.h"
#import "ios/web/public/test/web_test_with_web_state.h"
#include "testing/platform_test.h"
// Test fixture for autofill::FormActivityTabHelper class.
class FormActivityTabHelperTest
: public web::WebJsTest<web::WebTestWithWebState> {
public:
FormActivityTabHelperTest()
: web::WebJsTest<web::WebTestWithWebState>(
@[ @"chrome_bundle_all_frames" ]) {}
void SetUp() override {
web::WebJsTest<web::WebTestWithWebState>::SetUp();
autofill::FormActivityTabHelper* tab_helper =
autofill::FormActivityTabHelper::GetOrCreateForWebState(web_state());
observer_ =
std::make_unique<autofill::TestFormActivityObserver>(web_state());
tab_helper->AddObserver(observer_.get());
}
void TearDown() override {
autofill::FormActivityTabHelper* tab_helper =
autofill::FormActivityTabHelper::GetOrCreateForWebState(web_state());
tab_helper->RemoveObserver(observer_.get());
web::WebJsTest<web::WebTestWithWebState>::TearDown();
}
protected:
std::unique_ptr<autofill::TestFormActivityObserver> observer_;
};
// Test that observer is called on form submission.
TEST_F(FormActivityTabHelperTest, TestObserverDocumentSubmitted) {
LoadHtmlAndInject(
@"<form name='form-name'>"
"<input type='submit' id='submit'/>"
"</form>");
ASSERT_FALSE(observer_->submit_document_info());
const std::string kTestFormName("form-name");
bool has_user_gesture = false;
bool form_in_main_frame = true;
ExecuteJavaScript(@"document.getElementById('submit').click();");
ASSERT_TRUE(observer_->submit_document_info());
EXPECT_EQ(web_state(), observer_->submit_document_info()->web_state);
EXPECT_EQ(kTestFormName, observer_->submit_document_info()->form_name);
EXPECT_EQ(has_user_gesture,
observer_->submit_document_info()->has_user_gesture);
EXPECT_EQ(form_in_main_frame,
observer_->submit_document_info()->form_in_main_frame);
}
// Test that observer is called on form activity (input event).
TEST_F(FormActivityTabHelperTest, TestObserverFormActivity) {
LoadHtmlAndInject(
@"<form name='form-name'>"
"<input type='input' name='field-name' id='fieldid'/>"
"</form>");
ASSERT_FALSE(observer_->form_activity_info());
// First call will set document.activeElement (which is usually set by user
// action. Second call will trigger the message.
ExecuteJavaScript(@"document.getElementById('fieldid').focus();");
ASSERT_FALSE(observer_->form_activity_info());
ExecuteJavaScript(@"document.getElementById('fieldid').focus();");
EXPECT_TRUE(base::test::ios::WaitUntilConditionOrTimeout(5, ^bool {
return observer_->form_activity_info() != nullptr;
}));
EXPECT_EQ(web_state(), observer_->form_activity_info()->web_state);
EXPECT_EQ("form-name",
observer_->form_activity_info()->form_activity.form_name);
EXPECT_EQ("field-name",
observer_->form_activity_info()->form_activity.field_name);
EXPECT_EQ("text", observer_->form_activity_info()->form_activity.field_type);
EXPECT_EQ("focus", observer_->form_activity_info()->form_activity.type);
EXPECT_EQ("", observer_->form_activity_info()->form_activity.value);
EXPECT_FALSE(observer_->form_activity_info()->form_activity.input_missing);
EXPECT_TRUE(observer_->form_activity_info()->form_activity.is_main_frame);
EXPECT_TRUE(observer_->form_activity_info()->form_activity.has_user_gesture);
}
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// 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.
#include "components/autofill/ios/form_util/form_activity_tab_helper.h"
#include "components/autofill/ios/form_util/test_form_activity_observer.h"
#import "ios/web/public/browser_state.h" #import "ios/web/public/browser_state.h"
#import "ios/web/public/test/fakes/test_web_client.h" #import "ios/web/public/test/fakes/test_web_client.h"
#include "ios/web/public/test/fakes/test_web_state_observer.h" #include "ios/web/public/test/fakes/test_web_state_observer.h"
...@@ -28,24 +30,40 @@ class FormJsTest : public web::WebJsTest<web::WebTestWithWebState> { ...@@ -28,24 +30,40 @@ class FormJsTest : public web::WebJsTest<web::WebTestWithWebState> {
FormJsTest() FormJsTest()
: web::WebJsTest<web::WebTestWithWebState>( : web::WebJsTest<web::WebTestWithWebState>(
std::make_unique<FormTestClient>()) {} std::make_unique<FormTestClient>()) {}
void SetUp() override {
web::WebJsTest<web::WebTestWithWebState>::SetUp();
observer_ =
std::make_unique<autofill::TestFormActivityObserver>(web_state());
autofill::FormActivityTabHelper::GetOrCreateForWebState(web_state())
->AddObserver(observer_.get());
}
void TearDown() override {
autofill::FormActivityTabHelper::GetOrCreateForWebState(web_state())
->RemoveObserver(observer_.get());
web::WebJsTest<web::WebTestWithWebState>::TearDown();
}
protected:
std::unique_ptr<autofill::TestFormActivityObserver> observer_;
}; };
// Tests that keyup event correctly delivered to WebStateObserver if the element // Tests that keyup event correctly delivered to WebStateObserver if the element
// is focused. // is focused.
TEST_F(FormJsTest, KeyUpEventFocused) { TEST_F(FormJsTest, KeyUpEventFocused) {
web::TestWebStateObserver observer(web_state());
LoadHtml(@"<p><input id='test'/></p>"); LoadHtml(@"<p><input id='test'/></p>");
ASSERT_FALSE(observer.form_activity_info()); ASSERT_FALSE(observer_->form_activity_info());
ExecuteJavaScript( ExecuteJavaScript(
@"var e = document.getElementById('test');" @"var e = document.getElementById('test');"
"e.focus();" "e.focus();"
"var ev = new KeyboardEvent('keyup', {bubbles:true});" "var ev = new KeyboardEvent('keyup', {bubbles:true});"
"e.dispatchEvent(ev);"); "e.dispatchEvent(ev);");
web::TestWebStateObserver* block_observer = &observer; autofill::TestFormActivityObserver* block_observer = observer_.get();
WaitForCondition(^bool { WaitForCondition(^bool {
return block_observer->form_activity_info() != nullptr; return block_observer->form_activity_info() != nullptr;
}); });
web::TestFormActivityInfo* info = observer.form_activity_info(); autofill::TestFormActivityInfo* info = observer_->form_activity_info();
ASSERT_TRUE(info); ASSERT_TRUE(info);
EXPECT_EQ("keyup", info->form_activity.type); EXPECT_EQ("keyup", info->form_activity.type);
EXPECT_FALSE(info->form_activity.input_missing); EXPECT_FALSE(info->form_activity.input_missing);
...@@ -54,33 +72,31 @@ TEST_F(FormJsTest, KeyUpEventFocused) { ...@@ -54,33 +72,31 @@ TEST_F(FormJsTest, KeyUpEventFocused) {
// Tests that keyup event is not delivered to WebStateObserver if the element is // Tests that keyup event is not delivered to WebStateObserver if the element is
// not focused. // not focused.
TEST_F(FormJsTest, KeyUpEventNotFocused) { TEST_F(FormJsTest, KeyUpEventNotFocused) {
web::TestWebStateObserver observer(web_state());
LoadHtml(@"<p><input id='test'/></p>"); LoadHtml(@"<p><input id='test'/></p>");
ASSERT_FALSE(observer.form_activity_info()); ASSERT_FALSE(observer_->form_activity_info());
ExecuteJavaScript( ExecuteJavaScript(
@"var e = document.getElementById('test');" @"var e = document.getElementById('test');"
"var ev = new KeyboardEvent('keyup', {bubbles:true});" "var ev = new KeyboardEvent('keyup', {bubbles:true});"
"e.dispatchEvent(ev);"); "e.dispatchEvent(ev);");
WaitForBackgroundTasks(); WaitForBackgroundTasks();
web::TestFormActivityInfo* info = observer.form_activity_info(); autofill::TestFormActivityInfo* info = observer_->form_activity_info();
ASSERT_FALSE(info); ASSERT_FALSE(info);
} }
// Tests that focus event correctly delivered to WebStateObserver. // Tests that focus event correctly delivered to WebStateObserver.
TEST_F(FormJsTest, FocusMainFrame) { TEST_F(FormJsTest, FocusMainFrame) {
web::TestWebStateObserver observer(web_state());
LoadHtml( LoadHtml(
@"<form>" @"<form>"
"<input type='text' name='username' id='id1'>" "<input type='text' name='username' id='id1'>"
"<input type='password' name='password' id='id2'>" "<input type='password' name='password' id='id2'>"
"</form>"); "</form>");
ASSERT_FALSE(observer.form_activity_info()); ASSERT_FALSE(observer_->form_activity_info());
ExecuteJavaScript(@"document.getElementById('id1').focus();"); ExecuteJavaScript(@"document.getElementById('id1').focus();");
web::TestWebStateObserver* block_observer = &observer; autofill::TestFormActivityObserver* block_observer = observer_.get();
WaitForCondition(^bool { WaitForCondition(^bool {
return block_observer->form_activity_info() != nullptr; return block_observer->form_activity_info() != nullptr;
}); });
web::TestFormActivityInfo* info = observer.form_activity_info(); autofill::TestFormActivityInfo* info = observer_->form_activity_info();
ASSERT_TRUE(info); ASSERT_TRUE(info);
EXPECT_EQ("focus", info->form_activity.type); EXPECT_EQ("focus", info->form_activity.type);
EXPECT_FALSE(info->form_activity.input_missing); EXPECT_FALSE(info->form_activity.input_missing);
...@@ -88,15 +104,14 @@ TEST_F(FormJsTest, FocusMainFrame) { ...@@ -88,15 +104,14 @@ TEST_F(FormJsTest, FocusMainFrame) {
// Tests that submit event correctly delivered to WebStateObserver. // Tests that submit event correctly delivered to WebStateObserver.
TEST_F(FormJsTest, FormSubmitMainFrame) { TEST_F(FormJsTest, FormSubmitMainFrame) {
web::TestWebStateObserver observer(web_state());
LoadHtml( LoadHtml(
@"<form id='form1'>" @"<form id='form1'>"
"<input type='password'>" "<input type='password'>"
"<input type='submit' id='submit_input'/>" "<input type='submit' id='submit_input'/>"
"</form>"); "</form>");
ASSERT_FALSE(observer.submit_document_info()); ASSERT_FALSE(observer_->submit_document_info());
ExecuteJavaScript(@"document.getElementById('submit_input').click();"); ExecuteJavaScript(@"document.getElementById('submit_input').click();");
web::TestSubmitDocumentInfo* info = observer.submit_document_info(); autofill::TestSubmitDocumentInfo* info = observer_->submit_document_info();
ASSERT_TRUE(info); ASSERT_TRUE(info);
EXPECT_EQ("form1", info->form_name); EXPECT_EQ("form1", info->form_name);
} }
...@@ -104,7 +119,6 @@ TEST_F(FormJsTest, FormSubmitMainFrame) { ...@@ -104,7 +119,6 @@ TEST_F(FormJsTest, FormSubmitMainFrame) {
// Tests that focus event from same-origin iframe correctly delivered to // Tests that focus event from same-origin iframe correctly delivered to
// WebStateObserver. // WebStateObserver.
TEST_F(FormJsTest, FocusSameOriginIFrame) { TEST_F(FormJsTest, FocusSameOriginIFrame) {
web::TestWebStateObserver observer(web_state());
LoadHtml(@"<iframe id='frame1'></iframe>"); LoadHtml(@"<iframe id='frame1'></iframe>");
ExecuteJavaScript( ExecuteJavaScript(
@"document.getElementById('frame1').contentDocument.body.innerHTML = " @"document.getElementById('frame1').contentDocument.body.innerHTML = "
...@@ -116,11 +130,11 @@ TEST_F(FormJsTest, FocusSameOriginIFrame) { ...@@ -116,11 +130,11 @@ TEST_F(FormJsTest, FocusSameOriginIFrame) {
ExecuteJavaScript( ExecuteJavaScript(
@"document.getElementById('frame1').contentDocument.getElementById('id1')" @"document.getElementById('frame1').contentDocument.getElementById('id1')"
@".focus()"); @".focus()");
web::TestWebStateObserver* block_observer = &observer; autofill::TestFormActivityObserver* block_observer = observer_.get();
WaitForCondition(^bool { WaitForCondition(^bool {
return block_observer->form_activity_info() != nullptr; return block_observer->form_activity_info() != nullptr;
}); });
web::TestFormActivityInfo* info = observer.form_activity_info(); autofill::TestFormActivityInfo* info = observer_->form_activity_info();
ASSERT_TRUE(info); ASSERT_TRUE(info);
EXPECT_EQ("focus", info->form_activity.type); EXPECT_EQ("focus", info->form_activity.type);
EXPECT_FALSE(info->form_activity.input_missing); EXPECT_FALSE(info->form_activity.input_missing);
...@@ -129,7 +143,6 @@ TEST_F(FormJsTest, FocusSameOriginIFrame) { ...@@ -129,7 +143,6 @@ TEST_F(FormJsTest, FocusSameOriginIFrame) {
// Tests that submit event from same-origin iframe correctly delivered to // Tests that submit event from same-origin iframe correctly delivered to
// WebStateObserver. // WebStateObserver.
TEST_F(FormJsTest, FormSameOriginIFrame) { TEST_F(FormJsTest, FormSameOriginIFrame) {
web::TestWebStateObserver observer(web_state());
LoadHtml(@"<iframe id='frame1'></iframe>"); LoadHtml(@"<iframe id='frame1'></iframe>");
ExecuteJavaScript( ExecuteJavaScript(
@"document.getElementById('frame1').contentDocument.body.innerHTML = " @"document.getElementById('frame1').contentDocument.body.innerHTML = "
...@@ -140,22 +153,21 @@ TEST_F(FormJsTest, FormSameOriginIFrame) { ...@@ -140,22 +153,21 @@ TEST_F(FormJsTest, FormSameOriginIFrame) {
ExecuteJavaScript( ExecuteJavaScript(
@"document.getElementById('frame1').contentDocument.getElementById('" @"document.getElementById('frame1').contentDocument.getElementById('"
@"submit_input').click();"); @"submit_input').click();");
web::TestSubmitDocumentInfo* info = observer.submit_document_info(); autofill::TestSubmitDocumentInfo* info = observer_->submit_document_info();
ASSERT_TRUE(info); ASSERT_TRUE(info);
EXPECT_EQ("form1", info->form_name); EXPECT_EQ("form1", info->form_name);
} }
// Tests that a new form triggers form_changed event. // Tests that a new form triggers form_changed event.
TEST_F(FormJsTest, AddForm) { TEST_F(FormJsTest, AddForm) {
web::TestWebStateObserver observer(web_state());
LoadHtml(@"<body></body>"); LoadHtml(@"<body></body>");
ExecuteJavaScript( ExecuteJavaScript(
@"__gCrWeb.form.trackFormMutations(10);" @"__gCrWeb.form.trackFormMutations(10);"
@"var form = document.createElement('form');" @"var form = document.createElement('form');"
@"document.body.appendChild(form);"); @"document.body.appendChild(form);");
web::TestWebStateObserver* block_observer = &observer; autofill::TestFormActivityObserver* block_observer = observer_.get();
__block web::TestFormActivityInfo* info = nil; __block autofill::TestFormActivityInfo* info = nil;
WaitForCondition(^{ WaitForCondition(^{
info = block_observer->form_activity_info(); info = block_observer->form_activity_info();
return info != nil; return info != nil;
...@@ -166,15 +178,14 @@ TEST_F(FormJsTest, AddForm) { ...@@ -166,15 +178,14 @@ TEST_F(FormJsTest, AddForm) {
// Tests that a new input element triggers form_changed event. // Tests that a new input element triggers form_changed event.
TEST_F(FormJsTest, AddInput) { TEST_F(FormJsTest, AddInput) {
web::TestWebStateObserver observer(web_state());
LoadHtml(@"<form id='formId'/>"); LoadHtml(@"<form id='formId'/>");
ExecuteJavaScript( ExecuteJavaScript(
@"__gCrWeb.form.trackFormMutations(10);" @"__gCrWeb.form.trackFormMutations(10);"
@"var input = document.createElement('input');" @"var input = document.createElement('input');"
@"document.getElementById('formId').appendChild(input);"); @"document.getElementById('formId').appendChild(input);");
web::TestWebStateObserver* block_observer = &observer; autofill::TestFormActivityObserver* block_observer = observer_.get();
__block web::TestFormActivityInfo* info = nil; __block autofill::TestFormActivityInfo* info = nil;
WaitForCondition(^{ WaitForCondition(^{
info = block_observer->form_activity_info(); info = block_observer->form_activity_info();
return info != nil; return info != nil;
...@@ -185,15 +196,14 @@ TEST_F(FormJsTest, AddInput) { ...@@ -185,15 +196,14 @@ TEST_F(FormJsTest, AddInput) {
// Tests that a new select element triggers form_changed event. // Tests that a new select element triggers form_changed event.
TEST_F(FormJsTest, AddSelect) { TEST_F(FormJsTest, AddSelect) {
web::TestWebStateObserver observer(web_state());
LoadHtml(@"<form id='formId'/>"); LoadHtml(@"<form id='formId'/>");
ExecuteJavaScript( ExecuteJavaScript(
@"__gCrWeb.form.trackFormMutations(10);" @"__gCrWeb.form.trackFormMutations(10);"
@"var select = document.createElement('select');" @"var select = document.createElement('select');"
@"document.getElementById('formId').appendChild(select);"); @"document.getElementById('formId').appendChild(select);");
web::TestWebStateObserver* block_observer = &observer; autofill::TestFormActivityObserver* block_observer = observer_.get();
__block web::TestFormActivityInfo* info = nil; __block autofill::TestFormActivityInfo* info = nil;
WaitForCondition(^{ WaitForCondition(^{
info = block_observer->form_activity_info(); info = block_observer->form_activity_info();
return info != nil; return info != nil;
...@@ -204,7 +214,6 @@ TEST_F(FormJsTest, AddSelect) { ...@@ -204,7 +214,6 @@ TEST_F(FormJsTest, AddSelect) {
// Tests that a new option element triggers form_changed event. // Tests that a new option element triggers form_changed event.
TEST_F(FormJsTest, AddOption) { TEST_F(FormJsTest, AddOption) {
web::TestWebStateObserver observer(web_state());
LoadHtml( LoadHtml(
@"<form>" @"<form>"
"<select id='select1'><option value='CA'>CA</option></select>" "<select id='select1'><option value='CA'>CA</option></select>"
...@@ -214,8 +223,8 @@ TEST_F(FormJsTest, AddOption) { ...@@ -214,8 +223,8 @@ TEST_F(FormJsTest, AddOption) {
@"__gCrWeb.form.trackFormMutations(10);" @"__gCrWeb.form.trackFormMutations(10);"
@"var option = document.createElement('option');" @"var option = document.createElement('option');"
@"document.getElementById('select1').appendChild(option);"); @"document.getElementById('select1').appendChild(option);");
web::TestWebStateObserver* block_observer = &observer; autofill::TestFormActivityObserver* block_observer = observer_.get();
__block web::TestFormActivityInfo* info = nil; __block autofill::TestFormActivityInfo* info = nil;
WaitForCondition(^{ WaitForCondition(^{
info = block_observer->form_activity_info(); info = block_observer->form_activity_info();
return info != nil; return info != nil;
......
...@@ -373,7 +373,7 @@ var submitHandler_ = function(evt) { ...@@ -373,7 +373,7 @@ var submitHandler_ = function(evt) {
action = document.location.href; action = document.location.href;
} }
__gCrWeb.message.invokeOnHost({ __gCrWeb.message.invokeOnHost({
'command': 'document.submit', 'command': 'form.submit',
'formName': __gCrWeb.form.getFormIdentifier(evt.srcElement), 'formName': __gCrWeb.form.getFormIdentifier(evt.srcElement),
'href': getFullyQualifiedUrl_(action) 'href': getFullyQualifiedUrl_(action)
}); });
......
// 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 COMPONENTS_AUTOFILL_IOS_FORM_UTIL_TEST_FORM_ACTIVITY_OBSERVER_H_
#define COMPONENTS_AUTOFILL_IOS_FORM_UTIL_TEST_FORM_ACTIVITY_OBSERVER_H_
#include "components/autofill/ios/form_util/form_activity_observer.h"
#include "ios/web/public/web_state/form_activity_params.h"
namespace web {
class WebState;
}
namespace autofill {
// Arguments passed to |DocumentSubmitted|.
struct TestSubmitDocumentInfo {
web::WebState* web_state;
std::string form_name;
bool has_user_gesture;
bool form_in_main_frame;
};
// Arguments passed to |FormActivityRegistered|.
struct TestFormActivityInfo {
web::WebState* web_state;
web::FormActivityParams form_activity;
};
class TestFormActivityObserver : public autofill::FormActivityObserver {
public:
explicit TestFormActivityObserver(web::WebState* web_state);
~TestFormActivityObserver() override;
// Arguments passed to |DocumentSubmitted|.
TestSubmitDocumentInfo* submit_document_info();
// Arguments passed to |FormActivityRegistered|.
TestFormActivityInfo* form_activity_info();
void DidSubmitDocument(web::WebState* web_state,
const std::string& form_name,
bool has_user_gesture,
bool form_in_main_frame) override;
void OnFormActivity(web::WebState* web_state,
const web::FormActivityParams& params) override;
private:
web::WebState* web_state_ = nullptr;
std::unique_ptr<TestSubmitDocumentInfo> submit_document_info_;
std::unique_ptr<TestFormActivityInfo> form_activity_info_;
DISALLOW_COPY_AND_ASSIGN(TestFormActivityObserver);
};
} // namespace autofill
#endif // COMPONENTS_AUTOFILL_IOS_FORM_UTIL_TEST_FORM_ACTIVITY_OBSERVER_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.
#include "components/autofill/ios/form_util/test_form_activity_observer.h"
#include "testing/gtest/include/gtest/gtest.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace autofill {
TestFormActivityObserver::TestFormActivityObserver(web::WebState* web_state)
: web_state_(web_state) {}
TestFormActivityObserver::~TestFormActivityObserver() {}
TestSubmitDocumentInfo* TestFormActivityObserver::submit_document_info() {
return submit_document_info_.get();
}
TestFormActivityInfo* TestFormActivityObserver::form_activity_info() {
return form_activity_info_.get();
}
void TestFormActivityObserver::DidSubmitDocument(web::WebState* web_state,
const std::string& form_name,
bool has_user_gesture,
bool form_in_main_frame) {
ASSERT_EQ(web_state_, web_state);
submit_document_info_ = std::make_unique<TestSubmitDocumentInfo>();
submit_document_info_->web_state = web_state;
submit_document_info_->form_name = form_name;
submit_document_info_->has_user_gesture = has_user_gesture;
submit_document_info_->form_in_main_frame = form_in_main_frame;
}
void TestFormActivityObserver::OnFormActivity(
web::WebState* web_state,
const web::FormActivityParams& params) {
ASSERT_EQ(web_state_, web_state);
form_activity_info_ = std::make_unique<TestFormActivityInfo>();
form_activity_info_->web_state = web_state;
form_activity_info_->form_activity = params;
}
} // namespace autofill
// 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 COMPONENTS_AUTOFILL_IOS_FORM_UTIL_TEST_FORM_ACTIVITY_TAB_HELPER_H_
#define COMPONENTS_AUTOFILL_IOS_FORM_UTIL_TEST_FORM_ACTIVITY_TAB_HELPER_H_
#include <string>
#include "base/macros.h"
namespace web {
struct FormActivityParams;
class WebState;
} // namespace web
namespace autofill {
class TestFormActivityTabHelper {
public:
explicit TestFormActivityTabHelper(web::WebState* web_state);
~TestFormActivityTabHelper();
void OnFormActivity(const web::FormActivityParams& params);
void OnDocumentSubmitted(const std::string& form_name,
bool has_user_gesture,
bool form_in_main_frame);
private:
web::WebState* web_state_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(TestFormActivityTabHelper);
};
} // namespace autofill
#endif // COMPONENTS_AUTOFILL_IOS_FORM_UTIL_TEST_FORM_ACTIVITY_TAB_HELPER_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.
#include "components/autofill/ios/form_util/test_form_activity_tab_helper.h"
#include "base/observer_list.h"
#include "components/autofill/ios/form_util/form_activity_observer.h"
#include "components/autofill/ios/form_util/form_activity_tab_helper.h"
#include "ios/web/public/web_state/form_activity_params.h"
#include "ios/web/public/web_state/web_state.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace autofill {
TestFormActivityTabHelper::TestFormActivityTabHelper(web::WebState* web_state)
: web_state_(web_state) {}
TestFormActivityTabHelper::~TestFormActivityTabHelper() {}
void TestFormActivityTabHelper::OnFormActivity(
web::FormActivityParams const& params) {
autofill::FormActivityTabHelper* form_activity_tab_helper =
autofill::FormActivityTabHelper::GetOrCreateForWebState(web_state_);
for (auto& observer : form_activity_tab_helper->observers_) {
observer.OnFormActivity(web_state_, params);
}
}
void TestFormActivityTabHelper::OnDocumentSubmitted(
const std::string& form_name,
bool has_user_gesture,
bool form_in_main_frame) {
autofill::FormActivityTabHelper* form_activity_tab_helper =
autofill::FormActivityTabHelper::GetOrCreateForWebState(web_state_);
for (auto& observer : form_activity_tab_helper->observers_) {
observer.DidSubmitDocument(web_state_, form_name, has_user_gesture,
form_in_main_frame);
}
}
} // namespace autofill
...@@ -125,6 +125,7 @@ source_set("unit_tests") { ...@@ -125,6 +125,7 @@ source_set("unit_tests") {
"//components/autofill/core/common", "//components/autofill/core/common",
"//components/autofill/ios/browser", "//components/autofill/ios/browser",
"//components/autofill/ios/form_util", "//components/autofill/ios/form_util",
"//components/autofill/ios/form_util:test_support",
"//components/infobars/core", "//components/infobars/core",
"//components/keyed_service/core", "//components/keyed_service/core",
"//components/security_state/ios", "//components/security_state/ios",
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
namespace web { namespace web {
class WebState; class WebState;
struct FormActivityParams;
} }
@protocol CRWWebViewProxy; @protocol CRWWebViewProxy;
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#import "components/autofill/ios/browser/form_suggestion.h" #import "components/autofill/ios/browser/form_suggestion.h"
#import "components/autofill/ios/browser/form_suggestion_provider.h" #import "components/autofill/ios/browser/form_suggestion_provider.h"
#import "components/autofill/ios/form_util/form_activity_observer_bridge.h" #import "components/autofill/ios/form_util/form_activity_observer_bridge.h"
#include "components/autofill/ios/form_util/test_form_activity_tab_helper.h"
#import "ios/chrome/browser/autofill/form_input_accessory_view_controller.h" #import "ios/chrome/browser/autofill/form_input_accessory_view_controller.h"
#import "ios/chrome/browser/autofill/form_suggestion_view.h" #import "ios/chrome/browser/autofill/form_suggestion_view.h"
#include "ios/chrome/browser/ui/ui_util.h" #include "ios/chrome/browser/ui/ui_util.h"
...@@ -140,7 +141,8 @@ FormSuggestionView* GetSuggestionView(UIView* parent) { ...@@ -140,7 +141,8 @@ FormSuggestionView* GetSuggestionView(UIView* parent) {
// Test fixture for FormSuggestionController testing. // Test fixture for FormSuggestionController testing.
class FormSuggestionControllerTest : public PlatformTest { class FormSuggestionControllerTest : public PlatformTest {
public: public:
FormSuggestionControllerTest() {} FormSuggestionControllerTest()
: test_form_activity_tab_helper_(&test_web_state_) {}
void SetUp() override { void SetUp() override {
PlatformTest::SetUp(); PlatformTest::SetUp();
...@@ -244,6 +246,9 @@ class FormSuggestionControllerTest : public PlatformTest { ...@@ -244,6 +246,9 @@ class FormSuggestionControllerTest : public PlatformTest {
// The fake WebState to simulate navigation and JavaScript events. // The fake WebState to simulate navigation and JavaScript events.
web::TestWebState test_web_state_; web::TestWebState test_web_state_;
// The fake form tracker to simulate form events.
autofill::TestFormActivityTabHelper test_form_activity_tab_helper_;
DISALLOW_COPY_AND_ASSIGN(FormSuggestionControllerTest); DISALLOW_COPY_AND_ASSIGN(FormSuggestionControllerTest);
}; };
...@@ -281,7 +286,7 @@ TEST_F(FormSuggestionControllerTest, ...@@ -281,7 +286,7 @@ TEST_F(FormSuggestionControllerTest,
params.type = "type"; params.type = "type";
params.value = "value"; params.value = "value";
params.input_missing = false; params.input_missing = false;
test_web_state_.OnFormActivity(params); test_form_activity_tab_helper_.OnFormActivity(params);
EXPECT_TRUE(GetSuggestionView(input_accessory_view_)); EXPECT_TRUE(GetSuggestionView(input_accessory_view_));
// Trigger another page load. The suggestions accessory view should // Trigger another page load. The suggestions accessory view should
...@@ -300,7 +305,7 @@ TEST_F(FormSuggestionControllerTest, FormActivityBlurShouldBeIgnored) { ...@@ -300,7 +305,7 @@ TEST_F(FormSuggestionControllerTest, FormActivityBlurShouldBeIgnored) {
params.type = "blur"; // blur! params.type = "blur"; // blur!
params.value = "value"; params.value = "value";
params.input_missing = false; params.input_missing = false;
test_web_state_.OnFormActivity(params); test_form_activity_tab_helper_.OnFormActivity(params);
EXPECT_FALSE(GetSuggestionView(input_accessory_view_)); EXPECT_FALSE(GetSuggestionView(input_accessory_view_));
} }
...@@ -318,7 +323,7 @@ TEST_F(FormSuggestionControllerTest, ...@@ -318,7 +323,7 @@ TEST_F(FormSuggestionControllerTest,
params.type = "type"; params.type = "type";
params.value = "value"; params.value = "value";
params.input_missing = false; params.input_missing = false;
test_web_state_.OnFormActivity(params); test_form_activity_tab_helper_.OnFormActivity(params);
// The suggestions accessory view should be empty. // The suggestions accessory view should be empty.
FormSuggestionView* suggestionView = GetSuggestionView(input_accessory_view_); FormSuggestionView* suggestionView = GetSuggestionView(input_accessory_view_);
...@@ -347,7 +352,7 @@ TEST_F(FormSuggestionControllerTest, ...@@ -347,7 +352,7 @@ TEST_F(FormSuggestionControllerTest,
params.type = "type"; params.type = "type";
params.value = "value"; params.value = "value";
params.input_missing = false; params.input_missing = false;
test_web_state_.OnFormActivity(params); test_form_activity_tab_helper_.OnFormActivity(params);
// The providers should each be asked if they have suggestions for the // The providers should each be asked if they have suggestions for the
// form in question. // form in question.
...@@ -397,7 +402,7 @@ TEST_F(FormSuggestionControllerTest, ...@@ -397,7 +402,7 @@ TEST_F(FormSuggestionControllerTest,
params.type = "type"; params.type = "type";
params.value = "value"; params.value = "value";
params.input_missing = false; params.input_missing = false;
test_web_state_.OnFormActivity(params); test_form_activity_tab_helper_.OnFormActivity(params);
// Since the first provider has suggestions available, it and only it // Since the first provider has suggestions available, it and only it
// should have been asked. // should have been asked.
...@@ -437,7 +442,7 @@ TEST_F(FormSuggestionControllerTest, SelectingSuggestionShouldNotifyDelegate) { ...@@ -437,7 +442,7 @@ TEST_F(FormSuggestionControllerTest, SelectingSuggestionShouldNotifyDelegate) {
params.type = "type"; params.type = "type";
params.value = "value"; params.value = "value";
params.input_missing = false; params.input_missing = false;
test_web_state_.OnFormActivity(params); test_form_activity_tab_helper_.OnFormActivity(params);
// Selecting a suggestion should notify the delegate. // Selecting a suggestion should notify the delegate.
[suggestion_controller_ didSelectSuggestion:suggestions[0]]; [suggestion_controller_ didSelectSuggestion:suggestions[0]];
......
...@@ -40,11 +40,6 @@ ...@@ -40,11 +40,6 @@
// Arguments passed to |webStateDidSuppressDialog:|. // Arguments passed to |webStateDidSuppressDialog:|.
@property(nonatomic, readonly) @property(nonatomic, readonly)
web::TestDidSuppressDialogInfo* didSuppressDialogInfo; web::TestDidSuppressDialogInfo* didSuppressDialogInfo;
// Arguments passed to |webState:didSubmitDocumentWithFormNamed:userInitiated:|.
@property(nonatomic, readonly) web::TestSubmitDocumentInfo* submitDocumentInfo;
// Arguments passed to
// |webState:didRegisterFormActivity:|.
@property(nonatomic, readonly) web::TestFormActivityInfo* formActivityInfo;
// Arguments passed to |webState:didUpdateFaviconURLCandidates|. // Arguments passed to |webState:didUpdateFaviconURLCandidates|.
@property(nonatomic, readonly) @property(nonatomic, readonly)
web::TestUpdateFaviconUrlCandidatesInfo* updateFaviconUrlCandidatesInfo; web::TestUpdateFaviconUrlCandidatesInfo* updateFaviconUrlCandidatesInfo;
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include <memory> #include <memory>
#include "ios/web/public/web_state/form_activity_params.h"
#import "ios/web/public/web_state/navigation_context.h" #import "ios/web/public/web_state/navigation_context.h"
#import "ios/web/web_state/navigation_context_impl.h" #import "ios/web/web_state/navigation_context_impl.h"
#include "net/http/http_response_headers.h" #include "net/http/http_response_headers.h"
...@@ -50,12 +49,6 @@ TestUpdateFaviconUrlCandidatesInfo::~TestUpdateFaviconUrlCandidatesInfo() = ...@@ -50,12 +49,6 @@ TestUpdateFaviconUrlCandidatesInfo::~TestUpdateFaviconUrlCandidatesInfo() =
_didChangeVisibleSecurityStateInfo; _didChangeVisibleSecurityStateInfo;
// Arguments passed to |webStateDidSuppressDialog:|. // Arguments passed to |webStateDidSuppressDialog:|.
std::unique_ptr<web::TestDidSuppressDialogInfo> _didSuppressDialogInfo; std::unique_ptr<web::TestDidSuppressDialogInfo> _didSuppressDialogInfo;
// Arguments passed to
// |webState:didSubmitDocumentWithFormNamed:userInitiated:|.
std::unique_ptr<web::TestSubmitDocumentInfo> _submitDocumentInfo;
// Arguments passed to
// |webState:didRegisterFormActivity:|.
std::unique_ptr<web::TestFormActivityInfo> _formActivityInfo;
// Arguments passed to |webState:didUpdateFaviconURLCandidates|. // Arguments passed to |webState:didUpdateFaviconURLCandidates|.
std::unique_ptr<web::TestUpdateFaviconUrlCandidatesInfo> std::unique_ptr<web::TestUpdateFaviconUrlCandidatesInfo>
_updateFaviconUrlCandidatesInfo; _updateFaviconUrlCandidatesInfo;
...@@ -114,14 +107,6 @@ TestUpdateFaviconUrlCandidatesInfo::~TestUpdateFaviconUrlCandidatesInfo() = ...@@ -114,14 +107,6 @@ TestUpdateFaviconUrlCandidatesInfo::~TestUpdateFaviconUrlCandidatesInfo() =
return _didSuppressDialogInfo.get(); return _didSuppressDialogInfo.get();
} }
- (web::TestSubmitDocumentInfo*)submitDocumentInfo {
return _submitDocumentInfo.get();
}
- (web::TestFormActivityInfo*)formActivityInfo {
return _formActivityInfo.get();
}
- (web::TestUpdateFaviconUrlCandidatesInfo*)updateFaviconUrlCandidatesInfo { - (web::TestUpdateFaviconUrlCandidatesInfo*)updateFaviconUrlCandidatesInfo {
return _updateFaviconUrlCandidatesInfo.get(); return _updateFaviconUrlCandidatesInfo.get();
} }
...@@ -231,24 +216,6 @@ TestUpdateFaviconUrlCandidatesInfo::~TestUpdateFaviconUrlCandidatesInfo() = ...@@ -231,24 +216,6 @@ TestUpdateFaviconUrlCandidatesInfo::~TestUpdateFaviconUrlCandidatesInfo() =
_didSuppressDialogInfo->web_state = webState; _didSuppressDialogInfo->web_state = webState;
} }
- (void)webState:(web::WebState*)webState
didSubmitDocumentWithFormNamed:(const std::string&)formName
userInitiated:(BOOL)userInitiated
isMainFrame:(BOOL)isMainFrame {
_submitDocumentInfo = std::make_unique<web::TestSubmitDocumentInfo>();
_submitDocumentInfo->web_state = webState;
_submitDocumentInfo->form_name = formName;
_submitDocumentInfo->user_initiated = userInitiated;
_submitDocumentInfo->is_main_frame = isMainFrame;
}
- (void)webState:(web::WebState*)webState
didRegisterFormActivity:(const web::FormActivityParams&)params {
_formActivityInfo = std::make_unique<web::TestFormActivityInfo>();
_formActivityInfo->web_state = webState;
_formActivityInfo->form_activity = params;
}
- (void)webState:(web::WebState*)webState - (void)webState:(web::WebState*)webState
didUpdateFaviconURLCandidates: didUpdateFaviconURLCandidates:
(const std::vector<web::FaviconURL>&)candidates { (const std::vector<web::FaviconURL>&)candidates {
......
...@@ -122,10 +122,6 @@ class TestWebState : public WebState { ...@@ -122,10 +122,6 @@ class TestWebState : public WebState {
void OnNavigationStarted(NavigationContext* navigation_context); void OnNavigationStarted(NavigationContext* navigation_context);
void OnNavigationFinished(NavigationContext* navigation_context); void OnNavigationFinished(NavigationContext* navigation_context);
void OnRenderProcessGone(); void OnRenderProcessGone();
void OnFormActivity(const FormActivityParams& params);
void OnDocumentSubmitted(const std::string& form_name,
bool user_initiated,
bool is_main_frame);
void OnBackForwardStateChanged(); void OnBackForwardStateChanged();
void OnVisibleSecurityStateChanged(); void OnVisibleSecurityStateChanged();
......
...@@ -267,20 +267,6 @@ void TestWebState::OnRenderProcessGone() { ...@@ -267,20 +267,6 @@ void TestWebState::OnRenderProcessGone() {
observer.RenderProcessGone(this); observer.RenderProcessGone(this);
} }
void TestWebState::OnFormActivity(const FormActivityParams& params) {
for (auto& observer : observers_) {
observer.FormActivityRegistered(this, params);
}
}
void TestWebState::OnDocumentSubmitted(const std::string& form_name,
bool user_initiated,
bool is_main_frame) {
for (auto& observer : observers_) {
observer.DocumentSubmitted(this, form_name, user_initiated, is_main_frame);
}
}
void TestWebState::OnBackForwardStateChanged() { void TestWebState::OnBackForwardStateChanged() {
for (auto& observer : observers_) { for (auto& observer : observers_) {
observer.DidChangeBackForwardState(this); observer.DidChangeBackForwardState(this);
......
...@@ -65,14 +65,6 @@ class TestWebStateObserver : public WebStateObserver { ...@@ -65,14 +65,6 @@ class TestWebStateObserver : public WebStateObserver {
web::TestDidSuppressDialogInfo* did_suppress_dialog_info() { web::TestDidSuppressDialogInfo* did_suppress_dialog_info() {
return did_suppress_dialog_info_.get(); return did_suppress_dialog_info_.get();
} }
// Arguments passed to |DocumentSubmitted|.
web::TestSubmitDocumentInfo* submit_document_info() {
return submit_document_info_.get();
}
// Arguments passed to |FormActivityRegistered|.
web::TestFormActivityInfo* form_activity_info() {
return form_activity_info_.get();
}
// Arguments passed to |FaviconUrlUpdated|. // Arguments passed to |FaviconUrlUpdated|.
web::TestUpdateFaviconUrlCandidatesInfo* web::TestUpdateFaviconUrlCandidatesInfo*
update_favicon_url_candidates_info() { update_favicon_url_candidates_info() {
...@@ -114,12 +106,6 @@ class TestWebStateObserver : public WebStateObserver { ...@@ -114,12 +106,6 @@ class TestWebStateObserver : public WebStateObserver {
void TitleWasSet(WebState* web_state) override; void TitleWasSet(WebState* web_state) override;
void DidChangeVisibleSecurityState(WebState* web_state) override; void DidChangeVisibleSecurityState(WebState* web_state) override;
void DidSuppressDialog(WebState* web_state) override; void DidSuppressDialog(WebState* web_state) override;
void DocumentSubmitted(WebState* web_state,
const std::string& form_name,
bool user_initiated,
bool is_main_frame) override;
void FormActivityRegistered(WebState* web_state,
const FormActivityParams& params) override;
void FaviconUrlUpdated(WebState* web_state, void FaviconUrlUpdated(WebState* web_state,
const std::vector<FaviconURL>& candidates) override; const std::vector<FaviconURL>& candidates) override;
void RenderProcessGone(WebState* web_state) override; void RenderProcessGone(WebState* web_state) override;
...@@ -147,8 +133,6 @@ class TestWebStateObserver : public WebStateObserver { ...@@ -147,8 +133,6 @@ class TestWebStateObserver : public WebStateObserver {
std::unique_ptr<web::TestDidChangeVisibleSecurityStateInfo> std::unique_ptr<web::TestDidChangeVisibleSecurityStateInfo>
did_change_visible_security_state_info_; did_change_visible_security_state_info_;
std::unique_ptr<web::TestDidSuppressDialogInfo> did_suppress_dialog_info_; std::unique_ptr<web::TestDidSuppressDialogInfo> did_suppress_dialog_info_;
std::unique_ptr<web::TestSubmitDocumentInfo> submit_document_info_;
std::unique_ptr<web::TestFormActivityInfo> form_activity_info_;
std::unique_ptr<web::TestUpdateFaviconUrlCandidatesInfo> std::unique_ptr<web::TestUpdateFaviconUrlCandidatesInfo>
update_favicon_url_candidates_info_; update_favicon_url_candidates_info_;
std::unique_ptr<web::TestRenderProcessGoneInfo> render_process_gone_info_; std::unique_ptr<web::TestRenderProcessGoneInfo> render_process_gone_info_;
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include <memory> #include <memory>
#include "ios/web/public/web_state/form_activity_params.h"
#import "ios/web/public/web_state/navigation_context.h" #import "ios/web/public/web_state/navigation_context.h"
#include "ios/web/public/web_state/web_state.h" #include "ios/web/public/web_state/web_state.h"
#include "ios/web/web_state/navigation_context_impl.h" #include "ios/web/web_state/navigation_context_impl.h"
...@@ -141,27 +140,6 @@ void TestWebStateObserver::DidSuppressDialog(WebState* web_state) { ...@@ -141,27 +140,6 @@ void TestWebStateObserver::DidSuppressDialog(WebState* web_state) {
did_suppress_dialog_info_->web_state = web_state; did_suppress_dialog_info_->web_state = web_state;
} }
void TestWebStateObserver::DocumentSubmitted(WebState* web_state,
const std::string& form_name,
bool user_initiated,
bool is_main_frame) {
ASSERT_EQ(web_state_, web_state);
submit_document_info_ = std::make_unique<web::TestSubmitDocumentInfo>();
submit_document_info_->web_state = web_state;
submit_document_info_->form_name = form_name;
submit_document_info_->user_initiated = user_initiated;
submit_document_info_->is_main_frame = is_main_frame;
}
void TestWebStateObserver::FormActivityRegistered(
WebState* web_state,
const FormActivityParams& params) {
ASSERT_EQ(web_state_, web_state);
form_activity_info_ = std::make_unique<web::TestFormActivityInfo>();
form_activity_info_->web_state = web_state;
form_activity_info_->form_activity = params;
}
void TestWebStateObserver::FaviconUrlUpdated( void TestWebStateObserver::FaviconUrlUpdated(
WebState* web_state, WebState* web_state,
const std::vector<FaviconURL>& candidates) { const std::vector<FaviconURL>& candidates) {
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
namespace web { namespace web {
struct FaviconURL; struct FaviconURL;
struct FormActivityParams;
class NavigationContext; class NavigationContext;
struct LoadCommittedDetails; struct LoadCommittedDetails;
class WebState; class WebState;
...@@ -138,22 +137,6 @@ class WebStateObserver { ...@@ -138,22 +137,6 @@ class WebStateObserver {
// false. // false.
virtual void DidSuppressDialog(WebState* web_state) {} virtual void DidSuppressDialog(WebState* web_state) {}
// Called on form submission in the main frame or in a same-origin iframe.
// |user_initiated| is true if the user interacted with the page.
// |is_main_frame| is true if the submitted form is in the main frame.
// TODO(crbug.com/823285): move this handler to components/autofill.
virtual void DocumentSubmitted(WebState* web_state,
const std::string& form_name,
bool user_initiated,
bool is_main_frame) {}
// Called when the user is typing on a form field in the main frame or in a
// same-origin iframe. |params.input_missing| is indicating if there is any
// error when parsing the form field information.
// TODO(crbug.com/823285): move this handler to components/autofill.
virtual void FormActivityRegistered(WebState* web_state,
const FormActivityParams& params) {}
// Invoked when new favicon URL candidates are received. // Invoked when new favicon URL candidates are received.
virtual void FaviconUrlUpdated(WebState* web_state, virtual void FaviconUrlUpdated(WebState* web_state,
const std::vector<FaviconURL>& candidates) {} const std::vector<FaviconURL>& candidates) {}
......
...@@ -59,16 +59,6 @@ ...@@ -59,16 +59,6 @@
// Invoked by WebStateObserverBridge::DidSuppressDialog. // Invoked by WebStateObserverBridge::DidSuppressDialog.
- (void)webStateDidSuppressDialog:(web::WebState*)webState; - (void)webStateDidSuppressDialog:(web::WebState*)webState;
// Invoked by WebStateObserverBridge::DocumentSubmitted.
- (void)webState:(web::WebState*)webState
didSubmitDocumentWithFormNamed:(const std::string&)formName
userInitiated:(BOOL)userInitiated
isMainFrame:(BOOL)isMainFrame;
// Invoked by WebStateObserverBridge::FormActivityRegistered.
- (void)webState:(web::WebState*)webState
didRegisterFormActivity:(const web::FormActivityParams&)params;
// Invoked by WebStateObserverBridge::FaviconUrlUpdated. // Invoked by WebStateObserverBridge::FaviconUrlUpdated.
- (void)webState:(web::WebState*)webState - (void)webState:(web::WebState*)webState
didUpdateFaviconURLCandidates: didUpdateFaviconURLCandidates:
...@@ -119,12 +109,6 @@ class WebStateObserverBridge : public web::WebStateObserver { ...@@ -119,12 +109,6 @@ class WebStateObserverBridge : public web::WebStateObserver {
void TitleWasSet(web::WebState* web_state) override; void TitleWasSet(web::WebState* web_state) override;
void DidChangeVisibleSecurityState(web::WebState* web_state) override; void DidChangeVisibleSecurityState(web::WebState* web_state) override;
void DidSuppressDialog(web::WebState* web_state) override; void DidSuppressDialog(web::WebState* web_state) override;
void DocumentSubmitted(web::WebState* web_state,
const std::string& form_name,
bool user_initiated,
bool is_main_frame) override;
void FormActivityRegistered(web::WebState* web_state,
const FormActivityParams& params) override;
void FaviconUrlUpdated(web::WebState* web_state, void FaviconUrlUpdated(web::WebState* web_state,
const std::vector<FaviconURL>& candidates) override; const std::vector<FaviconURL>& candidates) override;
void RenderProcessGone(web::WebState* web_state) override; void RenderProcessGone(web::WebState* web_state) override;
......
...@@ -64,7 +64,6 @@ ...@@ -64,7 +64,6 @@
#import "ios/web/public/web_client.h" #import "ios/web/public/web_client.h"
#include "ios/web/public/web_kit_constants.h" #include "ios/web/public/web_kit_constants.h"
#import "ios/web/public/web_state/context_menu_params.h" #import "ios/web/public/web_state/context_menu_params.h"
#include "ios/web/public/web_state/form_activity_params.h"
#import "ios/web/public/web_state/js/crw_js_injection_manager.h" #import "ios/web/public/web_state/js/crw_js_injection_manager.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"
#import "ios/web/public/web_state/page_display_state.h" #import "ios/web/public/web_state/page_display_state.h"
...@@ -810,14 +809,6 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); ...@@ -810,14 +809,6 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
// Handles 'document.favicons' message. // Handles 'document.favicons' message.
- (BOOL)handleDocumentFaviconsMessage:(base::DictionaryValue*)message - (BOOL)handleDocumentFaviconsMessage:(base::DictionaryValue*)message
context:(NSDictionary*)context; context:(NSDictionary*)context;
// Handles 'document.submit' message.
// TODO(crbug.com/823285): move this handler to components/autofill.
- (BOOL)handleDocumentSubmitMessage:(base::DictionaryValue*)message
context:(NSDictionary*)context;
// Handles 'form.activity' message.
// TODO(crbug.com/823285): move this handler to components/autofill.
- (BOOL)handleFormActivityMessage:(base::DictionaryValue*)message
context:(NSDictionary*)context;
// Handles 'window.error' message. // Handles 'window.error' message.
- (BOOL)handleWindowErrorMessage:(base::DictionaryValue*)message - (BOOL)handleWindowErrorMessage:(base::DictionaryValue*)message
context:(NSDictionary*)context; context:(NSDictionary*)context;
...@@ -2328,10 +2319,6 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -2328,10 +2319,6 @@ registerLoadRequestForURL:(const GURL&)requestURL
(*handlers)["console"] = @selector(handleConsoleMessage:context:); (*handlers)["console"] = @selector(handleConsoleMessage:context:);
(*handlers)["document.favicons"] = (*handlers)["document.favicons"] =
@selector(handleDocumentFaviconsMessage:context:); @selector(handleDocumentFaviconsMessage:context:);
(*handlers)["document.submit"] =
@selector(handleDocumentSubmitMessage:context:);
(*handlers)["form.activity"] =
@selector(handleFormActivityMessage:context:);
(*handlers)["window.error"] = @selector(handleWindowErrorMessage:context:); (*handlers)["window.error"] = @selector(handleWindowErrorMessage:context:);
(*handlers)["window.hashchange"] = (*handlers)["window.hashchange"] =
@selector(handleWindowHashChangeMessage:context:); @selector(handleWindowHashChangeMessage:context:);
...@@ -2490,44 +2477,6 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -2490,44 +2477,6 @@ registerLoadRequestForURL:(const GURL&)requestURL
return YES; return YES;
} }
- (BOOL)handleDocumentSubmitMessage:(base::DictionaryValue*)message
context:(NSDictionary*)context {
std::string href;
if (!message->GetString("href", &href)) {
DLOG(WARNING) << "JS message parameter not found: href";
return NO;
}
std::string formName;
message->GetString("formName", &formName);
// We decide the form is user-submitted if the user has interacted with
// the main page (using logic from the popup blocker), or if the keyboard
// is visible.
BOOL submittedByUser = [context[kUserIsInteractingKey] boolValue] ||
[_webViewProxy keyboardAccessory];
_webStateImpl->OnDocumentSubmitted(formName, submittedByUser,
[context[kIsMainFrame] boolValue]);
return YES;
}
- (BOOL)handleFormActivityMessage:(base::DictionaryValue*)message
context:(NSDictionary*)context {
web::FormActivityParams params;
if (!message->GetString("formName", &params.form_name) ||
!message->GetString("fieldName", &params.field_name) ||
!message->GetString("fieldIdentifier", &params.field_identifier) ||
!message->GetString("fieldType", &params.field_type) ||
!message->GetString("type", &params.type) ||
!message->GetString("value", &params.value) ||
!message->GetBoolean("hasUserGesture", &params.has_user_gesture)) {
params.input_missing = true;
}
params.is_main_frame = [context[kIsMainFrame] boolValue];
_webStateImpl->OnFormActivityRegistered(params);
return YES;
}
- (BOOL)handleWindowErrorMessage:(base::DictionaryValue*)message - (BOOL)handleWindowErrorMessage:(base::DictionaryValue*)message
context:(NSDictionary*)context { context:(NSDictionary*)context {
std::string errorMessage; std::string errorMessage;
......
...@@ -44,7 +44,6 @@ namespace web { ...@@ -44,7 +44,6 @@ namespace web {
class BrowserState; class BrowserState;
struct ContextMenuParams; struct ContextMenuParams;
struct FaviconURL; struct FaviconURL;
struct FormActivityParams;
struct LoadCommittedDetails; struct LoadCommittedDetails;
class NavigationContext; class NavigationContext;
class NavigationManager; class NavigationManager;
...@@ -110,14 +109,6 @@ class WebStateImpl : public WebState, public NavigationManagerDelegate { ...@@ -110,14 +109,6 @@ class WebStateImpl : public WebState, public NavigationManagerDelegate {
// Called when a page is loaded. Must be called only once per page. // Called when a page is loaded. Must be called only once per page.
void OnPageLoaded(const GURL& url, bool load_success); void OnPageLoaded(const GURL& url, bool load_success);
// Called on form submission.
void OnDocumentSubmitted(const std::string& form_name,
bool user_initiated,
bool is_main_frame);
// Called when form activity is registered.
void OnFormActivityRegistered(const FormActivityParams& params);
// Called when new FaviconURL candidates are received. // Called when new FaviconURL candidates are received.
void OnFaviconUrlUpdated(const std::vector<FaviconURL>& candidates); void OnFaviconUrlUpdated(const std::vector<FaviconURL>& candidates);
......
...@@ -266,12 +266,6 @@ void WebStateImpl::OnPageLoaded(const GURL& url, bool load_success) { ...@@ -266,12 +266,6 @@ void WebStateImpl::OnPageLoaded(const GURL& url, bool load_success) {
observer.PageLoaded(this, load_completion_status); observer.PageLoaded(this, load_completion_status);
} }
void WebStateImpl::OnFormActivityRegistered(const FormActivityParams& params) {
for (auto& observer : observers_) {
observer.FormActivityRegistered(this, params);
}
}
void WebStateImpl::OnFaviconUrlUpdated( void WebStateImpl::OnFaviconUrlUpdated(
const std::vector<FaviconURL>& candidates) { const std::vector<FaviconURL>& candidates) {
cached_favicon_urls_ = candidates; cached_favicon_urls_ = candidates;
...@@ -279,13 +273,6 @@ void WebStateImpl::OnFaviconUrlUpdated( ...@@ -279,13 +273,6 @@ void WebStateImpl::OnFaviconUrlUpdated(
observer.FaviconUrlUpdated(this, candidates); observer.FaviconUrlUpdated(this, candidates);
} }
void WebStateImpl::OnDocumentSubmitted(const std::string& form_name,
bool user_initiated,
bool is_main_frame) {
for (auto& observer : observers_)
observer.DocumentSubmitted(this, form_name, user_initiated, is_main_frame);
}
NavigationManagerImpl& WebStateImpl::GetNavigationManagerImpl() { NavigationManagerImpl& WebStateImpl::GetNavigationManagerImpl() {
return *navigation_manager_; return *navigation_manager_;
} }
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#import "ios/web/public/test/fakes/test_web_state_observer.h" #import "ios/web/public/test/fakes/test_web_state_observer.h"
#include "ios/web/public/test/web_test.h" #include "ios/web/public/test/web_test.h"
#import "ios/web/public/web_state/context_menu_params.h" #import "ios/web/public/web_state/context_menu_params.h"
#include "ios/web/public/web_state/form_activity_params.h"
#include "ios/web/public/web_state/global_web_state_observer.h" #include "ios/web/public/web_state/global_web_state_observer.h"
#import "ios/web/public/web_state/web_state_delegate.h" #import "ios/web/public/web_state/web_state_delegate.h"
#include "ios/web/public/web_state/web_state_observer.h" #include "ios/web/public/web_state/web_state_observer.h"
...@@ -383,44 +382,6 @@ TEST_P(WebStateImplTest, ObserverTest) { ...@@ -383,44 +382,6 @@ TEST_P(WebStateImplTest, ObserverTest) {
ASSERT_TRUE(observer->did_suppress_dialog_info()); ASSERT_TRUE(observer->did_suppress_dialog_info());
EXPECT_EQ(web_state_.get(), observer->did_suppress_dialog_info()->web_state); EXPECT_EQ(web_state_.get(), observer->did_suppress_dialog_info()->web_state);
// Test that DocumentSubmitted() is called.
ASSERT_FALSE(observer->submit_document_info());
const std::string kTestFormName("form-name");
bool user_initiated = true;
bool is_main_frame = false;
web_state_->OnDocumentSubmitted(kTestFormName, user_initiated, is_main_frame);
ASSERT_TRUE(observer->submit_document_info());
EXPECT_EQ(web_state_.get(), observer->submit_document_info()->web_state);
EXPECT_EQ(kTestFormName, observer->submit_document_info()->form_name);
EXPECT_EQ(user_initiated, observer->submit_document_info()->user_initiated);
EXPECT_EQ(is_main_frame, observer->submit_document_info()->is_main_frame);
// Test that FormActivityRegistered() is called.
ASSERT_FALSE(observer->form_activity_info());
FormActivityParams params;
params.form_name = kTestFormName;
params.field_name = "field-name";
params.field_type = "field-type";
params.type = "type";
params.value = "value";
params.input_missing = true;
params.is_main_frame = false;
params.has_user_gesture = true;
web_state_->OnFormActivityRegistered(params);
ASSERT_TRUE(observer->form_activity_info());
EXPECT_EQ(web_state_.get(), observer->form_activity_info()->web_state);
EXPECT_EQ(params.form_name,
observer->form_activity_info()->form_activity.form_name);
EXPECT_EQ(params.field_name,
observer->form_activity_info()->form_activity.field_name);
EXPECT_EQ(params.field_type,
observer->form_activity_info()->form_activity.field_type);
EXPECT_EQ(params.type, observer->form_activity_info()->form_activity.type);
EXPECT_EQ(params.value, observer->form_activity_info()->form_activity.value);
EXPECT_TRUE(observer->form_activity_info()->form_activity.input_missing);
EXPECT_FALSE(observer->form_activity_info()->form_activity.is_main_frame);
EXPECT_TRUE(observer->form_activity_info()->form_activity.has_user_gesture);
// Test that FaviconUrlUpdated() is called. // Test that FaviconUrlUpdated() is called.
ASSERT_FALSE(observer->update_favicon_url_candidates_info()); ASSERT_FALSE(observer->update_favicon_url_candidates_info());
web::FaviconURL favicon_url(GURL("https://chromium.test/"), web::FaviconURL favicon_url(GURL("https://chromium.test/"),
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#import "ios/web/public/web_state/web_state_observer_bridge.h" #import "ios/web/public/web_state/web_state_observer_bridge.h"
#include "ios/web/public/web_state/form_activity_params.h"
#import "ios/web/public/web_state/web_state.h" #import "ios/web/public/web_state/web_state.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
...@@ -132,29 +131,6 @@ void WebStateObserverBridge::DidSuppressDialog(web::WebState* web_state) { ...@@ -132,29 +131,6 @@ void WebStateObserverBridge::DidSuppressDialog(web::WebState* web_state) {
} }
} }
void WebStateObserverBridge::DocumentSubmitted(web::WebState* web_state,
const std::string& form_name,
bool user_initiated,
bool is_main_frame) {
SEL selector = @selector
(webState:didSubmitDocumentWithFormNamed:userInitiated:isMainFrame:);
if ([observer_ respondsToSelector:selector]) {
[observer_ webState:web_state
didSubmitDocumentWithFormNamed:form_name
userInitiated:user_initiated
isMainFrame:is_main_frame];
}
}
void WebStateObserverBridge::FormActivityRegistered(
web::WebState* web_state,
const FormActivityParams& params) {
SEL selector = @selector(webState:didRegisterFormActivity:);
if ([observer_ respondsToSelector:selector]) {
[observer_ webState:web_state didRegisterFormActivity:params];
}
}
void WebStateObserverBridge::FaviconUrlUpdated( void WebStateObserverBridge::FaviconUrlUpdated(
web::WebState* web_state, web::WebState* web_state,
const std::vector<FaviconURL>& candidates) { const std::vector<FaviconURL>& candidates) {
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "ios/web/public/favicon_url.h" #include "ios/web/public/favicon_url.h"
#import "ios/web/public/test/fakes/crw_test_web_state_observer.h" #import "ios/web/public/test/fakes/crw_test_web_state_observer.h"
#import "ios/web/public/test/fakes/test_web_state.h" #import "ios/web/public/test/fakes/test_web_state.h"
#include "ios/web/public/web_state/form_activity_params.h"
#import "ios/web/public/web_state/web_state_observer_bridge.h" #import "ios/web/public/web_state/web_state_observer_bridge.h"
#import "ios/web/web_state/navigation_context_impl.h" #import "ios/web/web_state/navigation_context_impl.h"
#include "net/http/http_response_headers.h" #include "net/http/http_response_headers.h"
...@@ -212,47 +211,6 @@ TEST_F(WebStateObserverBridgeTest, DidSuppressDialog) { ...@@ -212,47 +211,6 @@ TEST_F(WebStateObserverBridgeTest, DidSuppressDialog) {
EXPECT_EQ(&test_web_state_, [observer_ didSuppressDialogInfo]->web_state); EXPECT_EQ(&test_web_state_, [observer_ didSuppressDialogInfo]->web_state);
} }
// Tests |webState:didRegisterFormActivityWithParams:| forwarding.
TEST_F(WebStateObserverBridgeTest, DocumentSubmitted) {
ASSERT_FALSE([observer_ submitDocumentInfo]);
std::string kTestFormName("form-name");
bool user_initiated = true;
bool is_main_frame = true;
observer_bridge_.DocumentSubmitted(&test_web_state_, kTestFormName,
user_initiated, is_main_frame);
ASSERT_TRUE([observer_ submitDocumentInfo]);
EXPECT_EQ(&test_web_state_, [observer_ submitDocumentInfo]->web_state);
EXPECT_EQ(kTestFormName, [observer_ submitDocumentInfo]->form_name);
EXPECT_EQ(user_initiated, [observer_ submitDocumentInfo]->user_initiated);
EXPECT_EQ(is_main_frame, [observer_ submitDocumentInfo]->is_main_frame);
}
// Tests |webState:didRegisterFormActivity:...| forwarding.
TEST_F(WebStateObserverBridgeTest, FormActivityRegistered) {
ASSERT_FALSE([observer_ formActivityInfo]);
FormActivityParams params;
params.form_name = "form-name";
params.field_name = "field-name";
params.field_type = "field-type";
params.type = "type";
params.value = "value";
params.input_missing = true;
observer_bridge_.FormActivityRegistered(&test_web_state_, params);
ASSERT_TRUE([observer_ formActivityInfo]);
EXPECT_EQ(&test_web_state_, [observer_ formActivityInfo]->web_state);
EXPECT_EQ(params.form_name,
[observer_ formActivityInfo]->form_activity.form_name);
EXPECT_EQ(params.field_name,
[observer_ formActivityInfo]->form_activity.field_name);
EXPECT_EQ(params.field_type,
[observer_ formActivityInfo]->form_activity.field_type);
EXPECT_EQ(params.type, [observer_ formActivityInfo]->form_activity.type);
EXPECT_EQ(params.value, [observer_ formActivityInfo]->form_activity.value);
EXPECT_TRUE([observer_ formActivityInfo]->form_activity.input_missing);
}
// Tests |webState:didUpdateFaviconURLCandidates:| forwarding. // Tests |webState:didUpdateFaviconURLCandidates:| forwarding.
TEST_F(WebStateObserverBridgeTest, FaviconUrlUpdated) { TEST_F(WebStateObserverBridgeTest, FaviconUrlUpdated) {
ASSERT_FALSE([observer_ updateFaviconUrlCandidatesInfo]); ASSERT_FALSE([observer_ updateFaviconUrlCandidatesInfo]);
......
...@@ -350,6 +350,7 @@ test("ios_web_view_unittests") { ...@@ -350,6 +350,7 @@ test("ios_web_view_unittests") {
"//base/test:test_support", "//base/test:test_support",
"//components/autofill/core/browser:test_support", "//components/autofill/core/browser:test_support",
"//components/autofill/ios/browser:test_support", "//components/autofill/ios/browser:test_support",
"//components/autofill/ios/form_util:test_support",
"//components/prefs:test_support", "//components/prefs:test_support",
"//ios/web/public/test", "//ios/web/public/test",
"//ios/web/public/test/fakes", "//ios/web/public/test/fakes",
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#import "components/autofill/ios/browser/fake_js_autofill_manager.h" #import "components/autofill/ios/browser/fake_js_autofill_manager.h"
#import "components/autofill/ios/browser/form_suggestion.h" #import "components/autofill/ios/browser/form_suggestion.h"
#import "components/autofill/ios/browser/js_suggestion_manager.h" #import "components/autofill/ios/browser/js_suggestion_manager.h"
#import "components/autofill/ios/form_util/form_activity_tab_helper.h"
#import "components/autofill/ios/form_util/test_form_activity_tab_helper.h"
#import "ios/web/public/test/fakes/crw_test_js_injection_receiver.h" #import "ios/web/public/test/fakes/crw_test_js_injection_receiver.h"
#import "ios/web/public/test/fakes/test_web_state.h" #import "ios/web/public/test/fakes/test_web_state.h"
#include "ios/web/public/test/test_web_thread_bundle.h" #include "ios/web/public/test/test_web_thread_bundle.h"
...@@ -71,6 +73,8 @@ class CWVAutofillControllerTest : public PlatformTest { ...@@ -71,6 +73,8 @@ class CWVAutofillControllerTest : public PlatformTest {
autofillAgent:autofill_agent_ autofillAgent:autofill_agent_
JSAutofillManager:js_autofill_manager_ JSAutofillManager:js_autofill_manager_
JSSuggestionManager:js_suggestion_manager_]; JSSuggestionManager:js_suggestion_manager_];
test_form_activity_tab_helper_ =
std::make_unique<autofill::TestFormActivityTabHelper>(&web_state_);
}; };
web::WebClient web_client_; web::WebClient web_client_;
...@@ -80,6 +84,8 @@ class CWVAutofillControllerTest : public PlatformTest { ...@@ -80,6 +84,8 @@ class CWVAutofillControllerTest : public PlatformTest {
CWVAutofillController* autofill_controller_; CWVAutofillController* autofill_controller_;
FakeAutofillAgent* autofill_agent_; FakeAutofillAgent* autofill_agent_;
FakeJSAutofillManager* js_autofill_manager_; FakeJSAutofillManager* js_autofill_manager_;
std::unique_ptr<autofill::TestFormActivityTabHelper>
test_form_activity_tab_helper_;
id js_suggestion_manager_; id js_suggestion_manager_;
}; };
...@@ -208,7 +214,7 @@ TEST_F(CWVAutofillControllerTest, FocusCallback) { ...@@ -208,7 +214,7 @@ TEST_F(CWVAutofillControllerTest, FocusCallback) {
params.field_identifier = base::SysNSStringToUTF8(kTestFieldIdentifier); params.field_identifier = base::SysNSStringToUTF8(kTestFieldIdentifier);
params.value = base::SysNSStringToUTF8(kTestFieldValue); params.value = base::SysNSStringToUTF8(kTestFieldValue);
params.type = "focus"; params.type = "focus";
web_state_.OnFormActivity(params); test_form_activity_tab_helper_->OnFormActivity(params);
[delegate verify]; [delegate verify];
} }
...@@ -235,7 +241,7 @@ TEST_F(CWVAutofillControllerTest, InputCallback) { ...@@ -235,7 +241,7 @@ TEST_F(CWVAutofillControllerTest, InputCallback) {
params.field_identifier = base::SysNSStringToUTF8(kTestFieldIdentifier); params.field_identifier = base::SysNSStringToUTF8(kTestFieldIdentifier);
params.value = base::SysNSStringToUTF8(kTestFieldValue); params.value = base::SysNSStringToUTF8(kTestFieldValue);
params.type = "input"; params.type = "input";
web_state_.OnFormActivity(params); test_form_activity_tab_helper_->OnFormActivity(params);
[delegate verify]; [delegate verify];
} }
...@@ -261,7 +267,7 @@ TEST_F(CWVAutofillControllerTest, BlurCallback) { ...@@ -261,7 +267,7 @@ TEST_F(CWVAutofillControllerTest, BlurCallback) {
params.field_identifier = base::SysNSStringToUTF8(kTestFieldIdentifier); params.field_identifier = base::SysNSStringToUTF8(kTestFieldIdentifier);
params.value = base::SysNSStringToUTF8(kTestFieldValue); params.value = base::SysNSStringToUTF8(kTestFieldValue);
params.type = "blur"; params.type = "blur";
web_state_.OnFormActivity(params); test_form_activity_tab_helper_->OnFormActivity(params);
[delegate verify]; [delegate verify];
} }
...@@ -280,18 +286,20 @@ TEST_F(CWVAutofillControllerTest, SubmitCallback) { ...@@ -280,18 +286,20 @@ TEST_F(CWVAutofillControllerTest, SubmitCallback) {
userInitiated:YES userInitiated:YES
isMainFrame:YES]; isMainFrame:YES];
web_state_.OnDocumentSubmitted(base::SysNSStringToUTF8(kTestFormName), test_form_activity_tab_helper_->OnDocumentSubmitted(
/*user_initiated=*/true, base::SysNSStringToUTF8(kTestFormName),
/*is_main_frame=*/true); /*user_initiated=*/true,
/*is_main_frame=*/true);
[[delegate expect] autofillController:autofill_controller_ [[delegate expect] autofillController:autofill_controller_
didSubmitFormWithName:kTestFormName didSubmitFormWithName:kTestFormName
userInitiated:NO userInitiated:NO
isMainFrame:YES]; isMainFrame:YES];
web_state_.OnDocumentSubmitted(base::SysNSStringToUTF8(kTestFormName), test_form_activity_tab_helper_->OnDocumentSubmitted(
/*user_initiated=*/false, base::SysNSStringToUTF8(kTestFormName),
/*is_main_frame=*/true); /*user_initiated=*/false,
/*is_main_frame=*/true);
[delegate verify]; [delegate verify];
} }
......
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