chromium/chrome/browser/ui/views/digital_credentials/digital_identity_safety_interstitial_integration_test.cc

// Copyright 2024 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 <string>

#include "base/files/file_path.h"
#include "base/functional/callback.h"
#include "base/memory/weak_ptr.h"
#include "base/run_loop.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/app/chrome_main_delegate.h"
#include "chrome/browser/chrome_content_browser_client.h"
#include "chrome/browser/digital_credentials/digital_identity_provider_desktop.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/views/digital_credentials/digital_identity_safety_interstitial_controller_desktop.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/digital_identity_provider.h"
#include "content/public/common/content_features.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "testing/gtest/include/gtest/gtest-spi.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/views/widget/any_widget_observer.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
#include "ui/views/widget/widget_observer.h"

namespace {

// Callback for when a views::Widget is shown. Sets `was_dialog_shown` if the
// shown views::Widget has `expected_dialog_title`.
void OnDialogShown(base::RepeatingClosure dialog_shown_callback,
                   std::u16string expected_dialog_title,
                   views::Widget* widget) {}

// content::DigitalIdentityProvider which:
// - always succeeds
// - offers method to wait till DigitalIdentityProvider::Request() is invoked.
class TestDigitalIdentityProvider final
    : public DigitalIdentityProviderDesktop {};

// ChromeContentBrowserClient which returns custom
// content::DigitalIdentityProvider.
class TestBrowserClient : public ChromeContentBrowserClient {};

}  // anonymous namespace

// Tests for DigitalIdentitySafetyInterstitialControllerDesktop.
//
// A bunch of logic for showing the interstitial is shared between the desktop
// and Android implementations. For the sake of not duplicating integration
// tests for shared code for both desktop and Android, integration tests for
// shared logic are intentionally Android-only.
class DigitalIdentitySafetyInterstitialIntegrationTest
    : public InProcessBrowserTest {};

/**
 * Test that an interstitial is shown if the page requests more than just the
 * age.
 */
IN_PROC_BROWSER_TEST_F(DigitalIdentitySafetyInterstitialIntegrationTest,
                       InterstitialShownMoreThanJustAge) {}

/**
 * Test that an interstitial is not shown if the page only requests the age.
 */
IN_PROC_BROWSER_TEST_F(DigitalIdentitySafetyInterstitialIntegrationTest,
                       InterstitialNotShown) {}