1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_TEST_SUPERVISED_USER_FAMILY_LIVE_TEST_H_
#define CHROME_TEST_SUPERVISED_USER_FAMILY_LIVE_TEST_H_
#include <memory>
#include <string>
#include <string_view>
#include "chrome/browser/signin/e2e_tests/live_test.h"
#include "chrome/browser/signin/e2e_tests/signin_util.h"
#include "chrome/test/interaction/interactive_browser_test.h"
#include "chrome/test/supervised_user/browser_user.h"
#include "components/signin/public/identity_manager/test_accounts.h"
#include "components/supervised_user/test_support/family_link_settings_state_management.h"
#include "ui/base/interaction/interaction_sequence.h"
#include "ui/base/interaction/interactive_test_internal.h"
#include "ui/base/interaction/state_observer.h"
#include "url/gurl.h"
namespace supervised_user {
// Refers to the family prefix in resources/signin/test_accounts.json
inline constexpr char kAccountRepositoryPath[] =
"supervised-tests-account-repository-path";
inline constexpr char kFamilyFeatureIdentifierSwitch[] =
"supervised-tests-family-identifier";
// Alternatively, use these two to provide head of household's and child's
// credentials directly, in <username>:<password> syntax (colon separated).
inline constexpr char kHeadOfHouseholdCredentialsSwitch[] =
"supervised-tests-hoh-credentials";
inline constexpr char kChildCredentialsSwitch[] =
"supervised-tests-child-credentials";
// A LiveTest which assumes a specific structure of provided test accounts,
// which are forming a family:
// * head of household,
// * child.
// The family is read from command line switch at kFamilyIdentifierSwitch.
class FamilyLiveTest : public signin::test::LiveTest {
public:
// Determines which user will call the rpc.
enum class RpcMode : int {
// Rpc mode will mimic real life: there will be two browsers, one for a
// supervisor (typically, head of household or parent), and one for
// the supervised user (child).
kProd = 0,
// Rpc mode will take advantage of test backend impersonation feature, where
// the client is only using child account, and the
// server is impersonating the child.
kTestImpersonation = 1,
};
explicit FamilyLiveTest(RpcMode rpc_mode);
// The provided family identifier will be used to select the test accounts.
// Navigation will be allowed to extra hosts.
FamilyLiveTest(FamilyLiveTest::RpcMode rpc_mode,
const std::vector<std::string_view>& extra_enabled_hosts);
~FamilyLiveTest() override;
// Turns on sync for eligible users depending on the ::rpc_mode_
// (see ::TurnOnSyncFor).
void TurnOnSync();
// Turns on sync and waits for the sync subsystem to start. Manages the list
// of open service tabs.
void TurnOnSyncFor(BrowserUser& browser_user);
protected:
void SetUp() override;
void SetUpOnMainThread() override;
void SetUpInProcessBrowserTestFixture() override;
void TearDownOnMainThread() override;
// Creates the GURL from the `url_spec` and ensures that the host part was
// explicitly added to `extra_enabled_hosts`.
GURL GetRoutedUrl(std::string_view url_spec) const;
// Members of the family.
BrowserUser& head_of_household() const;
BrowserUser& child() const;
// Family member that will issue rpc.
BrowserUser& rpc_issuer() const;
private:
// Creates a FamilyMember entity using credentials from TestAccount.
void SetHeadOfHousehold(const test_accounts::FamilyMember& credentials);
void SetChild(const test_accounts::FamilyMember& credentials);
// Extracts requested account from test_accounts.json file, which must exist.
signin::TestAccountSigninCredentials GetAccountFromFile(
std::string_view account_name_suffix) const;
// Creates a new browser signed in to the specified account credentials that
// represent a family member.
std::unique_ptr<BrowserUser> MakeSignedInBrowser(
const test_accounts::FamilyMember& credentials);
// Empty, if rpc_mode_ is kImpersonation.
std::unique_ptr<BrowserUser> head_of_household_;
// Subject of testing.
std::unique_ptr<BrowserUser> child_;
// List of additional hosts that will have host resolution enabled. Host
// resolution is configured as part of test startup.
const std::vector<std::string> extra_enabled_hosts_;
const RpcMode rpc_mode_;
};
std::string ToString(FamilyLiveTest::RpcMode rpc_mode);
// Fixture that combines InProcessBrowserTest with InteractiveBrowserTest,
// adding Family test related utilities.
class InteractiveFamilyLiveTest
: public InteractiveBrowserTestT<FamilyLiveTest> {
public:
// Observes if the browser has reached the intended state.
using InIntendedStateObserver = ui::test::PollingStateObserver<bool>;
explicit InteractiveFamilyLiveTest(FamilyLiveTest::RpcMode rpc_mode);
InteractiveFamilyLiveTest(
FamilyLiveTest::RpcMode rpc_mode,
const std::vector<std::string_view>& extra_enabled_hosts);
protected:
// After completion, supervised user settings are in `state`.
ui::test::internal::InteractiveTestPrivate::MultiStep WaitForStateSeeding(
ui::test::StateIdentifier<InIntendedStateObserver> id,
const BrowserUser& browser_user,
const FamilyLinkSettingsState& state_manager);
};
} // namespace supervised_user
#endif // CHROME_TEST_SUPERVISED_USER_FAMILY_LIVE_TEST_H_
|