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

Web Share Target for Chrome OS: Register all share targets

We previously only registered share targets that received files.

Test uses web_share_target/poster.html, a web app added in
https://chromium-review.googlesource.com/c/chromium/src/+/2584625


Bug: 1125880
Change-Id: Iee54e946a26128b72c2c86df47e58768ca917c63
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2584430
Auto-Submit: Eric Willigers <ericwilligers@chromium.org>
Reviewed-by: default avatarNancy Wang <nancylingwang@chromium.org>
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836913}
parent d1361435
...@@ -586,13 +586,6 @@ void PopulateIntentFilters(const web_app::WebApp& web_app, ...@@ -586,13 +586,6 @@ void PopulateIntentFilters(const web_app::WebApp& web_app,
const apps::ShareTarget& share_target = web_app.share_target().value(); const apps::ShareTarget& share_target = web_app.share_target().value();
// TODO(crbug.com/1127670): Support title/text/url sharing on ChromeOS
if (share_target.params.files.empty() ||
share_target.method != apps::ShareTarget::Method::kPost ||
share_target.enctype != apps::ShareTarget::Enctype::kMultipartFormData) {
return;
}
std::vector<std::string> content_types; std::vector<std::string> content_types;
for (const auto& files_entry : share_target.params.files) { for (const auto& files_entry : share_target.params.files) {
for (const auto& file_type : files_entry.accept) { for (const auto& file_type : files_entry.accept) {
...@@ -606,9 +599,6 @@ void PopulateIntentFilters(const web_app::WebApp& web_app, ...@@ -606,9 +599,6 @@ void PopulateIntentFilters(const web_app::WebApp& web_app,
} }
} }
if (content_types.empty())
return;
const std::vector<std::string> intent_actions( const std::vector<std::string> intent_actions(
{apps_util::kIntentActionSend, apps_util::kIntentActionSendMultiple}); {apps_util::kIntentActionSend, apps_util::kIntentActionSendMultiple});
target.push_back(CreateShareFileFilter(intent_actions, content_types)); target.push_back(CreateShareFileFilter(intent_actions, content_types));
......
...@@ -98,7 +98,7 @@ void CheckShareFileFilter(const apps::mojom::IntentFilterPtr& intent_filter, ...@@ -98,7 +98,7 @@ void CheckShareFileFilter(const apps::mojom::IntentFilterPtr& intent_filter,
EXPECT_FALSE(intent_filter->activity_name.has_value()); EXPECT_FALSE(intent_filter->activity_name.has_value());
EXPECT_FALSE(intent_filter->activity_label.has_value()); EXPECT_FALSE(intent_filter->activity_label.has_value());
EXPECT_EQ(intent_filter->conditions.size(), 2U); EXPECT_EQ(intent_filter->conditions.size(), filter_types.empty() ? 1U : 2U);
{ {
const Condition& condition = *intent_filter->conditions[0]; const Condition& condition = *intent_filter->conditions[0];
...@@ -114,7 +114,7 @@ void CheckShareFileFilter(const apps::mojom::IntentFilterPtr& intent_filter, ...@@ -114,7 +114,7 @@ void CheckShareFileFilter(const apps::mojom::IntentFilterPtr& intent_filter,
EXPECT_EQ(condition.condition_values[1]->value, "send_multiple"); EXPECT_EQ(condition.condition_values[1]->value, "send_multiple");
} }
{ if (!filter_types.empty()) {
const Condition& condition = *intent_filter->conditions[1]; const Condition& condition = *intent_filter->conditions[1];
EXPECT_EQ(condition.condition_type, ConditionType::kMimeType); EXPECT_EQ(condition.condition_type, ConditionType::kMimeType);
EXPECT_EQ(condition.condition_values.size(), filter_types.size()); EXPECT_EQ(condition.condition_values.size(), filter_types.size());
...@@ -227,6 +227,35 @@ IN_PROC_BROWSER_TEST_F(WebAppsBaseBrowserTest, PartialWild) { ...@@ -227,6 +227,35 @@ IN_PROC_BROWSER_TEST_F(WebAppsBaseBrowserTest, PartialWild) {
CheckShareFileFilter(target[1], filter_types, accepted_types, rejected_types); CheckShareFileFilter(target[1], filter_types, accepted_types, rejected_types);
} }
IN_PROC_BROWSER_TEST_F(WebAppsBaseBrowserTest, ShareTargetWithoutFiles) {
ASSERT_TRUE(embedded_test_server()->Start());
const GURL app_url(
embedded_test_server()->GetURL("/web_share_target/poster.html"));
std::vector<mojom::IntentFilterPtr> target;
{
const web_app::WebAppRegistrar* registrar =
web_app::WebAppProvider::Get(browser()->profile())
->registrar()
.AsWebAppRegistrar();
const web_app::AppId app_id =
web_app::InstallWebAppFromManifest(browser(), app_url);
const web_app::WebApp* web_app = registrar->GetAppById(app_id);
ASSERT_TRUE(web_app);
PopulateIntentFilters(*web_app, target);
}
EXPECT_EQ(target.size(), 2U);
CheckUrlScopeFilter(target[0], app_url.GetWithoutFilename(),
/*different_url=*/GURL("file:///"));
const std::vector<std::string> filter_types; // No types are filtered.
const std::vector<std::string> accepted_types({"audio/mp3"});
const std::vector<std::string> rejected_types; // No types are rejected.
CheckShareFileFilter(target[1], filter_types, accepted_types, rejected_types);
}
IN_PROC_BROWSER_TEST_F(WebAppsBaseBrowserTest, LaunchWithIntent) { IN_PROC_BROWSER_TEST_F(WebAppsBaseBrowserTest, LaunchWithIntent) {
ASSERT_TRUE(embedded_test_server()->Start()); ASSERT_TRUE(embedded_test_server()->Start());
const GURL app_url( const GURL app_url(
...@@ -262,6 +291,42 @@ IN_PROC_BROWSER_TEST_F(WebAppsBaseBrowserTest, LaunchWithIntent) { ...@@ -262,6 +291,42 @@ IN_PROC_BROWSER_TEST_F(WebAppsBaseBrowserTest, LaunchWithIntent) {
run_loop.Run(); run_loop.Run();
} }
IN_PROC_BROWSER_TEST_F(WebAppsBaseBrowserTest, IntentWithoutFiles) {
ASSERT_TRUE(embedded_test_server()->Start());
const GURL app_url(
embedded_test_server()->GetURL("/web_share_target/poster.html"));
Profile* const profile = browser()->profile();
const web_app::AppId app_id =
web_app::InstallWebAppFromManifest(browser(), app_url);
base::RunLoop run_loop;
web_app::WebAppLaunchManager::SetOpenApplicationCallbackForTesting(
base::BindLambdaForTesting(
[&run_loop](apps::AppLaunchParams&& params) -> content::WebContents* {
EXPECT_EQ(*params.intent->action,
apps_util::kIntentActionSendMultiple);
EXPECT_EQ(*params.intent->mime_type, "*/*");
EXPECT_EQ(params.intent->file_urls->size(), 0U);
run_loop.Quit();
return nullptr;
}));
apps::mojom::IntentPtr intent = apps_util::CreateShareIntentFromFiles(
profile, /*file_paths=*/std::vector<base::FilePath>(),
/*mime_types=*/std::vector<std::string>(),
/*share_text=*/"Message",
/*share_title=*/"Subject");
const int32_t event_flags =
apps::GetEventFlags(apps::mojom::LaunchContainer::kLaunchContainerWindow,
WindowOpenDisposition::NEW_WINDOW,
/*prefer_container=*/true);
apps::AppServiceProxyFactory::GetForProfile(profile)->LaunchAppWithIntent(
app_id, event_flags, std::move(intent),
apps::mojom::LaunchSource::kFromSharesheet, display::kDefaultDisplayId);
run_loop.Run();
}
IN_PROC_BROWSER_TEST_F(WebAppsBaseBrowserTest, ExposeAppServicePublisherId) { IN_PROC_BROWSER_TEST_F(WebAppsBaseBrowserTest, ExposeAppServicePublisherId) {
ASSERT_TRUE(embedded_test_server()->Start()); ASSERT_TRUE(embedded_test_server()->Start());
const GURL app_url(embedded_test_server()->GetURL("/web_apps/basic.html")); const GURL app_url(embedded_test_server()->GetURL("/web_apps/basic.html"));
......
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