Commit 1dc10acb authored by David Black's avatar David Black Committed by Commit Bot

Create deep link for Assistant Reminders by id.

This CL adds an |id| paramter to the existing Assistant Reminders
deep link to allow opening a specific reminder.

Omitting an |id| falls back to top-level Assistant Settings.

Bug: b:120085149
Change-Id: If2e4a5c532ce585102bb3e448f1d585c02c9cf62
Reviewed-on: https://chromium-review.googlesource.com/c/1352477Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Commit-Queue: David Black <dmblack@google.com>
Cr-Commit-Position: refs/heads/master@{#611462}
parent 78b186c9
......@@ -182,7 +182,7 @@ void AssistantWebView::OnDeepLinkReceived(
contents_->AddObserver(this);
// Navigate to the url associated with the received deep link.
contents_->Navigate(assistant::util::GetWebUrl(type).value());
contents_->Navigate(assistant::util::GetWebUrl(type, params).value());
}
void AssistantWebView::DidAutoResizeView(const gfx::Size& new_size) {
......
......@@ -23,6 +23,7 @@ namespace {
// Supported deep link param keys. These values must be kept in sync with the
// server. See more details at go/cros-assistant-deeplink.
constexpr char kIdParamKey[] = "id";
constexpr char kQueryParamKey[] = "q";
constexpr char kPageParamKey[] = "page";
constexpr char kRelaunchParamKey[] = "relaunch";
......@@ -90,6 +91,7 @@ base::Optional<std::string> GetDeepLinkParam(
DeepLinkParam param) {
// Map of supported deep link params to their keys.
static const std::map<DeepLinkParam, std::string> kDeepLinkParamKeys = {
{DeepLinkParam::kId, kIdParamKey},
{DeepLinkParam::kPage, kPageParamKey},
{DeepLinkParam::kQuery, kQueryParamKey},
{DeepLinkParam::kRelaunch, kRelaunchParamKey}};
......@@ -145,6 +147,17 @@ bool IsDeepLinkUrl(const GURL& url) {
return GetDeepLinkType(url) != DeepLinkType::kUnsupported;
}
GURL GetAssistantRemindersUrl(const base::Optional<std::string>& id) {
// TODO(b/113357196): Make these URLs configurable for development purposes.
static constexpr char kAssistantRemindersWebUrl[] =
"https://assistant.google.com/reminders/mainview";
static constexpr char kAssistantRemindersByIdWebUrl[] =
"https://assistant.google.com/reminders/id/";
return (id && !id.value().empty())
? CreateLocalizedGURL(kAssistantRemindersByIdWebUrl + id.value())
: CreateLocalizedGURL(kAssistantRemindersWebUrl);
}
GURL GetChromeSettingsUrl(const base::Optional<std::string>& page) {
static constexpr char kChromeSettingsUrl[] = "chrome://settings/";
......@@ -161,13 +174,13 @@ GURL GetChromeSettingsUrl(const base::Optional<std::string>& page) {
}
base::Optional<GURL> GetWebUrl(const GURL& deep_link) {
return GetWebUrl(GetDeepLinkType(deep_link));
return GetWebUrl(GetDeepLinkType(deep_link), GetDeepLinkParams(deep_link));
}
base::Optional<GURL> GetWebUrl(DeepLinkType type) {
base::Optional<GURL> GetWebUrl(
DeepLinkType type,
const std::map<std::string, std::string>& params) {
// TODO(b/113357196): Make these URLs configurable for development purposes.
static constexpr char kAssistantRemindersWebUrl[] =
"https://assistant.google.com/reminders/mainview";
static constexpr char kAssistantSettingsWebUrl[] =
"https://assistant.google.com/settings/mainpage";
......@@ -176,7 +189,8 @@ base::Optional<GURL> GetWebUrl(DeepLinkType type) {
switch (type) {
case DeepLinkType::kReminders:
return CreateLocalizedGURL(kAssistantRemindersWebUrl);
return GetAssistantRemindersUrl(
GetDeepLinkParam(params, DeepLinkParam::kId));
case DeepLinkType::kSettings:
return CreateLocalizedGURL(kAssistantSettingsWebUrl);
case DeepLinkType::kUnsupported:
......
......@@ -33,6 +33,7 @@ enum class DeepLinkType {
// Enumeration of deep link parameters.
enum class DeepLinkParam {
kId,
kPage,
kQuery,
kRelaunch,
......@@ -72,6 +73,10 @@ ASH_EXPORT bool IsDeepLinkType(const GURL& url, DeepLinkType type);
// Returns true if the specified |url| is a deep link, false otherwise.
ASH_EXPORT bool IsDeepLinkUrl(const GURL& url);
// Returns the URL for the specified Assistant reminder |id|. If id is absent,
// the returned URL will be for top-level Assistant Reminders.
ASH_EXPORT GURL GetAssistantRemindersUrl(const base::Optional<std::string>& id);
// Returns the URL for the specified Chrome Settings |page|. If page is absent
// or not allowed, the URL will be for top-level Chrome Settings.
ASH_EXPORT GURL GetChromeSettingsUrl(const base::Optional<std::string>& page);
......@@ -81,10 +86,12 @@ ASH_EXPORT GURL GetChromeSettingsUrl(const base::Optional<std::string>& page);
// IsWebDeepLink(GURL) API.
ASH_EXPORT base::Optional<GURL> GetWebUrl(const GURL& deep_link);
// Returns the web URL for a deep link of the specified |type|. A return value
// will only be present if the deep link type is a web deep link type as
// identified by the IsWebDeepLinkType(DeepLinkType) API.
ASH_EXPORT base::Optional<GURL> GetWebUrl(DeepLinkType type);
// Returns the web URL for a deep link of the specified |type| with the given
// |params|. A return value will only be present if the deep link type is a web
// deep link type as identified by the IsWebDeepLinkType(DeepLinkType) API.
ASH_EXPORT base::Optional<GURL> GetWebUrl(
DeepLinkType type,
const std::map<std::string, std::string>& params);
// Returns true if the specified |deep_link| is a web deep link.
ASH_EXPORT bool IsWebDeepLink(const GURL& deep_link);
......
......@@ -262,6 +262,22 @@ TEST_F(DeepLinkUnitTest, IsDeepLinkUrl) {
ASSERT_EQ(test_case.second, IsDeepLinkUrl(GURL(test_case.first)));
}
TEST_F(DeepLinkUnitTest, GetAssistantRemindersUrl) {
const std::map<base::Optional<std::string>, std::string> test_cases = {
// OK: Absent/empty id.
{base::nullopt,
"https://assistant.google.com/reminders/mainview?hl=en-US"},
{base::Optional<std::string>(std::string()),
"https://assistant.google.com/reminders/mainview?hl=en-US"},
// OK: Specified id.
{base::Optional<std::string>("123456"),
"https://assistant.google.com/reminders/id/123456?hl=en-US"}};
for (const auto& test_case : test_cases)
ASSERT_EQ(test_case.second, GetAssistantRemindersUrl(test_case.first));
}
TEST_F(DeepLinkUnitTest, GetChromeSettingsUrl) {
const std::map<base::Optional<std::string>, std::string> test_cases = {
// OK: Absent/empty page.
......@@ -293,8 +309,8 @@ TEST_F(DeepLinkUnitTest, GetWebUrl) {
GURL("https://assistant.google.com/settings/mainpage?hl=en-US")},
// OK: Parameterized deep links.
{"googleassistant://reminders?param=true",
GURL("https://assistant.google.com/reminders/mainview?hl=en-US")},
{"googleassistant://reminders?id=123456",
GURL("https://assistant.google.com/reminders/id/123456?hl=en-US")},
{"googleassistant://settings?param=true",
GURL("https://assistant.google.com/settings/mainpage?hl=en-US")},
......@@ -329,28 +345,51 @@ TEST_F(DeepLinkUnitTest, GetWebUrl) {
}
TEST_F(DeepLinkUnitTest, GetWebUrlByType) {
const std::map<DeepLinkType, base::Optional<GURL>> test_cases = {
using DeepLinkParams = std::map<std::string, std::string>;
using TestCase = std::pair<DeepLinkType, DeepLinkParams>;
// Creates a test case with a single parameter.
auto CreateTestCaseWithParam =
[](DeepLinkType type,
base::Optional<std::pair<std::string, std::string>> param =
base::nullopt) {
DeepLinkParams params;
if (param)
params.insert(param.value());
return std::make_pair(type, params);
};
// Creates a test case with no parameters.
auto CreateTestCase = [&CreateTestCaseWithParam](DeepLinkType type) {
return CreateTestCaseWithParam(type);
};
const std::map<TestCase, base::Optional<GURL>> test_cases = {
// OK: Supported web deep link types.
{DeepLinkType::kReminders,
{CreateTestCase(DeepLinkType::kReminders),
GURL("https://assistant.google.com/reminders/mainview?hl=en-US")},
{DeepLinkType::kSettings,
{CreateTestCaseWithParam(DeepLinkType::kReminders,
std::make_pair("id", "123456")),
GURL("https://assistant.google.com/reminders/id/123456?hl=en-US")},
{CreateTestCase(DeepLinkType::kSettings),
GURL("https://assistant.google.com/settings/mainpage?hl=en-US")},
// FAIL: Non-web deep link types.
{DeepLinkType::kChromeSettings, base::nullopt},
{DeepLinkType::kFeedback, base::nullopt},
{DeepLinkType::kOnboarding, base::nullopt},
{DeepLinkType::kQuery, base::nullopt},
{DeepLinkType::kScreenshot, base::nullopt},
{DeepLinkType::kTaskManager, base::nullopt},
{DeepLinkType::kWhatsOnMyScreen, base::nullopt},
{CreateTestCase(DeepLinkType::kChromeSettings), base::nullopt},
{CreateTestCase(DeepLinkType::kFeedback), base::nullopt},
{CreateTestCase(DeepLinkType::kOnboarding), base::nullopt},
{CreateTestCase(DeepLinkType::kQuery), base::nullopt},
{CreateTestCase(DeepLinkType::kScreenshot), base::nullopt},
{CreateTestCase(DeepLinkType::kTaskManager), base::nullopt},
{CreateTestCase(DeepLinkType::kWhatsOnMyScreen), base::nullopt},
// FAIL: Unsupported deep link types.
{DeepLinkType::kUnsupported, base::nullopt}};
{CreateTestCase(DeepLinkType::kUnsupported), base::nullopt}};
for (const auto& test_case : test_cases) {
const base::Optional<GURL>& expected = test_case.second;
const base::Optional<GURL> actual = GetWebUrl(test_case.first);
const base::Optional<GURL> actual = GetWebUrl(
/*type=*/test_case.first.first, /*params=*/test_case.first.second);
// Assert |has_value| equivalence.
ASSERT_EQ(expected, actual);
......
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