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 3 // found in the LICENSE file. 4 5 #ifndef TESTING_EMBEDDER_TEST_H_ 6 #define TESTING_EMBEDDER_TEST_H_ 7 8 #include <string> 9 10 #include "../core/include/fxcrt/fx_system.h" 11 #include "../public/fpdf_dataavail.h" 12 #include "../public/fpdf_ext.h" 13 #include "../public/fpdf_formfill.h" 14 #include "../public/fpdfview.h" 15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "v8/include/v8.h" 17 18 class TestLoader; 19 20 // This class is used to load a PDF document, and then run programatic 21 // API tests against it. 22 class EmbedderTest : public ::testing::Test, 23 public UNSUPPORT_INFO, 24 public IPDF_JSPLATFORM, 25 public FPDF_FORMFILLINFO { 26 public: 27 class Delegate { 28 public: ~Delegate()29 virtual ~Delegate() { } 30 31 // Equivalent to UNSUPPORT_INFO::FSDK_UnSupport_Handler(). UnsupportedHandler(int type)32 virtual void UnsupportedHandler(int type) { } 33 34 // Equivalent to IPDF_JSPLATFORM::app_alert(). Alert(FPDF_WIDESTRING message,FPDF_WIDESTRING title,int type,int icon)35 virtual int Alert(FPDF_WIDESTRING message, FPDF_WIDESTRING title, 36 int type, int icon) { 37 return 0; 38 } 39 40 // Equivalent to FPDF_FORMFILLINFO::FFI_SetTimer(). SetTimer(int msecs,TimerCallback fn)41 virtual int SetTimer(int msecs, TimerCallback fn) { return 0; } 42 43 // Equivalent to FPDF_FORMFILLINFO::FFI_KillTimer(). KillTimer(int id)44 virtual void KillTimer(int id) { } 45 }; 46 47 EmbedderTest(); 48 virtual ~EmbedderTest(); 49 50 void SetUp() override; 51 void TearDown() override; 52 SetDelegate(Delegate * delegate)53 void SetDelegate(Delegate* delegate) { 54 delegate_ = delegate ? delegate : default_delegate_; 55 } 56 document()57 FPDF_DOCUMENT document() { return document_; } form_handle()58 FPDF_FORMHANDLE form_handle() { return form_handle_; } 59 60 // Open the document specified by |filename|, and create its form fill 61 // environment, or return false on failure. 62 virtual bool OpenDocument(const std::string& filename); 63 64 // Perform JavaScript actions that are to run at document open time. 65 virtual void DoOpenActions(); 66 67 // Determine the page numbers present in the document. 68 virtual int GetFirstPageNum(); 69 virtual int GetPageCount(); 70 71 // Load a specific page of the open document. 72 virtual FPDF_PAGE LoadPage(int page_number); 73 74 // Convert a loaded page into a bitmap. 75 virtual FPDF_BITMAP RenderPage(FPDF_PAGE page); 76 77 // Relese the resources obtained from LoadPage(). Further use of |page| 78 // is prohibited after this call is made. 79 virtual void UnloadPage(FPDF_PAGE page); 80 81 protected: 82 Delegate* delegate_; 83 Delegate* default_delegate_; 84 FPDF_DOCUMENT document_; 85 FPDF_FORMHANDLE form_handle_; 86 FPDF_AVAIL avail_; 87 FX_DOWNLOADHINTS hints_; 88 FPDF_FILEACCESS file_access_; 89 FX_FILEAVAIL file_avail_; 90 v8::Platform* platform_; 91 v8::StartupData natives_; 92 v8::StartupData snapshot_; 93 TestLoader* loader_; 94 size_t file_length_; 95 char* file_contents_; 96 97 private: 98 static void UnsupportedHandlerTrampoline(UNSUPPORT_INFO*, int type); 99 static int AlertTrampoline(IPDF_JSPLATFORM* plaform, FPDF_WIDESTRING message, 100 FPDF_WIDESTRING title, int type, int icon); 101 static int SetTimerTrampoline(FPDF_FORMFILLINFO* info, int msecs, 102 TimerCallback fn); 103 static void KillTimerTrampoline(FPDF_FORMFILLINFO* info, int id); 104 }; 105 106 #endif // TESTING_EMBEDDER_TEST_H_ 107