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 #include "embedder_test.h" | 5 #include "embedder_test.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
11 | 11 |
12 #include <list> | 12 #include <list> |
13 #include <string> | 13 #include <string> |
14 #include <utility> | 14 #include <utility> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "../fpdfsdk/include/fpdf_ext.h" | |
18 #include "../fpdfsdk/include/fpdftext.h" | 17 #include "../fpdfsdk/include/fpdftext.h" |
19 #include "../fpdfsdk/include/fpdfview.h" | 18 #include "../fpdfsdk/include/fpdfview.h" |
20 #include "../core/include/fxcrt/fx_system.h" | 19 #include "../core/include/fxcrt/fx_system.h" |
21 #include "v8/include/v8.h" | 20 #include "v8/include/v8.h" |
22 | 21 |
23 #ifdef _WIN32 | 22 #ifdef _WIN32 |
24 #define snprintf _snprintf | 23 #define snprintf _snprintf |
25 #define PATH_SEPARATOR '\\' | 24 #define PATH_SEPARATOR '\\' |
26 #else | 25 #else |
27 #define PATH_SEPARATOR '/' | 26 #define PATH_SEPARATOR '/' |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 return false; | 86 return false; |
88 } | 87 } |
89 result_data->data = const_cast<const char*>(data_buffer); | 88 result_data->data = const_cast<const char*>(data_buffer); |
90 result_data->raw_size = data_length; | 89 result_data->raw_size = data_length; |
91 return true; | 90 return true; |
92 } | 91 } |
93 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 92 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
94 | 93 |
95 } // namespace | 94 } // namespace |
96 | 95 |
97 int Form_Alert(IPDF_JSPLATFORM*, FPDF_WIDESTRING, FPDF_WIDESTRING, int, int) { | 96 class EmbedderTestDefaultDelegate : public EmbedderTest::Delegate { |
98 printf("Form_Alert called.\n"); | 97 public: |
99 return 0; | 98 int Alert(FPDF_WIDESTRING, FPDF_WIDESTRING, int, int) override { |
100 } | 99 printf("Form_Alert called.\n"); |
100 return 0; | |
101 } | |
101 | 102 |
102 void Unsupported_Handler(UNSUPPORT_INFO*, int type) { | 103 void UnsupportedHandler(int type) { |
103 std::string feature = "Unknown"; | 104 std::string feature = "Unknown"; |
104 switch (type) { | 105 switch (type) { |
105 case FPDF_UNSP_DOC_XFAFORM: | 106 case FPDF_UNSP_DOC_XFAFORM: |
106 feature = "XFA"; | 107 feature = "XFA"; |
107 break; | 108 break; |
108 case FPDF_UNSP_DOC_PORTABLECOLLECTION: | 109 case FPDF_UNSP_DOC_PORTABLECOLLECTION: |
109 feature = "Portfolios_Packages"; | 110 feature = "Portfolios_Packages"; |
110 break; | 111 break; |
111 case FPDF_UNSP_DOC_ATTACHMENT: | 112 case FPDF_UNSP_DOC_ATTACHMENT: |
112 case FPDF_UNSP_ANNOT_ATTACHMENT: | 113 case FPDF_UNSP_ANNOT_ATTACHMENT: |
113 feature = "Attachment"; | 114 feature = "Attachment"; |
114 break; | 115 break; |
115 case FPDF_UNSP_DOC_SECURITY: | 116 case FPDF_UNSP_DOC_SECURITY: |
116 feature = "Rights_Management"; | 117 feature = "Rights_Management"; |
117 break; | 118 break; |
118 case FPDF_UNSP_DOC_SHAREDREVIEW: | 119 case FPDF_UNSP_DOC_SHAREDREVIEW: |
119 feature = "Shared_Review"; | 120 feature = "Shared_Review"; |
120 break; | 121 break; |
121 case FPDF_UNSP_DOC_SHAREDFORM_ACROBAT: | 122 case FPDF_UNSP_DOC_SHAREDFORM_ACROBAT: |
122 case FPDF_UNSP_DOC_SHAREDFORM_FILESYSTEM: | 123 case FPDF_UNSP_DOC_SHAREDFORM_FILESYSTEM: |
123 case FPDF_UNSP_DOC_SHAREDFORM_EMAIL: | 124 case FPDF_UNSP_DOC_SHAREDFORM_EMAIL: |
124 feature = "Shared_Form"; | 125 feature = "Shared_Form"; |
125 break; | 126 break; |
126 case FPDF_UNSP_ANNOT_3DANNOT: | 127 case FPDF_UNSP_ANNOT_3DANNOT: |
127 feature = "3D"; | 128 feature = "3D"; |
128 break; | 129 break; |
129 case FPDF_UNSP_ANNOT_MOVIE: | 130 case FPDF_UNSP_ANNOT_MOVIE: |
130 feature = "Movie"; | 131 feature = "Movie"; |
131 break; | 132 break; |
132 case FPDF_UNSP_ANNOT_SOUND: | 133 case FPDF_UNSP_ANNOT_SOUND: |
133 feature = "Sound"; | 134 feature = "Sound"; |
134 break; | 135 break; |
135 case FPDF_UNSP_ANNOT_SCREEN_MEDIA: | 136 case FPDF_UNSP_ANNOT_SCREEN_MEDIA: |
136 case FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA: | 137 case FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA: |
137 feature = "Screen"; | 138 feature = "Screen"; |
138 break; | 139 break; |
139 case FPDF_UNSP_ANNOT_SIG: | 140 case FPDF_UNSP_ANNOT_SIG: |
140 feature = "Digital_Signature"; | 141 feature = "Digital_Signature"; |
141 break; | 142 break; |
143 } | |
144 printf("Unsupported feature: %s.\n", feature.c_str()); | |
142 } | 145 } |
143 printf("Unsupported feature: %s.\n", feature.c_str()); | 146 }; |
144 } | |
145 | 147 |
146 class TestLoader { | 148 class TestLoader { |
147 public: | 149 public: |
148 TestLoader(const char* pBuf, size_t len); | 150 TestLoader(const char* pBuf, size_t len); |
149 | 151 |
150 const char* m_pBuf; | 152 const char* m_pBuf; |
151 size_t m_Len; | 153 size_t m_Len; |
152 }; | 154 }; |
153 | 155 |
154 TestLoader::TestLoader(const char* pBuf, size_t len) | 156 TestLoader::TestLoader(const char* pBuf, size_t len) |
155 : m_pBuf(pBuf), m_Len(len) { | 157 : m_pBuf(pBuf), m_Len(len) { |
156 } | 158 } |
157 | 159 |
158 int Get_Block(void* param, unsigned long pos, unsigned char* pBuf, | 160 int Get_Block(void* param, unsigned long pos, unsigned char* pBuf, |
159 unsigned long size) { | 161 unsigned long size) { |
160 TestLoader* pLoader = (TestLoader*) param; | 162 TestLoader* pLoader = (TestLoader*) param; |
161 if (pos + size < pos || pos + size > pLoader->m_Len) return 0; | 163 if (pos + size < pos || pos + size > pLoader->m_Len) return 0; |
162 memcpy(pBuf, pLoader->m_pBuf + pos, size); | 164 memcpy(pBuf, pLoader->m_pBuf + pos, size); |
163 return 1; | 165 return 1; |
164 } | 166 } |
165 | 167 |
166 bool Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) { | 168 bool Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) { |
167 return true; | 169 return true; |
168 } | 170 } |
169 | 171 |
170 void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) { | 172 void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) { |
171 } | 173 } |
172 | 174 |
175 EmbedderTest::EmbedderTest() : | |
176 document_(nullptr), | |
177 form_handle_(nullptr), | |
178 avail_(nullptr), | |
179 loader_(nullptr), | |
180 file_length_(0), | |
181 file_contents_(nullptr) { | |
182 memset(&hints_, 0, sizeof(hints_)); | |
183 memset(&file_access_, 0, sizeof(file_access_)); | |
184 memset(&file_avail_, 0, sizeof(file_avail_)); | |
185 original_delegate_ = new EmbedderTestDefaultDelegate(); | |
186 delegate_ = original_delegate_; | |
187 } | |
188 | |
189 EmbedderTest::~EmbedderTest() { | |
190 delete original_delegate_; | |
191 } | |
192 | |
173 void EmbedderTest::SetUp() { | 193 void EmbedderTest::SetUp() { |
174 v8::V8::InitializeICU(); | 194 v8::V8::InitializeICU(); |
175 | 195 |
176 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 196 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
177 ASSERT_TRUE(GetExternalData(g_exe_path_, "natives_blob.bin", &natives_)); | 197 ASSERT_TRUE(GetExternalData(g_exe_path_, "natives_blob.bin", &natives_)); |
178 ASSERT_TRUE(GetExternalData(g_exe_path_, "snapshot_blob.bin", &snapshot_)); | 198 ASSERT_TRUE(GetExternalData(g_exe_path_, "snapshot_blob.bin", &snapshot_)); |
179 v8::V8::SetNativesDataBlob(&natives_); | 199 v8::V8::SetNativesDataBlob(&natives_); |
180 v8::V8::SetSnapshotDataBlob(&snapshot_); | 200 v8::V8::SetSnapshotDataBlob(&snapshot_); |
181 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 201 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
182 | 202 |
183 FPDF_InitLibrary(); | 203 FPDF_InitLibrary(); |
184 | 204 |
185 UNSUPPORT_INFO unsuppored_info; | 205 UNSUPPORT_INFO *info = static_cast<UNSUPPORT_INFO*>(this); |
Lei Zhang
2015/02/25 23:02:50
nit: * on the left
Tom Sepez
2015/02/25 23:25:22
Done.
| |
186 memset(&unsuppored_info, '\0', sizeof(unsuppored_info)); | 206 memset(info, 0, sizeof(UNSUPPORT_INFO)); |
187 unsuppored_info.version = 1; | 207 info->version = 1; |
188 unsuppored_info.FSDK_UnSupport_Handler = Unsupported_Handler; | 208 info->FSDK_UnSupport_Handler = UnsupportedHandlerTrampoline; |
189 FSDK_SetUnSpObjProcessHandler(&unsuppored_info); | 209 FSDK_SetUnSpObjProcessHandler(info); |
Lei Zhang
2015/02/25 23:02:50
I'm surprised this ever worked. Wouldn't |unsuppor
Tom Sepez
2015/02/25 23:25:22
I thought it copied its contents, but further insp
| |
190 } | 210 } |
191 | 211 |
192 void EmbedderTest::TearDown() { | 212 void EmbedderTest::TearDown() { |
193 if (form_handle_) { | 213 if (form_handle_) { |
194 FORM_DoDocumentAAction(form_handle_, FPDFDOC_AACTION_WC); | 214 FORM_DoDocumentAAction(form_handle_, FPDFDOC_AACTION_WC); |
195 FPDFDOC_ExitFormFillEnvironment(form_handle_); | 215 FPDFDOC_ExitFormFillEnvironment(form_handle_); |
196 } | 216 } |
197 if (document_) { | 217 if (document_) { |
198 FPDF_CloseDocument(document_); | 218 FPDF_CloseDocument(document_); |
199 } | 219 } |
(...skipping 29 matching lines...) Expand all Loading... | |
229 | 249 |
230 if (!FPDFAvail_IsLinearized(avail_)) { | 250 if (!FPDFAvail_IsLinearized(avail_)) { |
231 document_ = FPDF_LoadCustomDocument(&file_access_, NULL); | 251 document_ = FPDF_LoadCustomDocument(&file_access_, NULL); |
232 } else { | 252 } else { |
233 document_ = FPDFAvail_GetDocument(avail_, NULL); | 253 document_ = FPDFAvail_GetDocument(avail_, NULL); |
234 } | 254 } |
235 | 255 |
236 (void) FPDF_GetDocPermissions(document_); | 256 (void) FPDF_GetDocPermissions(document_); |
237 (void) FPDFAvail_IsFormAvail(avail_, &hints_); | 257 (void) FPDFAvail_IsFormAvail(avail_, &hints_); |
238 | 258 |
239 IPDF_JSPLATFORM platform_callbacks; | 259 IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this); |
240 memset(&platform_callbacks, '\0', sizeof(platform_callbacks)); | 260 memset(platform, 0, sizeof(IPDF_JSPLATFORM)); |
241 platform_callbacks.version = 1; | 261 platform->version = 1; |
242 platform_callbacks.app_alert = Form_Alert; | 262 platform->app_alert = AlertTrampoline; |
243 | 263 |
244 FPDF_FORMFILLINFO form_callbacks; | 264 FPDF_FORMFILLINFO* formfillinfo = static_cast<FPDF_FORMFILLINFO*>(this); |
245 memset(&form_callbacks, '\0', sizeof(form_callbacks)); | 265 memset(formfillinfo, 0, sizeof(FPDF_FORMFILLINFO)); |
246 form_callbacks.version = 1; | 266 formfillinfo->version = 1; |
247 form_callbacks.m_pJsPlatform = &platform_callbacks; | 267 formfillinfo->m_pJsPlatform = platform; |
248 | 268 |
249 form_handle_ = FPDFDOC_InitFormFillEnvironment(document_, &form_callbacks); | 269 form_handle_ = FPDFDOC_InitFormFillEnvironment(document_, formfillinfo); |
250 FPDF_SetFormFieldHighlightColor(form_handle_, 0, 0xFFE4DD); | 270 FPDF_SetFormFieldHighlightColor(form_handle_, 0, 0xFFE4DD); |
251 FPDF_SetFormFieldHighlightAlpha(form_handle_, 100); | 271 FPDF_SetFormFieldHighlightAlpha(form_handle_, 100); |
252 | 272 |
253 return true; | 273 return true; |
254 } | 274 } |
255 | 275 |
256 void EmbedderTest::DoOpenActions() { | 276 void EmbedderTest::DoOpenActions() { |
257 FORM_DoDocumentJSAction(form_handle_); | 277 FORM_DoDocumentJSAction(form_handle_); |
258 FORM_DoDocumentOpenAction(form_handle_); | 278 FORM_DoDocumentOpenAction(form_handle_); |
259 } | 279 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 FPDF_FFLDraw(form_handle_, bitmap, page, 0, 0, width, height, 0, 0); | 311 FPDF_FFLDraw(form_handle_, bitmap, page, 0, 0, width, height, 0, 0); |
292 return bitmap; | 312 return bitmap; |
293 } | 313 } |
294 | 314 |
295 void EmbedderTest::UnloadPage(FPDF_PAGE page) { | 315 void EmbedderTest::UnloadPage(FPDF_PAGE page) { |
296 FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_CLOSE); | 316 FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_CLOSE); |
297 FORM_OnBeforeClosePage(page, form_handle_); | 317 FORM_OnBeforeClosePage(page, form_handle_); |
298 FPDF_ClosePage(page); | 318 FPDF_ClosePage(page); |
299 } | 319 } |
300 | 320 |
321 // static | |
322 void EmbedderTest::UnsupportedHandlerTrampoline(UNSUPPORT_INFO* info, | |
323 int type) { | |
324 EmbedderTest* test = static_cast<EmbedderTest*>(info); | |
325 if (test->delegate_) { | |
Lei Zhang
2015/02/25 23:02:51
Should we just assume |delegate_| is always valid?
Tom Sepez
2015/02/25 23:25:22
Yep. In fact, we can make SetDelegate(0) mean res
| |
326 test->delegate_->UnsupportedHandler(type); | |
327 } | |
328 } | |
329 | |
330 // static | |
331 int EmbedderTest::AlertTrampoline(IPDF_JSPLATFORM* platform, | |
332 FPDF_WIDESTRING message, | |
333 FPDF_WIDESTRING title, | |
334 int type, | |
335 int icon) { | |
336 EmbedderTest* test = static_cast<EmbedderTest*>(platform); | |
337 if (!test->delegate_) { | |
338 return 0; | |
339 } | |
340 return test->delegate_->Alert(message, title, type, icon); | |
341 } | |
342 | |
301 // Can't use gtest-provided main since we need to stash the path to the | 343 // Can't use gtest-provided main since we need to stash the path to the |
302 // executable in order to find the external V8 binary data files. | 344 // executable in order to find the external V8 binary data files. |
303 int main(int argc, char** argv) { | 345 int main(int argc, char** argv) { |
304 g_exe_path_ = argv[0]; | 346 g_exe_path_ = argv[0]; |
305 testing::InitGoogleTest(&argc, argv); | 347 testing::InitGoogleTest(&argc, argv); |
306 return RUN_ALL_TESTS(); | 348 return RUN_ALL_TESTS(); |
307 } | 349 } |
OLD | NEW |