| OLD | NEW |
| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 86 |
| 87 #ifdef PDF_ENABLE_V8 | 87 #ifdef PDF_ENABLE_V8 |
| 88 v8::V8::ShutdownPlatform(); | 88 v8::V8::ShutdownPlatform(); |
| 89 delete platform_; | 89 delete platform_; |
| 90 #endif // PDF_ENABLE_V8 | 90 #endif // PDF_ENABLE_V8 |
| 91 | 91 |
| 92 delete loader_; | 92 delete loader_; |
| 93 free(file_contents_); | 93 free(file_contents_); |
| 94 } | 94 } |
| 95 | 95 |
| 96 bool EmbedderTest::CreateEmptyDocument() { |
| 97 document_ = FPDF_CreateNewDocument(); |
| 98 if (!document_) |
| 99 return false; |
| 100 |
| 101 SetupFormFillEnvironment(); |
| 102 return true; |
| 103 } |
| 104 |
| 96 bool EmbedderTest::OpenDocument(const std::string& filename, | 105 bool EmbedderTest::OpenDocument(const std::string& filename, |
| 97 bool must_linearize) { | 106 bool must_linearize) { |
| 98 std::string file_path; | 107 std::string file_path; |
| 99 if (!PathService::GetTestFilePath(filename, &file_path)) | 108 if (!PathService::GetTestFilePath(filename, &file_path)) |
| 100 return false; | 109 return false; |
| 101 file_contents_ = GetFileContents(file_path.c_str(), &file_length_); | 110 file_contents_ = GetFileContents(file_path.c_str(), &file_length_); |
| 102 if (!file_contents_) | 111 if (!file_contents_) |
| 103 return false; | 112 return false; |
| 104 | 113 |
| 105 loader_ = new TestLoader(file_contents_, file_length_); | 114 loader_ = new TestLoader(file_contents_, file_length_); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 if (must_linearize) { | 154 if (must_linearize) { |
| 146 return false; | 155 return false; |
| 147 } | 156 } |
| 148 document_ = FPDF_LoadCustomDocument(&file_access_, nullptr); | 157 document_ = FPDF_LoadCustomDocument(&file_access_, nullptr); |
| 149 if (!document_) { | 158 if (!document_) { |
| 150 return false; | 159 return false; |
| 151 } | 160 } |
| 152 } | 161 } |
| 153 | 162 |
| 154 (void)FPDF_GetDocPermissions(document_); | 163 (void)FPDF_GetDocPermissions(document_); |
| 164 SetupFormFillEnvironment(); |
| 165 return true; |
| 166 } |
| 155 | 167 |
| 168 void EmbedderTest::SetupFormFillEnvironment() { |
| 156 IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this); | 169 IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this); |
| 157 memset(platform, 0, sizeof(IPDF_JSPLATFORM)); | 170 memset(platform, 0, sizeof(IPDF_JSPLATFORM)); |
| 158 platform->version = 2; | 171 platform->version = 2; |
| 159 platform->app_alert = AlertTrampoline; | 172 platform->app_alert = AlertTrampoline; |
| 160 | 173 |
| 161 FPDF_FORMFILLINFO* formfillinfo = static_cast<FPDF_FORMFILLINFO*>(this); | 174 FPDF_FORMFILLINFO* formfillinfo = static_cast<FPDF_FORMFILLINFO*>(this); |
| 162 memset(formfillinfo, 0, sizeof(FPDF_FORMFILLINFO)); | 175 memset(formfillinfo, 0, sizeof(FPDF_FORMFILLINFO)); |
| 163 formfillinfo->version = 1; | 176 formfillinfo->version = 1; |
| 164 formfillinfo->FFI_SetTimer = SetTimerTrampoline; | 177 formfillinfo->FFI_SetTimer = SetTimerTrampoline; |
| 165 formfillinfo->FFI_KillTimer = KillTimerTrampoline; | 178 formfillinfo->FFI_KillTimer = KillTimerTrampoline; |
| 166 formfillinfo->FFI_GetPage = GetPageTrampoline; | 179 formfillinfo->FFI_GetPage = GetPageTrampoline; |
| 167 formfillinfo->m_pJsPlatform = platform; | 180 formfillinfo->m_pJsPlatform = platform; |
| 168 | 181 |
| 169 form_handle_ = FPDFDOC_InitFormFillEnvironment(document_, formfillinfo); | 182 form_handle_ = FPDFDOC_InitFormFillEnvironment(document_, formfillinfo); |
| 170 FPDF_SetFormFieldHighlightColor(form_handle_, 0, 0xFFE4DD); | 183 FPDF_SetFormFieldHighlightColor(form_handle_, 0, 0xFFE4DD); |
| 171 FPDF_SetFormFieldHighlightAlpha(form_handle_, 100); | 184 FPDF_SetFormFieldHighlightAlpha(form_handle_, 100); |
| 172 | |
| 173 return true; | |
| 174 } | 185 } |
| 175 | 186 |
| 176 void EmbedderTest::DoOpenActions() { | 187 void EmbedderTest::DoOpenActions() { |
| 177 FORM_DoDocumentJSAction(form_handle_); | 188 FORM_DoDocumentJSAction(form_handle_); |
| 178 FORM_DoDocumentOpenAction(form_handle_); | 189 FORM_DoDocumentOpenAction(form_handle_); |
| 179 } | 190 } |
| 180 | 191 |
| 181 int EmbedderTest::GetFirstPageNum() { | 192 int EmbedderTest::GetFirstPageNum() { |
| 182 int first_page = FPDFAvail_GetFirstPageNum(document_); | 193 int first_page = FPDFAvail_GetFirstPageNum(document_); |
| 183 (void)FPDFAvail_IsPageAvail(avail_, first_page, &hints_); | 194 (void)FPDFAvail_IsPageAvail(avail_, first_page, &hints_); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 } | 296 } |
| 286 | 297 |
| 287 // Can't use gtest-provided main since we need to stash the path to the | 298 // Can't use gtest-provided main since we need to stash the path to the |
| 288 // executable in order to find the external V8 binary data files. | 299 // executable in order to find the external V8 binary data files. |
| 289 int main(int argc, char** argv) { | 300 int main(int argc, char** argv) { |
| 290 g_exe_path_ = argv[0]; | 301 g_exe_path_ = argv[0]; |
| 291 testing::InitGoogleTest(&argc, argv); | 302 testing::InitGoogleTest(&argc, argv); |
| 292 testing::InitGoogleMock(&argc, argv); | 303 testing::InitGoogleMock(&argc, argv); |
| 293 return RUN_ALL_TESTS(); | 304 return RUN_ALL_TESTS(); |
| 294 } | 305 } |
| OLD | NEW |