chromium/components/origin_trials/browser/origin_trials_unittest.cc

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/origin_trials/browser/origin_trials.h"

#include <memory>
#include <string_view>
#include <utility>
#include <vector>

#include "base/containers/flat_set.h"
#include "base/memory/scoped_refptr.h"
#include "base/time/time.h"
#include "components/origin_trials/common/persisted_trial_token.h"
#include "components/origin_trials/test/test_persistence_provider.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/origin_trials/scoped_test_origin_trial_policy.h"
#include "third_party/blink/public/common/origin_trials/trial_token_validator.h"
#include "third_party/blink/public/mojom/origin_trial_feature/origin_trial_feature.mojom-shared.h"
#include "url/gurl.h"
#include "url/origin.h"

namespace origin_trials {
namespace {

OriginTrialFeature;

const char kPersistentTrialName[] =;
const char kPersistentThirdPartyDeprecationTrialName[] =;
const char kNonPersistentTrialName[] =;
const char kInvalidTrialName[] =;
const char kTrialEnabledOriginA[] =;
const char kTrialEnabledOriginASubdomain[] =;
const char kTrialEnabledOriginASubdomainAlt[] =;
const char kTrialEnabledOriginB[] =;
const char kThirdPartyTrialEnabledOrigin[] =;
const char kThirdPartyTrialEnabledOriginSubdomain[] =;
const char kThirdPartyTrialEnabledOriginSubdomainAlt[] =;

// A dummy value that hasn't been explicitly disabled
const char kDummyTokenSignature[] =;

const base::Time kValidTime =;
const base::Time kExpiryTime =;

// Valid header token for FrobulatePersistent
// generated with
// tools/origin_trials/generate_token.py enabled.example.com FrobulatePersistent
// --expire-timestamp=2000000000
const char kFrobulatePersistentToken[] =;

// Valid subdomain matching header token for FrobulatePersistent
// generated with
// tools/origin_trials/generate_token.py enabled.example.com FrobulatePersistent
// --expire-timestamp=2000000000 --is-subdomain
const char kFrobulatePersistentSubdomainToken[] =;

// Valid header token for FrobulatePersistent
// generated with
// tools/origin_trials/generate_token.py enabled.alternate.com
// FrobulatePersistent
// --expire-timestamp=2000000000
const char kFrobulatePersistentTokenAlternate[] =;

// Valid header token for Frobulate
// generated with
// tools/origin_trials/generate_token.py enabled.example.com Frobulate
// --expire-timestamp=2000000000
const char kFrobulateToken[] =;

// Valid header token for Frobulate
// generated with
// tools/origin_trials/generate_token.py enabled.example.com
// FrobulateManualCompletion
// --expire-timestamp=2000000000
const char kFrobulateManualCompletionToken[] =;

// Valid header token for FrobulatePersistentExpiryGracePeriod
// generated with
// tools/origin_trials/generate_token.py enabled.example.com
// FrobulatePersistentExpiryGracePeriod
// --expire-timestamp=2000000000
const char kFrobulatePersistentExpiryGracePeriodToken[] =;

// Valid third-party token for FrobulatePersistent
// generated with
// tools/origin_trials/generate_token.py enabled.thirdparty.com
// FrobulatePersistent --expire-timestamp=2000000000 --is-third-party
const char kFrobulatePersistentThirdPartyToken[] =;

// Valid header token for FrobulatePersistentThirdPartyDeprecation
// generated with
// tools/origin_trials/generate_token.py enabled.example.com
// FrobulatePersistentThirdPartyDeprecation --expire-timestamp=2000000000
// --is-subdomain
const char kFrobulatePersistentThirdPartyDeprecationSubdomainToken[] =;

// Valid third-party token for FrobulatePersistentThirdPartyDeprecation
// generated with
// tools/origin_trials/generate_token.py enabled.thirdparty.com
// FrobulatePersistentThirdPartyDeprecation --expire-timestamp=2000000000
// --is-third-party
const char kFrobulatePersistentThirdPartyDeprecationThirdPartyToken[] =;

// Valid subdomain matching third-party token for
// FrobulatePersistentThirdPartyDeprecation
// generated with
// tools/origin_trials/generate_token.py enabled.thirdparty.com
// FrobulatePersistentThirdPartyDeprecation --expire-timestamp=2000000000
// --is-subdomain --is-third-party
const char kFrobulatePersistentThirdPartyDeprecationSubdomainThirdPartyToken[] =;

const char kFrobulatePersistentInvalidOsToken[] =;

const ukm::SourceId kFakeSourceId1 =;
const ukm::SourceId kFakeSourceId2 =;

class OpenScopedTestOriginTrialPolicy
    : public blink::ScopedTestOriginTrialPolicy {};

class TestStatusObserver
    : public content::OriginTrialsControllerDelegate::Observer {};

}  // namespace

class OriginTrialsTest : public testing::Test {};

TEST_F(OriginTrialsTest, CleanObjectHasNoPersistentTrials) {}

TEST_F(OriginTrialsTest, EnabledTrialsArePersisted) {}

TEST_F(OriginTrialsTest, OnlyPersistentTrialsAreEnabled) {}

TEST_F(OriginTrialsTest, ResetClearsPersistedTrials) {}

TEST_F(OriginTrialsTest, TrialNotEnabledByDefault) {}

TEST_F(OriginTrialsTest, TrialEnablesFeature) {}

TEST_F(OriginTrialsTest, TrialDoesNotEnableOtherFeatures) {}

TEST_F(OriginTrialsTest, TrialIsNotEnabledOrPersistedOnInvalidOs) {}

TEST_F(OriginTrialsTest, TokensCanBeAppended) {}

TEST_F(OriginTrialsTest, ThirdPartyTokensCanBeAppendedOnlyIfDeprecation) {}

TEST_F(OriginTrialsTest, SubdomainTokensEnableTrialForSubdomainsOfTokenOrigin) {}

TEST_F(OriginTrialsTest,
       TrialNotEnabledForNonSubdomainsOfSubdomainTokenOrigin) {}

// Verifies that the trial is enabled for the token origin when a
// subdomain-matching token is provided by a subdomain of the token origin.
TEST_F(OriginTrialsTest, SubdomainTokensEnableTrialForTokenOrigin) {}

TEST_F(OriginTrialsTest,
       ThirdPartySubdomainTokensEnableTrialForSubdomainsOfTokenOrigin) {}

// Verifies that a subdomain-matching header token being provided by a subdomain
// of the token origin appends the token for the token origin (instead of
// overwriting).
TEST_F(OriginTrialsTest,
       SubdomainTokensProvidedBySubdomainsAppendForTokenOrigin) {}

// Checks that when a trial is enabled using a subdomain-matching token, the
// trial is not disabled by subdomains of the token origin, even if the
// subdomain provided the token.
TEST_F(OriginTrialsTest, SubdomainTokenNotDisabledBySubdomain) {}

// Checks that when a trial is enabled using a subdomain-matching token, the
// trial is disabled if the origin that's stored in the token is loaded without
// it.
TEST_F(OriginTrialsTest, SubdomainTokenDisabledByTokenOrigin) {}

// Check that a stored trial name is not returned if that trial is no longer
// valid or configured to be persistent
TEST_F(OriginTrialsTest, StoredEnabledTrialNotReturnedIfNoLongerPersistent) {}

TEST_F(OriginTrialsTest, StatusObserverIsAdded) {}

TEST_F(OriginTrialsTest, StatusObserverIsRemoved) {}

TEST_F(OriginTrialsTest, NotifyOnEnable) {}

TEST_F(OriginTrialsTest, NotifyOnEnableWithSubdomainMatching) {}

TEST_F(OriginTrialsTest, NotifyOnDisable) {}

TEST_F(OriginTrialsTest, NotifyOnDisableWithSubdomainMatching) {}

// Verifies that the origin stored in a subdomain-matching token is provided in
// the notification when one of its subdomain uses the token to enable a trial.
TEST_F(OriginTrialsTest, NotifyUsingTokenOriginOnEnable) {}

TEST_F(OriginTrialsTest, DontNotifyOnDisableIfNotPreviouslyEnabled) {}

TEST_F(OriginTrialsTest, NotifyOnEnabledOnlyIfPreviouslyDisabled) {}

TEST_F(OriginTrialsTest, NotifyOnStatusChangeMultiplePartitionSites) {}

// Check that observers are only notified of status change events for the trial
// corresponding to their `trial_name` value.
TEST_F(OriginTrialsTest, NotifyForCorrectTrial) {}

TEST_F(OriginTrialsTest, NotifyWithTokenOriginForSubdomainTokens) {}

TEST_F(OriginTrialsTest, NotifyOnPersistedTokensCleared) {}

TEST_F(OriginTrialsTest, NotifyOnPersistedTokensClearedNoTokens) {}

// Check that a saved trial name is not returned if it has been disabled by
// policy
TEST_F(OriginTrialsTest, DisabledTrialsNotReturned) {}

// Check that a saved token is not returned if its signature has been disabled
// by policy
TEST_F(OriginTrialsTest, DisabledTokensNotReturned) {}

TEST_F(OriginTrialsTest, UserDisabledTokensNotReturned) {}

TEST_F(OriginTrialsTest, GracePeriodIsRespected) {}

TEST_F(OriginTrialsTest, DoNotPersistTokensForOpaqueOrigins) {}

TEST_F(OriginTrialsTest, PersistTokensInOpaquePartition) {}

TEST_F(OriginTrialsTest, TokensArePartitionedByTopLevelSite) {}

TEST_F(OriginTrialsTest, PartitionSiteIsETLDPlusOne) {}

TEST_F(OriginTrialsTest,
       PartitionSiteUsesPrivateRegistryAsEffectiveTopLevelDomain) {}

TEST_F(OriginTrialsTest, PartitionSiteCanBeIpAddress) {}

TEST_F(OriginTrialsTest, PartitionSiteCanBeLocalhost) {}

TEST_F(OriginTrialsTest, PartitionSiteCanHaveNonstandardPort) {}

TEST_F(OriginTrialsTest, OpaqueOriginAsPartitionSiteSerializesAsSentinelValue) {}

struct OriginValidationTestCase {};

std::vector<OriginValidationTestCase> kOriginValidationTestCases =;

// Test parsing of fields from JSON token.
class OriginTrialsTokenOriginValidationTest
    : public OriginTrialsTest,
      public testing::WithParamInterface<OriginValidationTestCase> {};

TEST_P(OriginTrialsTokenOriginValidationTest, MatchesTokenOrigin) {}

INSTANTIATE_TEST_SUITE_P();

}  // namespace origin_trials