123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580 |
- // Copyright 2019 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- #include "components/content_capture/browser/content_capture_receiver.h"
- #include "base/json/json_reader.h"
- #include "base/test/scoped_feature_list.h"
- #include "base/test/test_mock_time_task_runner.h"
- #include "build/build_config.h"
- #include "components/content_capture/browser/content_capture_test_helper.h"
- #include "content/public/common/content_features.h"
- #include "content/public/test/test_renderer_host.h"
- #include "content/public/test/test_utils.h"
- #include "third_party/blink/public/mojom/favicon/favicon_url.mojom.h"
- #include "ui/gfx/geometry/size.h"
- namespace content_capture {
- namespace {
- static constexpr char16_t kMainFrameUrl[] = u"http://foo.com/main.html";
- static constexpr char16_t kMainFrameUrl2[] = u"http://foo.com/2.html";
- static constexpr char16_t kChildFrameUrl[] = u"http://foo.org/child.html";
- static constexpr char16_t kMainFrameSameDocument[] =
- u"http://foo.com/main.html#1";
- } // namespace
- class ContentCaptureReceiverTest : public content::RenderViewHostTestHarness,
- public ::testing::WithParamInterface<bool> {
- public:
- void SetUp() override {
- // TODO (crbug.com/1115234): Remove the param when BFCache same site feature
- // launched.
- if (GetParam()) {
- scoped_feature_list_.InitWithFeaturesAndParameters(
- {{{features::kBackForwardCache}, {{"enable_same_site", "true"}}}},
- // Allow BackForwardCache for all devices regardless of their memory.
- {features::kBackForwardCacheMemoryControls});
- }
- content::RenderViewHostTestHarness::SetUp();
- helper_.CreateProviderAndConsumer(web_contents(),
- &session_removed_test_helper_);
- // This needed to keep the WebContentsObserverConsistencyChecker checks
- // happy for when AppendChild is called.
- NavigateAndCommit(GURL(kMainFrameUrl));
- main_frame_ = web_contents()->GetPrimaryMainFrame();
- EXPECT_TRUE(main_frame_);
- main_frame_sender_ = std::make_unique<FakeContentCaptureSender>();
- main_frame_sender_->Bind(main_frame_);
- helper_.InitTestData(kMainFrameUrl, kChildFrameUrl);
- }
- void NavigateMainFrame(const GURL& url) {
- consumer()->Reset();
- NavigateAndCommit(url);
- main_frame_ = web_contents()->GetPrimaryMainFrame();
- }
- void NavigateMainFrameSameDocument() {
- consumer()->Reset();
- NavigateAndCommit(GURL(kMainFrameSameDocument));
- }
- void SetupChildFrame() {
- child_frame_ = content::RenderFrameHostTester::For(main_frame_.get())
- ->AppendChild("child");
- EXPECT_TRUE(child_frame_);
- child_frame_sender_ = std::make_unique<FakeContentCaptureSender>();
- child_frame_sender_->Bind(child_frame_);
- }
- void BuildChildSession(const ContentCaptureSession& parent,
- const ContentCaptureFrame& data,
- ContentCaptureSession* child) {
- ContentCaptureFrame child_frame = data;
- child_frame.children.clear();
- child->clear();
- child->push_back(child_frame);
- DCHECK(parent.size() == 1);
- child->push_back(parent.front());
- }
- int64_t GetFrameId(bool main_frame) {
- return ContentCaptureReceiver::GetIdFrom(main_frame ? main_frame_.get()
- : child_frame_.get());
- }
- const std::vector<int64_t>& expected_removed_ids() const {
- return expected_removed_ids_;
- }
- SessionRemovedTestHelper* session_removed_test_helper() {
- return &session_removed_test_helper_;
- }
- OnscreenContentProvider* provider() const {
- return helper_.onscreen_content_provider();
- }
- ContentCaptureConsumerHelper* consumer() const {
- return helper_.content_capture_consumer();
- }
- FakeContentCaptureSender* main_frame_sender() const {
- return main_frame_sender_.get();
- }
- FakeContentCaptureSender* child_frame_sender() const {
- return child_frame_sender_.get();
- }
- const ContentCaptureTestHelper* helper() const { return &helper_; }
- private:
- ContentCaptureTestHelper helper_;
- // The sender for main frame.
- std::unique_ptr<FakeContentCaptureSender> main_frame_sender_;
- // The sender for child frame.
- std::unique_ptr<FakeContentCaptureSender> child_frame_sender_;
- raw_ptr<content::RenderFrameHost> main_frame_ = nullptr;
- raw_ptr<content::RenderFrameHost> child_frame_ = nullptr;
- // Expected removed Ids.
- std::vector<int64_t> expected_removed_ids_{2};
- SessionRemovedTestHelper session_removed_test_helper_;
- base::test::ScopedFeatureList scoped_feature_list_;
- };
- INSTANTIATE_TEST_SUITE_P(,
- ContentCaptureReceiverTest,
- testing::Values(true, false));
- TEST_P(ContentCaptureReceiverTest, DidCaptureContent) {
- main_frame_sender()->DidCaptureContent(helper()->test_data(),
- true /* first_data */);
- EXPECT_TRUE(consumer()->parent_session().empty());
- EXPECT_TRUE(consumer()->removed_sessions().empty());
- EXPECT_EQ(GetExpectedTestData(helper()->test_data(),
- GetFrameId(true /* main_frame */)),
- consumer()->captured_data());
- }
- TEST_P(ContentCaptureReceiverTest, MultipleConsumers) {
- std::unique_ptr<ContentCaptureConsumerHelper> consumer2 =
- std::make_unique<ContentCaptureConsumerHelper>(nullptr);
- provider()->AddConsumer(*(consumer2.get()));
- main_frame_sender()->DidCaptureContent(helper()->test_data(),
- true /* first_data */);
- EXPECT_TRUE(consumer()->parent_session().empty());
- EXPECT_TRUE(consumer()->removed_sessions().empty());
- EXPECT_EQ(GetExpectedTestData(helper()->test_data(),
- GetFrameId(true /* main_frame */)),
- consumer()->captured_data());
- EXPECT_TRUE(consumer2->parent_session().empty());
- EXPECT_TRUE(consumer2->removed_sessions().empty());
- EXPECT_EQ(GetExpectedTestData(helper()->test_data(),
- GetFrameId(true /* main_frame */)),
- consumer2->captured_data());
- // Verifies to get the remove session callback in RemoveConsumer.
- provider()->RemoveConsumer(*(consumer2.get()));
- EXPECT_TRUE(consumer()->removed_sessions().empty());
- EXPECT_EQ(1u, consumer2->removed_sessions().size());
- std::vector<ContentCaptureFrame> expected{GetExpectedTestData(
- helper()->test_data(), GetFrameId(true /* main_frame */))};
- VerifySession(expected, consumer2->removed_sessions().front());
- EXPECT_EQ(1u, provider()->GetConsumersForTesting().size());
- EXPECT_EQ(consumer(), provider()->GetConsumersForTesting()[0]);
- }
- // TODO(https://crbug.com/1010179): Fix flakes on win10_chromium_x64_rel_ng and
- // re-enable this test.
- #if BUILDFLAG(IS_WIN)
- #define MAYBE_DidCaptureContentWithUpdate DISABLED_DidCaptureContentWithUpdate
- #else
- #define MAYBE_DidCaptureContentWithUpdate DidCaptureContentWithUpdate
- #endif
- TEST_P(ContentCaptureReceiverTest, MAYBE_DidCaptureContentWithUpdate) {
- main_frame_sender()->DidCaptureContent(helper()->test_data(),
- true /* first_data */);
- // Verifies to get test_data() with correct frame content id.
- EXPECT_TRUE(consumer()->parent_session().empty());
- EXPECT_TRUE(consumer()->removed_sessions().empty());
- EXPECT_EQ(GetExpectedTestData(helper()->test_data(),
- GetFrameId(true /* main_frame */)),
- consumer()->captured_data());
- // Simulates to update the content within the same document.
- main_frame_sender()->DidCaptureContent(helper()->test_data_update(),
- false /* first_data */);
- // Verifies to get test_data2() with correct frame content id.
- EXPECT_TRUE(consumer()->parent_session().empty());
- // Verifies that the session isn't removed.
- EXPECT_TRUE(consumer()->removed_sessions().empty());
- EXPECT_EQ(GetExpectedTestData(helper()->test_data_update(),
- GetFrameId(true /* main_frame */)),
- consumer()->captured_data());
- }
- // TODO(https://crbug.com/1011204): Fix flakes on win10_chromium_x64_rel_ng and
- // re-enable this test.
- #if BUILDFLAG(IS_WIN)
- #define MAYBE_DidUpdateContent DISABLED_DidUpdateContent
- #else
- #define MAYBE_DidUpdateContent DidUpdateContent
- #endif
- TEST_P(ContentCaptureReceiverTest, MAYBE_DidUpdateContent) {
- main_frame_sender()->DidCaptureContent(helper()->test_data(),
- true /* first_data */);
- EXPECT_TRUE(consumer()->parent_session().empty());
- EXPECT_TRUE(consumer()->removed_sessions().empty());
- ContentCaptureFrame expected_data = GetExpectedTestData(
- helper()->test_data(), GetFrameId(true /* main_frame */));
- EXPECT_EQ(expected_data, consumer()->captured_data());
- // Simulate content change.
- main_frame_sender()->DidUpdateContent(helper()->test_data_change());
- EXPECT_TRUE(consumer()->updated_parent_session().empty());
- EXPECT_TRUE(consumer()->removed_sessions().empty());
- EXPECT_EQ(GetExpectedTestData(helper()->test_data_change(), expected_data.id),
- consumer()->updated_data());
- }
- TEST_P(ContentCaptureReceiverTest, DidRemoveSession) {
- main_frame_sender()->DidCaptureContent(helper()->test_data(),
- true /* first_data */);
- // Verifies to get test_data() with correct frame content id.
- EXPECT_TRUE(consumer()->parent_session().empty());
- EXPECT_TRUE(consumer()->removed_sessions().empty());
- EXPECT_EQ(GetExpectedTestData(helper()->test_data(),
- GetFrameId(true /* main_frame */)),
- consumer()->captured_data());
- // Simulates to navigate other document.
- main_frame_sender()->DidCaptureContent(helper()->test_data2(),
- true /* first_data */);
- EXPECT_TRUE(consumer()->parent_session().empty());
- // Verifies that the previous session was removed.
- EXPECT_EQ(1u, consumer()->removed_sessions().size());
- std::vector<ContentCaptureFrame> expected{GetExpectedTestData(
- helper()->test_data(), GetFrameId(true /* main_frame */))};
- VerifySession(expected, consumer()->removed_sessions().front());
- // Verifies that we get the test_data2() from the new document.
- EXPECT_EQ(GetExpectedTestData(helper()->test_data2(),
- GetFrameId(true /* main_frame */)),
- consumer()->captured_data());
- }
- TEST_P(ContentCaptureReceiverTest, DidRemoveContent) {
- main_frame_sender()->DidCaptureContent(helper()->test_data(),
- true /* first_data */);
- // Verifies to get test_data() with correct frame content id.
- EXPECT_TRUE(consumer()->parent_session().empty());
- EXPECT_TRUE(consumer()->removed_sessions().empty());
- EXPECT_EQ(GetExpectedTestData(helper()->test_data(),
- GetFrameId(true /* main_frame */)),
- consumer()->captured_data());
- // Simulates to remove the content.
- main_frame_sender()->DidRemoveContent(expected_removed_ids());
- EXPECT_TRUE(consumer()->parent_session().empty());
- EXPECT_TRUE(consumer()->removed_sessions().empty());
- // Verifies that the removed_ids() was removed from the correct session.
- EXPECT_EQ(expected_removed_ids(), consumer()->removed_ids());
- std::vector<ContentCaptureFrame> expected{GetExpectedTestData(
- helper()->test_data(), GetFrameId(true /* main_frame */))};
- VerifySession(expected, consumer()->session());
- }
- TEST_P(ContentCaptureReceiverTest, ChildFrameDidCaptureContent) {
- // Simulate add child frame.
- SetupChildFrame();
- // Simulate to capture the content from main frame.
- main_frame_sender()->DidCaptureContent(helper()->test_data(),
- true /* first_data */);
- // Verifies to get test_data() with correct frame content id.
- EXPECT_TRUE(consumer()->parent_session().empty());
- EXPECT_TRUE(consumer()->removed_sessions().empty());
- EXPECT_EQ(GetExpectedTestData(helper()->test_data(),
- GetFrameId(true /* main_frame */)),
- consumer()->captured_data());
- // Simulate to capture the content from child frame.
- child_frame_sender()->DidCaptureContent(helper()->test_data2(),
- true /* first_data */);
- // Verifies that the parent_session was set correctly.
- EXPECT_FALSE(consumer()->parent_session().empty());
- std::vector<ContentCaptureFrame> expected{GetExpectedTestData(
- helper()->test_data(), GetFrameId(true /* main_frame */))};
- VerifySession(expected, consumer()->parent_session());
- EXPECT_TRUE(consumer()->removed_sessions().empty());
- // Verifies that we receive the correct content from child frame.
- EXPECT_EQ(GetExpectedTestData(helper()->test_data2(),
- GetFrameId(false /* main_frame */)),
- consumer()->captured_data());
- }
- // This test is for issue crbug.com/995121 .
- TEST_P(ContentCaptureReceiverTest, RenderFrameHostGone) {
- auto* receiver = provider()->ContentCaptureReceiverForFrameForTesting(
- web_contents()->GetPrimaryMainFrame());
- // No good way to simulate crbug.com/995121, just set rfh_ to nullptr in
- // ContentCaptureReceiver, so content::WebContents::FromRenderFrameHost()
- // won't return WebContents.
- receiver->rfh_ = nullptr;
- // Ensure no crash.
- main_frame_sender()->DidCaptureContent(helper()->test_data(),
- true /* first_data */);
- main_frame_sender()->DidUpdateContent(helper()->test_data());
- main_frame_sender()->DidRemoveContent(expected_removed_ids());
- }
- TEST_P(ContentCaptureReceiverTest, TitleUpdateTaskDelay) {
- auto* receiver = provider()->ContentCaptureReceiverForFrameForTesting(
- web_contents()->GetPrimaryMainFrame());
- auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>();
- // Uses TestMockTimeTaskRunner to check the task state.
- receiver->title_update_task_runner_ = task_runner;
- receiver->SetTitle(u"title 1");
- // No task scheduled because no content has been captured.
- EXPECT_FALSE(receiver->notify_title_update_callback_);
- EXPECT_FALSE(task_runner->HasPendingTask());
- // Capture content, then update the title.
- main_frame_sender()->DidCaptureContent(helper()->test_data(),
- /*first_data=*/true);
- std::u16string title2 = u"title 2";
- receiver->SetTitle(title2);
- // A task should be scheduled.
- EXPECT_TRUE(receiver->notify_title_update_callback_);
- EXPECT_TRUE(task_runner->HasPendingTask());
- EXPECT_EQ(2u, receiver->exponential_delay_);
- // Run the pending task.
- task_runner->FastForwardBy(base::Seconds(receiver->exponential_delay_ / 2));
- task_runner->RunUntilIdle();
- // Verify the title is updated and the task is reset.
- EXPECT_EQ(title2, consumer()->updated_title());
- EXPECT_FALSE(receiver->notify_title_update_callback_);
- EXPECT_FALSE(task_runner->HasPendingTask());
- // Set the task_runner again since it is reset after task runs.
- receiver->title_update_task_runner_ = task_runner;
- // Change title again and verify the result.
- receiver->SetTitle(u"title 3");
- EXPECT_TRUE(receiver->notify_title_update_callback_);
- EXPECT_TRUE(task_runner->HasPendingTask());
- EXPECT_EQ(4u, receiver->exponential_delay_);
- // Remove the session to verify the pending task cancelled.
- receiver->RemoveSession();
- EXPECT_FALSE(receiver->notify_title_update_callback_);
- // The cancelled task isn't removed from the TaskRunner, prune it.
- task_runner->TakePendingTasks();
- EXPECT_FALSE(task_runner->HasPendingTask());
- // The delay time is reset after session is removed.
- EXPECT_EQ(1u, receiver->exponential_delay_);
- // Verify the latest task isn't run.
- EXPECT_EQ(title2, consumer()->updated_title());
- }
- // TODO(https://crbug.com/1010416): Fix flakes on win10_chromium_x64_rel_ng and
- // re-enable this test.
- #if BUILDFLAG(IS_WIN)
- #define MAYBE_ChildFrameCaptureContentFirst \
- DISABLED_ChildFrameCaptureContentFirst
- #else
- #define MAYBE_ChildFrameCaptureContentFirst ChildFrameCaptureContentFirst
- #endif
- TEST_P(ContentCaptureReceiverTest, MAYBE_ChildFrameCaptureContentFirst) {
- // Simulate add child frame.
- SetupChildFrame();
- // Simulate to capture the content from child frame.
- child_frame_sender()->DidCaptureContent(helper()->test_data2(),
- true /* first_data */);
- // Verifies that the parent_session was set correctly.
- EXPECT_FALSE(consumer()->parent_session().empty());
- ContentCaptureFrame data = GetExpectedTestData(
- helper()->test_data(), GetFrameId(true /* main_frame */));
- // Currently, there is no way to fake frame size, set it to 0.
- data.bounds = gfx::Rect();
- ContentCaptureSession expected{data};
- VerifySession(expected, consumer()->parent_session());
- EXPECT_TRUE(consumer()->removed_sessions().empty());
- // Verifies that we receive the correct content from child frame.
- EXPECT_EQ(GetExpectedTestData(helper()->test_data2(),
- GetFrameId(false /* main_frame */)),
- consumer()->captured_data());
- // Get the child session, so we can verify that it has been removed in next
- // navigation
- ContentCaptureFrame child_frame = GetExpectedTestData(
- helper()->test_data2(), GetFrameId(false /* main_frame */));
- // child_frame.children.clear();
- ContentCaptureSession removed_child_session;
- BuildChildSession(expected, consumer()->captured_data(),
- &removed_child_session);
- ContentCaptureSession removed_main_session = expected;
- // When main frame navigates to same url, the parent session will not change.
- NavigateMainFrame(GURL(kMainFrameUrl));
- SetupChildFrame();
- child_frame_sender()->DidCaptureContent(helper()->test_data2(),
- true /* first_data */);
- VerifySession(expected, consumer()->parent_session());
- EXPECT_EQ(2u, consumer()->removed_sessions().size());
- VerifySession(removed_child_session, consumer()->removed_sessions().back());
- VerifySession(removed_main_session, consumer()->removed_sessions().front());
- // Get main and child session to verify that they are removed in next
- // navigateion.
- removed_main_session = expected;
- BuildChildSession(expected, consumer()->captured_data(),
- &removed_child_session);
- // When main frame navigates to same domain, the parent session will change.
- NavigateMainFrame(GURL(kMainFrameUrl2));
- SetupChildFrame();
- child_frame_sender()->DidCaptureContent(helper()->test_data2(),
- true /* first_data */);
- // Intentionally reuse the data.id from previous result, so we know navigating
- // to same domain didn't create new ContentCaptureReceiver when call
- // VerifySession(), otherwise, we can't test the code to handle the navigation
- // in ContentCaptureReceiver. - except when ProactivelySwapBrowsingInstance
- // or RenderDocument is enabled on same-site main frame navigation, where we
- // will get new RenderFrameHosts after the navigation to |kMainFrameUrl2|.
- if (content::CanSameSiteMainFrameNavigationsChangeRenderFrameHosts())
- data = GetExpectedTestData(helper()->test_data(),
- GetFrameId(true /* main_frame */));
- data.url = kMainFrameUrl2;
- // Currently, there is no way to fake frame size, set it to 0.
- data.bounds = gfx::Rect();
- expected.clear();
- expected.push_back(data);
- VerifySession(expected, consumer()->parent_session());
- // There are two sessions removed, one the main frame because we navigate to
- // different URL (though the domain is same), another one is child frame
- // because of the main frame change.
- EXPECT_EQ(2u, consumer()->removed_sessions().size());
- VerifySession(removed_child_session, consumer()->removed_sessions().back());
- VerifySession(removed_main_session, consumer()->removed_sessions().front());
- // Keep current sessions to verify removed sessions later.
- removed_main_session = expected;
- BuildChildSession(expected, consumer()->captured_data(),
- &removed_child_session);
- // When main frame navigates to different domain, the parent session will
- // change.
- NavigateMainFrame(GURL(kChildFrameUrl));
- SetupChildFrame();
- child_frame_sender()->DidCaptureContent(helper()->test_data2(),
- true /* first_data */);
- data = GetExpectedTestData(helper()->test_data2(),
- GetFrameId(true /* main_frame */));
- // Currently, there is no way to fake frame size, set it to 0.
- data.bounds = gfx::Rect();
- expected.clear();
- expected.push_back(data);
- VerifySession(expected, consumer()->parent_session());
- EXPECT_EQ(2u, consumer()->removed_sessions().size());
- VerifySession(removed_child_session, consumer()->removed_sessions().back());
- VerifySession(removed_main_session, consumer()->removed_sessions().front());
- // Keep current sessions to verify removed sessions later.
- removed_main_session = expected;
- BuildChildSession(expected, consumer()->captured_data(),
- &removed_child_session);
- session_removed_test_helper()->Reset();
- DeleteContents();
- EXPECT_EQ(2u, session_removed_test_helper()->removed_sessions().size());
- VerifySession(removed_child_session,
- session_removed_test_helper()->removed_sessions().front());
- VerifySession(removed_main_session,
- session_removed_test_helper()->removed_sessions().back());
- }
- TEST_P(ContentCaptureReceiverTest, SameDocumentSameSession) {
- main_frame_sender()->DidCaptureContent(helper()->test_data(),
- true /* first_data */);
- // Verifies to get test_data() with correct frame content id.
- EXPECT_TRUE(consumer()->parent_session().empty());
- EXPECT_TRUE(consumer()->removed_sessions().empty());
- EXPECT_EQ(GetExpectedTestData(helper()->test_data(),
- GetFrameId(true /* main_frame */)),
- consumer()->captured_data());
- NavigateMainFrameSameDocument();
- // Verifies the session wasn't removed for the same document navigation.
- EXPECT_TRUE(consumer()->removed_sessions().empty());
- }
- TEST_P(ContentCaptureReceiverTest, ConvertFaviconURLToJSON) {
- std::vector<blink::mojom::FaviconURLPtr> favicon_urls;
- EXPECT_TRUE(ContentCaptureReceiver::ToJSON(favicon_urls).empty());
- favicon_urls.push_back(blink::mojom::FaviconURL::New(
- GURL{"https://a.com"}, blink::mojom::FaviconIconType::kFavicon,
- std::vector<gfx::Size>{gfx::Size(10, 10)}));
- favicon_urls.push_back(blink::mojom::FaviconURL::New(
- GURL{"https://b.com"}, blink::mojom::FaviconIconType::kTouchIcon,
- std::vector<gfx::Size>{gfx::Size(100, 100), gfx::Size(20, 20)}));
- favicon_urls.push_back(blink::mojom::FaviconURL::New(
- GURL{"https://c.com"},
- blink::mojom::FaviconIconType::kTouchPrecomposedIcon,
- std::vector<gfx::Size>{}));
- std::string actual_json = ContentCaptureReceiver::ToJSON(favicon_urls);
- absl::optional<base::Value> actual = base::JSONReader::Read(actual_json);
- std::string expected_json =
- R"JSON(
- [
- {
- "sizes":[{"height":10,"width":10}],
- "type":"favicon",
- "url":"https://a.com/"
- },
- {
- "sizes":[{"height":100,"width":100},
- {"height":20,"width":20}],
- "type":"touch icon",
- "url":"https://b.com/"
- },
- {
- "type":"touch precomposed icon",
- "url":"https://c.com/"
- }
- ]
- )JSON";
- absl::optional<base::Value> expected = base::JSONReader::Read(expected_json);
- EXPECT_TRUE(actual);
- EXPECT_EQ(expected, actual);
- }
- class ContentCaptureReceiverMultipleFrameTest
- : public content::RenderViewHostTestHarness {
- public:
- void SetUp() override {
- // Setup multiple frames before creates OnscreenContentProvider.
- content::RenderViewHostTestHarness::SetUp();
- // This needed to keep the WebContentsObserverConsistencyChecker checks
- // happy for when AppendChild is called.
- NavigateAndCommit(GURL("about:blank"));
- content::RenderFrameHostTester::For(web_contents()->GetPrimaryMainFrame())
- ->AppendChild("child");
- helper_.CreateProviderAndConsumer(web_contents());
- }
- OnscreenContentProvider* provider() const {
- return helper_.onscreen_content_provider();
- }
- private:
- ContentCaptureTestHelper helper_;
- };
- // TODO(https://crbug.com/1010417): Fix flakes on win10_chromium_x64_rel_ng and
- // re-enable this test.
- #if BUILDFLAG(IS_WIN)
- #define MAYBE_ReceiverCreatedForExistingFrame \
- DISABLED_ReceiverCreatedForExistingFrame
- #else
- #define MAYBE_ReceiverCreatedForExistingFrame ReceiverCreatedForExistingFrame
- #endif
- TEST_F(ContentCaptureReceiverMultipleFrameTest,
- MAYBE_ReceiverCreatedForExistingFrame) {
- EXPECT_EQ(2u, provider()->GetFrameMapSizeForTesting());
- }
- } // namespace content_capture
|