Commit de5181e6 authored by David Black's avatar David Black Committed by Commit Bot

Enforce max conversation starters.

The number of conversation starters should not exceed our stated max.
Note that this CL also updates names of some unittests which contained
"_" in their names (which is discouraged).

Bug: b:148246719
Change-Id: I01ea72c5ba5967ec489a170c5a6a799de56a731b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2031666Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Commit-Queue: David Black <dmblack@google.com>
Cr-Commit-Position: refs/heads/master@{#737116}
parent e0074774
......@@ -203,8 +203,12 @@ void AssistantSuggestionsController::FetchConversationStarters() {
return;
}
// Otherwise we transform our conversation starters into the type that
// is understood by the suggestions model...
// The number of conversation starters should not exceed our maximum.
while (conversation_starters.size() > kMaxNumOfConversationStarters)
conversation_starters.pop_back();
// We need to transform our conversation starters into the type that is
// understood by the suggestions model...
std::vector<AssistantSuggestionPtr> suggestions;
std::transform(
conversation_starters.begin(), conversation_starters.end(),
......
......@@ -27,14 +27,14 @@ void ExpectEqual(const ash::ConversationStarter& a,
using ConversationStartersParserTest = ChromeAshTestBase;
// Verifies handling of an empty response.
TEST_F(ConversationStartersParserTest, Parse_EmptyResponse) {
TEST_F(ConversationStartersParserTest, HandlesEmptyResponse) {
const std::vector<ash::ConversationStarter> conversation_starters =
ConversationStartersParser::Parse(std::string());
EXPECT_TRUE(conversation_starters.empty());
}
// Verifies handling of a non-safe JSON response.
TEST_F(ConversationStartersParserTest, Parse_JsonResponse) {
TEST_F(ConversationStartersParserTest, HandlesJsonResponse) {
const std::vector<ash::ConversationStarter> conversation_starters =
ConversationStartersParser::Parse(R"(
{
......@@ -52,7 +52,7 @@ TEST_F(ConversationStartersParserTest, Parse_JsonResponse) {
}
// Verifies handling of a safe JSON response that is not recognized.
TEST_F(ConversationStartersParserTest, Parse_SafeJsonResponse_Unrecognized) {
TEST_F(ConversationStartersParserTest, HandlesUnrecognizedSafeJsonResponse) {
const std::vector<ash::ConversationStarter> conversation_starters =
ConversationStartersParser::Parse(R"()]}'
{
......@@ -83,7 +83,7 @@ TEST_F(ConversationStartersParserTest, Parse_SafeJsonResponse_Unrecognized) {
// Verifies handling of a safe JSON response that is recognized.
// Note that |label| is required, but |actionUrl|, |iconUrl|, and
// |requiredPermissions| are optional.
TEST_F(ConversationStartersParserTest, Parse_SafeJsonResponse_Recognized) {
TEST_F(ConversationStartersParserTest, HandlesRecognizedSafeJsonResponse) {
const std::vector<ash::ConversationStarter> conversation_starters =
ConversationStartersParser::Parse(R"()]}'
{
......@@ -133,7 +133,7 @@ TEST_F(ConversationStartersParserTest, Parse_SafeJsonResponse_Recognized) {
// Verifies that a conversation starter that does not specify a |label| is
// omitted from the collection.
TEST_F(ConversationStartersParserTest, Parse_MissingLabel) {
TEST_F(ConversationStartersParserTest, HandlesMissingLabel) {
const std::vector<ash::ConversationStarter> conversation_starters =
ConversationStartersParser::Parse(R"()]}'
{
......@@ -151,7 +151,7 @@ TEST_F(ConversationStartersParserTest, Parse_MissingLabel) {
// Verifies that a conversation starter that specifies a required permission
// that is not recognized is marked as requiring an unknown permission.
TEST_F(ConversationStartersParserTest, Parse_UnknownPermission) {
TEST_F(ConversationStartersParserTest, HandlesUnknownPermission) {
const std::vector<ash::ConversationStarter> conversation_starters =
ConversationStartersParser::Parse(R"()]}'
{
......
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