#include <algorithm>
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include "base/command_line.h"
#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/logging.h"
#include "base/run_loop.h"
#include "base/strings/string_util.h"
#include "base/strings/to_string.h"
#include "base/test/test_timeouts.h"
#include "base/test/values_test_util.h"
#include "base/threading/platform_thread.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/headless/headless_mode_browsertest.h"
#include "chrome/common/chrome_switches.h"
#include "components/headless/command_handler/headless_command_handler.h"
#include "components/headless/command_handler/headless_command_switches.h"
#include "components/headless/test/bitmap_utils.h"
#include "components/headless/test/capture_std_stream.h"
#include "components/headless/test/pdf_utils.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "pdf/pdf.h"
#include "printing/buildflags/buildflags.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/display/display_switches.h"
#include "ui/gfx/codec/png_codec.h"
#include "url/gurl.h"
namespace headless {
namespace {
bool DecodePNG(const std::string& png_data, SkBitmap* bitmap) { … }
}
class HeadlessModeCommandBrowserTest : public HeadlessModeBrowserTest { … };
#define HEADLESS_MODE_COMMAND_BROWSER_TEST_WITH_TARGET_URL( \
test_fixture, test_name, target_url) …
class HeadlessModeCommandBrowserTestWithTempDir
: public HeadlessModeCommandBrowserTest { … };
class HeadlessModeDumpDomCommandBrowserTestBase
: public HeadlessModeCommandBrowserTest { … };
class HeadlessModeDumpDomCommandBrowserTest
: public HeadlessModeDumpDomCommandBrowserTestBase,
public testing::WithParamInterface<bool> { … };
INSTANTIATE_TEST_SUITE_P(…);
#if BUILDFLAG(IS_MAC)
#define MAYBE_HeadlessDumpDom …
#else
#define MAYBE_HeadlessDumpDom …
#endif
IN_PROC_BROWSER_TEST_P(HeadlessModeDumpDomCommandBrowserTest,
MAYBE_HeadlessDumpDom) { … }
class HeadlessModeDumpDomCommandBrowserTestWithTimeoutBase
: public HeadlessModeDumpDomCommandBrowserTestBase { … };
class HeadlessModeDumpDomCommandBrowserTestWithTimeout
: public HeadlessModeDumpDomCommandBrowserTestWithTimeoutBase { … };
IN_PROC_BROWSER_TEST_F(HeadlessModeDumpDomCommandBrowserTestWithTimeout,
HeadlessDumpDomWithTimeout) { … }
class HeadlessModeDumpDomCommandBrowserTestWithSubResourceTimeout
: public HeadlessModeDumpDomCommandBrowserTestWithTimeoutBase,
public testing::WithParamInterface<bool> { … };
INSTANTIATE_TEST_SUITE_P(…);
IN_PROC_BROWSER_TEST_P(
HeadlessModeDumpDomCommandBrowserTestWithSubResourceTimeout,
HeadlessDumpDomWithSubResourceTimeout) { … }
HEADLESS_MODE_COMMAND_BROWSER_TEST_WITH_TARGET_URL(
HeadlessModeDumpDomCommandBrowserTestBase,
DumpDomWithBeforeUnloadPreventDefault,
"/before_unload_prevent_default.html") { … }
class HeadlessModeScreenshotCommandBrowserTest
: public HeadlessModeCommandBrowserTestWithTempDir { … };
IN_PROC_BROWSER_TEST_F(HeadlessModeScreenshotCommandBrowserTest,
HeadlessScreenshot) { … }
class HeadlessModeScreenshotCommandWithWindowSizeBrowserTest
: public HeadlessModeScreenshotCommandBrowserTest { … };
IN_PROC_BROWSER_TEST_F(HeadlessModeScreenshotCommandWithWindowSizeBrowserTest,
HeadlessScreenshotWithWindowSize) { … }
class HeadlessModeScreenshotCommandWithBackgroundBrowserTest
: public HeadlessModeScreenshotCommandBrowserTest { … };
IN_PROC_BROWSER_TEST_F(HeadlessModeScreenshotCommandWithBackgroundBrowserTest,
HeadlessScreenshotWithBackground) { … }
class HeadlessModePrintToPdfCommandBrowserTestBase
: public HeadlessModeCommandBrowserTestWithTempDir { … };
class HeadlessModePrintToPdfCommandBrowserTest
: public HeadlessModePrintToPdfCommandBrowserTestBase { … };
#if BUILDFLAG(IS_MAC)
#define MAYBE_HeadlessPrintToPdf …
#else
#define MAYBE_HeadlessPrintToPdf …
#endif
IN_PROC_BROWSER_TEST_F(HeadlessModePrintToPdfCommandBrowserTest,
MAYBE_HeadlessPrintToPdf) { … }
HEADLESS_MODE_COMMAND_BROWSER_TEST_WITH_TARGET_URL(
HeadlessModePrintToPdfCommandBrowserTestBase,
PrintToPdfWithLazyLoading,
"/page_with_lazy_image.html") { … }
class HeadlessModeTaggedPrintToPdfCommandBrowserTest
: public HeadlessModePrintToPdfCommandBrowserTestBase,
public ::testing::WithParamInterface<bool> { … };
const char kExpectedStructTreeJSON[] = …;
INSTANTIATE_TEST_SUITE_P(…);
IN_PROC_BROWSER_TEST_P(HeadlessModeTaggedPrintToPdfCommandBrowserTest,
HeadlessTaggedPrintToPdf) { … }
}