This source file includes following definitions.
- callback
- state
- TEST_F
- TEST_F
- TEST_F
#include "config.h"
#include "bindings/v8/ScriptPromise.h"
#include "bindings/v8/DOMWrapperWorld.h"
#include "bindings/v8/ScriptPromiseResolver.h"
#include "bindings/v8/ScriptValue.h"
#include "bindings/v8/V8Binding.h"
#include "bindings/v8/custom/V8PromiseCustom.h"
#include <gtest/gtest.h>
#include <v8.h>
namespace WebCore {
namespace {
void callback(const v8::FunctionCallbackInfo<v8::Value>& info) { }
class ScriptPromiseTest : public testing::Test {
public:
ScriptPromiseTest()
: m_isolate(v8::Isolate::GetCurrent())
{
m_scope = V8ExecutionScope::create(m_isolate);
}
~ScriptPromiseTest()
{
createClosure(callback, v8::Undefined(m_isolate), m_isolate);
}
V8PromiseCustom::PromiseState state(ScriptPromise promise)
{
return V8PromiseCustom::getState(V8PromiseCustom::getInternal(promise.v8Value().As<v8::Object>()));
}
protected:
v8::Isolate* m_isolate;
private:
OwnPtr<V8ExecutionScope> m_scope;
};
TEST_F(ScriptPromiseTest, constructFromNonPromise)
{
v8::TryCatch trycatch;
ScriptPromise promise(v8::Undefined(m_isolate), m_isolate);
ASSERT_TRUE(trycatch.HasCaught());
ASSERT_TRUE(promise.hasNoValue());
}
TEST_F(ScriptPromiseTest, castPromise)
{
ScriptPromise promise = ScriptPromiseResolver::create(m_isolate)->promise();
ScriptPromise newPromise = ScriptPromise::cast(ScriptValue(promise.v8Value(), m_isolate));
ASSERT_FALSE(promise.hasNoValue());
EXPECT_EQ(V8PromiseCustom::Pending, state(promise));
EXPECT_EQ(promise.v8Value(), newPromise.v8Value());
}
TEST_F(ScriptPromiseTest, castNonPromise)
{
ScriptValue value = ScriptValue(v8String(m_isolate, "hello"), m_isolate);
ScriptPromise promise1 = ScriptPromise::cast(ScriptValue(value.v8Value(), m_isolate));
ScriptPromise promise2 = ScriptPromise::cast(ScriptValue(value.v8Value(), m_isolate));
ASSERT_FALSE(promise1.hasNoValue());
ASSERT_FALSE(promise2.hasNoValue());
ASSERT_TRUE(V8PromiseCustom::isPromise(promise1.v8Value(), m_isolate));
ASSERT_TRUE(V8PromiseCustom::isPromise(promise2.v8Value(), m_isolate));
EXPECT_EQ(V8PromiseCustom::Fulfilled, state(promise1));
EXPECT_EQ(V8PromiseCustom::Fulfilled, state(promise2));
EXPECT_NE(promise1.v8Value(), promise2.v8Value());
}
}
}