Commit 5fa05717 authored by haraken@chromium.org's avatar haraken@chromium.org

Ensure DOMWrapperWorld always exists in all webkit_unit_tests

Currently DOMWrapperWorld can be 0 in some tests. This is problematic since I want to make DOMWrapperWorld::current() callable from anywhere. Thus this CL adds DOMWrapperWorld to all webkit_unit_tests.

- It's verbose to initialize v8::HandleScope, v8::Context, v8::Context::Scope, V8PerContextData and DOMWrapperWorld in each test. So this CL adds a helper class (V8BindingTestScope) that does all the initialization work.

- This CL also fixes indentation of V8Binding.h.

BUG=341032

Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=168355

R=dcarney@chromium.org

Review URL: https://codereview.chromium.org/180743013

git-svn-id: svn://svn.chromium.org/blink/trunk@168376 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 2932a6c8
......@@ -115,7 +115,7 @@ DOMWrapperWorld::~DOMWrapperWorld()
#ifndef NDEBUG
static bool isIsolatedWorldId(int worldId)
{
return worldId != MainWorldId && worldId != WorkerWorldId;
return MainWorldId < worldId && worldId < IsolatedWorldIdLimit;
}
#endif
......
......@@ -50,13 +50,15 @@ enum WorldIdConstants {
// Embedder isolated worlds can use IDs in [1, 1<<29).
EmbedderWorldIdLimit = (1 << 29),
ScriptPreprocessorIsolatedWorldId,
IsolatedWorldIdLimit,
WorkerWorldId,
TestingWorldId,
};
// This class represent a collection of DOM wrappers for a specific world.
class DOMWrapperWorld : public RefCounted<DOMWrapperWorld> {
public:
static PassRefPtr<DOMWrapperWorld> create(int worldId, int extensionGroup);
static PassRefPtr<DOMWrapperWorld> create(int worldId = -1, int extensionGroup = -1);
static const int mainWorldExtensionGroup = 0;
static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(int worldId, int extensionGroup);
......@@ -96,7 +98,7 @@ public:
bool isMainWorld() const { return m_worldId == MainWorldId; }
bool isWorkerWorld() const { return m_worldId == WorkerWorldId; }
bool isIsolatedWorld() const { return !isMainWorld() && !isWorkerWorld(); }
bool isIsolatedWorld() const { return MainWorldId < m_worldId && m_worldId < IsolatedWorldIdLimit; }
int worldId() const { return m_worldId; }
int extensionGroup() const { return m_extensionGroup; }
......
......@@ -92,14 +92,11 @@ void checkKeyPathNumberValue(const ScriptValue& value, const String& keyPath, in
class IDBKeyFromValueAndKeyPathTest : public testing::Test {
public:
IDBKeyFromValueAndKeyPathTest()
: m_handleScope(v8::Isolate::GetCurrent())
, m_scope(v8::Context::New(v8::Isolate::GetCurrent()))
: m_scope(V8BindingTestScope::create(v8::Isolate::GetCurrent()))
{
}
private:
v8::HandleScope m_handleScope;
v8::Context::Scope m_scope;
OwnPtr<V8BindingTestScope> m_scope;
};
TEST_F(IDBKeyFromValueAndKeyPathTest, TopLevelPropertyStringValue)
......
......@@ -47,16 +47,12 @@ class ScriptPromiseResolverTest : public testing::Test {
public:
ScriptPromiseResolverTest()
: m_isolate(v8::Isolate::GetCurrent())
, m_handleScope(m_isolate)
, m_context(m_isolate, v8::Context::New(m_isolate))
, m_contextScope(m_context.newLocal(m_isolate))
{
}
void SetUp()
{
// FIXME: Create a new world and pass it to V8PerContextData.
m_perContextData = V8PerContextData::create(m_context.newLocal(m_isolate), 0);
m_scope = V8BindingTestScope::create(m_isolate);
m_promise = ScriptPromise::createPending();
m_resolver = ScriptPromiseResolver::create(m_promise);
}
......@@ -65,7 +61,7 @@ public:
{
m_resolver = nullptr;
m_promise.clear();
m_perContextData.clear();
m_scope.clear();
}
V8PromiseCustom::PromiseState state()
......@@ -86,12 +82,10 @@ public:
protected:
v8::Isolate* m_isolate;
v8::HandleScope m_handleScope;
ScopedPersistent<v8::Context> m_context;
v8::Context::Scope m_contextScope;
RefPtr<ScriptPromiseResolver> m_resolver;
ScriptPromise m_promise;
OwnPtr<V8PerContextData> m_perContextData;
private:
OwnPtr<V8BindingTestScope> m_scope;
};
TEST_F(ScriptPromiseResolverTest, initialState)
......
......@@ -47,21 +47,17 @@ class ScriptPromiseTest : public testing::Test {
public:
ScriptPromiseTest()
: m_isolate(v8::Isolate::GetCurrent())
, m_handleScope(m_isolate)
, m_context(m_isolate, v8::Context::New(m_isolate))
, m_contextScope(m_context.newLocal(m_isolate))
{
}
void SetUp()
{
// FIXME: Create a new world and pass it to V8PerContextData.
m_perContextData = V8PerContextData::create(m_context.newLocal(m_isolate), 0);
m_scope = V8BindingTestScope::create(m_isolate);
}
void TearDown()
{
m_perContextData.clear();
m_scope.clear();
}
V8PromiseCustom::PromiseState state(ScriptPromise promise)
......@@ -71,10 +67,9 @@ public:
protected:
v8::Isolate* m_isolate;
v8::HandleScope m_handleScope;
ScopedPersistent<v8::Context> m_context;
v8::Context::Scope m_contextScope;
OwnPtr<V8PerContextData> m_perContextData;
private:
OwnPtr<V8BindingTestScope> m_scope;
};
TEST_F(ScriptPromiseTest, castPromise)
......
......@@ -734,4 +734,18 @@ v8::Isolate* toIsolate(LocalFrame* frame)
return frame->script().isolate();
}
PassOwnPtr<V8BindingTestScope> V8BindingTestScope::create(v8::Isolate* isolate)
{
return adoptPtr(new V8BindingTestScope(isolate));
}
V8BindingTestScope::V8BindingTestScope(v8::Isolate* isolate)
: m_handleScope(isolate)
, m_context(v8::Context::New(isolate))
, m_contextScope(m_context)
, m_world(DOMWrapperWorld::create())
, m_perContextData(V8PerContextData::create(m_context, m_world.get()))
{
}
} // namespace WebCore
......@@ -68,7 +68,7 @@ WorkerScriptController::WorkerScriptController(WorkerGlobalScope& workerGlobalSc
V8Initializer::initializeWorker(m_isolate);
v8::V8::Initialize();
V8PerIsolateData::ensureInitialized(m_isolate);
m_world = DOMWrapperWorld::create(WorkerWorldId, -1);
m_world = DOMWrapperWorld::create(WorkerWorldId);
m_interruptor = adoptPtr(new V8IsolateInterruptor(m_isolate));
ThreadState::current()->addInterruptor(m_interruptor.get());
}
......
......@@ -36,18 +36,11 @@ protected:
class AnimationAnimationV8Test : public AnimationAnimationTest {
protected:
AnimationAnimationV8Test()
: isolate(v8::Isolate::GetCurrent())
, scope(isolate)
, context(v8::Context::New(isolate))
, contextScope(context)
: m_isolate(v8::Isolate::GetCurrent())
, m_scope(V8BindingTestScope::create(m_isolate))
{
}
v8::Isolate* isolate;
v8::HandleScope scope;
v8::Local<v8::Context> context;
v8::Context::Scope contextScope;
PassRefPtr<Animation> createAnimation(Element* element, Vector<Dictionary> keyframeDictionaryVector, Dictionary timingInput)
{
return Animation::createUnsafe(element, keyframeDictionaryVector, timingInput);
......@@ -62,13 +55,18 @@ protected:
{
return Animation::createUnsafe(element, keyframeDictionaryVector);
}
v8::Isolate* m_isolate;
private:
OwnPtr<V8BindingTestScope> m_scope;
};
TEST_F(AnimationAnimationV8Test, CanCreateAnAnimation)
{
Vector<Dictionary> jsKeyframes;
v8::Handle<v8::Object> keyframe1 = v8::Object::New(isolate);
v8::Handle<v8::Object> keyframe2 = v8::Object::New(isolate);
v8::Handle<v8::Object> keyframe1 = v8::Object::New(m_isolate);
v8::Handle<v8::Object> keyframe2 = v8::Object::New(m_isolate);
setV8ObjectPropertyAsString(keyframe1, "width", "100px");
setV8ObjectPropertyAsString(keyframe1, "offset", "0");
......@@ -77,8 +75,8 @@ TEST_F(AnimationAnimationV8Test, CanCreateAnAnimation)
setV8ObjectPropertyAsString(keyframe2, "offset", "1");
setV8ObjectPropertyAsString(keyframe2, "easing", "cubic-bezier(1, 1, 0.3, 0.3)");
jsKeyframes.append(Dictionary(keyframe1, isolate));
jsKeyframes.append(Dictionary(keyframe2, isolate));
jsKeyframes.append(Dictionary(keyframe1, m_isolate));
jsKeyframes.append(Dictionary(keyframe2, m_isolate));
String value1;
ASSERT_TRUE(jsKeyframes[0].get("width", value1));
......@@ -142,7 +140,7 @@ TEST_F(AnimationAnimationV8Test, SpecifiedGetters)
{
Vector<Dictionary, 0> jsKeyframes;
v8::Handle<v8::Object> timingInput = v8::Object::New(isolate);
v8::Handle<v8::Object> timingInput = v8::Object::New(m_isolate);
setV8ObjectPropertyAsNumber(timingInput, "delay", 2);
setV8ObjectPropertyAsNumber(timingInput, "endDelay", 0.5);
setV8ObjectPropertyAsString(timingInput, "fill", "backwards");
......@@ -151,7 +149,7 @@ TEST_F(AnimationAnimationV8Test, SpecifiedGetters)
setV8ObjectPropertyAsNumber(timingInput, "playbackRate", 2);
setV8ObjectPropertyAsString(timingInput, "direction", "reverse");
setV8ObjectPropertyAsString(timingInput, "easing", "step-start");
Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(timingInput), isolate);
Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(timingInput), m_isolate);
RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, timingInputDictionary);
......@@ -170,9 +168,9 @@ TEST_F(AnimationAnimationV8Test, SpecifiedDurationGetter)
{
Vector<Dictionary, 0> jsKeyframes;
v8::Handle<v8::Object> timingInputWithDuration = v8::Object::New(isolate);
v8::Handle<v8::Object> timingInputWithDuration = v8::Object::New(m_isolate);
setV8ObjectPropertyAsNumber(timingInputWithDuration, "duration", 2.5);
Dictionary timingInputDictionaryWithDuration = Dictionary(v8::Handle<v8::Value>::Cast(timingInputWithDuration), isolate);
Dictionary timingInputDictionaryWithDuration = Dictionary(v8::Handle<v8::Value>::Cast(timingInputWithDuration), m_isolate);
RefPtr<Animation> animationWithDuration = createAnimation(element.get(), jsKeyframes, timingInputDictionaryWithDuration);
......@@ -188,8 +186,8 @@ TEST_F(AnimationAnimationV8Test, SpecifiedDurationGetter)
EXPECT_EQ("", stringDuration);
v8::Handle<v8::Object> timingInputNoDuration = v8::Object::New(isolate);
Dictionary timingInputDictionaryNoDuration = Dictionary(v8::Handle<v8::Value>::Cast(timingInputNoDuration), isolate);
v8::Handle<v8::Object> timingInputNoDuration = v8::Object::New(m_isolate);
Dictionary timingInputDictionaryNoDuration = Dictionary(v8::Handle<v8::Value>::Cast(timingInputNoDuration), m_isolate);
RefPtr<Animation> animationNoDuration = createAnimation(element.get(), jsKeyframes, timingInputDictionaryNoDuration);
......@@ -208,8 +206,8 @@ TEST_F(AnimationAnimationV8Test, SpecifiedDurationGetter)
TEST_F(AnimationAnimationV8Test, SpecifiedSetters)
{
Vector<Dictionary, 0> jsKeyframes;
v8::Handle<v8::Object> timingInput = v8::Object::New(isolate);
Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(timingInput), isolate);
v8::Handle<v8::Object> timingInput = v8::Object::New(m_isolate);
Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(timingInput), m_isolate);
RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, timingInputDictionary);
RefPtr<TimedItemTiming> specified = animation->specified();
......@@ -250,8 +248,8 @@ TEST_F(AnimationAnimationV8Test, SpecifiedSetters)
TEST_F(AnimationAnimationV8Test, SetSpecifiedDuration)
{
Vector<Dictionary, 0> jsKeyframes;
v8::Handle<v8::Object> timingInput = v8::Object::New(isolate);
Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(timingInput), isolate);
v8::Handle<v8::Object> timingInput = v8::Object::New(m_isolate);
Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(timingInput), m_isolate);
RefPtr<Animation> animation = createAnimation(element.get(), jsKeyframes, timingInputDictionary);
RefPtr<TimedItemTiming> specified = animation->specified();
......
......@@ -17,18 +17,11 @@ namespace WebCore {
class AnimationAnimationTimingInputTest : public ::testing::Test {
protected:
AnimationAnimationTimingInputTest()
: isolate(v8::Isolate::GetCurrent())
, scope(isolate)
, context(v8::Context::New(isolate))
, contextScope(context)
: m_isolate(v8::Isolate::GetCurrent())
, m_scope(V8BindingTestScope::create(m_isolate))
{
}
v8::Isolate* isolate;
v8::HandleScope scope;
v8::Local<v8::Context> context;
v8::Context::Scope contextScope;
void populateTiming(Timing& timing, Dictionary timingInputDictionary)
{
Animation::populateTiming(timing, timingInputDictionary);
......@@ -36,9 +29,9 @@ protected:
Timing applyTimingInputNumber(String timingProperty, double timingPropertyValue)
{
v8::Handle<v8::Object> timingInput = v8::Object::New(isolate);
v8::Handle<v8::Object> timingInput = v8::Object::New(m_isolate);
setV8ObjectPropertyAsNumber(timingInput, timingProperty, timingPropertyValue);
Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(timingInput), isolate);
Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(timingInput), m_isolate);
Timing timing;
populateTiming(timing, timingInputDictionary);
return timing;
......@@ -46,13 +39,18 @@ protected:
Timing applyTimingInputString(String timingProperty, String timingPropertyValue)
{
v8::Handle<v8::Object> timingInput = v8::Object::New(isolate);
v8::Handle<v8::Object> timingInput = v8::Object::New(m_isolate);
setV8ObjectPropertyAsString(timingInput, timingProperty, timingPropertyValue);
Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(timingInput), isolate);
Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(timingInput), m_isolate);
Timing timing;
populateTiming(timing, timingInputDictionary);
return timing;
}
v8::Isolate* m_isolate;
private:
OwnPtr<V8BindingTestScope> m_scope;
};
TEST_F(AnimationAnimationTimingInputTest, TimingInputStartDelay)
......@@ -177,8 +175,8 @@ TEST_F(AnimationAnimationTimingInputTest, TimingInputEmpty)
Timing updatedTiming;
Timing controlTiming;
v8::Handle<v8::Object> timingInput = v8::Object::New(isolate);
Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(timingInput), isolate);
v8::Handle<v8::Object> timingInput = v8::Object::New(m_isolate);
Dictionary timingInputDictionary = Dictionary(v8::Handle<v8::Value>::Cast(timingInput), m_isolate);
populateTiming(updatedTiming, timingInputDictionary);
EXPECT_EQ(controlTiming.startDelay, updatedTiming.startDelay);
......
......@@ -72,8 +72,7 @@ NullExecutionContext::NullExecutionContext()
class IDBRequestTest : public testing::Test {
public:
IDBRequestTest()
: m_handleScope(v8::Isolate::GetCurrent())
, m_scope(v8::Context::New(v8::Isolate::GetCurrent()))
: m_scope(V8BindingTestScope::create(v8::Isolate::GetCurrent()))
, m_context(adoptRef(new NullExecutionContext()))
{
}
......@@ -84,8 +83,7 @@ public:
}
private:
v8::HandleScope m_handleScope;
v8::Context::Scope m_scope;
OwnPtr<V8BindingTestScope> m_scope;
RefPtr<ExecutionContext> m_context;
};
......
......@@ -50,8 +50,7 @@ namespace {
class IDBTransactionTest : public testing::Test {
public:
IDBTransactionTest()
: m_handleScope(v8::Isolate::GetCurrent())
, m_scope(v8::Context::New(v8::Isolate::GetCurrent()))
: m_scope(V8BindingTestScope::create(v8::Isolate::GetCurrent()))
, m_document(Document::create())
{
}
......@@ -62,8 +61,7 @@ public:
}
private:
v8::HandleScope m_handleScope;
v8::Context::Scope m_scope;
OwnPtr<V8BindingTestScope> m_scope;
RefPtr<Document> m_document;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment