chromium/chrome/browser/sync/test/integration/single_client_incoming_password_sharing_invitation_test.cc

// 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.

#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "base/containers/span.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/uuid.h"
#include "build/build_config.h"
#include "chrome/browser/sync/test/integration/encryption_helper.h"
#include "chrome/browser/sync/test/integration/fake_server_match_status_checker.h"
#include "chrome/browser/sync/test/integration/password_sharing_invitation_helper.h"
#include "chrome/browser/sync/test/integration/passwords_helper.h"
#include "chrome/browser/sync/test/integration/single_client_status_change_checker.h"
#include "chrome/browser/sync/test/integration/sync_service_impl_harness.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "components/password_manager/core/browser/features/password_manager_features_util.h"
#include "components/password_manager/core/browser/password_form.h"
#include "components/password_manager/core/browser/password_manager_metrics_util.h"
#include "components/signin/public/base/signin_switches.h"
#include "components/sync/base/data_type.h"
#include "components/sync/engine/nigori/cross_user_sharing_public_key.h"
#include "components/sync/engine/nigori/cross_user_sharing_public_private_key_pair.h"
#include "components/sync/protocol/nigori_specifics.pb.h"
#include "components/sync/protocol/password_sharing_invitation_specifics.pb.h"
#include "components/sync/protocol/sync_entity.pb.h"
#include "components/sync/test/fake_server_nigori_helper.h"
#include "content/public/test/browser_test.h"
#include "testing/gmock/include/gmock/gmock.h"

PasswordForm;
PasswordStoreInterface;
ProcessIncomingPasswordSharingInvitationResult;
CreateDefaultIncomingInvitation;
CreateDefaultSenderDisplayInfo;
CreateEncryptedIncomingInvitationSpecifics;
GetAccountPasswordStoreInterface;
GetAllLogins;
GetProfilePasswordStoreInterface;
EntitySpecifics;
IncomingPasswordSharingInvitationSpecifics;
PasswordSharingInvitationData;
SyncEntity;
SyncServiceImpl;
AllOf;
Contains;
Field;
IsEmpty;
Pointee;
SizeIs;
UnorderedElementsAre;

namespace {

constexpr char kPasswordValue[] =;
constexpr char kUsernameValue[] =;

MATCHER_P(HasPasswordValue, password_value, "") {}

MATCHER_P(HasUsernameElement, username_element, "") {}

IncomingPasswordSharingInvitationSpecifics CreateInvitationSpecifics(
    const sync_pb::CrossUserSharingPublicKey& recipient_public_key) {}

#if !BUILDFLAG(IS_CHROMEOS_ASH)
// Fill in fields in `password_data` required for computing password client tag.
// This is useful for testing collisions. Note that the `invitation` must
// contain only one password in a group.
void FillPasswordClientTagFromInvitation(
    const sync_pb::PasswordSharingInvitationData& invitation_data,
    sync_pb::PasswordSpecificsData* password_data) {}
#endif  // !BUILDFLAG(IS_CHROMEOS_ASH)

// Waits until all the incoming invitations are deleted from the fake server.
class ServerPasswordInvitationChecker
    : public fake_server::FakeServerMatchStatusChecker {};

// Waits for the Incoming Password Sharing Invitation data type to become
// inactive.
class IncomingPasswordSharingInvitationInactiveChecker
    : public SingleClientStatusChangeChecker {};

class SingleClientIncomingPasswordSharingInvitationTest : public SyncTest {};

IN_PROC_BROWSER_TEST_F(SingleClientIncomingPasswordSharingInvitationTest,
                       ShouldStoreIncomingPassword) {}

IN_PROC_BROWSER_TEST_F(SingleClientIncomingPasswordSharingInvitationTest,
                       ShouldStoreIncomingPasswordGroup) {}

IN_PROC_BROWSER_TEST_F(SingleClientIncomingPasswordSharingInvitationTest,
                       ShouldIssueTombstoneAfterProcessingInvitation) {}

// ChromeOS does not support signing out of a primary account, which these test
// relies on to initialize Nigori.
#if !BUILDFLAG(IS_CHROMEOS_ASH)
IN_PROC_BROWSER_TEST_F(SingleClientIncomingPasswordSharingInvitationTest,
                       ShouldHandleIncomingInvitationsAtInitialSync) {}

IN_PROC_BROWSER_TEST_F(
    SingleClientIncomingPasswordSharingInvitationTest,
    ShouldIgnoreIncomingInvitationIfPasswordExistsAtInitialSync) {}
#endif  // !BUILDFLAG(IS_CHROMEOS_ASH)

// The unconsented primary account isn't supported on ChromeOS.
// TODO(crbug.com/358053884): enable on Android once transport mode for
// Passwords is supported.
#if !BUILDFLAG(IS_CHROMEOS_ASH) && !BUILDFLAG(IS_ANDROID)
IN_PROC_BROWSER_TEST_F(SingleClientIncomingPasswordSharingInvitationTest,
                       ShouldStoreIncomingPasswordIntoAccountDB) {}

// This test verifies that Incoming Password Sharing Invitation data type is
// stopped when the Password data type is opted out in the transport mode.
IN_PROC_BROWSER_TEST_F(SingleClientIncomingPasswordSharingInvitationTest,
                       ShouldStopReceivingPasswordsWhenPasswordsOptedOut) {}
#endif  // !BUILDFLAG(IS_CHROMEOS_ASH) && !BUILDFLAG(IS_ANDROID)

// This test verifies that Incoming Password Sharing Invitation data type is
// stopped when the Password data type is encountered error.
IN_PROC_BROWSER_TEST_F(SingleClientIncomingPasswordSharingInvitationTest,
                       ShouldStopIncomingInvitationsOnPasswordsFailure) {}

}  // namespace