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, ...@@ -245,6 +245,13 @@ bool Compare(UserModel* user_model,
ContainsClientOnlyValue({*value_a, *value_b}))); ContainsClientOnlyValue({*value_a, *value_b})));
return true; 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 // All modes except EQUAL require a size of 1 and a common value type and
// are only supported for a subset of value types. // are only supported for a subset of value types.
...@@ -286,6 +293,7 @@ bool Compare(UserModel* user_model, ...@@ -286,6 +293,7 @@ bool Compare(UserModel* user_model,
result = *value_a > *value_b; result = *value_a > *value_b;
break; break;
case ValueComparisonProto::EQUAL: case ValueComparisonProto::EQUAL:
case ValueComparisonProto::NOT_EQUAL:
case ValueComparisonProto::UNDEFINED: case ValueComparisonProto::UNDEFINED:
NOTREACHED(); NOTREACHED();
return false; return false;
......
...@@ -436,8 +436,11 @@ TEST_F(BasicInteractionsTest, ComputeValueCompare) { ...@@ -436,8 +436,11 @@ TEST_F(BasicInteractionsTest, ComputeValueCompare) {
proto.set_result_model_identifier("result"); proto.set_result_model_identifier("result");
EXPECT_FALSE(basic_interactions_.ComputeValue(proto)); EXPECT_FALSE(basic_interactions_.ComputeValue(proto));
// EQUAL supported for all value types. // EQUAL and NOT_EQUAL supported for all value types.
proto.mutable_comparison()->set_mode(ValueComparisonProto::EQUAL); 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)); EXPECT_TRUE(basic_interactions_.ComputeValue(proto));
user_model_.SetValue("value_a", SimpleValue(std::string("string_a"))); user_model_.SetValue("value_a", SimpleValue(std::string("string_a")));
user_model_.SetValue("value_b", SimpleValue(std::string("string_b"))); user_model_.SetValue("value_b", SimpleValue(std::string("string_b")));
...@@ -456,8 +459,9 @@ TEST_F(BasicInteractionsTest, ComputeValueCompare) { ...@@ -456,8 +459,9 @@ TEST_F(BasicInteractionsTest, ComputeValueCompare) {
user_model_.SetValue("value_a", user_actions_value); user_model_.SetValue("value_a", user_actions_value);
user_model_.SetValue("value_b", user_actions_value); user_model_.SetValue("value_b", user_actions_value);
EXPECT_TRUE(basic_interactions_.ComputeValue(proto)); 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); proto.mutable_comparison()->set_mode(ValueComparisonProto::LESS);
user_model_.SetValue("value_a", ValueProto()); user_model_.SetValue("value_a", ValueProto());
user_model_.SetValue("value_b", ValueProto()); user_model_.SetValue("value_b", ValueProto());
...@@ -465,6 +469,8 @@ TEST_F(BasicInteractionsTest, ComputeValueCompare) { ...@@ -465,6 +469,8 @@ TEST_F(BasicInteractionsTest, ComputeValueCompare) {
user_model_.SetValue("value_a", SimpleValue(true)); user_model_.SetValue("value_a", SimpleValue(true));
user_model_.SetValue("value_b", SimpleValue(false)); user_model_.SetValue("value_b", SimpleValue(false));
EXPECT_FALSE(basic_interactions_.ComputeValue(proto)); 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_a", user_actions_value);
user_model_.SetValue("value_b", user_actions_value); user_model_.SetValue("value_b", user_actions_value);
EXPECT_FALSE(basic_interactions_.ComputeValue(proto)); EXPECT_FALSE(basic_interactions_.ComputeValue(proto));
...@@ -482,6 +488,12 @@ TEST_F(BasicInteractionsTest, ComputeValueCompare) { ...@@ -482,6 +488,12 @@ TEST_F(BasicInteractionsTest, ComputeValueCompare) {
user_model_.SetValue("value_b", multi_value); user_model_.SetValue("value_b", multi_value);
EXPECT_FALSE(basic_interactions_.ComputeValue(proto)); 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. // Check comparison results.
proto.mutable_comparison()->set_mode(ValueComparisonProto::LESS); proto.mutable_comparison()->set_mode(ValueComparisonProto::LESS);
user_model_.SetValue("value_a", SimpleValue(1)); user_model_.SetValue("value_a", SimpleValue(1));
...@@ -524,6 +536,21 @@ TEST_F(BasicInteractionsTest, ComputeValueCompare) { ...@@ -524,6 +536,21 @@ TEST_F(BasicInteractionsTest, ComputeValueCompare) {
SimpleValue(1, /* is_client_side_only = */ true)); SimpleValue(1, /* is_client_side_only = */ true));
EXPECT_TRUE(basic_interactions_.ComputeValue(proto)); EXPECT_TRUE(basic_interactions_.ComputeValue(proto));
EXPECT_EQ(*user_model_.GetValue("result"), SimpleValue(true, true)); 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) { TEST_F(BasicInteractionsTest, ComputeValueCreateCreditCardResponse) {
......
...@@ -208,9 +208,9 @@ message AutofillFormatProto { ...@@ -208,9 +208,9 @@ message AutofillFormatProto {
optional string locale = 2; optional string locale = 2;
} }
// A comparison of two values in the form |value_a| <mode> |value_b|. EQUAL is // A comparison of two values in the form |value_a| <mode> |value_b|. EQUAL and
// supported for all values. All other comparison modes are only supported for // NOT_EQUAL are supported for all values. All other comparison modes are only
// single integers, strings, and dates. // supported for single integers, strings, and dates.
message ValueComparisonProto { message ValueComparisonProto {
enum Mode { enum Mode {
UNDEFINED = 0; UNDEFINED = 0;
...@@ -219,6 +219,7 @@ message ValueComparisonProto { ...@@ -219,6 +219,7 @@ message ValueComparisonProto {
EQUAL = 3; EQUAL = 3;
GREATER_OR_EQUAL = 4; GREATER_OR_EQUAL = 4;
GREATER = 5; GREATER = 5;
NOT_EQUAL = 6;
} }
// The first value to compare. // 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