0

[pdf] Migrate HandleViewportMessage() tests

Migrates tests exercising PdfViewPluginBase's HandleViewportMessage()
method.

Bug: 1323307
Change-Id: I803d592177aec7ac5d1960b073ee9d9fbe24bbf7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3696544
Commit-Queue: K. Moon <kmoon@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1012615}
This commit is contained in:
K. Moon
2022-06-09 18:17:35 +00:00
committed by Chromium LUCI CQ
parent fc3d19dc90
commit aefb773cce
2 changed files with 127 additions and 143 deletions

@ -15,7 +15,6 @@
#include "base/values.h"
#include "pdf/accessibility_structs.h"
#include "pdf/document_attachment_info.h"
#include "pdf/document_layout.h"
#include "pdf/document_metadata.h"
#include "pdf/pdf_engine.h"
#include "pdf/pdfium/pdfium_form_filler.h"
@ -37,8 +36,6 @@ namespace chrome_pdf {
namespace {
using ::testing::ElementsAre;
using ::testing::IsEmpty;
using ::testing::NiceMock;
using ::testing::Return;
using ::testing::SaveArg;
@ -207,146 +204,6 @@ TEST_F(PdfViewPluginBaseWithEngineTest, HandleInputEvent) {
EXPECT_TRUE(fake_plugin_.HandleInputEvent(mouse_event));
}
TEST_F(PdfViewPluginBaseWithEngineTest,
HandleViewportMessageBeforeDocumentLoadComplete) {
auto* engine = static_cast<TestPDFiumEngine*>(fake_plugin_.engine());
EXPECT_CALL(*engine, ApplyDocumentLayout(DocumentLayout::Options()));
base::Value message = base::test::ParseJson(R"({
"type": "viewport",
"userInitiated": false,
"zoom": 1,
"layoutOptions": {
"direction": 0,
"defaultPageOrientation": 0,
"twoUpViewEnabled": false,
},
"xOffset": 0,
"yOffset": 0,
"pinchPhase": 0,
})");
fake_plugin_.HandleMessage(message.GetDict());
EXPECT_THAT(fake_plugin_.sent_messages(), IsEmpty());
}
TEST_F(PdfViewPluginBaseWithEngineTest,
HandleViewportMessageAfterDocumentLoadComplete) {
auto* engine = static_cast<TestPDFiumEngine*>(fake_plugin_.engine());
EXPECT_CALL(*engine, ApplyDocumentLayout(DocumentLayout::Options()));
fake_plugin_.DocumentLoadComplete();
fake_plugin_.clear_sent_messages();
base::Value message = base::test::ParseJson(R"({
"type": "viewport",
"userInitiated": false,
"zoom": 1,
"layoutOptions": {
"direction": 0,
"defaultPageOrientation": 0,
"twoUpViewEnabled": false,
},
"xOffset": 0,
"yOffset": 0,
"pinchPhase": 0,
})");
fake_plugin_.HandleMessage(message.GetDict());
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());
base::Value message1 = base::test::ParseJson(R"({
"type": "viewport",
"userInitiated": false,
"zoom": 1,
"layoutOptions": {
"direction": 0,
"defaultPageOrientation": 0,
"twoUpViewEnabled": false,
},
"xOffset": 0,
"yOffset": 0,
"pinchPhase": 0,
})");
fake_plugin_.HandleMessage(message1.GetDict());
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));
base::Value message2 = base::test::ParseJson(R"({
"type": "viewport",
"userInitiated": false,
"zoom": 1,
"layoutOptions": {
"direction": 0,
"defaultPageOrientation": 0,
"twoUpViewEnabled": true,
},
"xOffset": 0,
"yOffset": 0,
"pinchPhase": 0,
})");
fake_plugin_.HandleMessage(message2.GetDict());
EXPECT_THAT(fake_plugin_.sent_messages(), IsEmpty());
}
TEST_F(PdfViewPluginBaseWithEngineTest, HandleViewportMessageScroll) {
auto* engine = static_cast<TestPDFiumEngine*>(fake_plugin_.engine());
EXPECT_CALL(*engine, ApplyDocumentLayout)
.WillRepeatedly(Return(gfx::Size(16, 9)));
EXPECT_CALL(*engine, ScrolledToXPosition(2));
EXPECT_CALL(*engine, ScrolledToYPosition(3));
base::Value message = base::test::ParseJson(R"({
"type": "viewport",
"userInitiated": false,
"zoom": 1,
"layoutOptions": {
"direction": 2,
"defaultPageOrientation": 0,
"twoUpViewEnabled": false,
},
"xOffset": 2,
"yOffset": 3,
"pinchPhase": 0,
})");
fake_plugin_.HandleMessage(message.GetDict());
}
TEST_F(PdfViewPluginBaseWithEngineTest,
HandleViewportMessageScrollRightToLeft) {
auto* engine = static_cast<TestPDFiumEngine*>(fake_plugin_.engine());
EXPECT_CALL(*engine, ApplyDocumentLayout)
.WillRepeatedly(Return(gfx::Size(16, 9)));
EXPECT_CALL(*engine, ScrolledToXPosition(2));
EXPECT_CALL(*engine, ScrolledToYPosition(3));
base::Value message = base::test::ParseJson(R"({
"type": "viewport",
"userInitiated": false,
"zoom": 1,
"layoutOptions": {
"direction": 1,
"defaultPageOrientation": 0,
"twoUpViewEnabled": false,
},
"xOffset": 2,
"yOffset": 3,
"pinchPhase": 0,
})");
fake_plugin_.HandleMessage(message.GetDict());
}
TEST_F(PdfViewPluginBaseWithEngineTest, UpdateScroll) {
auto* engine = static_cast<TestPDFiumEngine*>(fake_plugin_.engine());
EXPECT_CALL(*engine, ScrolledToXPosition(0));

@ -31,6 +31,7 @@
#include "pdf/accessibility_structs.h"
#include "pdf/buildflags.h"
#include "pdf/content_restriction.h"
#include "pdf/document_layout.h"
#include "pdf/mojom/pdf.mojom.h"
#include "pdf/paint_ready_rect.h"
#include "pdf/pdf_accessibility_data_handler.h"
@ -1136,6 +1137,132 @@ TEST_F(PdfViewWebPluginTest, UpdateLayerTransformWithScaleAndTranslate) {
/*expected_clipped_rect=*/gfx::Rect(10, 15, 5, 10));
}
TEST_F(PdfViewWebPluginTest, HandleViewportMessageBeforeDocumentLoadComplete) {
EXPECT_CALL(*engine_ptr_, ApplyDocumentLayout(DocumentLayout::Options()));
EXPECT_CALL(*client_ptr_, PostMessage).Times(0);
base::Value message = base::test::ParseJson(R"({
"type": "viewport",
"userInitiated": false,
"zoom": 1,
"layoutOptions": {
"direction": 0,
"defaultPageOrientation": 0,
"twoUpViewEnabled": false,
},
"xOffset": 0,
"yOffset": 0,
"pinchPhase": 0,
})");
plugin_->OnMessage(message.GetDict());
}
TEST_F(PdfViewWebPluginTest, HandleViewportMessageAfterDocumentLoadComplete) {
plugin_->DocumentLoadComplete();
EXPECT_CALL(*engine_ptr_, ApplyDocumentLayout(DocumentLayout::Options()));
EXPECT_CALL(*client_ptr_, PostMessage(base::test::IsJson(R"({
"type": "loadProgress",
"progress": 100.0,
})")));
base::Value message = base::test::ParseJson(R"({
"type": "viewport",
"userInitiated": false,
"zoom": 1,
"layoutOptions": {
"direction": 0,
"defaultPageOrientation": 0,
"twoUpViewEnabled": false,
},
"xOffset": 0,
"yOffset": 0,
"pinchPhase": 0,
})");
plugin_->OnMessage(message.GetDict());
}
TEST_F(PdfViewWebPluginTest, HandleViewportMessageSubsequently) {
base::Value message1 = base::test::ParseJson(R"({
"type": "viewport",
"userInitiated": false,
"zoom": 1,
"layoutOptions": {
"direction": 0,
"defaultPageOrientation": 0,
"twoUpViewEnabled": false,
},
"xOffset": 0,
"yOffset": 0,
"pinchPhase": 0,
})");
plugin_->OnMessage(message1.GetDict());
DocumentLayout::Options two_up_options;
two_up_options.set_page_spread(DocumentLayout::PageSpread::kTwoUpOdd);
EXPECT_CALL(*engine_ptr_, ApplyDocumentLayout(two_up_options));
EXPECT_CALL(*client_ptr_, PostMessage).Times(0);
base::Value message2 = base::test::ParseJson(R"({
"type": "viewport",
"userInitiated": false,
"zoom": 1,
"layoutOptions": {
"direction": 0,
"defaultPageOrientation": 0,
"twoUpViewEnabled": true,
},
"xOffset": 0,
"yOffset": 0,
"pinchPhase": 0,
})");
plugin_->OnMessage(message2.GetDict());
}
TEST_F(PdfViewWebPluginTest, HandleViewportMessageScroll) {
EXPECT_CALL(*engine_ptr_, ApplyDocumentLayout)
.WillRepeatedly(Return(gfx::Size(16, 9)));
EXPECT_CALL(*engine_ptr_, ScrolledToXPosition(2));
EXPECT_CALL(*engine_ptr_, ScrolledToYPosition(3));
base::Value message = base::test::ParseJson(R"({
"type": "viewport",
"userInitiated": false,
"zoom": 1,
"layoutOptions": {
"direction": 2,
"defaultPageOrientation": 0,
"twoUpViewEnabled": false,
},
"xOffset": 2,
"yOffset": 3,
"pinchPhase": 0,
})");
plugin_->OnMessage(message.GetDict());
}
TEST_F(PdfViewWebPluginTest, HandleViewportMessageScrollRightToLeft) {
EXPECT_CALL(*engine_ptr_, ApplyDocumentLayout)
.WillRepeatedly(Return(gfx::Size(16, 9)));
EXPECT_CALL(*engine_ptr_, ScrolledToXPosition(2));
EXPECT_CALL(*engine_ptr_, ScrolledToYPosition(3));
base::Value message = base::test::ParseJson(R"({
"type": "viewport",
"userInitiated": false,
"zoom": 1,
"layoutOptions": {
"direction": 1,
"defaultPageOrientation": 0,
"twoUpViewEnabled": false,
},
"xOffset": 2,
"yOffset": 3,
"pinchPhase": 0,
})");
plugin_->OnMessage(message.GetDict());
}
TEST_F(PdfViewWebPluginTest, HandleSetBackgroundColorMessage) {
ASSERT_NE(SK_ColorGREEN, plugin_->GetBackgroundColor());