| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 |
| 7 #include "bindings/core/v8/V8PrivateScriptTest.h" |
| 8 #include "bindings/v8/PrivateScriptController.h" |
| 9 #include "bindings/v8/V8Binding.h" |
| 10 #include "core/testing/DummyPageHolder.h" |
| 11 #include "core/testing/UnitTestHelpers.h" |
| 12 #include <gtest/gtest.h> |
| 13 |
| 14 namespace WebCore { |
| 15 |
| 16 namespace { |
| 17 |
| 18 class PrivateScriptTest : public ::testing::Test { |
| 19 public: |
| 20 PrivateScriptTest() |
| 21 : m_scope(v8::Isolate::GetCurrent()) |
| 22 , m_dummyPageHolder(DummyPageHolder::create()) |
| 23 { |
| 24 } |
| 25 |
| 26 ~PrivateScriptTest() |
| 27 { |
| 28 } |
| 29 |
| 30 LocalFrame* frame() const { return &m_dummyPageHolder->frame(); } |
| 31 Document* document() const { return &m_dummyPageHolder->document(); } |
| 32 v8::Isolate* isolate() const { return m_scope.isolate(); } |
| 33 |
| 34 protected: |
| 35 V8TestingScope m_scope; |
| 36 OwnPtr<DummyPageHolder> m_dummyPageHolder; |
| 37 }; |
| 38 |
| 39 TEST_F(PrivateScriptTest, doNothing) |
| 40 { |
| 41 bool success = V8PrivateScriptTest::doNothing(frame()); |
| 42 EXPECT_TRUE(success); |
| 43 } |
| 44 |
| 45 TEST_F(PrivateScriptTest, return123) |
| 46 { |
| 47 int value = -1; |
| 48 bool success = V8PrivateScriptTest::return123(frame(), &value); |
| 49 EXPECT_TRUE(success); |
| 50 EXPECT_EQ(value, 123); |
| 51 } |
| 52 |
| 53 TEST_F(PrivateScriptTest, echoInteger) |
| 54 { |
| 55 int value = -1; |
| 56 bool success = V8PrivateScriptTest::echoInteger(frame(), 123, &value); |
| 57 EXPECT_TRUE(success); |
| 58 EXPECT_EQ(value, 123); |
| 59 } |
| 60 |
| 61 TEST_F(PrivateScriptTest, echoString) |
| 62 { |
| 63 String value; |
| 64 bool success = V8PrivateScriptTest::echoString(frame(), "foo", &value); |
| 65 EXPECT_TRUE(success); |
| 66 EXPECT_EQ(value, "foo"); |
| 67 } |
| 68 |
| 69 TEST_F(PrivateScriptTest, addInteger) |
| 70 { |
| 71 int value = -1; |
| 72 bool success = V8PrivateScriptTest::addInteger(frame(), 100, 200, &value); |
| 73 EXPECT_TRUE(success); |
| 74 EXPECT_EQ(value, 300); |
| 75 } |
| 76 |
| 77 TEST_F(PrivateScriptTest, addString) |
| 78 { |
| 79 String value; |
| 80 bool success = V8PrivateScriptTest::addString(frame(), "foo", "bar", &value)
; |
| 81 EXPECT_TRUE(success); |
| 82 EXPECT_EQ(value, "foobar"); |
| 83 } |
| 84 |
| 85 TEST_F(PrivateScriptTest, cacheIntegerFromDocument) |
| 86 { |
| 87 int value = -1; |
| 88 bool success; |
| 89 success = V8PrivateScriptTest::getIntegerFromDocument(frame(), document(), &
value); |
| 90 EXPECT_TRUE(success); |
| 91 EXPECT_EQ(value, 0); |
| 92 success = V8PrivateScriptTest::setIntegerToDocument(frame(), document(), 123
); |
| 93 EXPECT_TRUE(success); |
| 94 success = V8PrivateScriptTest::getIntegerFromDocument(frame(), document(), &
value); |
| 95 EXPECT_TRUE(success); |
| 96 EXPECT_EQ(value, 123); |
| 97 } |
| 98 |
| 99 TEST_F(PrivateScriptTest, domTraverse) |
| 100 { |
| 101 RefPtrWillBeRawPtr<Node> node1 = nullptr; |
| 102 RefPtrWillBeRawPtr<Node> node2 = nullptr; |
| 103 RefPtrWillBeRawPtr<Node> node3 = nullptr; |
| 104 RefPtrWillBeRawPtr<Node> node4 = nullptr; |
| 105 bool success; |
| 106 success = V8PrivateScriptTest::createElement(frame(), document(), &node1); |
| 107 EXPECT_TRUE(success); |
| 108 EXPECT_NE(node1, nullptr); |
| 109 success = V8PrivateScriptTest::createElement(frame(), document(), &node2); |
| 110 EXPECT_TRUE(success); |
| 111 EXPECT_NE(node2, nullptr); |
| 112 success = V8PrivateScriptTest::createElement(frame(), document(), &node3); |
| 113 EXPECT_TRUE(success); |
| 114 EXPECT_NE(node3, nullptr); |
| 115 success = V8PrivateScriptTest::createElement(frame(), document(), &node4); |
| 116 EXPECT_TRUE(success); |
| 117 EXPECT_NE(node4, nullptr); |
| 118 |
| 119 success = V8PrivateScriptTest::appendChild(frame(), node1, node2); |
| 120 EXPECT_TRUE(success); |
| 121 success = V8PrivateScriptTest::appendChild(frame(), node1, node3); |
| 122 EXPECT_TRUE(success); |
| 123 success = V8PrivateScriptTest::appendChild(frame(), node1, node4); |
| 124 EXPECT_TRUE(success); |
| 125 |
| 126 RefPtrWillBeRawPtr<Node> node = nullptr; |
| 127 success = V8PrivateScriptTest::firstChild(frame(), node1, &node); |
| 128 EXPECT_TRUE(success); |
| 129 EXPECT_EQ(node, node2); |
| 130 success = V8PrivateScriptTest::nextSibling(frame(), node2, &node); |
| 131 EXPECT_TRUE(success); |
| 132 EXPECT_EQ(node, node3); |
| 133 success = V8PrivateScriptTest::nextSibling(frame(), node3, &node); |
| 134 EXPECT_TRUE(success); |
| 135 EXPECT_EQ(node, node4); |
| 136 success = V8PrivateScriptTest::nextSibling(frame(), node4, &node); |
| 137 EXPECT_TRUE(success); |
| 138 EXPECT_EQ(node, nullptr); |
| 139 } |
| 140 |
| 141 TEST_F(PrivateScriptTest, innerHTML) |
| 142 { |
| 143 RefPtrWillBeRawPtr<Node> node = nullptr; |
| 144 bool success; |
| 145 success = V8PrivateScriptTest::createElement(frame(), document(), &node); |
| 146 EXPECT_TRUE(success); |
| 147 EXPECT_NE(node, nullptr); |
| 148 String str; |
| 149 success = V8PrivateScriptTest::innerHTML(frame(), node, &str); |
| 150 EXPECT_TRUE(success); |
| 151 EXPECT_EQ(str, ""); |
| 152 success = V8PrivateScriptTest::setInnerHTML(frame(), node, "<div>foo</div>")
; |
| 153 EXPECT_TRUE(success); |
| 154 success = V8PrivateScriptTest::innerHTML(frame(), node, &str); |
| 155 EXPECT_TRUE(success); |
| 156 EXPECT_EQ(str, "<div>foo</div>"); |
| 157 |
| 158 RefPtrWillBeRawPtr<Node> childNode = nullptr; |
| 159 success = V8PrivateScriptTest::firstChild(frame(), node, &childNode); |
| 160 EXPECT_TRUE(success); |
| 161 EXPECT_NE(childNode, nullptr); |
| 162 success = V8PrivateScriptTest::innerHTML(frame(), childNode, &str); |
| 163 EXPECT_TRUE(success); |
| 164 EXPECT_EQ(str, "foo"); |
| 165 } |
| 166 |
| 167 TEST_F(PrivateScriptTest, eventListener) |
| 168 { |
| 169 RefPtrWillBeRawPtr<Node> node = nullptr; |
| 170 bool success; |
| 171 success = V8PrivateScriptTest::createElement(frame(), document(), &node); |
| 172 EXPECT_TRUE(success); |
| 173 EXPECT_NE(node, nullptr); |
| 174 String str; |
| 175 success = V8PrivateScriptTest::innerHTML(frame(), node, &str); |
| 176 EXPECT_TRUE(success); |
| 177 EXPECT_EQ(str, ""); |
| 178 success = V8PrivateScriptTest::addClickListener(frame(), node); |
| 179 EXPECT_TRUE(success); |
| 180 success = V8PrivateScriptTest::clickNode(frame(), document(), node); |
| 181 EXPECT_TRUE(success); |
| 182 success = V8PrivateScriptTest::innerHTML(frame(), node, &str); |
| 183 EXPECT_TRUE(success); |
| 184 EXPECT_EQ(str, "clicked"); |
| 185 } |
| 186 |
| 187 } // namespace |
| 188 |
| 189 } // namespace WebCore |
| OLD | NEW |