Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(323)

Side by Side Diff: testing/embedder_test.cpp

Issue 960703002: Merge to XFA: Implement a delegate for EmbedderTests. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « testing/embedder_test.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 default_delegate_ = new EmbedderTestDefaultDelegate();
186 delegate_ = default_delegate_;
187 }
188
189 EmbedderTest::~EmbedderTest() {
190 delete default_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);
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);
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 } else { 252 } else {
233 document_ = FPDFAvail_GetDocument(avail_, NULL); 253 document_ = FPDFAvail_GetDocument(avail_, NULL);
234 } 254 }
235 if (!document_) { 255 if (!document_) {
236 return false; 256 return false;
237 } 257 }
238 (void) FPDF_LoadXFA(document_); 258 (void) FPDF_LoadXFA(document_);
239 (void) FPDF_GetDocPermissions(document_); 259 (void) FPDF_GetDocPermissions(document_);
240 (void) FPDFAvail_IsFormAvail(avail_, &hints_); 260 (void) FPDFAvail_IsFormAvail(avail_, &hints_);
241 261
242 IPDF_JSPLATFORM platform_callbacks; 262 IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this);
243 memset(&platform_callbacks, '\0', sizeof(platform_callbacks)); 263 memset(platform, 0, sizeof(IPDF_JSPLATFORM));
244 platform_callbacks.version = 1; 264 platform->version = 1;
245 platform_callbacks.app_alert = Form_Alert; 265 platform->app_alert = AlertTrampoline;
246 266
247 FPDF_FORMFILLINFO form_callbacks; 267 FPDF_FORMFILLINFO* formfillinfo = static_cast<FPDF_FORMFILLINFO*>(this);
248 memset(&form_callbacks, '\0', sizeof(form_callbacks)); 268 memset(formfillinfo, 0, sizeof(FPDF_FORMFILLINFO));
249 form_callbacks.version = 1; 269 formfillinfo->version = 1;
250 form_callbacks.m_pJsPlatform = &platform_callbacks; 270 formfillinfo->m_pJsPlatform = platform;
251 271
252 form_handle_ = FPDFDOC_InitFormFillEnvironment(document_, &form_callbacks); 272 form_handle_ = FPDFDOC_InitFormFillEnvironment(document_, formfillinfo);
253 FPDF_SetFormFieldHighlightColor(form_handle_, 0, 0xFFE4DD); 273 FPDF_SetFormFieldHighlightColor(form_handle_, 0, 0xFFE4DD);
254 FPDF_SetFormFieldHighlightAlpha(form_handle_, 100); 274 FPDF_SetFormFieldHighlightAlpha(form_handle_, 100);
255 275
256 return true; 276 return true;
257 } 277 }
258 278
259 void EmbedderTest::DoOpenActions() { 279 void EmbedderTest::DoOpenActions() {
260 FORM_DoDocumentJSAction(form_handle_); 280 FORM_DoDocumentJSAction(form_handle_);
261 FORM_DoDocumentOpenAction(form_handle_); 281 FORM_DoDocumentOpenAction(form_handle_);
262 } 282 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 FPDF_FFLDraw(form_handle_, bitmap, page, 0, 0, width, height, 0, 0); 314 FPDF_FFLDraw(form_handle_, bitmap, page, 0, 0, width, height, 0, 0);
295 return bitmap; 315 return bitmap;
296 } 316 }
297 317
298 void EmbedderTest::UnloadPage(FPDF_PAGE page) { 318 void EmbedderTest::UnloadPage(FPDF_PAGE page) {
299 FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_CLOSE); 319 FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_CLOSE);
300 FORM_OnBeforeClosePage(page, form_handle_); 320 FORM_OnBeforeClosePage(page, form_handle_);
301 FPDF_ClosePage(page); 321 FPDF_ClosePage(page);
302 } 322 }
303 323
324 // static
325 void EmbedderTest::UnsupportedHandlerTrampoline(UNSUPPORT_INFO* info,
326 int type) {
327 EmbedderTest* test = static_cast<EmbedderTest*>(info);
328 test->delegate_->UnsupportedHandler(type);
329 }
330
331 // static
332 int EmbedderTest::AlertTrampoline(IPDF_JSPLATFORM* platform,
333 FPDF_WIDESTRING message,
334 FPDF_WIDESTRING title,
335 int type,
336 int icon) {
337 EmbedderTest* test = static_cast<EmbedderTest*>(platform);
338 return test->delegate_->Alert(message, title, type, icon);
339 }
340
304 // Can't use gtest-provided main since we need to stash the path to the 341 // Can't use gtest-provided main since we need to stash the path to the
305 // executable in order to find the external V8 binary data files. 342 // executable in order to find the external V8 binary data files.
306 int main(int argc, char** argv) { 343 int main(int argc, char** argv) {
307 g_exe_path_ = argv[0]; 344 g_exe_path_ = argv[0];
308 testing::InitGoogleTest(&argc, argv); 345 testing::InitGoogleTest(&argc, argv);
309 return RUN_ALL_TESTS(); 346 return RUN_ALL_TESTS();
310 } 347 }
OLDNEW
« no previous file with comments | « testing/embedder_test.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698