Commit 8d9c0217 authored by David Black's avatar David Black Committed by Commit Bot

Handle opening of Assistant search results.

Opening of Assistant search results is delegated to the Assistant
Controller as it knows how to handle Assistant deep links.

Known issue:
- Launcher eagerly closes when opening search results. We will need to
  do a follow up CL to make this behavior conditional since more often
  than not Assistant search results will need to open in-Launcher
  embedded Assistant UI.

Bug: b:146673437
Change-Id: Ifc0e3bd5bde0ecb574ef9469d3e55968ad51fa7c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2153343
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759892}
parent 3aa1162e
static_library("test_support") {
testonly = true
sources = [
"mock_assistant_controller.cc",
"mock_assistant_controller.h",
]
deps = [
"//ash/public/cpp",
"//testing/gmock",
"//url",
]
}
// Copyright 2020 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 "ash/public/cpp/assistant/test_support/mock_assistant_controller.h"
namespace ash {
MockAssistantController::MockAssistantController() = default;
MockAssistantController::~MockAssistantController() = default;
} // namespace ash
// Copyright 2020 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.
#ifndef ASH_PUBLIC_CPP_ASSISTANT_TEST_SUPPORT_MOCK_ASSISTANT_CONTROLLER_H_
#define ASH_PUBLIC_CPP_ASSISTANT_TEST_SUPPORT_MOCK_ASSISTANT_CONTROLLER_H_
#include "ash/public/cpp/assistant/controller/assistant_controller.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "url/gurl.h"
namespace ash {
class MockAssistantController : public AssistantController {
public:
MockAssistantController();
MockAssistantController(const MockAssistantController&) = delete;
MockAssistantController& operator=(const MockAssistantController&) = delete;
~MockAssistantController() override;
MOCK_METHOD(void,
OpenUrl,
(const GURL& url, bool in_background, bool from_server),
(override));
MOCK_METHOD(base::WeakPtr<AssistantController>, GetWeakPtr, (), (override));
};
} // namespace ash
#endif // ASH_PUBLIC_CPP_ASSISTANT_TEST_SUPPORT_MOCK_ASSISTANT_CONTROLLER_H_
......@@ -8,6 +8,7 @@
#include "ash/public/cpp/app_list/app_list_config.h"
#include "ash/public/cpp/app_list/app_list_metrics.h"
#include "ash/public/cpp/app_list/app_list_types.h"
#include "ash/public/cpp/assistant/controller/assistant_controller.h"
#include "ash/public/cpp/vector_icons/vector_icons.h"
#include "base/strings/utf_string_conversions.h"
#include "base/unguessable_token.h"
......@@ -41,7 +42,8 @@ bool AreResultsAllowed() {
class AssistantSearchResult : public ChromeSearchResult {
public:
explicit AssistantSearchResult(
const AssistantSuggestion* conversation_starter) {
const AssistantSuggestion* conversation_starter)
: action_url_(conversation_starter->action_url) {
set_id(kIdPrefix + conversation_starter->id.ToString());
SetDisplayIndex(ash::SearchResultDisplayIndex::kFirstIndex);
SetDisplayType(ash::SearchResultDisplayType::kChip);
......@@ -63,8 +65,15 @@ class AssistantSearchResult : public ChromeSearchResult {
return ash::SearchResultType::ASSISTANT;
}
// TODO(b:153166883): Handle opening Assistant result.
void Open(int event_flags) override { NOTIMPLEMENTED(); }
// TODO(b:154152631): Prevent eager dismissal of launcher when opening.
// TODO(b:154153233): Create and utilize new Assistant entry point.
void Open(int event_flags) override {
// Opening of |action_url_| is delegated to the Assistant controller as only
// the Assistant controller knows how to handle Assistant deep links.
ash::AssistantController::Get()->OpenUrl(action_url_);
}
const GURL action_url_;
};
} // namespace
......
......@@ -8,6 +8,7 @@
#include "ash/public/cpp/app_list/app_list_config.h"
#include "ash/public/cpp/assistant/assistant_state.h"
#include "ash/public/cpp/assistant/controller/assistant_suggestions_controller.h"
#include "ash/public/cpp/assistant/test_support/mock_assistant_controller.h"
#include "ash/public/cpp/vector_icons/vector_icons.h"
#include "base/strings/utf_string_conversions.h"
#include "base/unguessable_token.h"
......@@ -15,17 +16,20 @@
#include "chrome/browser/ui/app_list/search/assistant_search_provider.h"
#include "chrome/browser/ui/app_list/search/chrome_search_result.h"
#include "chromeos/services/assistant/public/mojom/assistant.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/paint_vector_icon.h"
#include "url/gurl.h"
namespace app_list {
namespace test {
// Aliases.
using AssistantAllowedState = ash::mojom::AssistantAllowedState;
using AssistantSuggestion = chromeos::assistant::mojom::AssistantSuggestion;
using AssistantSuggestionPtr =
chromeos::assistant::mojom::AssistantSuggestionPtr;
using ash::mojom::AssistantAllowedState;
using chromeos::assistant::mojom::AssistantSuggestion;
using chromeos::assistant::mojom::AssistantSuggestionPtr;
using testing::DoAll;
using testing::NiceMock;
using testing::SaveArg;
// Expectations ----------------------------------------------------------------
......@@ -73,6 +77,7 @@ class ConversationStarterBuilder {
AssistantSuggestionPtr conversation_starter = AssistantSuggestion::New();
conversation_starter->id = id_;
conversation_starter->text = text_;
conversation_starter->action_url = action_url_;
return conversation_starter;
}
......@@ -86,9 +91,15 @@ class ConversationStarterBuilder {
return *this;
}
ConversationStarterBuilder& WithActionUrl(const std::string& action_url) {
action_url_ = GURL(action_url);
return *this;
}
private:
base::UnguessableToken id_;
std::string text_;
GURL action_url_;
};
// TestAssistantState ----------------------------------------------------------
......@@ -181,9 +192,13 @@ class AssistantSearchProviderTest : public AppListTestBase {
delete;
~AssistantSearchProviderTest() override = default;
AssistantSearchProvider& search_provider() { return search_provider_; }
TestAssistantState& assistant_state() { return assistant_state_; }
AssistantSearchProvider& search_provider() { return search_provider_; }
NiceMock<ash::MockAssistantController>& assistant_controller() {
return assistant_controller_;
}
TestAssistantSuggestionsController& suggestions_controller() {
return suggestions_controller_;
......@@ -191,6 +206,7 @@ class AssistantSearchProviderTest : public AppListTestBase {
private:
TestAssistantState assistant_state_;
NiceMock<ash::MockAssistantController> assistant_controller_;
TestAssistantSuggestionsController suggestions_controller_;
AssistantSearchProvider search_provider_;
};
......@@ -264,5 +280,30 @@ TEST_F(AssistantSearchProviderTest,
Expect(result).Matches(*update);
}
TEST_F(AssistantSearchProviderTest,
ShouldDelegateOpeningResultsToAssistantController) {
suggestions_controller().SetConversationStarter(
ConversationStarterBuilder()
.WithId(base::UnguessableToken::Create())
.WithText("Weather")
.WithActionUrl("googleassistant://send-query?q=weather")
.Build());
ASSERT_EQ(1u, search_provider().results().size());
GURL url;
bool in_background = true;
bool from_user = true;
EXPECT_CALL(assistant_controller(), OpenUrl)
.WillOnce(DoAll(SaveArg<0>(&url), SaveArg<1>(&in_background),
SaveArg<2>(&from_user)));
search_provider().results().at(0)->Open(/*event_flags=*/0);
EXPECT_EQ(GURL("googleassistant://send-query?q=weather"), url);
EXPECT_FALSE(in_background);
EXPECT_FALSE(from_user);
}
} // namespace test
} // namespace app_list
......@@ -4440,6 +4440,7 @@ test("unit_tests") {
deps += [
"//ash:test_support",
"//ash/app_list:test_support",
"//ash/public/cpp/assistant/test_support",
"//ash/public/cpp/resources:ash_public_unscaled_resources",
"//ash/resources/vector_icons",
"//ash/strings",
......
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