chromium/chrome/renderer/accessibility/read_anything_app_controller_browsertest.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/renderer/accessibility/read_anything_app_controller.h"

#include <cstddef>
#include <string>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/common/accessibility/read_anything_constants.h"
#include "chrome/renderer/accessibility/ax_tree_distiller.h"
#include "chrome/renderer/accessibility/read_anything_test_utils.h"
#include "chrome/test/base/chrome_render_view_test.h"
#include "content/public/renderer/render_frame.h"
#include "read_anything_test_utils.h"
#include "services/strings/grit/services_strings.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/accessibility/accessibility_features.h"
#include "ui/accessibility/ax_node.h"
#include "ui/accessibility/ax_node_id_forward.h"
#include "ui/accessibility/ax_serializable_tree.h"
#include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h"

class MockAXTreeDistiller : public AXTreeDistiller {};

class MockReadAnythingUntrustedPageHandler
    : public read_anything::mojom::UntrustedPageHandler {};

ElementsAre;
IsEmpty;
Mock;

class ReadAnythingAppControllerTest : public ChromeRenderViewTest {};

TEST_F(ReadAnythingAppControllerTest, IsReadAloudEnabled) {}

TEST_F(ReadAnythingAppControllerTest, OnLetterSpacingChange_ValidChange) {}

TEST_F(ReadAnythingAppControllerTest, OnLetterSpacingChange_InvalidChange) {}

TEST_F(ReadAnythingAppControllerTest, OnLineSpacingChange_ValidChange) {}

TEST_F(ReadAnythingAppControllerTest, OnLineSpacingChange_InvalidChange) {}

TEST_F(ReadAnythingAppControllerTest, OnThemeChange_ValidChange) {}

TEST_F(ReadAnythingAppControllerTest, OnThemeChange_InvalidChange) {}

TEST_F(ReadAnythingAppControllerTest, OnFontChange_UpdatesFont) {}

TEST_F(ReadAnythingAppControllerTest, GetValidatedFontName_FontWithQuotes) {}

TEST_F(ReadAnythingAppControllerTest, GetValidatedFontName_FontWithoutQuotes) {}

TEST_F(ReadAnythingAppControllerTest, GetValidatedFontName_InvalidFont) {}

TEST_F(ReadAnythingAppControllerTest, GetValidatedFontName_UnsupportedFont) {}

TEST_F(ReadAnythingAppControllerTest, OnSpeechRateChange) {}

TEST_F(ReadAnythingAppControllerTest, OnLanguagePrefChange) {}

TEST_F(ReadAnythingAppControllerTest,
       GetStoredVoice_NoAutoSwitching_ReturnsLatestVoice) {}

TEST_F(ReadAnythingAppControllerTest,
       GetStoredVoice_NoAutoSwitching_ReturnsLatestVoiceRegardlessOfLang) {}

TEST_F(ReadAnythingAppControllerTest, GetStoredVoice_NoVoices_ReturnsEmpty) {}

TEST_F(ReadAnythingAppControllerTest,
       GetStoredVoice_CurrentBaseLangStored_ReturnsExpectedVoice) {}

TEST_F(ReadAnythingAppControllerTest,
       GetStoredVoice_CurrentFullLangStored_ReturnsExpectedVoice) {}

TEST_F(
    ReadAnythingAppControllerTest,
    GetStoredVoice_BaseLangStoredButCurrentLangIsFull_ReturnsStoredBaseLang) {}

TEST_F(ReadAnythingAppControllerTest,
       GetStoredVoice_CurrentLangNotStored_ReturnsEmpty) {}

TEST_F(ReadAnythingAppControllerTest, OnSettingsRestoredFromPrefs) {}

TEST_F(ReadAnythingAppControllerTest, RootIdIsSnapshotRootId) {}

TEST_F(ReadAnythingAppControllerTest, GetChildren_NoSelectionOrContentNodes) {}

