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

Side by Side Diff: Source/bindings/v8/ScriptPromiseResolverTest.cpp

Issue 197213007: ScriptPromise implementation for V8 Promises (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 9 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "bindings/v8/ScriptPromiseResolver.h" 32 #include "bindings/v8/ScriptPromiseResolver.h"
33 33
34 #include "RuntimeEnabledFeatures.h"
34 #include "bindings/v8/DOMWrapperWorld.h" 35 #include "bindings/v8/DOMWrapperWorld.h"
35 #include "bindings/v8/ScriptPromise.h" 36 #include "bindings/v8/ScriptPromise.h"
36 #include "bindings/v8/V8Binding.h" 37 #include "bindings/v8/V8Binding.h"
37 #include "bindings/v8/custom/V8PromiseCustom.h" 38 #include "bindings/v8/custom/V8PromiseCustom.h"
38 39
39 #include <gtest/gtest.h> 40 #include <gtest/gtest.h>
40 #include <v8.h> 41 #include <v8.h>
41 42
42 namespace WebCore { 43 namespace WebCore {
43 44
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 protected: 84 protected:
84 v8::Isolate* m_isolate; 85 v8::Isolate* m_isolate;
85 RefPtr<ScriptPromiseResolver> m_resolver; 86 RefPtr<ScriptPromiseResolver> m_resolver;
86 ScriptPromise m_promise; 87 ScriptPromise m_promise;
87 private: 88 private:
88 OwnPtr<V8ExecutionScope> m_scope; 89 OwnPtr<V8ExecutionScope> m_scope;
89 }; 90 };
90 91
91 TEST_F(ScriptPromiseResolverTest, initialState) 92 TEST_F(ScriptPromiseResolverTest, initialState)
92 { 93 {
93 EXPECT_TRUE(m_resolver->isPending()); 94 if (RuntimeEnabledFeatures::scriptPromiseOnV8PromiseEnabled())
95 return;
94 EXPECT_EQ(V8PromiseCustom::Pending, state()); 96 EXPECT_EQ(V8PromiseCustom::Pending, state());
95 EXPECT_TRUE(result()->IsUndefined()); 97 EXPECT_TRUE(result()->IsUndefined());
96 } 98 }
97 99
98 TEST_F(ScriptPromiseResolverTest, resolve) 100 TEST_F(ScriptPromiseResolverTest, resolve)
99 { 101 {
100 EXPECT_TRUE(m_resolver->isPending()); 102 if (RuntimeEnabledFeatures::scriptPromiseOnV8PromiseEnabled())
103 return;
101 EXPECT_EQ(V8PromiseCustom::Pending, state()); 104 EXPECT_EQ(V8PromiseCustom::Pending, state());
102 EXPECT_TRUE(result()->IsUndefined()); 105 EXPECT_TRUE(result()->IsUndefined());
103 106
104 m_resolver->resolve(ScriptValue(v8::Integer::New(m_isolate, 3), m_isolate)); 107 m_resolver->resolve(ScriptValue(v8::Integer::New(m_isolate, 3), m_isolate));
105 108
106 EXPECT_FALSE(m_resolver->isPending());
107 EXPECT_EQ(V8PromiseCustom::Fulfilled, state()); 109 EXPECT_EQ(V8PromiseCustom::Fulfilled, state());
108 ASSERT_TRUE(result()->IsNumber()); 110 ASSERT_TRUE(result()->IsNumber());
109 EXPECT_EQ(3, result().As<v8::Integer>()->Value()); 111 EXPECT_EQ(3, result().As<v8::Integer>()->Value());
110 } 112 }
111 113
112 TEST_F(ScriptPromiseResolverTest, reject) 114 TEST_F(ScriptPromiseResolverTest, reject)
113 { 115 {
114 EXPECT_TRUE(m_resolver->isPending()); 116 if (RuntimeEnabledFeatures::scriptPromiseOnV8PromiseEnabled())
117 return;
115 EXPECT_EQ(V8PromiseCustom::Pending, state()); 118 EXPECT_EQ(V8PromiseCustom::Pending, state());
116 EXPECT_TRUE(result()->IsUndefined()); 119 EXPECT_TRUE(result()->IsUndefined());
117 120
118 m_resolver->reject(ScriptValue(v8::Integer::New(m_isolate, 3), m_isolate)); 121 m_resolver->reject(ScriptValue(v8::Integer::New(m_isolate, 3), m_isolate));
119 122
120 EXPECT_FALSE(m_resolver->isPending());
121 EXPECT_EQ(V8PromiseCustom::Rejected, state()); 123 EXPECT_EQ(V8PromiseCustom::Rejected, state());
122 ASSERT_TRUE(result()->IsNumber()); 124 ASSERT_TRUE(result()->IsNumber());
123 EXPECT_EQ(3, result().As<v8::Integer>()->Value()); 125 EXPECT_EQ(3, result().As<v8::Integer>()->Value());
124 } 126 }
125 127
126 TEST_F(ScriptPromiseResolverTest, resolveOverResolve) 128 TEST_F(ScriptPromiseResolverTest, resolveOverResolve)
127 { 129 {
128 EXPECT_TRUE(m_resolver->isPending()); 130 if (RuntimeEnabledFeatures::scriptPromiseOnV8PromiseEnabled())
131 return;
129 EXPECT_EQ(V8PromiseCustom::Pending, state()); 132 EXPECT_EQ(V8PromiseCustom::Pending, state());
130 EXPECT_TRUE(result()->IsUndefined()); 133 EXPECT_TRUE(result()->IsUndefined());
131 134
132 m_resolver->resolve(ScriptValue(v8::Integer::New(m_isolate, 3), m_isolate)); 135 m_resolver->resolve(ScriptValue(v8::Integer::New(m_isolate, 3), m_isolate));
133 136
134 EXPECT_FALSE(m_resolver->isPending());
135 EXPECT_EQ(V8PromiseCustom::Fulfilled, state()); 137 EXPECT_EQ(V8PromiseCustom::Fulfilled, state());
136 ASSERT_TRUE(result()->IsNumber()); 138 ASSERT_TRUE(result()->IsNumber());
137 EXPECT_EQ(3, result().As<v8::Integer>()->Value()); 139 EXPECT_EQ(3, result().As<v8::Integer>()->Value());
138 140
139 m_resolver->resolve(ScriptValue(v8::Integer::New(m_isolate, 4), m_isolate)); 141 m_resolver->resolve(ScriptValue(v8::Integer::New(m_isolate, 4), m_isolate));
140 EXPECT_FALSE(m_resolver->isPending());
141 EXPECT_EQ(V8PromiseCustom::Fulfilled, state()); 142 EXPECT_EQ(V8PromiseCustom::Fulfilled, state());
142 ASSERT_TRUE(result()->IsNumber()); 143 ASSERT_TRUE(result()->IsNumber());
143 EXPECT_EQ(3, result().As<v8::Integer>()->Value()); 144 EXPECT_EQ(3, result().As<v8::Integer>()->Value());
144 } 145 }
145 146
146 TEST_F(ScriptPromiseResolverTest, rejectOverResolve) 147 TEST_F(ScriptPromiseResolverTest, rejectOverResolve)
147 { 148 {
148 EXPECT_TRUE(m_resolver->isPending()); 149 if (RuntimeEnabledFeatures::scriptPromiseOnV8PromiseEnabled())
150 return;
149 EXPECT_EQ(V8PromiseCustom::Pending, state()); 151 EXPECT_EQ(V8PromiseCustom::Pending, state());
150 EXPECT_TRUE(result()->IsUndefined()); 152 EXPECT_TRUE(result()->IsUndefined());
151 153
152 m_resolver->resolve(ScriptValue(v8::Integer::New(m_isolate, 3), m_isolate)); 154 m_resolver->resolve(ScriptValue(v8::Integer::New(m_isolate, 3), m_isolate));
153 155
154 EXPECT_FALSE(m_resolver->isPending());
155 EXPECT_EQ(V8PromiseCustom::Fulfilled, state()); 156 EXPECT_EQ(V8PromiseCustom::Fulfilled, state());
156 ASSERT_TRUE(result()->IsNumber()); 157 ASSERT_TRUE(result()->IsNumber());
157 EXPECT_EQ(3, result().As<v8::Integer>()->Value()); 158 EXPECT_EQ(3, result().As<v8::Integer>()->Value());
158 159
159 m_resolver->reject(ScriptValue(v8::Integer::New(m_isolate, 4), m_isolate)); 160 m_resolver->reject(ScriptValue(v8::Integer::New(m_isolate, 4), m_isolate));
160 EXPECT_FALSE(m_resolver->isPending());
161 EXPECT_EQ(V8PromiseCustom::Fulfilled, state()); 161 EXPECT_EQ(V8PromiseCustom::Fulfilled, state());
162 ASSERT_TRUE(result()->IsNumber()); 162 ASSERT_TRUE(result()->IsNumber());
163 EXPECT_EQ(3, result().As<v8::Integer>()->Value()); 163 EXPECT_EQ(3, result().As<v8::Integer>()->Value());
164 } 164 }
165 165
166 } // namespace 166 } // namespace
167 167
168 } // namespace WebCore 168 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698