Commit 8633318b authored by Clemens Arbesser's avatar Clemens Arbesser Committed by Commit Bot

[Autofill Assistant] Added NOT_EQUAL comparison operator.

Bug: b/145043394
Change-Id: I3311290b6fe2d59b9f4fedbce9f0e5bb2a06a102
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2309435Reviewed-by: default avatarLuca Hunkeler <hluca@google.com>
Commit-Queue: Clemens Arbesser <arbesser@google.com>
Cr-Commit-Position: refs/heads/master@{#790346}
parent 06502e81
......@@ -245,6 +245,13 @@ bool Compare(UserModel* user_model,
ContainsClientOnlyValue({*value_a, *value_b})));
return true;
}
if (proto.mode() == ValueComparisonProto::NOT_EQUAL) {
user_model->SetValue(
result_model_identifier,
SimpleValue(*value_a != *value_b,
ContainsClientOnlyValue({*value_a, *value_b})));
return true;
}
// All modes except EQUAL require a size of 1 and a common value type and
// are only supported for a subset of value types.
......@@ -286,6 +293,7 @@ bool Compare(UserModel* user_model,
result = *value_a > *value_b;
break;
case ValueComparisonProto::EQUAL:
case ValueComparisonProto::NOT_EQUAL:
case ValueComparisonProto::UNDEFINED:
NOTREACHED();
return false;
......
......@@ -436,28 +436,32 @@ TEST_F(BasicInteractionsTest, ComputeValueCompare) {
proto.set_result_model_identifier("result");
EXPECT_FALSE(basic_interactions_.ComputeValue(proto));
// EQUAL supported for all value types.
proto.mutable_comparison()->set_mode(ValueComparisonProto::EQUAL);
EXPECT_TRUE(basic_interactions_.ComputeValue(proto));
user_model_.SetValue("value_a", SimpleValue(std::string("string_a")));
user_model_.SetValue("value_b", SimpleValue(std::string("string_b")));
EXPECT_TRUE(basic_interactions_.ComputeValue(proto));
user_model_.SetValue("value_a", SimpleValue(true));
user_model_.SetValue("value_b", SimpleValue(false));
EXPECT_TRUE(basic_interactions_.ComputeValue(proto));
user_model_.SetValue("value_a", SimpleValue(1));
user_model_.SetValue("value_b", SimpleValue(2));
EXPECT_TRUE(basic_interactions_.ComputeValue(proto));
user_model_.SetValue("value_a", SimpleValue(CreateDateProto(2020, 8, 7)));
user_model_.SetValue("value_b", SimpleValue(CreateDateProto(2020, 11, 5)));
EXPECT_TRUE(basic_interactions_.ComputeValue(proto));
ValueProto user_actions_value;
user_actions_value.mutable_user_actions();
user_model_.SetValue("value_a", user_actions_value);
user_model_.SetValue("value_b", user_actions_value);
EXPECT_TRUE(basic_interactions_.ComputeValue(proto));
// EQUAL and NOT_EQUAL supported for all value types.
ValueComparisonProto::Mode support_all_types_modes[] = {
ValueComparisonProto::EQUAL, ValueComparisonProto::NOT_EQUAL};
for (const auto mode : support_all_types_modes) {
proto.mutable_comparison()->set_mode(mode);
EXPECT_TRUE(basic_interactions_.ComputeValue(proto));
user_model_.SetValue("value_a", SimpleValue(std::string("string_a")));
user_model_.SetValue("value_b", SimpleValue(std::string("string_b")));
EXPECT_TRUE(basic_interactions_.ComputeValue(proto));
user_model_.SetValue("value_a", SimpleValue(true));
user_model_.SetValue("value_b", SimpleValue(false));
EXPECT_TRUE(basic_interactions_.ComputeValue(proto));
user_model_.SetValue("value_a", SimpleValue(1));
user_model_.SetValue("value_b", SimpleValue(2));
EXPECT_TRUE(basic_interactions_.ComputeValue(proto));
user_model_.SetValue("value_a", SimpleValue(CreateDateProto(2020, 8, 7)));
user_model_.SetValue("value_b", SimpleValue(CreateDateProto(2020, 11, 5)));
EXPECT_TRUE(basic_interactions_.ComputeValue(proto));
ValueProto user_actions_value;
user_actions_value.mutable_user_actions();
user_model_.SetValue("value_a", user_actions_value);
user_model_.SetValue("value_b", user_actions_value);
EXPECT_TRUE(basic_interactions_.ComputeValue(proto));
}
// Some types are not supported for comparison mode != EQUAL.
// Some types are not supported for modes other than EQUAL and NOT_EQUAL.
proto.mutable_comparison()->set_mode(ValueComparisonProto::LESS);
user_model_.SetValue("value_a", ValueProto());
user_model_.SetValue("value_b", ValueProto());
......@@ -465,6 +469,8 @@ TEST_F(BasicInteractionsTest, ComputeValueCompare) {
user_model_.SetValue("value_a", SimpleValue(true));
user_model_.SetValue("value_b", SimpleValue(false));
EXPECT_FALSE(basic_interactions_.ComputeValue(proto));
ValueProto user_actions_value;
user_actions_value.mutable_user_actions();
user_model_.SetValue("value_a", user_actions_value);
user_model_.SetValue("value_b", user_actions_value);
EXPECT_FALSE(basic_interactions_.ComputeValue(proto));
......@@ -482,6 +488,12 @@ TEST_F(BasicInteractionsTest, ComputeValueCompare) {
user_model_.SetValue("value_b", multi_value);
EXPECT_FALSE(basic_interactions_.ComputeValue(proto));
// Different types succeed for mode == NOT_EQUAL.
proto.mutable_comparison()->set_mode(ValueComparisonProto::NOT_EQUAL);
user_model_.SetValue("value_a", SimpleValue(1));
user_model_.SetValue("value_b", SimpleValue(std::string("a")));
EXPECT_TRUE(basic_interactions_.ComputeValue(proto));
// Check comparison results.
proto.mutable_comparison()->set_mode(ValueComparisonProto::LESS);
user_model_.SetValue("value_a", SimpleValue(1));
......@@ -524,6 +536,21 @@ TEST_F(BasicInteractionsTest, ComputeValueCompare) {
SimpleValue(1, /* is_client_side_only = */ true));
EXPECT_TRUE(basic_interactions_.ComputeValue(proto));
EXPECT_EQ(*user_model_.GetValue("result"), SimpleValue(true, true));
proto.mutable_comparison()->set_mode(ValueComparisonProto::NOT_EQUAL);
user_model_.SetValue("value_a", SimpleValue(1));
user_model_.SetValue("value_b", SimpleValue(std::string("a")));
EXPECT_TRUE(basic_interactions_.ComputeValue(proto));
EXPECT_EQ(user_model_.GetValue("result"), SimpleValue(true));
user_model_.SetValue("value_a", SimpleValue(1));
user_model_.SetValue("value_b", SimpleValue(2));
EXPECT_TRUE(basic_interactions_.ComputeValue(proto));
EXPECT_EQ(user_model_.GetValue("result"), SimpleValue(true));
user_model_.SetValue("value_b", SimpleValue(1));
EXPECT_TRUE(basic_interactions_.ComputeValue(proto));
EXPECT_EQ(user_model_.GetValue("result"), SimpleValue(false));
}
TEST_F(BasicInteractionsTest, ComputeValueCreateCreditCardResponse) {
......
......@@ -208,9 +208,9 @@ message AutofillFormatProto {
optional string locale = 2;
}
// A comparison of two values in the form |value_a| <mode> |value_b|. EQUAL is
// supported for all values. All other comparison modes are only supported for
// single integers, strings, and dates.
// A comparison of two values in the form |value_a| <mode> |value_b|. EQUAL and
// NOT_EQUAL are supported for all values. All other comparison modes are only
// supported for single integers, strings, and dates.
message ValueComparisonProto {
enum Mode {
UNDEFINED = 0;
......@@ -219,6 +219,7 @@ message ValueComparisonProto {
EQUAL = 3;
GREATER_OR_EQUAL = 4;
GREATER = 5;
NOT_EQUAL = 6;
}
// The first value to compare.
......
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