Commit 859579de authored by Ramin Halavati's avatar Ramin Halavati Committed by Chromium LUCI CQ

Create Guest profile for signin intercept.

Create and use an ephemeral Guest profile if user has chosen Guest
option in signin intercept.

Bug: 1157764
Change-Id: I9d00b7c06897bcb0ebfd35c36289502acab6ff92
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2611955Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Commit-Queue: Ramin Halavati <rhalavati@chromium.org>
Cr-Commit-Position: refs/heads/master@{#840986}
parent 1f835bd6
......@@ -139,8 +139,15 @@ DiceSignedInProfileCreator::DiceSignedInProfileCreator(
: source_profile_(source_profile),
account_id_(account_id),
callback_(std::move(callback)) {
// TODO(https://crbug.com/2587062): Use |use_guest_profile| param.
DCHECK(!use_guest_profile || Profile::IsEphemeralGuestProfileEnabled());
if (use_guest_profile) {
DCHECK(Profile::IsEphemeralGuestProfileEnabled());
DCHECK(!ProfileManager::GuestProfileExists());
g_browser_process->profile_manager()->CreateProfileAsync(
ProfileManager::GetGuestProfilePath(),
base::BindRepeating(&DiceSignedInProfileCreator::OnNewProfileCreated,
weak_pointer_factory_.GetWeakPtr()),
base::string16(), std::string());
} else {
ProfileAttributesStorage& storage =
g_browser_process->profile_manager()->GetProfileAttributesStorage();
if (!icon_index.has_value())
......@@ -152,6 +159,7 @@ DiceSignedInProfileCreator::DiceSignedInProfileCreator(
name, profiles::GetDefaultAvatarIconUrl(*icon_index),
base::BindRepeating(&DiceSignedInProfileCreator::OnNewProfileCreated,
weak_pointer_factory_.GetWeakPtr()));
}
}
DiceSignedInProfileCreator::DiceSignedInProfileCreator(
......
......@@ -43,6 +43,8 @@ std::unique_ptr<TestingProfile> BuildTestingProfile(const base::FilePath& path,
IdentityTestEnvironmentProfileAdaptor adaptor(profile.get());
adaptor.identity_test_env()->ResetToAccountsNotYetLoadedFromDiskState();
}
if (profile->GetPath() == ProfileManager::GetGuestProfilePath())
profile->SetGuestSession(true);
return profile;
}
......@@ -196,6 +198,10 @@ TEST_P(DiceSignedInProfileCreatorTest, CreateWithTokensLoaded) {
EXPECT_TRUE(IdentityManagerFactory::GetForProfile(signed_in_profile())
->HasAccountWithRefreshToken(account_info.account_id));
// Check profile type
ASSERT_EQ(use_guest_profile(),
signed_in_profile()->IsEphemeralGuestProfile());
// Check the profile name and icon.
ProfileAttributesEntry* entry = nullptr;
ProfileAttributesStorage& storage =
......@@ -203,8 +209,11 @@ TEST_P(DiceSignedInProfileCreatorTest, CreateWithTokensLoaded) {
ASSERT_TRUE(storage.GetProfileAttributesWithPath(
signed_in_profile()->GetPath(), &entry));
ASSERT_TRUE(entry);
ASSERT_EQ(entry->IsGuest(), use_guest_profile());
if (!use_guest_profile()) {
EXPECT_EQ(kProfileTestName16, entry->GetLocalProfileName());
EXPECT_EQ(kTestIcon, entry->GetAvatarIconIndex());
}
}
TEST_P(DiceSignedInProfileCreatorTest, CreateWithTokensNotLoaded) {
......
......@@ -59,6 +59,8 @@ class DiceWebSigninInterceptionBubbleView
BubbleDeclined);
FRIEND_TEST_ALL_PREFIXES(DiceWebSigninInterceptionBubbleBrowserTest,
BubbleAccepted);
FRIEND_TEST_ALL_PREFIXES(DiceWebSigninInterceptionBubbleBrowserTest,
BubbleAcceptedGuestMode);
// Closes the bubble when `ScopedHandle` is destroyed. Does nothing if the
// bubble has been already closed.
......
......@@ -14,6 +14,7 @@
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/toolbar_button_provider.h"
#include "chrome/browser/ui/views/profiles/avatar_toolbar_button.h"
#include "chrome/test/base/testing_profile.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "content/public/test/browser_test.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
......@@ -22,7 +23,10 @@
class DiceWebSigninInterceptionBubbleBrowserTest : public DialogBrowserTest {
public:
DiceWebSigninInterceptionBubbleBrowserTest() = default;
DiceWebSigninInterceptionBubbleBrowserTest() {
TestingProfile::SetScopedFeatureListForEphemeralGuestProfiles(
scoped_feature_list_, /*enabled=*/true);
}
// DialogBrowserTest:
void ShowUi(const std::string& name) override {
......@@ -59,6 +63,7 @@ class DiceWebSigninInterceptionBubbleBrowserTest : public DialogBrowserTest {
account, primary_account};
}
base::test::ScopedFeatureList scoped_feature_list_;
base::Optional<SigninInterceptionResult> callback_result_;
std::unique_ptr<ScopedDiceWebSigninInterceptionBubbleHandle> bubble_handle_;
};
......@@ -170,5 +175,50 @@ IN_PROC_BROWSER_TEST_F(DiceWebSigninInterceptionBubbleBrowserTest,
histogram_tester.ExpectTotalCount("Signin.InterceptResult.Switch", 0);
}
// TODO(https://crbug.com/1157764): Add Test for Bubble Guest selection when
// functionality is supported.
// Tests that the callback is called once when the bubble is accepted with Guest
// mode offer. The bubble is not destroyed until a new browser window is
// created.
IN_PROC_BROWSER_TEST_F(DiceWebSigninInterceptionBubbleBrowserTest,
BubbleAcceptedGuestMode) {
if (!Profile::IsEphemeralGuestProfileEnabled())
return;
base::HistogramTester histogram_tester;
// `bubble` is owned by the view hierarchy.
DiceWebSigninInterceptionBubbleView* bubble =
new DiceWebSigninInterceptionBubbleView(
browser()->profile(), GetAvatarButton(), GetTestBubbleParameters(),
base::BindOnce(&DiceWebSigninInterceptionBubbleBrowserTest::
OnInterceptionComplete,
base::Unretained(this)));
views::Widget* widget = views::BubbleDialogDelegateView::CreateBubble(bubble);
widget->Show();
EXPECT_FALSE(callback_result_.has_value());
// Take a handle on the bubble, to close it later.
bubble_handle_ = bubble->GetHandle();
views::test::WidgetClosingObserver closing_observer(widget);
EXPECT_FALSE(bubble->HasAccepted());
// Simulate clicking Guest in the WebUI.
bubble->OnWebUIUserChoice(SigninInterceptionUserChoice::kGuest);
ASSERT_TRUE(callback_result_.has_value());
EXPECT_EQ(callback_result_, SigninInterceptionResult::kAcceptedWithGuest);
EXPECT_TRUE(bubble->HasAccepted());
// Widget was not closed yet.
ASSERT_FALSE(closing_observer.widget_closed());
// Simulate completion of the interception process.
bubble_handle_.reset();
// Widget will close now.
closing_observer.Wait();
// Check that histograms are recorded.
histogram_tester.ExpectUniqueSample(
"Signin.InterceptResult.MultiUser",
SigninInterceptionResult::kAcceptedWithGuest, 1);
histogram_tester.ExpectUniqueSample(
"Signin.InterceptResult.MultiUser.NoSync",
SigninInterceptionResult::kAcceptedWithGuest, 1);
histogram_tester.ExpectTotalCount("Signin.InterceptResult.Enterprise", 0);
histogram_tester.ExpectTotalCount("Signin.InterceptResult.Switch", 0);
}
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