#include <stdint.h>
#include <memory>
#include "base/containers/span.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "components/download/public/common/download_task_runner.h"
#include "content/browser/download/mhtml_generation_manager.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/common/download/mhtml_file_writer.mojom.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/mhtml_extra_parts.h"
#include "content/public/browser/mhtml_generation_result.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_paths.h"
#include "content/public/common/mhtml_generation_params.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
#include "crypto/secure_hash.h"
#include "crypto/sha2.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "net/base/filename_util.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/cleanup/cleanup.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/mojom/frame/find_in_page.mojom.h"
#if BUILDFLAG(IS_WIN)
#include "base/functional/callback_helpers.h"
#include "base/test/bind.h"
#endif
ContainsRegex;
HasSubstr;
Not;
namespace content {
namespace {
class FindTrackingDelegate : public WebContentsDelegate { … };
int FindTrackingDelegate::global_request_id = …;
const std::string_view kTestData = …;
class MockWriterBase : public mojom::MhtmlFileWriter { … };
class RespondAndDisconnectMockWriter
: public MockWriterBase,
public base::RefCountedThreadSafe<RespondAndDisconnectMockWriter> { … };
}
class MHTMLGenerationTest : public ContentBrowserTest,
public testing::WithParamInterface<bool> { … };
IN_PROC_BROWSER_TEST_P(MHTMLGenerationTest, GenerateMHTML) { … }
#if BUILDFLAG(IS_WIN)
IN_PROC_BROWSER_TEST_P(MHTMLGenerationTest, GenerateMHTMLInNonTempDir) {
base::FilePath local_app_data;
EXPECT_TRUE(
base::PathService::Get(base::DIR_LOCAL_APP_DATA, &local_app_data));
base::FilePath new_dir;
{
base::ScopedAllowBlockingForTesting allow_blocking;
EXPECT_TRUE(base::CreateTemporaryDirInDir(
local_app_data, FILE_PATH_LITERAL("MHTMLGenerationTest"), &new_dir));
}
absl::Cleanup delete_dir = [new_dir] {
base::ScopedAllowBlockingForTesting allow_blocking;
base::DeletePathRecursively(new_dir);
};
base::FilePath path = new_dir.Append(FILE_PATH_LITERAL("test.mht"));
GenerateMHTML(path, embedded_test_server()->GetURL("/simple_page.html"));
EXPECT_GT(file_size(), 0);
EXPECT_GT(ReadFileSizeFromDisk(path), 100);
{
base::ScopedAllowBlockingForTesting allow_blocking;
std::string mhtml;
ASSERT_TRUE(base::ReadFileToString(path, &mhtml));
EXPECT_THAT(mhtml,
HasSubstr("Content-Transfer-Encoding: quoted-printable"));
}
}
#endif
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_GenerateMHTMLAndCloseConnection …
#else
#define MAYBE_GenerateMHTMLAndCloseConnection …
#endif
IN_PROC_BROWSER_TEST_P(MHTMLGenerationTest,
MAYBE_GenerateMHTMLAndCloseConnection) { … }
#if BUILDFLAG(IS_WIN)
#define MAYBE_InvalidPath …
#else
#define MAYBE_InvalidPath …
#endif
IN_PROC_BROWSER_TEST_P(MHTMLGenerationTest, MAYBE_InvalidPath) { … }
IN_PROC_BROWSER_TEST_P(MHTMLGenerationTest, GenerateNonBinaryMHTMLWithImage) { … }
IN_PROC_BROWSER_TEST_P(MHTMLGenerationTest, GenerateBinaryMHTMLWithImage) { … }
IN_PROC_BROWSER_TEST_P(MHTMLGenerationTest, GenerateMHTMLIgnoreNoStore) { … }
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_ViewedMHTMLContainsNoStoreContent …
#else
#define MAYBE_ViewedMHTMLContainsNoStoreContent …
#endif
IN_PROC_BROWSER_TEST_P(MHTMLGenerationTest,
MAYBE_ViewedMHTMLContainsNoStoreContent) { … }
class MHTMLGenerationSitePerProcessTest : public MHTMLGenerationTest { … };
IN_PROC_BROWSER_TEST_P(MHTMLGenerationSitePerProcessTest, GenerateMHTML) { … }
IN_PROC_BROWSER_TEST_P(MHTMLGenerationTest, RemovePopupOverlay) { … }
IN_PROC_BROWSER_TEST_P(MHTMLGenerationTest, GenerateMHTMLWithExtraData) { … }
IN_PROC_BROWSER_TEST_P(MHTMLGenerationTest, GenerateMHTMLWithMultipleFrames) { … }
INSTANTIATE_TEST_SUITE_P(…);
INSTANTIATE_TEST_SUITE_P(…);
}