| 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 29 matching lines...) Expand all Loading... |
| 40 #include <v8.h> | 40 #include <v8.h> |
| 41 | 41 |
| 42 namespace WebCore { | 42 namespace WebCore { |
| 43 | 43 |
| 44 namespace { | 44 namespace { |
| 45 | 45 |
| 46 class ScriptPromiseResolverTest : public testing::Test { | 46 class ScriptPromiseResolverTest : public testing::Test { |
| 47 public: | 47 public: |
| 48 ScriptPromiseResolverTest() | 48 ScriptPromiseResolverTest() |
| 49 : m_isolate(v8::Isolate::GetCurrent()) | 49 : m_isolate(v8::Isolate::GetCurrent()) |
| 50 , m_handleScope(m_isolate) | |
| 51 , m_context(m_isolate, v8::Context::New(m_isolate)) | |
| 52 , m_contextScope(m_context.newLocal(m_isolate)) | |
| 53 { | 50 { |
| 54 } | 51 } |
| 55 | 52 |
| 56 void SetUp() | 53 void SetUp() |
| 57 { | 54 { |
| 58 // FIXME: Create a new world and pass it to V8PerContextData. | 55 m_scope = V8BindingTestScope::create(m_isolate); |
| 59 m_perContextData = V8PerContextData::create(m_context.newLocal(m_isolate
), 0); | |
| 60 m_promise = ScriptPromise::createPending(); | 56 m_promise = ScriptPromise::createPending(); |
| 61 m_resolver = ScriptPromiseResolver::create(m_promise); | 57 m_resolver = ScriptPromiseResolver::create(m_promise); |
| 62 } | 58 } |
| 63 | 59 |
| 64 void TearDown() | 60 void TearDown() |
| 65 { | 61 { |
| 66 m_resolver = nullptr; | 62 m_resolver = nullptr; |
| 67 m_promise.clear(); | 63 m_promise.clear(); |
| 68 m_perContextData.clear(); | 64 m_scope.clear(); |
| 69 } | 65 } |
| 70 | 66 |
| 71 V8PromiseCustom::PromiseState state() | 67 V8PromiseCustom::PromiseState state() |
| 72 { | 68 { |
| 73 return V8PromiseCustom::getState(V8PromiseCustom::getInternal(promise())
); | 69 return V8PromiseCustom::getState(V8PromiseCustom::getInternal(promise())
); |
| 74 } | 70 } |
| 75 | 71 |
| 76 v8::Local<v8::Value> result() | 72 v8::Local<v8::Value> result() |
| 77 { | 73 { |
| 78 return V8PromiseCustom::getInternal(promise())->GetInternalField(V8Promi
seCustom::InternalResultIndex); | 74 return V8PromiseCustom::getInternal(promise())->GetInternalField(V8Promi
seCustom::InternalResultIndex); |
| 79 } | 75 } |
| 80 | 76 |
| 81 v8::Local<v8::Object> promise() | 77 v8::Local<v8::Object> promise() |
| 82 { | 78 { |
| 83 ASSERT(!m_promise.hasNoValue()); | 79 ASSERT(!m_promise.hasNoValue()); |
| 84 return m_promise.v8Value().As<v8::Object>(); | 80 return m_promise.v8Value().As<v8::Object>(); |
| 85 } | 81 } |
| 86 | 82 |
| 87 protected: | 83 protected: |
| 88 v8::Isolate* m_isolate; | 84 v8::Isolate* m_isolate; |
| 89 v8::HandleScope m_handleScope; | |
| 90 ScopedPersistent<v8::Context> m_context; | |
| 91 v8::Context::Scope m_contextScope; | |
| 92 RefPtr<ScriptPromiseResolver> m_resolver; | 85 RefPtr<ScriptPromiseResolver> m_resolver; |
| 93 ScriptPromise m_promise; | 86 ScriptPromise m_promise; |
| 94 OwnPtr<V8PerContextData> m_perContextData; | 87 private: |
| 88 OwnPtr<V8BindingTestScope> m_scope; |
| 95 }; | 89 }; |
| 96 | 90 |
| 97 TEST_F(ScriptPromiseResolverTest, initialState) | 91 TEST_F(ScriptPromiseResolverTest, initialState) |
| 98 { | 92 { |
| 99 EXPECT_TRUE(m_resolver->isPending()); | 93 EXPECT_TRUE(m_resolver->isPending()); |
| 100 EXPECT_EQ(V8PromiseCustom::Pending, state()); | 94 EXPECT_EQ(V8PromiseCustom::Pending, state()); |
| 101 EXPECT_TRUE(result()->IsUndefined()); | 95 EXPECT_TRUE(result()->IsUndefined()); |
| 102 } | 96 } |
| 103 | 97 |
| 104 TEST_F(ScriptPromiseResolverTest, resolve) | 98 TEST_F(ScriptPromiseResolverTest, resolve) |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 m_resolver->reject(ScriptValue(v8::Integer::New(m_isolate, 4), m_isolate)); | 159 m_resolver->reject(ScriptValue(v8::Integer::New(m_isolate, 4), m_isolate)); |
| 166 EXPECT_FALSE(m_resolver->isPending()); | 160 EXPECT_FALSE(m_resolver->isPending()); |
| 167 EXPECT_EQ(V8PromiseCustom::Fulfilled, state()); | 161 EXPECT_EQ(V8PromiseCustom::Fulfilled, state()); |
| 168 ASSERT_TRUE(result()->IsNumber()); | 162 ASSERT_TRUE(result()->IsNumber()); |
| 169 EXPECT_EQ(3, result().As<v8::Integer>()->Value()); | 163 EXPECT_EQ(3, result().As<v8::Integer>()->Value()); |
| 170 } | 164 } |
| 171 | 165 |
| 172 } // namespace | 166 } // namespace |
| 173 | 167 |
| 174 } // namespace WebCore | 168 } // namespace WebCore |
| OLD | NEW |