#include "components/optimization_guide/content/browser/page_text_observer.h"
#include <optional>
#include <string>
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/strings/strcat.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/types/optional_util.h"
#include "components/optimization_guide/content/mojom/page_text_service.mojom.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/test/navigation_simulator.h"
#include "content/public/test/prerender_test_util.h"
#include "content/public/test/test_renderer_host.h"
#include "content/public/test/web_contents_tester.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/http/http_response_headers.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/common/features.h"
namespace optimization_guide {
namespace {
FrameTextDumpResult MakeFrameDump(mojom::TextDumpEvent event,
content::GlobalRenderFrameHostId rfh_id,
bool amp_frame,
int unique_navigation_id,
const std::u16string& contents) { … }
class TestConsumer : public PageTextObserver::Consumer { … };
class FakePageTextService : public mojom::PageTextService { … };
class TestPageTextObserver : public PageTextObserver { … };
}
class PageTextObserverTest : public content::RenderViewHostTestHarness { … };
TEST_F(PageTextObserverTest, ConsumerCalled) { … }
TEST_F(PageTextObserverTest, ConsumerCalledSameDocument) { … }
TEST_F(PageTextObserverTest, ConsumerNotCalledSubframe) { … }
TEST_F(PageTextObserverTest, ConsumerNotCalledNoCommit) { … }
TEST_F(PageTextObserverTest, MojoPlumbingSuccessCase) { … }
TEST_F(PageTextObserverTest, CompletedFrameDumpMetrics_Empty) { … }
TEST_F(PageTextObserverTest, CompletedFrameDumpMetrics_NotEmpty) { … }
TEST_F(PageTextObserverTest, DisconnectedFrameDumpMetrics) { … }
TEST_F(PageTextObserverTest, MaxLengthOnChunkBorder) { … }
TEST_F(PageTextObserverTest, MaxLengthWithinChunk) { … }
TEST_F(PageTextObserverTest, MaxLengthWithoutOnEnd) { … }
TEST_F(PageTextObserverTest, TwoConsumers) { … }
TEST_F(PageTextObserverTest, RemoveConsumer) { … }
TEST_F(PageTextObserverTest, TwoEventsRequested) { … }
TEST_F(PageTextObserverTest, AbandonedRequest) { … }
TEST_F(PageTextObserverTest, AMPRequestedOnOOPIF) { … }
TEST_F(PageTextObserverTest, AMPNotRequestedOnOOPIF) { … }
TEST_F(PageTextObserverTest, AMPRequestedOnNonOOPIF) { … }
class PageTextObserverWithPrerenderTest : public PageTextObserverTest { … };
TEST_F(PageTextObserverWithPrerenderTest,
PrerenderingShouldNotResetOutstandingRequest) { … }
TEST_F(PageTextObserverWithPrerenderTest, AMPRequestedOnOOPIFInPrerendering) { … }
class PageTextObserverFencedFramesTest : public PageTextObserverTest { … };
TEST_F(PageTextObserverFencedFramesTest, AMPRequestedOnOOPIFInFencedFrame) { … }
}