TEST_F(FPDFDocEmbedderTest, GetXFALinks) { EXPECT_TRUE(OpenDocument("simple_xfa.pdf")); ScopedFPDFPage page(FPDF_LoadPage(document(), 0)); ASSERT_TRUE(page); FPDFLink_GetLinkAtPoint(page.get(), 150, 360); FPDFLink_GetLinkAtPoint(page.get(), 150, 420); // Test passes if it doesn't crash. See https://crbug.com/840922 }
TEST_F(FPDFDocEmbedderTest, ActionURI) { EXPECT_TRUE(OpenDocument("uri_action.pdf")); FPDF_PAGE page = LoadPage(0); ASSERT_TRUE(page); // The target action is nearly the size of the whole page. FPDF_LINK link = FPDFLink_GetLinkAtPoint(page, 100, 100); ASSERT_TRUE(link); FPDF_ACTION action = FPDFLink_GetAction(link); ASSERT_TRUE(action); EXPECT_EQ(static_cast<unsigned long>(PDFACTION_URI), FPDFAction_GetType(action)); const char kExpectedResult[] = "https://example.com/page.html"; const unsigned long kExpectedLength = sizeof(kExpectedResult); unsigned long bufsize = FPDFAction_GetURIPath(document(), action, nullptr, 0); ASSERT_EQ(kExpectedLength, bufsize); char buf[1024]; EXPECT_EQ(bufsize, FPDFAction_GetURIPath(document(), action, buf, bufsize)); EXPECT_STREQ(kExpectedResult, buf); // Other public methods are not appropriate for URI actions EXPECT_EQ(nullptr, FPDFAction_GetDest(document(), action)); EXPECT_EQ(0u, FPDFAction_GetFilePath(action, buf, sizeof(buf))); UnloadPage(page); }
TEST_F(FPDFDocEmbedderTest, ActionNonesuch) { EXPECT_TRUE(OpenDocument("nonesuch_action.pdf")); FPDF_PAGE page = LoadPage(0); ASSERT_TRUE(page); // The target action is nearly the size of the whole page. FPDF_LINK link = FPDFLink_GetLinkAtPoint(page, 100, 100); ASSERT_TRUE(link); FPDF_ACTION action = FPDFLink_GetAction(link); ASSERT_TRUE(action); EXPECT_EQ(static_cast<unsigned long>(PDFACTION_UNSUPPORTED), FPDFAction_GetType(action)); // No public methods are appropriate for unsupported actions. char buf[1024]; EXPECT_FALSE(FPDFAction_GetDest(document(), action)); EXPECT_EQ(0u, FPDFAction_GetFilePath(action, buf, sizeof(buf))); EXPECT_EQ(0u, FPDFAction_GetURIPath(document(), action, buf, sizeof(buf))); UnloadPage(page); }
TEST_F(FPDFDocEmbeddertest, ActionGetFilePath) { EXPECT_TRUE(OpenDocument("launch_action.pdf")); FPDF_PAGE page = FPDF_LoadPage(document(), 0); ASSERT_TRUE(page); // The target action is nearly the size of the whole page. FPDF_LINK link = FPDFLink_GetLinkAtPoint(page, 100, 100); ASSERT_TRUE(link); FPDF_ACTION action = FPDFLink_GetAction(link); ASSERT_TRUE(action); const char kExpectedResult[] = "test.pdf"; const unsigned long kExpectedLength = sizeof(kExpectedResult); unsigned long bufsize = FPDFAction_GetFilePath(action, nullptr, 0); ASSERT_EQ(kExpectedLength, bufsize); char buf[kExpectedLength]; EXPECT_EQ(bufsize, FPDFAction_GetFilePath(action, buf, bufsize)); EXPECT_EQ(std::string(kExpectedResult), std::string(buf)); FPDF_ClosePage(page); }
TEST_F(FPDFDocEmbedderTest, BUG_821454) { EXPECT_TRUE(OpenDocument("bug_821454.pdf")); FPDF_PAGE page = LoadPage(0); ASSERT_TRUE(page); // Cover some NULL arg cases while we're at it. EXPECT_FALSE(FPDFLink_GetLinkAtPoint(nullptr, 150, 360)); EXPECT_EQ(-1, FPDFLink_GetLinkZOrderAtPoint(nullptr, 150, 360)); FPDF_LINK link1 = FPDFLink_GetLinkAtPoint(page, 150, 360); ASSERT_TRUE(link1); FPDF_LINK link2 = FPDFLink_GetLinkAtPoint(page, 150, 420); ASSERT_TRUE(link2); EXPECT_EQ(0, FPDFLink_GetLinkZOrderAtPoint(page, 150, 360)); EXPECT_EQ(1, FPDFLink_GetLinkZOrderAtPoint(page, 150, 420)); FPDF_DEST dest1 = FPDFLink_GetDest(document(), link1); ASSERT_TRUE(dest1); FPDF_DEST dest2 = FPDFLink_GetDest(document(), link2); ASSERT_TRUE(dest2); EXPECT_EQ(0, FPDFDest_GetDestPageIndex(document(), dest1)); EXPECT_EQ(0, FPDFDest_GetDestPageIndex(document(), dest2)); { FPDF_BOOL has_x_coord; FPDF_BOOL has_y_coord; FPDF_BOOL has_zoom; FS_FLOAT x; FS_FLOAT y; FS_FLOAT zoom; FPDF_BOOL success = FPDFDest_GetLocationInPage( dest1, &has_x_coord, &has_y_coord, &has_zoom, &x, &y, &zoom); ASSERT_TRUE(success); EXPECT_TRUE(has_x_coord); EXPECT_TRUE(has_y_coord); EXPECT_FALSE(has_zoom); EXPECT_FLOAT_EQ(100.0f, x); EXPECT_FLOAT_EQ(200.0f, y); } { FPDF_BOOL has_x_coord; FPDF_BOOL has_y_coord; FPDF_BOOL has_zoom; FS_FLOAT x; FS_FLOAT y; FS_FLOAT zoom; FPDF_BOOL success = FPDFDest_GetLocationInPage( dest2, &has_x_coord, &has_y_coord, &has_zoom, &x, &y, &zoom); ASSERT_TRUE(success); EXPECT_TRUE(has_x_coord); EXPECT_TRUE(has_y_coord); EXPECT_FALSE(has_zoom); EXPECT_FLOAT_EQ(150.0f, x); EXPECT_FLOAT_EQ(250.0f, y); } UnloadPage(page); }