| Index: Source/bindings/v8/ScriptPromiseTest.cpp
|
| diff --git a/Source/bindings/v8/ScriptPromiseTest.cpp b/Source/bindings/v8/ScriptPromiseTest.cpp
|
| deleted file mode 100644
|
| index 8f9d74d17527cebec3dc5485c4e98a5b0342a728..0000000000000000000000000000000000000000
|
| --- a/Source/bindings/v8/ScriptPromiseTest.cpp
|
| +++ /dev/null
|
| @@ -1,260 +0,0 @@
|
| -/*
|
| - * Copyright (C) 2014 Google Inc. All rights reserved.
|
| - *
|
| - * Redistribution and use in source and binary forms, with or without
|
| - * modification, are permitted provided that the following conditions are
|
| - * met:
|
| - *
|
| - * * Redistributions of source code must retain the above copyright
|
| - * notice, this list of conditions and the following disclaimer.
|
| - * * Redistributions in binary form must reproduce the above
|
| - * copyright notice, this list of conditions and the following disclaimer
|
| - * in the documentation and/or other materials provided with the
|
| - * distribution.
|
| - * * Neither the name of Google Inc. nor the names of its
|
| - * contributors may be used to endorse or promote products derived from
|
| - * this software without specific prior written permission.
|
| - *
|
| - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| - */
|
| -
|
| -#include "config.h"
|
| -#include "bindings/v8/ScriptPromise.h"
|
| -
|
| -#include "bindings/v8/ScriptFunction.h"
|
| -#include "bindings/v8/ScriptValue.h"
|
| -#include "bindings/v8/V8Binding.h"
|
| -#include "core/dom/DOMException.h"
|
| -#include "core/dom/ExceptionCode.h"
|
| -
|
| -#include <gtest/gtest.h>
|
| -#include <v8.h>
|
| -
|
| -namespace WebCore {
|
| -
|
| -namespace {
|
| -
|
| -void callback(const v8::FunctionCallbackInfo<v8::Value>& info) { }
|
| -
|
| -class Function : public ScriptFunction {
|
| -public:
|
| - static PassOwnPtr<Function> create(v8::Isolate* isolate, String* value)
|
| - {
|
| - return adoptPtr(new Function(isolate, value));
|
| - }
|
| -
|
| - virtual ScriptValue call(ScriptValue value) OVERRIDE
|
| - {
|
| - ASSERT(!value.isEmpty());
|
| - *m_value = toCoreString(value.v8Value()->ToString());
|
| - return value;
|
| - }
|
| -
|
| -private:
|
| - Function(v8::Isolate* isolate, String* value) : ScriptFunction(isolate), m_value(value) { }
|
| -
|
| - String* m_value;
|
| -};
|
| -
|
| -class ScriptPromiseTest : public testing::Test {
|
| -public:
|
| - ScriptPromiseTest()
|
| - : m_scope(v8::Isolate::GetCurrent())
|
| - {
|
| - }
|
| -
|
| - ~ScriptPromiseTest()
|
| - {
|
| - // FIXME: We put this statement here to clear an exception from the isolate.
|
| - createClosure(callback, v8::Undefined(m_scope.isolate()), m_scope.isolate());
|
| -
|
| - // Execute all pending microtasks
|
| - isolate()->RunMicrotasks();
|
| - }
|
| -
|
| - ScriptState* scriptState() const { return m_scope.scriptState(); }
|
| - v8::Isolate* isolate() const { return m_scope.isolate(); }
|
| -
|
| -protected:
|
| - typedef ScriptPromise::InternalResolver Resolver;
|
| - V8TestingScope m_scope;
|
| -};
|
| -
|
| -TEST_F(ScriptPromiseTest, constructFromNonPromise)
|
| -{
|
| - v8::TryCatch trycatch;
|
| - ScriptPromise promise(scriptState(), v8::Undefined(isolate()));
|
| - ASSERT_TRUE(trycatch.HasCaught());
|
| - ASSERT_TRUE(promise.isEmpty());
|
| -}
|
| -
|
| -TEST_F(ScriptPromiseTest, thenResolve)
|
| -{
|
| - Resolver resolver(scriptState());
|
| - ScriptPromise promise = resolver.promise();
|
| - String onFulfilled, onRejected;
|
| - promise.then(Function::create(isolate(), &onFulfilled), Function::create(isolate(), &onRejected));
|
| -
|
| - ASSERT_FALSE(promise.isEmpty());
|
| - EXPECT_EQ(String(), onFulfilled);
|
| - EXPECT_EQ(String(), onRejected);
|
| -
|
| - isolate()->RunMicrotasks();
|
| - resolver.resolve(v8String(isolate(), "hello"));
|
| -
|
| - EXPECT_EQ(String(), onFulfilled);
|
| - EXPECT_EQ(String(), onRejected);
|
| -
|
| - isolate()->RunMicrotasks();
|
| -
|
| - EXPECT_EQ("hello", onFulfilled);
|
| - EXPECT_EQ(String(), onRejected);
|
| -}
|
| -
|
| -TEST_F(ScriptPromiseTest, resolveThen)
|
| -{
|
| - Resolver resolver(scriptState());
|
| - ScriptPromise promise = resolver.promise();
|
| - String onFulfilled, onRejected;
|
| - resolver.resolve(v8String(isolate(), "hello"));
|
| - promise.then(Function::create(isolate(), &onFulfilled), Function::create(isolate(), &onRejected));
|
| -
|
| - ASSERT_FALSE(promise.isEmpty());
|
| - EXPECT_EQ(String(), onFulfilled);
|
| - EXPECT_EQ(String(), onRejected);
|
| -
|
| - isolate()->RunMicrotasks();
|
| -
|
| - EXPECT_EQ("hello", onFulfilled);
|
| - EXPECT_EQ(String(), onRejected);
|
| -}
|
| -
|
| -TEST_F(ScriptPromiseTest, thenReject)
|
| -{
|
| - Resolver resolver(scriptState());
|
| - ScriptPromise promise = resolver.promise();
|
| - String onFulfilled, onRejected;
|
| - promise.then(Function::create(isolate(), &onFulfilled), Function::create(isolate(), &onRejected));
|
| -
|
| - ASSERT_FALSE(promise.isEmpty());
|
| - EXPECT_EQ(String(), onFulfilled);
|
| - EXPECT_EQ(String(), onRejected);
|
| -
|
| - isolate()->RunMicrotasks();
|
| - resolver.reject(v8String(isolate(), "hello"));
|
| -
|
| - EXPECT_EQ(String(), onFulfilled);
|
| - EXPECT_EQ(String(), onRejected);
|
| -
|
| - isolate()->RunMicrotasks();
|
| -
|
| - EXPECT_EQ(String(), onFulfilled);
|
| - EXPECT_EQ("hello", onRejected);
|
| -}
|
| -
|
| -TEST_F(ScriptPromiseTest, rejectThen)
|
| -{
|
| - Resolver resolver(scriptState());
|
| - ScriptPromise promise = resolver.promise();
|
| - String onFulfilled, onRejected;
|
| - resolver.reject(v8String(isolate(), "hello"));
|
| - promise.then(Function::create(isolate(), &onFulfilled), Function::create(isolate(), &onRejected));
|
| -
|
| - ASSERT_FALSE(promise.isEmpty());
|
| - EXPECT_EQ(String(), onFulfilled);
|
| - EXPECT_EQ(String(), onRejected);
|
| -
|
| - isolate()->RunMicrotasks();
|
| -
|
| - EXPECT_EQ(String(), onFulfilled);
|
| - EXPECT_EQ("hello", onRejected);
|
| -}
|
| -
|
| -TEST_F(ScriptPromiseTest, castPromise)
|
| -{
|
| - ScriptPromise promise = Resolver(scriptState()).promise();
|
| - ScriptPromise newPromise = ScriptPromise::cast(scriptState(), promise.v8Value());
|
| -
|
| - ASSERT_FALSE(promise.isEmpty());
|
| - EXPECT_EQ(promise.v8Value(), newPromise.v8Value());
|
| -}
|
| -
|
| -TEST_F(ScriptPromiseTest, castNonPromise)
|
| -{
|
| - String onFulfilled1, onFulfilled2, onRejected1, onRejected2;
|
| -
|
| - ScriptValue value = ScriptValue(scriptState(), v8String(isolate(), "hello"));
|
| - ScriptPromise promise1 = ScriptPromise::cast(scriptState(), ScriptValue(value));
|
| - ScriptPromise promise2 = ScriptPromise::cast(scriptState(), ScriptValue(value));
|
| - promise1.then(Function::create(isolate(), &onFulfilled1), Function::create(isolate(), &onRejected1));
|
| - promise2.then(Function::create(isolate(), &onFulfilled2), Function::create(isolate(), &onRejected2));
|
| -
|
| - ASSERT_FALSE(promise1.isEmpty());
|
| - ASSERT_FALSE(promise2.isEmpty());
|
| - EXPECT_NE(promise1.v8Value(), promise2.v8Value());
|
| -
|
| - ASSERT_TRUE(promise1.v8Value()->IsPromise());
|
| - ASSERT_TRUE(promise2.v8Value()->IsPromise());
|
| -
|
| - EXPECT_EQ(String(), onFulfilled1);
|
| - EXPECT_EQ(String(), onFulfilled2);
|
| - EXPECT_EQ(String(), onRejected1);
|
| - EXPECT_EQ(String(), onRejected2);
|
| -
|
| - isolate()->RunMicrotasks();
|
| -
|
| - EXPECT_EQ("hello", onFulfilled1);
|
| - EXPECT_EQ("hello", onFulfilled2);
|
| - EXPECT_EQ(String(), onRejected1);
|
| - EXPECT_EQ(String(), onRejected2);
|
| -}
|
| -
|
| -TEST_F(ScriptPromiseTest, reject)
|
| -{
|
| - String onFulfilled, onRejected;
|
| -
|
| - ScriptValue value = ScriptValue(scriptState(), v8String(isolate(), "hello"));
|
| - ScriptPromise promise = ScriptPromise::reject(scriptState(), ScriptValue(value));
|
| - promise.then(Function::create(isolate(), &onFulfilled), Function::create(isolate(), &onRejected));
|
| -
|
| - ASSERT_FALSE(promise.isEmpty());
|
| - ASSERT_TRUE(promise.v8Value()->IsPromise());
|
| -
|
| - EXPECT_EQ(String(), onFulfilled);
|
| - EXPECT_EQ(String(), onRejected);
|
| -
|
| - isolate()->RunMicrotasks();
|
| -
|
| - EXPECT_EQ(String(), onFulfilled);
|
| - EXPECT_EQ("hello", onRejected);
|
| -}
|
| -
|
| -TEST_F(ScriptPromiseTest, rejectWithExceptionState)
|
| -{
|
| - String onFulfilled, onRejected;
|
| - ScriptPromise promise = ScriptPromise::rejectWithDOMException(scriptState(), DOMException::create(SyntaxError, "some syntax error"));
|
| - promise.then(Function::create(isolate(), &onFulfilled), Function::create(isolate(), &onRejected));
|
| -
|
| - ASSERT_FALSE(promise.isEmpty());
|
| - EXPECT_EQ(String(), onFulfilled);
|
| - EXPECT_EQ(String(), onRejected);
|
| -
|
| - isolate()->RunMicrotasks();
|
| -
|
| - EXPECT_EQ(String(), onFulfilled);
|
| - EXPECT_EQ("SyntaxError: some syntax error", onRejected);
|
| -}
|
| -
|
| -} // namespace
|
| -
|
| -} // namespace WebCore
|
|
|