#include <memory>
#include <optional>
#include <tuple>
#include <utility>
#include <vector>
#include "base/check_op.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/browser/printing/print_browsertest.h"
#include "chrome/browser/printing/print_job.h"
#include "chrome/browser/printing/print_test_utils.h"
#include "chrome/browser/printing/print_view_manager_base.h"
#include "chrome/browser/printing/print_view_manager_common.h"
#include "chrome/browser/printing/printer_query.h"
#include "chrome/browser/printing/test_print_preview_observer.h"
#include "chrome/browser/printing/test_print_view_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/enterprise/buildflags/buildflags.h"
#include "content/public/browser/global_routing_id.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/no_renderer_crashes_assertion.h"
#include "mojo/public/cpp/bindings/pending_associated_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "printing/buildflags/buildflags.h"
#include "printing/mojom/print.mojom.h"
#include "printing/printing_context.h"
#include "printing/printing_features.h"
#include "printing/printing_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/size_f.h"
#if BUILDFLAG(ENABLE_OOP_PRINTING)
#include "chrome/browser/printing/print_backend_service_manager.h"
#include "chrome/browser/printing/print_backend_service_test_impl.h"
#include "chrome/browser/printing/print_job_worker_oop.h"
#include "chrome/browser/printing/print_preview_dialog_controller.h"
#include "chrome/browser/printing/printer_query_oop.h"
#include "chrome/browser/task_manager/task_manager_browsertest_util.h"
#include "chrome/browser/task_manager/task_manager_interface.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/services/printing/public/mojom/print_backend_service.mojom.h"
#endif
#if BUILDFLAG(ENTERPRISE_CONTENT_ANALYSIS)
#include "chrome/browser/enterprise/connectors/analysis/content_analysis_dialog.h"
#include "chrome/browser/enterprise/connectors/common.h"
#include "chrome/browser/enterprise/connectors/test/deep_scanning_test_utils.h"
#include "chrome/browser/enterprise/connectors/test/fake_content_analysis_delegate.h"
#include "chrome/browser/policy/dm_token_utils.h"
#include "components/enterprise/common/proto/connectors.pb.h"
#if BUILDFLAG(ENTERPRISE_LOCAL_CONTENT_ANALYSIS)
#include "chrome/browser/enterprise/connectors/test/fake_content_analysis_sdk_manager.h"
#endif
#endif
#if BUILDFLAG(IS_CHROMEOS)
#error "ChromeOS not supported here yet"
#endif
TaskManagerInterface;
MatchAnyTab;
MatchUtility;
WaitForTaskManagerRows;
namespace printing {
namespace {
#if BUILDFLAG(ENABLE_OOP_PRINTING) && !BUILDFLAG(IS_CHROMEOS)
constexpr gfx::SizeF kLetterPhysicalSize = …;
constexpr gfx::RectF kLetterPrintableArea = …;
constexpr gfx::SizeF kLegalPhysicalSize = …;
constexpr gfx::RectF kLegalPrintableArea = …;
constexpr gfx::SizeF kLetterExpectedContentSize = …;
constexpr gfx::SizeF kLegalExpectedContentSize = …;
#endif
#if BUILDFLAG(ENTERPRISE_CONTENT_ANALYSIS)
constexpr char kFakeDmToken[] = …;
constexpr char kCloudAnalysisBlockingPolicy[] = …;
constexpr char kCloudAnalysisNonBlockingPolicy[] = …;
#if BUILDFLAG(ENTERPRISE_LOCAL_CONTENT_ANALYSIS)
constexpr char kLocalAnalysisPolicy[] = …;
#endif
OnDidCompositeForContentAnalysis;
#endif
#if BUILDFLAG(ENABLE_OOP_PRINTING)
void CancelPrintPreview(content::WebContents* preview_dialog) { … }
enum class PrintBackendFeatureVariation { … };
const char* GetPrintBackendString(PrintBackendFeatureVariation variation) { … }
enum class PlatformPrintApiVariation { … };
const char* GetPlatformPrintApiString(PlatformPrintApiVariation variation) { … }
struct PrintBackendAndPlatformPrintApiVariation { … };
constexpr PrintBackendAndPlatformPrintApiVariation
kSandboxedServicePlatformPrintLanguageApiVariations[] = …;
std::string GetPrintBackendAndPlatformPrintApiString(
const PrintBackendAndPlatformPrintApiVariation& variation) { … }
std::string GetPrintBackendAndPlatformPrintApiTestSuffix(
const testing::TestParamInfo<PrintBackendAndPlatformPrintApiVariation>&
info) { … }
std::vector<PrintBackendAndPlatformPrintApiVariation>
GeneratePrintBackendAndPlatformPrintApiVariations(
std::vector<PrintBackendFeatureVariation> print_backend_variations) { … }
std::string GetServiceLaunchTimingTestSuffix(
const testing::TestParamInfo<bool>& info) { … }
#endif
}
#if BUILDFLAG(ENABLE_OOP_PRINTING)
OnUseDefaultSettingsCallback;
OnGetSettingsWithUICallback;
ErrorCheckCallback;
OnDidUseDefaultSettingsCallback;
#if BUILDFLAG(ENABLE_OOP_BASIC_PRINT_DIALOG)
using OnDidAskUserForSettingsCallback =
base::RepeatingCallback<void(mojom::ResultCode result)>;
#endif
OnDidUpdatePrintSettingsCallback;
OnFinishDocumentDoneCallback;
OnDidStartPrintingCallback;
#if BUILDFLAG(IS_WIN)
using OnDidRenderPrintedPageCallback =
base::RepeatingCallback<void(uint32_t page_number,
mojom::ResultCode result)>;
#endif
OnDidRenderPrintedDocumentCallback;
OnDidDocumentDoneCallback;
OnDidCancelCallback;
OnDidShowErrorDialog;
class TestPrintJobWorker : public PrintJobWorker { … };
class TestPrinterQuery : public PrinterQuery { … };
class TestPrintJobWorkerOop : public PrintJobWorkerOop { … };
class TestPrinterQueryOop : public PrinterQueryOop { … };
#endif
class SystemAccessProcessPrintBrowserTestBase
: public PrintBrowserTest,
public PrintJob::Observer,
public PrintViewManagerBase::TestObserver { … };
#if BUILDFLAG(ENABLE_OOP_PRINTING)
class SystemAccessProcessUnsandboxedEarlyStartServicePrintBrowserTest
: public SystemAccessProcessPrintBrowserTestBase,
public testing::WithParamInterface<bool> { … };
INSTANTIATE_TEST_SUITE_P(…);
class SystemAccessProcessPrintBrowserTest
: public SystemAccessProcessPrintBrowserTestBase,
public testing::WithParamInterface<
PrintBackendAndPlatformPrintApiVariation> { … };
INSTANTIATE_TEST_SUITE_P(…);
SystemAccessProcessServicePrintBrowserTest;
INSTANTIATE_TEST_SUITE_P(…);
SystemAccessProcessSandboxedServicePrintBrowserTest;
INSTANTIATE_TEST_SUITE_P(…);
SystemAccessProcessSandboxedServiceLanguagePrintBrowserTest;
INSTANTIATE_TEST_SUITE_P(…);
IN_PROC_BROWSER_TEST_P(
SystemAccessProcessUnsandboxedEarlyStartServicePrintBrowserTest,
ServiceLaunched) { … }
IN_PROC_BROWSER_TEST_P(SystemAccessProcessPrintBrowserTest,
UpdatePrintSettings) { … }
IN_PROC_BROWSER_TEST_P(SystemAccessProcessPrintBrowserTest,
UpdatePrintSettingsPrintableArea) { … }
IN_PROC_BROWSER_TEST_P(SystemAccessProcessPrintBrowserTest,
UpdatePrintSettingsFails) { … }
IN_PROC_BROWSER_TEST_P(SystemAccessProcessPrintBrowserTest,
PrintWithPreviewBeforeLoadedUpdatePrintSettingsFails) { … }
IN_PROC_BROWSER_TEST_P(
SystemAccessProcessSandboxedServiceLanguagePrintBrowserTest,
StartPrinting) { … }
IN_PROC_BROWSER_TEST_P(SystemAccessProcessSandboxedServicePrintBrowserTest,
StartPrintingMultipage) { … }
IN_PROC_BROWSER_TEST_P(SystemAccessProcessServicePrintBrowserTest,
StartPrintingSpoolingSharedMemoryError) { … }
#if BUILDFLAG(IS_WIN)
IN_PROC_BROWSER_TEST_P(SystemAccessProcessPrintBrowserTest,
StartPrintingPdfConversionFails) {
AddPrinter("printer1");
SetPrinterNameForSubsequentContexts("printer1");
PrimeForPdfConversionErrorOnPageIndex(1);
ASSERT_TRUE(embedded_test_server()->Started());
GURL url(embedded_test_server()->GetURL("/printing/3_pages.html"));
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url));
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(web_contents);
SetUpPrintViewManager(web_contents);
if (UseService()) {
SetNumExpectedMessages(4);
} else {
SetNumExpectedMessages(2);
}
PrintAfterPreviewIsReadyAndLoaded();
if (UseService()) {
EXPECT_EQ(start_printing_result(), mojom::ResultCode::kSuccess);
} else {
EXPECT_THAT(in_process_last_error_result_code(),
testing::Optional(mojom::ResultCode::kCanceled));
}
EXPECT_EQ(error_dialog_shown_count(), 0u);
EXPECT_EQ(print_job_destruction_count(), 1);
}
#endif
IN_PROC_BROWSER_TEST_P(SystemAccessProcessPrintBrowserTest,
StartPrintingFails) { … }
IN_PROC_BROWSER_TEST_P(SystemAccessProcessPrintBrowserTest,
StartPrintingCanceled) { … }
IN_PROC_BROWSER_TEST_P(SystemAccessProcessSandboxedServicePrintBrowserTest,
StartPrintingAccessDenied) { … }
IN_PROC_BROWSER_TEST_P(SystemAccessProcessSandboxedServicePrintBrowserTest,
StartPrintingRepeatedAccessDenied) { … }
#if BUILDFLAG(IS_WIN)
IN_PROC_BROWSER_TEST_P(SystemAccessProcessSandboxedServicePrintBrowserTest,
StartPrintingRenderPageAccessDenied) {
AddPrinter("printer1");
SetPrinterNameForSubsequentContexts("printer1");
PrimeForAccessDeniedErrorsInRenderPrintedPage();
ASSERT_TRUE(embedded_test_server()->Started());
GURL url(embedded_test_server()->GetURL("/printing/test3.html"));
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url));
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(web_contents);
SetUpPrintViewManager(web_contents);
SetNumExpectedMessages(6);
PrintAfterPreviewIsReadyAndLoaded();
EXPECT_EQ(start_printing_result(), mojom::ResultCode::kSuccess);
EXPECT_EQ(render_printed_page_result(), mojom::ResultCode::kAccessDenied);
EXPECT_EQ(render_printed_page_count(), 0);
EXPECT_EQ(error_dialog_shown_count(), 1u);
EXPECT_EQ(cancel_count(), 1);
EXPECT_EQ(print_job_destruction_count(), 1);
}
IN_PROC_BROWSER_TEST_P(SystemAccessProcessSandboxedServicePrintBrowserTest,
StartPrintingMultipageMidJobError) {
AddPrinter("printer1");
SetPrinterNameForSubsequentContexts("printer1");
PrimeForDelayedRenderingUntilPage(3);
PrimeForRenderingErrorOnPage(2);
ASSERT_TRUE(embedded_test_server()->Started());
GURL url(embedded_test_server()->GetURL("/printing/3_pages.html"));
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url));
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(web_contents);
SetUpPrintViewManager(web_contents);
SetNumExpectedMessages(8);
PrintAfterPreviewIsReadyAndLoaded();
EXPECT_EQ(start_printing_result(), mojom::ResultCode::kSuccess);
EXPECT_EQ(render_printed_page_result(), mojom::ResultCode::kCanceled);
EXPECT_EQ(render_printed_page_count(), 1);
EXPECT_EQ(error_dialog_shown_count(), 1u);
EXPECT_EQ(cancel_count(), 1);
EXPECT_EQ(print_job_destruction_count(), 1);
}
#endif
#if !BUILDFLAG(IS_WIN)
IN_PROC_BROWSER_TEST_P(SystemAccessProcessSandboxedServicePrintBrowserTest,
StartPrintingRenderDocumentAccessDenied) { … }
#endif
IN_PROC_BROWSER_TEST_P(SystemAccessProcessSandboxedServicePrintBrowserTest,
StartPrintingDocumentDoneAccessDenied) { … }
#if BUILDFLAG(ENABLE_BASIC_PRINT_DIALOG)
IN_PROC_BROWSER_TEST_P(SystemAccessProcessPrintBrowserTest,
SystemPrintFromPrintPreview) { … }
#if BUILDFLAG(IS_WIN)
IN_PROC_BROWSER_TEST_P(SystemAccessProcessPrintBrowserTest,
SystemPrintFromPrintPreviewUpdatePrintSettingsFails) {
AddPrinter("printer1");
SetPrinterNameForSubsequentContexts("printer1");
PrimeForFailInUpdatePrinterSettings();
ASSERT_TRUE(embedded_test_server()->Started());
GURL url(embedded_test_server()->GetURL("/printing/test3.html"));
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url));
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(web_contents);
SetUpPrintViewManager(web_contents);
SetNumExpectedMessages(2);
SystemPrintFromPreviewOnceReadyAndLoaded(true);
EXPECT_EQ(update_print_settings_result(), mojom::ResultCode::kFailed);
EXPECT_EQ(error_dialog_shown_count(), 1u);
}
IN_PROC_BROWSER_TEST_P(
SystemAccessProcessSandboxedServicePrintBrowserTest,
PrintPreviewAfterSystemPrintFromPrintPreviewUpdatePrintSettingsFails) {
AddPrinter("printer1");
SetPrinterNameForSubsequentContexts("printer1");
PrimeForFailInUpdatePrinterSettings();
ASSERT_TRUE(embedded_test_server()->Started());
GURL url(embedded_test_server()->GetURL("/printing/test3.html"));
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url));
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(web_contents);
SetUpPrintViewManager(web_contents);
SetCheckForPrintPreviewDone(true);
SetNumExpectedMessages(3);
SystemPrintFromPreviewOnceReadyAndLoaded(true);
EXPECT_EQ(update_print_settings_result(), mojom::ResultCode::kFailed);
EXPECT_EQ(error_dialog_shown_count(), 1u);
PrepareRunloop();
ResetNumReceivedMessages();
SetCheckForPrintPreviewDone(false);
SetNumExpectedMessages(2);
PrintAfterPreviewIsReadyAndLoaded();
EXPECT_EQ(update_print_settings_result(), mojom::ResultCode::kFailed);
EXPECT_EQ(error_dialog_shown_count(), 2u);
}
IN_PROC_BROWSER_TEST_P(SystemAccessProcessSandboxedServicePrintBrowserTest,
SystemPrintFromPrintPreviewCancelRetry) {
AddPrinter("printer1");
SetPrinterNameForSubsequentContexts("printer1");
PrimeForCancelInAskUserForSettings();
ASSERT_TRUE(embedded_test_server()->Started());
GURL url(embedded_test_server()->GetURL("/printing/test3.html"));
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url));
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(web_contents);
SetUpPrintViewManager(web_contents);
SetCheckForPrintPreviewDone(true);
SetNumExpectedMessages(2);
SystemPrintFromPreviewOnceReadyAndLoaded(true);
EXPECT_EQ(update_print_settings_result(), mojom::ResultCode::kCanceled);
EXPECT_EQ(error_dialog_shown_count(), 0u);
EXPECT_EQ(print_job_destruction_count(), 0);
PrepareRunloop();
ResetNumReceivedMessages();
SystemPrintFromPreviewOnceReadyAndLoaded(true);
EXPECT_EQ(update_print_settings_result(), mojom::ResultCode::kCanceled);
EXPECT_EQ(error_dialog_shown_count(), 0u);
EXPECT_EQ(print_job_destruction_count(), 0);
}
IN_PROC_BROWSER_TEST_P(SystemAccessProcessPrintBrowserTest,
SystemPrintAfterSystemPrintFromPrintPreview) {
AddPrinter("printer1");
SetPrinterNameForSubsequentContexts("printer1");
PrimeForCancelInAskUserForSettings();
ASSERT_TRUE(embedded_test_server()->Started());
GURL url(embedded_test_server()->GetURL("/printing/test3.html"));
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url));
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(web_contents);
SetUpPrintViewManager(web_contents);
SetCheckForPrintPreviewDone(true);
if (UseService()) {
SetNumExpectedMessages(2);
} else {
SetNumExpectedMessages(2);
}
SystemPrintFromPreviewOnceReadyAndLoaded(true);
if (UseService()) {
EXPECT_EQ(update_print_settings_result(), mojom::ResultCode::kCanceled);
} else {
EXPECT_FALSE(did_use_default_settings());
EXPECT_FALSE(did_get_settings_with_ui());
EXPECT_FALSE(print_backend_service_use_detected());
}
PrepareRunloop();
ResetNumReceivedMessages();
SetNumExpectedMessages(2);
StartBasicPrint(web_contents);
WaitUntilCallbackReceived();
if (UseService()) {
EXPECT_EQ(use_default_settings_result(), mojom::ResultCode::kSuccess);
EXPECT_EQ(ask_user_for_settings_result(), mojom::ResultCode::kCanceled);
} else {
EXPECT_TRUE(did_use_default_settings());
EXPECT_TRUE(did_get_settings_with_ui());
}
EXPECT_EQ(error_dialog_shown_count(), 0u);
EXPECT_EQ(print_job_destruction_count(), 0);
}
#endif
IN_PROC_BROWSER_TEST_P(SystemAccessProcessSandboxedServicePrintBrowserTest,
PrintPreviewPrintAfterSystemPrintRendererCrash) { … }
IN_PROC_BROWSER_TEST_P(SystemAccessProcessSandboxedServicePrintBrowserTest,
StartBasicPrint) { … }
IN_PROC_BROWSER_TEST_P(SystemAccessProcessSandboxedServicePrintBrowserTest,
StartBasicPrintPageRanges) { … }
IN_PROC_BROWSER_TEST_P(SystemAccessProcessPrintBrowserTest,
StartBasicPrintCancel) { … }
IN_PROC_BROWSER_TEST_P(SystemAccessProcessPrintBrowserTest,
StartBasicPrintAskUserForSettingsFails) { … }
IN_PROC_BROWSER_TEST_P(SystemAccessProcessPrintBrowserTest,
StartBasicPrintFails) { … }
#if BUILDFLAG(IS_WIN)
IN_PROC_BROWSER_TEST_P(SystemAccessProcessPrintBrowserTest,
StartBasicPrintPdfConversionFails) {
AddPrinter("printer1");
SetPrinterNameForSubsequentContexts("printer1");
PrimeForPdfConversionErrorOnPageIndex(1);
ASSERT_TRUE(embedded_test_server()->Started());
GURL url(embedded_test_server()->GetURL("/printing/3_pages.html"));
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url));
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(web_contents);
SetUpPrintViewManager(web_contents);
if (UseService()) {
SetNumExpectedMessages(6);
} else {
SetNumExpectedMessages(4);
}
StartBasicPrint(web_contents);
WaitUntilCallbackReceived();
if (UseService()) {
EXPECT_EQ(start_printing_result(), mojom::ResultCode::kSuccess);
} else {
EXPECT_THAT(in_process_last_error_result_code(),
testing::Optional(mojom::ResultCode::kCanceled));
}
EXPECT_EQ(error_dialog_shown_count(), 0u);
EXPECT_EQ(print_job_destruction_count(), 1);
}
#endif
#if BUILDFLAG(ENABLE_CONCURRENT_BASIC_PRINT_DIALOGS)
IN_PROC_BROWSER_TEST_P(SystemAccessProcessSandboxedServicePrintBrowserTest,
StartBasicPrintConcurrentAllowed) { … }
#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
IN_PROC_BROWSER_TEST_P(SystemAccessProcessSandboxedServicePrintBrowserTest,
SystemPrintFromPrintPreviewConcurrentAllowed) { … }
#endif
#else
IN_PROC_BROWSER_TEST_P(SystemAccessProcessSandboxedServicePrintBrowserTest,
StartBasicPrintConcurrentNotAllowed) {
ASSERT_TRUE(embedded_test_server()->Started());
GURL url(embedded_test_server()->GetURL("/printing/test3.html"));
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url));
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(web_contents);
TestPrintViewManager* print_view_manager =
SetUpAndReturnPrintViewManager(web_contents);
std::optional<PrintBackendServiceManager::ClientId> client_id =
PrintBackendServiceManager::GetInstance().RegisterQueryWithUiClient();
ASSERT_TRUE(client_id.has_value());
StartBasicPrint(web_contents);
EXPECT_THAT(print_view_manager->print_now_result(), testing::Optional(false));
EXPECT_EQ(error_dialog_shown_count(), 0u);
PrintBackendServiceManager::GetInstance().UnregisterClient(*client_id);
}
#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
IN_PROC_BROWSER_TEST_P(SystemAccessProcessSandboxedServicePrintBrowserTest,
SystemPrintFromPrintPreviewConcurrentNotAllowed) {
AddPrinter("printer1");
SetPrinterNameForSubsequentContexts("printer1");
ASSERT_TRUE(embedded_test_server()->Started());
GURL url(embedded_test_server()->GetURL("/printing/test3.html"));
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url));
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(web_contents);
SetUpPrintViewManager(web_contents);
std::optional<PrintBackendServiceManager::ClientId> client_id =
PrintBackendServiceManager::GetInstance().RegisterQueryWithUiClient();
ASSERT_TRUE(client_id.has_value());
SystemPrintFromPreviewOnceReadyAndLoaded(false);
EXPECT_THAT(system_print_registration_succeeded(), testing::Optional(false));
EXPECT_EQ(error_dialog_shown_count(), 0u);
PrintBackendServiceManager::GetInstance().UnregisterClient(*client_id);
}
#endif
#endif
IN_PROC_BROWSER_TEST_P(SystemAccessProcessServicePrintBrowserTest,
StartBasicPrintUseDefaultFails) { … }
IN_PROC_BROWSER_TEST_P(SystemAccessProcessServicePrintBrowserTest,
StartBasicPrintServiceDisappearsAfterGetSettings) { … }
#if BUILDFLAG(ENABLE_OOP_BASIC_PRINT_DIALOG) && BUILDFLAG(IS_WIN)
IN_PROC_BROWSER_TEST_P(
SystemAccessProcessServicePrintBrowserTest,
SystemPrintFromPrintPreviewUpdatePrintSettingsServiceDisappearsAfterGetSettings) {
AddPrinter("printer1");
SetPrinterNameForSubsequentContexts("printer1");
PrimeForServiceTerminatesAfterUpdatePrintSettings();
SkipPersistentContextsCheckOnShutdown();
ASSERT_TRUE(embedded_test_server()->Started());
GURL url(embedded_test_server()->GetURL("/printing/test3.html"));
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url));
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(web_contents);
SetUpPrintViewManager(web_contents);
SetNumExpectedMessages(2);
SystemPrintFromPreviewOnceReadyAndLoaded(true);
EXPECT_EQ(update_print_settings_result(), mojom::ResultCode::kSuccess);
EXPECT_EQ(error_dialog_shown_count(), 1u);
}
#endif
#endif
#if BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_P(SystemAccessProcessPrintBrowserTest, OpenPdfInPreview) {
AddPrinter("printer1");
SetPrinterNameForSubsequentContexts("printer1");
constexpr int kJobId = 1;
SetNewDocumentJobId(kJobId);
ASSERT_TRUE(embedded_test_server()->Started());
GURL url(embedded_test_server()->GetURL("/printing/test3.html"));
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url));
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(web_contents);
SetUpPrintViewManager(web_contents);
if (UseService()) {
SetNumExpectedMessages(5);
} else {
SetNumExpectedMessages(2);
}
OpenPdfInPreviewOnceReadyAndLoaded();
if (UseService()) {
EXPECT_EQ(start_printing_result(), mojom::ResultCode::kSuccess);
EXPECT_EQ(render_printed_document_result(), mojom::ResultCode::kSuccess);
EXPECT_EQ(document_done_result(), mojom::ResultCode::kSuccess);
} else {
EXPECT_FALSE(in_process_last_error_result_code().has_value());
}
EXPECT_THAT(document_done_job_id(), testing::Optional(kJobId));
EXPECT_TRUE(destination_is_preview());
EXPECT_EQ(error_dialog_shown_count(), 0u);
EXPECT_EQ(print_job_destruction_count(), 1);
}
#endif
#endif
#if BUILDFLAG(ENTERPRISE_CONTENT_ANALYSIS)
class TestPrintViewManagerForContentAnalysis : public TestPrintViewManager { … };
ContentAnalysisConfigurationVariation;
class ContentAnalysisPrintBrowserTestBase
: public SystemAccessProcessPrintBrowserTestBase { … };
class ContentAnalysisAfterPrintPreviewBrowserTest
: public ContentAnalysisPrintBrowserTestBase,
public testing::WithParamInterface<
ContentAnalysisConfigurationVariation> { … };
class ContentAnalysisScriptedPreviewlessPrintBrowserTestBase
: public ContentAnalysisPrintBrowserTestBase,
public testing::WithParamInterface<
ContentAnalysisConfigurationVariation> { … };
class ContentAnalysisScriptedPreviewlessPrintAfterDialogBrowserTest
: public ContentAnalysisScriptedPreviewlessPrintBrowserTestBase { … };
#if !BUILDFLAG(IS_CHROMEOS)
IN_PROC_BROWSER_TEST_P(ContentAnalysisAfterPrintPreviewBrowserTest,
PrintWithPreviewBeforeLoaded) { … }
IN_PROC_BROWSER_TEST_P(ContentAnalysisAfterPrintPreviewBrowserTest,
SystemPrintFromPrintPreview) { … }
#if BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_P(ContentAnalysisAfterPrintPreviewBrowserTest,
OpenPdfInPreviewFromPrintPreview) {
AddPrinter("printer_name");
if (UseService() && !PrintAllowedOrNonBlockingPolicy()) {
SkipPersistentContextsCheckOnShutdown();
}
ASSERT_TRUE(embedded_test_server()->Started());
GURL url(embedded_test_server()->GetURL("/printing/test3.html"));
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url));
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(web_contents);
auto* print_view_manager = SetUpAndReturnPrintViewManagerForContentAnalysis(
web_contents,
enterprise_connectors::ContentAnalysisRequest::PRINT_PREVIEW_PRINT);
if (PrintAllowedOrNonBlockingPolicy()) {
if (UseService()) {
SetNumExpectedMessages(5);
} else {
SetNumExpectedMessages(2);
}
} else {
print_view_manager->set_on_print_preview_done_closure(base::BindOnce(
&ContentAnalysisAfterPrintPreviewBrowserTest::CheckForQuit,
base::Unretained(this)));
SetNumExpectedMessages(1);
}
OpenPdfInPreviewOnceReadyAndLoaded();
EXPECT_THAT(print_view_manager->preview_allowed(), testing::Optional(true));
EXPECT_EQ(print_job_destruction_count(),
PrintAllowedOrNonBlockingPolicy() ? 1 : 0);
EXPECT_EQ(scanning_responses_count(), 1);
EXPECT_EQ(new_document_called_count(), GetExpectedNewDocumentCalledCount());
}
#endif
IN_PROC_BROWSER_TEST_P(
ContentAnalysisScriptedPreviewlessPrintAfterDialogBrowserTest,
PrintNow) { … }
IN_PROC_BROWSER_TEST_P(
ContentAnalysisScriptedPreviewlessPrintAfterDialogBrowserTest,
DocumentExecPrint) { … }
IN_PROC_BROWSER_TEST_P(
ContentAnalysisScriptedPreviewlessPrintAfterDialogBrowserTest,
WindowPrint) { … }
#endif
INSTANTIATE_TEST_SUITE_P(…);
#if BUILDFLAG(ENABLE_BASIC_PRINT_DIALOG)
INSTANTIATE_TEST_SUITE_P(…);
#endif
#endif
}