| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 187 |
| 188 ASSERT_FALSE(promise.isEmpty()); | 188 ASSERT_FALSE(promise.isEmpty()); |
| 189 EXPECT_EQ(promise.v8Value(), newPromise.v8Value()); | 189 EXPECT_EQ(promise.v8Value(), newPromise.v8Value()); |
| 190 } | 190 } |
| 191 | 191 |
| 192 TEST_F(ScriptPromiseTest, castNonPromise) | 192 TEST_F(ScriptPromiseTest, castNonPromise) |
| 193 { | 193 { |
| 194 String onFulfilled1, onFulfilled2, onRejected1, onRejected2; | 194 String onFulfilled1, onFulfilled2, onRejected1, onRejected2; |
| 195 | 195 |
| 196 ScriptValue value = ScriptValue(scriptState(), v8String(isolate(), "hello"))
; | 196 ScriptValue value = ScriptValue(scriptState(), v8String(isolate(), "hello"))
; |
| 197 ScriptPromise promise1 = ScriptPromise::cast(ScriptValue(value)); | 197 ScriptPromise promise1 = ScriptPromise::cast(scriptState(), ScriptValue(valu
e)); |
| 198 ScriptPromise promise2 = ScriptPromise::cast(ScriptValue(value)); | 198 ScriptPromise promise2 = ScriptPromise::cast(scriptState(), ScriptValue(valu
e)); |
| 199 promise1.then(Function::create(isolate(), &onFulfilled1), Function::create(i
solate(), &onRejected1)); | 199 promise1.then(Function::create(isolate(), &onFulfilled1), Function::create(i
solate(), &onRejected1)); |
| 200 promise2.then(Function::create(isolate(), &onFulfilled2), Function::create(i
solate(), &onRejected2)); | 200 promise2.then(Function::create(isolate(), &onFulfilled2), Function::create(i
solate(), &onRejected2)); |
| 201 | 201 |
| 202 ASSERT_FALSE(promise1.isEmpty()); | 202 ASSERT_FALSE(promise1.isEmpty()); |
| 203 ASSERT_FALSE(promise2.isEmpty()); | 203 ASSERT_FALSE(promise2.isEmpty()); |
| 204 EXPECT_NE(promise1.v8Value(), promise2.v8Value()); | 204 EXPECT_NE(promise1.v8Value(), promise2.v8Value()); |
| 205 | 205 |
| 206 ASSERT_TRUE(promise1.v8Value()->IsPromise()); | 206 ASSERT_TRUE(promise1.v8Value()->IsPromise()); |
| 207 ASSERT_TRUE(promise2.v8Value()->IsPromise()); | 207 ASSERT_TRUE(promise2.v8Value()->IsPromise()); |
| 208 | 208 |
| 209 EXPECT_EQ(String(), onFulfilled1); | 209 EXPECT_EQ(String(), onFulfilled1); |
| 210 EXPECT_EQ(String(), onFulfilled2); | 210 EXPECT_EQ(String(), onFulfilled2); |
| 211 EXPECT_EQ(String(), onRejected1); | 211 EXPECT_EQ(String(), onRejected1); |
| 212 EXPECT_EQ(String(), onRejected2); | 212 EXPECT_EQ(String(), onRejected2); |
| 213 | 213 |
| 214 isolate()->RunMicrotasks(); | 214 isolate()->RunMicrotasks(); |
| 215 | 215 |
| 216 EXPECT_EQ("hello", onFulfilled1); | 216 EXPECT_EQ("hello", onFulfilled1); |
| 217 EXPECT_EQ("hello", onFulfilled2); | 217 EXPECT_EQ("hello", onFulfilled2); |
| 218 EXPECT_EQ(String(), onRejected1); | 218 EXPECT_EQ(String(), onRejected1); |
| 219 EXPECT_EQ(String(), onRejected2); | 219 EXPECT_EQ(String(), onRejected2); |
| 220 } | 220 } |
| 221 | 221 |
| 222 TEST_F(ScriptPromiseTest, reject) | 222 TEST_F(ScriptPromiseTest, reject) |
| 223 { | 223 { |
| 224 String onFulfilled, onRejected; | 224 String onFulfilled, onRejected; |
| 225 | 225 |
| 226 ScriptValue value = ScriptValue(scriptState(), v8String(isolate(), "hello"))
; | 226 ScriptValue value = ScriptValue(scriptState(), v8String(isolate(), "hello"))
; |
| 227 ScriptPromise promise = ScriptPromise::reject(ScriptValue(value)); | 227 ScriptPromise promise = ScriptPromise::reject(scriptState(), ScriptValue(val
ue)); |
| 228 promise.then(Function::create(isolate(), &onFulfilled), Function::create(iso
late(), &onRejected)); | 228 promise.then(Function::create(isolate(), &onFulfilled), Function::create(iso
late(), &onRejected)); |
| 229 | 229 |
| 230 ASSERT_FALSE(promise.isEmpty()); | 230 ASSERT_FALSE(promise.isEmpty()); |
| 231 ASSERT_TRUE(promise.v8Value()->IsPromise()); | 231 ASSERT_TRUE(promise.v8Value()->IsPromise()); |
| 232 | 232 |
| 233 EXPECT_EQ(String(), onFulfilled); | 233 EXPECT_EQ(String(), onFulfilled); |
| 234 EXPECT_EQ(String(), onRejected); | 234 EXPECT_EQ(String(), onRejected); |
| 235 | 235 |
| 236 isolate()->RunMicrotasks(); | 236 isolate()->RunMicrotasks(); |
| 237 | 237 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 251 | 251 |
| 252 isolate()->RunMicrotasks(); | 252 isolate()->RunMicrotasks(); |
| 253 | 253 |
| 254 EXPECT_EQ(String(), onFulfilled); | 254 EXPECT_EQ(String(), onFulfilled); |
| 255 EXPECT_EQ("SyntaxError: some syntax error", onRejected); | 255 EXPECT_EQ("SyntaxError: some syntax error", onRejected); |
| 256 } | 256 } |
| 257 | 257 |
| 258 } // namespace | 258 } // namespace |
| 259 | 259 |
| 260 } // namespace WebCore | 260 } // namespace WebCore |
| OLD | NEW |