blob: 5cede6c6b4ba0ba95cb67892a1822d7b60a0162a [file] [log] [blame]
Tom Sepez96d13342015-01-16 14:59:26 -08001// 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"
Tom Sepez1ed8a212015-05-11 15:25:39 -070011#include "../public/fpdf_dataavail.h"
12#include "../public/fpdf_ext.h"
13#include "../public/fpdf_formfill.h"
14#include "../public/fpdfview.h"
Tom Sepez96d13342015-01-16 14:59:26 -080015#include "testing/gtest/include/gtest/gtest.h"
16#include "v8/include/v8.h"
17
18class TestLoader;
19
20// This class is used to load a PDF document, and then run programatic
21// API tests against it.
Tom Sepez4cb0fa72015-02-25 16:08:18 -080022class EmbedderTest : public ::testing::Test,
23 public UNSUPPORT_INFO,
24 public IPDF_JSPLATFORM,
25 public FPDF_FORMFILLINFO {
Tom Sepez96d13342015-01-16 14:59:26 -080026 public:
Tom Sepez4cb0fa72015-02-25 16:08:18 -080027 class Delegate {
28 public:
29 virtual ~Delegate() { }
Tom Sepez96d13342015-01-16 14:59:26 -080030
Tom Sepez4cb0fa72015-02-25 16:08:18 -080031 // Equivalent to UNSUPPORT_INFO::FSDK_UnSupport_Handler().
32 virtual void UnsupportedHandler(int type) { }
33
34 // Equivalent to IPDF_JSPLATFORM::app_alert().
35 virtual int Alert(FPDF_WIDESTRING message, FPDF_WIDESTRING title,
36 int type, int icon) {
37 return 0;
38 }
39 };
40
41 EmbedderTest();
42 virtual ~EmbedderTest();
Tom Sepez96d13342015-01-16 14:59:26 -080043
44 void SetUp() override;
45 void TearDown() override;
46
Tom Sepez4cb0fa72015-02-25 16:08:18 -080047 void SetDelegate(Delegate* delegate) {
48 delegate_ = delegate ? delegate : default_delegate_;
49 }
50
Tom Sepez96d13342015-01-16 14:59:26 -080051 FPDF_DOCUMENT document() { return document_; }
Tom Sepezda8189e2015-01-30 14:41:50 -080052 FPDF_FORMHANDLE form_handle() { return form_handle_; }
Tom Sepez96d13342015-01-16 14:59:26 -080053
Tom Sepezda8189e2015-01-30 14:41:50 -080054 // Open the document specified by |filename|, and create its form fill
55 // environment, or return false on failure.
Tom Sepez96d13342015-01-16 14:59:26 -080056 virtual bool OpenDocument(const std::string& filename);
57
Tom Sepez96d13342015-01-16 14:59:26 -080058 // Perform JavaScript actions that are to run at document open time.
Tom Sepezda8189e2015-01-30 14:41:50 -080059 virtual void DoOpenActions();
Tom Sepez96d13342015-01-16 14:59:26 -080060
61 // Determine the page numbers present in the document.
62 virtual int GetFirstPageNum();
63 virtual int GetPageCount();
64
65 // Load a specific page of the open document.
Tom Sepezda8189e2015-01-30 14:41:50 -080066 virtual FPDF_PAGE LoadPage(int page_number);
Tom Sepez96d13342015-01-16 14:59:26 -080067
68 // Convert a loaded page into a bitmap.
Tom Sepezda8189e2015-01-30 14:41:50 -080069 virtual FPDF_BITMAP RenderPage(FPDF_PAGE page);
Tom Sepez96d13342015-01-16 14:59:26 -080070
71 // Relese the resources obtained from LoadPage(). Further use of |page|
72 // is prohibited after this call is made.
Tom Sepezda8189e2015-01-30 14:41:50 -080073 virtual void UnloadPage(FPDF_PAGE page);
Tom Sepez96d13342015-01-16 14:59:26 -080074
Tom Sepez2255a1b2015-01-23 15:33:44 -080075 protected:
Tom Sepez4cb0fa72015-02-25 16:08:18 -080076 Delegate* delegate_;
77 Delegate* default_delegate_;
Tom Sepez96d13342015-01-16 14:59:26 -080078 FPDF_DOCUMENT document_;
Tom Sepezda8189e2015-01-30 14:41:50 -080079 FPDF_FORMHANDLE form_handle_;
Tom Sepez96d13342015-01-16 14:59:26 -080080 FPDF_AVAIL avail_;
81 FX_DOWNLOADHINTS hints_;
82 FPDF_FILEACCESS file_access_;
83 FX_FILEAVAIL file_avail_;
84 v8::StartupData natives_;
85 v8::StartupData snapshot_;
86 TestLoader* loader_;
87 size_t file_length_;
88 char* file_contents_;
Tom Sepez4cb0fa72015-02-25 16:08:18 -080089
90 private:
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);
Tom Sepez96d13342015-01-16 14:59:26 -080094};
95
96#endif // TESTING_EMBEDDER_TEST_H_
97