Commit a31099c6 authored by Stephane Zermatten's avatar Stephane Zermatten Committed by Commit Bot

[Autofill Assistant] Make scripts without preconditions runnable.

With this change, scripts without precondition are not treated as
invalid, but runnable. Also includes a small test
ProtocolUtils::ParseScripts.

Bug: 806868
Change-Id: I6c286b1622bfeb4d635310396cb3b158ffd6933e
Reviewed-on: https://chromium-review.googlesource.com/1219748Reviewed-by: default avatarGanggui Tang <gogerald@chromium.org>
Commit-Queue: Stephane Zermatten <szermatt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590333}
parent c3dc46d8
...@@ -72,6 +72,7 @@ source_set("unit_tests") { ...@@ -72,6 +72,7 @@ source_set("unit_tests") {
"mock_ui_controller.h", "mock_ui_controller.h",
"mock_web_controller.cc", "mock_web_controller.cc",
"mock_web_controller.h", "mock_web_controller.h",
"protocol_utils_unittest.cc",
"script_executor_unittest.cc", "script_executor_unittest.cc",
"script_precondition_unittest.cc", "script_precondition_unittest.cc",
"script_tracker_unittest.cc", "script_tracker_unittest.cc",
......
...@@ -51,11 +51,8 @@ bool ProtocolUtils::ParseScripts( ...@@ -51,11 +51,8 @@ bool ProtocolUtils::ParseScripts(
const auto& presentation = script_proto.presentation(); const auto& presentation = script_proto.presentation();
script->handle.name = presentation.name(); script->handle.name = presentation.name();
if (presentation.has_precondition()) {
script->precondition = script->precondition =
ScriptPrecondition::FromProto(presentation.precondition()); ScriptPrecondition::FromProto(presentation.precondition());
}
if (script->handle.name.empty() || script->handle.path.empty() || if (script->handle.name.empty() || script->handle.path.empty() ||
!script->precondition) { !script->precondition) {
......
// 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_assistant/browser/protocol_utils.h"
#include "base/macros.h"
#include "components/autofill_assistant/browser/service.pb.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace autofill_assistant {
namespace {
using ::testing::SizeIs;
using ::testing::IsEmpty;
TEST(ProtocolUtilsTest, NoScripts) {
std::vector<std::unique_ptr<Script>> scripts;
EXPECT_TRUE(ProtocolUtils::ParseScripts("", &scripts));
EXPECT_THAT(scripts, IsEmpty());
}
TEST(ProtocolUtilsTest, SomeInvalidScripts) {
SupportsScriptResponseProto proto;
// 2 Invalid scripts, 1 valid one, with no preconditions.
proto.add_scripts()->mutable_presentation()->set_name("missing path");
proto.add_scripts()->set_path("missing name");
SupportedScriptProto* script = proto.add_scripts();
script->set_path("ok");
script->mutable_presentation()->set_name("ok name");
// Only the valid script is returned.
std::vector<std::unique_ptr<Script>> scripts;
std::string proto_str;
proto.SerializeToString(&proto_str);
EXPECT_TRUE(ProtocolUtils::ParseScripts(proto_str, &scripts));
ASSERT_THAT(scripts, SizeIs(1));
EXPECT_EQ("ok", scripts[0]->handle.path);
EXPECT_EQ("ok name", scripts[0]->handle.name);
EXPECT_NE(nullptr, scripts[0]->precondition);
}
} // namespace
} // namespace autofill_assistant
...@@ -27,7 +27,7 @@ message SupportsScriptResponseProto { ...@@ -27,7 +27,7 @@ message SupportsScriptResponseProto {
// Supported script. // Supported script.
message SupportedScriptProto { message SupportedScriptProto {
// This is the internal name of the script. // This is the internal name of the script.
required string path = 1; optional string path = 1;
message PresentationProto { message PresentationProto {
// Script name. // Script name.
......
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