chromium/chrome/browser/ui/views/side_panel/read_anything/read_anything_coordinator_unittest.cc

// Copyright 2022 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/ui/views/side_panel/read_anything/read_anything_coordinator.h"

#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "chrome/browser/accessibility/embedded_a11y_extension_loader.h"
#include "chrome/browser/companion/core/features.h"
#include "chrome/browser/extensions/component_loader.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/test_extension_system.h"
#include "chrome/browser/ui/browser_window/public/browser_window_features.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/test_with_browser_view.h"
#include "chrome/browser/ui/views/side_panel/read_anything/read_anything_side_panel_web_view.h"
#include "chrome/browser/ui/views/side_panel/side_panel_coordinator.h"
#include "chrome/browser/ui/views/side_panel/side_panel_entry.h"
#include "chrome/browser/ui/views/side_panel/side_panel_registry.h"
#include "chrome/browser/ui/webui/side_panel/read_anything/read_anything_untrusted_ui.h"
#include "chrome/common/extensions/extension_constants.h"
#include "content/public/test/scoped_web_ui_controller_factory_registration.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/accessibility/accessibility_features.h"

#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chrome/browser/lacros/embedded_a11y_manager_lacros.h"
#endif  // BUILDFLAG(IS_CHROMEOS_LACROS)

_;

class MockReadAnythingCoordinatorObserver
    : public ReadAnythingCoordinator::Observer {};

class ReadAnythingCoordinatorTest : public TestWithBrowserView {};

// TODO(crbug.com/40853217): Fix the memory leak on destruction observed on
// these tests on asan mac.
#if !BUILDFLAG(IS_MAC) || !defined(ADDRESS_SANITIZER)

TEST_F(ReadAnythingCoordinatorTest, ContainerViewsAreUnique) {}

TEST_F(ReadAnythingCoordinatorTest,
       ActivateCalled_ShowAndHideReadAnythingEntry) {}

#if !BUILDFLAG(IS_CHROMEOS_LACROS)
TEST_F(ReadAnythingCoordinatorTest,
       SidePanelShowAndHide_NonLacros_CallEmbeddedA11yExtensionLoader) {}
#endif  // !BUILDFLAG(IS_CHROMEOS_LACROS)

#if BUILDFLAG(IS_CHROMEOS_LACROS)
TEST_F(
    ReadAnythingCoordinatorTest,
    SidePanelShowAndHide_Lacros_EmbeddedA11yManagerLacrosUpdateReadingModeState) {
  SidePanelEntry* entry = contextual_registries_[0]->GetEntryForKey(
      SidePanelEntry::Key(SidePanelEntry::Id::kReadAnything));
  EXPECT_FALSE(
      EmbeddedA11yManagerLacros::GetInstance()->IsReadingModeEnabled());

  // If the local side panel entry is shown, set reading mode enabled to true.
  entry->OnEntryShown();
  EXPECT_TRUE(EmbeddedA11yManagerLacros::GetInstance()->IsReadingModeEnabled());

  // If the local side panel entry is hidden, set reading mode enabled to false
  // after a timeout.
  entry->OnEntryHidden();
  // The reading mode setting is not updated immediately.
  EXPECT_TRUE(EmbeddedA11yManagerLacros::GetInstance()->IsReadingModeEnabled());
  // The reading mode setting is updated after a timeout.
  task_environment()->FastForwardBy(base::Seconds(30));
  EXPECT_FALSE(
      EmbeddedA11yManagerLacros::GetInstance()->IsReadingModeEnabled());
}
#endif  // BUILDFLAG(IS_CHROMEOS_LACROS)

TEST_F(ReadAnythingCoordinatorTest,
       OnBrowserSetLastActive_SidePanelIsNotVisible) {}

TEST_F(ReadAnythingCoordinatorTest, WithWebUIFlagEnabled_ShowsWebUIToolbar) {}

class ReadAnythingCoordinatorScreen2xDataCollectionModeTest
    : public TestWithBrowserView {};

TEST_F(ReadAnythingCoordinatorScreen2xDataCollectionModeTest,
       OnBrowserSetLastActive_SidePanelIsVisible) {}

#endif  // !defined(ADDRESS_SANITIZER)