Have PDF test code initialize the blink isolate
Avoid blink::MainThreadIsolate calls and store it in a static for PDF test helpers Bug: 263412 Change-Id: I9b428a193ab0aa3f5505aaa9bf29cae6cb578a15 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5250073 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Dave Tapuska <dtapuska@chromium.org> Cr-Commit-Position: refs/heads/main@{#1254687}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
bc3cc01db0
commit
e155525822
@ -60,7 +60,6 @@
|
||||
#include "third_party/blink/public/platform/web_url.h"
|
||||
#include "third_party/blink/public/platform/web_url_request.h"
|
||||
#include "third_party/blink/public/platform/web_url_response.h"
|
||||
#include "third_party/blink/public/web/blink.h"
|
||||
#include "third_party/blink/public/web/web_associated_url_loader.h"
|
||||
#include "third_party/blink/public/web/web_associated_url_loader_client.h"
|
||||
#include "third_party/blink/public/web/web_plugin_container.h"
|
||||
@ -215,8 +214,7 @@ class FakePdfViewWebPluginClient : public PdfViewWebPlugin::Client {
|
||||
});
|
||||
return associated_loader;
|
||||
});
|
||||
ON_CALL(*this, GetIsolate)
|
||||
.WillByDefault(Return(blink::MainThreadIsolate()));
|
||||
ON_CALL(*this, GetIsolate).WillByDefault(Return(GetBlinkIsolate()));
|
||||
ON_CALL(*this, GetEmbedderOriginString)
|
||||
.WillByDefault(
|
||||
Return("chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/"));
|
||||
|
@ -12,9 +12,9 @@
|
||||
#include "pdf/pdfium/pdfium_engine.h"
|
||||
#include "pdf/pdfium/pdfium_test_base.h"
|
||||
#include "pdf/test/test_client.h"
|
||||
#include "pdf/test/test_helpers.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "third_party/blink/public/common/input/web_input_event.h"
|
||||
#include "third_party/blink/public/web/blink.h"
|
||||
#include "third_party/pdfium/public/fpdf_annot.h"
|
||||
#include "third_party/pdfium/public/fpdf_formfill.h"
|
||||
#include "ui/gfx/geometry/point.h"
|
||||
@ -204,7 +204,7 @@ class FormFillerJavaScriptTest : public FormFillerTest {
|
||||
TEST_P(FormFillerJavaScriptTest, IsolateScoping) {
|
||||
// Enter the embedder's isolate so it can be captured when the
|
||||
// `PDFiumFormFiller` is created.
|
||||
v8::Isolate* embedder_isolate = blink::MainThreadIsolate();
|
||||
v8::Isolate* embedder_isolate = GetBlinkIsolate();
|
||||
v8::Isolate::Scope embedder_isolate_scope(embedder_isolate);
|
||||
|
||||
FormFillerTestClient client;
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "base/test/test_suite.h"
|
||||
#include "mojo/core/embedder/embedder.h"
|
||||
#include "mojo/public/cpp/bindings/binder_map.h"
|
||||
#include "pdf/test/test_helpers.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/blink/public/platform/platform.h"
|
||||
#include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h"
|
||||
@ -76,13 +77,15 @@ class PdfTestSuite final : public base::TestSuite {
|
||||
platform_ = std::make_unique<BlinkPlatformForTesting>();
|
||||
|
||||
mojo::BinderMap binders;
|
||||
blink::Initialize(platform_.get(), &binders,
|
||||
platform_->GetMainThreadScheduler());
|
||||
|
||||
blink::InitializeWithoutIsolateForTesting(
|
||||
platform_.get(), &binders, platform_->GetMainThreadScheduler());
|
||||
v8::Isolate* isolate = blink::CreateMainThreadIsolate();
|
||||
chrome_pdf::SetBlinkIsolate(isolate);
|
||||
InitializeResourceBundle();
|
||||
}
|
||||
|
||||
void Shutdown() override {
|
||||
chrome_pdf::SetBlinkIsolate(nullptr);
|
||||
platform_.reset();
|
||||
ui::ResourceBundle::CleanupSharedInstance();
|
||||
base::TestSuite::Shutdown();
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "base/time/time.h"
|
||||
#include "pdf/document_layout.h"
|
||||
#include "pdf/loader/url_loader.h"
|
||||
#include "third_party/blink/public/web/blink.h"
|
||||
#include "pdf/test/test_helpers.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
|
||||
namespace chrome_pdf {
|
||||
@ -44,7 +44,7 @@ std::unique_ptr<UrlLoader> TestClient::CreateUrlLoader() {
|
||||
}
|
||||
|
||||
v8::Isolate* TestClient::GetIsolate() {
|
||||
return blink::MainThreadIsolate();
|
||||
return GetBlinkIsolate();
|
||||
}
|
||||
|
||||
std::vector<PDFEngine::Client::SearchStringResult> TestClient::SearchString(
|
||||
|
@ -59,4 +59,14 @@ sk_sp<SkImage> CreateSkiaImageForTesting(const gfx::Size& size, SkColor color) {
|
||||
return CreateSkiaSurfaceForTesting(size, color)->makeImageSnapshot();
|
||||
}
|
||||
|
||||
static v8::Isolate* g_isolate = nullptr;
|
||||
|
||||
v8::Isolate* GetBlinkIsolate() {
|
||||
return g_isolate;
|
||||
}
|
||||
|
||||
void SetBlinkIsolate(v8::Isolate* isolate) {
|
||||
g_isolate = isolate;
|
||||
}
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
#include "third_party/skia/include/core/SkRefCnt.h"
|
||||
#include "v8/include/v8-forward.h"
|
||||
|
||||
class SkImage;
|
||||
class SkSurface;
|
||||
@ -36,6 +37,12 @@ sk_sp<SkSurface> CreateSkiaSurfaceForTesting(const gfx::Size& size,
|
||||
// Creates a Skia image with dimensions `size` and filled with `color`.
|
||||
sk_sp<SkImage> CreateSkiaImageForTesting(const gfx::Size& size, SkColor color);
|
||||
|
||||
// Retrieves the `v8::Isolate` the test harness created when initializing blink.
|
||||
v8::Isolate* GetBlinkIsolate();
|
||||
|
||||
// Stores the `v8::Isolate` the test harness created when initializing blink.
|
||||
void SetBlinkIsolate(v8::Isolate* isolate);
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
||||
#endif // PDF_TEST_TEST_HELPERS_H_
|
||||
|
Reference in New Issue
Block a user