summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-06-07 00:42:46 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-06-07 00:42:46 +0000
commit10569fcd4a3a9fb0140aa641372bcd462c6aa2f3 (patch)
treeffa3de81c0a8ca3236fef02ebac03e4bc61fe591
parent6ffd840c1f4d7d74a6c4c07c5791c4f3db8d50b9 (diff)
downloadpdfium-10569fcd4a3a9fb0140aa641372bcd462c6aa2f3.tar.xz
Simplify cfxjs_engine_embeddertest.cpp
In a world without context slots, we don't need to test getting an engine from a content slot. Change-Id: If572c364d663d1f20af659392bda3b96348fd4d4 Reviewed-on: https://pdfium-review.googlesource.com/34270 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
-rw-r--r--fxjs/cfxjs_engine_embeddertest.cpp89
1 files changed, 27 insertions, 62 deletions
diff --git a/fxjs/cfxjs_engine_embeddertest.cpp b/fxjs/cfxjs_engine_embeddertest.cpp
index 75f07982aa..ff866d3ee0 100644
--- a/fxjs/cfxjs_engine_embeddertest.cpp
+++ b/fxjs/cfxjs_engine_embeddertest.cpp
@@ -19,35 +19,25 @@ const wchar_t kScript2[] = L"fred = 8";
} // namespace
-class CFXJSEngineEmbedderTest : public JSEmbedderTest {
- public:
- Optional<IJS_Runtime::JS_Error> ExecuteInCurrentContext(
- const WideString& script) {
- auto* current_engine =
- CFXJS_Engine::EngineFromIsolateCurrentContext(isolate());
- return current_engine->Execute(script);
- }
-
- void CheckAssignmentInCurrentContext(double expected) {
- auto* current_engine =
- CFXJS_Engine::EngineFromIsolateCurrentContext(isolate());
- v8::Local<v8::Object> This = current_engine->GetThisObj();
- v8::Local<v8::Value> fred =
- current_engine->GetObjectProperty(This, L"fred");
- EXPECT_TRUE(fred->IsNumber());
- EXPECT_EQ(expected, current_engine->ToDouble(fred));
- }
-};
+using CFXJSEngineEmbedderTest = JSEmbedderTest;
+
+void CheckAssignmentInEngineContext(CFXJS_Engine* current_engine,
+ double expected) {
+ v8::Context::Scope context_scope(current_engine->GetV8Context());
+ v8::Local<v8::Object> This = current_engine->GetThisObj();
+ v8::Local<v8::Value> fred = current_engine->GetObjectProperty(This, L"fred");
+ EXPECT_TRUE(fred->IsNumber());
+ EXPECT_EQ(expected, current_engine->ToDouble(fred));
+}
TEST_F(CFXJSEngineEmbedderTest, Getters) {
v8::Isolate::Scope isolate_scope(isolate());
v8::HandleScope handle_scope(isolate());
v8::Context::Scope context_scope(GetV8Context());
- Optional<IJS_Runtime::JS_Error> err =
- ExecuteInCurrentContext(WideString(kScript1));
+ Optional<IJS_Runtime::JS_Error> err = engine()->Execute(WideString(kScript1));
EXPECT_FALSE(err);
- CheckAssignmentInCurrentContext(kExpected1);
+ CheckAssignmentInEngineContext(engine(), kExpected1);
}
TEST_F(CFXJSEngineEmbedderTest, MultipleEngines) {
@@ -60,53 +50,28 @@ TEST_F(CFXJSEngineEmbedderTest, MultipleEngines) {
CFXJS_Engine engine2(isolate());
engine2.InitializeEngine();
- v8::Local<v8::Context> context1 = engine1.GetV8Context();
- v8::Local<v8::Context> context2 = engine2.GetV8Context();
-
v8::Context::Scope context_scope(GetV8Context());
- Optional<IJS_Runtime::JS_Error> err =
- ExecuteInCurrentContext(WideString(kScript0));
+ Optional<IJS_Runtime::JS_Error> err = engine()->Execute(WideString(kScript0));
EXPECT_FALSE(err);
- CheckAssignmentInCurrentContext(kExpected0);
+ CheckAssignmentInEngineContext(engine(), kExpected0);
{
- v8::Context::Scope context_scope1(context1);
- Optional<IJS_Runtime::JS_Error> err =
- ExecuteInCurrentContext(WideString(kScript1));
+ // engine1 executing in engine1's context doesn't affect main.
+ v8::Context::Scope context_scope1(engine1.GetV8Context());
+ Optional<IJS_Runtime::JS_Error> err = engine1.Execute(WideString(kScript1));
EXPECT_FALSE(err);
- CheckAssignmentInCurrentContext(kExpected1);
+ CheckAssignmentInEngineContext(engine(), kExpected0);
+ CheckAssignmentInEngineContext(&engine1, kExpected1);
}
{
- v8::Context::Scope context_scope2(context2);
- Optional<IJS_Runtime::JS_Error> err =
- ExecuteInCurrentContext(WideString(kScript2));
+ // engine1 executing in engine2's context doesn't affect engine1.
+ v8::Context::Scope context_scope2(engine2.GetV8Context());
+ Optional<IJS_Runtime::JS_Error> err = engine1.Execute(WideString(kScript2));
EXPECT_FALSE(err);
- CheckAssignmentInCurrentContext(kExpected2);
+ CheckAssignmentInEngineContext(engine(), kExpected0);
+ CheckAssignmentInEngineContext(&engine1, kExpected1);
+ CheckAssignmentInEngineContext(&engine2, kExpected2);
}
-
- CheckAssignmentInCurrentContext(kExpected0);
-
- {
- v8::Context::Scope context_scope1(context1);
- CheckAssignmentInCurrentContext(kExpected1);
- {
- v8::Context::Scope context_scope2(context2);
- CheckAssignmentInCurrentContext(kExpected2);
- }
- CheckAssignmentInCurrentContext(kExpected1);
- }
- {
- v8::Context::Scope context_scope2(context2);
- CheckAssignmentInCurrentContext(kExpected2);
- {
- v8::Context::Scope context_scope1(context1);
- CheckAssignmentInCurrentContext(kExpected1);
- }
- CheckAssignmentInCurrentContext(kExpected2);
- }
-
- CheckAssignmentInCurrentContext(kExpected0);
-
engine1.ReleaseEngine();
engine2.ReleaseEngine();
}
@@ -117,7 +82,7 @@ TEST_F(CFXJSEngineEmbedderTest, JSCompileError) {
v8::Context::Scope context_scope(GetV8Context());
Optional<IJS_Runtime::JS_Error> err =
- ExecuteInCurrentContext(L"functoon(x) { return x+1; }");
+ engine()->Execute(L"functoon(x) { return x+1; }");
EXPECT_TRUE(err);
EXPECT_EQ(L"SyntaxError: Unexpected token {", err->exception);
EXPECT_EQ(1, err->line);
@@ -130,7 +95,7 @@ TEST_F(CFXJSEngineEmbedderTest, JSRuntimeError) {
v8::Context::Scope context_scope(GetV8Context());
Optional<IJS_Runtime::JS_Error> err =
- ExecuteInCurrentContext(L"let a = 3;\nundefined.colour");
+ engine()->Execute(L"let a = 3;\nundefined.colour");
EXPECT_TRUE(err);
EXPECT_EQ(L"TypeError: Cannot read property 'colour' of undefined",
err->exception);