| 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 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 ScriptPromiseTest : public testing::Test { | 46 class ScriptPromiseTest : public testing::Test { |
| 47 public: | 47 public: |
| 48 ScriptPromiseTest() | 48 ScriptPromiseTest() |
| 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 } | 60 } |
| 57 | 61 |
| 58 void TearDown() | 62 void TearDown() |
| 59 { | 63 { |
| 60 m_scope.clear(); | 64 m_perContextData.clear(); |
| 61 } | 65 } |
| 62 | 66 |
| 63 V8PromiseCustom::PromiseState state(ScriptPromise promise) | 67 V8PromiseCustom::PromiseState state(ScriptPromise promise) |
| 64 { | 68 { |
| 65 return V8PromiseCustom::getState(V8PromiseCustom::getInternal(promise.v8
Value().As<v8::Object>())); | 69 return V8PromiseCustom::getState(V8PromiseCustom::getInternal(promise.v8
Value().As<v8::Object>())); |
| 66 } | 70 } |
| 67 | 71 |
| 68 protected: | 72 protected: |
| 69 v8::Isolate* m_isolate; | 73 v8::Isolate* m_isolate; |
| 70 | 74 v8::HandleScope m_handleScope; |
| 71 private: | 75 ScopedPersistent<v8::Context> m_context; |
| 72 OwnPtr<V8BindingTestScope> m_scope; | 76 v8::Context::Scope m_contextScope; |
| 77 OwnPtr<V8PerContextData> m_perContextData; |
| 73 }; | 78 }; |
| 74 | 79 |
| 75 TEST_F(ScriptPromiseTest, castPromise) | 80 TEST_F(ScriptPromiseTest, castPromise) |
| 76 { | 81 { |
| 77 ScriptPromise promise = ScriptPromise::createPending(); | 82 ScriptPromise promise = ScriptPromise::createPending(); |
| 78 ScriptPromise newPromise(ScriptValue(promise.v8Value(), m_isolate)); | 83 ScriptPromise newPromise(ScriptValue(promise.v8Value(), m_isolate)); |
| 79 | 84 |
| 80 ASSERT_FALSE(promise.hasNoValue()); | 85 ASSERT_FALSE(promise.hasNoValue()); |
| 81 EXPECT_EQ(V8PromiseCustom::Pending, state(promise)); | 86 EXPECT_EQ(V8PromiseCustom::Pending, state(promise)); |
| 82 EXPECT_EQ(promise.v8Value(), newPromise.v8Value()); | 87 EXPECT_EQ(promise.v8Value(), newPromise.v8Value()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 95 ASSERT_TRUE(V8PromiseCustom::isPromise(promise2.v8Value(), m_isolate)); | 100 ASSERT_TRUE(V8PromiseCustom::isPromise(promise2.v8Value(), m_isolate)); |
| 96 | 101 |
| 97 EXPECT_EQ(V8PromiseCustom::Fulfilled, state(promise1)); | 102 EXPECT_EQ(V8PromiseCustom::Fulfilled, state(promise1)); |
| 98 EXPECT_EQ(V8PromiseCustom::Fulfilled, state(promise2)); | 103 EXPECT_EQ(V8PromiseCustom::Fulfilled, state(promise2)); |
| 99 EXPECT_NE(promise1.v8Value(), promise2.v8Value()); | 104 EXPECT_NE(promise1.v8Value(), promise2.v8Value()); |
| 100 } | 105 } |
| 101 | 106 |
| 102 } // namespace | 107 } // namespace |
| 103 | 108 |
| 104 } // namespace WebCore | 109 } // namespace WebCore |
| OLD | NEW |