TEST_F(ReadAnythingAppControllerTest, GetChildren_WithContentNodes) {}

TEST_F(ReadAnythingAppControllerTest,
       GetChildren_WithSelection_ContainsNearbyNodes) {}

TEST_F(ReadAnythingAppControllerTest,
       GetChildren_WithBackwardSelection_ContainsNearbyNodes) {}

TEST_F(ReadAnythingAppControllerTest, GetHtmlTag) {}

TEST_F(ReadAnythingAppControllerTest, GetHtmlTag_TextFieldReturnsDiv) {}

TEST_F(ReadAnythingAppControllerTest, GetHtmlTag_SvgReturnsDivIfGoogleDocs) {}

TEST_F(ReadAnythingAppControllerTest,
       GetHtmlTag_paragraphWithTagGReturnsPIfGoogleDocs) {}

TEST_F(ReadAnythingAppControllerTest,
       GetHtmlTag_DivWithHeadingAndAriaLevelReturnsH) {}

TEST_F(ReadAnythingAppControllerTest, GetHtmlTag_PDF) {}

TEST_F(ReadAnythingAppControllerTest, GetHtmlTag_IncorrectlyFormattedPDF) {}

TEST_F(ReadAnythingAppControllerTest, GetHtmlTag_InaccessiblePDF) {}

TEST_F(ReadAnythingAppControllerTest, GetAltText) {}

TEST_F(ReadAnythingAppControllerTest, GetAltText_Unset) {}

TEST_F(ReadAnythingAppControllerTest, GetImageDataUrl) {}

TEST_F(ReadAnythingAppControllerTest, GetImageDataUrl_Unset) {}

TEST_F(ReadAnythingAppControllerTest, GetTextContent_NoSelection) {}

TEST_F(ReadAnythingAppControllerTest, GetTextContent_WithSelection) {}

TEST_F(ReadAnythingAppControllerTest,
       GetTextContent_IgoreStaticTextIfGoogleDocs) {}

TEST_F(ReadAnythingAppControllerTest,
       GetTextContent_UseNameAttributeTextIfGoogleDocs) {}

TEST_F(ReadAnythingAppControllerTest,
       GetTextContent_DoNotUseNameAttributeTextIfNotGoogleDocs) {}

TEST_F(ReadAnythingAppControllerTest, GetDisplayNameForLocale) {}

TEST_F(ReadAnythingAppControllerTest, GetUrl) {}

TEST_F(ReadAnythingAppControllerTest, ShouldBold) {}

TEST_F(ReadAnythingAppControllerTest, GetDataFontCss) {}

TEST_F(ReadAnythingAppControllerTest, IsOverline) {}

TEST_F(ReadAnythingAppControllerTest, IsLeafNode) {}

TEST_F(ReadAnythingAppControllerTest,
       SelectionNodeIdsContains_SelectionAndNearbyNodes) {}

TEST_F(ReadAnythingAppControllerTest,
       SelectionNodeIdsContains_BackwardSelectionAndNearbyNodes) {}

TEST_F(ReadAnythingAppControllerTest, DisplayNodeIdsContains_ContentNodes) {}

TEST_F(ReadAnythingAppControllerTest,
       DisplayNodeIdsContains_NoSelectionOrContentNodes) {}

TEST_F(ReadAnythingAppControllerTest, DoesNotCrashIfContentNodeNotFoundInTree) {}

TEST_F(ReadAnythingAppControllerTest, Draw_RecomputeDisplayNodes) {}

TEST_F(ReadAnythingAppControllerTest, Draw_DoNotRecomputeDisplayNodesForDocs) {}

TEST_F(ReadAnythingAppControllerTest, AccessibilityEventReceived) {}

TEST_F(ReadAnythingAppControllerTest,
       AccessibilityEventReceivedWhileDistilling) {}

TEST_F(ReadAnythingAppControllerTest, AccessibilityEventReceivedWhileSpeaking) {}

