chromium/chrome/browser/enterprise/connectors/analysis/content_analysis_dialog_browsertest.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 "chrome/browser/enterprise/connectors/analysis/content_analysis_dialog.h"

#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_future.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/enterprise/connectors/analysis/content_analysis_delegate.h"
#include "chrome/browser/enterprise/connectors/analysis/content_analysis_downloads_delegate.h"
#include "chrome/browser/enterprise/connectors/analysis/content_analysis_features.h"
#include "chrome/browser/enterprise/connectors/test/deep_scanning_browsertest_base.h"
#include "chrome/browser/enterprise/connectors/test/deep_scanning_test_utils.h"
#include "chrome/browser/enterprise/connectors/test/fake_content_analysis_delegate.h"
#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_utils.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/test/test_browser_dialog.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/theme_resources.h"
#include "components/download/public/common/mock_download_item.h"
#include "components/enterprise/common/proto/connectors.pb.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/mojom/dialog_button.mojom.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/textarea/textarea.h"
#include "ui/views/controls/throbber.h"
#include "ui/views/test/ax_event_counter.h"
#include "ui/views/test/views_test_utils.h"

namespace enterprise_connectors {

namespace {

constexpr base::TimeDelta kNoDelay =;
constexpr base::TimeDelta kSmallDelay =;
constexpr base::TimeDelta kNormalDelay =;

constexpr char kBlockingScansForDlpAndMalware[] =;

constexpr char kBlockingScansForDlp[] =;

constexpr char kBlockingScansForDlpAndMalwareWithCustomMessage[] =;

std::string text() {}

// Tests the behavior of the dialog in the following ways:
// - It shows the appropriate buttons depending on its state.
// - It transitions from states in the correct order.
// - It respects time constraints (minimum shown time, initial delay, timeout)
// - It is always destroyed, therefore |quit_closure_| is called in the dtor
//   observer.
// - It sends accessibility events correctly.
class ContentAnalysisDialogBehaviorBrowserTest
    : public test::DeepScanningBrowserTestBase,
      public ContentAnalysisDialog::TestObserver,
      public testing::WithParamInterface<
          std::tuple<bool, bool, base::TimeDelta, bool>> {};

// Tests the behavior of the dialog in the following ways:
// - It closes when the "Cancel" button is clicked.
// - It returns a negative verdict on the scanned content.
// - The "CancelledByUser" metrics are recorded.
class ContentAnalysisDialogCancelPendingScanBrowserTest
    : public test::DeepScanningBrowserTestBase,
      public ContentAnalysisDialog::TestObserver {};

// Tests the behavior of the dialog in the following ways:
// - It shows the appropriate buttons depending when showing a warning.
// - It calls the appropriate methods when the user bypasses/respects the
//   warning.
class ContentAnalysisDialogWarningBrowserTest
    : public test::DeepScanningBrowserTestBase,
      public ContentAnalysisDialog::TestObserver,
      public testing::WithParamInterface<bool> {};

// Tests the behavior of the dialog in the following ways:
// - It shows the appropriate message depending on its access point and scan
//   type (file or text).
// - It shows the appropriate top image depending on its access point and scan
//   type.
// - It shows the appropriate spinner depending on its state.
class ContentAnalysisDialogAppearanceBrowserTest
    : public test::DeepScanningBrowserTestBase,
      public ContentAnalysisDialog::TestObserver,
      public testing::WithParamInterface<
          std::tuple<bool,
                     bool,
                     safe_browsing::DeepScanAccessPoint,
                     bool,
                     bool>> {};

// Tests the behavior of the dialog in the same way as
// ContentAnalysisDialogAppearanceBrowserTest but with a custom
// message set by the admin.
class ContentAnalysisDialogCustomMessageBrowserTest
    : public ContentAnalysisDialogAppearanceBrowserTest {};

constexpr char kTestUrl[] =;

}  // namespace

IN_PROC_BROWSER_TEST_P(ContentAnalysisDialogBehaviorBrowserTest, Test) {}

// The scan type controls if DLP, malware or both are enabled via policies. The
// dialog currently behaves identically in all 3 cases, so this parameter
// ensures this assumption is not broken by new code.
//
// The DLP/Malware success parameters determine how the response is populated,
// and therefore what the dialog should show.
//
// The three different delays test three cases:
// kNoDelay: The response is as fast as possible, and therefore the pending
//           UI is not shown (kNoDelay < GetInitialUIDelay).
// kSmallDelay: The response is not fast enough to prevent the pending UI from
//              showing, but fast enough that it hasn't been show long enough
//              (GetInitialDelay < kSmallDelay < GetMinimumPendingDialogTime).
// kNormalDelay: The response is slow enough that the pending UI is shown for
//               more than its minimum duration (GetMinimumPendingDialogTime <
//               kNormalDelay).
INSTANTIATE_TEST_SUITE_P();

IN_PROC_BROWSER_TEST_F(ContentAnalysisDialogCancelPendingScanBrowserTest,
                       Test) {}

IN_PROC_BROWSER_TEST_P(ContentAnalysisDialogWarningBrowserTest, Test) {}

INSTANTIATE_TEST_SUITE_P();

IN_PROC_BROWSER_TEST_P(ContentAnalysisDialogAppearanceBrowserTest, Test) {}

INSTANTIATE_TEST_SUITE_P();

IN_PROC_BROWSER_TEST_P(ContentAnalysisDialogCustomMessageBrowserTest, Test) {}

INSTANTIATE_TEST_SUITE_P();

class ContentAnalysisDialogPlainTests : public InProcessBrowserTest {};

IN_PROC_BROWSER_TEST_F(ContentAnalysisDialogPlainTests, TestCustomMessage) {}

IN_PROC_BROWSER_TEST_F(ContentAnalysisDialogPlainTests, TestCustomRuleMessage) {}

IN_PROC_BROWSER_TEST_F(ContentAnalysisDialogPlainTests,
                       TestBypassJustification) {}

IN_PROC_BROWSER_TEST_F(ContentAnalysisDialogPlainTests,
                       TestBypassJustificationTooLongDisablesBypassButton) {}

IN_PROC_BROWSER_TEST_F(ContentAnalysisDialogPlainTests,
                       TestOpenInDefaultPendingState) {}

IN_PROC_BROWSER_TEST_F(ContentAnalysisDialogPlainTests,
                       TestOpenInWarningState) {}

IN_PROC_BROWSER_TEST_F(ContentAnalysisDialogPlainTests, TestOpenInBlockState) {}

IN_PROC_BROWSER_TEST_F(ContentAnalysisDialogPlainTests,
                       TestOpenInFailClosedState) {}

IN_PROC_BROWSER_TEST_F(ContentAnalysisDialogPlainTests,
                       TestOpenInLargeFilesState) {}

IN_PROC_BROWSER_TEST_F(ContentAnalysisDialogPlainTests,
                       TestOpenInEncryptedFilesState) {}

IN_PROC_BROWSER_TEST_F(ContentAnalysisDialogPlainTests,
                       TestWithDownloadsDelegateBypassWarning) {}

IN_PROC_BROWSER_TEST_F(ContentAnalysisDialogPlainTests,
                       TestWithDownloadsDelegateDiscardWarning) {}

IN_PROC_BROWSER_TEST_F(ContentAnalysisDialogPlainTests,
                       TestWithDownloadsDelegateDiscardBlock) {}

IN_PROC_BROWSER_TEST_F(ContentAnalysisDialogPlainTests,
                       BypassJustificationLabelAndTextareaAccessibility) {}

class ContentAnalysisDialogUiTest
    : public DialogBrowserTest,
      public testing::WithParamInterface<std::tuple<bool, bool, bool>> {};

IN_PROC_BROWSER_TEST_P(ContentAnalysisDialogUiTest, InvokeUi_default) {}

INSTANTIATE_TEST_SUITE_P();

class ContentAnalysisDialogCustomRuleMessageUiTest
    : public ContentAnalysisDialogUiTest {};

IN_PROC_BROWSER_TEST_P(ContentAnalysisDialogCustomRuleMessageUiTest,
                       InvokeUi_default) {}

INSTANTIATE_TEST_SUITE_P();

class ContentAnalysisDialogDownloadObserverTest
    : public test::DeepScanningBrowserTestBase,
      public ContentAnalysisDialog::TestObserver {};

IN_PROC_BROWSER_TEST_F(ContentAnalysisDialogDownloadObserverTest,
                       DownloadOpened) {}

IN_PROC_BROWSER_TEST_F(ContentAnalysisDialogDownloadObserverTest,
                       DownloadUpdated) {}

IN_PROC_BROWSER_TEST_F(ContentAnalysisDialogDownloadObserverTest,
                       DownloadDestroyed) {}

}  // namespace enterprise_connectors