| OLD | NEW |
| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 , m_handleScope(m_isolate) | 49 , m_handleScope(m_isolate) |
| 50 , m_context(m_isolate, v8::Context::New(m_isolate)) | 50 , m_context(m_isolate, v8::Context::New(m_isolate)) |
| 51 , m_contextScope(m_context.newLocal(m_isolate)) | 51 , m_contextScope(m_context.newLocal(m_isolate)) |
| 52 { | 52 { |
| 53 } | 53 } |
| 54 | 54 |
| 55 void SetUp() | 55 void SetUp() |
| 56 { | 56 { |
| 57 m_perContextData = V8PerContextData::create(m_context.newLocal(m_isolate
)); | 57 m_perContextData = V8PerContextData::create(m_context.newLocal(m_isolate
)); |
| 58 m_perContextData->init(); | 58 m_perContextData->init(); |
| 59 m_resolver = ScriptPromiseResolver::create(); | 59 m_promise = ScriptPromise::createPending(); |
| 60 m_promise = m_resolver->promise(); | 60 m_resolver = ScriptPromiseResolver::create(m_promise); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void TearDown() | 63 void TearDown() |
| 64 { | 64 { |
| 65 m_resolver = 0; | 65 m_resolver = 0; |
| 66 m_promise.clear(); | 66 m_promise.clear(); |
| 67 m_perContextData.clear(); | 67 m_perContextData.clear(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 V8PromiseCustom::PromiseState state() | 70 V8PromiseCustom::PromiseState state() |
| (...skipping 22 matching lines...) Expand all Loading... |
| 93 OwnPtr<V8PerContextData> m_perContextData; | 93 OwnPtr<V8PerContextData> m_perContextData; |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 TEST_F(ScriptPromiseResolverTest, initialState) | 96 TEST_F(ScriptPromiseResolverTest, initialState) |
| 97 { | 97 { |
| 98 EXPECT_TRUE(m_resolver->isPending()); | 98 EXPECT_TRUE(m_resolver->isPending()); |
| 99 EXPECT_EQ(V8PromiseCustom::Pending, state()); | 99 EXPECT_EQ(V8PromiseCustom::Pending, state()); |
| 100 EXPECT_TRUE(result()->IsUndefined()); | 100 EXPECT_TRUE(result()->IsUndefined()); |
| 101 } | 101 } |
| 102 | 102 |
| 103 TEST_F(ScriptPromiseResolverTest, fulfill) | |
| 104 { | |
| 105 EXPECT_TRUE(m_resolver->isPending()); | |
| 106 EXPECT_EQ(V8PromiseCustom::Pending, state()); | |
| 107 EXPECT_TRUE(result()->IsUndefined()); | |
| 108 | |
| 109 m_resolver->fulfill(ScriptValue(v8::Integer::New(3, m_isolate), m_isolate)); | |
| 110 | |
| 111 EXPECT_FALSE(m_resolver->isPending()); | |
| 112 EXPECT_EQ(V8PromiseCustom::Fulfilled, state()); | |
| 113 ASSERT_TRUE(result()->IsNumber()); | |
| 114 EXPECT_EQ(3, result().As<v8::Integer>()->Value()); | |
| 115 } | |
| 116 | |
| 117 TEST_F(ScriptPromiseResolverTest, resolve) | 103 TEST_F(ScriptPromiseResolverTest, resolve) |
| 118 { | 104 { |
| 119 EXPECT_TRUE(m_resolver->isPending()); | 105 EXPECT_TRUE(m_resolver->isPending()); |
| 120 EXPECT_EQ(V8PromiseCustom::Pending, state()); | 106 EXPECT_EQ(V8PromiseCustom::Pending, state()); |
| 121 EXPECT_TRUE(result()->IsUndefined()); | 107 EXPECT_TRUE(result()->IsUndefined()); |
| 122 | 108 |
| 123 m_resolver->resolve(ScriptValue(v8::Integer::New(3, m_isolate), m_isolate)); | 109 m_resolver->resolve(ScriptValue(v8::Integer::New(3, m_isolate), m_isolate)); |
| 124 | 110 |
| 125 EXPECT_FALSE(m_resolver->isPending()); | 111 EXPECT_FALSE(m_resolver->isPending()); |
| 126 EXPECT_EQ(V8PromiseCustom::Fulfilled, state()); | 112 EXPECT_EQ(V8PromiseCustom::Fulfilled, state()); |
| 127 ASSERT_TRUE(result()->IsNumber()); | 113 ASSERT_TRUE(result()->IsNumber()); |
| 128 EXPECT_EQ(3, result().As<v8::Integer>()->Value()); | 114 EXPECT_EQ(3, result().As<v8::Integer>()->Value()); |
| 129 } | 115 } |
| 130 | 116 |
| 131 TEST_F(ScriptPromiseResolverTest, reject) | 117 TEST_F(ScriptPromiseResolverTest, reject) |
| 132 { | 118 { |
| 133 EXPECT_TRUE(m_resolver->isPending()); | 119 EXPECT_TRUE(m_resolver->isPending()); |
| 134 EXPECT_EQ(V8PromiseCustom::Pending, state()); | 120 EXPECT_EQ(V8PromiseCustom::Pending, state()); |
| 135 EXPECT_TRUE(result()->IsUndefined()); | 121 EXPECT_TRUE(result()->IsUndefined()); |
| 136 | 122 |
| 137 m_resolver->reject(ScriptValue(v8::Integer::New(3, m_isolate), m_isolate)); | 123 m_resolver->reject(ScriptValue(v8::Integer::New(3, m_isolate), m_isolate)); |
| 138 | 124 |
| 139 EXPECT_FALSE(m_resolver->isPending()); | 125 EXPECT_FALSE(m_resolver->isPending()); |
| 140 EXPECT_EQ(V8PromiseCustom::Rejected, state()); | 126 EXPECT_EQ(V8PromiseCustom::Rejected, state()); |
| 141 ASSERT_TRUE(result()->IsNumber()); | 127 ASSERT_TRUE(result()->IsNumber()); |
| 142 EXPECT_EQ(3, result().As<v8::Integer>()->Value()); | 128 EXPECT_EQ(3, result().As<v8::Integer>()->Value()); |
| 143 } | 129 } |
| 144 | 130 |
| 145 TEST_F(ScriptPromiseResolverTest, fulfillOverFulfill) | 131 TEST_F(ScriptPromiseResolverTest, resolveOverResolve) |
| 146 { | 132 { |
| 147 EXPECT_TRUE(m_resolver->isPending()); | 133 EXPECT_TRUE(m_resolver->isPending()); |
| 148 EXPECT_EQ(V8PromiseCustom::Pending, state()); | 134 EXPECT_EQ(V8PromiseCustom::Pending, state()); |
| 149 EXPECT_TRUE(result()->IsUndefined()); | 135 EXPECT_TRUE(result()->IsUndefined()); |
| 150 | 136 |
| 151 m_resolver->fulfill(ScriptValue(v8::Integer::New(3, m_isolate), m_isolate)); | 137 m_resolver->resolve(ScriptValue(v8::Integer::New(3, m_isolate), m_isolate)); |
| 152 | 138 |
| 153 EXPECT_FALSE(m_resolver->isPending()); | 139 EXPECT_FALSE(m_resolver->isPending()); |
| 154 EXPECT_EQ(V8PromiseCustom::Fulfilled, state()); | 140 EXPECT_EQ(V8PromiseCustom::Fulfilled, state()); |
| 155 ASSERT_TRUE(result()->IsNumber()); | 141 ASSERT_TRUE(result()->IsNumber()); |
| 156 EXPECT_EQ(3, result().As<v8::Integer>()->Value()); | 142 EXPECT_EQ(3, result().As<v8::Integer>()->Value()); |
| 157 | 143 |
| 158 m_resolver->fulfill(ScriptValue(v8::Integer::New(4, m_isolate), m_isolate)); | 144 m_resolver->resolve(ScriptValue(v8::Integer::New(4, m_isolate), m_isolate)); |
| 159 EXPECT_FALSE(m_resolver->isPending()); | 145 EXPECT_FALSE(m_resolver->isPending()); |
| 160 EXPECT_EQ(V8PromiseCustom::Fulfilled, state()); | 146 EXPECT_EQ(V8PromiseCustom::Fulfilled, state()); |
| 161 ASSERT_TRUE(result()->IsNumber()); | 147 ASSERT_TRUE(result()->IsNumber()); |
| 162 EXPECT_EQ(3, result().As<v8::Integer>()->Value()); | 148 EXPECT_EQ(3, result().As<v8::Integer>()->Value()); |
| 163 } | 149 } |
| 164 | 150 |
| 165 TEST_F(ScriptPromiseResolverTest, rejectOverFulfill) | 151 TEST_F(ScriptPromiseResolverTest, rejectOverResolve) |
| 166 { | 152 { |
| 167 EXPECT_TRUE(m_resolver->isPending()); | 153 EXPECT_TRUE(m_resolver->isPending()); |
| 168 EXPECT_EQ(V8PromiseCustom::Pending, state()); | 154 EXPECT_EQ(V8PromiseCustom::Pending, state()); |
| 169 EXPECT_TRUE(result()->IsUndefined()); | 155 EXPECT_TRUE(result()->IsUndefined()); |
| 170 | 156 |
| 171 m_resolver->fulfill(ScriptValue(v8::Integer::New(3, m_isolate), m_isolate)); | 157 m_resolver->resolve(ScriptValue(v8::Integer::New(3, m_isolate), m_isolate)); |
| 172 | 158 |
| 173 EXPECT_FALSE(m_resolver->isPending()); | 159 EXPECT_FALSE(m_resolver->isPending()); |
| 174 EXPECT_EQ(V8PromiseCustom::Fulfilled, state()); | 160 EXPECT_EQ(V8PromiseCustom::Fulfilled, state()); |
| 175 ASSERT_TRUE(result()->IsNumber()); | 161 ASSERT_TRUE(result()->IsNumber()); |
| 176 EXPECT_EQ(3, result().As<v8::Integer>()->Value()); | 162 EXPECT_EQ(3, result().As<v8::Integer>()->Value()); |
| 177 | 163 |
| 178 m_resolver->reject(ScriptValue(v8::Integer::New(4, m_isolate), m_isolate)); | 164 m_resolver->reject(ScriptValue(v8::Integer::New(4, m_isolate), m_isolate)); |
| 179 EXPECT_FALSE(m_resolver->isPending()); | 165 EXPECT_FALSE(m_resolver->isPending()); |
| 180 EXPECT_EQ(V8PromiseCustom::Fulfilled, state()); | 166 EXPECT_EQ(V8PromiseCustom::Fulfilled, state()); |
| 181 ASSERT_TRUE(result()->IsNumber()); | 167 ASSERT_TRUE(result()->IsNumber()); |
| 182 EXPECT_EQ(3, result().As<v8::Integer>()->Value()); | 168 EXPECT_EQ(3, result().As<v8::Integer>()->Value()); |
| 183 } | 169 } |
| 184 | 170 |
| 185 TEST_F(ScriptPromiseResolverTest, detach) | |
| 186 { | |
| 187 EXPECT_TRUE(m_resolver->isPending()); | |
| 188 EXPECT_EQ(V8PromiseCustom::Pending, state()); | |
| 189 EXPECT_TRUE(result()->IsUndefined()); | |
| 190 | |
| 191 m_resolver->detach(); | |
| 192 | |
| 193 EXPECT_FALSE(m_resolver->isPending()); | |
| 194 EXPECT_EQ(V8PromiseCustom::Rejected, state()); | |
| 195 EXPECT_TRUE(result()->IsUndefined()); | |
| 196 } | |
| 197 | |
| 198 } // namespace | 171 } // namespace |
| 199 | 172 |
| 200 } // namespace WebCore | 173 } // namespace WebCore |
| OLD | NEW |