OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * |
| 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are |
| 6 * met: |
| 7 * |
| 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. |
| 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ |
| 30 |
| 31 #include "config.h" |
| 32 #include "bindings/v8/ThenableCoercions.h" |
| 33 |
| 34 #include "bindings/v8/V8Binding.h" |
| 35 |
| 36 #include <gtest/gtest.h> |
| 37 #include <v8.h> |
| 38 |
| 39 namespace WebCore { |
| 40 |
| 41 namespace { |
| 42 |
| 43 class ThenableCoercionsTest : public testing::Test { |
| 44 public: |
| 45 ThenableCoercionsTest() |
| 46 : m_isolate(v8::Isolate::GetCurrent()) |
| 47 , m_handleScope(m_isolate) |
| 48 , m_context(m_isolate, v8::Context::New(m_isolate)) |
| 49 , m_contextScope(m_context.newLocal(m_isolate)) |
| 50 { |
| 51 } |
| 52 |
| 53 void SetUp() |
| 54 { |
| 55 m_perContextData = V8PerContextData::create(m_context.newLocal(m_isolate
)); |
| 56 m_perContextData->init(); |
| 57 } |
| 58 |
| 59 void TearDown() |
| 60 { |
| 61 m_perContextData.clear(); |
| 62 } |
| 63 |
| 64 protected: |
| 65 v8::Isolate* m_isolate; |
| 66 v8::HandleScope m_handleScope; |
| 67 ScopedPersistent<v8::Context> m_context; |
| 68 v8::Context::Scope m_contextScope; |
| 69 OwnPtr<V8PerContextData> m_perContextData; |
| 70 }; |
| 71 |
| 72 TEST_F(ThenableCoercionsTest, has) |
| 73 { |
| 74 OwnPtr<ThenableCoercions> thenableCoercions = ThenableCoercions::create(); |
| 75 v8::Handle<v8::Object> key = v8::Object::New(); |
| 76 v8::Handle<v8::Object> key2 = v8::Object::New(); |
| 77 v8::Handle<v8::Object> value = v8::Object::New(); |
| 78 |
| 79 EXPECT_FALSE(thenableCoercions->has(key)); |
| 80 |
| 81 thenableCoercions->set(key, value, m_isolate); |
| 82 EXPECT_TRUE(thenableCoercions->has(key)); |
| 83 EXPECT_TRUE(thenableCoercions->get(key2).IsEmpty()); |
| 84 } |
| 85 |
| 86 TEST_F(ThenableCoercionsTest, get) |
| 87 { |
| 88 OwnPtr<ThenableCoercions> thenableCoercions = ThenableCoercions::create(); |
| 89 v8::Handle<v8::Object> key = v8::Object::New(); |
| 90 v8::Handle<v8::Object> key2 = v8::Object::New(); |
| 91 v8::Handle<v8::Object> value = v8::Object::New(); |
| 92 |
| 93 EXPECT_TRUE(thenableCoercions->get(key).IsEmpty()); |
| 94 |
| 95 thenableCoercions->set(key, value, m_isolate); |
| 96 EXPECT_TRUE(thenableCoercions->has(key)); |
| 97 EXPECT_TRUE(thenableCoercions->get(key)->StrictEquals(value)); |
| 98 |
| 99 EXPECT_TRUE(thenableCoercions->get(key2).IsEmpty()); |
| 100 } |
| 101 |
| 102 TEST_F(ThenableCoercionsTest, set) |
| 103 { |
| 104 OwnPtr<ThenableCoercions> thenableCoercions = ThenableCoercions::create(); |
| 105 v8::Handle<v8::Object> key = v8::Object::New(); |
| 106 v8::Handle<v8::Object> key2 = v8::Object::New(); |
| 107 v8::Handle<v8::Object> value = v8::Object::New(); |
| 108 v8::Handle<v8::Object> value2 = v8::Object::New(); |
| 109 |
| 110 EXPECT_FALSE(thenableCoercions->has(key)); |
| 111 EXPECT_FALSE(thenableCoercions->has(key2)); |
| 112 |
| 113 thenableCoercions->set(key, value, m_isolate); |
| 114 EXPECT_TRUE(thenableCoercions->has(key)); |
| 115 EXPECT_FALSE(thenableCoercions->has(key2)); |
| 116 |
| 117 thenableCoercions->set(key2, value2, m_isolate); |
| 118 EXPECT_TRUE(thenableCoercions->has(key)); |
| 119 EXPECT_TRUE(thenableCoercions->has(key2)); |
| 120 |
| 121 EXPECT_TRUE(thenableCoercions->get(key)->StrictEquals(value)); |
| 122 EXPECT_TRUE(thenableCoercions->get(key2)->StrictEquals(value2)); |
| 123 } |
| 124 |
| 125 } // namespace |
| 126 |
| 127 } // namespace WebCore |
OLD | NEW |