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.
5 #ifndef TESTING_EMBEDDER_TEST_H_
6 #define TESTING_EMBEDDER_TEST_H_
10 #include "../public/fpdf_dataavail.h"
11 #include "../public/fpdf_ext.h"
12 #include "../public/fpdf_formfill.h"
13 #include "../public/fpdfview.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "v8/include/v8.h"
19 // This class is used to load a PDF document, and then run programatic
20 // API tests against it.
21 class EmbedderTest : public ::testing::Test,
22 public UNSUPPORT_INFO,
23 public IPDF_JSPLATFORM,
24 public FPDF_FORMFILLINFO {
28 virtual ~Delegate() {}
30 // Equivalent to UNSUPPORT_INFO::FSDK_UnSupport_Handler().
31 virtual void UnsupportedHandler(int type) {}
33 // Equivalent to IPDF_JSPLATFORM::app_alert().
34 virtual int Alert(FPDF_WIDESTRING message,
35 FPDF_WIDESTRING title,
41 // Equivalent to FPDF_FORMFILLINFO::FFI_SetTimer().
42 virtual int SetTimer(int msecs, TimerCallback fn) { return 0; }
44 // Equivalent to FPDF_FORMFILLINFO::FFI_KillTimer().
45 virtual void KillTimer(int id) {}
49 virtual ~EmbedderTest();
51 void SetUp() override;
52 void TearDown() override;
54 void SetDelegate(Delegate* delegate) {
55 delegate_ = delegate ? delegate : default_delegate_;
58 FPDF_DOCUMENT document() { return document_; }
59 FPDF_FORMHANDLE form_handle() { return form_handle_; }
61 // Open the document specified by |filename|, and create its form fill
62 // environment, or return false on failure.
63 virtual bool OpenDocument(const std::string& filename);
65 // Perform JavaScript actions that are to run at document open time.
66 virtual void DoOpenActions();
68 // Determine the page numbers present in the document.
69 virtual int GetFirstPageNum();
70 virtual int GetPageCount();
72 // Load a specific page of the open document.
73 virtual FPDF_PAGE LoadPage(int page_number);
75 // Convert a loaded page into a bitmap.
76 virtual FPDF_BITMAP RenderPage(FPDF_PAGE page);
78 // Relese the resources obtained from LoadPage(). Further use of |page|
79 // is prohibited after this call is made.
80 virtual void UnloadPage(FPDF_PAGE page);
84 Delegate* default_delegate_;
85 FPDF_DOCUMENT document_;
86 FPDF_FORMHANDLE form_handle_;
88 FX_DOWNLOADHINTS hints_;
89 FPDF_FILEACCESS file_access_;
90 FX_FILEAVAIL file_avail_;
91 v8::Platform* platform_;
92 v8::StartupData natives_;
93 v8::StartupData snapshot_;
99 static void UnsupportedHandlerTrampoline(UNSUPPORT_INFO*, int type);
100 static int AlertTrampoline(IPDF_JSPLATFORM* plaform,
101 FPDF_WIDESTRING message,
102 FPDF_WIDESTRING title,
105 static int SetTimerTrampoline(FPDF_FORMFILLINFO* info,
108 static void KillTimerTrampoline(FPDF_FORMFILLINFO* info, int id);
111 #endif // TESTING_EMBEDDER_TEST_H_