Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Unified Diff: Source/bindings/v8/ScriptPromiseTest.cpp

Issue 351423002: Moved files under Source/bindings/v8 to Source/bindings/core/v8. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/v8/ScriptPromiseResolver.cpp ('k') | Source/bindings/v8/ScriptRegexp.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « Source/bindings/v8/ScriptPromiseResolver.cpp ('k') | Source/bindings/v8/ScriptRegexp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698