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

Web Share for Chrome OS: Allow file sharing in guest mode

In guest mode, shared files in the .WebShare/ directory are deleted
when the user logs off (if they are not deleted earlier).

In incognito mode, we continue to prevent file sharing.

Bug: 1161373
Change-Id: I0542d4ba92381c7ab2f07bbab896242bcc643057
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2626991
Commit-Queue: Glen Robertson <glenrob@chromium.org>
Reviewed-by: default avatarGlen Robertson <glenrob@chromium.org>
Auto-Submit: Eric Willigers <ericwilligers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843298}
parent 184e26ea
...@@ -102,7 +102,7 @@ void SharesheetClient::Share( ...@@ -102,7 +102,7 @@ void SharesheetClient::Share(
// To prevent sites from using that to detect whether incognito mode is // To prevent sites from using that to detect whether incognito mode is
// active, we deny after a random time delay, to simulate a user cancelling // active, we deny after a random time delay, to simulate a user cancelling
// the share. // the share.
if (profile->IsOffTheRecord() && !files.empty()) { if (profile->IsIncognitoProfile() && !files.empty()) {
// Random number of seconds in the range [1.0, 2.0). // Random number of seconds in the range [1.0, 2.0).
double delay_seconds = 1.0 + 1.0 * base::RandDouble(); double delay_seconds = 1.0 + 1.0 * base::RandDouble();
VisibilityTimerTabHelper::CreateForWebContents(web_contents()); VisibilityTimerTabHelper::CreateForWebContents(web_contents());
......
...@@ -35,13 +35,26 @@ class SharesheetClientUnitTest : public ChromeRenderViewHostTestHarness { ...@@ -35,13 +35,26 @@ class SharesheetClientUnitTest : public ChromeRenderViewHostTestHarness {
void SetUp() override { void SetUp() override {
ChromeRenderViewHostTestHarness::SetUp(); ChromeRenderViewHostTestHarness::SetUp();
StoreFileTask::SkipCopyingForTesting();
SharesheetClient::SetSharesheetCallbackForTesting( SharesheetClient::SetSharesheetCallbackForTesting(
base::BindRepeating(&SharesheetClientUnitTest::AcceptShareRequest)); base::BindRepeating(&SharesheetClientUnitTest::AcceptShareRequest));
} }
void SetIncognito() { void SetGuest() {
Profile* const otr_profile = profile()->GetOffTheRecordProfile( Profile* const otr_profile = profile()->GetOffTheRecordProfile(
Profile::OTRProfileID("Test::SharesheetClient")); Profile::OTRProfileID("Test::SharesheetClient"));
EXPECT_TRUE(otr_profile->IsOffTheRecord());
EXPECT_FALSE(otr_profile->IsIncognitoProfile());
scoped_refptr<content::SiteInstance> instance =
content::SiteInstance::Create(otr_profile);
SetContents(content::WebContentsTester::CreateTestWebContents(
otr_profile, std::move(instance)));
}
void SetIncognito() {
Profile* const otr_profile = profile()->GetPrimaryOTRProfile();
EXPECT_TRUE(otr_profile->IsOffTheRecord());
EXPECT_TRUE(otr_profile->IsIncognitoProfile());
scoped_refptr<content::SiteInstance> instance = scoped_refptr<content::SiteInstance> instance =
content::SiteInstance::Create(otr_profile); content::SiteInstance::Create(otr_profile);
SetContents(content::WebContentsTester::CreateTestWebContents( SetContents(content::WebContentsTester::CreateTestWebContents(
...@@ -108,6 +121,7 @@ TEST_F(SharesheetClientUnitTest, TestWithoutFilesInIncognito) { ...@@ -108,6 +121,7 @@ TEST_F(SharesheetClientUnitTest, TestWithoutFilesInIncognito) {
} }
TEST_F(SharesheetClientUnitTest, DeleteAfterShare) { TEST_F(SharesheetClientUnitTest, DeleteAfterShare) {
SetGuest();
SharesheetClient sharesheet_client(web_contents()); SharesheetClient sharesheet_client(web_contents());
const base::FilePath my_files = const base::FilePath my_files =
file_manager::util::GetMyFilesFolderForProfile(profile()); file_manager::util::GetMyFilesFolderForProfile(profile());
...@@ -127,7 +141,6 @@ TEST_F(SharesheetClientUnitTest, DeleteAfterShare) { ...@@ -127,7 +141,6 @@ TEST_F(SharesheetClientUnitTest, DeleteAfterShare) {
base::RunLoop run_loop; base::RunLoop run_loop;
blink::mojom::ShareError error = blink::mojom::ShareError::INTERNAL_ERROR; blink::mojom::ShareError error = blink::mojom::ShareError::INTERNAL_ERROR;
StoreFileTask::SkipCopyingForTesting();
sharesheet_client.Share( sharesheet_client.Share(
title, text, share_url, std::move(files), title, text, share_url, std::move(files),
base::BindLambdaForTesting( base::BindLambdaForTesting(
......
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