chromium/content/browser/sms/webotp_service_unittest.cc

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

#include "content/browser/sms/webotp_service.h"

#include <memory>
#include <optional>
#include <string>
#include <utility>

#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "components/ukm/test_ukm_recorder.h"
#include "content/browser/sms/sms_fetcher_impl.h"
#include "content/browser/sms/test/mock_sms_provider.h"
#include "content/browser/sms/test/mock_sms_web_contents_delegate.h"
#include "content/browser/sms/test/mock_user_consent_handler.h"
#include "content/browser/sms/user_consent_handler.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/sms_fetcher.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/navigation_simulator.h"
#include "content/public/test/test_browser_context.h"
#include "content/public/test/test_renderer_host.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/test_support/test_utils.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/service_manager/public/cpp/bind_source_info.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/sms/webotp_service_outcome.h"
#include "third_party/blink/public/mojom/sms/webotp_service.mojom-shared.h"
#include "third_party/blink/public/mojom/sms/webotp_service.mojom.h"

BindLambdaForTesting;
SmsStatus;
WebOTPService;
optional;
string;
_;
ByMove;
Invoke;
NiceMock;
Return;
StrictMock;
Origin;

namespace content {

class RenderFrameHost;

Entry;
FailureType;
UserConsent;

namespace {

const char kTestUrl[] =;

class StubWebContentsDelegate : public WebContentsDelegate {};

// Service encapsulates a WebOTPService endpoint, with all of its dependencies
// mocked out (and the common plumbing needed to inject them), and a
// mojo::Remote<WebOTPService> endpoint that tests can use to make requests.
// It exposes some common methods, like MakeRequest and NotifyReceive, but it
// also exposes the low level mocks that enables tests to set expectations and
// control the testing environment.
class Service {};

class WebOTPServiceTest : public RenderViewHostTestHarness {};

}  // namespace

TEST_F(WebOTPServiceTest, Basic) {}

TEST_F(WebOTPServiceTest, HandlesMultipleCalls) {}

TEST_F(WebOTPServiceTest, IgnoreFromOtherOrigins) {}

TEST_F(WebOTPServiceTest, ExpectOneReceiveTwo) {}

TEST_F(WebOTPServiceTest, AtMostOneSmsRequestPerOrigin) {}

TEST_F(WebOTPServiceTest, CleansUp) {}

TEST_F(WebOTPServiceTest, Abort) {}

// Following tests exercise parts of sms service logic that depend on user
// prompting. In particular how we handle incoming request while there is an
// active in-flight prompts.

class ServiceWithPrompt : public Service {};

TEST_F(WebOTPServiceTest, SecondRequestDuringPrompt) {}

TEST_F(WebOTPServiceTest, AbortWhilePrompt) {}

TEST_F(WebOTPServiceTest, RequestAfterAbortWhilePrompt) {}

TEST_F(WebOTPServiceTest, SecondRequestWhilePrompt) {}

TEST_F(WebOTPServiceTest, RecordTimeMetricsForContinueOnSuccess) {}

TEST_F(WebOTPServiceTest, RecordMetricsForCancelOnSuccess) {}

TEST_F(WebOTPServiceTest, RecordTimeoutAsOutcomeWithoutFailure) {}

TEST_F(WebOTPServiceTest, RecordTimeoutAsOutcomeWithTimerActivation) {}

TEST_F(WebOTPServiceTest, NotRecordTimeoutAsOutcomeWithoutTimerActivation) {}

TEST_F(WebOTPServiceTest, RecordTimeoutAsOutcomeUponPreviousRequestCancelled) {}

TEST_F(WebOTPServiceTest, RecordTimeoutAsOutcomeUponDestruction) {}

TEST_F(WebOTPServiceTest, RecordUserCancelledAsOutcome) {}

TEST_F(WebOTPServiceTest,
       NotRecordUserCancelledAsOutcomeWithoutTimerActivation) {}

TEST_F(WebOTPServiceTest,
       RecordUserCancelledAsOutcomeUponPreviousRequestCancelled) {}

TEST_F(WebOTPServiceTest, RecordUserCancelledAsOutcomeUponDestruction) {}

TEST_F(WebOTPServiceTest, RecordUserDismissPrompt) {}

TEST_F(WebOTPServiceTest, RecordUnhandledRequestOnNavigation) {}

TEST_F(WebOTPServiceTest, NotRecordUnhandledRequestWhenThereIsNoRequest) {}

TEST_F(WebOTPServiceTest, NotRecordUnhandledRequestWhenRequestIsHandled) {}

TEST_F(WebOTPServiceTest, RecordWebContentsVisibilityForUserConsentAPI) {}

TEST_F(WebOTPServiceTest, RecordCancelledAsOutcome) {}

TEST_F(WebOTPServiceTest,
       RecordCrossDeviceFailureAsOutcomeUponPreviousRequestCancelled) {}

TEST_F(WebOTPServiceTest, RecordCrossDeviceFailureAsOutcomeUponDestruction) {}

}  // namespace content