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

Side by Side Diff: testing/embedder_test.cpp

Issue 1567643002: Merge to XFA: Add fpdf_edit basic creation embedder test. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 4 years, 11 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 2015 PDFium Authors. All rights reserved. 1 // Copyright 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 "testing/embedder_test.h" 5 #include "testing/embedder_test.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 8
9 #include <list> 9 #include <list>
10 #include <string> 10 #include <string>
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 95
96 #ifdef PDF_ENABLE_V8 96 #ifdef PDF_ENABLE_V8
97 v8::V8::ShutdownPlatform(); 97 v8::V8::ShutdownPlatform();
98 delete platform_; 98 delete platform_;
99 #endif // PDF_ENABLE_V8 99 #endif // PDF_ENABLE_V8
100 100
101 delete loader_; 101 delete loader_;
102 free(file_contents_); 102 free(file_contents_);
103 } 103 }
104 104
105 bool EmbedderTest::CreateEmptyDocument() {
106 document_ = FPDF_CreateNewDocument();
107 if (!document_)
108 return false;
109
110 SetupFormFillEnvironment();
111 return true;
112 }
113
105 bool EmbedderTest::OpenDocument(const std::string& filename, 114 bool EmbedderTest::OpenDocument(const std::string& filename,
106 bool must_linearize) { 115 bool must_linearize) {
107 std::string file_path; 116 std::string file_path;
108 if (!PathService::GetTestFilePath(filename, &file_path)) 117 if (!PathService::GetTestFilePath(filename, &file_path))
109 return false; 118 return false;
110 file_contents_ = GetFileContents(file_path.c_str(), &file_length_); 119 file_contents_ = GetFileContents(file_path.c_str(), &file_length_);
111 if (!file_contents_) 120 if (!file_contents_)
112 return false; 121 return false;
113 122
114 loader_ = new TestLoader(file_contents_, file_length_); 123 loader_ = new TestLoader(file_contents_, file_length_);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 171
163 #ifdef PDF_ENABLE_XFA 172 #ifdef PDF_ENABLE_XFA
164 int docType = DOCTYPE_PDF; 173 int docType = DOCTYPE_PDF;
165 if (FPDF_HasXFAField(document_, &docType)) { 174 if (FPDF_HasXFAField(document_, &docType)) {
166 if (docType != DOCTYPE_PDF) 175 if (docType != DOCTYPE_PDF)
167 (void)FPDF_LoadXFA(document_); 176 (void)FPDF_LoadXFA(document_);
168 } 177 }
169 #endif // PDF_ENABLE_XFA 178 #endif // PDF_ENABLE_XFA
170 179
171 (void)FPDF_GetDocPermissions(document_); 180 (void)FPDF_GetDocPermissions(document_);
181 SetupFormFillEnvironment();
182 return true;
183 }
172 184
185 void EmbedderTest::SetupFormFillEnvironment() {
173 IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this); 186 IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this);
174 memset(platform, 0, sizeof(IPDF_JSPLATFORM)); 187 memset(platform, 0, sizeof(IPDF_JSPLATFORM));
175 platform->version = 2; 188 platform->version = 2;
176 platform->app_alert = AlertTrampoline; 189 platform->app_alert = AlertTrampoline;
177 190
178 FPDF_FORMFILLINFO* formfillinfo = static_cast<FPDF_FORMFILLINFO*>(this); 191 FPDF_FORMFILLINFO* formfillinfo = static_cast<FPDF_FORMFILLINFO*>(this);
179 memset(formfillinfo, 0, sizeof(FPDF_FORMFILLINFO)); 192 memset(formfillinfo, 0, sizeof(FPDF_FORMFILLINFO));
180 #ifdef PDF_ENABLE_XFA 193 #ifdef PDF_ENABLE_XFA
181 formfillinfo->version = 2; 194 formfillinfo->version = 2;
182 #else // PDF_ENABLE_XFA 195 #else // PDF_ENABLE_XFA
183 formfillinfo->version = 1; 196 formfillinfo->version = 1;
184 #endif // PDF_ENABLE_XFA 197 #endif // PDF_ENABLE_XFA
185 formfillinfo->FFI_SetTimer = SetTimerTrampoline; 198 formfillinfo->FFI_SetTimer = SetTimerTrampoline;
186 formfillinfo->FFI_KillTimer = KillTimerTrampoline; 199 formfillinfo->FFI_KillTimer = KillTimerTrampoline;
187 formfillinfo->FFI_GetPage = GetPageTrampoline; 200 formfillinfo->FFI_GetPage = GetPageTrampoline;
188 formfillinfo->m_pJsPlatform = platform; 201 formfillinfo->m_pJsPlatform = platform;
189 202
190 form_handle_ = FPDFDOC_InitFormFillEnvironment(document_, formfillinfo); 203 form_handle_ = FPDFDOC_InitFormFillEnvironment(document_, formfillinfo);
191 FPDF_SetFormFieldHighlightColor(form_handle_, 0, 0xFFE4DD); 204 FPDF_SetFormFieldHighlightColor(form_handle_, 0, 0xFFE4DD);
192 FPDF_SetFormFieldHighlightAlpha(form_handle_, 100); 205 FPDF_SetFormFieldHighlightAlpha(form_handle_, 100);
193
194 return true;
195 } 206 }
196 207
197 void EmbedderTest::DoOpenActions() { 208 void EmbedderTest::DoOpenActions() {
198 FORM_DoDocumentJSAction(form_handle_); 209 FORM_DoDocumentJSAction(form_handle_);
199 FORM_DoDocumentOpenAction(form_handle_); 210 FORM_DoDocumentOpenAction(form_handle_);
200 } 211 }
201 212
202 int EmbedderTest::GetFirstPageNum() { 213 int EmbedderTest::GetFirstPageNum() {
203 int first_page = FPDFAvail_GetFirstPageNum(document_); 214 int first_page = FPDFAvail_GetFirstPageNum(document_);
204 (void)FPDFAvail_IsPageAvail(avail_, first_page, &hints_); 215 (void)FPDFAvail_IsPageAvail(avail_, first_page, &hints_);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 } 317 }
307 318
308 // Can't use gtest-provided main since we need to stash the path to the 319 // Can't use gtest-provided main since we need to stash the path to the
309 // executable in order to find the external V8 binary data files. 320 // executable in order to find the external V8 binary data files.
310 int main(int argc, char** argv) { 321 int main(int argc, char** argv) {
311 g_exe_path_ = argv[0]; 322 g_exe_path_ = argv[0];
312 testing::InitGoogleTest(&argc, argv); 323 testing::InitGoogleTest(&argc, argv);
313 testing::InitGoogleMock(&argc, argv); 324 testing::InitGoogleMock(&argc, argv);
314 return RUN_ALL_TESTS(); 325 return RUN_ALL_TESTS();
315 } 326 }
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