| Index: Source/bindings/v8/PrivateScriptTest.cpp
|
| diff --git a/Source/bindings/v8/PrivateScriptTest.cpp b/Source/bindings/v8/PrivateScriptTest.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4d7e7392847b93c95b5c4f3436f0c1c9e105a111
|
| --- /dev/null
|
| +++ b/Source/bindings/v8/PrivateScriptTest.cpp
|
| @@ -0,0 +1,189 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "config.h"
|
| +
|
| +#include "bindings/core/v8/V8PrivateScriptTest.h"
|
| +#include "bindings/v8/PrivateScriptController.h"
|
| +#include "bindings/v8/V8Binding.h"
|
| +#include "core/testing/DummyPageHolder.h"
|
| +#include "core/testing/UnitTestHelpers.h"
|
| +#include <gtest/gtest.h>
|
| +
|
| +namespace WebCore {
|
| +
|
| +namespace {
|
| +
|
| +class PrivateScriptTest : public ::testing::Test {
|
| +public:
|
| + PrivateScriptTest()
|
| + : m_scope(v8::Isolate::GetCurrent())
|
| + , m_dummyPageHolder(DummyPageHolder::create())
|
| + {
|
| + }
|
| +
|
| + ~PrivateScriptTest()
|
| + {
|
| + }
|
| +
|
| + LocalFrame* frame() const { return &m_dummyPageHolder->frame(); }
|
| + Document* document() const { return &m_dummyPageHolder->document(); }
|
| + v8::Isolate* isolate() const { return m_scope.isolate(); }
|
| +
|
| +protected:
|
| + V8TestingScope m_scope;
|
| + OwnPtr<DummyPageHolder> m_dummyPageHolder;
|
| +};
|
| +
|
| +TEST_F(PrivateScriptTest, doNothing)
|
| +{
|
| + bool success = V8PrivateScriptTest::doNothing(frame());
|
| + EXPECT_TRUE(success);
|
| +}
|
| +
|
| +TEST_F(PrivateScriptTest, return123)
|
| +{
|
| + int value = -1;
|
| + bool success = V8PrivateScriptTest::return123(frame(), &value);
|
| + EXPECT_TRUE(success);
|
| + EXPECT_EQ(value, 123);
|
| +}
|
| +
|
| +TEST_F(PrivateScriptTest, echoInteger)
|
| +{
|
| + int value = -1;
|
| + bool success = V8PrivateScriptTest::echoInteger(frame(), 123, &value);
|
| + EXPECT_TRUE(success);
|
| + EXPECT_EQ(value, 123);
|
| +}
|
| +
|
| +TEST_F(PrivateScriptTest, echoString)
|
| +{
|
| + String value;
|
| + bool success = V8PrivateScriptTest::echoString(frame(), "foo", &value);
|
| + EXPECT_TRUE(success);
|
| + EXPECT_EQ(value, "foo");
|
| +}
|
| +
|
| +TEST_F(PrivateScriptTest, addInteger)
|
| +{
|
| + int value = -1;
|
| + bool success = V8PrivateScriptTest::addInteger(frame(), 100, 200, &value);
|
| + EXPECT_TRUE(success);
|
| + EXPECT_EQ(value, 300);
|
| +}
|
| +
|
| +TEST_F(PrivateScriptTest, addString)
|
| +{
|
| + String value;
|
| + bool success = V8PrivateScriptTest::addString(frame(), "foo", "bar", &value);
|
| + EXPECT_TRUE(success);
|
| + EXPECT_EQ(value, "foobar");
|
| +}
|
| +
|
| +TEST_F(PrivateScriptTest, cacheIntegerFromDocument)
|
| +{
|
| + int value = -1;
|
| + bool success;
|
| + success = V8PrivateScriptTest::getIntegerFromDocument(frame(), document(), &value);
|
| + EXPECT_TRUE(success);
|
| + EXPECT_EQ(value, 0);
|
| + success = V8PrivateScriptTest::setIntegerToDocument(frame(), document(), 123);
|
| + EXPECT_TRUE(success);
|
| + success = V8PrivateScriptTest::getIntegerFromDocument(frame(), document(), &value);
|
| + EXPECT_TRUE(success);
|
| + EXPECT_EQ(value, 123);
|
| +}
|
| +
|
| +TEST_F(PrivateScriptTest, domTraverse)
|
| +{
|
| + RefPtrWillBeRawPtr<Node> node1 = nullptr;
|
| + RefPtrWillBeRawPtr<Node> node2 = nullptr;
|
| + RefPtrWillBeRawPtr<Node> node3 = nullptr;
|
| + RefPtrWillBeRawPtr<Node> node4 = nullptr;
|
| + bool success;
|
| + success = V8PrivateScriptTest::createElement(frame(), document(), &node1);
|
| + EXPECT_TRUE(success);
|
| + EXPECT_NE(node1, nullptr);
|
| + success = V8PrivateScriptTest::createElement(frame(), document(), &node2);
|
| + EXPECT_TRUE(success);
|
| + EXPECT_NE(node2, nullptr);
|
| + success = V8PrivateScriptTest::createElement(frame(), document(), &node3);
|
| + EXPECT_TRUE(success);
|
| + EXPECT_NE(node3, nullptr);
|
| + success = V8PrivateScriptTest::createElement(frame(), document(), &node4);
|
| + EXPECT_TRUE(success);
|
| + EXPECT_NE(node4, nullptr);
|
| +
|
| + success = V8PrivateScriptTest::appendChild(frame(), node1, node2);
|
| + EXPECT_TRUE(success);
|
| + success = V8PrivateScriptTest::appendChild(frame(), node1, node3);
|
| + EXPECT_TRUE(success);
|
| + success = V8PrivateScriptTest::appendChild(frame(), node1, node4);
|
| + EXPECT_TRUE(success);
|
| +
|
| + RefPtrWillBeRawPtr<Node> node = nullptr;
|
| + success = V8PrivateScriptTest::firstChild(frame(), node1, &node);
|
| + EXPECT_TRUE(success);
|
| + EXPECT_EQ(node, node2);
|
| + success = V8PrivateScriptTest::nextSibling(frame(), node2, &node);
|
| + EXPECT_TRUE(success);
|
| + EXPECT_EQ(node, node3);
|
| + success = V8PrivateScriptTest::nextSibling(frame(), node3, &node);
|
| + EXPECT_TRUE(success);
|
| + EXPECT_EQ(node, node4);
|
| + success = V8PrivateScriptTest::nextSibling(frame(), node4, &node);
|
| + EXPECT_TRUE(success);
|
| + EXPECT_EQ(node, nullptr);
|
| +}
|
| +
|
| +TEST_F(PrivateScriptTest, innerHTML)
|
| +{
|
| + RefPtrWillBeRawPtr<Node> node = nullptr;
|
| + bool success;
|
| + success = V8PrivateScriptTest::createElement(frame(), document(), &node);
|
| + EXPECT_TRUE(success);
|
| + EXPECT_NE(node, nullptr);
|
| + String str;
|
| + success = V8PrivateScriptTest::innerHTML(frame(), node, &str);
|
| + EXPECT_TRUE(success);
|
| + EXPECT_EQ(str, "");
|
| + success = V8PrivateScriptTest::setInnerHTML(frame(), node, "<div>foo</div>");
|
| + EXPECT_TRUE(success);
|
| + success = V8PrivateScriptTest::innerHTML(frame(), node, &str);
|
| + EXPECT_TRUE(success);
|
| + EXPECT_EQ(str, "<div>foo</div>");
|
| +
|
| + RefPtrWillBeRawPtr<Node> childNode = nullptr;
|
| + success = V8PrivateScriptTest::firstChild(frame(), node, &childNode);
|
| + EXPECT_TRUE(success);
|
| + EXPECT_NE(childNode, nullptr);
|
| + success = V8PrivateScriptTest::innerHTML(frame(), childNode, &str);
|
| + EXPECT_TRUE(success);
|
| + EXPECT_EQ(str, "foo");
|
| +}
|
| +
|
| +TEST_F(PrivateScriptTest, eventListener)
|
| +{
|
| + RefPtrWillBeRawPtr<Node> node = nullptr;
|
| + bool success;
|
| + success = V8PrivateScriptTest::createElement(frame(), document(), &node);
|
| + EXPECT_TRUE(success);
|
| + EXPECT_NE(node, nullptr);
|
| + String str;
|
| + success = V8PrivateScriptTest::innerHTML(frame(), node, &str);
|
| + EXPECT_TRUE(success);
|
| + EXPECT_EQ(str, "");
|
| + success = V8PrivateScriptTest::addClickListener(frame(), node);
|
| + EXPECT_TRUE(success);
|
| + success = V8PrivateScriptTest::clickNode(frame(), document(), node);
|
| + EXPECT_TRUE(success);
|
| + success = V8PrivateScriptTest::innerHTML(frame(), node, &str);
|
| + EXPECT_TRUE(success);
|
| + EXPECT_EQ(str, "clicked");
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +} // namespace WebCore
|
|
|