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