0

Revert "[unseasoned-pdf] Block 100% loading on PDF layout"

This reverts commit 76d6ade99f.

Causes AnnotationsFeatureEnabled to fail on linux-chromeos-chrome. This
is a partial revert, due to some merge conflicts with later changes.

Bug: 1237952
Change-Id: I504d9a9471332eea265e9260c68d303866cd5839
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3131376
Commit-Queue: K. Moon <kmoon@chromium.org>
Commit-Queue: Hui Yingst <nigi@chromium.org>
Auto-Submit: K. Moon <kmoon@chromium.org>
Reviewed-by: Hui Yingst <nigi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#916626}
This commit is contained in:
K. Moon
2021-08-31 00:54:03 +00:00
committed by Chromium LUCI CQ
parent 952798081e
commit b2960260f1
4 changed files with 23 additions and 80 deletions

@ -412,7 +412,6 @@ if (enable_pdf) {
":ppapi_migration",
"//base",
"//ppapi/cpp:objects",
"//testing/gmock",
"//testing/gtest",
"//third_party/blink/public/common:headers",
"//ui/gfx:geometry_skia",

@ -327,6 +327,7 @@ void PdfViewPluginBase::DocumentLoadComplete() {
SendAttachments();
SendBookmarks();
SendMetadata();
SendLoadingProgress(/*percentage=*/100);
if (accessibility_state_ == AccessibilityState::kPending)
LoadAccessibility();
@ -389,6 +390,7 @@ void PdfViewPluginBase::DocumentLoadProgress(uint32_t available,
if (progress <= last_progress_sent_ + 1)
return;
last_progress_sent_ = progress;
SendLoadingProgress(progress);
}
@ -566,7 +568,6 @@ void PdfViewPluginBase::ConsumeSaveToken(const std::string& token) {
void PdfViewPluginBase::SendLoadingProgress(double percentage) {
DCHECK(percentage == -1 || (percentage >= 0 && percentage <= 100));
last_progress_sent_ = percentage;
base::Value message(base::Value::Type::DICTIONARY);
message.SetStringKey("type", "loadProgress");
@ -1150,10 +1151,6 @@ void PdfViewPluginBase::HandleViewportMessage(const base::Value& message) {
// TODO(crbug.com/1013800): Eliminate need to get document size from here.
document_size_ = engine()->ApplyDocumentLayout(layout_options);
OnGeometryChanged(zoom_, device_scale_);
// Send 100% loading progress only after initial layout negotiated.
if (last_progress_sent_ < 100)
SendLoadingProgress(/*percentage=*/100);
}
gfx::PointF scroll_position(message.FindDoubleKey("xOffset").value(),

@ -19,7 +19,6 @@
#include "pdf/buildflags.h"
#include "pdf/content_restriction.h"
#include "pdf/document_attachment_info.h"
#include "pdf/document_layout.h"
#include "pdf/document_metadata.h"
#include "pdf/pdf_engine.h"
#include "pdf/ppapi_migration/callback.h"
@ -36,7 +35,6 @@ namespace chrome_pdf {
namespace {
using ::testing::ElementsAre;
using ::testing::IsEmpty;
using ::testing::SaveArg;
@ -338,6 +336,13 @@ base::Value CreateExpectedNoMetadataResponse() {
return message;
}
base::Value CreateExpectedLoadingProgressResponse() {
base::Value message(base::Value::Type::DICTIONARY);
message.SetStringKey("type", "loadProgress");
message.SetDoubleKey("progress", 100);
return message;
}
base::Value CreateSaveRequestMessage(PdfViewPluginBase::SaveRequestType type,
const std::string& token) {
base::Value message(base::Value::Type::DICTIONARY);
@ -374,8 +379,8 @@ class PdfViewPluginBaseTest : public testing::Test {
class PdfViewPluginBaseWithEngineTest : public PdfViewPluginBaseTest {
public:
void SetUp() override {
auto engine =
std::make_unique<testing::NiceMock<TestPDFiumEngine>>(&fake_plugin_);
std::unique_ptr<TestPDFiumEngine> engine =
std::make_unique<TestPDFiumEngine>(&fake_plugin_);
fake_plugin_.InitializeEngine(std::move(engine));
}
};
@ -532,7 +537,7 @@ TEST_F(PdfViewPluginBaseWithDocInfoTest,
fake_plugin_.accessibility_state());
// Check all the sent messages.
ASSERT_EQ(4u, fake_plugin_.sent_messages().size());
ASSERT_EQ(5u, fake_plugin_.sent_messages().size());
EXPECT_EQ(CreateExpectedFormTextFieldFocusChangeResponse(),
fake_plugin_.sent_messages()[0]);
EXPECT_EQ(CreateExpectedAttachmentsResponse(),
@ -541,6 +546,8 @@ TEST_F(PdfViewPluginBaseWithDocInfoTest,
CreateExpectedBookmarksResponse(fake_plugin_.engine()->GetBookmarks()),
fake_plugin_.sent_messages()[2]);
EXPECT_EQ(CreateExpectedMetadataResponse(), fake_plugin_.sent_messages()[3]);
EXPECT_EQ(CreateExpectedLoadingProgressResponse(),
fake_plugin_.sent_messages()[4]);
}
TEST_F(PdfViewPluginBaseWithDocInfoTest,
@ -572,7 +579,7 @@ TEST_F(PdfViewPluginBaseWithDocInfoTest,
fake_plugin_.accessibility_state());
// Check all the sent messages.
ASSERT_EQ(4u, fake_plugin_.sent_messages().size());
ASSERT_EQ(5u, fake_plugin_.sent_messages().size());
EXPECT_EQ(CreateExpectedFormTextFieldFocusChangeResponse(),
fake_plugin_.sent_messages()[0]);
EXPECT_EQ(CreateExpectedAttachmentsResponse(),
@ -581,6 +588,8 @@ TEST_F(PdfViewPluginBaseWithDocInfoTest,
CreateExpectedBookmarksResponse(fake_plugin_.engine()->GetBookmarks()),
fake_plugin_.sent_messages()[2]);
EXPECT_EQ(CreateExpectedMetadataResponse(), fake_plugin_.sent_messages()[3]);
EXPECT_EQ(CreateExpectedLoadingProgressResponse(),
fake_plugin_.sent_messages()[4]);
}
TEST_F(PdfViewPluginBaseWithDocInfoTest,
@ -604,7 +613,7 @@ TEST_F(PdfViewPluginBaseWithDocInfoTest,
fake_plugin_.document_load_state());
// Check all the sent messages.
ASSERT_EQ(4u, fake_plugin_.sent_messages().size());
ASSERT_EQ(5u, fake_plugin_.sent_messages().size());
EXPECT_EQ(CreateExpectedFormTextFieldFocusChangeResponse(),
fake_plugin_.sent_messages()[0]);
EXPECT_EQ(CreateExpectedAttachmentsResponse(),
@ -613,6 +622,8 @@ TEST_F(PdfViewPluginBaseWithDocInfoTest,
CreateExpectedBookmarksResponse(fake_plugin_.engine()->GetBookmarks()),
fake_plugin_.sent_messages()[2]);
EXPECT_EQ(CreateExpectedMetadataResponse(), fake_plugin_.sent_messages()[3]);
EXPECT_EQ(CreateExpectedLoadingProgressResponse(),
fake_plugin_.sent_messages()[4]);
}
TEST_F(PdfViewPluginBaseWithoutDocInfoTest, DocumentLoadCompletePostMessages) {
@ -630,11 +641,13 @@ TEST_F(PdfViewPluginBaseWithoutDocInfoTest, DocumentLoadCompletePostMessages) {
// Check the sent messages when the document doesn't have any metadata,
// attachments or bookmarks.
ASSERT_EQ(2u, fake_plugin_.sent_messages().size());
ASSERT_EQ(3u, fake_plugin_.sent_messages().size());
EXPECT_EQ(CreateExpectedFormTextFieldFocusChangeResponse(),
fake_plugin_.sent_messages()[0]);
EXPECT_EQ(CreateExpectedNoMetadataResponse(),
fake_plugin_.sent_messages()[1]);
EXPECT_EQ(CreateExpectedLoadingProgressResponse(),
fake_plugin_.sent_messages()[2]);
}
TEST_F(PdfViewPluginBaseTest, DocumentLoadFailedWithNotifiedRenderFrame) {
@ -875,66 +888,6 @@ TEST_F(PdfViewPluginBaseTest, HandleSetBackgroundColorMessage) {
EXPECT_EQ(kNewBackgroundColor, fake_plugin_.GetBackgroundColor());
}
TEST_F(PdfViewPluginBaseWithEngineTest, HandleViewportMessageInitially) {
auto* engine = static_cast<TestPDFiumEngine*>(fake_plugin_.engine());
EXPECT_CALL(*engine, ApplyDocumentLayout(DocumentLayout::Options()));
fake_plugin_.HandleMessage(base::test::ParseJson(R"({
"type": "viewport",
"userInitiated": false,
"zoom": 1,
"layoutOptions": {
"defaultPageOrientation": 0,
"twoUpViewEnabled": false,
},
"xOffset": 0,
"yOffset": 0,
"pinchPhase": 0,
})"));
EXPECT_THAT(fake_plugin_.sent_messages(), ElementsAre(base::test::IsJson(R"({
"type": "loadProgress",
"progress": 100.0,
})")));
}
TEST_F(PdfViewPluginBaseWithEngineTest, HandleViewportMessageSubsequently) {
auto* engine = static_cast<TestPDFiumEngine*>(fake_plugin_.engine());
fake_plugin_.HandleMessage(base::test::ParseJson(R"({
"type": "viewport",
"userInitiated": false,
"zoom": 1,
"layoutOptions": {
"defaultPageOrientation": 0,
"twoUpViewEnabled": false,
},
"xOffset": 0,
"yOffset": 0,
"pinchPhase": 0,
})"));
fake_plugin_.clear_sent_messages();
DocumentLayout::Options two_up_options;
two_up_options.set_page_spread(DocumentLayout::PageSpread::kTwoUpOdd);
EXPECT_CALL(*engine, ApplyDocumentLayout(two_up_options));
fake_plugin_.HandleMessage(base::test::ParseJson(R"({
"type": "viewport",
"userInitiated": false,
"zoom": 1,
"layoutOptions": {
"defaultPageOrientation": 0,
"twoUpViewEnabled": true,
},
"xOffset": 0,
"yOffset": 0,
"pinchPhase": 0,
})"));
EXPECT_THAT(fake_plugin_.sent_messages(), IsEmpty());
}
TEST_F(PdfViewPluginBaseWithEngineTest, GetContentRestrictions) {
auto* engine = static_cast<TestPDFiumEngine*>(fake_plugin_.engine());
static constexpr int kContentRestrictionCutPaste =

@ -16,7 +16,6 @@
#include "pdf/document_metadata.h"
#include "pdf/pdf_engine.h"
#include "pdf/pdfium/pdfium_engine.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/common/input/web_mouse_event.h"
namespace blink {
@ -41,11 +40,6 @@ class TestPDFiumEngine : public PDFiumEngine {
~TestPDFiumEngine() override;
MOCK_METHOD(gfx::Size,
ApplyDocumentLayout,
(const DocumentLayout::Options&),
(override));
// Sets a scaled mouse event for testing.
bool HandleInputEvent(const blink::WebInputEvent& scaled_event) override;