fpdfformfill_embeddertest.cpp revision 4d3acf4ec42bf6e838f9060103aff98fbf170794
1// Copyright 2015 PDFium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "public/fpdf_formfill.h" 6#include "testing/embedder_test.h" 7#include "testing/embedder_test_mock_delegate.h" 8#include "testing/embedder_test_timer_handling_delegate.h" 9#include "testing/gmock/include/gmock/gmock.h" 10#include "testing/gtest/include/gtest/gtest.h" 11 12using testing::_; 13using testing::Return; 14 15class FPDFFormFillEmbeddertest : public EmbedderTest {}; 16 17TEST_F(FPDFFormFillEmbeddertest, FirstTest) { 18 EmbedderTestMockDelegate mock; 19 EXPECT_CALL(mock, Alert(_, _, _, _)).Times(0); 20 EXPECT_CALL(mock, UnsupportedHandler(_)).Times(0); 21 EXPECT_CALL(mock, SetTimer(_, _)).Times(0); 22 EXPECT_CALL(mock, KillTimer(_)).Times(0); 23 SetDelegate(&mock); 24 25 EXPECT_TRUE(OpenDocument("hello_world.pdf")); 26 FPDF_PAGE page = LoadPage(0); 27 EXPECT_TRUE(page); 28 UnloadPage(page); 29} 30 31TEST_F(FPDFFormFillEmbeddertest, BUG_487928) { 32 EmbedderTestTimerHandlingDelegate delegate; 33 SetDelegate(&delegate); 34 35 EXPECT_TRUE(OpenDocument("bug_487928.pdf")); 36 FPDF_PAGE page = LoadPage(0); 37 EXPECT_TRUE(page); 38 DoOpenActions(); 39 delegate.AdvanceTime(5000); 40 UnloadPage(page); 41} 42 43TEST_F(FPDFFormFillEmbeddertest, BUG_507316) { 44 EmbedderTestTimerHandlingDelegate delegate; 45 SetDelegate(&delegate); 46 47 EXPECT_TRUE(OpenDocument("bug_507316.pdf")); 48 FPDF_PAGE page = LoadPage(2); 49 EXPECT_TRUE(page); 50 DoOpenActions(); 51 delegate.AdvanceTime(4000); 52 UnloadPage(page); 53} 54 55TEST_F(FPDFFormFillEmbeddertest, BUG_514690) { 56 EXPECT_TRUE(OpenDocument("hello_world.pdf")); 57 FPDF_PAGE page = LoadPage(0); 58 EXPECT_TRUE(page); 59 60 // Test that FORM_OnMouseMove() etc. permit null HANDLES and PAGES. 61 FORM_OnMouseMove(nullptr, page, 0, 10.0, 10.0); 62 FORM_OnMouseMove(form_handle(), nullptr, 0, 10.0, 10.0); 63 64 UnloadPage(page); 65} 66 67#ifdef PDF_ENABLE_V8 68TEST_F(FPDFFormFillEmbeddertest, BUG_551248) { 69 // Test that timers fire once and intervals fire repeatedly. 70 EmbedderTestTimerHandlingDelegate delegate; 71 SetDelegate(&delegate); 72 73 EXPECT_TRUE(OpenDocument("bug_551248.pdf")); 74 FPDF_PAGE page = LoadPage(0); 75 EXPECT_TRUE(page); 76 DoOpenActions(); 77 78 const auto& alerts = delegate.GetAlerts(); 79 EXPECT_EQ(0U, alerts.size()); 80 81 delegate.AdvanceTime(1000); 82 EXPECT_EQ(0U, alerts.size()); // nothing fired. 83 delegate.AdvanceTime(1000); 84 EXPECT_EQ(1U, alerts.size()); // interval fired. 85 delegate.AdvanceTime(1000); 86 EXPECT_EQ(2U, alerts.size()); // timer fired. 87 delegate.AdvanceTime(1000); 88 EXPECT_EQ(3U, alerts.size()); // interval fired again. 89 delegate.AdvanceTime(1000); 90 EXPECT_EQ(3U, alerts.size()); // nothing fired. 91 delegate.AdvanceTime(1000); 92 EXPECT_EQ(4U, alerts.size()); // interval fired again. 93 delegate.AdvanceTime(1000); 94 EXPECT_EQ(4U, alerts.size()); // nothing fired. 95 UnloadPage(page); 96 97 ASSERT_EQ(4U, alerts.size()); // nothing else fired. 98 99 EXPECT_STREQ(L"interval fired", alerts[0].message.c_str()); 100 EXPECT_STREQ(L"Alert", alerts[0].title.c_str()); 101 EXPECT_EQ(0, alerts[0].type); 102 EXPECT_EQ(0, alerts[0].icon); 103 104 EXPECT_STREQ(L"timer fired", alerts[1].message.c_str()); 105 EXPECT_STREQ(L"Alert", alerts[1].title.c_str()); 106 EXPECT_EQ(0, alerts[1].type); 107 EXPECT_EQ(0, alerts[1].icon); 108 109 EXPECT_STREQ(L"interval fired", alerts[2].message.c_str()); 110 EXPECT_STREQ(L"Alert", alerts[2].title.c_str()); 111 EXPECT_EQ(0, alerts[2].type); 112 EXPECT_EQ(0, alerts[2].icon); 113 114 EXPECT_STREQ(L"interval fired", alerts[3].message.c_str()); 115 EXPECT_STREQ(L"Alert", alerts[3].title.c_str()); 116 EXPECT_EQ(0, alerts[3].type); 117 EXPECT_EQ(0, alerts[3].icon); 118} 119 120TEST_F(FPDFFormFillEmbeddertest, BUG_620428) { 121 // Test that timers and intervals are cancelable. 122 EmbedderTestTimerHandlingDelegate delegate; 123 SetDelegate(&delegate); 124 125 EXPECT_TRUE(OpenDocument("bug_620428.pdf")); 126 FPDF_PAGE page = LoadPage(0); 127 EXPECT_TRUE(page); 128 DoOpenActions(); 129 delegate.AdvanceTime(5000); 130 UnloadPage(page); 131 132 const auto& alerts = delegate.GetAlerts(); 133 ASSERT_EQ(1U, alerts.size()); 134 EXPECT_STREQ(L"done", alerts[0].message.c_str()); 135} 136 137TEST_F(FPDFFormFillEmbeddertest, BUG_634394) { 138 // Cancel timer inside timer callback. 139 EmbedderTestTimerHandlingDelegate delegate; 140 SetDelegate(&delegate); 141 142 EXPECT_TRUE(OpenDocument("bug_634394.pdf")); 143 FPDF_PAGE page = LoadPage(0); 144 EXPECT_TRUE(page); 145 DoOpenActions(); 146 147 // Timers fire at most once per AdvanceTime(), allow intervals 148 // to fire several times if possible. 149 delegate.AdvanceTime(1000); 150 delegate.AdvanceTime(1000); 151 delegate.AdvanceTime(1000); 152 delegate.AdvanceTime(1000); 153 delegate.AdvanceTime(1000); 154 UnloadPage(page); 155 156 const auto& alerts = delegate.GetAlerts(); 157 EXPECT_EQ(2U, alerts.size()); 158} 159 160TEST_F(FPDFFormFillEmbeddertest, BUG_634716) { 161 EmbedderTestTimerHandlingDelegate delegate; 162 SetDelegate(&delegate); 163 164 EXPECT_TRUE(OpenDocument("bug_634716.pdf")); 165 FPDF_PAGE page = LoadPage(0); 166 EXPECT_TRUE(page); 167 DoOpenActions(); 168 169 // Timers fire at most once per AdvanceTime(), allow intervals 170 // to fire several times if possible. 171 delegate.AdvanceTime(1000); 172 delegate.AdvanceTime(1000); 173 delegate.AdvanceTime(1000); 174 delegate.AdvanceTime(1000); 175 delegate.AdvanceTime(1000); 176 UnloadPage(page); 177 178 const auto& alerts = delegate.GetAlerts(); 179 EXPECT_EQ(2U, alerts.size()); 180} 181 182TEST_F(FPDFFormFillEmbeddertest, BUG_679649) { 183 EmbedderTestTimerHandlingDelegate delegate; 184 SetDelegate(&delegate); 185 186 EXPECT_TRUE(OpenDocument("bug_679649.pdf")); 187 FPDF_PAGE page = LoadPage(0); 188 EXPECT_TRUE(page); 189 190 delegate.SetFailNextTimer(); 191 DoOpenActions(); 192 delegate.AdvanceTime(2000); 193 UnloadPage(page); 194 195 const auto& alerts = delegate.GetAlerts(); 196 EXPECT_EQ(0u, alerts.size()); 197} 198 199#endif // PDF_ENABLE_V8 200