Commit 5d942d36 authored by Ramin Halavati's avatar Ramin Halavati Committed by Commit Bot

Update Ambient Authentication browser tests for ephemeral Guest profiles.

Ambient Authentication browser tests are updated to cover both current
and ephemeral Guest profiles.

Please see go/ephemeral-guest-profiles for more context.

Bug: 1125474
Change-Id: I76a6e4ec9de4dd079377ed3d01a68cfdc3fe6cb2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2488563Reviewed-by: default avatarAsanka Herath <asanka@chromium.org>
Commit-Queue: Ramin Halavati <rhalavati@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819382}
parent d71bdfff
......@@ -39,6 +39,7 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/metrics/content/subprocess_metrics_provider.h"
#include "components/policy/core/common/policy_map.h"
......@@ -287,9 +288,13 @@ IN_PROC_BROWSER_TEST_F(ProfileNetworkContextServiceCacheChangeBrowsertest,
"None scoped_feature_list_trial_group None");
}
class AmbientAuthenticationTestWithPolicy : public policy::PolicyTest {
class AmbientAuthenticationTestWithPolicy
: public policy::PolicyTest,
public ::testing::WithParamInterface<bool> {
public:
AmbientAuthenticationTestWithPolicy() {
TestingProfile::SetScopedFeatureListForEphemeralGuestProfiles(
scoped_feature_list_, GetParam());
policy::PolicyTest::SetUpInProcessBrowserTestFixture();
}
......@@ -316,7 +321,7 @@ class AmbientAuthenticationTestWithPolicy : public policy::PolicyTest {
#if !defined(OS_CHROMEOS)
EXPECT_EQ(
AmbientAuthenticationTestHelper::IsAmbientAuthAllowedForProfile(
AmbientAuthenticationTestHelper::GetGuestProfile()),
CreateGuestBrowser()->profile()),
AmbientAuthenticationTestHelper::IsGuestAllowedInPolicy(policy_value));
#endif
}
......@@ -330,30 +335,35 @@ class AmbientAuthenticationTestWithPolicy : public policy::PolicyTest {
private:
policy::PolicyMap policies_;
base::test::ScopedFeatureList scoped_feature_list_;
};
IN_PROC_BROWSER_TEST_F(AmbientAuthenticationTestWithPolicy, RegularOnly) {
IN_PROC_BROWSER_TEST_P(AmbientAuthenticationTestWithPolicy, RegularOnly) {
EnablePolicyWithValue(net::AmbientAuthAllowedProfileTypes::REGULAR_ONLY);
IsAmbientAuthAllowedForProfilesTest();
}
IN_PROC_BROWSER_TEST_F(AmbientAuthenticationTestWithPolicy,
IN_PROC_BROWSER_TEST_P(AmbientAuthenticationTestWithPolicy,
IncognitoAndRegular) {
EnablePolicyWithValue(
net::AmbientAuthAllowedProfileTypes::INCOGNITO_AND_REGULAR);
IsAmbientAuthAllowedForProfilesTest();
}
IN_PROC_BROWSER_TEST_F(AmbientAuthenticationTestWithPolicy, GuestAndRegular) {
IN_PROC_BROWSER_TEST_P(AmbientAuthenticationTestWithPolicy, GuestAndRegular) {
EnablePolicyWithValue(net::AmbientAuthAllowedProfileTypes::GUEST_AND_REGULAR);
IsAmbientAuthAllowedForProfilesTest();
}
IN_PROC_BROWSER_TEST_F(AmbientAuthenticationTestWithPolicy, All) {
IN_PROC_BROWSER_TEST_P(AmbientAuthenticationTestWithPolicy, All) {
EnablePolicyWithValue(net::AmbientAuthAllowedProfileTypes::ALL);
IsAmbientAuthAllowedForProfilesTest();
}
INSTANTIATE_TEST_SUITE_P(All,
AmbientAuthenticationTestWithPolicy,
/*ephemeral_guest_profile_enabled=*/testing::Bool());
// Test subclass that adds switches::kDiskCacheDir and switches::kDiskCacheSize
// to the command line, to make sure they're respected.
class ProfileNetworkContextServiceDiskCacheBrowsertest
......
......@@ -32,11 +32,6 @@ bool AmbientAuthenticationTestHelper::IsGuestAllowedInPolicy(int policy_value) {
return policy_value & static_cast<int>(AmbientAuthProfileBit::GUEST);
}
Profile* AmbientAuthenticationTestHelper::GetGuestProfile() {
Profile* guest_profile = OpenGuestBrowser()->profile();
return guest_profile;
}
bool AmbientAuthenticationTestHelper::IsAmbientAuthAllowedForProfile(
Profile* profile) {
ProfileNetworkContextService* profile_network_context_service =
......@@ -51,33 +46,3 @@ bool AmbientAuthenticationTestHelper::IsAmbientAuthAllowedForProfile(
->allow_default_credentials ==
net::HttpAuthPreferences::ALLOW_DEFAULT_CREDENTIALS;
}
// OpenGuestBrowser method code borrowed from
// chrome/browser/profiles/profile_window_browsertest.cc
Browser* AmbientAuthenticationTestHelper::OpenGuestBrowser() {
size_t num_browsers = BrowserList::GetInstance()->size();
// Create a guest browser nicely. Using CreateProfile() and CreateBrowser()
// does incomplete initialization that would lead to
// SystemUrlRequestContextGetter being leaked.
profiles::SwitchToGuestProfile(ProfileManager::CreateCallback());
ui_test_utils::WaitForBrowserToOpen();
DCHECK_NE(static_cast<Profile*>(nullptr),
g_browser_process->profile_manager()->GetProfileByPath(
ProfileManager::GetGuestProfilePath()));
EXPECT_EQ(num_browsers + 1, BrowserList::GetInstance()->size());
Profile* guest = g_browser_process->profile_manager()->GetProfileByPath(
ProfileManager::GetGuestProfilePath());
Browser* browser = chrome::FindAnyBrowser(guest, true);
EXPECT_TRUE(browser);
// When |browser| closes a BrowsingDataRemover will be created and executed.
// It needs a loaded TemplateUrlService or else it hangs on to a
// CallbackList::Subscription forever.
search_test_utils::WaitForTemplateURLServiceToLoad(
TemplateURLServiceFactory::GetForProfile(guest));
return browser;
}
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