TEST_F(ReadAnythingAppControllerTest, OnActiveAXTreeIDChanged) {}

TEST_F(ReadAnythingAppControllerTest, IsGoogleDocs) {}

TEST_F(ReadAnythingAppControllerTest, DoesNotCrashIfActiveAXTreeIDUnknown) {}

TEST_F(ReadAnythingAppControllerTest, DoesNotCrashIfActiveAXTreeIDNotInTrees) {}

TEST_F(ReadAnythingAppControllerTest, AddAndRemoveTrees) {}

TEST_F(ReadAnythingAppControllerTest, OnAXTreeDestroyed_EraseTreeCalled) {}

TEST_F(ReadAnythingAppControllerTest,
       DistillationInProgress_TreeUpdateReceivedOnActiveTree) {}

TEST_F(ReadAnythingAppControllerTest,
       SpeechPlaying_TreeUpdateReceivedOnActiveTree) {}

TEST_F(ReadAnythingAppControllerTest,
       AccessibilityReceivedAfterDistillingOnSameTree_DoesNotCrash) {}

TEST_F(ReadAnythingAppControllerTest,
       DistillationInProgress_ActiveTreeIDChanges) {}

TEST_F(ReadAnythingAppControllerTest,
       OnAXTreeDistilledCalledWithInactiveTreeId) {}

TEST_F(ReadAnythingAppControllerTest,
       OnAXTreeDistilledCalledWithDestroyedTreeId) {}

TEST_F(ReadAnythingAppControllerTest,
       OnAXTreeDistilledCalledWithUnknownActiveTreeId) {}

TEST_F(ReadAnythingAppControllerTest,
       OnAXTreeDistilledCalledWithUnknownTreeId) {}

TEST_F(ReadAnythingAppControllerTest,
       ChangeActiveTreeWithPendingUpdates_UnknownID) {}

TEST_F(ReadAnythingAppControllerTest, OnLinkClicked) {}

TEST_F(ReadAnythingAppControllerTest, RequestImageDataUrl) {}

TEST_F(ReadAnythingAppControllerTest, OnLinkClicked_DistillationInProgress) {}

TEST_F(ReadAnythingAppControllerTest, ScrollToTargetNode_ScrollsIfGoogleDocs) {}

TEST_F(ReadAnythingAppControllerTest,
       ScrollToTargetNode_DoesNotScrollIfNotGoogleDocs) {}

TEST_F(ReadAnythingAppControllerTest, OnSelectionChange) {}

TEST_F(ReadAnythingAppControllerTest, OnCollapseSelection) {}

TEST_F(ReadAnythingAppControllerTest,
       OnSelectionChange_ClickAfterClickDoesNotUpdateSelection) {}

TEST_F(ReadAnythingAppControllerTest,
       OnSelectionChange_ClickAfterSelectionClearsSelection) {}

TEST_F(ReadAnythingAppControllerTest,
       OnSelectionChange_DistillationInProgress) {}

TEST_F(ReadAnythingAppControllerTest,
       OnSelectionChange_NonTextFieldDoesNotUpdateSelection) {}

TEST_F(ReadAnythingAppControllerTest, Selection_Forward) {}

TEST_F(ReadAnythingAppControllerTest, Selection_Backward) {}

TEST_F(ReadAnythingAppControllerTest, Selection_IgnoredNode) {}

TEST_F(ReadAnythingAppControllerTest, Selection_IsCollapsed) {}

TEST_F(ReadAnythingAppControllerTest, OnFontSizeReset_SetsFontSizeToDefault) {}

TEST_F(ReadAnythingAppControllerTest,
       OnLinksEnabledChanged_SetsEnabledToFalse) {}

TEST_F(ReadAnythingAppControllerTest, TurnedHighlightOn_SavesHighlightState) {}

TEST_F(ReadAnythingAppControllerTest, TurnedHighlightOff_SavesHighlightState) {}

