Lei Zhang | 1ac47eb | 2015-12-21 11:04:44 -0800 | [diff] [blame^] | 1 | // Copyright 2015 PDFium Authors. All rights reserved. |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Wei Li | 091f7a0 | 2015-11-09 12:09:55 -0800 | [diff] [blame] | 5 | #include "testing/embedder_test.h" |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 6 | |
| 7 | #include <limits.h> |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 8 | |
| 9 | #include <list> |
| 10 | #include <string> |
| 11 | #include <utility> |
| 12 | #include <vector> |
| 13 | |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 14 | #include "public/fpdf_dataavail.h" |
| 15 | #include "public/fpdf_text.h" |
| 16 | #include "public/fpdfview.h" |
Tom Sepez | a310e00 | 2015-02-27 13:03:07 -0800 | [diff] [blame] | 17 | #include "testing/gmock/include/gmock/gmock.h" |
Wei Li | 091f7a0 | 2015-11-09 12:09:55 -0800 | [diff] [blame] | 18 | #include "testing/test_support.h" |
| 19 | #include "testing/utils/path_service.h" |
Tom Sepez | 452b4f3 | 2015-10-13 09:27:27 -0700 | [diff] [blame] | 20 | |
| 21 | #ifdef PDF_ENABLE_V8 |
Tom Sepez | 6efc0ad | 2015-06-02 17:11:18 -0700 | [diff] [blame] | 22 | #include "v8/include/v8.h" |
Lei Zhang | 8241df7 | 2015-11-06 14:38:48 -0800 | [diff] [blame] | 23 | #include "v8/include/v8-platform.h" |
Tom Sepez | 452b4f3 | 2015-10-13 09:27:27 -0700 | [diff] [blame] | 24 | #endif // PDF_ENABLE_V8 |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 25 | |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 26 | namespace { |
Tom Sepez | 1b1bb49 | 2015-01-22 17:36:32 -0800 | [diff] [blame] | 27 | const char* g_exe_path_ = nullptr; |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 28 | } // namespace |
| 29 | |
Tom Sepez | cf22eb8 | 2015-05-12 17:28:08 -0700 | [diff] [blame] | 30 | FPDF_BOOL Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) { |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 31 | return true; |
| 32 | } |
| 33 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 34 | void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) {} |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 35 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 36 | EmbedderTest::EmbedderTest() |
Tom Sepez | a72e8e2 | 2015-10-07 10:17:53 -0700 | [diff] [blame] | 37 | : default_delegate_(new EmbedderTest::Delegate()), |
| 38 | document_(nullptr), |
Tom Sepez | 4cb0fa7 | 2015-02-25 16:08:18 -0800 | [diff] [blame] | 39 | form_handle_(nullptr), |
| 40 | avail_(nullptr), |
Tom Sepez | a72e8e2 | 2015-10-07 10:17:53 -0700 | [diff] [blame] | 41 | external_isolate_(nullptr), |
Tom Sepez | 4cb0fa7 | 2015-02-25 16:08:18 -0800 | [diff] [blame] | 42 | loader_(nullptr), |
| 43 | file_length_(0), |
| 44 | file_contents_(nullptr) { |
| 45 | memset(&hints_, 0, sizeof(hints_)); |
| 46 | memset(&file_access_, 0, sizeof(file_access_)); |
| 47 | memset(&file_avail_, 0, sizeof(file_avail_)); |
Tom Sepez | a72e8e2 | 2015-10-07 10:17:53 -0700 | [diff] [blame] | 48 | delegate_ = default_delegate_.get(); |
Tom Sepez | 4cb0fa7 | 2015-02-25 16:08:18 -0800 | [diff] [blame] | 49 | |
Tom Sepez | 452b4f3 | 2015-10-13 09:27:27 -0700 | [diff] [blame] | 50 | #ifdef PDF_ENABLE_V8 |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 51 | #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
Tom Sepez | d831dc7 | 2015-10-19 16:04:22 -0700 | [diff] [blame] | 52 | InitializeV8ForPDFium(g_exe_path_, std::string(), &natives_, &snapshot_, |
| 53 | &platform_); |
| 54 | #else |
| 55 | InitializeV8ForPDFium(&platform_); |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 56 | #endif // V8_USE_EXTERNAL_STARTUP_DATA |
Tom Sepez | 452b4f3 | 2015-10-13 09:27:27 -0700 | [diff] [blame] | 57 | #endif // FPDF_ENABLE_V8 |
Tom Sepez | f288bb1 | 2015-11-20 12:12:46 -0800 | [diff] [blame] | 58 | } |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 59 | |
Tom Sepez | f288bb1 | 2015-11-20 12:12:46 -0800 | [diff] [blame] | 60 | EmbedderTest::~EmbedderTest() {} |
| 61 | |
| 62 | void EmbedderTest::SetUp() { |
Tom Sepez | a72e8e2 | 2015-10-07 10:17:53 -0700 | [diff] [blame] | 63 | FPDF_LIBRARY_CONFIG config; |
| 64 | config.version = 2; |
| 65 | config.m_pUserFontPaths = nullptr; |
Tom Sepez | a72e8e2 | 2015-10-07 10:17:53 -0700 | [diff] [blame] | 66 | config.m_v8EmbedderSlot = 0; |
Tom Sepez | 452b4f3 | 2015-10-13 09:27:27 -0700 | [diff] [blame] | 67 | config.m_pIsolate = external_isolate_; |
Tom Sepez | a72e8e2 | 2015-10-07 10:17:53 -0700 | [diff] [blame] | 68 | FPDF_InitLibraryWithConfig(&config); |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 69 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 70 | UNSUPPORT_INFO* info = static_cast<UNSUPPORT_INFO*>(this); |
| 71 | memset(info, 0, sizeof(UNSUPPORT_INFO)); |
| 72 | info->version = 1; |
| 73 | info->FSDK_UnSupport_Handler = UnsupportedHandlerTrampoline; |
| 74 | FSDK_SetUnSpObjProcessHandler(info); |
| 75 | } |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 76 | |
| 77 | void EmbedderTest::TearDown() { |
Tom Sepez | da8189e | 2015-01-30 14:41:50 -0800 | [diff] [blame] | 78 | if (document_) { |
Lei Zhang | d27acae | 2015-05-15 15:36:02 -0700 | [diff] [blame] | 79 | FORM_DoDocumentAAction(form_handle_, FPDFDOC_AACTION_WC); |
Tom Sepez | c46d000 | 2015-11-30 15:46:36 -0800 | [diff] [blame] | 80 | #ifdef PDF_ENABLE_XFA |
Lei Zhang | ba02691 | 2015-07-16 10:06:11 -0700 | [diff] [blame] | 81 | // Note: The shut down order here is the reverse of the non-XFA branch |
| 82 | // order. Need to work out if this is required, and if it is, the lifetimes |
| 83 | // of objects owned by |doc| that |form| reference. |
Tom Sepez | da8189e | 2015-01-30 14:41:50 -0800 | [diff] [blame] | 84 | FPDF_CloseDocument(document_); |
Lei Zhang | d27acae | 2015-05-15 15:36:02 -0700 | [diff] [blame] | 85 | FPDFDOC_ExitFormFillEnvironment(form_handle_); |
Tom Sepez | c46d000 | 2015-11-30 15:46:36 -0800 | [diff] [blame] | 86 | #else // PDF_ENABLE_XFA |
| 87 | FPDFDOC_ExitFormFillEnvironment(form_handle_); |
| 88 | FPDF_CloseDocument(document_); |
| 89 | #endif // PDF_ENABLE_XFA |
Tom Sepez | da8189e | 2015-01-30 14:41:50 -0800 | [diff] [blame] | 90 | } |
Tom Sepez | c46d000 | 2015-11-30 15:46:36 -0800 | [diff] [blame] | 91 | |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 92 | FPDFAvail_Destroy(avail_); |
| 93 | FPDF_DestroyLibrary(); |
Tom Sepez | 452b4f3 | 2015-10-13 09:27:27 -0700 | [diff] [blame] | 94 | |
| 95 | #ifdef PDF_ENABLE_V8 |
Tom Sepez | 6efc0ad | 2015-06-02 17:11:18 -0700 | [diff] [blame] | 96 | v8::V8::ShutdownPlatform(); |
| 97 | delete platform_; |
Tom Sepez | 452b4f3 | 2015-10-13 09:27:27 -0700 | [diff] [blame] | 98 | #endif // PDF_ENABLE_V8 |
| 99 | |
Lei Zhang | d27acae | 2015-05-15 15:36:02 -0700 | [diff] [blame] | 100 | delete loader_; |
| 101 | free(file_contents_); |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 102 | } |
| 103 | |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 104 | bool EmbedderTest::OpenDocument(const std::string& filename, |
| 105 | bool must_linearize) { |
Wei Li | 091f7a0 | 2015-11-09 12:09:55 -0800 | [diff] [blame] | 106 | std::string file_path; |
| 107 | if (!PathService::GetTestFilePath(filename, &file_path)) |
| 108 | return false; |
| 109 | file_contents_ = GetFileContents(file_path.c_str(), &file_length_); |
Dan Sinclair | 6be2aab | 2015-10-28 13:58:49 -0400 | [diff] [blame] | 110 | if (!file_contents_) |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 111 | return false; |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 112 | |
| 113 | loader_ = new TestLoader(file_contents_, file_length_); |
| 114 | file_access_.m_FileLen = static_cast<unsigned long>(file_length_); |
Tom Sepez | d831dc7 | 2015-10-19 16:04:22 -0700 | [diff] [blame] | 115 | file_access_.m_GetBlock = TestLoader::GetBlock; |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 116 | file_access_.m_Param = loader_; |
| 117 | |
| 118 | file_avail_.version = 1; |
| 119 | file_avail_.IsDataAvail = Is_Data_Avail; |
| 120 | |
| 121 | hints_.version = 1; |
| 122 | hints_.AddSegment = Add_Segment; |
| 123 | |
| 124 | avail_ = FPDFAvail_Create(&file_avail_, &file_access_); |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 125 | |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 126 | if (FPDFAvail_IsLinearized(avail_) == PDF_LINEARIZED) { |
Lei Zhang | d27acae | 2015-05-15 15:36:02 -0700 | [diff] [blame] | 127 | document_ = FPDFAvail_GetDocument(avail_, nullptr); |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 128 | if (!document_) { |
| 129 | return false; |
| 130 | } |
| 131 | int32_t nRet = PDF_DATA_NOTAVAIL; |
| 132 | while (nRet == PDF_DATA_NOTAVAIL) { |
| 133 | nRet = FPDFAvail_IsDocAvail(avail_, &hints_); |
| 134 | } |
| 135 | if (nRet == PDF_DATA_ERROR) { |
| 136 | return false; |
| 137 | } |
| 138 | nRet = FPDFAvail_IsFormAvail(avail_, &hints_); |
| 139 | if (nRet == PDF_FORM_ERROR || nRet == PDF_FORM_NOTAVAIL) { |
| 140 | return false; |
| 141 | } |
| 142 | int page_count = FPDF_GetPageCount(document_); |
| 143 | for (int i = 0; i < page_count; ++i) { |
| 144 | nRet = PDF_DATA_NOTAVAIL; |
| 145 | while (nRet == PDF_DATA_NOTAVAIL) { |
| 146 | nRet = FPDFAvail_IsPageAvail(avail_, i, &hints_); |
| 147 | } |
| 148 | if (nRet == PDF_DATA_ERROR) { |
| 149 | return false; |
| 150 | } |
| 151 | } |
| 152 | } else { |
| 153 | if (must_linearize) { |
| 154 | return false; |
| 155 | } |
| 156 | document_ = FPDF_LoadCustomDocument(&file_access_, nullptr); |
| 157 | if (!document_) { |
| 158 | return false; |
| 159 | } |
| 160 | } |
Dan Sinclair | 6be2aab | 2015-10-28 13:58:49 -0400 | [diff] [blame] | 161 | |
Tom Sepez | c46d000 | 2015-11-30 15:46:36 -0800 | [diff] [blame] | 162 | #ifdef PDF_ENABLE_XFA |
JUN FANG | 827a172 | 2015-03-05 13:39:21 -0800 | [diff] [blame] | 163 | int docType = DOCTYPE_PDF; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 164 | if (FPDF_HasXFAField(document_, &docType)) { |
JUN FANG | 827a172 | 2015-03-05 13:39:21 -0800 | [diff] [blame] | 165 | if (docType != DOCTYPE_PDF) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 166 | (void)FPDF_LoadXFA(document_); |
JUN FANG | 827a172 | 2015-03-05 13:39:21 -0800 | [diff] [blame] | 167 | } |
Tom Sepez | c46d000 | 2015-11-30 15:46:36 -0800 | [diff] [blame] | 168 | #endif // PDF_ENABLE_XFA |
Dan Sinclair | 6be2aab | 2015-10-28 13:58:49 -0400 | [diff] [blame] | 169 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 170 | (void)FPDF_GetDocPermissions(document_); |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 171 | |
Tom Sepez | 4cb0fa7 | 2015-02-25 16:08:18 -0800 | [diff] [blame] | 172 | IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this); |
| 173 | memset(platform, 0, sizeof(IPDF_JSPLATFORM)); |
Jochen Eisinger | 06b6002 | 2015-07-30 17:44:35 +0200 | [diff] [blame] | 174 | platform->version = 2; |
Tom Sepez | 4cb0fa7 | 2015-02-25 16:08:18 -0800 | [diff] [blame] | 175 | platform->app_alert = AlertTrampoline; |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 176 | |
Tom Sepez | 4cb0fa7 | 2015-02-25 16:08:18 -0800 | [diff] [blame] | 177 | FPDF_FORMFILLINFO* formfillinfo = static_cast<FPDF_FORMFILLINFO*>(this); |
| 178 | memset(formfillinfo, 0, sizeof(FPDF_FORMFILLINFO)); |
Lei Zhang | cd39695 | 2015-11-04 20:26:50 -0800 | [diff] [blame] | 179 | #ifdef PDF_ENABLE_XFA |
| 180 | formfillinfo->version = 2; |
Tom Sepez | c46d000 | 2015-11-30 15:46:36 -0800 | [diff] [blame] | 181 | #else // PDF_ENABLE_XFA |
Tom Sepez | 4cb0fa7 | 2015-02-25 16:08:18 -0800 | [diff] [blame] | 182 | formfillinfo->version = 1; |
Tom Sepez | c46d000 | 2015-11-30 15:46:36 -0800 | [diff] [blame] | 183 | #endif // PDF_ENABLE_XFA |
Tom Sepez | 6efc0ad | 2015-06-02 17:11:18 -0700 | [diff] [blame] | 184 | formfillinfo->FFI_SetTimer = SetTimerTrampoline; |
| 185 | formfillinfo->FFI_KillTimer = KillTimerTrampoline; |
Tom Sepez | 396e872 | 2015-09-09 10:16:08 -0700 | [diff] [blame] | 186 | formfillinfo->FFI_GetPage = GetPageTrampoline; |
Tom Sepez | 4cb0fa7 | 2015-02-25 16:08:18 -0800 | [diff] [blame] | 187 | formfillinfo->m_pJsPlatform = platform; |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 188 | |
Tom Sepez | 4cb0fa7 | 2015-02-25 16:08:18 -0800 | [diff] [blame] | 189 | form_handle_ = FPDFDOC_InitFormFillEnvironment(document_, formfillinfo); |
Tom Sepez | da8189e | 2015-01-30 14:41:50 -0800 | [diff] [blame] | 190 | FPDF_SetFormFieldHighlightColor(form_handle_, 0, 0xFFE4DD); |
| 191 | FPDF_SetFormFieldHighlightAlpha(form_handle_, 100); |
| 192 | |
| 193 | return true; |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 194 | } |
| 195 | |
Tom Sepez | da8189e | 2015-01-30 14:41:50 -0800 | [diff] [blame] | 196 | void EmbedderTest::DoOpenActions() { |
| 197 | FORM_DoDocumentJSAction(form_handle_); |
| 198 | FORM_DoDocumentOpenAction(form_handle_); |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | int EmbedderTest::GetFirstPageNum() { |
| 202 | int first_page = FPDFAvail_GetFirstPageNum(document_); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 203 | (void)FPDFAvail_IsPageAvail(avail_, first_page, &hints_); |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 204 | return first_page; |
| 205 | } |
| 206 | |
| 207 | int EmbedderTest::GetPageCount() { |
| 208 | int page_count = FPDF_GetPageCount(document_); |
| 209 | for (int i = 0; i < page_count; ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 210 | (void)FPDFAvail_IsPageAvail(avail_, i, &hints_); |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 211 | } |
| 212 | return page_count; |
| 213 | } |
| 214 | |
Tom Sepez | da8189e | 2015-01-30 14:41:50 -0800 | [diff] [blame] | 215 | FPDF_PAGE EmbedderTest::LoadPage(int page_number) { |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 216 | FPDF_PAGE page = FPDF_LoadPage(document_, page_number); |
| 217 | if (!page) { |
| 218 | return nullptr; |
| 219 | } |
Tom Sepez | da8189e | 2015-01-30 14:41:50 -0800 | [diff] [blame] | 220 | FORM_OnAfterLoadPage(page, form_handle_); |
| 221 | FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_OPEN); |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 222 | return page; |
| 223 | } |
| 224 | |
Tom Sepez | 396e872 | 2015-09-09 10:16:08 -0700 | [diff] [blame] | 225 | FPDF_PAGE EmbedderTest::LoadAndCachePage(int page_number) { |
| 226 | FPDF_PAGE page = delegate_->GetPage(form_handle_, document_, page_number); |
| 227 | if (!page) { |
| 228 | return nullptr; |
| 229 | } |
| 230 | FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_OPEN); |
| 231 | return page; |
| 232 | } |
| 233 | |
Tom Sepez | da8189e | 2015-01-30 14:41:50 -0800 | [diff] [blame] | 234 | FPDF_BITMAP EmbedderTest::RenderPage(FPDF_PAGE page) { |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 235 | int width = static_cast<int>(FPDF_GetPageWidth(page)); |
| 236 | int height = static_cast<int>(FPDF_GetPageHeight(page)); |
| 237 | FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, 0); |
| 238 | FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF); |
| 239 | FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); |
Tom Sepez | da8189e | 2015-01-30 14:41:50 -0800 | [diff] [blame] | 240 | FPDF_FFLDraw(form_handle_, bitmap, page, 0, 0, width, height, 0, 0); |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 241 | return bitmap; |
| 242 | } |
| 243 | |
Tom Sepez | da8189e | 2015-01-30 14:41:50 -0800 | [diff] [blame] | 244 | void EmbedderTest::UnloadPage(FPDF_PAGE page) { |
| 245 | FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_CLOSE); |
| 246 | FORM_OnBeforeClosePage(page, form_handle_); |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 247 | FPDF_ClosePage(page); |
| 248 | } |
Tom Sepez | 1b1bb49 | 2015-01-22 17:36:32 -0800 | [diff] [blame] | 249 | |
Tom Sepez | 396e872 | 2015-09-09 10:16:08 -0700 | [diff] [blame] | 250 | FPDF_PAGE EmbedderTest::Delegate::GetPage(FPDF_FORMHANDLE form_handle, |
| 251 | FPDF_DOCUMENT document, |
| 252 | int page_index) { |
| 253 | auto it = m_pageMap.find(page_index); |
| 254 | if (it != m_pageMap.end()) { |
| 255 | return it->second; |
| 256 | } |
| 257 | FPDF_PAGE page = FPDF_LoadPage(document, page_index); |
| 258 | if (!page) { |
| 259 | return nullptr; |
| 260 | } |
| 261 | m_pageMap[page_index] = page; |
| 262 | FORM_OnAfterLoadPage(page, form_handle); |
| 263 | return page; |
| 264 | } |
| 265 | |
Tom Sepez | 4cb0fa7 | 2015-02-25 16:08:18 -0800 | [diff] [blame] | 266 | // static |
| 267 | void EmbedderTest::UnsupportedHandlerTrampoline(UNSUPPORT_INFO* info, |
| 268 | int type) { |
| 269 | EmbedderTest* test = static_cast<EmbedderTest*>(info); |
| 270 | test->delegate_->UnsupportedHandler(type); |
| 271 | } |
| 272 | |
| 273 | // static |
| 274 | int EmbedderTest::AlertTrampoline(IPDF_JSPLATFORM* platform, |
| 275 | FPDF_WIDESTRING message, |
| 276 | FPDF_WIDESTRING title, |
| 277 | int type, |
| 278 | int icon) { |
| 279 | EmbedderTest* test = static_cast<EmbedderTest*>(platform); |
| 280 | return test->delegate_->Alert(message, title, type, icon); |
| 281 | } |
| 282 | |
Tom Sepez | 6efc0ad | 2015-06-02 17:11:18 -0700 | [diff] [blame] | 283 | // static |
| 284 | int EmbedderTest::SetTimerTrampoline(FPDF_FORMFILLINFO* info, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 285 | int msecs, |
| 286 | TimerCallback fn) { |
Tom Sepez | 6efc0ad | 2015-06-02 17:11:18 -0700 | [diff] [blame] | 287 | EmbedderTest* test = static_cast<EmbedderTest*>(info); |
| 288 | return test->delegate_->SetTimer(msecs, fn); |
| 289 | } |
| 290 | |
| 291 | // static |
| 292 | void EmbedderTest::KillTimerTrampoline(FPDF_FORMFILLINFO* info, int id) { |
| 293 | EmbedderTest* test = static_cast<EmbedderTest*>(info); |
| 294 | return test->delegate_->KillTimer(id); |
| 295 | } |
| 296 | |
Tom Sepez | 396e872 | 2015-09-09 10:16:08 -0700 | [diff] [blame] | 297 | // static |
| 298 | FPDF_PAGE EmbedderTest::GetPageTrampoline(FPDF_FORMFILLINFO* info, |
| 299 | FPDF_DOCUMENT document, |
| 300 | int page_index) { |
| 301 | EmbedderTest* test = static_cast<EmbedderTest*>(info); |
Tom Sepez | 436977e | 2015-10-02 09:16:40 -0700 | [diff] [blame] | 302 | return test->delegate_->GetPage(test->form_handle(), document, page_index); |
Tom Sepez | 396e872 | 2015-09-09 10:16:08 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Tom Sepez | 1b1bb49 | 2015-01-22 17:36:32 -0800 | [diff] [blame] | 305 | // Can't use gtest-provided main since we need to stash the path to the |
| 306 | // executable in order to find the external V8 binary data files. |
| 307 | int main(int argc, char** argv) { |
| 308 | g_exe_path_ = argv[0]; |
| 309 | testing::InitGoogleTest(&argc, argv); |
Tom Sepez | a310e00 | 2015-02-27 13:03:07 -0800 | [diff] [blame] | 310 | testing::InitGoogleMock(&argc, argv); |
Tom Sepez | 1b1bb49 | 2015-01-22 17:36:32 -0800 | [diff] [blame] | 311 | return RUN_ALL_TESTS(); |
| 312 | } |