chromium/third_party/blink/renderer/core/origin_trials/origin_trial_context_test.cc

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

#include "third_party/blink/renderer/core/origin_trials/origin_trial_context.h"

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

#include "base/containers/span.h"
#include "base/ranges/algorithm.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/origin_trials/origin_trials.h"
#include "third_party/blink/public/common/origin_trials/trial_token.h"
#include "third_party/blink/public/common/origin_trials/trial_token_result.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 "third_party/blink/public/mojom/permissions_policy/permissions_policy.mojom-blink.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/html/html_head_element.h"
#include "third_party/blink/renderer/core/html/html_meta_element.h"
#include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/permissions_policy/permissions_policy_parser.h"
#include "third_party/blink/renderer/core/testing/dummy_page_holder.h"
#include "third_party/blink/renderer/core/testing/null_execution_context.h"
#include "third_party/blink/renderer/platform/testing/task_environment.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"

namespace blink {
namespace {

const char kUnknownTrialName[] =;
const char kFrobulateTrialName[] =;
const char kFrobulateThirdPartyTrialName[] =;
const char kFrobulateNavigationTrialName[] =;
const char kFrobulateDeprecationTrialName[] =;
const char kFrobulateBrowserReadWriteTrialName[] =;
const char kFrobulateEnabledOrigin[] =;
const char kFrobulateEnabledOriginInsecure[] =;
const char kUnrelatedSecureOrigin[] =;

// The tokens expire in 2033.
const base::Time kBaseTokenExpiryTime =;

// Trial token placeholder for mocked calls to validator
const char kTokenPlaceholder[] =;

// Since all of trial token validation is tested elsewhere,
// this mock lets us test the context in isolation and assert
// that correct parameters are passed to the validator
// without having to generate a large number of valid tokens
class MockTokenValidator : public TrialTokenValidator {};

}  // namespace

class OriginTrialContextTest : public testing::Test {};

// Test that we're passing correct information to the validator
TEST_F(OriginTrialContextTest, ValidatorGetsCorrectInfo) {}

// Test that we're passing correct security information to the validator
TEST_F(OriginTrialContextTest,
       ValidatorGetsCorrectSecurityInfoForInsecureOrigins) {}

// Test that we're passing correct security information to the validator
TEST_F(OriginTrialContextTest, ValidatorGetsCorrectSecurityInfoThirdParty) {}

// Test that unrelated features are not enabled
TEST_F(OriginTrialContextTest, EnabledNonExistingTrial) {}

// The feature should be enabled if a valid token for the origin is provided
TEST_F(OriginTrialContextTest, EnabledSecureRegisteredOrigin) {}

// The feature should be enabled when all of:
// 1) token is valid for third party origin
// 2) token is enabled for secure, third party origin
// 3) trial allows third party origins
TEST_F(OriginTrialContextTest, ThirdPartyTrialWithThirdPartyTokenEnabled) {}

// If the browser says it's invalid for any reason, that's enough to reject.
TEST_F(OriginTrialContextTest, InvalidTokenResponseFromPlatform) {}

// Features should not be enabled on insecure origins
TEST_F(OriginTrialContextTest, FeatureNotEnableOnInsecureOrigin) {}

// Features should not be enabled on insecure third-party origins
TEST_F(OriginTrialContextTest, FeatureNotEnableOnInsecureThirdPartyOrigin) {}

TEST_F(OriginTrialContextTest, ParseHeaderValue) {}

TEST_F(OriginTrialContextTest, ParseHeaderValue_NotCommaSeparated) {}

TEST_F(OriginTrialContextTest, PermissionsPolicy) {}

TEST_F(OriginTrialContextTest, GetEnabledNavigationFeatures) {}

TEST_F(OriginTrialContextTest, ActivateNavigationFeature) {}

TEST_F(OriginTrialContextTest, GetTokenExpiryTimeIgnoresIrrelevantTokens) {}

TEST_F(OriginTrialContextTest, LastExpiryForFeatureIsUsed) {}

TEST_F(OriginTrialContextTest, ImpliedFeatureExpiryTimesAreUpdated) {}

TEST_F(OriginTrialContextTest, SettingFeatureUpdatesDocumentSettings) {}

// This test ensures that the feature and token data are correctly mapped. The
// assertions mirror the code that is used to send origin trial overrides to the
// browser process via RuntimeFeatureStateOverrideContext's IPC.
TEST_F(OriginTrialContextTest, AddedFeaturesAreMappedToTokens) {}

class OriginTrialContextDevtoolsTest : public OriginTrialContextTest {};

TEST_F(OriginTrialContextDevtoolsTest, DependentFeatureNotEnabled) {}

TEST_F(OriginTrialContextDevtoolsTest, TrialNameNotRecognized) {}

TEST_F(OriginTrialContextDevtoolsTest, NoValidToken) {}

TEST_F(OriginTrialContextDevtoolsTest, Enabled) {}

TEST_F(OriginTrialContextDevtoolsTest, UnparsableToken) {}

TEST_F(OriginTrialContextDevtoolsTest, InsecureOrigin) {}

}  // namespace blink