TEST_F(ReadAnythingAppControllerTest, SetLanguageCode_UpdatesModelLanguage) {}

TEST_F(ReadAnythingAppControllerTest,
       SetLanguageCode_EmptyCode_DoesNotUpdateModelLanguage) {}

TEST_F(ReadAnythingAppControllerTest,
       SetLanguageCode_EmptyCode_SetsRootLanguageOnceAvailable) {}

TEST_F(ReadAnythingAppControllerTest,
       GetCurrentText_WhenCalledManyTimes_ReturnsSameNode) {}

TEST_F(ReadAnythingAppControllerTest, GetCurrentText_ReturnsExpectedNodes) {}

TEST_F(ReadAnythingAppControllerTest,
       PreprocessNodes_DoesNotImpactCurrentNodes) {}

TEST_F(ReadAnythingAppControllerTest,
       PreprocessNodes_CalledMultipleTimes_DoesNotImpactCurrentNodes) {}

TEST_F(ReadAnythingAppControllerTest,
       GetCurrentText_AfterRestartReadAloud_StartsOver) {}

TEST_F(ReadAnythingAppControllerTest,
       GetCurrentText_AfterResetGranularityIndex_StartsOver) {}

TEST_F(ReadAnythingAppControllerTest, GetCurrentText_AfterAXTreeRefresh) {}

TEST_F(ReadAnythingAppControllerTest,
       GetCurrentText_SentenceSplitAcrossMultipleNodes) {}

TEST_F(ReadAnythingAppControllerTest,
       GetCurrentText_SentenceSplitAcrossTwoNodes) {}

TEST_F(ReadAnythingAppControllerTest,
       GetCurrentText_OpeningPunctuationIgnored) {}

TEST_F(ReadAnythingAppControllerTest,
       GetCurrentText_OpeningPunctuationIncludedWhenEntireNode) {}

TEST_F(ReadAnythingAppControllerTest,
       GetCurrentText_SuperscriptCombinedWithCurrentSegment) {}

TEST_F(ReadAnythingAppControllerTest,
       GetCurrentText_SuperscriptWithBracketsCombinedWithCurrentSegment) {}

TEST_F(ReadAnythingAppControllerTest,
       GetCurrentText_SuperscriptIncludedWhenEntireNode) {}

TEST_F(ReadAnythingAppControllerTest,
       GetCurrentText_SuperscriptIncludedWhenEntireNodeAndMoreTextAfterScript) {}

TEST_F(ReadAnythingAppControllerTest, GetCurrentText_IncludesListMarkers) {}

TEST_F(ReadAnythingAppControllerTest,
       GetCurrentText_SentenceSplitAcrossParagraphs) {}

TEST_F(ReadAnythingAppControllerTest,
       GetCurrentText_SentenceSplitAcrossParagraphsWithoutParagraphRoles) {}

TEST_F(ReadAnythingAppControllerTest,
       GetCurrentText_MultipleSentencesInSameNode) {}

TEST_F(ReadAnythingAppControllerTest, GetCurrentText_EmptyTree) {}

TEST_F(ReadAnythingAppControllerTest, GetPreviousText_AfterAXTreeRefresh) {}

TEST_F(ReadAnythingAppControllerTest, GetPreviousText_ReturnsExpectedNodes) {}

TEST_F(ReadAnythingAppControllerTest, GetPreviousText_EmptyTree) {}

TEST_F(
    ReadAnythingAppControllerTest,
    MoveToPreviousGranularityAndGetText_WhenFirstInitialized_StillReturnsFirstGranularity) {}

TEST_F(ReadAnythingAppControllerTest,
       GetCurrentText_WhenGranularityWasInitiallySkipped_ReturnsText) {}

TEST_F(ReadAnythingAppControllerTest,
       GetPreviousText_SentenceSplitAcrossMultipleNodes) {}

