chromium/chrome/browser/sync/test/integration/encryption_helper.h

// Copyright 2018 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_BROWSER_SYNC_TEST_INTEGRATION_ENCRYPTION_HELPER_H_
#define CHROME_BROWSER_SYNC_TEST_INTEGRATION_ENCRYPTION_HELPER_H_

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

#include "base/memory/raw_ptr.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/sync/test/integration/fake_server_match_status_checker.h"
#include "chrome/browser/sync/test/integration/single_client_status_change_checker.h"
#include "chrome/browser/sync/test/integration/status_change_checker.h"
#include "components/sync/base/passphrase_enums.h"
#include "components/sync/test/fake_server.h"
#include "components/trusted_vault/trusted_vault_client.h"
#include "net/test/embedded_test_server/embedded_test_server.h"

namespace encryption_helper {

// Setups `test_server` in a way it will redirect from trusted vault URLs (key
// retrieval URL and degraded recoverability URL) to fake pages. These pages
// will populate parameters (`trusted_vault_key` and its version in case of key
// retrieval, `recovery_method_public_key` in case of degraded recoverability)
// to Chrome upon loading and will close themselves automatically.
// Must be called before `test_server` starts to accept connections.
// `test_server` must not be null.
void SetupFakeTrustedVaultPages(
    const std::string& gaia_id,
    const std::vector<uint8_t>& trusted_vault_key,
    int trusted_vault_key_version,
    const std::vector<uint8_t>& recovery_method_public_key,
    net::test_server::EmbeddedTestServer* test_server);

}  // namespace encryption_helper

// Checker used to block until a Nigori with a given passphrase type is
// available on the server.
class ServerPassphraseTypeChecker
    : public fake_server::FakeServerMatchStatusChecker {};

// Checker used to block until a Nigori populated with a new public key
// available on the server. If the previous public key value is not provided,
// waits for a non-empty public key.
class ServerCrossUserSharingPublicKeyChangedChecker
    : public fake_server::FakeServerMatchStatusChecker {};

// Checker used to block until a Nigori with a given keybag encryption key name
// is available on the server.
class ServerNigoriKeyNameChecker
    : public fake_server::FakeServerMatchStatusChecker {};

// Checker to block until service is waiting for a passphrase.
class PassphraseRequiredChecker : public SingleClientStatusChangeChecker {};

// Checker to block until service has accepted a new passphrase.
class PassphraseAcceptedChecker : public SingleClientStatusChangeChecker {};

// Checker to block until service has finished setting up a given passphrase
// type.
class PassphraseTypeChecker : public SingleClientStatusChangeChecker {};

// Checker used to block until Sync requires or stops requiring trusted vault
// keys.
class TrustedVaultKeyRequiredStateChecker
    : public SingleClientStatusChangeChecker {};

// Checker used to block until trusted vault keys are changed.
class TrustedVaultKeysChangedStateChecker
    : public StatusChangeChecker,
      trusted_vault::TrustedVaultClient::Observer {};

// Used to wait until IsTrustedVaultRecoverabilityDegraded() returns the desired
// value.
class TrustedVaultRecoverabilityDegradedStateChecker
    : public SingleClientStatusChangeChecker {};

#endif  // CHROME_BROWSER_SYNC_TEST_INTEGRATION_ENCRYPTION_HELPER_H_