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 "../core/include/fxcrt/fx_system.h"
11 #include "../fpdfsdk/include/fpdf_dataavail.h"
12 #include "../fpdfsdk/include/fpdf_ext.h"
13 #include "../fpdfsdk/include/fpdfformfill.h"
14 #include "../fpdfsdk/include/fpdfview.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "v8/include/v8.h"
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 {
29 virtual ~Delegate() { }
31 // Equivalent to UNSUPPORT_INFO::FSDK_UnSupport_Handler().
32 virtual void UnsupportedHandler(int type) { }
34 // Equivalent to IPDF_JSPLATFORM::app_alert().
35 virtual int Alert(FPDF_WIDESTRING message, FPDF_WIDESTRING title,
42 virtual ~EmbedderTest();
44 void SetUp() override;
45 void TearDown() override;
47 void SetDelegate(Delegate* delegate) {
48 delegate_ = delegate ? delegate : default_delegate_;
51 FPDF_DOCUMENT document() { return document_; }
52 FPDF_FORMHANDLE form_handle() { return form_handle_; }
54 // Open the document specified by |filename|, and create its form fill
55 // environment, or return false on failure.
56 virtual bool OpenDocument(const std::string& filename);
58 // Perform JavaScript actions that are to run at document open time.
59 virtual void DoOpenActions();
61 // Determine the page numbers present in the document.
62 virtual int GetFirstPageNum();
63 virtual int GetPageCount();
65 // Load a specific page of the open document.
66 virtual FPDF_PAGE LoadPage(int page_number);
68 // Convert a loaded page into a bitmap.
69 virtual FPDF_BITMAP RenderPage(FPDF_PAGE page);
71 // Relese the resources obtained from LoadPage(). Further use of |page|
72 // is prohibited after this call is made.
73 virtual void UnloadPage(FPDF_PAGE page);
77 Delegate* default_delegate_;
78 FPDF_DOCUMENT document_;
79 FPDF_FORMHANDLE form_handle_;
81 FX_DOWNLOADHINTS hints_;
82 FPDF_FILEACCESS file_access_;
83 FX_FILEAVAIL file_avail_;
84 v8::StartupData natives_;
85 v8::StartupData snapshot_;
91 static void UnsupportedHandlerTrampoline(UNSUPPORT_INFO*, int type);
92 static int AlertTrampoline(IPDF_JSPLATFORM* plaform, FPDF_WIDESTRING message,
93 FPDF_WIDESTRING title, int type, int icon);
96 #endif // TESTING_EMBEDDER_TEST_H_