[PDF Searchify] Do not Searchify Print Preview
The PDF displayed in Print Preview should reflect what is being sent to the printer and should not be modified by Searchify. The minimal PDF Viewer that displays the preview is also not capable of displaying Searchify's UI. Thus it raises JS errors when Searchify tries to ask it to. Add a PDFiumOnDemandSearchifierTest case to show this CL stops Searchify in Print Preview. To do so, enhance SearchifierTestClient to be able to tell PDFiumEngine that it is in Print Preview mode. Along the way, encapsulate SearchifierTestClient. Bug: 405433817, 406530484 Change-Id: I535ece9beb7429a4844c3310add52bc5fd6f1952 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6405712 Reviewed-by: Ramin Halavati <rhalavati@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org> Cr-Commit-Position: refs/heads/main@{#1439561}
This commit is contained in:
parent
6e786c79de
commit
3a745b822c
@ -4410,7 +4410,7 @@ void PDFiumEngine::ScheduleSearchifyIfNeeded(PDFiumPage* page) {
|
||||
CHECK(page);
|
||||
CHECK(page->available());
|
||||
|
||||
if (page->IsPageSearchified()) {
|
||||
if (client_->IsPrintPreview() || page->IsPageSearchified()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,8 @@ class SearchifierTestClient : public TestClient {
|
||||
SearchifierTestClient& operator=(const SearchifierTestClient&) = delete;
|
||||
~SearchifierTestClient() override = default;
|
||||
|
||||
bool IsPrintPreview() const override { return is_print_preview_; }
|
||||
|
||||
void OnSearchifyStateChange(bool busy) override {
|
||||
if (busy) {
|
||||
busy_state_changed_count_++;
|
||||
@ -49,6 +51,13 @@ class SearchifierTestClient : public TestClient {
|
||||
}
|
||||
}
|
||||
|
||||
void set_for_print_preview() { is_print_preview_ = true; }
|
||||
|
||||
int busy_state_changed_count() const { return busy_state_changed_count_; }
|
||||
int idle_state_changed_count() const { return idle_state_changed_count_; }
|
||||
|
||||
private:
|
||||
bool is_print_preview_ = false;
|
||||
int busy_state_changed_count_ = 0;
|
||||
int idle_state_changed_count_ = 0;
|
||||
};
|
||||
@ -116,6 +125,11 @@ class PDFiumOnDemandSearchifierTest : public PDFiumTestBase {
|
||||
ASSERT_TRUE(engine_) << test_filename;
|
||||
}
|
||||
|
||||
void CreatePreviewEngine(const base::FilePath::CharType* test_filename) {
|
||||
client_.set_for_print_preview();
|
||||
CreateEngine(test_filename);
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
// PDFium gets uninitialized via `FPDF_DestroyLibrary`. If `engine_` is not
|
||||
// destroyed here, its destruction results in a crash later.
|
||||
@ -152,10 +166,10 @@ class PDFiumOnDemandSearchifierTest : public PDFiumTestBase {
|
||||
int performed_ocrs() const { return performed_ocrs_; }
|
||||
PDFiumEngine* engine() { return engine_.get(); }
|
||||
int busy_state_changed_count() const {
|
||||
return client_.busy_state_changed_count_;
|
||||
return client_.busy_state_changed_count();
|
||||
}
|
||||
int idle_state_changed_count() const {
|
||||
return client_.idle_state_changed_count_;
|
||||
return client_.idle_state_changed_count();
|
||||
}
|
||||
|
||||
private:
|
||||
@ -400,6 +414,18 @@ TEST_P(PDFiumOnDemandSearchifierTest, MultiplePagesWithUnload) {
|
||||
EXPECT_TRUE(page3_info.value().is_searchified);
|
||||
}
|
||||
|
||||
TEST_P(PDFiumOnDemandSearchifierTest, OnePageWithImagesInPrintPreview) {
|
||||
CreatePreviewEngine(FILE_PATH_LITERAL("image_alt_text.pdf"));
|
||||
|
||||
PDFiumPage& page = GetPDFiumPageForTest(*engine(), 0);
|
||||
|
||||
// Load the page to trigger Searchify, but it should not do anything for Print
|
||||
// Preview.
|
||||
page.GetPage();
|
||||
ASSERT_FALSE(engine()->PageNeedsSearchify(0));
|
||||
ASSERT_FALSE(engine()->GetSearchifierForTesting());
|
||||
}
|
||||
|
||||
TEST_P(PDFiumOnDemandSearchifierTest, OcrCancellation) {
|
||||
constexpr int kPageCount = 4;
|
||||
CreateEngine(FILE_PATH_LITERAL("multi_page_no_text.pdf"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user