Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(325)

Unified Diff: Source/bindings/v8/BlinkInJSTest.cpp

Issue 345893002: Implement an infrastructure of Blink-in-JS Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/bindings/v8/BlinkInJSTest.cpp
diff --git a/Source/bindings/v8/BlinkInJSTest.cpp b/Source/bindings/v8/BlinkInJSTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..088c39f857b910267de158bf1810143546798979
--- /dev/null
+++ b/Source/bindings/v8/BlinkInJSTest.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/V8BlinkInJSTest.h"
+#include "bindings/v8/BlinkInJSController.h"
+#include "bindings/v8/V8Binding.h"
+#include "core/testing/DummyPageHolder.h"
+#include "core/testing/UnitTestHelpers.h"
+#include <gtest/gtest.h>
+
+namespace WebCore {
+
+namespace {
+
+class BlinkInJSTest : public ::testing::Test {
+public:
+ BlinkInJSTest()
+ : m_scope(v8::Isolate::GetCurrent())
+ , m_dummyPageHolder(DummyPageHolder::create())
+ {
+ }
+
+ ~BlinkInJSTest()
+ {
+ }
+
+ 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(BlinkInJSTest, doNothing)
+{
+ bool success = V8BlinkInJSTest::doNothing(frame());
+ EXPECT_TRUE(success);
+}
+
+TEST_F(BlinkInJSTest, return123)
+{
+ int value = -1;
+ bool success = V8BlinkInJSTest::return123(frame(), &value);
+ EXPECT_TRUE(success);
+ EXPECT_EQ(value, 123);
+}
+
+TEST_F(BlinkInJSTest, echoInteger)
+{
+ int value = -1;
+ bool success = V8BlinkInJSTest::echoInteger(frame(), 123, &value);
+ EXPECT_TRUE(success);
+ EXPECT_EQ(value, 123);
+}
+
+TEST_F(BlinkInJSTest, echoString)
+{
+ String value;
+ bool success = V8BlinkInJSTest::echoString(frame(), "foo", &value);
+ EXPECT_TRUE(success);
+ EXPECT_EQ(value, "foo");
+}
+
+TEST_F(BlinkInJSTest, addInteger)
+{
+ int value = -1;
+ bool success = V8BlinkInJSTest::addInteger(frame(), 100, 200, &value);
+ EXPECT_TRUE(success);
+ EXPECT_EQ(value, 300);
+}
+
+TEST_F(BlinkInJSTest, addString)
+{
+ String value;
+ bool success = V8BlinkInJSTest::addString(frame(), "foo", "bar", &value);
+ EXPECT_TRUE(success);
+ EXPECT_EQ(value, "foobar");
+}
+
+TEST_F(BlinkInJSTest, cacheIntegerFromDocument)
+{
+ int value = -1;
+ bool success;
+ success = V8BlinkInJSTest::getIntegerFromDocument(frame(), document(), &value);
+ EXPECT_TRUE(success);
+ EXPECT_EQ(value, 0);
+ success = V8BlinkInJSTest::setIntegerToDocument(frame(), document(), 123);
+ EXPECT_TRUE(success);
+ success = V8BlinkInJSTest::getIntegerFromDocument(frame(), document(), &value);
+ EXPECT_TRUE(success);
+ EXPECT_EQ(value, 123);
+}
+
+TEST_F(BlinkInJSTest, domTraverse)
+{
+ RefPtrWillBeRawPtr<Node> node1 = nullptr;
+ RefPtrWillBeRawPtr<Node> node2 = nullptr;
+ RefPtrWillBeRawPtr<Node> node3 = nullptr;
+ RefPtrWillBeRawPtr<Node> node4 = nullptr;
+ bool success;
+ success = V8BlinkInJSTest::createElement(frame(), document(), &node1);
+ EXPECT_TRUE(success);
+ EXPECT_NE(node1, nullptr);
+ success = V8BlinkInJSTest::createElement(frame(), document(), &node2);
+ EXPECT_TRUE(success);
+ EXPECT_NE(node2, nullptr);
+ success = V8BlinkInJSTest::createElement(frame(), document(), &node3);
+ EXPECT_TRUE(success);
+ EXPECT_NE(node3, nullptr);
+ success = V8BlinkInJSTest::createElement(frame(), document(), &node4);
+ EXPECT_TRUE(success);
+ EXPECT_NE(node4, nullptr);
+
+ success = V8BlinkInJSTest::appendChild(frame(), node1, node2);
+ EXPECT_TRUE(success);
+ success = V8BlinkInJSTest::appendChild(frame(), node1, node3);
+ EXPECT_TRUE(success);
+ success = V8BlinkInJSTest::appendChild(frame(), node1, node4);
+ EXPECT_TRUE(success);
+
+ RefPtrWillBeRawPtr<Node> node = nullptr;
+ success = V8BlinkInJSTest::firstChild(frame(), node1, &node);
+ EXPECT_TRUE(success);
+ EXPECT_EQ(node, node2);
+ success = V8BlinkInJSTest::nextSibling(frame(), node2, &node);
+ EXPECT_TRUE(success);
+ EXPECT_EQ(node, node3);
+ success = V8BlinkInJSTest::nextSibling(frame(), node3, &node);
+ EXPECT_TRUE(success);
+ EXPECT_EQ(node, node4);
+ success = V8BlinkInJSTest::nextSibling(frame(), node4, &node);
+ EXPECT_TRUE(success);
+ EXPECT_EQ(node, nullptr);
+}
+
+TEST_F(BlinkInJSTest, innerHTML)
+{
+ RefPtrWillBeRawPtr<Node> node = nullptr;
+ bool success;
+ success = V8BlinkInJSTest::createElement(frame(), document(), &node);
+ EXPECT_TRUE(success);
+ EXPECT_NE(node, nullptr);
+ String str;
+ success = V8BlinkInJSTest::innerHTML(frame(), node, &str);
+ EXPECT_TRUE(success);
+ EXPECT_EQ(str, "");
+ success = V8BlinkInJSTest::setInnerHTML(frame(), node, "<div>foo</div>");
+ EXPECT_TRUE(success);
+ success = V8BlinkInJSTest::innerHTML(frame(), node, &str);
+ EXPECT_TRUE(success);
+ EXPECT_EQ(str, "<div>foo</div>");
+
+ RefPtrWillBeRawPtr<Node> childNode = nullptr;
+ success = V8BlinkInJSTest::firstChild(frame(), node, &childNode);
+ EXPECT_TRUE(success);
+ EXPECT_NE(childNode, nullptr);
+ success = V8BlinkInJSTest::innerHTML(frame(), childNode, &str);
+ EXPECT_TRUE(success);
+ EXPECT_EQ(str, "foo");
+}
+
+TEST_F(BlinkInJSTest, eventListener)
+{
+ RefPtrWillBeRawPtr<Node> node = nullptr;
+ bool success;
+ success = V8BlinkInJSTest::createElement(frame(), document(), &node);
+ EXPECT_TRUE(success);
+ EXPECT_NE(node, nullptr);
+ String str;
+ success = V8BlinkInJSTest::innerHTML(frame(), node, &str);
+ EXPECT_TRUE(success);
+ EXPECT_EQ(str, "");
+ success = V8BlinkInJSTest::addClickListener(frame(), node);
+ EXPECT_TRUE(success);
+ success = V8BlinkInJSTest::clickNode(frame(), document(), node);
+ EXPECT_TRUE(success);
+ success = V8BlinkInJSTest::innerHTML(frame(), node, &str);
+ EXPECT_TRUE(success);
+ EXPECT_EQ(str, "clicked");
+}
+
+} // namespace
+
+} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698