| 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 <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "../public/fpdf_dataavail.h" | 11 #include "../public/fpdf_dataavail.h" |
| 12 #include "../public/fpdf_ext.h" | 12 #include "../public/fpdf_ext.h" |
| 13 #include "../public/fpdf_formfill.h" | 13 #include "../public/fpdf_formfill.h" |
| 14 #include "../public/fpdfview.h" | 14 #include "../public/fpdfview.h" |
| 15 #include "../third_party/base/nonstd_unique_ptr.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "v8/include/v8.h" | 17 #include "v8/include/v8.h" |
| 17 | 18 |
| 18 class TestLoader; | 19 class TestLoader; |
| 19 | 20 |
| 20 // This class is used to load a PDF document, and then run programatic | 21 // This class is used to load a PDF document, and then run programatic |
| 21 // API tests against it. | 22 // API tests against it. |
| 22 class EmbedderTest : public ::testing::Test, | 23 class EmbedderTest : public ::testing::Test, |
| 23 public UNSUPPORT_INFO, | 24 public UNSUPPORT_INFO, |
| 24 public IPDF_JSPLATFORM, | 25 public IPDF_JSPLATFORM, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 53 private: | 54 private: |
| 54 std::map<int, FPDF_PAGE> m_pageMap; | 55 std::map<int, FPDF_PAGE> m_pageMap; |
| 55 }; | 56 }; |
| 56 | 57 |
| 57 EmbedderTest(); | 58 EmbedderTest(); |
| 58 virtual ~EmbedderTest(); | 59 virtual ~EmbedderTest(); |
| 59 | 60 |
| 60 void SetUp() override; | 61 void SetUp() override; |
| 61 void TearDown() override; | 62 void TearDown() override; |
| 62 | 63 |
| 64 // Call before SetUp to pass shared isolate, otherwise PDFium creates one. |
| 65 void SetExternalIsolate(v8::Isolate* isolate) { external_isolate_ = isolate; } |
| 66 |
| 63 void SetDelegate(Delegate* delegate) { | 67 void SetDelegate(Delegate* delegate) { |
| 64 delegate_ = delegate ? delegate : default_delegate_; | 68 delegate_ = delegate ? delegate : default_delegate_.get(); |
| 65 } | 69 } |
| 66 | 70 |
| 67 FPDF_DOCUMENT document() { return document_; } | 71 FPDF_DOCUMENT document() { return document_; } |
| 68 FPDF_FORMHANDLE form_handle() { return form_handle_; } | 72 FPDF_FORMHANDLE form_handle() { return form_handle_; } |
| 69 | 73 |
| 70 // Open the document specified by |filename|, and create its form fill | 74 // Open the document specified by |filename|, and create its form fill |
| 71 // environment, or return false on failure. | 75 // environment, or return false on failure. |
| 72 virtual bool OpenDocument(const std::string& filename); | 76 virtual bool OpenDocument(const std::string& filename); |
| 73 | 77 |
| 74 // Perform JavaScript actions that are to run at document open time. | 78 // Perform JavaScript actions that are to run at document open time. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 87 | 91 |
| 88 // Convert a loaded page into a bitmap. | 92 // Convert a loaded page into a bitmap. |
| 89 virtual FPDF_BITMAP RenderPage(FPDF_PAGE page); | 93 virtual FPDF_BITMAP RenderPage(FPDF_PAGE page); |
| 90 | 94 |
| 91 // Relese the resources obtained from LoadPage(). Further use of |page| | 95 // Relese the resources obtained from LoadPage(). Further use of |page| |
| 92 // is prohibited after this call is made. | 96 // is prohibited after this call is made. |
| 93 virtual void UnloadPage(FPDF_PAGE page); | 97 virtual void UnloadPage(FPDF_PAGE page); |
| 94 | 98 |
| 95 protected: | 99 protected: |
| 96 Delegate* delegate_; | 100 Delegate* delegate_; |
| 97 Delegate* default_delegate_; | 101 nonstd::unique_ptr<Delegate> default_delegate_; |
| 98 FPDF_DOCUMENT document_; | 102 FPDF_DOCUMENT document_; |
| 99 FPDF_FORMHANDLE form_handle_; | 103 FPDF_FORMHANDLE form_handle_; |
| 100 FPDF_AVAIL avail_; | 104 FPDF_AVAIL avail_; |
| 101 FX_DOWNLOADHINTS hints_; | 105 FX_DOWNLOADHINTS hints_; |
| 102 FPDF_FILEACCESS file_access_; | 106 FPDF_FILEACCESS file_access_; |
| 103 FX_FILEAVAIL file_avail_; | 107 FX_FILEAVAIL file_avail_; |
| 104 v8::Platform* platform_; | 108 v8::Platform* platform_; |
| 105 v8::StartupData natives_; | 109 v8::StartupData natives_; |
| 106 v8::StartupData snapshot_; | 110 v8::StartupData snapshot_; |
| 111 v8::Isolate* external_isolate_; |
| 107 TestLoader* loader_; | 112 TestLoader* loader_; |
| 108 size_t file_length_; | 113 size_t file_length_; |
| 109 char* file_contents_; | 114 char* file_contents_; |
| 110 | 115 |
| 111 private: | 116 private: |
| 112 static void UnsupportedHandlerTrampoline(UNSUPPORT_INFO*, int type); | 117 static void UnsupportedHandlerTrampoline(UNSUPPORT_INFO*, int type); |
| 113 static int AlertTrampoline(IPDF_JSPLATFORM* plaform, | 118 static int AlertTrampoline(IPDF_JSPLATFORM* plaform, |
| 114 FPDF_WIDESTRING message, | 119 FPDF_WIDESTRING message, |
| 115 FPDF_WIDESTRING title, | 120 FPDF_WIDESTRING title, |
| 116 int type, | 121 int type, |
| 117 int icon); | 122 int icon); |
| 118 static int SetTimerTrampoline(FPDF_FORMFILLINFO* info, | 123 static int SetTimerTrampoline(FPDF_FORMFILLINFO* info, |
| 119 int msecs, | 124 int msecs, |
| 120 TimerCallback fn); | 125 TimerCallback fn); |
| 121 static void KillTimerTrampoline(FPDF_FORMFILLINFO* info, int id); | 126 static void KillTimerTrampoline(FPDF_FORMFILLINFO* info, int id); |
| 122 static FPDF_PAGE GetPageTrampoline(FPDF_FORMFILLINFO* info, | 127 static FPDF_PAGE GetPageTrampoline(FPDF_FORMFILLINFO* info, |
| 123 FPDF_DOCUMENT document, | 128 FPDF_DOCUMENT document, |
| 124 int page_index); | 129 int page_index); |
| 125 }; | 130 }; |
| 126 | 131 |
| 127 #endif // TESTING_EMBEDDER_TEST_H_ | 132 #endif // TESTING_EMBEDDER_TEST_H_ |
| OLD | NEW |