Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: test/JsValue.cpp

Issue 10184021: Some refactoring of global JavaScript objects (Closed)
Patch Set: Unbitrotted patch Created April 16, 2013, 3:32 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/JsEngine.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/JsValue.cpp
===================================================================
--- a/test/JsValue.cpp
+++ b/test/JsValue.cpp
@@ -24,16 +24,17 @@ TEST(JsValueTest, UndefinedValue)
ASSERT_FALSE(value->IsArray());
ASSERT_FALSE(value->IsFunction());
ASSERT_EQ("undefined", value->AsString());
ASSERT_FALSE(value->AsBool());
ASSERT_ANY_THROW(value->AsList());
ASSERT_ANY_THROW(value->GetProperty("foo"));
ASSERT_ANY_THROW(value->SetProperty("foo", false));
ASSERT_ANY_THROW(value->GetClassName());
+ ASSERT_ANY_THROW(value->GetOwnPropertyNames());
ASSERT_ANY_THROW(value->Call());
}
TEST(JsValueTest, NullValue)
{
ThrowingErrorCallback errorCallback;
AdblockPlus::JsEngine jsEngine(0, 0, &errorCallback);
AdblockPlus::JsValuePtr value = jsEngine.Evaluate("null");
@@ -46,16 +47,17 @@ TEST(JsValueTest, NullValue)
ASSERT_FALSE(value->IsArray());
ASSERT_FALSE(value->IsFunction());
ASSERT_EQ("null", value->AsString());
ASSERT_FALSE(value->AsBool());
ASSERT_ANY_THROW(value->AsList());
ASSERT_ANY_THROW(value->GetProperty("foo"));
ASSERT_ANY_THROW(value->SetProperty("foo", false));
ASSERT_ANY_THROW(value->GetClassName());
+ ASSERT_ANY_THROW(value->GetOwnPropertyNames());
ASSERT_ANY_THROW(value->Call());
}
TEST(JsValueTest, StringValue)
{
ThrowingErrorCallback errorCallback;
AdblockPlus::JsEngine jsEngine(0, 0, &errorCallback);
AdblockPlus::JsValuePtr value = jsEngine.Evaluate("'123'");
@@ -69,16 +71,17 @@ TEST(JsValueTest, StringValue)
ASSERT_FALSE(value->IsFunction());
ASSERT_EQ("123", value->AsString());
ASSERT_EQ(123, value->AsInt());
ASSERT_TRUE(value->AsBool());
ASSERT_ANY_THROW(value->AsList());
ASSERT_ANY_THROW(value->GetProperty("foo"));
ASSERT_ANY_THROW(value->SetProperty("foo", false));
ASSERT_ANY_THROW(value->GetClassName());
+ ASSERT_ANY_THROW(value->GetOwnPropertyNames());
ASSERT_ANY_THROW(value->Call());
}
TEST(JsValueTest, IntValue)
{
ThrowingErrorCallback errorCallback;
AdblockPlus::JsEngine jsEngine(0, 0, &errorCallback);
AdblockPlus::JsValuePtr value = jsEngine.Evaluate("123");
@@ -92,16 +95,17 @@ TEST(JsValueTest, IntValue)
ASSERT_FALSE(value->IsFunction());
ASSERT_EQ("123", value->AsString());
ASSERT_EQ(123, value->AsInt());
ASSERT_TRUE(value->AsBool());
ASSERT_ANY_THROW(value->AsList());
ASSERT_ANY_THROW(value->GetProperty("foo"));
ASSERT_ANY_THROW(value->SetProperty("foo", false));
ASSERT_ANY_THROW(value->GetClassName());
+ ASSERT_ANY_THROW(value->GetOwnPropertyNames());
ASSERT_ANY_THROW(value->Call());
}
TEST(JsValueTest, BoolValue)
{
ThrowingErrorCallback errorCallback;
AdblockPlus::JsEngine jsEngine(0, 0, &errorCallback);
AdblockPlus::JsValuePtr value = jsEngine.Evaluate("true");
@@ -114,16 +118,17 @@ TEST(JsValueTest, BoolValue)
ASSERT_FALSE(value->IsArray());
ASSERT_FALSE(value->IsFunction());
ASSERT_EQ("true", value->AsString());
ASSERT_TRUE(value->AsBool());
ASSERT_ANY_THROW(value->AsList());
ASSERT_ANY_THROW(value->GetProperty("foo"));
ASSERT_ANY_THROW(value->SetProperty("foo", false));
ASSERT_ANY_THROW(value->GetClassName());
+ ASSERT_ANY_THROW(value->GetOwnPropertyNames());
ASSERT_ANY_THROW(value->Call());
}
TEST(JsValueTest, ObjectValue)
{
ThrowingErrorCallback errorCallback;
AdblockPlus::JsEngine jsEngine(0, 0, &errorCallback);
const std::string source("\
@@ -144,17 +149,20 @@ TEST(JsValueTest, ObjectValue)
ASSERT_FALSE(value->IsFunction());
ASSERT_EQ("foo", value->AsString());
ASSERT_EQ(123, value->AsInt());
ASSERT_TRUE(value->AsBool());
ASSERT_ANY_THROW(value->AsList());
ASSERT_EQ(2, value->GetProperty("x")->AsInt());
value->SetProperty("x", 12);
ASSERT_EQ(12, value->GetProperty("x")->AsInt());
+ value->SetProperty("x", jsEngine.NewValue(15));
+ ASSERT_EQ(15, value->GetProperty("x")->AsInt());
ASSERT_EQ("Foo", value->GetClassName());
+ ASSERT_EQ(3u, value->GetOwnPropertyNames().size());
ASSERT_ANY_THROW(value->Call());
}
TEST(JsValueTest, ArrayValue)
{
ThrowingErrorCallback errorCallback;
AdblockPlus::JsEngine jsEngine(0, 0, &errorCallback);
AdblockPlus::JsValuePtr value = jsEngine.Evaluate("[5,8,12]");
« no previous file with comments | « test/JsEngine.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld