Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Side by Side Diff: testing/embedder_test.cpp

Issue 891763003: Merge to XFA: track formhandles in embeddder test class itself (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « testing/embedder_test.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015 PDFium Authors. All rights reserved. 1 // Copyright (c) 2015 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "embedder_test.h" 5 #include "embedder_test.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 FPDF_InitLibrary(); 183 FPDF_InitLibrary();
184 184
185 UNSUPPORT_INFO unsuppored_info; 185 UNSUPPORT_INFO unsuppored_info;
186 memset(&unsuppored_info, '\0', sizeof(unsuppored_info)); 186 memset(&unsuppored_info, '\0', sizeof(unsuppored_info));
187 unsuppored_info.version = 1; 187 unsuppored_info.version = 1;
188 unsuppored_info.FSDK_UnSupport_Handler = Unsupported_Handler; 188 unsuppored_info.FSDK_UnSupport_Handler = Unsupported_Handler;
189 FSDK_SetUnSpObjProcessHandler(&unsuppored_info); 189 FSDK_SetUnSpObjProcessHandler(&unsuppored_info);
190 } 190 }
191 191
192 void EmbedderTest::TearDown() { 192 void EmbedderTest::TearDown() {
193 FPDF_CloseDocument(document_); 193 if (form_handle_) {
194 FORM_DoDocumentAAction(form_handle_, FPDFDOC_AACTION_WC);
195 FPDFDOC_ExitFormFillEnvironment(form_handle_);
196 }
197 if (document_) {
198 FPDF_CloseDocument(document_);
199 }
194 FPDFAvail_Destroy(avail_); 200 FPDFAvail_Destroy(avail_);
195 FPDF_DestroyLibrary(); 201 FPDF_DestroyLibrary();
196 if (loader_) { 202 if (loader_) {
197 delete loader_; 203 delete loader_;
198 } 204 }
199 if (file_contents_) { 205 if (file_contents_) {
200 free(file_contents_); 206 free(file_contents_);
201 } 207 }
202 } 208 }
203 209
(...skipping 21 matching lines...) Expand all
225 document_ = FPDF_LoadCustomDocument(&file_access_, NULL); 231 document_ = FPDF_LoadCustomDocument(&file_access_, NULL);
226 } else { 232 } else {
227 document_ = FPDFAvail_GetDocument(avail_, NULL); 233 document_ = FPDFAvail_GetDocument(avail_, NULL);
228 } 234 }
229 if (!document_) { 235 if (!document_) {
230 return false; 236 return false;
231 } 237 }
232 (void) FPDF_LoadXFA(document_); 238 (void) FPDF_LoadXFA(document_);
233 (void) FPDF_GetDocPermissions(document_); 239 (void) FPDF_GetDocPermissions(document_);
234 (void) FPDFAvail_IsFormAvail(avail_, &hints_); 240 (void) FPDFAvail_IsFormAvail(avail_, &hints_);
235 return true;
236 }
237 241
238 FPDF_FORMHANDLE EmbedderTest::SetFormFillEnvironment() {
239 IPDF_JSPLATFORM platform_callbacks; 242 IPDF_JSPLATFORM platform_callbacks;
240 memset(&platform_callbacks, '\0', sizeof(platform_callbacks)); 243 memset(&platform_callbacks, '\0', sizeof(platform_callbacks));
241 platform_callbacks.version = 1; 244 platform_callbacks.version = 1;
242 platform_callbacks.app_alert = Form_Alert; 245 platform_callbacks.app_alert = Form_Alert;
243 246
244 FPDF_FORMFILLINFO form_callbacks; 247 FPDF_FORMFILLINFO form_callbacks;
245 memset(&form_callbacks, '\0', sizeof(form_callbacks)); 248 memset(&form_callbacks, '\0', sizeof(form_callbacks));
246 form_callbacks.version = 1; 249 form_callbacks.version = 1;
247 form_callbacks.m_pJsPlatform = &platform_callbacks; 250 form_callbacks.m_pJsPlatform = &platform_callbacks;
248 251
249 FPDF_FORMHANDLE form = FPDFDOC_InitFormFillEnvironment(document_, 252 form_handle_ = FPDFDOC_InitFormFillEnvironment(document_, &form_callbacks);
250 &form_callbacks); 253 FPDF_SetFormFieldHighlightColor(form_handle_, 0, 0xFFE4DD);
251 FPDF_SetFormFieldHighlightColor(form, 0, 0xFFE4DD); 254 FPDF_SetFormFieldHighlightAlpha(form_handle_, 100);
252 FPDF_SetFormFieldHighlightAlpha(form, 100); 255
253 return form; 256 return true;
254 } 257 }
255 258
256 void EmbedderTest::ClearFormFillEnvironment(FPDF_FORMHANDLE form) { 259 void EmbedderTest::DoOpenActions() {
257 FORM_DoDocumentAAction(form, FPDFDOC_AACTION_WC); 260 FORM_DoDocumentJSAction(form_handle_);
258 FPDFDOC_ExitFormFillEnvironment(form); 261 FORM_DoDocumentOpenAction(form_handle_);
259 }
260
261 void EmbedderTest::DoOpenActions(FPDF_FORMHANDLE form) {
262 FORM_DoDocumentJSAction(form);
263 FORM_DoDocumentOpenAction(form);
264 } 262 }
265 263
266 int EmbedderTest::GetFirstPageNum() { 264 int EmbedderTest::GetFirstPageNum() {
267 int first_page = FPDFAvail_GetFirstPageNum(document_); 265 int first_page = FPDFAvail_GetFirstPageNum(document_);
268 (void) FPDFAvail_IsPageAvail(avail_, first_page, &hints_); 266 (void) FPDFAvail_IsPageAvail(avail_, first_page, &hints_);
269 return first_page; 267 return first_page;
270 } 268 }
271 269
272 int EmbedderTest::GetPageCount() { 270 int EmbedderTest::GetPageCount() {
273 int page_count = FPDF_GetPageCount(document_); 271 int page_count = FPDF_GetPageCount(document_);
274 for (int i = 0; i < page_count; ++i) { 272 for (int i = 0; i < page_count; ++i) {
275 (void) FPDFAvail_IsPageAvail(avail_, i, &hints_); 273 (void) FPDFAvail_IsPageAvail(avail_, i, &hints_);
276 } 274 }
277 return page_count; 275 return page_count;
278 } 276 }
279 277
280 FPDF_PAGE EmbedderTest::LoadPage(int page_number, 278 FPDF_PAGE EmbedderTest::LoadPage(int page_number) {
281 FPDF_FORMHANDLE form) {
282 FPDF_PAGE page = FPDF_LoadPage(document_, page_number); 279 FPDF_PAGE page = FPDF_LoadPage(document_, page_number);
283 if (!page) { 280 if (!page) {
284 return nullptr; 281 return nullptr;
285 } 282 }
286 FORM_OnAfterLoadPage(page, form); 283 FORM_OnAfterLoadPage(page, form_handle_);
287 FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_OPEN); 284 FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_OPEN);
288 return page; 285 return page;
289 } 286 }
290 287
291 FPDF_BITMAP EmbedderTest::RenderPage(FPDF_PAGE page, 288 FPDF_BITMAP EmbedderTest::RenderPage(FPDF_PAGE page) {
292 FPDF_FORMHANDLE form) {
293 int width = static_cast<int>(FPDF_GetPageWidth(page)); 289 int width = static_cast<int>(FPDF_GetPageWidth(page));
294 int height = static_cast<int>(FPDF_GetPageHeight(page)); 290 int height = static_cast<int>(FPDF_GetPageHeight(page));
295 FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, 0); 291 FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, 0);
296 FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF); 292 FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF);
297 FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); 293 FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0);
298 FPDF_FFLDraw(form, bitmap, page, 0, 0, width, height, 0, 0); 294 FPDF_FFLDraw(form_handle_, bitmap, page, 0, 0, width, height, 0, 0);
299 return bitmap; 295 return bitmap;
300 } 296 }
301 297
302 void EmbedderTest::UnloadPage(FPDF_PAGE page, FPDF_FORMHANDLE form) { 298 void EmbedderTest::UnloadPage(FPDF_PAGE page) {
303 FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_CLOSE); 299 FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_CLOSE);
304 FORM_OnBeforeClosePage(page, form); 300 FORM_OnBeforeClosePage(page, form_handle_);
305 FPDF_ClosePage(page); 301 FPDF_ClosePage(page);
306 } 302 }
307 303
308 // Can't use gtest-provided main since we need to stash the path to the 304 // Can't use gtest-provided main since we need to stash the path to the
309 // executable in order to find the external V8 binary data files. 305 // executable in order to find the external V8 binary data files.
310 int main(int argc, char** argv) { 306 int main(int argc, char** argv) {
311 g_exe_path_ = argv[0]; 307 g_exe_path_ = argv[0];
312 testing::InitGoogleTest(&argc, argv); 308 testing::InitGoogleTest(&argc, argv);
313 return RUN_ALL_TESTS(); 309 return RUN_ALL_TESTS();
314 } 310 }
OLDNEW
« no previous file with comments | « testing/embedder_test.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698