TEST_F(ReadAnythingAppControllerTest,
       GetPreviousText_SentenceSplitAcrossTwoNodes) {}

TEST_F(ReadAnythingAppControllerTest,
       GetAccessibleBoundary_MaxLengthCutsOffSentence_ReturnsCorrectIndex) {}

TEST_F(ReadAnythingAppControllerTest,
       GetAccessibleBoundary_TextLongerThanMaxLength_ReturnsCorrectIndex) {}

TEST_F(
    ReadAnythingAppControllerTest,
    GetAccessibleBoundary_MaxLengthCutsOffSentence_OnlyOneSentence_ReturnsCorrectIndex) {}

TEST_F(ReadAnythingAppControllerTest, GetNextValidPosition) {}

TEST_F(ReadAnythingAppControllerTest, GetNextValidPosition_SkipsNonTextNode) {}

TEST_F(ReadAnythingAppControllerTest,
       GetNextValidPosition_SkipsNonDistilledNode) {}

TEST_F(ReadAnythingAppControllerTest,
       GetNextValidPosition_SkipsNodeWithHTMLTag) {}

TEST_F(ReadAnythingAppControllerTest,
       GetNextValidPosition_ReturnsNullPositionAtEndOfTree) {}

TEST_F(
    ReadAnythingAppControllerTest,
    GetNextValidPosition_AfterGetNextNodesButBeforeGetCurrentText_UsesCurrentGranularity) {}

TEST_F(ReadAnythingAppControllerTest,
       GetNextNodes_AfterResetReadAloudState_StartsOver) {}

testing::Matcher<ReadAloudTextSegment> TextSegmentMatcher(ui::AXNodeID id,
                                                          int text_start,
                                                          int text_end) {}

TEST_F(ReadAnythingAppControllerTest,
       GetHighlightForCurrentSegmentIndex_ReturnsCorrectNodes) {}

TEST_F(
    ReadAnythingAppControllerTest,
    GetHighlightForCurrentSegmentIndex_SentenceSpansMultipleNodes_ReturnsCorrectNodes) {}

TEST_F(
    ReadAnythingAppControllerTest,
    GetHighlightForCurrentSegmentIndex_NodeSpansMultipleSentences_ReturnsCorrectNodes) {}

TEST_F(ReadAnythingAppControllerTest,
       GetHighlightForCurrentSegmentIndex_AfterNext_ReturnsCorrectNodes) {}

TEST_F(ReadAnythingAppControllerTest,
       GetHighlightForCurrentSegmentIndex_AfterPrevious_ReturnsCorrectNodes) {}

TEST_F(ReadAnythingAppControllerTest,
       GetHighlightForCurrentSegmentIndex_MultinodeWords_ReturnsCorrectLength) {}

class ReadAnythingAppControllerScreen2xDataCollectionModeTest
    : public ReadAnythingAppControllerTest {};

TEST_F(ReadAnythingAppControllerScreen2xDataCollectionModeTest,
       DoesNotDistillImmediately) {}

TEST_F(ReadAnythingAppControllerScreen2xDataCollectionModeTest,
       DistillsAfterDelay) {}

TEST_F(ReadAnythingAppControllerScreen2xDataCollectionModeTest,
       DistillsAfterDelayScreenAIServiceReady) {}

TEST_F(ReadAnythingAppControllerScreen2xDataCollectionModeTest,
       DoesNotDistillIfScreenAIServiceNotReady) {}

TEST_F(ReadAnythingAppControllerScreen2xDataCollectionModeTest,
       DistillsAfterDelayWhenTreeIsStable) {}

TEST_F(ReadAnythingAppControllerScreen2xDataCollectionModeTest,
       DoesNotDistillAfterDelayIfTreeIsUnstable) {}

TEST_F(ReadAnythingAppControllerScreen2xDataCollectionModeTest,
       DistillsAfter30sDelayEvenIfTreeIsUnstable) {}