chromium/chrome/browser/ui/views/permissions/chip/dashboard_kombucha_interactive_uitest.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 "base/test/scoped_feature_list.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/permissions/system/system_permission_settings.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_element_identifiers.h"
#include "chrome/browser/ui/views/page_info/page_info_main_view.h"
#include "chrome/browser/ui/views/page_info/permission_toggle_row_view.h"
#include "chrome/browser/ui/views/permissions/chip/permission_chip_theme.h"
#include "chrome/browser/ui/views/permissions/chip/permission_chip_view.h"
#include "chrome/browser/ui/views/permissions/chip/permission_dashboard_view.h"
#include "chrome/browser/ui/views/permissions/permission_prompt_bubble_base_view.h"
#include "chrome/test/interaction/interactive_browser_test.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/content_settings/core/common/features.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/test/browser_test.h"
#include "net/dns/mock_host_resolver.h"

namespace {
DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE();
const char kFirstPermissionRow[] =;
const char kSecondPermissionRow[] =;

}  // namespace

class DashboardKombuchaInteractiveUITest : public InteractiveBrowserTest {};

IN_PROC_BROWSER_TEST_F(DashboardKombuchaInteractiveUITest,
                       PermissionChipClickTest) {}

// 1. Enable Camera permission
// 2. Use `getUserMedia` to show camera activity indicator
// 3. Click on the indicator to open PageInfo
// 4. Verify that Camera permission is shown in PageInfo
// 5. Verify that Camera permission has "Using now" subtitle.
// 6. Verify that the system settings link is not shown.
IN_PROC_BROWSER_TEST_F(DashboardKombuchaInteractiveUITest, CameraUsingTest) {}

// 1. Enable Camera permission
// 2. Use `getUserMedia` to show camera activity indicator
// 3. Click on the indicator to open PageInfo
// 4. Verify that Camera permission is shown in PageInfo
// 5. Verify that Camera permission has "Using now" subtitle.
// 6. Verify that the system settings link is shown.
IN_PROC_BROWSER_TEST_F(DashboardKombuchaInteractiveUITest,
                       CameraUsingTestWithSystemBlock) {}

IN_PROC_BROWSER_TEST_F(DashboardKombuchaInteractiveUITest,
                       MicrophoneUsingTest) {}

IN_PROC_BROWSER_TEST_F(DashboardKombuchaInteractiveUITest,
                       MicrophoneUsingTestWithSystemBlock) {}

#if BUILDFLAG(IS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(DashboardKombuchaInteractiveUITest, LocationUsingTest) {
  SetPermission(ContentSettingsType::GEOLOCATION, CONTENT_SETTING_ALLOW);

  system_permission_settings::ScopedSettingsForTesting scoped_system_permission(
      ContentSettingsType::GEOLOCATION, false);

  RunTestSequence(
      InstrumentTab(kWebContentsElementId),
      NavigateWebContents(kWebContentsElementId, GetURL()),
      EnsureNotPresent(PermissionDashboardView::kDashboardElementId),
      ExecuteJs(kWebContentsElementId, "requestLocation"),
      // Request chip should be hidden.
      PressButton(kLocationIconElementId),
      WaitForShow(PageInfoMainView::kPermissionsElementId),
      CheckViewProperty(PageInfoMainView::kMainLayoutElementId,
                        &PageInfoMainView::GetVisiblePermissionsCountForTesting,
                        1),
      // Set id to the first children of `kPermissionsElementId` -
      // permissions view in PageInfo.
      NameChildView(PageInfoMainView::kPermissionsElementId,
                    kFirstPermissionRow, 0u),
      // Verify the row label is Location
      CheckViewProperty(
          kFirstPermissionRow, &PermissionToggleRowView::GetRowTitleForTesting,
          l10n_util::GetStringUTF16(IDS_SITE_SETTINGS_TYPE_LOCATION)),
      EnsureNotPresent(
          PermissionToggleRowView::kPermissionDisabledAtSystemLevelElementId));
}

IN_PROC_BROWSER_TEST_F(DashboardKombuchaInteractiveUITest,
                       LocationUsingTestWithSystemBlock) {
  SetPermission(ContentSettingsType::GEOLOCATION, CONTENT_SETTING_ALLOW);

  system_permission_settings::ScopedSettingsForTesting scoped_system_permission(
      ContentSettingsType::GEOLOCATION, true);

  RunTestSequence(
      InstrumentTab(kWebContentsElementId),
      NavigateWebContents(kWebContentsElementId, GetURL()),
      EnsureNotPresent(PermissionDashboardView::kDashboardElementId),
      ExecuteJs(kWebContentsElementId, "requestLocation"),
      // Request chip should be hidden.
      PressButton(kLocationIconElementId),
      WaitForShow(PageInfoMainView::kPermissionsElementId),
      CheckViewProperty(PageInfoMainView::kMainLayoutElementId,
                        &PageInfoMainView::GetVisiblePermissionsCountForTesting,
                        1),
      // Set id to the first children of `kPermissionsElementId` -
      // permissions view in PageInfo.
      NameChildView(PageInfoMainView::kPermissionsElementId,
                    kFirstPermissionRow, 0u),
      // Verify the row label is Location
      CheckViewProperty(
          kFirstPermissionRow, &PermissionToggleRowView::GetRowTitleForTesting,
          l10n_util::GetStringUTF16(IDS_SITE_SETTINGS_TYPE_LOCATION)),
      WaitForShow(
          PermissionToggleRowView::kPermissionDisabledAtSystemLevelElementId));
}
#endif

IN_PROC_BROWSER_TEST_F(DashboardKombuchaInteractiveUITest,
                       CameraAndMicrophoneUsingTest) {}

// 1. Enable Camera permission
// 2. Use `getUserMedia` to show camera activity indicator
// 3. Click on the indicator to open PageInfo
// 4. Verify that Camera permission is shown in PageInfo
// 5. Verify that Camera permission has no subtitle.
IN_PROC_BROWSER_TEST_F(DashboardKombuchaInteractiveUITest,
                       CameraPermissionBlockedInUseTest) {}

IN_PROC_BROWSER_TEST_F(DashboardKombuchaInteractiveUITest,
                       MicrophonePermissionBlockedInUseTest) {}

IN_PROC_BROWSER_TEST_F(DashboardKombuchaInteractiveUITest,
                       CameraAndMicrophonePermissionsBlockedInUseTest) {}

IN_PROC_BROWSER_TEST_F(DashboardKombuchaInteractiveUITest,
                       CameraAllowStartStopTest) {}

IN_PROC_BROWSER_TEST_F(DashboardKombuchaInteractiveUITest,
                       CameraBlockStartStopTest) {}

IN_PROC_BROWSER_TEST_F(DashboardKombuchaInteractiveUITest,
                       MicrophoneAllowStartStopTest) {}

IN_PROC_BROWSER_TEST_F(DashboardKombuchaInteractiveUITest,
                       MicBlockStartStopTest) {}

// Make sure PageInfo does not re-open on an indicator click.
IN_PROC_BROWSER_TEST_F(DashboardKombuchaInteractiveUITest,
                       SuppressPageInfoReopen) {}