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