Commit 9a42b991 authored by sandromaggi's avatar sandromaggi Committed by Commit Bot

[Autofill Assistant] Remove Assistant UI on navigation to Google

Similarly to the startup condition for SRP (must come from a Google
domain), if the user navigates back to a Google domain, remove the UI
instead of showing the error message.

Bug: b/156387203
Change-Id: I432becb75cbf138ef6a2a70a76e7c61b612e3243
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2203061
Commit-Queue: Sandro Maggi <sandromaggi@google.com>
Reviewed-by: default avatarMathias Carlen <mcarlen@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#769635}
parent f21a237f
......@@ -188,6 +188,7 @@ jumbo_static_library("browser") {
"//components/autofill/core/browser",
"//components/autofill/core/common",
"//components/autofill_assistant/browser/devtools",
"//components/google/core/common:common",
"//components/password_manager/core/browser:browser",
"//components/signin/public/identity_manager",
"//components/strings:components_strings_grit",
......
include_rules = [
"+chrome/android/features/autofill_assistant/test_support_jni_headers",
"+components/autofill",
"+components/google/core/common",
"+components/password_manager/core/browser",
"+components/version_info",
"+content/public/browser",
......
......@@ -23,6 +23,7 @@
#include "components/autofill_assistant/browser/service_impl.h"
#include "components/autofill_assistant/browser/trigger_context.h"
#include "components/autofill_assistant/browser/user_data.h"
#include "components/google/core/common/google_util.h"
#include "components/password_manager/core/browser/password_manager_client.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/browser_task_traits.h"
......@@ -1662,6 +1663,15 @@ void Controller::DidFinishNavigation(
Metrics::DropOutReason::DOMAIN_CHANGE_DURING_BROWSE_MODE);
}
}
// When in STOPPED state, entered by an unexpected DidStartNavigation or
// domain change while in BROWSE state (above), and the new URL is on a
// Google property, destroy the UI immediately.
if (state_ == AutofillAssistantState::STOPPED &&
google_util::IsGoogleDomainUrl(
web_contents()->GetLastCommittedURL(), google_util::ALLOW_SUBDOMAIN,
google_util::DISALLOW_NON_STANDARD_PORTS)) {
client_->DestroyUI();
}
if (start_after_navigation_) {
std::move(start_after_navigation_).Run();
......
......@@ -1587,6 +1587,77 @@ TEST_F(ControllerTest, UnexpectedNavigationDuringPromptAction) {
AutofillAssistantState::STOPPED));
}
TEST_F(ControllerTest, NavigationToGooglePropertyDestroysUI) {
SupportsScriptResponseProto script_response;
AddRunnableScript(&script_response, "autostart")
->mutable_presentation()
->set_autostart(true);
SetNextScriptResponse(script_response);
ActionsResponseProto autostart_script;
autostart_script.add_actions()
->mutable_prompt()
->add_choices()
->mutable_chip()
->set_text("continue");
SetupActionsForScript("autostart", autostart_script);
Start();
EXPECT_EQ(AutofillAssistantState::PROMPT, controller_->GetState());
EXPECT_CALL(mock_client_, Shutdown(Metrics::DropOutReason::NAVIGATION));
EXPECT_CALL(mock_client_, DestroyUI);
GURL google("https://google.com/search");
SetLastCommittedUrl(google);
content::NavigationSimulator::NavigateAndCommitFromBrowser(web_contents(),
google);
EXPECT_EQ(AutofillAssistantState::STOPPED, controller_->GetState());
// Full history of state transitions.
EXPECT_THAT(states_, ElementsAre(AutofillAssistantState::STARTING,
AutofillAssistantState::RUNNING,
AutofillAssistantState::PROMPT,
AutofillAssistantState::STOPPED));
}
TEST_F(ControllerTest, DomainChangeToGooglePropertyDuringBrowseDestroysUI) {
SupportsScriptResponseProto script_response;
AddRunnableScript(&script_response, "runnable")
->mutable_presentation()
->set_autostart(true);
ActionsResponseProto runnable_script;
auto* prompt = runnable_script.add_actions()->mutable_prompt();
prompt->set_browse_mode(true);
prompt->add_choices()->mutable_chip()->set_text("continue");
SetupActionsForScript("runnable", runnable_script);
std::string response_str;
script_response.SerializeToString(&response_str);
EXPECT_CALL(*mock_service_,
OnGetScriptsForUrl(GURL("http://a.example.com/"), _, _))
.WillOnce(RunOnceCallback<2>(true, response_str));
Start("http://a.example.com/");
EXPECT_EQ(AutofillAssistantState::BROWSE, controller_->GetState());
EXPECT_CALL(
mock_client_,
Shutdown(Metrics::DropOutReason::DOMAIN_CHANGE_DURING_BROWSE_MODE));
EXPECT_CALL(mock_client_, DestroyUI);
GURL google("https://google.com/search");
SetLastCommittedUrl(google);
content::NavigationSimulator::NavigateAndCommitFromBrowser(web_contents(),
google);
EXPECT_EQ(AutofillAssistantState::STOPPED, controller_->GetState());
// Full history of state transitions.
EXPECT_THAT(states_, ElementsAre(AutofillAssistantState::STARTING,
AutofillAssistantState::RUNNING,
AutofillAssistantState::BROWSE,
AutofillAssistantState::STOPPED));
}
TEST_F(ControllerTest, UserDataFormEmpty) {
auto options = std::make_unique<MockCollectUserDataOptions>();
auto user_data = std::make_unique<UserData>();
......
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