Commit 94716b9e authored by Eric Willigers's avatar Eric Willigers Committed by Chromium LUCI CQ

[IntentHandling] Omit empty title or text

apps_util::CreateShareIntentFromFiles now omits title or
text strings from the intent, if the supplied string are
empty.

Bug: 1127670
Change-Id: Ic62b1e80299ad2cfe067132e7e852fb34b8c6e26
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2569324Reviewed-by: default avatarNancy Wang <nancylingwang@chromium.org>
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833143}
parent 035e8a63
......@@ -159,8 +159,10 @@ apps::mojom::IntentPtr CreateShareIntentFromFiles(
const std::string& share_text,
const std::string& share_title) {
auto intent = CreateShareIntentFromFiles(filesystem_urls, mime_types);
intent->share_text = share_text;
intent->share_title = share_title;
if (!share_text.empty())
intent->share_text = share_text;
if (!share_title.empty())
intent->share_title = share_title;
return intent;
}
......
......@@ -359,3 +359,36 @@ TEST_F(IntentUtilTest, CommonMimeTypeMatch) {
EXPECT_FALSE(apps_util::IntentMatchesFilter(intent, filter_sub_wildcard));
EXPECT_TRUE(apps_util::IntentMatchesFilter(intent, filter_all_wildcard));
}
TEST_F(IntentUtilTest, FileWithTitleText) {
const std::string mime_type = "image/jpeg";
auto filter = apps_util::CreateIntentFilterForSend(mime_type);
const std::vector<GURL> urls{GURL("abc")};
const std::vector<std::string> mime_types{mime_type};
auto intent =
apps_util::CreateShareIntentFromFiles(urls, mime_types, "text", "title");
EXPECT_TRUE(intent->share_text.has_value());
EXPECT_EQ(intent->share_text.value(), "text");
EXPECT_TRUE(intent->share_title.has_value());
EXPECT_EQ(intent->share_title.value(), "title");
EXPECT_TRUE(apps_util::IntentMatchesFilter(intent, filter));
intent = apps_util::CreateShareIntentFromFiles(urls, mime_types, "text", "");
EXPECT_TRUE(intent->share_text.has_value());
EXPECT_EQ(intent->share_text.value(), "text");
EXPECT_FALSE(intent->share_title.has_value());
EXPECT_TRUE(apps_util::IntentMatchesFilter(intent, filter));
intent = apps_util::CreateShareIntentFromFiles(urls, mime_types, "", "title");
EXPECT_FALSE(intent->share_text.has_value());
EXPECT_TRUE(intent->share_title.has_value());
EXPECT_EQ(intent->share_title.value(), "title");
EXPECT_TRUE(apps_util::IntentMatchesFilter(intent, filter));
intent = apps_util::CreateShareIntentFromFiles(urls, mime_types, "", "");
EXPECT_FALSE(intent->share_text.has_value());
EXPECT_FALSE(intent->share_title.has_value());
EXPECT_TRUE(apps_util::IntentMatchesFilter(intent, filter));
}
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